From 2df963666ddd90691caaf8505a8f424efc583efb Mon Sep 17 00:00:00 2001 From: Ben Gamari <ben@smart-cactus.org> Date: Mon, 22 Jan 2024 17:09:26 -0500 Subject: [PATCH] base: Cleanup whitespace in cbits --- libraries/base/cbits/consUtils.c | 22 +-- libraries/base/cbits/iconv.c | 10 +- libraries/base/cbits/md5.c | 282 +++++++++++++++---------------- libraries/base/cbits/primFloat.c | 250 ++++++++++++++------------- libraries/base/include/HsBase.h | 22 +-- libraries/base/include/HsEvent.h | 6 +- libraries/base/include/md5.h | 6 +- 7 files changed, 298 insertions(+), 300 deletions(-) diff --git a/libraries/base/cbits/consUtils.c b/libraries/base/cbits/consUtils.c index ac5d3ea75a1f..0a76ed940267 100644 --- a/libraries/base/cbits/consUtils.c +++ b/libraries/base/cbits/consUtils.c @@ -48,10 +48,10 @@ set_console_buffering__(int fd, int cooked) DWORD flgs = ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT; if ( (h = (HANDLE)_get_osfhandle(fd)) != INVALID_HANDLE_VALUE ) { - if ( GetConsoleMode(h,&st) && - SetConsoleMode(h, cooked ? (st | ENABLE_LINE_INPUT) : st & ~flgs) ) { - return 0; - } + if ( GetConsoleMode(h,&st) && + SetConsoleMode(h, cooked ? (st | ENABLE_LINE_INPUT) : st & ~flgs) ) { + return 0; + } } return -1; } @@ -64,10 +64,10 @@ set_console_echo__(int fd, int on) DWORD flgs = ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT; if ( (h = (HANDLE)_get_osfhandle(fd)) != INVALID_HANDLE_VALUE ) { - if ( GetConsoleMode(h,&st) && - SetConsoleMode(h,( on ? (st | flgs) : (st & ~ENABLE_ECHO_INPUT))) ) { - return 0; - } + if ( GetConsoleMode(h,&st) && + SetConsoleMode(h,( on ? (st | flgs) : (st & ~ENABLE_ECHO_INPUT))) ) { + return 0; + } } return -1; } @@ -79,9 +79,9 @@ get_console_echo__(int fd) DWORD st; if ( (h = (HANDLE)_get_osfhandle(fd)) != INVALID_HANDLE_VALUE ) { - if ( GetConsoleMode(h,&st) ) { - return (st & ENABLE_ECHO_INPUT ? 1 : 0); - } + if ( GetConsoleMode(h,&st) ) { + return (st & ENABLE_ECHO_INPUT ? 1 : 0); + } } return -1; } diff --git a/libraries/base/cbits/iconv.c b/libraries/base/cbits/iconv.c index e1123a43a12e..8643e82c5eab 100644 --- a/libraries/base/cbits/iconv.c +++ b/libraries/base/cbits/iconv.c @@ -4,14 +4,14 @@ #include <iconv.h> iconv_t hs_iconv_open(const char* tocode, - const char* fromcode) + const char* fromcode) { - return iconv_open(tocode, fromcode); + return iconv_open(tocode, fromcode); } size_t hs_iconv(iconv_t cd, - const char* * inbuf, size_t * inbytesleft, - char* * outbuf, size_t * outbytesleft) + const char* * inbuf, size_t * inbytesleft, + char* * outbuf, size_t * outbytesleft) { // (void*) cast avoids a warning. Some iconvs use (const // char**inbuf), other use (char **inbuf). @@ -19,7 +19,7 @@ size_t hs_iconv(iconv_t cd, } int hs_iconv_close(iconv_t cd) { - return iconv_close(cd); + return iconv_close(cd); } #endif diff --git a/libraries/base/cbits/md5.c b/libraries/base/cbits/md5.c index 0d93a8f1f131..4fa83bda7aac 100644 --- a/libraries/base/cbits/md5.c +++ b/libraries/base/cbits/md5.c @@ -32,13 +32,13 @@ void __hsbase_MD5Transform(uint32_t buf[4], uint32_t const in[16]); static void byteSwap(uint32_t *buf, unsigned words) { - uint8_t *p = (uint8_t *)buf; + uint8_t *p = (uint8_t *)buf; - do { - *buf++ = (uint32_t)((unsigned)p[3] << 8 | p[2]) << 16 | - ((unsigned)p[1] << 8 | p[0]); - p += 4; - } while (--words); + do { + *buf++ = (uint32_t)((unsigned)p[3] << 8 | p[2]) << 16 | + ((unsigned)p[1] << 8 | p[0]); + p += 4; + } while (--words); } /* @@ -48,13 +48,13 @@ byteSwap(uint32_t *buf, unsigned words) void __hsbase_MD5Init(struct MD5Context *ctx) { - ctx->buf[0] = 0x67452301; - ctx->buf[1] = 0xefcdab89; - ctx->buf[2] = 0x98badcfe; - ctx->buf[3] = 0x10325476; + ctx->buf[0] = 0x67452301; + ctx->buf[1] = 0xefcdab89; + ctx->buf[2] = 0x98badcfe; + ctx->buf[3] = 0x10325476; - ctx->bytes[0] = 0; - ctx->bytes[1] = 0; + ctx->bytes[0] = 0; + ctx->bytes[1] = 0; } /* @@ -64,73 +64,73 @@ __hsbase_MD5Init(struct MD5Context *ctx) void __hsbase_MD5Update(struct MD5Context *ctx, uint8_t const *buf, int len) { - uint32_t t; - - /* Update byte count */ - - t = ctx->bytes[0]; - if ((ctx->bytes[0] = t + len) < t) - ctx->bytes[1]++; /* Carry from low to high */ - - t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */ - if ((unsigned)t > len) { - memcpy((uint8_t *)ctx->in + 64 - (unsigned)t, buf, len); - return; - } - /* First chunk is an odd size */ - memcpy((uint8_t *)ctx->in + 64 - (unsigned)t, buf, (unsigned)t); - byteSwap(ctx->in, 16); + uint32_t t; + + /* Update byte count */ + + t = ctx->bytes[0]; + if ((ctx->bytes[0] = t + len) < t) + ctx->bytes[1]++; /* Carry from low to high */ + + t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */ + if ((unsigned)t > len) { + memcpy((uint8_t *)ctx->in + 64 - (unsigned)t, buf, len); + return; + } + /* First chunk is an odd size */ + memcpy((uint8_t *)ctx->in + 64 - (unsigned)t, buf, (unsigned)t); + byteSwap(ctx->in, 16); __hsbase_MD5Transform(ctx->buf, ctx->in); - buf += (unsigned)t; - len -= (unsigned)t; + buf += (unsigned)t; + len -= (unsigned)t; - /* Process data in 64-byte chunks */ - while (len >= 64) { - memcpy(ctx->in, buf, 64); - byteSwap(ctx->in, 16); + /* Process data in 64-byte chunks */ + while (len >= 64) { + memcpy(ctx->in, buf, 64); + byteSwap(ctx->in, 16); __hsbase_MD5Transform(ctx->buf, ctx->in); - buf += 64; - len -= 64; - } + buf += 64; + len -= 64; + } - /* Handle any remaining bytes of data. */ - memcpy(ctx->in, buf, len); + /* Handle any remaining bytes of data. */ + memcpy(ctx->in, buf, len); } /* - * Final wrapup - pad to 64-byte boundary with the bit pattern + * Final wrapup - pad to 64-byte boundary with the bit pattern * 1 0* (64-bit count of bits processed, MSB-first) */ void __hsbase_MD5Final(uint8_t digest[16], struct MD5Context *ctx) { - int count = (int)(ctx->bytes[0] & 0x3f); /* Bytes in ctx->in */ - uint8_t *p = (uint8_t *)ctx->in + count; /* First unused byte */ + int count = (int)(ctx->bytes[0] & 0x3f); /* Bytes in ctx->in */ + uint8_t *p = (uint8_t *)ctx->in + count; /* First unused byte */ - /* Set the first char of padding to 0x80. There is always room. */ - *p++ = 0x80; + /* Set the first char of padding to 0x80. There is always room. */ + *p++ = 0x80; - /* Bytes of padding needed to make 56 bytes (-8..55) */ - count = 56 - 1 - count; + /* Bytes of padding needed to make 56 bytes (-8..55) */ + count = 56 - 1 - count; - if (count < 0) { /* Padding forces an extra block */ - memset(p, 0, count+8); - byteSwap(ctx->in, 16); + if (count < 0) { /* Padding forces an extra block */ + memset(p, 0, count+8); + byteSwap(ctx->in, 16); __hsbase_MD5Transform(ctx->buf, ctx->in); - p = (uint8_t *)ctx->in; - count = 56; - } - memset(p, 0, count+8); - byteSwap(ctx->in, 14); - - /* Append length in bits and transform */ - ctx->in[14] = ctx->bytes[0] << 3; - ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29; + p = (uint8_t *)ctx->in; + count = 56; + } + memset(p, 0, count+8); + byteSwap(ctx->in, 14); + + /* Append length in bits and transform */ + ctx->in[14] = ctx->bytes[0] << 3; + ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29; __hsbase_MD5Transform(ctx->buf, ctx->in); - byteSwap(ctx->buf, 4); - memcpy(digest, ctx->buf, 16); - memset(ctx, 0, sizeof(*ctx)); + byteSwap(ctx->buf, 4); + memcpy(digest, ctx->buf, 16); + memset(ctx, 0, sizeof(*ctx)); } @@ -144,7 +144,7 @@ __hsbase_MD5Final(uint8_t digest[16], struct MD5Context *ctx) /* This is the central step in the MD5 algorithm. */ #define MD5STEP(f,w,x,y,z,in,s) \ - (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x) + (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x) /* * The core of the MD5 algorithm, this alters an existing MD5 hash to @@ -155,84 +155,84 @@ __hsbase_MD5Final(uint8_t digest[16], struct MD5Context *ctx) void __hsbase_MD5Transform(uint32_t buf[4], uint32_t const in[16]) { - register uint32_t a, b, c, d; - - a = buf[0]; - b = buf[1]; - c = buf[2]; - d = buf[3]; - - MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); - MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); - MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); - MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); - MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); - MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); - MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); - MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); - MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); - MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); - MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); - MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); - MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); - MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); - MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); - MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); - - MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); - MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); - MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); - MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); - MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); - MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); - MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); - MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); - MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); - MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); - MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); - MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); - MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); - MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); - MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); - MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); - - MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); - MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); - MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); - MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); - MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); - MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); - MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); - MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); - MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); - MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); - MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); - MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); - MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); - MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); - MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); - MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); - - MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); - MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); - MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); - MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); - MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); - MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); - MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); - MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); - MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); - MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); - MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); - MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); - MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); - MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); - MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); - MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); - - buf[0] += a; - buf[1] += b; - buf[2] += c; - buf[3] += d; + register uint32_t a, b, c, d; + + a = buf[0]; + b = buf[1]; + c = buf[2]; + d = buf[3]; + + MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); + MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); + MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); + MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); + MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); + MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); + MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); + MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); + MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); + MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); + MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); + MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); + MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); + MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); + MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); + MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); + + MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); + MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); + MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); + MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); + MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); + MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); + MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); + MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); + MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); + MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); + MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); + MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); + MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); + MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); + MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); + MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); + + MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); + MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); + MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); + MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); + MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); + MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); + MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); + MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); + MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); + MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); + MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); + MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); + MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); + MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); + MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); + MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); + + MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); + MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); + MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); + MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); + MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); + MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); + MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); + MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); + MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); + MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); + MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); + MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); + MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); + MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); + MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); + MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); + + buf[0] += a; + buf[1] += b; + buf[2] += c; + buf[3] += d; } diff --git a/libraries/base/cbits/primFloat.c b/libraries/base/cbits/primFloat.c index dde5d0650364..b20aa33e743e 100644 --- a/libraries/base/cbits/primFloat.c +++ b/libraries/base/cbits/primFloat.c @@ -5,7 +5,8 @@ * * Miscellaneous support for floating-point primitives * - * ---------------------------------------------------------------------------*/ + * --------------------------------------------------------------------------- + */ #include "HsFFI.h" #include "Rts.h" // XXX wrong (for IEEE_FLOATING_POINT and WORDS_BIGENDIAN) @@ -14,94 +15,91 @@ union stg_ieee754_flt { - float f; - struct { - + float f; + struct { #if WORDS_BIGENDIAN - unsigned int negative:1; - unsigned int exponent:8; - unsigned int mantissa:23; + unsigned int negative:1; + unsigned int exponent:8; + unsigned int mantissa:23; #else - unsigned int mantissa:23; - unsigned int exponent:8; - unsigned int negative:1; + unsigned int mantissa:23; + unsigned int exponent:8; + unsigned int negative:1; #endif - } ieee; - struct { + } ieee; + struct { #if WORDS_BIGENDIAN - unsigned int negative:1; - unsigned int exponent:8; - unsigned int quiet_nan:1; - unsigned int mantissa:22; + unsigned int negative:1; + unsigned int exponent:8; + unsigned int quiet_nan:1; + unsigned int mantissa:22; #else - unsigned int mantissa:22; - unsigned int quiet_nan:1; - unsigned int exponent:8; - unsigned int negative:1; + unsigned int mantissa:22; + unsigned int quiet_nan:1; + unsigned int exponent:8; + unsigned int negative:1; #endif - } ieee_nan; + } ieee_nan; }; /* - - To recap, here's the representation of a double precision - IEEE floating point number: - - sign 63 sign bit (0==positive, 1==negative) - exponent 62-52 exponent (biased by 1023) - fraction 51-0 fraction (bits to right of binary point) -*/ + * To recap, here's the representation of a double precision + * IEEE floating point number: + * + * sign 63 sign bit (0==positive, 1==negative) + * exponent 62-52 exponent (biased by 1023) + * fraction 51-0 fraction (bits to right of binary point) + */ union stg_ieee754_dbl { - double d; - struct { - + double d; + struct { #if WORDS_BIGENDIAN - unsigned int negative:1; - unsigned int exponent:11; - unsigned int mantissa0:20; - unsigned int mantissa1:32; + unsigned int negative:1; + unsigned int exponent:11; + unsigned int mantissa0:20; + unsigned int mantissa1:32; #else #if FLOAT_WORDS_BIGENDIAN - unsigned int mantissa0:20; - unsigned int exponent:11; - unsigned int negative:1; - unsigned int mantissa1:32; + unsigned int mantissa0:20; + unsigned int exponent:11; + unsigned int negative:1; + unsigned int mantissa1:32; #else - unsigned int mantissa1:32; - unsigned int mantissa0:20; - unsigned int exponent:11; - unsigned int negative:1; + unsigned int mantissa1:32; + unsigned int mantissa0:20; + unsigned int exponent:11; + unsigned int negative:1; #endif #endif - } ieee; - /* This format makes it easier to see if a NaN is a signalling NaN. */ - struct { + } ieee; + /* This format makes it easier to see if a NaN is a signalling NaN. */ + struct { #if WORDS_BIGENDIAN - unsigned int negative:1; - unsigned int exponent:11; - unsigned int quiet_nan:1; - unsigned int mantissa0:19; - unsigned int mantissa1:32; + unsigned int negative:1; + unsigned int exponent:11; + unsigned int quiet_nan:1; + unsigned int mantissa0:19; + unsigned int mantissa1:32; #else #if FLOAT_WORDS_BIGENDIAN - unsigned int mantissa0:19; - unsigned int quiet_nan:1; - unsigned int exponent:11; - unsigned int negative:1; - unsigned int mantissa1:32; + unsigned int mantissa0:19; + unsigned int quiet_nan:1; + unsigned int exponent:11; + unsigned int negative:1; + unsigned int mantissa1:32; #else - unsigned int mantissa1:32; - unsigned int mantissa0:19; - unsigned int quiet_nan:1; - unsigned int exponent:11; - unsigned int negative:1; + unsigned int mantissa1:32; + unsigned int mantissa0:19; + unsigned int quiet_nan:1; + unsigned int exponent:11; + unsigned int negative:1; #endif #endif - } ieee_nan; + } ieee_nan; }; /* @@ -114,24 +112,24 @@ union stg_ieee754_dbl HsInt isDoubleFinite(HsDouble d) { - union stg_ieee754_dbl u; + union stg_ieee754_dbl u; - u.d = d; + u.d = d; - return u.ieee.exponent != 2047; + return u.ieee.exponent != 2047; } HsInt isDoubleNaN(HsDouble d) { - union stg_ieee754_dbl u; + union stg_ieee754_dbl u; - u.d = d; + u.d = d; - return ( - u.ieee.exponent == 2047 /* 2^11 - 1 */ && /* Is the exponent all ones? */ - (u.ieee.mantissa0 != 0 || u.ieee.mantissa1 != 0) - /* and the mantissa non-zero? */ + return ( + u.ieee.exponent == 2047 /* 2^11 - 1 */ && /* Is the exponent all ones? */ + (u.ieee.mantissa0 != 0 || u.ieee.mantissa1 != 0) + /* and the mantissa non-zero? */ ); } @@ -142,12 +140,12 @@ isDoubleInfinite(HsDouble d) u.d = d; - /* Inf iff exponent is all ones, mantissa all zeros */ + /* Inf iff exponent is all ones, mantissa all zeros */ return ( u.ieee.exponent == 2047 /* 2^11 - 1 */ && - u.ieee.mantissa0 == 0 && - u.ieee.mantissa1 == 0 - ); + u.ieee.mantissa0 == 0 && + u.ieee.mantissa1 == 0 + ); } HsInt @@ -157,19 +155,17 @@ isDoubleDenormalized(HsDouble d) u.d = d; - /* A (single/double/quad) precision floating point number - is denormalised iff: - - exponent is zero - - mantissa is non-zero. - - (don't care about setting of sign bit.) + /* A (single/double/quad) precision floating point number + is denormalised iff: + - exponent is zero + - mantissa is non-zero. + - (don't care about setting of sign bit.) - */ + */ return ( - u.ieee.exponent == 0 && - (u.ieee.mantissa0 != 0 || - u.ieee.mantissa1 != 0) - ); - + u.ieee.exponent == 0 && + (u.ieee.mantissa0 != 0 || + u.ieee.mantissa1 != 0)); } HsInt @@ -181,23 +177,22 @@ isDoubleNegativeZero(HsDouble d) /* sign (bit 63) set (only) => negative zero */ return ( - u.ieee.negative == 1 && - u.ieee.exponent == 0 && - u.ieee.mantissa0 == 0 && - u.ieee.mantissa1 == 0); + u.ieee.negative == 1 && + u.ieee.exponent == 0 && + u.ieee.mantissa0 == 0 && + u.ieee.mantissa1 == 0); } /* Same tests, this time for HsFloats. */ /* - To recap, here's the representation of a single precision - IEEE floating point number: - - sign 31 sign bit (0 == positive, 1 == negative) - exponent 30-23 exponent (biased by 127) - fraction 22-0 fraction (bits to right of binary point) -*/ - + * To recap, here's the representation of a single precision + * IEEE floating point number: + * + * sign 31 sign bit (0 == positive, 1 == negative) + * exponent 30-23 exponent (biased by 127) + * fraction 22-0 fraction (bits to right of binary point) + */ HsInt isFloatFinite(HsFloat f) @@ -213,11 +208,11 @@ isFloatNaN(HsFloat f) union stg_ieee754_flt u; u.f = f; - /* Floating point NaN iff exponent is all ones, mantissa is - non-zero (but see below.) */ - return ( - u.ieee.exponent == 255 /* 2^8 - 1 */ && - u.ieee.mantissa != 0); + /* Floating point NaN iff exponent is all ones, mantissa is + * non-zero (but see below.) */ + return ( + u.ieee.exponent == 255 /* 2^8 - 1 */ && + u.ieee.mantissa != 0); } HsInt @@ -227,10 +222,10 @@ isFloatInfinite(HsFloat f) u.f = f; /* A float is Inf iff exponent is max (all ones), - and mantissa is min(all zeros.) */ + * and mantissa is min(all zeros.) */ return ( - u.ieee.exponent == 255 /* 2^8 - 1 */ && - u.ieee.mantissa == 0); + u.ieee.exponent == 255 /* 2^8 - 1 */ && + u.ieee.mantissa == 0); } HsInt @@ -239,16 +234,16 @@ isFloatDenormalized(HsFloat f) union stg_ieee754_flt u; u.f = f; - /* A (single/double/quad) precision floating point number - is denormalised iff: - - exponent is zero - - mantissa is non-zero. - - (don't care about setting of sign bit.) - - */ + /* + * A (single/double/quad) precision floating point number + * is denormalised iff: + * - exponent is zero + * - mantissa is non-zero. + * - (don't care about setting of sign bit.) + */ return ( - u.ieee.exponent == 0 && - u.ieee.mantissa != 0); + u.ieee.exponent == 0 && + u.ieee.mantissa != 0); } HsInt @@ -257,17 +252,17 @@ isFloatNegativeZero(HsFloat f) union stg_ieee754_flt u; u.f = f; - /* sign (bit 31) set (only) => negative zero */ + /* sign (bit 31) set (only) => negative zero */ return ( - u.ieee.negative && - u.ieee.exponent == 0 && - u.ieee.mantissa == 0); + u.ieee.negative && + u.ieee.exponent == 0 && + u.ieee.mantissa == 0); } /* - There are glibc versions around with buggy rintf or rint, hence we - provide our own. We always round ties to even, so we can be simpler. -*/ + * There are glibc versions around with buggy rintf or rint, hence we + * provide our own. We always round ties to even, so we can be simpler. + */ #define FLT_HIDDEN 0x800000 #define FLT_POWER2 0x1000000 @@ -277,6 +272,7 @@ rintFloat(HsFloat f) { union stg_ieee754_flt u; u.f = f; + /* if real exponent > 22, it's already integral, infinite or nan */ if (u.ieee.exponent > 149) /* 22 + 127 */ { @@ -457,9 +453,11 @@ HsInt isFloatDenormalized(HsFloat f) { return 0; } HsInt isFloatNegativeZero(HsFloat f) { return 0; } -/* For exotic floating point formats, we can't do much */ -/* We suppose the format has not too many bits */ -/* I hope nobody tries to build GHC where this is wrong */ +/* + * For exotic floating point formats, we can't do much + * We suppose the format has not too many bits + * I hope nobody tries to build GHC where this is wrong + */ #define FLT_UPP 536870912.0 diff --git a/libraries/base/include/HsBase.h b/libraries/base/include/HsBase.h index d883eb8d64a9..0e159237e39f 100644 --- a/libraries/base/include/HsBase.h +++ b/libraries/base/include/HsBase.h @@ -117,7 +117,7 @@ #if !HAVE_GETRUSAGE && HAVE_SYS_SYSCALL_H # include <sys/syscall.h> -# if defined(SYS_GETRUSAGE) /* hpux_HOST_OS */ +# if defined(SYS_GETRUSAGE) /* hpux_HOST_OS */ # define getrusage(a, b) syscall(SYS_GETRUSAGE, a, b) # define HAVE_GETRUSAGE 1 # endif @@ -327,23 +327,23 @@ INLINE ino_t __hscore_st_ino ( struct_stat* st ) { return st->st_ino; } #if defined(_WIN32) INLINE int __hscore_stat(wchar_t *file, struct_stat *buf) { - return _wstati64(file,buf); + return _wstati64(file,buf); } INLINE int __hscore_fstat(int fd, struct_stat *buf) { - return _fstati64(fd,buf); + return _fstati64(fd,buf); } INLINE int __hscore_lstat(wchar_t *fname, struct_stat *buf ) { - return _wstati64(fname,buf); + return _wstati64(fname,buf); } #else INLINE int __hscore_stat(char *file, struct_stat *buf) { - return stat(file,buf); + return stat(file,buf); } INLINE int __hscore_fstat(int fd, struct_stat *buf) { - return fstat(fd,buf); + return fstat(fd,buf); } INLINE int __hscore_lstat( const char *fname, struct stat *buf ) @@ -520,11 +520,11 @@ extern int __hs_swopen (const wchar_t* filename, int oflag, int shflag, INLINE int __hscore_open(wchar_t *file, int how, mode_t mode) { int result = -1; - if ((how & O_WRONLY) || (how & O_RDWR) || (how & O_APPEND)) - result = __hs_swopen(file,how | _O_NOINHERIT,_SH_DENYNO,mode); + if ((how & O_WRONLY) || (how & O_RDWR) || (how & O_APPEND)) + result = __hs_swopen(file,how | _O_NOINHERIT,_SH_DENYNO,mode); // _O_NOINHERIT: see #2650 - else - result = __hs_swopen(file,how | _O_NOINHERIT,_SH_DENYNO,mode); + else + result = __hs_swopen(file,how | _O_NOINHERIT,_SH_DENYNO,mode); // _O_NOINHERIT: see #2650 /* This call is very important, otherwise the I/O system will not propagate @@ -536,7 +536,7 @@ INLINE int __hscore_open(wchar_t *file, int how, mode_t mode) { } #else INLINE int __hscore_open(char *file, int how, mode_t mode) { - return open(file,how,mode); + return open(file,how,mode); } #endif diff --git a/libraries/base/include/HsEvent.h b/libraries/base/include/HsEvent.h index e2fb629e3511..248f4e983884 100644 --- a/libraries/base/include/HsEvent.h +++ b/libraries/base/include/HsEvent.h @@ -33,7 +33,7 @@ INLINE int __hsevent_kill_thread(pthread_t *tid, int sig) } /* - * Local Variables: - * c-file-style: "stroustrup" - * End: + * Local Variables: + * c-file-style: "stroustrup" + * End: */ diff --git a/libraries/base/include/md5.h b/libraries/base/include/md5.h index 8d3441617a7b..a87296687a2f 100644 --- a/libraries/base/include/md5.h +++ b/libraries/base/include/md5.h @@ -4,9 +4,9 @@ #include <stdint.h> struct MD5Context { - uint32_t buf[4]; - uint32_t bytes[2]; - uint32_t in[16]; + uint32_t buf[4]; + uint32_t bytes[2]; + uint32_t in[16]; }; void __hsbase_MD5Init(struct MD5Context *context); -- GitLab