The Gaudi Framework  master (adcf1ca6)
Loading...
Searching...
No Matches
instrset.h File Reference
#include <stdint.h>
#include <stdlib.h>
Include dependency graph for instrset.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Const_int_t< n >
 
class  Const_uint_t< n >
 
struct  EList< T, N >
 

Macros

#define ALLOW_FP_PERMUTE   true
 
#define INSTRSET   0
 
#define const_int(n)
 
#define const_uint(n)
 

Functions

int instrset_detect (void)
 
bool hasFMA3 (void)
 
bool hasFMA4 (void)
 
bool hasXOP (void)
 
bool hasAVX512ER (void)
 
bool hasAVX512VBMI (void)
 
bool hasAVX512VBMI2 (void)
 
int physicalProcessors (int *logical_processors=0)
 
constexpr int bit_scan_reverse_const (uint64_t const n)
 
template<typename V>
constexpr auto get_inttype ()
 
template<int N>
constexpr auto zero_mask (int const (&a)[N])
 
template<typename V>
constexpr auto zero_mask_broad (int const (&A)[V::size()])
 
template<int N, int B>
constexpr uint64_t make_bit_mask (int const (&a)[N])
 
template<typename V>
constexpr auto make_broad_mask (uint64_t const m)
 
template<typename V>
constexpr auto perm_mask_broad (int const (&A)[V::size()])
 
template<typename V>
constexpr uint64_t perm_flags (int const (&a)[V::size()])
 
template<int N>
constexpr uint64_t compress_mask (int const (&a)[N])
 
template<int N>
constexpr uint64_t expand_mask (int const (&a)[N])
 
template<typename V>
constexpr uint64_t perm16_flags (int const (&a)[V::size()])
 
template<typename V, int oppos = 0>
constexpr auto pshufb_mask (int const (&A)[V::size()])
 
template<int N>
constexpr EList< int, N/2 > largeblock_perm (int const (&a)[N])
 
template<typename V>
constexpr uint64_t blend_flags (int const (&a)[V::size()])
 
template<int N, int dozero>
constexpr EList< int, 2 *N > blend_perm_indexes (int const (&a)[N])
 
template<int N>
constexpr EList< int, N/2 > largeblock_indexes (int const (&a)[N])
 
template<typename dummy>
void blend2 ()
 
template<typename dummy>
void blend4 ()
 
template<typename dummy>
void blend8 ()
 
template<typename dummy>
void blend16 ()
 
template<typename dummy>
void blend32 ()
 
template<int N, int dozero, int src1, int src2>
constexpr EList< int, N > blend_half_indexes (int const (&a)[N])
 
template<typename W, int... i0>
auto blend_half (W const &a, W const &b)
 

Variables

constexpr int V_DC = -256
 
const int perm_zeroing = 1
 
const int perm_perm = 2
 
const int perm_allzero = 4
 
const int perm_largeblock = 8
 
const int perm_addz = 0x10
 
const int perm_addz2 = 0x20
 
const int perm_cross_lane = 0x40
 
const int perm_same_pattern = 0x80
 
const int perm_punpckh = 0x100
 
const int perm_punpckl = 0x200
 
const int perm_rotate
 
const int perm_shright
 
const int perm_shleft
 
const int perm_rotate_big
 
const int perm_broadcast = 0x8000
 
const int perm_zext = 0x10000
 
const int perm_compress = 0x20000
 
const int perm_expand = 0x40000
 
const int perm_outofrange = 0x10000000
 
const int perm_rot_count = 32
 
const int perm_ipattern
 
const int blend_zeroing = 1
 
const int blend_allzero = 2
 
const int blend_largeblock = 4
 
const int blend_addz = 8
 
const int blend_a = 0x10
 
const int blend_b = 0x20
 
const int blend_perma = 0x40
 
const int blend_permb = 0x80
 
const int blend_cross_lane = 0x100
 
const int blend_same_pattern = 0x200
 
const int blend_punpckhab = 0x1000
 
const int blend_punpckhba = 0x2000
 
const int blend_punpcklab = 0x4000
 
const int blend_punpcklba = 0x8000
 
const int blend_rotateab = 0x10000
 
const int blend_rotateba = 0x20000
 
const int blend_shufab = 0x40000
 
const int blend_shufba = 0x80000
 
const int blend_rotate_big = 0x100000
 
const int blend_outofrange = 0x10000000
 
const int blend_shufpattern = 32
 
const int blend_rotpattern = 40
 

Macro Definition Documentation

◆ ALLOW_FP_PERMUTE

#define ALLOW_FP_PERMUTE   true

Definition at line 28 of file instrset.h.

◆ const_int

#define const_int ( n)
Value:

Definition at line 406 of file instrset.h.

◆ const_uint

#define const_uint ( n)
Value:

Definition at line 407 of file instrset.h.

◆ INSTRSET

#define INSTRSET   0

Definition at line 76 of file instrset.h.

Function Documentation

◆ bit_scan_reverse_const()

int bit_scan_reverse_const ( uint64_t const n)
constexpr

Definition at line 381 of file instrset.h.

381 {
382 if ( n == 0 ) return -1;
383 uint64_t a = n, b = 0, j = 64, k = 0;
384 do {
385 j >>= 1;
386 k = (uint64_t)1 << j;
387 if ( a >= k ) {
388 a >>= j;
389 b += j;
390 }
391 } while ( j > 0 );
392 return int( b );
393 }

◆ blend16()

template<typename dummy>
void blend16 ( )

Definition at line 1298 of file instrset.h.

1298{}

◆ blend2()

template<typename dummy>
void blend2 ( )

Definition at line 1292 of file instrset.h.

1292{}

◆ blend32()

template<typename dummy>
void blend32 ( )

Definition at line 1300 of file instrset.h.

1300{}

◆ blend4()

template<typename dummy>
void blend4 ( )

Definition at line 1294 of file instrset.h.

1294{}

◆ blend8()

template<typename dummy>
void blend8 ( )

Definition at line 1296 of file instrset.h.

1296{}

◆ blend_flags()

template<typename V>
uint64_t blend_flags ( int const (&) a[V::size()])
constexpr

Definition at line 1037 of file instrset.h.

