| 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 "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 |
RISCV |
| 24 |
RISCV64 |
| 25 |
S390X |
| 26 |
Wasm |
| 27 |
) |
| 28 |
|
| 29 |
// Arch represents an individual architecture. |
| 30 |
type Arch struct { |
| 31 |
Name string |
| 32 |
Family ArchFamily |
| 33 |
|
| 34 |
ByteOrder binary.ByteOrder |
| 35 |
|
| 36 |
// PtrSize is the size in bytes of pointers and the |
| 37 |
// predeclared "int", "uint", and "uintptr" types. |
| 38 |
PtrSize int |
| 39 |
|
| 40 |
// RegSize is the size in bytes of general purpose registers. |
| 41 |
RegSize int |
| 42 |
|
| 43 |
// MinLC is the minimum length of an instruction code. |
| 44 |
MinLC int |
| 45 |
|
| 46 |
// Alignment is maximum alignment required by the architecture |
| 47 |
// for any (compiler-generated) load or store instruction. |
| 48 |
// Loads or stores smaller than Alignment must be naturally aligned. |
| 49 |
// Loads or stores larger than Alignment need only be Alignment-aligned. |
| 50 |
Alignment int8 |
| 51 |
|
| 52 |
// CanMergeLoads reports whether the backend optimization passes |
| 53 |
// can combine adjacent loads into a single larger, possibly unaligned, load. |
| 54 |
// Note that currently the optimizations must be able to handle little endian byte order. |
| 55 |
CanMergeLoads bool |
| 56 |
} |
| 57 |
|
| 58 |
// InFamily reports whether a is a member of any of the specified |
| 59 |
// architecture families. |
| 60 |
func (a *Arch) InFamily(xs ...ArchFamily) bool { |
| 61 |
for _, x := range xs { |
| 62 |
if a.Family == x { |
| 63 |
return true |
| 64 |
} |
| 65 |
} |
| 66 |
return false |
| 67 |
} |
| 68 |
|
| 69 |
var Arch386 = &Arch{ |
| 70 |
Name: "386", |
| 71 |
Family: I386, |
| 72 |
ByteOrder: binary.LittleEndian, |
| 73 |
PtrSize: 4, |
| 74 |
RegSize: 4, |
| 75 |
MinLC: 1, |
| 76 |
Alignment: 1, |
| 77 |
CanMergeLoads: true, |
| 78 |
} |
| 79 |
|
| 80 |
var ArchAMD64 = &Arch{ |
| 81 |
Name: "amd64", |
| 82 |
Family: AMD64, |
| 83 |
ByteOrder: binary.LittleEndian, |
| 84 |
PtrSize: 8, |
| 85 |
RegSize: 8, |
| 86 |
MinLC: 1, |
| 87 |
Alignment: 1, |
| 88 |
CanMergeLoads: true, |
| 89 |
} |
| 90 |
|
| 91 |
var ArchARM = &Arch{ |
| 92 |
Name: "arm", |
| 93 |
Family: ARM, |
| 94 |
ByteOrder: binary.LittleEndian, |
| 95 |
PtrSize: 4, |
| 96 |
RegSize: 4, |
| 97 |
MinLC: 4, |
| 98 |
Alignment: 4, // TODO: just for arm5? |
| 99 |
CanMergeLoads: false, |
| 100 |
} |
| 101 |
|
| 102 |
var ArchARM64 = &Arch{ |
| 103 |
Name: "arm64", |
| 104 |
Family: ARM64, |
| 105 |
ByteOrder: binary.LittleEndian, |
| 106 |
PtrSize: 8, |
| 107 |
RegSize: 8, |
| 108 |
MinLC: 4, |
| 109 |
Alignment: 1, |
| 110 |
CanMergeLoads: true, |
| 111 |
} |
| 112 |
|
| 113 |
var ArchLoong64 = &Arch{ |
| 114 |
Name: "loong64", |
| 115 |
Family: Loong64, |
| 116 |
ByteOrder: binary.LittleEndian, |
| 117 |
PtrSize: 8, |
| 118 |
RegSize: 8, |
| 119 |
MinLC: 4, |
| 120 |
Alignment: 8, // Unaligned accesses are not guaranteed to be fast |
| 121 |
CanMergeLoads: false, |
| 122 |
} |
| 123 |
|
| 124 |
var ArchMIPS = &Arch{ |
| 125 |
Name: "mips", |
| 126 |
Family: MIPS, |
| 127 |
ByteOrder: binary.BigEndian, |
| 128 |
PtrSize: 4, |
| 129 |
RegSize: 4, |
| 130 |
MinLC: 4, |
| 131 |
Alignment: 4, |
| 132 |
CanMergeLoads: false, |
| 133 |
} |
| 134 |
|
| 135 |
var ArchMIPSLE = &Arch{ |
| 136 |
Name: "mipsle", |
| 137 |
Family: MIPS, |
| 138 |
ByteOrder: binary.LittleEndian, |
| 139 |
PtrSize: 4, |
| 140 |
RegSize: 4, |
| 141 |
MinLC: 4, |
| 142 |
Alignment: 4, |
| 143 |
CanMergeLoads: false, |
| 144 |
} |
| 145 |
|
| 146 |
var ArchMIPS64 = &Arch{ |
| 147 |
Name: "mips64", |
| 148 |
Family: MIPS64, |
| 149 |
ByteOrder: binary.BigEndian, |
| 150 |
PtrSize: 8, |
| 151 |
RegSize: 8, |
| 152 |
MinLC: 4, |
| 153 |
Alignment: 8, |
| 154 |
CanMergeLoads: false, |
| 155 |
} |
| 156 |
|
| 157 |
var ArchMIPS64LE = &Arch{ |
| 158 |
Name: "mips64le", |
| 159 |
Family: MIPS64, |
| 160 |
ByteOrder: binary.LittleEndian, |
| 161 |
PtrSize: 8, |
| 162 |
RegSize: 8, |
| 163 |
MinLC: 4, |
| 164 |
Alignment: 8, |
| 165 |
CanMergeLoads: false, |
| 166 |
} |
| 167 |
|
| 168 |
var ArchPPC64 = &Arch{ |
| 169 |
Name: "ppc64", |
| 170 |
Family: PPC64, |
| 171 |
ByteOrder: binary.BigEndian, |
| 172 |
PtrSize: 8, |
| 173 |
RegSize: 8, |
| 174 |
MinLC: 4, |
| 175 |
Alignment: 1, |
| 176 |
CanMergeLoads: false, |
| 177 |
} |
| 178 |
|
| 179 |
var ArchPPC64LE = &Arch{ |
| 180 |
Name: "ppc64le", |
| 181 |
Family: PPC64, |
| 182 |
ByteOrder: binary.LittleEndian, |
| 183 |
PtrSize: 8, |
| 184 |
RegSize: 8, |
| 185 |
MinLC: 4, |
| 186 |
Alignment: 1, |
| 187 |
CanMergeLoads: true, |
| 188 |
} |
| 189 |
|
| 190 |
var ArchRISCV = &Arch{ |
| 191 |
Name: "riscv", |
| 192 |
Family: RISCV, |
| 193 |
ByteOrder: binary.LittleEndian, |
| 194 |
PtrSize: 4, |
| 195 |
RegSize: 4, |
| 196 |
MinLC: 4, |
| 197 |
} |
| 198 |
|
| 199 |
var ArchRISCV64 = &Arch{ |
| 200 |
Name: "riscv64", |
| 201 |
Family: RISCV64, |
| 202 |
ByteOrder: binary.LittleEndian, |
| 203 |
PtrSize: 8, |
| 204 |
RegSize: 8, |
| 205 |
MinLC: 4, |
| 206 |
Alignment: 8, // riscv unaligned loads work, but are really slow (trap + simulated by OS) |
| 207 |
CanMergeLoads: false, |
| 208 |
} |
| 209 |
|
| 210 |
var ArchS390X = &Arch{ |
| 211 |
Name: "s390x", |
| 212 |
Family: S390X, |
| 213 |
ByteOrder: binary.BigEndian, |
| 214 |
PtrSize: 8, |
| 215 |
RegSize: 8, |
| 216 |
MinLC: 2, |
| 217 |
Alignment: 1, |
| 218 |
CanMergeLoads: true, |
| 219 |
} |
| 220 |
|
| 221 |
var ArchWasm = &Arch{ |
| 222 |
Name: "wasm", |
| 223 |
Family: Wasm, |
| 224 |
ByteOrder: binary.LittleEndian, |
| 225 |
PtrSize: 8, |
| 226 |
RegSize: 8, |
| 227 |
MinLC: 1, |
| 228 |
Alignment: 1, |
| 229 |
CanMergeLoads: false, |
| 230 |
} |
| 231 |
|
| 232 |
var Archs = [...]*Arch{ |
| 233 |
Arch386, |
| 234 |
ArchAMD64, |
| 235 |
ArchARM, |
| 236 |
ArchARM64, |
| 237 |
ArchLoong64, |
| 238 |
ArchMIPS, |
| 239 |
ArchMIPSLE, |
| 240 |
ArchMIPS64, |
| 241 |
ArchMIPS64LE, |
| 242 |
ArchPPC64, |
| 243 |
ArchPPC64LE, |
| 244 |
ArchRISCV, |
| 245 |
ArchRISCV64, |
| 246 |
ArchS390X, |
| 247 |
ArchWasm, |
| 248 |
} |