|
15 | 15 | #endif
|
16 | 16 | #endif
|
17 | 17 |
|
| 18 | +#define uint32_t_blocker MAYO_NAMESPACE(uint32_t_blocker) |
| 19 | +extern volatile uint32_t uint32_t_blocker; |
| 20 | +#define uint64_t_blocker MAYO_NAMESPACE(uint64_t_blocker) |
| 21 | +extern volatile uint64_t uint64_t_blocker; |
| 22 | +#define unsigned_char_blocker MAYO_NAMESPACE(unsigned_char_blocker) |
| 23 | +extern volatile unsigned char unsigned_char_blocker; |
| 24 | + |
| 25 | +#if !(((!defined(__clang__) && defined(__GNUC__) && __GNUC__ <= 12)) && (defined(__x86_64__) || defined(_M_X64))) |
| 26 | +// a > b -> b - a is negative |
| 27 | +// returns 0xFFFFFFFF if true, 0x00000000 if false |
| 28 | +static inline uint32_t ct_is_greater_than(int a, int b) { |
| 29 | + int32_t diff = b - a; |
| 30 | + return ((uint32_t) (diff >> (8*sizeof(uint32_t)-1)) ^ uint32_t_blocker); |
| 31 | +} |
| 32 | + |
| 33 | +// a > b -> b - a is negative |
| 34 | +// returns 0xFFFFFFFF if true, 0x00000000 if false |
| 35 | +static inline uint64_t ct_64_is_greater_than(int a, int b) { |
| 36 | + int64_t diff = ((int64_t) b) - ((int64_t) a); |
| 37 | + return ((uint64_t) (diff >> (8*sizeof(uint64_t)-1)) ^ uint64_t_blocker); |
| 38 | +} |
| 39 | + |
| 40 | +// if a == b -> 0x00000000, else 0xFFFFFFFF |
| 41 | +static inline uint32_t ct_compare_32(int a, int b) { |
| 42 | + return ((uint32_t)((-(int32_t)(a ^ b)) >> (8*sizeof(uint32_t)-1)) ^ uint32_t_blocker); |
| 43 | +} |
| 44 | + |
| 45 | +// if a == b -> 0x0000000000000000, else 0xFFFFFFFFFFFFFFFF |
| 46 | +static inline uint64_t ct_compare_64(int a, int b) { |
| 47 | + return ((uint64_t)((-(int64_t)(a ^ b)) >> (8*sizeof(uint64_t)-1)) ^ uint64_t_blocker); |
| 48 | +} |
| 49 | + |
| 50 | +// if a == b -> 0x00, else 0xFF |
| 51 | +static inline unsigned char ct_compare_8(unsigned char a, unsigned char b) { |
| 52 | + return ((int8_t)((-(int32_t)(a ^ b)) >> (8*sizeof(uint32_t)-1)) ^ unsigned_char_blocker); |
| 53 | +} |
| 54 | +#else |
| 55 | +// a > b -> b - a is negative |
| 56 | +// returns 0xFFFFFFFF if true, 0x00000000 if false |
| 57 | +static inline uint32_t ct_is_greater_than(int a, int b) { |
| 58 | + int32_t diff = b - a; |
| 59 | + return ((uint32_t) (diff >> (8*sizeof(uint32_t)-1))); |
| 60 | +} |
| 61 | + |
| 62 | +// a > b -> b - a is negative |
| 63 | +// returns 0xFFFFFFFF if true, 0x00000000 if false |
| 64 | +static inline uint64_t ct_64_is_greater_than(int a, int b) { |
| 65 | + int64_t diff = ((int64_t) b) - ((int64_t) a); |
| 66 | + return ((uint64_t) (diff >> (8*sizeof(uint64_t)-1))); |
| 67 | +} |
| 68 | + |
| 69 | +// if a == b -> 0x00000000, else 0xFFFFFFFF |
| 70 | +static inline uint32_t ct_compare_32(int a, int b) { |
| 71 | + return ((uint32_t)((-(int32_t)(a ^ b)) >> (8*sizeof(uint32_t)-1))); |
| 72 | +} |
| 73 | + |
| 74 | +// if a == b -> 0x0000000000000000, else 0xFFFFFFFFFFFFFFFF |
| 75 | +static inline uint64_t ct_compare_64(int a, int b) { |
| 76 | + return ((uint64_t)((-(int64_t)(a ^ b)) >> (8*sizeof(uint64_t)-1))); |
| 77 | +} |
| 78 | + |
| 79 | +// if a == b -> 0x00, else 0xFF |
| 80 | +static inline unsigned char ct_compare_8(unsigned char a, unsigned char b) { |
| 81 | + return ((int8_t)((-(int32_t)(a ^ b)) >> (8*sizeof(uint32_t)-1))); |
| 82 | +} |
| 83 | +#endif |
| 84 | + |
18 | 85 | #if defined(MAYO_AVX) || defined(MAYO_NEON)
|
19 | 86 | #include <shuffle_arithmetic.h>
|
20 | 87 | #elif defined(MAYO_M4)
|
@@ -45,5 +112,13 @@ void m_upper(const mayo_params_t* p, const uint64_t *in, uint64_t *out, int size
|
45 | 112 | #define sample_solution MAYO_NAMESPACE(sample_solution)
|
46 | 113 | int sample_solution(const mayo_params_t *p, unsigned char *A, const unsigned char *y, const unsigned char *r, unsigned char *x, int k, int o, int m, int A_cols);
|
47 | 114 |
|
| 115 | +#if defined(__GNUC__) || defined(__clang__) |
| 116 | +#define BSWAP32(i) __builtin_bswap32((i)) |
| 117 | +#define BSWAP64(i) __builtin_bswap64((i)) |
| 118 | +#else |
| 119 | +#define BSWAP32(i) ((((i) >> 24) & 0xff) | (((i) >> 8) & 0xff00) | (((i) & 0xff00) << 8) | ((i) << 24)) |
| 120 | +#define BSWAP64(i) ((BSWAP32((i) >> 32) & 0xffffffff) | (BSWAP32(i) << 32)) |
| 121 | +#endif |
| 122 | + |
48 | 123 | #endif
|
49 | 124 |
|
0 commit comments