1037 {
1038 // a is a reference to a constexpr array of permutation indexes
1039 // V is a vector class
1040 constexpr int N = V::size(); // number of elements
1041 uint64_t r = blend_largeblock | blend_same_pattern | blend_allzero; // return value
1042 uint32_t iu = 0; // loop counter
1043 int32_t ii = 0; // loop counter
1044 int ix = 0; // index number i
1045 const uint32_t nlanes = sizeof( V ) / 16; // number of 128-bit lanes
1046 const uint32_t lanesize = N / nlanes; // elements per lane
1047 uint32_t lane = 0; // current lane
1048 uint32_t rot = 999; // rotate left count
1049 int lanepattern[lanesize] = { 0 }; // pattern in each lane
1050 if ( lanesize == 2 && N <= 8 ) {
1051 r |= blend_shufab | blend_shufba; // check if it fits shufpd
1052 }
1053
1054 for ( ii = 0; ii < N; ii++ ) { // loop through indexes
1055 ix = a[ii]; // index
1056 if ( ix < 0 ) {
1057 if ( ix == -1 )
1058 r |= blend_zeroing; // set to zero
1059 else if ( ix != V_DC ) {
1060 r = blend_outofrange;
1061 break; // illegal index
1062 }
1063 } else { // ix >= 0
1064 r &= ~blend_allzero;
1065 if ( ix < N ) {
1066 r |= blend_a; // data from a
1067 if ( ix != ii ) r |= blend_perma; // permutation of a
1068 } else if ( ix < 2 * N ) {
1069 r |= blend_b; // data from b
1070 if ( ix != ii + N ) r |= blend_permb; // permutation of b
1071 } else {
1072 r = blend_outofrange;
1073 break; // illegal index
1074 }
1075 }
1076 // check if pattern fits a larger block size:
1077 // even indexes must be even, odd indexes must fit the preceding even index + 1
1078 if ( ( ii & 1 ) == 0 ) { // even index
1079 if ( ix >= 0 && ( ix & 1 ) ) r &= ~blend_largeblock; // not even. does not fit larger block size
1080 int iy = a[ii + 1]; // next odd index
1081 if ( iy >= 0 && ( iy & 1 ) == 0 ) r &= ~blend_largeblock; // not odd. does not fit larger block size
1082 if ( ix >= 0 && iy >= 0 && iy != ix + 1 ) r &= ~blend_largeblock; // does not fit preceding index + 1
1083 if ( ix == -1 && iy >= 0 ) r |= blend_addz; // needs additional zeroing at current block size
1084 if ( iy == -1 && ix >= 0 ) r |= blend_addz; // needs additional zeroing at current block size
1085 }
1086 lane = (uint32_t)ii / lanesize; // current lane
1087 if ( lane == 0 ) { // first lane, or no pattern yet
1088 lanepattern[ii] = ix; // save pattern
1089 }
1090 // check if crossing lanes
1091 if ( ix >= 0 ) {
1092 uint32_t lanei = uint32_t( ix & ~N ) / lanesize; // source lane
1093 if ( lanei != lane ) {
1094 r |= blend_cross_lane; // crossing lane
1095 }
1096 if ( lanesize == 2 ) { // check if it fits pshufd
1097 if ( lanei != lane ) r &= ~( blend_shufab | blend_shufba );
1098 if ( ( ( ( ix & N ) != 0 ) ^ ii ) & 1 )
1099 r &= ~blend_shufab;
1100 else
1101 r &= ~blend_shufba;
1102 }
1103 }
1104 // check if same pattern in all lanes
1105 if ( lane != 0 && ix >= 0 ) { // not first lane
1106 int j = ii - int( lane * lanesize ); // index into lanepattern
1107 int jx = ix - int( lane * lanesize ); // pattern within lane
1108 if ( jx < 0 || ( jx & ~N ) >= (int)lanesize ) r &= ~blend_same_pattern; // source is in another lane
1109 if ( lanepattern[j] < 0 ) {
1110 lanepattern[j] = jx; // pattern not known from previous lane
1111 } else {
1112 if ( lanepattern[j] != jx ) r &= ~blend_same_pattern; // not same pattern
1113 }
1114 }
1115 }
1116 if ( !( r & blend_largeblock ) ) r &= ~blend_addz; // remove irrelevant flag
1117 if ( r & blend_cross_lane ) r &= ~blend_same_pattern; // remove irrelevant flag
1118 if ( !( r & ( blend_perma | blend_permb ) ) ) {
1119 return r; // no permutation. more checks are superfluous
1120 }
1121 if ( r & blend_same_pattern ) {
1122 // same pattern in all lanes. check if it fits unpack patterns
1124 for ( iu = 0; iu < lanesize; iu++ ) { // loop through lanepattern
1125 ix = lanepattern[iu];
1126 if ( ix >= 0 ) {
1127 if ( (uint32_t)ix != iu / 2 + ( iu & 1 ) * N ) r &= ~blend_punpcklab;
1128 if ( (uint32_t)ix != iu / 2 + ( ( iu & 1 ) ^ 1 ) * N ) r &= ~blend_punpcklba;
1129 if ( (uint32_t)ix != ( iu + lanesize ) / 2 + ( iu & 1 ) * N ) r &= ~blend_punpckhab;
1130 if ( (uint32_t)ix != ( iu + lanesize ) / 2 + ( ( iu & 1 ) ^ 1 ) * N ) r &= ~blend_punpckhba;
1131 }
1132 }
1133#if INSTRSET >= 4 // SSSE3. check if it fits palignr
1134 for ( iu = 0; iu < lanesize; iu++ ) {
1135 ix = lanepattern[iu];
1136 if ( ix >= 0 ) {
1137 uint32_t t = ix & ~N;
1138 if ( ix & N ) t += lanesize;
1139 uint32_t tb = ( t + 2 * lanesize - iu ) % ( lanesize * 2 );
1140 if ( rot == 999 ) {
1141 rot = tb;
1142 } else { // check if fit
1143 if ( rot != tb ) rot = 1000;
1144 }
1145 }
1146 }
1147 if ( rot < 999 ) { // firs palignr
1148 if ( rot < lanesize ) {
1149 r |= blend_rotateba;
1150 } else {
1151 r |= blend_rotateab;
1152 }
1153 const uint32_t elementsize = sizeof( V ) / N;
1154 r |= uint64_t( ( rot & ( lanesize - 1 ) ) * elementsize ) << blend_rotpattern;
1155 }
1156#endif
1157 if ( lanesize == 4 ) {
1158 // check if it fits shufps
1160 for ( ii = 0; ii < 2; ii++ ) {
1161 ix = lanepattern[ii];
1162 if ( ix >= 0 ) {
1163 if ( ix & N )
1164 r &= ~blend_shufab;
1165 else
1166 r &= ~blend_shufba;
1167 }
1168 }
1169 for ( ; ii < 4; ii++ ) {
1170 ix = lanepattern[ii];
1171 if ( ix >= 0 ) {
1172 if ( ix & N )
1173 r &= ~blend_shufba;
1174 else
1175 r &= ~blend_shufab;
1176 }
1177 }
1178 if ( r & ( blend_shufab | blend_shufba ) ) { // fits shufps/shufpd
1179 uint8_t shufpattern = 0; // get pattern
1180 for ( iu = 0; iu < lanesize; iu++ ) { shufpattern |= ( lanepattern[iu] & 3 ) << iu * 2; }
1181 r |= (uint64_t)shufpattern << blend_shufpattern; // return pattern
1182 }
1183 }
1184 } else if ( nlanes > 1 ) { // not same pattern in all lanes
1185 rot = 999; // check if it fits big rotate
1186 for ( ii = 0; ii < N; ii++ ) {
1187 ix = a[ii];
1188 if ( ix >= 0 ) {
1189 uint32_t rot2 = ( ix + 2 * N - ii ) % ( 2 * N ); // rotate count
1190 if ( rot == 999 ) {
1191 rot = rot2; // save rotate count
1192 } else if ( rot != rot2 ) {
1193 rot = 1000;
1194 break; // does not fit big rotate
1195 }
1196 }
1197 }
1198 if ( rot < 2 * N ) { // fits big rotate
1199 r |= blend_rotate_big | (uint64_t)rot << blend_rotpattern;
1200 }
1201 }
1202 if ( lanesize == 2 && ( r & ( blend_shufab | blend_shufba ) ) ) { // fits shufpd. Get pattern
1203 for ( ii = 0; ii < N; ii++ ) { r |= uint64_t( a[ii] & 1 ) << ( blend_shufpattern + ii ); }
1204 }
1205 return r;
1206 }
const int blend_rotpattern
Definition instrset.h:1034
const int blend_permb
Definition instrset.h:1020
const int blend_punpckhba
Definition instrset.h:1024
const int blend_shufpattern
Definition instrset.h:1033
const int blend_rotateab
Definition instrset.h:1027
const int blend_cross_lane
Definition instrset.h:1021
const int blend_rotateba
Definition instrset.h:1028
const int blend_largeblock
Definition instrset.h:1015
const int blend_a
Definition instrset.h:1017
const int blend_addz
Definition instrset.h:1016
const int blend_shufba
Definition instrset.h:1030
const int blend_rotate_big
Definition instrset.h:1031
const int blend_perma
Definition instrset.h:1019
const int blend_outofrange
Definition instrset.h:1032
const int blend_same_pattern
Definition instrset.h:1022
const int blend_punpcklab
Definition instrset.h:1025
const int blend_allzero
Definition instrset.h:1014
const int blend_punpckhab
Definition instrset.h:1023
const int blend_zeroing
Definition instrset.h:1013
constexpr int V_DC
Definition instrset.h:219
const int blend_punpcklba
Definition instrset.h:1026
const int blend_shufab
Definition instrset.h:1029
const int blend_b
Definition instrset.h:1018
int N
Definition IOTest.py:112

