mirror of
https://github.com/JayDDee/cpuminer-opt.git
synced 2025-09-17 23:44:27 +00:00
v3.9.4
This commit is contained in:
@@ -384,6 +384,7 @@ static inline void mm256_intrlv_8x32( void *d, const void *s0,
|
||||
// bit_len == 1024
|
||||
}
|
||||
|
||||
// A couple of mining specifi functions.
|
||||
|
||||
// Interleave 80 bytes of 32 bit data for 8 lanes.
|
||||
static inline void mm256_bswap_intrlv80_8x32( void *d, const void *s )
|
||||
@@ -469,6 +470,20 @@ static inline void mm256_bswap_intrlv80_4x64( void *d, const void *s )
|
||||
mm256_bswap_intrlv_4x64_128( d+256, casti_m128i( s, 4 ) );
|
||||
}
|
||||
|
||||
// Blend 32 byte lanes of hash from 2 sources according to control mask.
|
||||
// macro due to 256 bit value arg.
|
||||
#define mm256_blend_hash_4x64( dst, a, b, mask ) \
|
||||
do { \
|
||||
dst[0] = _mm256_blendv_epi8( a[0], b[0], mask ); \
|
||||
dst[1] = _mm256_blendv_epi8( a[1], b[1], mask ); \
|
||||
dst[2] = _mm256_blendv_epi8( a[2], b[2], mask ); \
|
||||
dst[3] = _mm256_blendv_epi8( a[3], b[3], mask ); \
|
||||
dst[4] = _mm256_blendv_epi8( a[4], b[4], mask ); \
|
||||
dst[5] = _mm256_blendv_epi8( a[5], b[5], mask ); \
|
||||
dst[6] = _mm256_blendv_epi8( a[6], b[6], mask ); \
|
||||
dst[7] = _mm256_blendv_epi8( a[7], b[7], mask ); \
|
||||
} while(0)
|
||||
|
||||
// Deinterleave 4 buffers of 64 bit data from the source buffer.
|
||||
// bit_len must be 256, 512, 640 or 1024 bits.
|
||||
// Requires overrun padding for 640 bit len.
|
||||
|
@@ -103,6 +103,29 @@
|
||||
#define mm128_extr_lo128_256( a ) _mm256_castsi256_si128( a )
|
||||
#define mm128_extr_hi128_256( a ) _mm256_extracti128_si256( a, 1 )
|
||||
|
||||
// Extract 4 u64 from 256 bit vector.
|
||||
#define mm256_extr_4x64( a0, a1, a2, a3, src ) \
|
||||
do { \
|
||||
__m128i hi = _mm256_extracti128_si256( src, 1 ); \
|
||||
a0 = _mm_extract_epi64( _mm256_castsi256_si128( src ), 0 ); \
|
||||
a1 = _mm_extract_epi64( _mm256_castsi256_si128( src ), 1 ); \
|
||||
a2 = _mm_extract_epi64( hi, 0 ); \
|
||||
a3 = _mm_extract_epi64( hi, 1 ); \
|
||||
} while(0)
|
||||
|
||||
#define mm256_extr_8x32( a0, a1, a2, a3, a4, a5, a6, a7, src ) \
|
||||
do { \
|
||||
__m128i hi = _mm256_extracti128_si256( src, 1 ); \
|
||||
a0 = _mm_extract_epi32( _mm256_castsi256_si128( src ), 0 ); \
|
||||
a1 = _mm_extract_epi32( _mm256_castsi256_si128( src ), 1 ); \
|
||||
a2 = _mm_extract_epi32( _mm256_castsi256_si128( src ), 2 ); \
|
||||
a3 = _mm_extract_epi32( _mm256_castsi256_si128( src ), 3 ); \
|
||||
a4 = _mm_extract_epi32( hi, 0 ); \
|
||||
a5 = _mm_extract_epi32( hi, 1 ); \
|
||||
a6 = _mm_extract_epi32( hi, 2 ); \
|
||||
a7 = _mm_extract_epi32( hi, 3 ); \
|
||||
} while(0)
|
||||
|
||||
// input __m128i, returns __m256i
|
||||
// To build a 256 bit vector from 2 128 bit vectors lo must be done first.
|
||||
// lo alone leaves hi undefined, hi alone leaves lo unchanged.
|
||||
@@ -111,10 +134,24 @@
|
||||
#define mm256_ins_lo128_256( a, b ) _mm256_inserti128_si256( a, b, 0 )
|
||||
#define mm256_ins_hi128_256( a, b ) _mm256_inserti128_si256( a, b, 1 )
|
||||
|
||||
// concatenate two 128 bit vectors into one 256 bit vector
|
||||
// concatenate two 128 bit vectors into one 256 bit vector: { hi, lo }
|
||||
#define mm256_concat_128( hi, lo ) \
|
||||
mm256_ins_hi128_256( _mm256_castsi128_si256( lo ), hi )
|
||||
|
||||
// Horizontal vector testing
|
||||
|
||||
// Bit-wise test of entire vector, useful to test results of cmp.
|
||||
#define mm256_anybits0( a ) \
|
||||
( (uint128_t)mm128_extr_hi128_256( a ) \
|
||||
| (uint128_t)mm128_extr_lo128_256( a ) )
|
||||
|
||||
#define mm256_anybits1( a ) \
|
||||
( ( (uint128_t)mm128_extr_hi128_256( a ) + 1 ) \
|
||||
| ( (uint128_t)mm128_extr_lo128_256( a ) + 1 ) )
|
||||
|
||||
#define mm256_allbits0_256( a ) ( !mm256_anybits1(a) )
|
||||
#define mm256_allbits1_256( a ) ( !mm256_anybits0(a) )
|
||||
|
||||
// Parallel AES, for when x is expected to be in a 256 bit register.
|
||||
#define mm256_aesenc_2x128( x ) \
|
||||
mm256_concat_128( \
|
||||
|
@@ -3,9 +3,15 @@
|
||||
|
||||
///////////////////////////////////
|
||||
//
|
||||
// Integers up to 64 bits.
|
||||
// Integers up to 128 bits.
|
||||
//
|
||||
|
||||
// These utilities enhance support for integers up to 128 bits.
|
||||
// All standard operations are supported on 128 bit integers except
|
||||
// numeric constant representation and IO. 128 bit integers must be built
|
||||
// and displayed as 2 64 bit halves, just like the old times.
|
||||
//
|
||||
// Some utilities are also provided for smaller integers, most notably
|
||||
// bit rotation.
|
||||
|
||||
// MMX has no extract instruction for 32 bit elements so this:
|
||||
// Lo is trivial, high is a simple shift.
|
||||
@@ -17,7 +23,6 @@
|
||||
#define u64_extr_16( a, n ) ( (uint16_t)( (a) >> ( ( 4-(n)) <<4 ) ) )
|
||||
#define u64_extr_8( a, n ) ( (uint8_t) ( (a) >> ( ( 8-(n)) <<3 ) ) )
|
||||
|
||||
|
||||
// Rotate bits in various sized integers.
|
||||
#define u64_ror_64( x, c ) \
|
||||
(uint64_t)( ( (uint64_t)(x) >> (c) ) | ( (uint64_t)(x) << (64-(c)) ) )
|
||||
@@ -36,6 +41,9 @@
|
||||
#define u8_rol_8( x, c ) \
|
||||
(uint8_t) ( ( (uint8_t) (x) << (c) ) | ( (uint8_t) (x) >> ( 8-(c)) ) )
|
||||
|
||||
// Endian byte swap
|
||||
#define bswap_64( a ) __builtin_bswap64( a )
|
||||
#define bswap_32( a ) __builtin_bswap32( a )
|
||||
|
||||
// 64 bit mem functions use integral sizes instead of bytes, data must
|
||||
// be aligned to 64 bits. Mostly for scaled indexing convenience.
|
||||
@@ -56,21 +64,20 @@ static inline void memset_64( uint64_t *dst, const uint64_t a, int n )
|
||||
//
|
||||
|
||||
// No real need or use.
|
||||
#define i128_neg1 ((uint128_t)(-1LL))
|
||||
//#define u128_neg1 ((uint128_t)(-1))
|
||||
|
||||
// Extract specified 64 bit half of 128 bit integer.
|
||||
// typecast should work for lo: (uint64_t)(x), test it!
|
||||
// Extracting the low bits is a trivial cast.
|
||||
// These specialized functions are optimized while providing a
|
||||
// consistent interface.
|
||||
#define u128_hi64( x ) ( (uint64_t)( (uint128_t)(x) >> 64 ) )
|
||||
#define u128_lo64( x ) ( (uint64_t)( (uint128_t)(x) << 64 >> 64 ) )
|
||||
// #define i128_lo64( x ) ((uint64_t)(x))
|
||||
#define u128_lo64( x ) ( (uint64_t)(x) )
|
||||
|
||||
// Generic extract,
|
||||
// Generic extract, don't use for extracting low bits, cast instead.
|
||||
#define u128_extr_64( a, n ) ( (uint64_t)( (a) >> ( ( 2-(n)) <<6 ) ) )
|
||||
#define u128_extr_32( a, n ) ( (uint32_t)( (a) >> ( ( 4-(n)) <<5 ) ) )
|
||||
#define u128_extr_16( a, n ) ( (uint16_t)( (a) >> ( ( 8-(n)) <<4 ) ) )
|
||||
#define u128_extr_8( a, n ) ( (uint8_t) ( (a) >> ( (16-(n)) <<3 ) ) )
|
||||
|
||||
|
||||
// Not much need for this but it fills a gap.
|
||||
#define u128_ror_128( x, c ) \
|
||||
( ( (uint128_t)(x) >> (c) ) | ( (uint128_t)(x) << (128-(c)) ) )
|
||||
|
@@ -111,8 +111,8 @@
|
||||
|
||||
#if defined(__SSSE3__)
|
||||
|
||||
// An SSE2 versin of this would be monstrous, shifting, masking and oring
|
||||
// each byte individually.
|
||||
// An SSE2 or MMX version of this would be monstrous, shifting, masking and
|
||||
// oring each byte individually.
|
||||
#define mm64_invert_8( v ) \
|
||||
_mm_shuffle_pi8( (__m64)v, _mm_set_pi8( 0,1,2,3,4,5,6,7 ) );
|
||||
|
||||
|
@@ -10,11 +10,21 @@
|
||||
// SSE2 is generally required for full 128 bit support. Some functions
|
||||
// are also optimized with SSSE3 or SSE4.1.
|
||||
//
|
||||
// Do not call _mm_extract directly, it isn't supported in SSE2.
|
||||
// Use mm128_extr instead, it will select the appropriate implementation.
|
||||
//
|
||||
// 128 bit operations are enhanced with uint128 which adds 128 bit integer
|
||||
// support for arithmetic and other operations. Casting to uint128_t is not
|
||||
// free, it requires a move from mmx to gpr but is often the only way or
|
||||
// the more efficient way for certain operations.
|
||||
|
||||
// Compile time constant initializers are type agnostic and can have
|
||||
// a pointer handle of almost any type. All arguments must be scalar constants.
|
||||
// up to 64 bits. These iniitializers should only be used at compile time
|
||||
// to initialize vector arrays. All data reside in memory.
|
||||
//
|
||||
// These are of limited use, it is often simpler to use uint64_t arrays
|
||||
// and cast as required.
|
||||
|
||||
#define mm128_const_64( x1, x0 ) {{ x1, x0 }}
|
||||
#define mm128_const1_64( x ) {{ x, x }}
|
||||
@@ -80,6 +90,28 @@
|
||||
#define mm128_negate_32( v ) _mm_sub_epi32( m128_zero, v )
|
||||
#define mm128_negate_16( v ) _mm_sub_epi16( m128_zero, v )
|
||||
|
||||
// Use uint128_t for most arithmetic, bit shift, comparison operations
|
||||
// spanning all 128 bits. Some extractions are also more efficient
|
||||
// casting __m128i as uint128_t and usingstandard operators.
|
||||
|
||||
// This isn't cheap, not suitable for bulk usage.
|
||||
#define mm128_extr_4x32( a0, a1, a2, a3, src ) \
|
||||
do { \
|
||||
a0 = _mm_extract_epi32( src, 0 ); \
|
||||
a1 = _mm_extract_epi32( src, 1 ); \
|
||||
a1 = _mm_extract_epi32( src, 2 ); \
|
||||
a3 = _mm_extract_epi32( src, 3 ); \
|
||||
} while(0)
|
||||
|
||||
// Horizontal vector testing
|
||||
|
||||
// Bit-wise test of entire vector, useful to test results of cmp.
|
||||
#define mm128_anybits0( a ) (uint128_t)(a)
|
||||
#define mm128_anybits1( a ) (((uint128_t)(a))+1)
|
||||
|
||||
#define mm128_allbits0( a ) ( !mm128_anybits1(a) )
|
||||
#define mm128_allbits1( a ) ( !mm128_anybits0(a) )
|
||||
|
||||
//
|
||||
// Vector pointer cast
|
||||
|
||||
|
@@ -93,6 +93,7 @@
|
||||
// my_int128 = (uint128_t)_mm256_extracti128_si256( v256, 1 );
|
||||
|
||||
// Compiler check for __int128 support
|
||||
// Configure also has a test for int128.
|
||||
#if ( __GNUC__ > 4 ) || ( ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ >= 8 ) )
|
||||
#define GCC_INT128 1
|
||||
#endif
|
||||
@@ -386,13 +387,3 @@ typedef union _regarray_v256 regarray_v256;
|
||||
#define u8_1e u8_._1e
|
||||
#define u8_1f u8_._1f
|
||||
|
||||
|
||||
// This is in use by, coincidentally, simd hash.
|
||||
union _m256_v16 {
|
||||
uint16_t u16[16];
|
||||
__m256i v256;
|
||||
};
|
||||
typedef union _m256_v16 m256_v16;
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user