Add TODOs for using MSVC intrinsics

This commit is contained in:
Nigel Tao committed 2021-03-10 14:22:11 +11:00
1 parent 334974f56e
commit e16fbafdca
3 files changed
+6 -2

No files matched your search

+2
View File
@@ -552,6 +552,7 @@ wuffs_base__multiply_u64(uint64_t x, uint64_t y) {
o.hi = ((uint64_t)(z >> 64));
return o;
#else
// TODO: consider using the _mul128 intrinsic if defined(_MSC_VER).
uint64_t x0 = x & 0xFFFFFFFF;
uint64_t x1 = x >> 32;
uint64_t y0 = y & 0xFFFFFFFF;
@@ -578,6 +579,7 @@ wuffs_base__count_leading_zeroes_u64(uint64_t u) {
}
#else
// TODO: consider using the _BitScanReverse intrinsic if defined(_MSC_VER).
static inline uint32_t //
wuffs_base__count_leading_zeroes_u64(uint64_t u) {
+2 -2
View File
@@ -90,9 +90,9 @@ const BaseFundamentalPublicH = "" +
"// --------\n\n// Saturating arithmetic (sat_add, sat_sub) branchless bit-twiddling algorithms\n// are per https://locklessinc.com/articles/sat_arithmetic/\n//\n// It is important that the underlying types are unsigned integers, as signed\n// integer arithmetic overflow is undefined behavior in C.\n\nstatic inline uint8_t //\nwuffs_base__u8__sat_add(uint8_t x, uint8_t y) {\n uint8_t res = (uint8_t)(x + y);\n res |= (uint8_t)(-(res < x));\n return res;\n}\n\nstatic inline uint8_t //\nwuffs_base__u8__sat_sub(uint8_t x, uint8_t y) {\n uint8_t res = (uint8_t)(x - y);\n res &= (uint8_t)(-(res <= x));\n return res;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__sat_add(uint16_t x, uint16_t y) {\n uint16_t res = (uint16_t)(x + y);\n res |= (uint16_t)(-(res < x));\n return res;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__sat_sub(uint16_t x, uint16_t y) {\n uint16_t res = (uint16_t)(x - y);\n res &= (uint16_t)(-(res <= x));\n return res;\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__sat_add(uint32_t x, uint32_t y) {\n uint32" +
"_t res = (uint32_t)(x + y);\n res |= (uint32_t)(-(res < x));\n return res;\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__sat_sub(uint32_t x, uint32_t y) {\n uint32_t res = (uint32_t)(x - y);\n res &= (uint32_t)(-(res <= x));\n return res;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__sat_add(uint64_t x, uint64_t y) {\n uint64_t res = (uint64_t)(x + y);\n res |= (uint64_t)(-(res < x));\n return res;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__sat_sub(uint64_t x, uint64_t y) {\n uint64_t res = (uint64_t)(x - y);\n res &= (uint64_t)(-(res <= x));\n return res;\n}\n\n" +
"" +
"// --------\n\ntypedef struct wuffs_base__multiply_u64__output__struct {\n uint64_t lo;\n uint64_t hi;\n} wuffs_base__multiply_u64__output;\n\n// wuffs_base__multiply_u64 returns x*y as a 128-bit value.\n//\n// The maximum inclusive output hi_lo is 0xFFFFFFFFFFFFFFFE_0000000000000001.\nstatic inline wuffs_base__multiply_u64__output //\nwuffs_base__multiply_u64(uint64_t x, uint64_t y) {\n#if defined(__SIZEOF_INT128__)\n __uint128_t z = ((__uint128_t)x) * ((__uint128_t)y);\n wuffs_base__multiply_u64__output o;\n o.lo = ((uint64_t)(z));\n o.hi = ((uint64_t)(z >> 64));\n return o;\n#else\n uint64_t x0 = x & 0xFFFFFFFF;\n uint64_t x1 = x >> 32;\n uint64_t y0 = y & 0xFFFFFFFF;\n uint64_t y1 = y >> 32;\n uint64_t w0 = x0 * y0;\n uint64_t t = (x1 * y0) + (w0 >> 32);\n uint64_t w1 = t & 0xFFFFFFFF;\n uint64_t w2 = t >> 32;\n w1 += x0 * y1;\n wuffs_base__multiply_u64__output o;\n o.lo = x * y;\n o.hi = (x1 * y1) + w2 + (w1 >> 32);\n return o;\n#endif\n}\n\n" +
"// --------\n\ntypedef struct wuffs_base__multiply_u64__output__struct {\n uint64_t lo;\n uint64_t hi;\n} wuffs_base__multiply_u64__output;\n\n// wuffs_base__multiply_u64 returns x*y as a 128-bit value.\n//\n// The maximum inclusive output hi_lo is 0xFFFFFFFFFFFFFFFE_0000000000000001.\nstatic inline wuffs_base__multiply_u64__output //\nwuffs_base__multiply_u64(uint64_t x, uint64_t y) {\n#if defined(__SIZEOF_INT128__)\n __uint128_t z = ((__uint128_t)x) * ((__uint128_t)y);\n wuffs_base__multiply_u64__output o;\n o.lo = ((uint64_t)(z));\n o.hi = ((uint64_t)(z >> 64));\n return o;\n#else\n // TODO: consider using the _mul128 intrinsic if defined(_MSC_VER).\n uint64_t x0 = x & 0xFFFFFFFF;\n uint64_t x1 = x >> 32;\n uint64_t y0 = y & 0xFFFFFFFF;\n uint64_t y1 = y >> 32;\n uint64_t w0 = x0 * y0;\n uint64_t t = (x1 * y0) + (w0 >> 32);\n uint64_t w1 = t & 0xFFFFFFFF;\n uint64_t w2 = t >> 32;\n w1 += x0 * y1;\n wuffs_base__multiply_u64__output o;\n o.lo = x * y;\n o.hi = (x1 * y1) + w2 + (w1 >> 32);\n return o;\n#endif\n}\n\n" +
"" +
"// --------\n\n#if defined(__GNUC__) && (__SIZEOF_LONG__ == 8)\n\nstatic inline uint32_t //\nwuffs_base__count_leading_zeroes_u64(uint64_t u) {\n return u ? ((uint32_t)(__builtin_clzl(u))) : 64u;\n}\n\n#else\n\nstatic inline uint32_t //\nwuffs_base__count_leading_zeroes_u64(uint64_t u) {\n if (u == 0) {\n return 64;\n }\n\n uint32_t n = 0;\n if ((u >> 32) == 0) {\n n |= 32;\n u <<= 32;\n }\n if ((u >> 48) == 0) {\n n |= 16;\n u <<= 16;\n }\n if ((u >> 56) == 0) {\n n |= 8;\n u <<= 8;\n }\n if ((u >> 60) == 0) {\n n |= 4;\n u <<= 4;\n }\n if ((u >> 62) == 0) {\n n |= 2;\n u <<= 2;\n }\n if ((u >> 63) == 0) {\n n |= 1;\n u <<= 1;\n }\n return n;\n}\n\n#endif // defined(__GNUC__) && (__SIZEOF_LONG__ == 8)\n\n" +
"// --------\n\n#if defined(__GNUC__) && (__SIZEOF_LONG__ == 8)\n\nstatic inline uint32_t //\nwuffs_base__count_leading_zeroes_u64(uint64_t u) {\n return u ? ((uint32_t)(__builtin_clzl(u))) : 64u;\n}\n\n#else\n// TODO: consider using the _BitScanReverse intrinsic if defined(_MSC_VER).\n\nstatic inline uint32_t //\nwuffs_base__count_leading_zeroes_u64(uint64_t u) {\n if (u == 0) {\n return 64;\n }\n\n uint32_t n = 0;\n if ((u >> 32) == 0) {\n n |= 32;\n u <<= 32;\n }\n if ((u >> 48) == 0) {\n n |= 16;\n u <<= 16;\n }\n if ((u >> 56) == 0) {\n n |= 8;\n u <<= 8;\n }\n if ((u >> 60) == 0) {\n n |= 4;\n u <<= 4;\n }\n if ((u >> 62) == 0) {\n n |= 2;\n u <<= 2;\n }\n if ((u >> 63) == 0) {\n n |= 1;\n u <<= 1;\n }\n return n;\n}\n\n#endif // defined(__GNUC__) && (__SIZEOF_LONG__ == 8)\n\n" +
"" +
"// --------\n\n#define wuffs_base__peek_u8be__no_bounds_check \\\n wuffs_base__peek_u8__no_bounds_check\n#define wuffs_base__peek_u8le__no_bounds_check \\\n wuffs_base__peek_u8__no_bounds_check\n\nstatic inline uint8_t //\nwuffs_base__peek_u8__no_bounds_check(const uint8_t* p) {\n return p[0];\n}\n\nstatic inline uint16_t //\nwuffs_base__peek_u16be__no_bounds_check(const uint8_t* p) {\n return (uint16_t)(((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0));\n}\n\nstatic inline uint16_t //\nwuffs_base__peek_u16le__no_bounds_check(const uint8_t* p) {\n return (uint16_t)(((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8));\n}\n\nstatic inline uint32_t //\nwuffs_base__peek_u24be__no_bounds_check(const uint8_t* p) {\n return ((uint32_t)(p[0]) << 16) | ((uint32_t)(p[1]) << 8) |\n ((uint32_t)(p[2]) << 0);\n}\n\nstatic inline uint32_t //\nwuffs_base__peek_u24le__no_bounds_check(const uint8_t* p) {\n return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |\n ((uint32_t)(p[2]) << 16);\n}\n\nstatic inline uint32_t //\nwuffs_base" +
"__peek_u32be__no_bounds_check(const uint8_t* p) {\n return ((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) |\n ((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0);\n}\n\nstatic inline uint32_t //\nwuffs_base__peek_u32le__no_bounds_check(const uint8_t* p) {\n return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |\n ((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24);\n}\n\nstatic inline uint64_t //\nwuffs_base__peek_u40be__no_bounds_check(const uint8_t* p) {\n return ((uint64_t)(p[0]) << 32) | ((uint64_t)(p[1]) << 24) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 8) |\n ((uint64_t)(p[4]) << 0);\n}\n\nstatic inline uint64_t //\nwuffs_base__peek_u40le__no_bounds_check(const uint8_t* p) {\n return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 32);\n}\n\nstatic inline uint64_t //\nwuffs_base__peek_u48be__no_bounds_check(const uint8_t* p) {\n return ((uint64_t)(p[0]) << 40) | ((uint64_t)(p[" +
+2
View File
@@ -758,6 +758,7 @@ wuffs_base__multiply_u64(uint64_t x, uint64_t y) {
o.hi = ((uint64_t)(z >> 64));
return o;
#else
// TODO: consider using the _mul128 intrinsic if defined(_MSC_VER).
uint64_t x0 = x & 0xFFFFFFFF;
uint64_t x1 = x >> 32;
uint64_t y0 = y & 0xFFFFFFFF;
@@ -784,6 +785,7 @@ wuffs_base__count_leading_zeroes_u64(uint64_t u) {
}
#else
// TODO: consider using the _BitScanReverse intrinsic if defined(_MSC_VER).
static inline uint32_t //
wuffs_base__count_leading_zeroes_u64(uint64_t u) {