◆ blend_half()

template<typename W, int... i0>
auto blend_half ( W const & a,
W const & b )

Definition at line 1353 of file instrset.h.

1353 {
1354 typedef decltype( a.get_low() ) V; // type for half-size vector
1355 constexpr int N = V::size(); // size of half-size vector
1356 static_assert( sizeof...( i0 ) == N, "wrong number of indexes in blend_half" );
1357 constexpr int ind[N] = { i0... }; // array of indexes
1358
1359 // lambda to find which of the four possible sources are used
1360 // return: EList<int, 5> containing a list of up to 4 sources. The last element is the number of sources used
1361 auto listsources = []( int const n, int const( &ind )[N] ) constexpr {
1362 bool source_used[4] = { false, false, false, false }; // list of sources used
1363 int i = 0;
1364 for ( i = 0; i < n; i++ ) {
1365 int ix = ind[i]; // index
1366 if ( ix >= 0 ) {
1367 int src = ix / n; // source used
1368 source_used[src & 3] = true;
1369 }
1370 }
1371 // return a list of sources used. The last element is the number of sources used
1372 EList<int, 5> sources = { { 0 } };
1373 int nsrc = 0; // number of sources
1374 for ( i = 0; i < 4; i++ ) {
1375 if ( source_used[i] ) { sources.a[nsrc++] = i; }
1376 }
1377 sources.a[4] = nsrc;
1378 return sources;
1379 };
1380 // list of sources used
1381 constexpr EList<int, 5> sources = listsources( N, ind );
1382 constexpr int nsrc = sources.a[4]; // number of sources used
1383
1384 if constexpr ( nsrc == 0 ) { // no sources
1385 return V( 0 );
1386 }
1387 // get indexes for the first one or two sources
1388 constexpr int uindex = ( nsrc > 2 ) ? 1 : 2; // unused elements set to zero if two blends are combined
1389 constexpr EList<int, N> L = blend_half_indexes<N, uindex, sources.a[0], sources.a[1]>( ind );
1390 V x0;
1391 V src0 = selectblend<W, sources.a[0]>( a, b ); // first source
1392 V src1 = selectblend<W, sources.a[1]>( a, b ); // second source
1393 if constexpr ( N == 2 ) {
1394 x0 = blend2<L.a[0], L.a[1]>( src0, src1 );
1395 } else if constexpr ( N == 4 ) {
1396 x0 = blend4<L.a[0], L.a[1], L.a[2], L.a[3]>( src0, src1 );
1397 } else if constexpr ( N == 8 ) {
1398 x0 = blend8<L.a[0], L.a[1], L.a[2], L.a[3], L.a[4], L.a[5], L.a[6], L.a[7]>( src0, src1 );
1399 } else if constexpr ( N == 16 ) {
1400 x0 = blend16<L.a[0], L.a[1], L.a[2], L.a[3], L.a[4], L.a[5], L.a[6], L.a[7], L.a[8], L.a[9], L.a[10], L.a[11],
1401 L.a[12], L.a[13], L.a[14], L.a[15]>( src0, src1 );
1402 } else if constexpr ( N == 32 ) {
1403 x0 = blend32<L.a[0], L.a[1], L.a[2], L.a[3], L.a[4], L.a[5], L.a[6], L.a[7], L.a[8], L.a[9], L.a[10], L.a[11],
1404 L.a[12], L.a[13], L.a[14], L.a[15], L.a[16], L.a[17], L.a[18], L.a[19], L.a[20], L.a[21], L.a[22],
1405 L.a[23], L.a[24], L.a[25], L.a[26], L.a[27], L.a[28], L.a[29], L.a[30], L.a[31]>( src0, src1 );
1406 }
1407 if constexpr ( nsrc > 2 ) { // get last one or two sources
1408 constexpr EList<int, N> M = blend_half_indexes<N, 1, sources.a[2], sources.a[3]>( ind );
1409 V x1;
1410 V src2 = selectblend<W, sources.a[2]>( a, b ); // third source
1411 V src3 = selectblend<W, sources.a[3]>( a, b ); // fourth source
1412 if constexpr ( N == 2 ) {
1413 x1 = blend2<M.a[0], M.a[1]>( src0, src1 );
1414 } else if constexpr ( N == 4 ) {
1415 x1 = blend4<M.a[0], M.a[1], M.a[2], M.a[3]>( src2, src3 );
1416 } else if constexpr ( N == 8 ) {
1417 x1 = blend8<M.a[0], M.a[1], M.a[2], M.a[3], M.a[4], M.a[5], M.a[6], M.a[7]>( src2, src3 );
1418 } else if constexpr ( N == 16 ) {
1419 x1 = blend16<M.a[0], M.a[1], M.a[2], M.a[3], M.a[4], M.a[5], M.a[6], M.a[7], M.a[8], M.a[9], M.a[10], M.a[11],
1420 M.a[12], M.a[13], M.a[14], M.a[15]>( src2, src3 );
1421 } else if constexpr ( N == 32 ) {
1422 x1 = blend32<M.a[0], M.a[1], M.a[2], M.a[3], M.a[4], M.a[5], M.a[6], M.a[7], M.a[8], M.a[9], M.a[10], M.a[11],
1423 M.a[12], M.a[13], M.a[14], M.a[15], M.a[16], M.a[17], M.a[18], M.a[19], M.a[20], M.a[21], M.a[22],
1424 M.a[23], M.a[24], M.a[25], M.a[26], M.a[27], M.a[28], M.a[29], M.a[30], M.a[31]>( src2, src3 );
1425 }
1426 x0 |= x1; // combine result of two blends. Unused elements are zero
1427 }
1428 return x0;
1429 }
void blend8()
Definition instrset.h:1296
void blend2()
Definition instrset.h:1292
void blend32()
Definition instrset.h:1300
void blend16()
Definition instrset.h:1298
void blend4()
Definition instrset.h:1294
constexpr EList< int, N > blend_half_indexes(int const (&a)[N])
Definition instrset.h:1309
constexpr double L
T a[N]
Definition instrset.h:463

◆ blend_half_indexes()

template<int N, int dozero, int src1, int src2>
EList< int, N > blend_half_indexes ( int const (&) a[N])
constexpr

Definition at line 1309 of file instrset.h.

