Source file test/codegen/simd_clmul_amd64.go

     1  // asmcheck
     2  
     3  // Copyright 2026 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  // These tests check code generation of amd64 SIMD carryless multiply.
     8  
     9  //go:build goexperiment.simd && amd64
    10  
    11  package codegen
    12  
    13  import "simd/archsimd"
    14  
    15  // The CarrylessMul methods check CPU features to choose between a single
    16  // instruction for the whole vector, the Uint64x2 instruction applied to each
    17  // 128-bit part, and software. Check that the methods are inlined, that both
    18  // instruction paths are inlined with a constant immediate, and that only the
    19  // software path is a call.
    20  
    21  func simdCarrylessMulUint64x2(x, y archsimd.Uint64x2) archsimd.Uint64x2 {
    22  	// amd64:`VPCLMULQDQ \$0, X[0-9]+, X[0-9]+, X[0-9]+` -`CALL .*\.CarrylessMul` `CALL .*\.carrylessMultiplySoft`
    23  	return x.CarrylessMulEven(y)
    24  }
    25  
    26  func simdCarrylessMulUint64x4(x, y archsimd.Uint64x4) archsimd.Uint64x4 {
    27  	// amd64:`VPCLMULQDQ \$17, Y[0-9]+, Y[0-9]+, Y[0-9]+` `VPCLMULQDQ \$17, X[0-9]+, X[0-9]+, X[0-9]+`
    28  	// amd64:`VEXTRACTI128` `VINSERTI128` -`CALL .*\.CarrylessMul` `CALL .*\.carrylessMultiplySoft`
    29  	return x.CarrylessMulOdd(y)
    30  }
    31  
    32  func simdCarrylessMulUint64x8(x, y archsimd.Uint64x8) archsimd.Uint64x8 {
    33  	// amd64:`VPCLMULQDQ \$16, Z[0-9]+, Z[0-9]+, Z[0-9]+` `VPCLMULQDQ \$16, X[0-9]+, X[0-9]+, X[0-9]+`
    34  	// amd64:`VEXTRACTI64X4` `VINSERTI64X4` -`CALL .*\.CarrylessMul` `CALL .*\.carrylessMultiplySoft`
    35  	return x.CarrylessMulEvenOdd(y)
    36  }
    37  
    38  // When the Uint64x2 instruction stands in for a wider one on a CPU with AVX-512,
    39  // it must use registers X0 through X15: with X16 through X31 it would need the
    40  // EVEX encoding, which requires the wider VPCLMULQDQ feature that's missing.
    41  //
    42  // The register allocator prefers the low registers, so this only tests
    43  // something if it runs out of them. Keep 16 other vectors live across the
    44  // multiply, and check that some of them are in the high registers.
    45  
    46  func simdCarrylessMulUint64x8VEX(p *[18]archsimd.Uint64x8) archsimd.Uint64x8 {
    47  	v0, v1, v2, v3 := p[0], p[1], p[2], p[3]
    48  	v4, v5, v6, v7 := p[4], p[5], p[6], p[7]
    49  	v8, v9, v10, v11 := p[8], p[9], p[10], p[11]
    50  	// amd64:`VMOVDQU64 .*, Z(1[6-9]|2[0-9]|3[01])`
    51  	v12, v13, v14, v15 := p[12], p[13], p[14], p[15]
    52  	// amd64:-`VPCLMULQDQ \$1, .*X(1[6-9]|2[0-9]|3[01])`
    53  	r := p[16].CarrylessMulOddEven(p[17])
    54  	return r.Xor(v0).Xor(v1).Xor(v2).Xor(v3).
    55  		Xor(v4).Xor(v5).Xor(v6).Xor(v7).
    56  		Xor(v8).Xor(v9).Xor(v10).Xor(v11).
    57  		Xor(v12).Xor(v13).Xor(v14).Xor(v15)
    58  }
    59  

View as plain text