pax_global_header00006660000000000000000000000064147661436270014532gustar00rootroot0000000000000052 comment=31a9ef61bc6d2a2493442c1c993490697cee7a46 golang-github-minio-crc64nvme-1.0.1/000077500000000000000000000000001476614362700171765ustar00rootroot00000000000000golang-github-minio-crc64nvme-1.0.1/LICENSE000066400000000000000000000261361476614362700202130ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. golang-github-minio-crc64nvme-1.0.1/README.md000066400000000000000000000017641476614362700204650ustar00rootroot00000000000000 ## crc64nvme This Golang package calculates CRC64 checksums using carryless-multiplication accelerated with SIMD instructions for both ARM and x86. It is based on the NVME polynomial as specified in the [NVM Express® NVM Command Set Specification](https://nvmexpress.org/wp-content/uploads/NVM-Express-NVM-Command-Set-Specification-1.0d-2023.12.28-Ratified.pdf). The code is based on the [crc64fast-nvme](https://github.com/awesomized/crc64fast-nvme.git) package in Rust and is released under the Apache 2.0 license. For more background on the exact technique used, see this [Fast CRC Computation for Generic Polynomials Using PCLMULQDQ Instruction](https://web.archive.org/web/20131224125630/https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/fast-crc-computation-generic-polynomials-pclmulqdq-paper.pdf) paper. ### Performance To follow. ### Requirements All Go versions >= 1.22 are supported. ### Contributing Contributions are welcome, please send PRs for any enhancements. golang-github-minio-crc64nvme-1.0.1/crc64.go000066400000000000000000000105021476614362700204440ustar00rootroot00000000000000// Copyright (c) 2025 Minio Inc. All rights reserved. // Use of this source code is governed by a license that can be // found in the LICENSE file. // Package crc64nvme implements the 64-bit cyclic redundancy check with NVME polynomial. package crc64nvme import ( "encoding/binary" "errors" "hash" "sync" "unsafe" ) const ( // The size of a CRC-64 checksum in bytes. Size = 8 // The NVME polynoimial (reversed, as used by Go) NVME = 0x9a6c9329ac4bc9b5 ) var ( // precalculated table. nvmeTable = makeTable(NVME) ) // table is a 256-word table representing the polynomial for efficient processing. type table [256]uint64 var ( slicing8TablesBuildOnce sync.Once slicing8TableNVME *[8]table ) func buildSlicing8TablesOnce() { slicing8TablesBuildOnce.Do(buildSlicing8Tables) } func buildSlicing8Tables() { slicing8TableNVME = makeSlicingBy8Table(makeTable(NVME)) } func makeTable(poly uint64) *table { t := new(table) for i := 0; i < 256; i++ { crc := uint64(i) for j := 0; j < 8; j++ { if crc&1 == 1 { crc = (crc >> 1) ^ poly } else { crc >>= 1 } } t[i] = crc } return t } func makeSlicingBy8Table(t *table) *[8]table { var helperTable [8]table helperTable[0] = *t for i := 0; i < 256; i++ { crc := t[i] for j := 1; j < 8; j++ { crc = t[crc&0xff] ^ (crc >> 8) helperTable[j][i] = crc } } return &helperTable } // digest represents the partial evaluation of a checksum. type digest struct { crc uint64 } // New creates a new hash.Hash64 computing the CRC-64 checksum using the // NVME polynomial. Its Sum method will lay the // value out in big-endian byte order. The returned Hash64 also // implements [encoding.BinaryMarshaler] and [encoding.BinaryUnmarshaler] to // marshal and unmarshal the internal state of the hash. func New() hash.Hash64 { return &digest{0} } func (d *digest) Size() int { return Size } func (d *digest) BlockSize() int { return 1 } func (d *digest) Reset() { d.crc = 0 } const ( magic = "crc\x02" marshaledSize = len(magic) + 8 + 8 ) func (d *digest) MarshalBinary() ([]byte, error) { b := make([]byte, 0, marshaledSize) b = append(b, magic...) b = binary.BigEndian.AppendUint64(b, tableSum) b = binary.BigEndian.AppendUint64(b, d.crc) return b, nil } func (d *digest) UnmarshalBinary(b []byte) error { if len(b) < len(magic) || string(b[:len(magic)]) != magic { return errors.New("hash/crc64: invalid hash state identifier") } if len(b) != marshaledSize { return errors.New("hash/crc64: invalid hash state size") } if tableSum != binary.BigEndian.Uint64(b[4:]) { return errors.New("hash/crc64: tables do not match") } d.crc = binary.BigEndian.Uint64(b[12:]) return nil } func update(crc uint64, p []byte) uint64 { if hasAsm && len(p) > 127 { ptr := unsafe.Pointer(&p[0]) if align := (uintptr(ptr)+15)&^0xf - uintptr(ptr); align > 0 { // Align to 16-byte boundary. crc = update(crc, p[:align]) p = p[align:] } runs := len(p) / 128 crc = updateAsm(crc, p[:128*runs]) return update(crc, p[128*runs:]) } buildSlicing8TablesOnce() crc = ^crc // table comparison is somewhat expensive, so avoid it for small sizes for len(p) >= 64 { var helperTable = slicing8TableNVME // Update using slicing-by-8 for len(p) > 8 { crc ^= binary.LittleEndian.Uint64(p) crc = helperTable[7][crc&0xff] ^ helperTable[6][(crc>>8)&0xff] ^ helperTable[5][(crc>>16)&0xff] ^ helperTable[4][(crc>>24)&0xff] ^ helperTable[3][(crc>>32)&0xff] ^ helperTable[2][(crc>>40)&0xff] ^ helperTable[1][(crc>>48)&0xff] ^ helperTable[0][crc>>56] p = p[8:] } } // For reminders or small sizes for _, v := range p { crc = nvmeTable[byte(crc)^v] ^ (crc >> 8) } return ^crc } // Update returns the result of adding the bytes in p to the crc. func Update(crc uint64, p []byte) uint64 { return update(crc, p) } func (d *digest) Write(p []byte) (n int, err error) { d.crc = update(d.crc, p) return len(p), nil } func (d *digest) Sum64() uint64 { return d.crc } func (d *digest) Sum(in []byte) []byte { s := d.Sum64() return append(in, byte(s>>56), byte(s>>48), byte(s>>40), byte(s>>32), byte(s>>24), byte(s>>16), byte(s>>8), byte(s)) } // Checksum returns the CRC-64 checksum of data // using the NVME polynomial. func Checksum(data []byte) uint64 { return update(0, data) } // ISO tablesum of NVME poly const tableSum = 0x8ddd9ee4402c7163 golang-github-minio-crc64nvme-1.0.1/crc64_amd64.go000066400000000000000000000005751476614362700214500ustar00rootroot00000000000000// Copyright (c) 2025 Minio Inc. All rights reserved. // Use of this source code is governed by a license that can be // found in the LICENSE file. //go:build !noasm && !appengine && !gccgo package crc64nvme import ( "github.com/klauspost/cpuid/v2" ) var hasAsm = cpuid.CPU.Supports(cpuid.SSE2, cpuid.CLMUL, cpuid.SSE4) func updateAsm(crc uint64, p []byte) (checksum uint64) golang-github-minio-crc64nvme-1.0.1/crc64_amd64.s000066400000000000000000000067261476614362700213110ustar00rootroot00000000000000// Copyright (c) 2025 Minio Inc. All rights reserved. // Use of this source code is governed by a license that can be // found in the LICENSE file. //go:build !noasm && !appengine && !gccgo #include "textflag.h" TEXT ·updateAsm(SB), $0-40 MOVQ crc+0(FP), AX // checksum MOVQ p_base+8(FP), SI // start pointer MOVQ p_len+16(FP), CX // length of buffer NOTQ AX SHRQ $7, CX CMPQ CX, $1 JLT skip128 VMOVDQA 0x00(SI), X0 VMOVDQA 0x10(SI), X1 VMOVDQA 0x20(SI), X2 VMOVDQA 0x30(SI), X3 VMOVDQA 0x40(SI), X4 VMOVDQA 0x50(SI), X5 VMOVDQA 0x60(SI), X6 VMOVDQA 0x70(SI), X7 MOVQ AX, X8 PXOR X8, X0 CMPQ CX, $1 JE tail128 MOVQ $0xa1ca681e733f9c40, AX MOVQ AX, X8 MOVQ $0x5f852fb61e8d92dc, AX PINSRQ $0x1, AX, X9 loop128: ADDQ $128, SI SUBQ $1, CX VMOVDQA X0, X10 PCLMULQDQ $0x00, X8, X10 PCLMULQDQ $0x11, X9, X0 PXOR X10, X0 PXOR 0(SI), X0 VMOVDQA X1, X10 PCLMULQDQ $0x00, X8, X10 PCLMULQDQ $0x11, X9, X1 PXOR X10, X1 PXOR 0x10(SI), X1 VMOVDQA X2, X10 PCLMULQDQ $0x00, X8, X10 PCLMULQDQ $0x11, X9, X2 PXOR X10, X2 PXOR 0x20(SI), X2 VMOVDQA X3, X10 PCLMULQDQ $0x00, X8, X10 PCLMULQDQ $0x11, X9, X3 PXOR X10, X3 PXOR 0x30(SI), X3 VMOVDQA X4, X10 PCLMULQDQ $0x00, X8, X10 PCLMULQDQ $0x11, X9, X4 PXOR X10, X4 PXOR 0x40(SI), X4 VMOVDQA X5, X10 PCLMULQDQ $0x00, X8, X10 PCLMULQDQ $0x11, X9, X5 PXOR X10, X5 PXOR 0x50(SI), X5 VMOVDQA X6, X10 PCLMULQDQ $0x00, X8, X10 PCLMULQDQ $0x11, X9, X6 PXOR X10, X6 PXOR 0x60(SI), X6 VMOVDQA X7, X10 PCLMULQDQ $0x00, X8, X10 PCLMULQDQ $0x11, X9, X7 PXOR X10, X7 PXOR 0x70(SI), X7 CMPQ CX, $1 JGT loop128 tail128: MOVQ $0xd083dd594d96319d, AX MOVQ AX, X11 PCLMULQDQ $0x00, X0, X11 MOVQ $0x946588403d4adcbc, AX PINSRQ $0x1, AX, X12 PCLMULQDQ $0x11, X12, X0 PXOR X11, X7 PXOR X0, X7 MOVQ $0x3c255f5ebc414423, AX MOVQ AX, X11 PCLMULQDQ $0x00, X1, X11 MOVQ $0x34f5a24e22d66e90, AX PINSRQ $0x1, AX, X12 PCLMULQDQ $0x11, X12, X1 PXOR X11, X1 PXOR X7, X1 MOVQ $0x7b0ab10dd0f809fe, AX MOVQ AX, X11 PCLMULQDQ $0x00, X2, X11 MOVQ $0x03363823e6e791e5, AX PINSRQ $0x1, AX, X12 PCLMULQDQ $0x11, X12, X2 PXOR X11, X2 PXOR X1, X2 MOVQ $0x0c32cdb31e18a84a, AX MOVQ AX, X11 PCLMULQDQ $0x00, X3, X11 MOVQ $0x62242240ace5045a, AX PINSRQ $0x1, AX, X12 PCLMULQDQ $0x11, X12, X3 PXOR X11, X3 PXOR X2, X3 MOVQ $0xbdd7ac0ee1a4a0f0, AX MOVQ AX, X11 PCLMULQDQ $0x00, X4, X11 MOVQ $0xa3ffdc1fe8e82a8b, AX PINSRQ $0x1, AX, X12 PCLMULQDQ $0x11, X12, X4 PXOR X11, X4 PXOR X3, X4 MOVQ $0xb0bc2e589204f500, AX MOVQ AX, X11 PCLMULQDQ $0x00, X5, X11 MOVQ $0xe1e0bb9d45d7a44c, AX PINSRQ $0x1, AX, X12 PCLMULQDQ $0x11, X12, X5 PXOR X11, X5 PXOR X4, X5 MOVQ $0xeadc41fd2ba3d420, AX MOVQ AX, X11 PCLMULQDQ $0x00, X6, X11 MOVQ $0x21e9761e252621ac, AX PINSRQ $0x1, AX, X12 PCLMULQDQ $0x11, X12, X6 PXOR X11, X6 PXOR X5, X6 MOVQ AX, X5 PCLMULQDQ $0x00, X6, X5 PSHUFD $0xee, X6, X6 PXOR X5, X6 MOVQ $0x27ecfa329aef9f77, AX MOVQ AX, X4 PCLMULQDQ $0x00, X4, X6 PEXTRQ $0, X6, BX MOVQ $0x34d926535897936b, AX MOVQ AX, X4 PCLMULQDQ $0x00, X4, X6 PXOR X5, X6 PEXTRQ $1, X6, AX XORQ BX, AX skip128: NOTQ AX MOVQ AX, checksum+32(FP) RET golang-github-minio-crc64nvme-1.0.1/crc64_arm64.go000066400000000000000000000006101476614362700214540ustar00rootroot00000000000000// Copyright (c) 2025 Minio Inc. All rights reserved. // Use of this source code is governed by a license that can be // found in the LICENSE file. //go:build !noasm && !appengine && !gccgo package crc64nvme import ( "github.com/klauspost/cpuid/v2" ) var hasAsm = cpuid.CPU.Supports(cpuid.ASIMD) && cpuid.CPU.Supports(cpuid.PMULL) func updateAsm(crc uint64, p []byte) (checksum uint64) golang-github-minio-crc64nvme-1.0.1/crc64_arm64.s000066400000000000000000000104611476614362700213160ustar00rootroot00000000000000// Copyright (c) 2025 Minio Inc. All rights reserved. // Use of this source code is governed by a license that can be // found in the LICENSE file. //go:build !noasm && !appengine && !gccgo #include "textflag.h" TEXT ·updateAsm(SB), $0-40 MOVD crc+0(FP), R0 // checksum MOVD p_base+8(FP), R1 // start pointer MOVD p_len+16(FP), R2 // length of buffer MOVD $·const(SB), R3 // constants MVN R0, R0 LSR $7, R2, R2 CMP $1, R2 BLT skip128 FLDPQ (R1), (F0, F1) FLDPQ 32(R1), (F2, F3) FLDPQ 64(R1), (F4, F5) FLDPQ 96(R1), (F6, F7) FMOVD R0, F8 VMOVI $0, V9.B16 VMOV V9.D[0], V8.D[1] VEOR V8.B16, V0.B16, V0.B16 CMP $1, R2 BEQ tail128 MOVD 112(R3), R4 MOVD 120(R3), R5 FMOVD R4, F8 VDUP R5, V9.D2 loop128: ADD $128, R1, R1 SUB $1, R2, R2 VPMULL V0.D1, V8.D1, V10.Q1 VPMULL2 V0.D2, V9.D2, V0.Q1 FLDPQ (R1), (F11, F12) VEOR3 V0.B16, V11.B16, V10.B16, V0.B16 VPMULL V1.D1, V8.D1, V10.Q1 VPMULL2 V1.D2, V9.D2, V1.Q1 VEOR3 V1.B16, V12.B16, V10.B16, V1.B16 VPMULL V2.D1, V8.D1, V10.Q1 VPMULL2 V2.D2, V9.D2, V2.Q1 FLDPQ 32(R1), (F11, F12) VEOR3 V2.B16, V11.B16, V10.B16, V2.B16 VPMULL V3.D1, V8.D1, V10.Q1 VPMULL2 V3.D2, V9.D2, V3.Q1 VEOR3 V3.B16, V12.B16, V10.B16, V3.B16 VPMULL V4.D1, V8.D1, V10.Q1 VPMULL2 V4.D2, V9.D2, V4.Q1 FLDPQ 64(R1), (F11, F12) VEOR3 V4.B16, V11.B16, V10.B16, V4.B16 VPMULL V5.D1, V8.D1, V10.Q1 VPMULL2 V5.D2, V9.D2, V5.Q1 VEOR3 V5.B16, V12.B16, V10.B16, V5.B16 VPMULL V6.D1, V8.D1, V10.Q1 VPMULL2 V6.D2, V9.D2, V6.Q1 FLDPQ 96(R1), (F11, F12) VEOR3 V6.B16, V11.B16, V10.B16, V6.B16 VPMULL V7.D1, V8.D1, V10.Q1 VPMULL2 V7.D2, V9.D2, V7.Q1 VEOR3 V7.B16, V12.B16, V10.B16, V7.B16 CMP $1, R2 BHI loop128 tail128: MOVD (R3), R4 FMOVD R4, F11 VPMULL V0.D1, V11.D1, V11.Q1 MOVD 8(R3), R4 VDUP R4, V12.D2 VPMULL2 V0.D2, V12.D2, V0.Q1 VEOR3 V0.B16, V7.B16, V11.B16, V7.B16 MOVD 16(R3), R4 FMOVD R4, F11 VPMULL V1.D1, V11.D1, V11.Q1 MOVD 24(R3), R4 VDUP R4, V12.D2 VPMULL2 V1.D2, V12.D2, V1.Q1 VEOR3 V1.B16, V11.B16, V7.B16, V1.B16 MOVD 32(R3), R4 FMOVD R4, F11 VPMULL V2.D1, V11.D1, V11.Q1 MOVD 40(R3), R4 VDUP R4, V12.D2 VPMULL2 V2.D2, V12.D2, V2.Q1 VEOR3 V2.B16, V11.B16, V1.B16, V2.B16 MOVD 48(R3), R4 FMOVD R4, F11 VPMULL V3.D1, V11.D1, V11.Q1 MOVD 56(R3), R4 VDUP R4, V12.D2 VPMULL2 V3.D2, V12.D2, V3.Q1 VEOR3 V3.B16, V11.B16, V2.B16, V3.B16 MOVD 64(R3), R4 FMOVD R4, F11 VPMULL V4.D1, V11.D1, V11.Q1 MOVD 72(R3), R4 VDUP R4, V12.D2 VPMULL2 V4.D2, V12.D2, V4.Q1 VEOR3 V4.B16, V11.B16, V3.B16, V4.B16 MOVD 80(R3), R4 FMOVD R4, F11 VPMULL V5.D1, V11.D1, V11.Q1 MOVD 88(R3), R4 VDUP R4, V12.D2 VPMULL2 V5.D2, V12.D2, V5.Q1 VEOR3 V5.B16, V11.B16, V4.B16, V5.B16 MOVD 96(R3), R4 FMOVD R4, F11 VPMULL V6.D1, V11.D1, V11.Q1 MOVD 104(R3), R4 VDUP R4, V12.D2 VPMULL2 V6.D2, V12.D2, V6.Q1 VEOR3 V6.B16, V11.B16, V5.B16, V6.B16 FMOVD R4, F5 VPMULL V6.D1, V5.D1, V5.Q1 VDUP V6.D[1], V6.D2 VEOR V5.B8, V6.B8, V6.B8 MOVD 128(R3), R4 FMOVD R4, F4 VPMULL V4.D1, V6.D1, V6.Q1 FMOVD F6, R4 MOVD 136(R3), R5 FMOVD R5, F4 VPMULL V4.D1, V6.D1, V6.Q1 VEOR V6.B16, V5.B16, V6.B16 VMOV V6.D[1], R5 EOR R4, R5, R0 skip128: MVN R0, R0 MOVD R0, checksum+32(FP) RET DATA ·const+0x000(SB)/8, $0xd083dd594d96319d // K_959 DATA ·const+0x008(SB)/8, $0x946588403d4adcbc // K_895 DATA ·const+0x010(SB)/8, $0x3c255f5ebc414423 // K_831 DATA ·const+0x018(SB)/8, $0x34f5a24e22d66e90 // K_767 DATA ·const+0x020(SB)/8, $0x7b0ab10dd0f809fe // K_703 DATA ·const+0x028(SB)/8, $0x03363823e6e791e5 // K_639 DATA ·const+0x030(SB)/8, $0x0c32cdb31e18a84a // K_575 DATA ·const+0x038(SB)/8, $0x62242240ace5045a // K_511 DATA ·const+0x040(SB)/8, $0xbdd7ac0ee1a4a0f0 // K_447 DATA ·const+0x048(SB)/8, $0xa3ffdc1fe8e82a8b // K_383 DATA ·const+0x050(SB)/8, $0xb0bc2e589204f500 // K_319 DATA ·const+0x058(SB)/8, $0xe1e0bb9d45d7a44c // K_255 DATA ·const+0x060(SB)/8, $0xeadc41fd2ba3d420 // K_191 DATA ·const+0x068(SB)/8, $0x21e9761e252621ac // K_127 DATA ·const+0x070(SB)/8, $0xa1ca681e733f9c40 // K_1087 DATA ·const+0x078(SB)/8, $0x5f852fb61e8d92dc // K_1023 DATA ·const+0x080(SB)/8, $0x27ecfa329aef9f77 // MU DATA ·const+0x088(SB)/8, $0x34d926535897936b // POLY GLOBL ·const(SB), (NOPTR+RODATA), $144 golang-github-minio-crc64nvme-1.0.1/crc64_other.go000066400000000000000000000005651476614362700216550ustar00rootroot00000000000000// Copyright (c) 2025 Minio Inc. All rights reserved. // Use of this source code is governed by a license that can be // found in the LICENSE file. //go:build (!amd64 || noasm || appengine || gccgo) && (!arm64 || noasm || appengine || gccgo) package crc64nvme var hasAsm = false func updateAsm(crc uint64, p []byte) (checksum uint64) { panic("should not be reached") } golang-github-minio-crc64nvme-1.0.1/crc64_test.go000066400000000000000000000101211476614362700215000ustar00rootroot00000000000000// Copyright (c) 2025 Minio Inc. All rights reserved. // Use of this source code is governed by a license that can be // found in the LICENSE file. package crc64nvme import ( "bytes" "fmt" "hash" "hash/crc64" "io" "math/rand" "runtime" "sync/atomic" "testing" ) var crc64Table = crc64.MakeTable(NVME) func TestChecksum(t *testing.T) { if hasAsm { testChecksum(t, "asm-") hasAsm = false testChecksum(t, "") hasAsm = true } else { testChecksum(t, "") } } func testChecksum(t *testing.T, asm string) { sizes := []int{0, 1, 3, 7, 8, 9, 15, 17, 127, 128, 129, 255, 256, 257, 1e3, 1e4, 1e5, 1e6} for _, size := range sizes { t.Run(fmt.Sprintf("%ssize=%d", asm, size), func(t *testing.T) { rng := rand.New(rand.NewSource(int64(size))) data := make([]byte, size) rng.Read(data) ref := crc64.Checksum(data, crc64Table) got := Checksum(data) if got != ref { t.Errorf("got 0x%x, want 0x%x", got, ref) } }) } } func TestHasher(t *testing.T) { if hasAsm { testHasher(t, "asm-") hasAsm = false testHasher(t, "") hasAsm = true } else { testHasher(t, "") } } func testHasher(t *testing.T, asm string) { sizes := []int{0, 1, 3, 7, 8, 9, 15, 17, 127, 128, 129, 255, 256, 257, 383, 384, 385, 1e3, 1e4, 1e5, 1e6} for _, size := range sizes { t.Run(fmt.Sprintf("%ssize=%d", asm, size), func(t *testing.T) { rng := rand.New(rand.NewSource(int64(size))) data := make([]byte, size) rng.Read(data) ref := crc64.Checksum(data, crc64Table) h := New() io.CopyBuffer(h, bytes.NewReader(data), make([]byte, 17)) got := h.Sum64() if got != ref { t.Errorf("got 0x%x, want 0x%x", got, ref) } }) } } func TestLoopAlignment(t *testing.T) { for l := 128; l <= 128*10; l++ { dataBlock := make([]byte, l) for i := range dataBlock { dataBlock[i] = byte(i + 1) } // make sure we don't start on an aligned boundary offset := rand.Intn(16) data := dataBlock[offset:] ref := crc64.Checksum(data, crc64Table) got := update(0, data) if got != ref { t.Errorf("got 0x%x, want 0x%x", got, ref) } } } func BenchmarkCrc64(b *testing.B) { b.Run("64MB", func(b *testing.B) { bench(b, New(), 64<<20) }) b.Run("stdlib-64MB", func(b *testing.B) { bench(b, crc64.New(crc64Table), 64<<20) }) b.Run("4MB", func(b *testing.B) { bench(b, New(), 4<<20) }) b.Run("stdlib-4MB", func(b *testing.B) { bench(b, crc64.New(crc64Table), 4<<20) }) b.Run("1MB", func(b *testing.B) { bench(b, New(), 1<<20) }) b.Run("stdlib-1MB", func(b *testing.B) { bench(b, crc64.New(crc64Table), 1<<20) }) b.Run("64KB", func(b *testing.B) { bench(b, New(), 64<<10) }) b.Run("stdlib-64KB", func(b *testing.B) { bench(b, crc64.New(crc64Table), 64<<10) }) b.Run("4KB", func(b *testing.B) { bench(b, New(), 4<<10) }) b.Run("stdlib-4KB", func(b *testing.B) { bench(b, crc64.New(crc64Table), 4<<10) }) b.Run("1KB", func(b *testing.B) { bench(b, New(), 1<<10) }) b.Run("stdlib-1KB", func(b *testing.B) { bench(b, crc64.New(crc64Table), 1<<10) }) } func bench(b *testing.B, h hash.Hash64, size int64) { b.SetBytes(size) data := make([]byte, size) for i := range data { data[i] = byte(i) } in := make([]byte, 0, h.Size()) b.ResetTimer() for i := 0; i < b.N; i++ { h.Reset() h.Write(data) h.Sum(in) } } func benchmarkParallel(b *testing.B, size int) { hashes := make([]hash.Hash64, runtime.GOMAXPROCS(0)) for i := range hashes { hashes[i] = New() } rng := rand.New(rand.NewSource(0xabadc0cac01a)) data := make([][]byte, runtime.GOMAXPROCS(0)) for i := range data { data[i] = make([]byte, size) rng.Read(data[i]) } b.SetBytes(int64(size)) b.ResetTimer() counter := uint64(0) b.RunParallel(func(pb *testing.PB) { for pb.Next() { index := atomic.AddUint64(&counter, 1) index = index % uint64(len(data)) hashes[index].Reset() hashes[index].Write(data[index]) in := make([]byte, 0, hashes[index].Size()) hashes[index].Sum(in) } }) } func BenchmarkParallel(b *testing.B) { // go test -cpu=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 -bench=Parallel b.Run("50M", func(b *testing.B) { benchmarkParallel(b, 50*1024*1024) }) } golang-github-minio-crc64nvme-1.0.1/go.mod000066400000000000000000000002071476614362700203030ustar00rootroot00000000000000module github.com/minio/crc64nvme go 1.22 require github.com/klauspost/cpuid/v2 v2.2.9 require golang.org/x/sys v0.28.0 // indirect golang-github-minio-crc64nvme-1.0.1/go.sum000066400000000000000000000005121476614362700203270ustar00rootroot00000000000000github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY= github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8= golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=