This commit is contained in:
Jay D Dee
2023-10-06 22:18:09 -04:00
parent bc5a5c6df8
commit 31c4dedf59
144 changed files with 5931 additions and 3746 deletions

View File

@@ -2,15 +2,84 @@
#define SIMD_INT_H__ 1
// Endian byte swap
#if defined(__x86_64__)
#define bswap_64 __builtin_bswap64
#define bswap_32 __builtin_bswap32
#elif defined(__aarch64__)
//#pragma message "aarch64 fast bswap"
static inline uint64_t bswap_64( uint64_t a )
{
uint64_t b;
asm( "rev %0, %1\n\t" : "=r"(b) : "r"(a) );
return b;
}
static inline uint32_t bswap_32( uint32_t a )
{
uint32_t b;
asm( "rev32 %0, %1\n\t" : "=r"(b) : "r"(a) );
return b;
}
#else
#define bswap_64(x) \
( ( ( (x) & 0x00000000FFFFFFFF ) << 32 ) \
| ( ( (x) & 0xFFFFFFFF00000000 ) >> 32 ) \
| ( ( (x) & 0x0000FFFF0000FFFF ) << 16 ) \
| ( ( (x) & 0xFFFF0000FFFF0000 ) >> 16 ) \
| ( ( (x) & 0x00FF00FF00FF00FF ) << 8 ) \
| ( ( (x) & 0xFF00FF00FF00FF00 ) >> 8 ) )
#define bswap_32(x) \
( ( ( (x) << 24 ) & 0xff000000 ) | ( ((x) << 8 ) & 0x00ff0000 ) \
| ( ( (x) >> 8 ) & 0x0000ff00 ) | ( ((x) >> 24 ) & 0x000000ff ) )
#endif
// Bit rotation
#if defined(__x86_64__)
#define rol64 __rolq
#define ror64 __rorq
#define rol32 __rold
#define ror32 __rord
#elif defined(__aarch64__)
//#pragma message "aarch64 fast bit rotation"
// "ror" instruction (intrinsic?) for 32 & 64 bits, args must determine size.
static inline uint64_t ror64( uint64_t a, const int c )
{
uint64_t b;
asm( "ror %0, %1, %2\n\t" : "=r"(b) : "r"(a), "r"(c) );
return b;
}
#define rol64( a, c ) ror64( a, 64-(c) )
static inline uint32_t ror32( uint32_t a, const int c )
{
uint32_t b;
asm( "ror %0, %1, %2\n\t" : "=r"(b) : "r"(a), "r"(c) );
return b;
}
#define rol32( a, c ) ror32( a, 32-(c) )
#else
#define ror64( x, c ) ( ( (x) >> (c) ) | ( (x) << (64-(c)) ) )
#define rol64( x, c ) ( ( (x) << (c) ) | ( (x) >> (64-(c)) ) )
#define ror32( x, c ) ( ( (x) >> (c) ) | ( (x) << (32-(c)) ) )
#define rol32( x, c ) ( ( (x) << (c) ) | ( (x) >> (32-(c)) ) )
#endif
// Safe division, integer or floating point. For floating point it's as
// safe as 0 is precisely zero.
// Returns safe_result if division by zero, typically zero.