github.com/corona10/go@v0.0.0-20180224231303-7a218942be57/src/hash/crc32/crc32_arm64.go (about)

     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  // ARM64-specific hardware-assisted CRC32 algorithms. See crc32.go for a
     6  // description of the interface that each architecture-specific file
     7  // implements.
     8  
     9  package crc32
    10  
    11  import "internal/cpu"
    12  
    13  func castagnoliUpdate(crc uint32, p []byte) uint32
    14  func ieeeUpdate(crc uint32, p []byte) uint32
    15  
    16  var hasCRC32 = cpu.ARM64.HasCRC32
    17  
    18  func archAvailableCastagnoli() bool {
    19  	return hasCRC32
    20  }
    21  
    22  func archInitCastagnoli() {
    23  	if !hasCRC32 {
    24  		panic("arch-specific crc32 instruction for Catagnoli not available")
    25  	}
    26  }
    27  
    28  func archUpdateCastagnoli(crc uint32, p []byte) uint32 {
    29  	if !hasCRC32 {
    30  		panic("arch-specific crc32 instruction for Castagnoli not available")
    31  	}
    32  
    33  	return ^castagnoliUpdate(^crc, p)
    34  }
    35  
    36  func archAvailableIEEE() bool {
    37  	return hasCRC32
    38  }
    39  
    40  func archInitIEEE() {
    41  	if !hasCRC32 {
    42  		panic("arch-specific crc32 instruction for IEEE not available")
    43  	}
    44  }
    45  
    46  func archUpdateIEEE(crc uint32, p []byte) uint32 {
    47  	if !hasCRC32 {
    48  		panic("arch-specific crc32 instruction for IEEE not available")
    49  	}
    50  
    51  	return ^ieeeUpdate(^crc, p)
    52  }