Source file src/simd/archsimd/shuffles_emulated_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  // This file contains constant permutation index tables for the emulated
    10  // shuffles in shuffles_gen_amd64.go, which tmplgen generates.
    11  //
    12  // The 128- and 256-bit emulations also reuse gatherLo64, gatherLo64Idx,
    13  // trunc16To8Idx, trunc32To16Idx, trunc16To8GroupedIdx, and
    14  // trunc32To16GroupedIdx from converts_emulated_amd64.go.
    15  
    16  // 512-bit InterleaveLo and InterleaveHi index vectors for ConcatLookupMod.
    17  var (
    18  	interleaveLo64x8Idx = [8]uint64{0, 8, 1, 9, 2, 10, 3, 11}
    19  	interleaveHi64x8Idx = [8]uint64{4, 12, 5, 13, 6, 14, 7, 15}
    20  
    21  	interleaveLo32x16Idx = [16]uint32{
    22  		0, 16, 1, 17, 2, 18, 3, 19,
    23  		4, 20, 5, 21, 6, 22, 7, 23,
    24  	}
    25  	interleaveHi32x16Idx = [16]uint32{
    26  		8, 24, 9, 25, 10, 26, 11, 27,
    27  		12, 28, 13, 29, 14, 30, 15, 31,
    28  	}
    29  
    30  	interleaveLo16x32Idx = [32]uint16{
    31  		0, 32, 1, 33, 2, 34, 3, 35, 4, 36, 5, 37, 6, 38, 7, 39,
    32  		8, 40, 9, 41, 10, 42, 11, 43, 12, 44, 13, 45, 14, 46, 15, 47,
    33  	}
    34  	interleaveHi16x32Idx = [32]uint16{
    35  		16, 48, 17, 49, 18, 50, 19, 51, 20, 52, 21, 53, 22, 54, 23, 55,
    36  		24, 56, 25, 57, 26, 58, 27, 59, 28, 60, 29, 61, 30, 62, 31, 63,
    37  	}
    38  
    39  	interleaveLo8x64Idx = [64]uint8{
    40  		0, 64, 1, 65, 2, 66, 3, 67, 4, 68, 5, 69, 6, 70, 7, 71,
    41  		8, 72, 9, 73, 10, 74, 11, 75, 12, 76, 13, 77, 14, 78, 15, 79,
    42  		16, 80, 17, 81, 18, 82, 19, 83, 20, 84, 21, 85, 22, 86, 23, 87,
    43  		24, 88, 25, 89, 26, 90, 27, 91, 28, 92, 29, 93, 30, 94, 31, 95,
    44  	}
    45  	interleaveHi8x64Idx = [64]uint8{
    46  		32, 96, 33, 97, 34, 98, 35, 99, 36, 100, 37, 101, 38, 102, 39, 103,
    47  		40, 104, 41, 105, 42, 106, 43, 107, 44, 108, 45, 109, 46, 110, 47, 111,
    48  		48, 112, 49, 113, 50, 114, 51, 115, 52, 116, 53, 117, 54, 118, 55, 119,
    49  		56, 120, 57, 121, 58, 122, 59, 123, 60, 124, 61, 125, 62, 126, 63, 127,
    50  	}
    51  
    52  	// 128-bit lane interleaving of two 512-bit vectors via Uint64x8.ConcatLookupMod,
    53  	// used for baseline AVX-512 (non-VBMI) 8-bit InterleaveLo and InterleaveHi.
    54  	interleaveLo128x4Idx = [8]uint64{0, 1, 8, 9, 2, 3, 10, 11}
    55  	interleaveHi128x4Idx = [8]uint64{4, 5, 12, 13, 6, 7, 14, 15}
    56  )
    57  
    58  // ConcatEven and ConcatOdd index vectors for ConcatLookupMod and LookupModOrZeroGrouped.
    59  var (
    60  	concatEven16x16Idx = [16]uint16{
    61  		0, 2, 4, 6, 8, 10, 12, 14,
    62  		16, 18, 20, 22, 24, 26, 28, 30,
    63  	}
    64  	concatOdd16x16Idx = [16]uint16{
    65  		1, 3, 5, 7, 9, 11, 13, 15,
    66  		17, 19, 21, 23, 25, 27, 29, 31,
    67  	}
    68  
    69  	concatEven8x32Idx = [32]uint8{
    70  		0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
    71  		32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62,
    72  	}
    73  	concatOdd8x32Idx = [32]uint8{
    74  		1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31,
    75  		33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63,
    76  	}
    77  
    78  	concatEven64x8Idx = [8]uint64{0, 2, 4, 6, 8, 10, 12, 14}
    79  	concatOdd64x8Idx  = [8]uint64{1, 3, 5, 7, 9, 11, 13, 15}
    80  
    81  	concatEven32x16Idx = [16]uint32{
    82  		0, 2, 4, 6, 8, 10, 12, 14,
    83  		16, 18, 20, 22, 24, 26, 28, 30,
    84  	}
    85  	concatOdd32x16Idx = [16]uint32{
    86  		1, 3, 5, 7, 9, 11, 13, 15,
    87  		17, 19, 21, 23, 25, 27, 29, 31,
    88  	}
    89  
    90  	concatEven16x32Idx = [32]uint16{
    91  		0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
    92  		32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62,
    93  	}
    94  	concatOdd16x32Idx = [32]uint16{
    95  		1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31,
    96  		33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63,
    97  	}
    98  
    99  	concatEven8x64Idx = [64]uint8{
   100  		0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
   101  		32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62,
   102  		64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94,
   103  		96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126,
   104  	}
   105  	concatOdd8x64Idx = [64]uint8{
   106  		1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31,
   107  		33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63,
   108  		65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95,
   109  		97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127,
   110  	}
   111  
   112  	// Per-128-bit-lane byte selectors packing even/odd bytes into the low 64 bits
   113  	// of each lane, used for baseline AVX-512 (non-VBMI) 8-bit ConcatEven and ConcatOdd.
   114  	concatEven8x64GroupedIdx = [64]int8{
   115  		0, 2, 4, 6, 8, 10, 12, 14, -1, -1, -1, -1, -1, -1, -1, -1,
   116  		0, 2, 4, 6, 8, 10, 12, 14, -1, -1, -1, -1, -1, -1, -1, -1,
   117  		0, 2, 4, 6, 8, 10, 12, 14, -1, -1, -1, -1, -1, -1, -1, -1,
   118  		0, 2, 4, 6, 8, 10, 12, 14, -1, -1, -1, -1, -1, -1, -1, -1,
   119  	}
   120  	concatOdd8x64GroupedIdx = [64]int8{
   121  		1, 3, 5, 7, 9, 11, 13, 15, -1, -1, -1, -1, -1, -1, -1, -1,
   122  		1, 3, 5, 7, 9, 11, 13, 15, -1, -1, -1, -1, -1, -1, -1, -1,
   123  		1, 3, 5, 7, 9, 11, 13, 15, -1, -1, -1, -1, -1, -1, -1, -1,
   124  		1, 3, 5, 7, 9, 11, 13, 15, -1, -1, -1, -1, -1, -1, -1, -1,
   125  	}
   126  )
   127  

View as plain text