1309 {
1310 // a is a reference to a constexpr array of permutation indexes
1311 EList<int, N> list = { { 0 } }; // list to return
1312 int u = dozero ? -1 : V_DC; // value to use for unused entries
1313 int j = 0; // loop counter
1314
1315 for ( j = 0; j < N; j++ ) { // loop through indexes
1316 int ix = a[j]; // current index
1317 if ( ix < 0 ) { // zero or don't care
1318 list.a[j] = ( dozero == 2 ) ? ix : u;
1319 } else {
1320 int src = ix / N; // source
1321 if ( src == src1 ) {
1322 list.a[j] = ix & ( N - 1 );
1323 } else if ( src == src2 ) {
1324 list.a[j] = ( ix & ( N - 1 ) ) + N;
1325 } else
1326 list.a[j] = u;
1327 }
1328 }
1329 return list;
1330 }

◆ blend_perm_indexes()

template<int N, int dozero>
EList< int, 2 *N > blend_perm_indexes ( int const (&) a[N])
constexpr

Definition at line 1214 of file instrset.h.

1214 {
1215 // a is a reference to a constexpr array of permutation indexes
1216 EList<int, 2 * N> list = { { 0 } }; // list to return
1217 int u = dozero ? -1 : V_DC; // value to use for unused entries
1218 int j = 0;
1219
1220 for ( j = 0; j < N; j++ ) { // loop through indexes
1221 int ix = a[j]; // current index
1222 if ( ix < 0 ) { // zero or don't care
1223 if ( dozero == 2 ) {
1224 // list.a[j] = list.a[j + N] = ix; // fails in gcc in complicated cases
1225 list.a[j] = ix;
1226 list.a[j + N] = ix;
1227 } else {
1228 // list.a[j] = list.a[j + N] = u;
1229 list.a[j] = u;
1230 list.a[j + N] = u;
1231 }
1232 } else if ( ix < N ) { // value from a
1233 list.a[j] = ix;
1234 list.a[j + N] = u;
1235 } else {
1236 list.a[j] = u; // value from b
1237 list.a[j + N] = ix - N;
1238 }
1239 }
1240 return list;
1241 }

◆ compress_mask()

template<int N>
uint64_t compress_mask ( int const (&) a[N])
constexpr

Definition at line 824 of file instrset.h.

824 {
825 // a is a reference to a constexpr array of permutation indexes
826 int ix = 0, lasti = -1, lastp = -1;
827 uint64_t m = 0;
828 int i = 0;
829 int j = 1; // loop counters
830 for ( i = 0; i < N; i++ ) {
831 ix = a[i]; // permutation index
832 if ( ix >= 0 ) {
833 m |= (uint64_t)1 << ix; // mask for compression source
834 for ( j = 1; j < i - lastp; j++ ) {
835 m |= (uint64_t)1 << ( lasti + j ); // dummy filling source
836 }
837 lastp = i;
838 lasti = ix;
839 }
840 }
841 return m;
842 }
constexpr double m

◆ expand_mask()

template<int N>
uint64_t expand_mask ( int const (&) a[N])
constexpr

Definition at line 848 of file instrset.h.

848 {
849 // a is a reference to a constexpr array of permutation indexes
850 int ix = 0, lasti = -1, lastp = -1;
851 uint64_t m = 0;
852 int i = 0;
853 int j = 1;
854 for ( i = 0; i < N; i++ ) {
855 ix = a[i]; // permutation index
856 if ( ix >= 0 ) {
857 m |= (uint64_t)1 << i; // mask for expansion destination
858 for ( j = 1; j < ix - lasti; j++ ) {
859 m |= (uint64_t)1 << ( lastp + j ); // dummy filling destination
860 }
861 lastp = i;
862 lasti = ix;
863 }
864 }
865 return m;
866 }

◆ get_inttype()

template<typename V>
auto get_inttype ( )
constexpr

Definition at line 469 of file instrset.h.

469 {
470 constexpr int elementsize = sizeof( V ) / V::size(); // size of vector elements
471
472 if constexpr ( elementsize >= 8 ) {
473 return -int64_t( 1 );
474 } else if constexpr ( elementsize >= 4 ) {
475 return int32_t( -1 );
476 } else if constexpr ( elementsize >= 2 ) {
477 return int16_t( -1 );
478 } else {
479 return int8_t( -1 );
480 }
481 }

◆ hasAVX512ER()

bool hasAVX512ER ( void )

Definition at line 142 of file instrset_detect.cpp.

142 {
143 if ( instrset_detect() < 9 ) return false; // must have AVX512F
144 int abcd[4]; // cpuid results
145 cpuid( abcd, 7 ); // call cpuid function 7
146 return ( ( abcd[1] & ( 1 << 27 ) ) != 0 ); // ebx bit 27 indicates AVX512ER
147 }
int instrset_detect(void)

◆ hasAVX512VBMI()

bool hasAVX512VBMI ( void )

Definition at line 150 of file instrset_detect.cpp.

150 {
151 if ( instrset_detect() < 10 ) return false; // must have AVX512BW
152 int abcd[4]; // cpuid results
153 cpuid( abcd, 7 ); // call cpuid function 7
154 return ( ( abcd[2] & ( 1 << 1 ) ) != 0 ); // ecx bit 1 indicates AVX512VBMI
155 }

◆ hasAVX512VBMI2()

bool hasAVX512VBMI2 ( void )

Definition at line 158 of file instrset_detect.cpp.

158 {
159 if ( instrset_detect() < 10 ) return false; // must have AVX512BW
160 int abcd[4]; // cpuid results
161 cpuid( abcd, 7 ); // call cpuid function 7
162 return ( ( abcd[2] & ( 1 << 6 ) ) != 0 ); // ecx bit 6 indicates AVX512VBMI2
163 }

◆ hasFMA3()

bool hasFMA3 ( void )

Definition at line 110 of file instrset_detect.cpp.

110 {
111 if ( instrset_detect() < 7 ) return false; // must have AVX
112 int abcd[4]; // cpuid results
113 cpuid( abcd, 1 ); // call cpuid function 1
114 return ( ( abcd[2] & ( 1 << 12 ) ) != 0 ); // ecx bit 12 indicates FMA3
115 }

◆ hasFMA4()

bool hasFMA4 ( void )

Definition at line 118 of file instrset_detect.cpp.

118 {
119 if ( instrset_detect() < 7 ) return false; // must have AVX
120 int abcd[4]; // cpuid results
121 cpuid( abcd, 0x80000001 ); // call cpuid function 0x80000001
122 return ( ( abcd[2] & ( 1 << 16 ) ) != 0 ); // ecx bit 16 indicates FMA4
123 }

◆ hasXOP()

bool hasXOP ( void )

Definition at line 126 of file instrset_detect.cpp.

126 {
127 if ( instrset_detect() < 7 ) return false; // must have AVX
128 int abcd[4]; // cpuid results
129 cpuid( abcd, 0x80000001 ); // call cpuid function 0x80000001
130 return ( ( abcd[2] & ( 1 << 11 ) ) != 0 ); // ecx bit 11 indicates XOP
131 }

◆ instrset_detect()

int instrset_detect ( void )

Definition at line 63 of file instrset_detect.cpp.

