7 #ifndef SECP256K1_UTIL_H
8 #define SECP256K1_UTIL_H
10 #if defined HAVE_CONFIG_H
11 #include "libsecp256k1-config.h"
19 void (*fn)(
const char *text,
void* data);
28 #define TEST_FAILURE(msg) do { \
29 fprintf(stderr, "%s\n", msg); \
33 #define TEST_FAILURE(msg) do { \
34 fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, msg); \
39 #ifdef HAVE_BUILTIN_EXPECT
40 #define EXPECT(x,c) __builtin_expect((x),(c))
42 #define EXPECT(x,c) (x)
46 #define CHECK(cond) do { \
47 if (EXPECT(!(cond), 0)) { \
48 TEST_FAILURE("test condition failed"); \
52 #define CHECK(cond) do { \
53 if (EXPECT(!(cond), 0)) { \
54 TEST_FAILURE("test condition failed: " #cond); \
61 #define VERIFY_CHECK(check)
62 #define VERIFY_SETUP(stmt)
64 #define VERIFY_CHECK CHECK
65 #define VERIFY_SETUP(stmt) do { stmt; } while(0)
67 #define VERIFY_CHECK(cond) do { (void)(cond); } while(0)
68 #define VERIFY_SETUP(stmt)
72 void *ret = malloc(size);
74 secp256k1_callback_call(cb,
"Out of memory");
80 void *ret = realloc(ptr, size);
82 secp256k1_callback_call(cb,
"Out of memory");
88 SECP256K1_INLINE static int secp256k1_sign_and_abs64(uint64_t *out, int64_t in) {
89 uint64_t mask0, mask1;
92 mask0 = ret + ~((uint64_t)0);
95 *out = (*out & mask0) | ((~*out + 1) & mask1);
104 # if defined(HAVE_BUILTIN_CLZLL)
105 ret = __builtin_clzll(x);
108 for (ret = 0; ((x & (1ULL << 63)) == 0); x <<= 1, ret++);
114 #if defined(SECP256K1_BUILD) && defined(VERIFY)
115 # define SECP256K1_RESTRICT
117 # if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) )
118 # if SECP256K1_GNUC_PREREQ(3,0)
119 # define SECP256K1_RESTRICT __restrict__
120 # elif (defined(_MSC_VER) && _MSC_VER >= 1400)
121 # define SECP256K1_RESTRICT __restrict
123 # define SECP256K1_RESTRICT
126 # define SECP256K1_RESTRICT restrict
131 # define I64FORMAT "I64d"
132 # define I64uFORMAT "I64u"
134 # define I64FORMAT "lld"
135 # define I64uFORMAT "llu"
138 #if defined(HAVE___INT128)
139 # if defined(__GNUC__)
140 # define SECP256K1_GNUC_EXT __extension__
142 # define SECP256K1_GNUC_EXT
144 SECP256K1_GNUC_EXT
typedef unsigned __int128
uint128_t;