Source file src/simd/archsimd/clmul_arm64.go

     1  // Copyright 2026 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  //go:build goexperiment.simd
     6  
     7  package archsimd
     8  
     9  // CarrylessMultiplyEven computes the carryless
    10  // multiplications of selected even halves of the elements of x and y.
    11  //
    12  // A carryless multiplication uses bitwise XOR instead of
    13  // add-with-carry, for example (in base two):
    14  //
    15  //	11 * 11 = 11 * (10 ^ 1) = (11 * 10) ^ (11 * 1) = 110 ^ 11 = 101
    16  //
    17  // This also models multiplication of polynomials with coefficients
    18  // from GF(2) -- 11 * 11 models (x+1)*(x+1) = x**2 + (1^1)x + 1 =
    19  // x**2 + 0x + 1 = x**2 + 1 modeled by 101.  (Note that "+" adds
    20  // polynomial terms, but coefficients "add" with XOR.)
    21  //
    22  // Asm: PMULL, CPU Feature: PMULL
    23  func (x Uint64x2) CarrylessMultiplyEven(y Uint64x2) Uint64x2 {
    24  	return x.carrylessMultiplyWidenLo(y)
    25  }
    26  
    27  // CarrylessMultiplyOdd computes the carryless
    28  // multiplications of selected odd halves of the elements of x and y.
    29  //
    30  // A carryless multiplication uses bitwise XOR instead of
    31  // add-with-carry, for example (in base two):
    32  //
    33  //	11 * 11 = 11 * (10 ^ 1) = (11 * 10) ^ (11 * 1) = 110 ^ 11 = 101
    34  //
    35  // This also models multiplication of polynomials with coefficients
    36  // from GF(2) -- 11 * 11 models (x+1)*(x+1) = x**2 + (1^1)x + 1 =
    37  // x**2 + 0x + 1 = x**2 + 1 modeled by 101.  (Note that "+" adds
    38  // polynomial terms, but coefficients "add" with XOR.)
    39  //
    40  // Asm: PMULL, CPU Feature: PMULL
    41  func (x Uint64x2) CarrylessMultiplyOdd(y Uint64x2) Uint64x2 {
    42  	return x.HiToLo().carrylessMultiplyWidenLo(y.HiToLo())
    43  }
    44  
    45  // CarrylessMultiplyOddEven computes the carryless
    46  // multiplications of selected odd half of x's elements and even half of y's elements.
    47  //
    48  // A carryless multiplication uses bitwise XOR instead of
    49  // add-with-carry, for example (in base two):
    50  //
    51  //	11 * 11 = 11 * (10 ^ 1) = (11 * 10) ^ (11 * 1) = 110 ^ 11 = 101
    52  //
    53  // This also models multiplication of polynomials with coefficients
    54  // from GF(2) -- 11 * 11 models (x+1)*(x+1) = x**2 + (1^1)x + 1 =
    55  // x**2 + 0x + 1 = x**2 + 1 modeled by 101.  (Note that "+" adds
    56  // polynomial terms, but coefficients "add" with XOR.)
    57  //
    58  // Asm: PMULL, CPU Feature: PMULL
    59  func (x Uint64x2) CarrylessMultiplyOddEven(y Uint64x2) Uint64x2 {
    60  	return x.HiToLo().carrylessMultiplyWidenLo(y)
    61  }
    62  
    63  // CarrylessMultiplyEvenOdd computes the carryless
    64  // multiplications of selected even half of x's elements and odd half of y's elements.
    65  //
    66  // A carryless multiplication uses bitwise XOR instead of
    67  // add-with-carry, for example (in base two):
    68  //
    69  //	11 * 11 = 11 * (10 ^ 1) = (11 * 10) ^ (11 * 1) = 110 ^ 11 = 101
    70  //
    71  // This also models multiplication of polynomials with coefficients
    72  // from GF(2) -- 11 * 11 models (x+1)*(x+1) = x**2 + (1^1)x + 1 =
    73  // x**2 + 0x + 1 = x**2 + 1 modeled by 101.  (Note that "+" adds
    74  // polynomial terms, but coefficients "add" with XOR.)
    75  //
    76  // Asm: PMULL, CPU Feature: PMULL
    77  func (x Uint64x2) CarrylessMultiplyEvenOdd(y Uint64x2) Uint64x2 {
    78  	return x.carrylessMultiplyWidenLo(y.HiToLo())
    79  }
    80  

View as plain text