| 1 |
package arm64 |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/segmentio/asm/cpu/cpuid" |
| 5 |
. "golang.org/x/sys/cpu" |
| 6 |
) |
| 7 |
|
| 8 |
type CPU cpuid.CPU |
| 9 |
|
| 10 |
func (cpu CPU) Has(feature Feature) bool { |
| 11 |
return cpuid.CPU(cpu).Has(cpuid.Feature(feature)) |
| 12 |
} |
| 13 |
|
| 14 |
func (cpu *CPU) set(feature Feature, enable bool) { |
| 15 |
(*cpuid.CPU)(cpu).Set(cpuid.Feature(feature), enable) |
| 16 |
} |
| 17 |
|
| 18 |
type Feature cpuid.Feature |
| 19 |
|
| 20 |
const ( |
| 21 |
FP Feature = 1 << iota // Floating-point instruction set (always available) |
| 22 |
ASIMD // Advanced SIMD (always available) |
| 23 |
EVTSTRM // Event stream support |
| 24 |
AES // AES hardware implementation |
| 25 |
PMULL // Polynomial multiplication instruction set |
| 26 |
SHA1 // SHA1 hardware implementation |
| 27 |
SHA2 // SHA2 hardware implementation |
| 28 |
CRC32 // CRC32 hardware implementation |
| 29 |
ATOMICS // Atomic memory operation instruction set |
| 30 |
FPHP // Half precision floating-point instruction set |
| 31 |
ASIMDHP // Advanced SIMD half precision instruction set |
| 32 |
CPUID // CPUID identification scheme registers |
| 33 |
ASIMDRDM // Rounding double multiply add/subtract instruction set |
| 34 |
JSCVT // Javascript conversion from floating-point to integer |
| 35 |
FCMA // Floating-point multiplication and addition of complex numbers |
| 36 |
LRCPC // Release Consistent processor consistent support |
| 37 |
DCPOP // Persistent memory support |
| 38 |
SHA3 // SHA3 hardware implementation |
| 39 |
SM3 // SM3 hardware implementation |
| 40 |
SM4 // SM4 hardware implementation |
| 41 |
ASIMDDP // Advanced SIMD double precision instruction set |
| 42 |
SHA512 // SHA512 hardware implementation |
| 43 |
SVE // Scalable Vector Extensions |
| 44 |
ASIMDFHM // Advanced SIMD multiplication FP16 to FP32 |
| 45 |
) |
| 46 |
|
| 47 |
func ABI() CPU { |
| 48 |
cpu := CPU(0) |
| 49 |
cpu.set(FP, ARM64.HasFP) |
| 50 |
cpu.set(ASIMD, ARM64.HasASIMD) |
| 51 |
cpu.set(EVTSTRM, ARM64.HasEVTSTRM) |
| 52 |
cpu.set(AES, ARM64.HasAES) |
| 53 |
cpu.set(PMULL, ARM64.HasPMULL) |
| 54 |
cpu.set(SHA1, ARM64.HasSHA1) |
| 55 |
cpu.set(SHA2, ARM64.HasSHA2) |
| 56 |
cpu.set(CRC32, ARM64.HasCRC32) |
| 57 |
cpu.set(ATOMICS, ARM64.HasATOMICS) |
| 58 |
cpu.set(FPHP, ARM64.HasFPHP) |
| 59 |
cpu.set(ASIMDHP, ARM64.HasASIMDHP) |
| 60 |
cpu.set(CPUID, ARM64.HasCPUID) |
| 61 |
cpu.set(ASIMDRDM, ARM64.HasASIMDRDM) |
| 62 |
cpu.set(JSCVT, ARM64.HasJSCVT) |
| 63 |
cpu.set(FCMA, ARM64.HasFCMA) |
| 64 |
cpu.set(LRCPC, ARM64.HasLRCPC) |
| 65 |
cpu.set(DCPOP, ARM64.HasDCPOP) |
| 66 |
cpu.set(SHA3, ARM64.HasSHA3) |
| 67 |
cpu.set(SM3, ARM64.HasSM3) |
| 68 |
cpu.set(SM4, ARM64.HasSM4) |
| 69 |
cpu.set(ASIMDDP, ARM64.HasASIMDDP) |
| 70 |
cpu.set(SHA512, ARM64.HasSHA512) |
| 71 |
cpu.set(SVE, ARM64.HasSVE) |
| 72 |
cpu.set(ASIMDFHM, ARM64.HasASIMDFHM) |
| 73 |
return cpu |
| 74 |
} |