diff options
| author | Paul Eggert | 2024-05-18 19:12:55 -0700 |
|---|---|---|
| committer | Paul Eggert | 2024-05-19 08:58:14 -0700 |
| commit | c07160b8df4e9f795dd73f08a3399ccef465c898 (patch) | |
| tree | 1c3b3eddbb19ef67bc0db000e2acf6aca6ac47d4 /lib | |
| parent | 370a386633b081107d30a00463dd0fe8d81b7e0f (diff) | |
| download | emacs-c07160b8df4e9f795dd73f08a3399ccef465c898.tar.gz emacs-c07160b8df4e9f795dd73f08a3399ccef465c898.zip | |
Update from Gnulib by running admin/merge-gnulib
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sha512.c | 2 | ||||
| -rw-r--r-- | lib/stdlib.in.h | 8 | ||||
| -rw-r--r-- | lib/u64.h | 60 |
3 files changed, 49 insertions, 21 deletions
diff --git a/lib/sha512.c b/lib/sha512.c index 9eb036fb327..6750041bc7b 100644 --- a/lib/sha512.c +++ b/lib/sha512.c | |||
| @@ -35,7 +35,7 @@ | |||
| 35 | #ifdef WORDS_BIGENDIAN | 35 | #ifdef WORDS_BIGENDIAN |
| 36 | # define SWAP(n) (n) | 36 | # define SWAP(n) (n) |
| 37 | #else | 37 | #else |
| 38 | # define SWAP(n) bswap_64 (n) | 38 | # define SWAP(n) u64bswap (n) |
| 39 | #endif | 39 | #endif |
| 40 | 40 | ||
| 41 | #if ! HAVE_OPENSSL_SHA512 | 41 | #if ! HAVE_OPENSSL_SHA512 |
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index 1888d3ee314..ef9fde30eb2 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h | |||
| @@ -231,6 +231,14 @@ _GL_CXXALIAS_SYS (abort, void, (void)); | |||
| 231 | _GL_CXXALIASWARN (abort); | 231 | _GL_CXXALIASWARN (abort); |
| 232 | # endif | 232 | # endif |
| 233 | #endif | 233 | #endif |
| 234 | #if @GNULIB_ABORT_DEBUG@ && @REPLACE_ABORT@ | ||
| 235 | _GL_EXTERN_C void _gl_pre_abort (void); | ||
| 236 | #else | ||
| 237 | # if !GNULIB_defined_gl_pre_abort | ||
| 238 | # define _gl_pre_abort() /* nothing */ | ||
| 239 | # define GNULIB_defined_gl_pre_abort 1 | ||
| 240 | # endif | ||
| 241 | #endif | ||
| 234 | 242 | ||
| 235 | 243 | ||
| 236 | #if @GNULIB_FREE_POSIX@ | 244 | #if @GNULIB_FREE_POSIX@ |
| @@ -22,8 +22,11 @@ | |||
| 22 | #error "Please include config.h first." | 22 | #error "Please include config.h first." |
| 23 | #endif | 23 | #endif |
| 24 | 24 | ||
| 25 | #include <stddef.h> | ||
| 25 | #include <stdint.h> | 26 | #include <stdint.h> |
| 26 | 27 | ||
| 28 | #include <byteswap.h> | ||
| 29 | |||
| 27 | _GL_INLINE_HEADER_BEGIN | 30 | _GL_INLINE_HEADER_BEGIN |
| 28 | #ifndef _GL_U64_INLINE | 31 | #ifndef _GL_U64_INLINE |
| 29 | # define _GL_U64_INLINE _GL_INLINE | 32 | # define _GL_U64_INLINE _GL_INLINE |
| @@ -34,9 +37,6 @@ extern "C" { | |||
| 34 | #endif | 37 | #endif |
| 35 | 38 | ||
| 36 | 39 | ||
| 37 | /* Return X rotated left by N bits, where 0 < N < 64. */ | ||
| 38 | #define u64rol(x, n) u64or (u64shl (x, n), u64shr (x, 64 - n)) | ||
| 39 | |||
| 40 | #ifdef UINT64_MAX | 40 | #ifdef UINT64_MAX |
| 41 | 41 | ||
| 42 | /* Native implementations are trivial. See below for comments on what | 42 | /* Native implementations are trivial. See below for comments on what |
| @@ -53,24 +53,30 @@ typedef uint64_t u64; | |||
| 53 | # define u64plus(x, y) ((x) + (y)) | 53 | # define u64plus(x, y) ((x) + (y)) |
| 54 | # define u64shl(x, n) ((x) << (n)) | 54 | # define u64shl(x, n) ((x) << (n)) |
| 55 | # define u64shr(x, n) ((x) >> (n)) | 55 | # define u64shr(x, n) ((x) >> (n)) |
| 56 | # define u64bswap(x) bswap_64 (x) | ||
| 56 | 57 | ||
| 57 | #else | 58 | #else |
| 58 | 59 | ||
| 59 | /* u64 is a 64-bit unsigned integer value. | 60 | # define _GL_U64_MASK32 0xfffffffful /* 2**32 - 1. */ |
| 61 | |||
| 62 | /* u64 represents a 64-bit unsigned integer value equal to (HI << 32) + LO. | ||
| 63 | Implement it with unsigned int, which the GNU coding standards say | ||
| 64 | is wide enough to hold 32 bits, and which does not signal an error | ||
| 65 | when adding (theoretically possible with types like uint_fast32_t). | ||
| 60 | u64init (HI, LO), is like u64hilo (HI, LO), but for use in | 66 | u64init (HI, LO), is like u64hilo (HI, LO), but for use in |
| 61 | initializer contexts. */ | 67 | initializer contexts. */ |
| 62 | # ifdef WORDS_BIGENDIAN | 68 | # ifdef WORDS_BIGENDIAN |
| 63 | typedef struct { uint32_t hi, lo; } u64; | 69 | typedef struct { unsigned int hi, lo; } u64; |
| 64 | # define u64init(hi, lo) { hi, lo } | 70 | # define u64init(hi, lo) { hi, lo } |
| 65 | # else | 71 | # else |
| 66 | typedef struct { uint32_t lo, hi; } u64; | 72 | typedef struct { unsigned int lo, hi; } u64; |
| 67 | # define u64init(hi, lo) { lo, hi } | 73 | # define u64init(hi, lo) { lo, hi } |
| 68 | # endif | 74 | # endif |
| 69 | 75 | ||
| 70 | /* Given the high and low-order 32-bit quantities HI and LO, return a u64 | 76 | /* Given the high and low-order 32-bit quantities HI and LO, return a u64 |
| 71 | value representing (HI << 32) + LO. */ | 77 | value representing (HI << 32) + LO. */ |
| 72 | _GL_U64_INLINE u64 | 78 | _GL_U64_INLINE u64 |
| 73 | u64hilo (uint32_t hi, uint32_t lo) | 79 | u64hilo (unsigned int hi, unsigned int lo) |
| 74 | { | 80 | { |
| 75 | u64 r; | 81 | u64 r; |
| 76 | r.hi = hi; | 82 | r.hi = hi; |
| @@ -78,9 +84,9 @@ u64hilo (uint32_t hi, uint32_t lo) | |||
| 78 | return r; | 84 | return r; |
| 79 | } | 85 | } |
| 80 | 86 | ||
| 81 | /* Return a u64 value representing LO. */ | 87 | /* Return a u64 value representing the 32-bit quantity LO. */ |
| 82 | _GL_U64_INLINE u64 | 88 | _GL_U64_INLINE u64 |
| 83 | u64lo (uint32_t lo) | 89 | u64lo (unsigned int lo) |
| 84 | { | 90 | { |
| 85 | u64 r; | 91 | u64 r; |
| 86 | r.hi = 0; | 92 | r.hi = 0; |
| @@ -88,18 +94,18 @@ u64lo (uint32_t lo) | |||
| 88 | return r; | 94 | return r; |
| 89 | } | 95 | } |
| 90 | 96 | ||
| 91 | /* Return a u64 value representing SIZE. */ | 97 | /* Return a u64 value representing SIZE, where 0 <= SIZE < 2**64. */ |
| 92 | _GL_U64_INLINE u64 | 98 | _GL_U64_INLINE u64 |
| 93 | u64size (size_t size) | 99 | u64size (size_t size) |
| 94 | { | 100 | { |
| 95 | u64 r; | 101 | u64 r; |
| 96 | r.hi = size >> 31 >> 1; | 102 | r.hi = size >> 31 >> 1; |
| 97 | r.lo = size; | 103 | r.lo = size & _GL_U64_MASK32; |
| 98 | return r; | 104 | return r; |
| 99 | } | 105 | } |
| 100 | 106 | ||
| 101 | /* Return X < Y. */ | 107 | /* Return X < Y. */ |
| 102 | _GL_U64_INLINE int | 108 | _GL_U64_INLINE bool |
| 103 | u64lt (u64 x, u64 y) | 109 | u64lt (u64 x, u64 y) |
| 104 | { | 110 | { |
| 105 | return x.hi < y.hi || (x.hi == y.hi && x.lo < y.lo); | 111 | return x.hi < y.hi || (x.hi == y.hi && x.lo < y.lo); |
| @@ -135,29 +141,29 @@ u64xor (u64 x, u64 y) | |||
| 135 | return r; | 141 | return r; |
| 136 | } | 142 | } |
| 137 | 143 | ||
| 138 | /* Return X + Y. */ | 144 | /* Return X + Y, wrapping around on overflow. */ |
| 139 | _GL_U64_INLINE u64 | 145 | _GL_U64_INLINE u64 |
| 140 | u64plus (u64 x, u64 y) | 146 | u64plus (u64 x, u64 y) |
| 141 | { | 147 | { |
| 142 | u64 r; | 148 | u64 r; |
| 143 | r.lo = x.lo + y.lo; | 149 | r.lo = (x.lo + y.lo) & _GL_U64_MASK32; |
| 144 | r.hi = x.hi + y.hi + (r.lo < x.lo); | 150 | r.hi = (x.hi + y.hi + (r.lo < x.lo)) & _GL_U64_MASK32; |
| 145 | return r; | 151 | return r; |
| 146 | } | 152 | } |
| 147 | 153 | ||
| 148 | /* Return X << N. */ | 154 | /* Return X << N, where 0 <= N < 64. */ |
| 149 | _GL_U64_INLINE u64 | 155 | _GL_U64_INLINE u64 |
| 150 | u64shl (u64 x, int n) | 156 | u64shl (u64 x, int n) |
| 151 | { | 157 | { |
| 152 | u64 r; | 158 | u64 r; |
| 153 | if (n < 32) | 159 | if (n < 32) |
| 154 | { | 160 | { |
| 155 | r.hi = (x.hi << n) | (x.lo >> (32 - n)); | 161 | r.hi = (x.hi << n & _GL_U64_MASK32) | x.lo >> (32 - n); |
| 156 | r.lo = x.lo << n; | 162 | r.lo = x.lo << n & _GL_U64_MASK32; |
| 157 | } | 163 | } |
| 158 | else | 164 | else |
| 159 | { | 165 | { |
| 160 | r.hi = x.lo << (n - 32); | 166 | r.hi = x.lo << (n - 32) & _GL_U64_MASK32; |
| 161 | r.lo = 0; | 167 | r.lo = 0; |
| 162 | } | 168 | } |
| 163 | return r; | 169 | return r; |
| @@ -171,7 +177,7 @@ u64shr (u64 x, int n) | |||
| 171 | if (n < 32) | 177 | if (n < 32) |
| 172 | { | 178 | { |
| 173 | r.hi = x.hi >> n; | 179 | r.hi = x.hi >> n; |
| 174 | r.lo = (x.hi << (32 - n)) | (x.lo >> n); | 180 | r.lo = (x.hi << (32 - n) & _GL_U64_MASK32) | x.lo >> n; |
| 175 | } | 181 | } |
| 176 | else | 182 | else |
| 177 | { | 183 | { |
| @@ -181,8 +187,22 @@ u64shr (u64 x, int n) | |||
| 181 | return r; | 187 | return r; |
| 182 | } | 188 | } |
| 183 | 189 | ||
| 190 | /* Return X with bytes in reverse order. */ | ||
| 191 | _GL_U64_INLINE u64 | ||
| 192 | u64bswap (u64 x) | ||
| 193 | { | ||
| 194 | return u64hilo (bswap_32 (x.lo), bswap_32 (x.hi)); | ||
| 195 | } | ||
| 196 | |||
| 184 | #endif | 197 | #endif |
| 185 | 198 | ||
| 199 | /* Return X rotated left by N bits, where 0 < N < 64. */ | ||
| 200 | _GL_U64_INLINE u64 | ||
| 201 | u64rol (u64 x, int n) | ||
| 202 | { | ||
| 203 | return u64or (u64shl (x, n), u64shr (x, 64 - n)); | ||
| 204 | } | ||
| 205 | |||
| 186 | 206 | ||
| 187 | #ifdef __cplusplus | 207 | #ifdef __cplusplus |
| 188 | } | 208 | } |