rcx

miscellaneous C library
git clone git://git.rr3.xyz/rcx
Log | Files | Refs | README | LICENSE

commit 2c0567085f8ddb562cb1d26a666e34e1004e96ee
parent 840e43fa9a1ba629c16d76b65d84b8ba9076620a
Author: Robert Russell <robert@rr3.xyz>
Date:   Sun, 12 Jan 2025 19:25:47 -0800

Assign high after low in add, sub, and mul

This is to simplify a project dependent on RCX.

Diffstat:
Minc/bits.h | 34+++++++++++++++-------------------
1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/inc/bits.h b/inc/bits.h @@ -217,111 +217,107 @@ r_rzb64(u64 n) { static inline void r_add8(u8 *h, u8 *l, u8 x, u8 y, u8 z) { u16 hl = (u16)x + (u16)y + (u16)z; - *l = hl; *h = hl >> 8; + *l = hl; } static inline void r_add16(u16 *h, u16 *l, u16 x, u16 y, u16 z) { u32 hl = (u32)x + (u32)y + (u32)z; - *l = hl; *h = hl >> 16; + *l = hl; } static inline void r_add32(u32 *h, u32 *l, u32 x, u32 y, u32 z) { u64 hl = (u64)x + (u64)y + (u64)z; - *l = hl; *h = hl >> 32; + *l = hl; } static inline void r_add64(u64 *h, u64 *l, u64 x, u64 y, u64 z) { #ifdef R_HAVE_128 u128 hl = (u128)x + (u128)y + (u128)z; - *l = hl; *h = hl >> 64; + *l = hl; #else u64 s = x + y; bool c0 = s < x; u64 t = s + z; bool c1 = t < s; - *l = t; *h = c0 + c1; + *l = t; #endif } static inline void r_sub8(u8 *h, u8 *l, u8 x, u8 y, u8 z) { u16 hl = (u16)x - (u16)y - (u16)z; - *l = hl; *h = hl >> 8; + *l = hl; } static inline void r_sub16(u16 *h, u16 *l, u16 x, u16 y, u16 z) { u32 hl = (u32)x - (u32)y - (u32)z; - *l = hl; *h = hl >> 16; + *l = hl; } static inline void r_sub32(u32 *h, u32 *l, u32 x, u32 y, u32 z) { u64 hl = (u64)x - (u64)y - (u64)z; - *l = hl; *h = hl >> 32; + *l = hl; } static inline void r_sub64(u64 *h, u64 *l, u64 x, u64 y, u64 z) { #ifdef R_HAVE_128 u128 hl = (u128)x - (u128)y - (u128)z; - *l = hl; *h = hl >> 64; + *l = hl; #else u64 s = x - y; bool c0 = s > x; u64 t = s - z; bool c1 = t > s; - *l = t; *h = -c0 - c1; + *l = t; #endif } -#undef SUBC64 -#undef ADDC64 -#undef HAVE_ADDC_SUBC - /* ----- Full width multiply ----- */ static inline void r_mul8(u8 *h, u8 *l, u8 x, u8 y) { u16 hl = (u16)x * (u16)y; - *l = hl; *h = hl >> 8; + *l = hl; } static inline void r_mul16(u16 *h, u16 *l, u16 x, u16 y) { u32 hl = (u32)x * (u32)y; - *l = hl; *h = hl >> 16; + *l = hl; } static inline void r_mul32(u32 *h, u32 *l, u32 x, u32 y) { u64 hl = (u64)x * (u64)y; - *l = hl; *h = hl >> 32; + *l = hl; } static inline void r_mul64(u64 *h, u64 *l, u64 x, u64 y) { #ifdef R_HAVE_128 u128 hl = (u128)x * (u128)y; - *l = hl; *h = hl >> 64; + *l = hl; #else const u64 m = (U64_C(1)<<32) - 1; @@ -337,8 +333,8 @@ r_mul64(u64 *h, u64 *l, u64 x, u64 y) { u64 c = ((x0y1&m) + (x1y0&m) + (x0y0>>32)) >> 32; - *l = x0y0 + (x0y1<<32) + (x1y0<<32); *h = x1y1 + (x0y1>>32) + (x1y0>>32) + c; + *l = x0y0 + (x0y1<<32) + (x1y0<<32); #endif }