63 {
64
65 static int iset = -1; // remember value for next call
66 if ( iset >= 0 ) {
67 return iset; // called before
68 }
69 iset = 0; // default value
70 int abcd[4] = { 0, 0, 0, 0 }; // cpuid results
71 cpuid( abcd, 0 ); // call cpuid function 0
72 if ( abcd[0] == 0 ) return iset; // no further cpuid function supported
73 cpuid( abcd, 1 ); // call cpuid function 1 for feature flags
74 if ( ( abcd[3] & ( 1 << 0 ) ) == 0 ) return iset; // no floating point
75 if ( ( abcd[3] & ( 1 << 23 ) ) == 0 ) return iset; // no MMX
76 if ( ( abcd[3] & ( 1 << 15 ) ) == 0 ) return iset; // no conditional move
77 if ( ( abcd[3] & ( 1 << 24 ) ) == 0 ) return iset; // no FXSAVE
78 if ( ( abcd[3] & ( 1 << 25 ) ) == 0 ) return iset; // no SSE
79 iset = 1; // 1: SSE supported
80 if ( ( abcd[3] & ( 1 << 26 ) ) == 0 ) return iset; // no SSE2
81 iset = 2; // 2: SSE2 supported
82 if ( ( abcd[2] & ( 1 << 0 ) ) == 0 ) return iset; // no SSE3
83 iset = 3; // 3: SSE3 supported
84 if ( ( abcd[2] & ( 1 << 9 ) ) == 0 ) return iset; // no SSSE3
85 iset = 4; // 4: SSSE3 supported
86 if ( ( abcd[2] & ( 1 << 19 ) ) == 0 ) return iset; // no SSE4.1
87 iset = 5; // 5: SSE4.1 supported
88 if ( ( abcd[2] & ( 1 << 23 ) ) == 0 ) return iset; // no POPCNT
89 if ( ( abcd[2] & ( 1 << 20 ) ) == 0 ) return iset; // no SSE4.2
90 iset = 6; // 6: SSE4.2 supported
91 if ( ( abcd[2] & ( 1 << 27 ) ) == 0 ) return iset; // no OSXSAVE
92 if ( ( xgetbv( 0 ) & 6 ) != 6 ) return iset; // AVX not enabled in O.S.
93 if ( ( abcd[2] & ( 1 << 28 ) ) == 0 ) return iset; // no AVX
94 iset = 7; // 7: AVX supported
95 cpuid( abcd, 7 ); // call cpuid leaf 7 for feature flags
96 if ( ( abcd[1] & ( 1 << 5 ) ) == 0 ) return iset; // no AVX2
97 iset = 8;
98 if ( ( abcd[1] & ( 1 << 16 ) ) == 0 ) return iset; // no AVX512
99 cpuid( abcd, 0xD ); // call cpuid leaf 0xD for feature flags
100 if ( ( abcd[0] & 0x60 ) != 0x60 ) return iset; // no AVX512
101 iset = 9;
102 cpuid( abcd, 7 ); // call cpuid leaf 7 for feature flags
103 if ( ( abcd[1] & ( 1 << 31 ) ) == 0 ) return iset; // no AVX512VL
104 if ( ( abcd[1] & 0x40020000 ) != 0x40020000 ) return iset; // no AVX512BW, AVX512DQ
105 iset = 10;
106 return iset;
107 }

◆ largeblock_indexes()

template<int N>
EList< int, N/2 > largeblock_indexes ( int const (&) a[N])
constexpr

Definition at line 1249 of file instrset.h.

1249 {
1250 // Parameter a is a reference to a constexpr array of N permutation indexes
1251 EList<int, N / 2> list = { { 0 } }; // list to return
1252
1253 bool fit_addz = false; // additional zeroing needed at the lower block level
1254 int ix = 0; // even index
1255 int iy = 0; // odd index
1256 int iz = 0; // combined index
1257 int i = 0; // loop counter
1258
1259 for ( i = 0; i < N; i += 2 ) {
1260 ix = a[i]; // even index
1261 iy = a[i + 1]; // odd index
1262 if ( ix >= 0 ) {
1263 iz = ix / 2; // half index
1264 } else if ( iy >= 0 ) {
1265 iz = iy / 2; // half index
1266 } else
1267 iz = ix | iy; // -1 or V_DC. -1 takes precedence
1268 list.a[i / 2] = iz; // save to list
1269 // check if additional zeroing is needed at current block size
1270 if ( ( ix == -1 && iy >= 0 ) || ( iy == -1 && ix >= 0 ) ) { fit_addz = true; }
1271 }
1272 // replace -1 by V_DC if fit_addz
1273 if ( fit_addz ) {
1274 for ( i = 0; i < N / 2; i++ ) {
1275 if ( list.a[i] < 0 ) list.a[i] = V_DC;
1276 }
1277 }
1278 return list;
1279 }

◆ largeblock_perm()

template<int N>
EList< int, N/2 > largeblock_perm ( int const (&) a[N])
constexpr

Definition at line 978 of file instrset.h.

978 {
979 // Parameter a is a reference to a constexpr array of permutation indexes
980 EList<int, N / 2> list = { { 0 } }; // result indexes
981 int ix = 0; // even index
982 int iy = 0; // odd index
983 int iz = 0; // combined index
984 bool fit_addz = false; // additional zeroing needed at the lower block level
985 int i = 0; // loop counter
986
987 // check if additional zeroing is needed at current block size
988 for ( i = 0; i < N; i += 2 ) {
989 ix = a[i]; // even index
990 iy = a[i + 1]; // odd index
991 if ( ( ix == -1 && iy >= 0 ) || ( iy == -1 && ix >= 0 ) ) { fit_addz = true; }
992 }
993
994 // loop through indexes
995 for ( i = 0; i < N; i += 2 ) {
996 ix = a[i]; // even index
997 iy = a[i + 1]; // odd index
998 if ( ix >= 0 ) {
999 iz = ix / 2; // half index
1000 } else if ( iy >= 0 ) {
1001 iz = iy / 2;
1002 } else {
1003 iz = ix | iy; // -1 or V_DC. -1 takes precedence
1004 if ( fit_addz ) iz = V_DC; // V_DC, because result will be zeroed later
1005 }
1006 list.a[i / 2] = iz; // save to list
1007 }
1008 return list;
1009 }

◆ make_bit_mask()

template<int N, int B>
uint64_t make_bit_mask ( int const (&) a[N])
constexpr

Definition at line 525 of file instrset.h.

525 {
526 uint64_t r = 0; // return value
527 uint8_t j = uint8_t( B & 0xFF ); // index to selected bit
528 uint64_t s = 0; // bit number i in r
529 uint64_t f = 0; // 1 if bit not flipped
530 int i = 0;
531 for ( i = 0; i < N; i++ ) {
532 int ix = a[i];
533 if ( ix < 0 ) { // -1 or V_DC
534 s = ( B >> 10 ) & 1;
535 } else {
536 s = ( (uint32_t)ix >> j ) & 1; // extract selected bit
537 if ( i < N / 2 ) {
538 f = ( B >> 8 ) & 1; // lower half
539 } else {
540 f = ( B >> 9 ) & 1; // upper half
541 }
542 s ^= f ^ 1; // flip bit if needed
543 }
544 r |= uint64_t( s ) << i; // set bit in return value
545 }
546 return r;
547 }

◆ make_broad_mask()

template<typename V>
auto make_broad_mask ( uint64_t const m)
constexpr

Definition at line 552 of file instrset.h.

552 {
553 constexpr int N = V::size(); // number of vector elements
554 typedef decltype( get_inttype<V>() ) Etype; // element type
555 EList<Etype, N> u = { { 0 } }; // list for returning
556 int i = 0;
557 for ( i = 0; i < N; i++ ) { u.a[i] = ( ( m >> i ) & 1 ) != 0 ? get_inttype<V>() : 0; }
558 return u; // return encapsulated array
559 }
constexpr auto get_inttype()
Definition instrset.h:469

