Source file src/internal/cpu/cpu_arm64.go

     1  // Copyright 2017 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 cpu
     6  
     7  // CacheLinePadSize is used to prevent false sharing of cache lines.
     8  // We choose 128 because Apple Silicon, a.k.a. M1, has 128-byte cache line size.
     9  // It doesn't cost much and is much more future-proof.
    10  const CacheLinePadSize = 128
    11  
    12  func doinit() {
    13  	options = []option{
    14  		{Name: "aes", Feature: &ARM64.HasAES},
    15  		{Name: "pmull", Feature: &ARM64.HasPMULL},
    16  		{Name: "sha1", Feature: &ARM64.HasSHA1},
    17  		{Name: "sha2", Feature: &ARM64.HasSHA2},
    18  		{Name: "sha512", Feature: &ARM64.HasSHA512},
    19  		{Name: "crc32", Feature: &ARM64.HasCRC32},
    20  		{Name: "atomics", Feature: &ARM64.HasATOMICS},
    21  		{Name: "cpuid", Feature: &ARM64.HasCPUID},
    22  		{Name: "isNeoverse", Feature: &ARM64.IsNeoverse},
    23  	}
    24  
    25  	// arm64 uses different ways to detect CPU features at runtime depending on the operating system.
    26  	osInit()
    27  }
    28  
    29  func getisar0() uint64
    30  
    31  func getpfr0() uint64
    32  
    33  func getMIDR() uint64
    34  
    35  func extractBits(data uint64, start, end uint) uint {
    36  	return (uint)(data>>start) & ((1 << (end - start + 1)) - 1)
    37  }
    38  
    39  func parseARM64SystemRegisters(isar0, pfr0 uint64) {
    40  	// ID_AA64ISAR0_EL1
    41  	switch extractBits(isar0, 4, 7) {
    42  	case 1:
    43  		ARM64.HasAES = true
    44  	case 2:
    45  		ARM64.HasAES = true
    46  		ARM64.HasPMULL = true
    47  	}
    48  
    49  	switch extractBits(isar0, 8, 11) {
    50  	case 1:
    51  		ARM64.HasSHA1 = true
    52  	}
    53  
    54  	switch extractBits(isar0, 12, 15) {
    55  	case 1:
    56  		ARM64.HasSHA2 = true
    57  	case 2:
    58  		ARM64.HasSHA2 = true
    59  		ARM64.HasSHA512 = true
    60  	}
    61  
    62  	switch extractBits(isar0, 16, 19) {
    63  	case 1:
    64  		ARM64.HasCRC32 = true
    65  	}
    66  
    67  	switch extractBits(isar0, 20, 23) {
    68  	case 2:
    69  		ARM64.HasATOMICS = true
    70  	}
    71  
    72  	switch extractBits(pfr0, 48, 51) {
    73  	case 1:
    74  		ARM64.HasDIT = true
    75  	}
    76  }
    77  

View as plain text