github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/internal/sys/arch.go (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package sys 6 7 import "github.com/shogo82148/std/encoding/binary" 8 9 // ArchFamily represents a family of one or more related architectures. 10 // For example, ppc64 and ppc64le are both members of the PPC64 family. 11 type ArchFamily byte 12 13 const ( 14 NoArch ArchFamily = iota 15 AMD64 16 ARM 17 ARM64 18 I386 19 Loong64 20 MIPS 21 MIPS64 22 PPC64 23 RISCV64 24 S390X 25 Wasm 26 ) 27 28 // Arch represents an individual architecture. 29 type Arch struct { 30 Name string 31 Family ArchFamily 32 33 ByteOrder binary.ByteOrder 34 35 // PtrSize is the size in bytes of pointers and the 36 // predeclared "int", "uint", and "uintptr" types. 37 PtrSize int 38 39 // RegSize is the size in bytes of general purpose registers. 40 RegSize int 41 42 // MinLC is the minimum length of an instruction code. 43 MinLC int 44 45 // Alignment is maximum alignment required by the architecture 46 // for any (compiler-generated) load or store instruction. 47 // Loads or stores smaller than Alignment must be naturally aligned. 48 // Loads or stores larger than Alignment need only be Alignment-aligned. 49 Alignment int8 50 51 // CanMergeLoads reports whether the backend optimization passes 52 // can combine adjacent loads into a single larger, possibly unaligned, load. 53 // Note that currently the optimizations must be able to handle little endian byte order. 54 CanMergeLoads bool 55 56 // CanJumpTable reports whether the backend can handle 57 // compiling a jump table. 58 CanJumpTable bool 59 60 // HasLR indicates that this architecture uses a link register 61 // for calls. 62 HasLR bool 63 64 // FixedFrameSize is the smallest possible offset from the 65 // hardware stack pointer to a local variable on the stack. 66 // Architectures that use a link register save its value on 67 // the stack in the function prologue and so always have a 68 // pointer between the hardware stack pointer and the local 69 // variable area. 70 FixedFrameSize int64 71 } 72 73 // InFamily reports whether a is a member of any of the specified 74 // architecture families. 75 func (a *Arch) InFamily(xs ...ArchFamily) bool 76 77 var Arch386 = &Arch{ 78 Name: "386", 79 Family: I386, 80 ByteOrder: binary.LittleEndian, 81 PtrSize: 4, 82 RegSize: 4, 83 MinLC: 1, 84 Alignment: 1, 85 CanMergeLoads: true, 86 HasLR: false, 87 FixedFrameSize: 0, 88 } 89 90 var ArchAMD64 = &Arch{ 91 Name: "amd64", 92 Family: AMD64, 93 ByteOrder: binary.LittleEndian, 94 PtrSize: 8, 95 RegSize: 8, 96 MinLC: 1, 97 Alignment: 1, 98 CanMergeLoads: true, 99 CanJumpTable: true, 100 HasLR: false, 101 FixedFrameSize: 0, 102 } 103 104 var ArchARM = &Arch{ 105 Name: "arm", 106 Family: ARM, 107 ByteOrder: binary.LittleEndian, 108 PtrSize: 4, 109 RegSize: 4, 110 MinLC: 4, 111 Alignment: 4, 112 CanMergeLoads: false, 113 HasLR: true, 114 FixedFrameSize: 4, 115 } 116 117 var ArchARM64 = &Arch{ 118 Name: "arm64", 119 Family: ARM64, 120 ByteOrder: binary.LittleEndian, 121 PtrSize: 8, 122 RegSize: 8, 123 MinLC: 4, 124 Alignment: 1, 125 CanMergeLoads: true, 126 CanJumpTable: true, 127 HasLR: true, 128 FixedFrameSize: 8, 129 } 130 131 var ArchLoong64 = &Arch{ 132 Name: "loong64", 133 Family: Loong64, 134 ByteOrder: binary.LittleEndian, 135 PtrSize: 8, 136 RegSize: 8, 137 MinLC: 4, 138 Alignment: 8, 139 CanMergeLoads: false, 140 HasLR: true, 141 FixedFrameSize: 8, 142 } 143 144 var ArchMIPS = &Arch{ 145 Name: "mips", 146 Family: MIPS, 147 ByteOrder: binary.BigEndian, 148 PtrSize: 4, 149 RegSize: 4, 150 MinLC: 4, 151 Alignment: 4, 152 CanMergeLoads: false, 153 HasLR: true, 154 FixedFrameSize: 4, 155 } 156 157 var ArchMIPSLE = &Arch{ 158 Name: "mipsle", 159 Family: MIPS, 160 ByteOrder: binary.LittleEndian, 161 PtrSize: 4, 162 RegSize: 4, 163 MinLC: 4, 164 Alignment: 4, 165 CanMergeLoads: false, 166 HasLR: true, 167 FixedFrameSize: 4, 168 } 169 170 var ArchMIPS64 = &Arch{ 171 Name: "mips64", 172 Family: MIPS64, 173 ByteOrder: binary.BigEndian, 174 PtrSize: 8, 175 RegSize: 8, 176 MinLC: 4, 177 Alignment: 8, 178 CanMergeLoads: false, 179 HasLR: true, 180 FixedFrameSize: 8, 181 } 182 183 var ArchMIPS64LE = &Arch{ 184 Name: "mips64le", 185 Family: MIPS64, 186 ByteOrder: binary.LittleEndian, 187 PtrSize: 8, 188 RegSize: 8, 189 MinLC: 4, 190 Alignment: 8, 191 CanMergeLoads: false, 192 HasLR: true, 193 FixedFrameSize: 8, 194 } 195 196 var ArchPPC64 = &Arch{ 197 Name: "ppc64", 198 Family: PPC64, 199 ByteOrder: binary.BigEndian, 200 PtrSize: 8, 201 RegSize: 8, 202 MinLC: 4, 203 Alignment: 1, 204 CanMergeLoads: false, 205 HasLR: true, 206 207 FixedFrameSize: 4 * 8, 208 } 209 210 var ArchPPC64LE = &Arch{ 211 Name: "ppc64le", 212 Family: PPC64, 213 ByteOrder: binary.LittleEndian, 214 PtrSize: 8, 215 RegSize: 8, 216 MinLC: 4, 217 Alignment: 1, 218 CanMergeLoads: true, 219 HasLR: true, 220 FixedFrameSize: 4 * 8, 221 } 222 223 var ArchRISCV64 = &Arch{ 224 Name: "riscv64", 225 Family: RISCV64, 226 ByteOrder: binary.LittleEndian, 227 PtrSize: 8, 228 RegSize: 8, 229 MinLC: 4, 230 Alignment: 8, 231 CanMergeLoads: false, 232 HasLR: true, 233 FixedFrameSize: 8, 234 } 235 236 var ArchS390X = &Arch{ 237 Name: "s390x", 238 Family: S390X, 239 ByteOrder: binary.BigEndian, 240 PtrSize: 8, 241 RegSize: 8, 242 MinLC: 2, 243 Alignment: 1, 244 CanMergeLoads: true, 245 HasLR: true, 246 FixedFrameSize: 8, 247 } 248 249 var ArchWasm = &Arch{ 250 Name: "wasm", 251 Family: Wasm, 252 ByteOrder: binary.LittleEndian, 253 PtrSize: 8, 254 RegSize: 8, 255 MinLC: 1, 256 Alignment: 1, 257 CanMergeLoads: false, 258 HasLR: false, 259 FixedFrameSize: 0, 260 } 261 262 var Archs = [...]*Arch{ 263 Arch386, 264 ArchAMD64, 265 ArchARM, 266 ArchARM64, 267 ArchLoong64, 268 ArchMIPS, 269 ArchMIPSLE, 270 ArchMIPS64, 271 ArchMIPS64LE, 272 ArchPPC64, 273 ArchPPC64LE, 274 ArchRISCV64, 275 ArchS390X, 276 ArchWasm, 277 }