◆ perm16_flags()

template<typename V>
uint64_t perm16_flags ( int const (&) a[V::size()])
constexpr

Definition at line 876 of file instrset.h.

876 {
877 // a is a reference to a constexpr array of permutation indexes
878 // V is a vector class
879 constexpr int N = V::size(); // number of elements
880
881 uint64_t retval = 0; // return value
882 uint32_t pat[4] = { 0, 0, 0, 0 }; // permute patterns
883 uint32_t i = 0; // loop counter
884 int ix = 0; // index number i
885 const uint32_t lanesize = 8; // elements per lane
886 uint32_t lane = 0; // current lane
887 int lanepattern[lanesize] = { 0 }; // pattern in each lane
888
889 for ( i = 0; i < N; i++ ) {
890 ix = a[i];
891 lane = i / lanesize; // current lane
892 if ( lane == 0 ) {
893 lanepattern[i] = ix; // save pattern
894 } else if ( ix >= 0 ) { // not first lane
895 uint32_t j = i - lane * lanesize; // index into lanepattern
896 int jx = ix - lane * lanesize; // pattern within lane
897 if ( lanepattern[j] < 0 ) {
898 lanepattern[j] = jx; // pattern not known from previous lane
899 }
900 }
901 }
902 // four patterns: low2low, high2high, high2low, low2high
903 for ( i = 0; i < 4; i++ ) {
904 // loop through low pattern
905 if ( lanepattern[i] >= 0 ) {
906 if ( lanepattern[i] < 4 ) { // low2low
907 retval |= 1;
908 pat[0] |= uint32_t( lanepattern[i] & 3 ) << ( 2 * i );
909 } else { // high2low
910 retval |= 4;
911 pat[2] |= uint32_t( lanepattern[i] & 3 ) << ( 2 * i );
912 }
913 }
914 // loop through high pattern
915 if ( lanepattern[i + 4] >= 0 ) {
916 if ( lanepattern[i + 4] < 4 ) { // low2high
917 retval |= 8;
918 pat[3] |= uint32_t( lanepattern[i + 4] & 3 ) << ( 2 * i );
919 } else { // high2high
920 retval |= 2;
921 pat[1] |= uint32_t( lanepattern[i + 4] & 3 ) << ( 2 * i );
922 }
923 }
924 }
925 // join return data
926 for ( i = 0; i < 4; i++ ) { retval |= (uint64_t)pat[i] << ( 32 + i * 8 ); }
927 return retval;
928 }

◆ perm_flags()

template<typename V>
uint64_t perm_flags ( int const (&) a[V::size()])
constexpr

Definition at line 603 of file instrset.h.

