| ... | @@ -650,7 +650,7 @@ typedef ptrdiff_t intptr_t; | ... | @@ -650,7 +650,7 @@ typedef ptrdiff_t intptr_t; |
| 650 | zig_operator(Type, Type, operation, operator) | 650 | zig_operator(Type, Type, operation, operator) |
| 651 | #define zig_shift_operator(Type, operation, operator) \ | 651 | #define zig_shift_operator(Type, operation, operator) \ |
| 652 | zig_operator(Type, uint8_t, operation, operator) | 652 | zig_operator(Type, uint8_t, operation, operator) |
| 653 | #define zig_int_helpers(w) \ | 653 | #define zig_int_helpers(w, PromotedUnsigned) \ |
| 654 | zig_basic_operator(uint##w##_t, and_u##w, &) \ | 654 | zig_basic_operator(uint##w##_t, and_u##w, &) \ |
| 655 | zig_basic_operator( int##w##_t, and_i##w, &) \ | 655 | zig_basic_operator( int##w##_t, and_i##w, &) \ |
| 656 | zig_basic_operator(uint##w##_t, or_u##w, |) \ | 656 | zig_basic_operator(uint##w##_t, or_u##w, |) \ |
| ... | @@ -726,16 +726,48 @@ typedef ptrdiff_t intptr_t; | ... | @@ -726,16 +726,48 @@ typedef ptrdiff_t intptr_t; |
| 726 | } \ | 726 | } \ |
| 727 | \ | 727 | \ |
| 728 | static inline uint##w##_t zig_mulw_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ | 728 | static inline uint##w##_t zig_mulw_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ |
| 729 | return zig_wrap_u##w(lhs * rhs, bits); \ | 729 | return zig_wrap_u##w((PromotedUnsigned)lhs * rhs, bits); \ |
| 730 | } \ | 730 | } \ |
| 731 | \ | 731 | \ |
| 732 | static inline int##w##_t zig_mulw_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ | 732 | static inline int##w##_t zig_mulw_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ |
| 733 | return zig_wrap_i##w((int##w##_t)((uint##w##_t)lhs * (uint##w##_t)rhs), bits); \ | 733 | return zig_wrap_i##w((int##w##_t)((uint##w##_t)lhs * (uint##w##_t)rhs), bits); \ |
| 734 | } | 734 | } |
| 735 | zig_int_helpers(8) | 735 | #if UINT8_MAX <= UINT_MAX |
| 736 | zig_int_helpers(16) | 736 | zig_int_helpers(8, unsigned int) |
| 737 | zig_int_helpers(32) | 737 | #elif UINT8_MAX <= ULONG_MAX |
| 738 | zig_int_helpers(64) | 738 | zig_int_helpers(8, unsigned long) |
| | 739 | #elif UINT8_MAX <= ULLONG_MAX |
| | 740 | zig_int_helpers(8, unsigned long long) |
| | 741 | #else |
| | 742 | zig_int_helpers(8, uint8_t) |
| | 743 | #endif |
| | 744 | #if UINT16_MAX <= UINT_MAX |
| | 745 | zig_int_helpers(16, unsigned int) |
| | 746 | #elif UINT16_MAX <= ULONG_MAX |
| | 747 | zig_int_helpers(16, unsigned long) |
| | 748 | #elif UINT16_MAX <= ULLONG_MAX |
| | 749 | zig_int_helpers(16, unsigned long long) |
| | 750 | #else |
| | 751 | zig_int_helpers(16, uint16_t) |
| | 752 | #endif |
| | 753 | #if UINT32_MAX <= UINT_MAX |
| | 754 | zig_int_helpers(32, unsigned int) |
| | 755 | #elif UINT32_MAX <= ULONG_MAX |
| | 756 | zig_int_helpers(32, unsigned long) |
| | 757 | #elif UINT32_MAX <= ULLONG_MAX |
| | 758 | zig_int_helpers(32, unsigned long long) |
| | 759 | #else |
| | 760 | zig_int_helpers(32, uint32_t) |
| | 761 | #endif |
| | 762 | #if UINT64_MAX <= UINT_MAX |
| | 763 | zig_int_helpers(64, unsigned int) |
| | 764 | #elif UINT64_MAX <= ULONG_MAX |
| | 765 | zig_int_helpers(64, unsigned long) |
| | 766 | #elif UINT64_MAX <= ULLONG_MAX |
| | 767 | zig_int_helpers(64, unsigned long long) |
| | 768 | #else |
| | 769 | zig_int_helpers(64, uint64_t) |
| | 770 | #endif |
| 739 | | 771 | |
| 740 | static inline bool zig_addo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) { | 772 | static inline bool zig_addo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) { |
| 741 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) | 773 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) |