Source file src/simd/archsimd/consts_amd64.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.simdstable && amd64 6 7 package archsimd 8 9 // These constants represent the source pattern for the four parameters 10 // (a, b, c, d) passed to ConcatPermuteScalars and ConcatPermuteScalarsGrouped. 11 // L means the element comes from the 'x' vector (Low), and 12 // H means it comes from the 'y' vector (High). 13 // The order of the letters corresponds to elements a, b, c, d. 14 // The underlying integer value is a bitmask where: 15 // Bit 0: Source of element 'a' (0 for x, 1 for y) 16 // Bit 1: Source of element 'b' (0 for x, 1 for y) 17 // Bit 2: Source of element 'c' (0 for x, 1 for y) 18 // Bit 3: Source of element 'd' (0 for x, 1 for y) 19 // Note that the least-significant bit is on the LEFT in this encoding. 20 const ( 21 _LLLL = iota // a:x, b:x, c:x, d:x 22 _HLLL // a:y, b:x, c:x, d:x 23 _LHLL // a:x, b:y, c:x, d:x 24 _HHLL // a:y, b:y, c:x, d:x 25 _LLHL // a:x, b:x, c:y, d:x 26 _HLHL // a:y, b:x, c:y, d:x 27 _LHHL // a:x, b:y, c:y, d:x 28 _HHHL // a:y, b:y, c:y, d:x 29 _LLLH // a:x, b:x, c:x, d:y 30 _HLLH // a:y, b:x, c:x, d:y 31 _LHLH // a:x, b:y, c:x, d:y 32 _HHLH // a:y, b:y, c:x, d:y 33 _LLHH // a:x, b:x, c:y, d:y 34 _HLHH // a:y, b:x, c:y, d:y 35 _LHHH // a:x, b:y, c:y, d:y 36 _HHHH // a:y, b:y, c:y, d:y 37 ) 38 39 // cscimm4 converts the 4 vector element indices into a single 40 // uint8 for use as an immediate. 41 func cscimm4(a, b, c, d uint8) uint8 { 42 return uint8(a + b<<2 + c<<4 + d<<6) 43 } 44 45 // These constants represent the source pattern for the two parameters 46 // (a, b) passed to ConcatPermuteScalars and ConcatPermuteScalarsGrouped for 47 // two-element vectors. 48 const ( 49 _LL = iota 50 _HL 51 _LH 52 _HH 53 ) 54 55 // cscimm2 converts the 2 vector element indices into a single 56 // uint8 for use as an immediate. 57 func cscimm2(a, b uint8) uint8 { 58 return uint8(a + b<<1) 59 } 60 61 // cscimm2g2 converts the 2 vector element indices into a single 62 // uint8 for use as an immediate, but duplicated for VSHUFPD 63 // to emulate grouped behavior of VSHUFPS. 64 func cscimm2g2(a, b uint8) uint8 { 65 g := cscimm2(a, b) 66 return g + g<<2 67 } 68 69 // cscimm2g4 converts the 2 vector element indices into a single 70 // uint8 for use as an immediate, but with four copies for VSHUFPD 71 // to emulate grouped behavior of VSHUFPS. 72 func cscimm2g4(a, b uint8) uint8 { 73 g := cscimm2g2(a, b) 74 return g + g<<4 75 } 76