603 {
604 // a is a reference to a constexpr array of permutation indexes
605 // V is a vector class
606 constexpr int N = V::size(); // number of elements
607 uint64_t r = perm_largeblock | perm_same_pattern | perm_allzero; // return value
608 uint32_t i = 0; // loop counter
609 int j = 0; // loop counter
610 int ix = 0; // index number i
611 const uint32_t nlanes = sizeof( V ) / 16; // number of 128-bit lanes
612 const uint32_t lanesize = N / nlanes; // elements per lane
613 const uint32_t elementsize = sizeof( V ) / N; // size of each vector element
614 uint32_t lane = 0; // current lane
615 uint32_t rot = 999; // rotate left count
616 int32_t broadc = 999; // index to broadcasted element
617 uint32_t patfail = 0; // remember certain patterns that do not fit
618 uint32_t addz2 = 0; // remember certain patterns need extra zeroing
619 int32_t compresslasti = -1; // last index in perm_compress fit
620 int32_t compresslastp = -1; // last position in perm_compress fit
621 int32_t expandlasti = -1; // last index in perm_expand fit
622 int32_t expandlastp = -1; // last position in perm_expand fit
623
624 int lanepattern[lanesize] = { 0 }; // pattern in each lane
625
626 for ( i = 0; i < N; i++ ) { // loop through indexes
627 ix = a[i]; // current index
628 // meaning of ix: -1 = set to zero, V_DC = don't care, non-negative value = permute.
629 if ( ix == -1 ) {
630 r |= perm_zeroing; // zeroing requested
631 } else if ( ix != V_DC && uint32_t( ix ) >= N ) {
632 r |= perm_outofrange; // index out of range
633 }
634 if ( ix >= 0 ) {
635 r &= ~perm_allzero; // not all zero
636 if ( ix != (int)i ) r |= perm_perm; // needs permutation
637 if ( broadc == 999 )
638 broadc = ix; // remember broadcast index
639 else if ( broadc != ix )
640 broadc = 1000; // does not fit broadcast
641 }
642 // check if pattern fits a larger block size:
643 // even indexes must be even, odd indexes must fit the preceding even index + 1
644 if ( ( i & 1 ) == 0 ) { // even index
645 if ( ix >= 0 && ( ix & 1 ) ) r &= ~perm_largeblock; // not even. does not fit larger block size
646 int iy = a[i + 1]; // next odd index
647 if ( iy >= 0 && ( iy & 1 ) == 0 ) r &= ~perm_largeblock; // not odd. does not fit larger block size
648 if ( ix >= 0 && iy >= 0 && iy != ix + 1 ) r &= ~perm_largeblock; // does not fit preceding index + 1
649 if ( ix == -1 && iy >= 0 ) r |= perm_addz; // needs additional zeroing at current block size
650 if ( iy == -1 && ix >= 0 ) r |= perm_addz; // needs additional zeroing at current block size
651 }
652 lane = i / lanesize; // current lane
653 if ( lane == 0 ) { // first lane, or no pattern yet
654 lanepattern[i] = ix; // save pattern
655 }
656 // check if crossing lanes
657 if ( ix >= 0 ) {
658 uint32_t lanei = (uint32_t)ix / lanesize; // source lane
659 if ( lanei != lane ) r |= perm_cross_lane; // crossing lane
660 }
661 // check if same pattern in all lanes
662 if ( lane != 0 && ix >= 0 ) { // not first lane
663 int j1 = i - int( lane * lanesize ); // index into lanepattern
664 int jx = ix - int( lane * lanesize ); // pattern within lane
665 if ( jx < 0 || jx >= (int)lanesize ) r &= ~perm_same_pattern; // source is in another lane
666 if ( lanepattern[j1] < 0 ) {
667 lanepattern[j1] = jx; // pattern not known from previous lane
668 } else {
669 if ( lanepattern[j1] != jx ) r &= ~perm_same_pattern; // not same pattern
670 }
671 }
672 if ( ix >= 0 ) {
673 // check if pattern fits zero extension (perm_zext)
674 if ( uint32_t( ix * 2 ) != i ) {
675 patfail |= 1; // does not fit zero extension
676 }
677 // check if pattern fits compress (perm_compress)
678 if ( ix > compresslasti && ix - compresslasti >= (int)i - compresslastp ) {
679 if ( (int)i - compresslastp > 1 ) addz2 |= 2; // perm_compress may need additional zeroing
680 compresslasti = ix;
681 compresslastp = i;
682 } else {
683 patfail |= 2; // does not fit perm_compress
684 }
685 // check if pattern fits expand (perm_expand)
686 if ( ix > expandlasti && ix - expandlasti <= (int)i - expandlastp ) {
687 if ( ix - expandlasti > 1 ) addz2 |= 4; // perm_expand may need additional zeroing
688 expandlasti = ix;
689 expandlastp = i;
690 } else {
691 patfail |= 4; // does not fit perm_compress
692 }
693 } else if ( ix == -1 ) {
694 if ( ( i & 1 ) == 0 ) addz2 |= 1; // zero extension needs additional zeroing
695 }
696 }
697 if ( !( r & perm_perm ) ) return r; // more checks are superfluous
698
699 if ( !( r & perm_largeblock ) ) r &= ~perm_addz; // remove irrelevant flag
700 if ( r & perm_cross_lane ) r &= ~perm_same_pattern; // remove irrelevant flag
701 if ( ( patfail & 1 ) == 0 ) {
702 r |= perm_zext; // fits zero extension
703 if ( ( addz2 & 1 ) != 0 ) r |= perm_addz2;
704 } else if ( ( patfail & 2 ) == 0 ) {
705 r |= perm_compress; // fits compression
706 if ( ( addz2 & 2 ) != 0 ) { // check if additional zeroing needed
707 for ( j = 0; j < compresslastp; j++ ) {
708 if ( a[j] == -1 ) r |= perm_addz2;
709 }
710 }
711 } else if ( ( patfail & 4 ) == 0 ) {
712 r |= perm_expand; // fits expansion
713 if ( ( addz2 & 4 ) != 0 ) { // check if additional zeroing needed
714 for ( j = 0; j < expandlastp; j++ ) {
715 if ( a[j] == -1 ) r |= perm_addz2;
716 }
717 }
718 }
719
720 if ( r & perm_same_pattern ) {
721 // same pattern in all lanes. check if it fits specific patterns
722 bool fit = true;
723 // fit shift or rotate
724 for ( i = 0; i < lanesize; i++ ) {
725 if ( lanepattern[i] >= 0 ) {
726 uint32_t rot1 = uint32_t( lanepattern[i] + lanesize - i ) % lanesize;
727 if ( rot == 999 ) {
728 rot = rot1;
729 } else { // check if fit
730 if ( rot != rot1 ) fit = false;
731 }
732 }
733 }
734 rot &= lanesize - 1; // prevent out of range values
735 if ( fit ) { // fits rotate, and possibly shift
736 uint64_t rot2 = ( rot * elementsize ) & 0xF; // rotate right count in bytes
737 r |= rot2 << perm_rot_count; // put shift/rotate count in output bit 16-19
738#if INSTRSET >= 4 // SSSE3
739 r |= perm_rotate; // allow palignr
740#endif
741 // fit shift left
742 fit = true;
743 for ( i = 0; i < lanesize - rot; i++ ) { // check if first rot elements are zero or don't care
744 if ( lanepattern[i] >= 0 ) fit = false;
745 }
746 if ( fit ) {
747 r |= perm_shleft;
748 for ( ; i < lanesize; i++ )
749 if ( lanepattern[i] == -1 ) r |= perm_addz; // additional zeroing needed
750 }
751 // fit shift right
752 fit = true;
753 for ( i = lanesize - (uint32_t)rot; i < lanesize;
754 i++ ) { // check if last (lanesize-rot) elements are zero or don't care
755 if ( lanepattern[i] >= 0 ) fit = false;
756 }
757 if ( fit ) {
758 r |= perm_shright;
759 for ( i = 0; i < lanesize - rot; i++ ) {
760 if ( lanepattern[i] == -1 ) r |= perm_addz; // additional zeroing needed
761 }
762 }
763 }
764 // fit punpckhi
765 fit = true;
766 uint32_t j2 = lanesize / 2;
767 for ( i = 0; i < lanesize; i++ ) {
768 if ( lanepattern[i] >= 0 && lanepattern[i] != (int)j2 ) fit = false;
769 if ( ( i & 1 ) != 0 ) j2++;
770 }
771 if ( fit ) r |= perm_punpckh;
772 // fit punpcklo
773 fit = true;
774 j2 = 0;
775 for ( i = 0; i < lanesize; i++ ) {
776 if ( lanepattern[i] >= 0 && lanepattern[i] != (int)j2 ) fit = false;
777 if ( ( i & 1 ) != 0 ) j2++;
778 }
779 if ( fit ) r |= perm_punpckl;
780 // fit pshufd
781 if ( elementsize >= 4 ) {
782 uint64_t p = 0;
783 for ( i = 0; i < lanesize; i++ ) {
784 if ( lanesize == 4 ) {
785 p |= ( lanepattern[i] & 3 ) << 2 * i;
786 } else { // lanesize = 2
787 p |= ( ( lanepattern[i] & 1 ) * 10 + 4 ) << 4 * i;
788 }
789 }
790 r |= p << perm_ipattern;
791 }
792 }
793#if INSTRSET >= 7
794 else { // not same pattern in all lanes
795 if constexpr ( nlanes > 1 ) { // Try if it fits big rotate
796 for ( i = 0; i < N; i++ ) {
797 ix = a[i];
798 if ( ix >= 0 ) {
799 uint32_t rot2 = ( ix + N - i ) % N; // rotate count
800 if ( rot == 999 ) {
801 rot = rot2; // save rotate count
802 } else if ( rot != rot2 ) {
803 rot = 1000;
804 break; // does not fit big rotate
805 }
806 }
807 }
808 if ( rot < N ) { // fits big rotate
809 r |= perm_rotate_big | (uint64_t)rot << perm_rot_count;
810 }
811 }
812 }
813#endif
814 if ( broadc < 999 && ( r & ( perm_rotate | perm_shright | perm_shleft | perm_rotate_big ) ) == 0 ) {
815 r |= perm_broadcast | (uint64_t)broadc << perm_rot_count; // fits broadcast
816 }
817 return r;
818 }
const int perm_compress
Definition instrset.h:595
const int perm_shleft
Definition instrset.h:589
const int perm_addz2
Definition instrset.h:580
const int perm_punpckl
Definition instrset.h:584
const int perm_rotate_big
Definition instrset.h:591
const int perm_broadcast
Definition instrset.h:593
const int perm_cross_lane
Definition instrset.h:581
const int perm_addz
Definition instrset.h:579
const int perm_zeroing
Definition instrset.h:575
const int perm_outofrange
Definition instrset.h:597
const int perm_largeblock
Definition instrset.h:578
const int perm_rotate
Definition instrset.h:585
const int perm_shright
Definition instrset.h:587
const int perm_punpckh
Definition instrset.h:583
const int perm_same_pattern
Definition instrset.h:582
const int perm_zext
Definition instrset.h:594
const int perm_perm
Definition instrset.h:576
const int perm_expand
Definition instrset.h:596
const int perm_allzero
Definition instrset.h:577
const int perm_ipattern
Definition instrset.h:599
const int perm_rot_count
Definition instrset.h:598

◆ perm_mask_broad()

template<typename V>
auto perm_mask_broad ( int const (&) A[V::size()])
constexpr

Definition at line 564 of file instrset.h.

564 {
565 constexpr int N = V::size(); // number of vector elements
566 typedef decltype( get_inttype<V>() ) Etype; // vector element type
567 EList<Etype, N> u = { { 0 } }; // list for returning
568 int i = 0;
569 for ( i = 0; i < N; i++ ) { u.a[i] = Etype( A[i] ); }
570 return u; // return encapsulated array
571 }

◆ physicalProcessors()

int physicalProcessors ( int * logical_processors = 0)

◆ pshufb_mask()

template<typename V, int oppos = 0>
auto pshufb_mask ( int const (&) A[V::size()])
constexpr

Definition at line 935 of file instrset.h.

935 {
936 // Parameter a is a reference to a constexpr array of permutation indexes
937 // V is a vector class
938 // oppos = 1 for data from the opposite 128-bit lane in 256-bit vectors
939 constexpr uint32_t N = V::size(); // number of vector elements
940 constexpr uint32_t elementsize = sizeof( V ) / N; // size of each vector element
941 constexpr uint32_t nlanes = sizeof( V ) / 16; // number of 128 bit lanes in vector
942 constexpr uint32_t elements_per_lane = N / nlanes; // number of vector elements per lane
943
944 EList<int8_t, sizeof( V )> u = { { 0 } }; // list for returning
945
946 uint32_t i = 0; // loop counters
947 uint32_t j = 0;
948 int m = 0;
949 int k = 0;
950 uint32_t lane = 0;
951
952 for ( lane = 0; lane < nlanes; lane++ ) { // loop through lanes
953 for ( i = 0; i < elements_per_lane; i++ ) { // loop through elements in lane
954 // permutation index for element within lane
955 int8_t p = -1;
956 int ix = A[m];
957 if ( ix >= 0 ) {
958 ix ^= oppos * elements_per_lane; // flip bit if opposite lane
959 }
960 ix -= int( lane * elements_per_lane ); // index relative to lane
961 if ( ix >= 0 && ix < (int)elements_per_lane ) { // index points to desired lane
962 p = ix * elementsize;
963 }
964 for ( j = 0; j < elementsize; j++ ) { // loop through bytes in element
965 u.a[k++] = p < 0 ? -1 : p + j; // store byte permutation index
966 }
967 m++;
968 }
969 }
970 return u; // return encapsulated array
971 }

◆ zero_mask()

template<int N>
auto zero_mask ( int const (&) a[N])
constexpr

Definition at line 486 of file instrset.h.

486 {
487 uint64_t mask = 0;
488 int i = 0;
489
490 for ( i = 0; i < N; i++ ) {
491 if ( a[i] >= 0 ) mask |= uint64_t( 1 ) << i;
492 }
493 if constexpr ( N <= 8 )
494 return uint8_t( mask );
495 else if constexpr ( N <= 16 )
496 return uint16_t( mask );
497 else if constexpr ( N <= 32 )
498 return uint32_t( mask );
499 else
500 return mask;
501 }

◆ zero_mask_broad()

template<typename V>
auto zero_mask_broad ( int const (&) A[V::size()])
constexpr

Definition at line 506 of file instrset.h.

506 {
507 constexpr int N = V::size(); // number of vector elements
508 typedef decltype( get_inttype<V>() ) Etype; // element type
509 EList<Etype, N> u = { { 0 } }; // list for return
510 int i = 0;
511 for ( i = 0; i < N; i++ ) { u.a[i] = A[i] >= 0 ? get_inttype<V>() : 0; }
512 return u; // return encapsulated array
513 }

Variable Documentation

◆ blend_a

const int blend_a = 0x10

Definition at line 1017 of file instrset.h.

◆ blend_addz

const int blend_addz = 8

Definition at line 1016 of file instrset.h.

◆ blend_allzero

const int blend_allzero = 2

Definition at line 1014 of file instrset.h.

◆ blend_b

const int blend_b = 0x20

Definition at line 1018 of file instrset.h.

◆ blend_cross_lane

const int blend_cross_lane = 0x100

Definition at line 1021 of file instrset.h.

◆ blend_largeblock

const int blend_largeblock = 4

Definition at line 1015 of file instrset.h.

◆ blend_outofrange

const int blend_outofrange = 0x10000000

Definition at line 1032 of file instrset.h.

◆ blend_perma

const int blend_perma = 0x40

Definition at line 1019 of file instrset.h.

◆ blend_permb

const int blend_permb = 0x80

Definition at line 1020 of file instrset.h.

◆ blend_punpckhab

const int blend_punpckhab = 0x1000

Definition at line 1023 of file instrset.h.

◆ blend_punpckhba

const int blend_punpckhba = 0x2000

Definition at line 1024 of file instrset.h.

◆ blend_punpcklab

const int blend_punpcklab = 0x4000

Definition at line 1025 of file instrset.h.

◆ blend_punpcklba

const int blend_punpcklba = 0x8000

Definition at line 1026 of file instrset.h.

◆ blend_rotate_big

const int blend_rotate_big = 0x100000

Definition at line 1031 of file instrset.h.

◆ blend_rotateab

const int blend_rotateab = 0x10000

Definition at line 1027 of file instrset.h.

◆ blend_rotateba

const int blend_rotateba = 0x20000

Definition at line 1028 of file instrset.h.

◆ blend_rotpattern

const int blend_rotpattern = 40

Definition at line 1034 of file instrset.h.

◆ blend_same_pattern

const int blend_same_pattern = 0x200

Definition at line 1022 of file instrset.h.

◆ blend_shufab

const int blend_shufab = 0x40000

Definition at line 1029 of file instrset.h.

◆ blend_shufba

const int blend_shufba = 0x80000

Definition at line 1030 of file instrset.h.

◆ blend_shufpattern

const int blend_shufpattern = 32

Definition at line 1033 of file instrset.h.

◆ blend_zeroing

const int blend_zeroing = 1

Definition at line 1013 of file instrset.h.

◆ perm_addz

const int perm_addz = 0x10

Definition at line 579 of file instrset.h.

◆ perm_addz2

const int perm_addz2 = 0x20

Definition at line 580 of file instrset.h.

◆ perm_allzero

const int perm_allzero = 4

Definition at line 577 of file instrset.h.

◆ perm_broadcast

const int perm_broadcast = 0x8000

Definition at line 593 of file instrset.h.

◆ perm_compress

const int perm_compress = 0x20000

Definition at line 595 of file instrset.h.

◆ perm_cross_lane

const int perm_cross_lane = 0x40

Definition at line 581 of file instrset.h.

◆ perm_expand

const int perm_expand = 0x40000

Definition at line 596 of file instrset.h.

◆ perm_ipattern

const int perm_ipattern
Initial value:
=
40

Definition at line 599 of file instrset.h.

◆ perm_largeblock

const int perm_largeblock = 8

Definition at line 578 of file instrset.h.

◆ perm_outofrange

const int perm_outofrange = 0x10000000

Definition at line 597 of file instrset.h.

◆ perm_perm

const int perm_perm = 2

Definition at line 576 of file instrset.h.

◆ perm_punpckh

const int perm_punpckh = 0x100

Definition at line 583 of file instrset.h.

◆ perm_punpckl

const int perm_punpckl = 0x200

Definition at line 584 of file instrset.h.

◆ perm_rot_count

const int perm_rot_count = 32

Definition at line 598 of file instrset.h.

◆ perm_rotate

const int perm_rotate
Initial value:
=
0x400

Definition at line 585 of file instrset.h.

◆ perm_rotate_big

const int perm_rotate_big
Initial value:
=
0x4000

Definition at line 591 of file instrset.h.

◆ perm_same_pattern

const int perm_same_pattern = 0x80

Definition at line 582 of file instrset.h.

◆ perm_shleft

const int perm_shleft
Initial value:
=
0x2000

Definition at line 589 of file instrset.h.

◆ perm_shright

const int perm_shright
Initial value:
=
0x1000

Definition at line 587 of file instrset.h.

◆ perm_zeroing

const int perm_zeroing = 1

Definition at line 575 of file instrset.h.

◆ perm_zext

const int perm_zext = 0x10000

Definition at line 594 of file instrset.h.

◆ V_DC

int V_DC = -256
constexpr

Definition at line 219 of file instrset.h.