add two small integers, checking for overflow. we want an efficient operation. for msvc, where we don't have built-in intrinsics, this is still pretty fast.
| 2024 | // we don't have built-in intrinsics, this is still |
| 2025 | // pretty fast. |
| 2026 | fastfloat_really_inline FASTFLOAT_CONSTEXPR20 |
| 2027 | limb scalar_add(limb x, limb y, bool& overflow) noexcept { |
| 2028 | limb z; |
| 2029 | // gcc and clang |
| 2030 | #if defined(__has_builtin) |
| 2031 | #if __has_builtin(__builtin_add_overflow) |
| 2032 | if (!cpp20_and_in_constexpr()) { |
| 2033 | overflow = __builtin_add_overflow(x, y, &z); |
| 2034 | return z; |
| 2035 | } |
| 2036 | #endif |
| 2037 | #endif |
| 2038 | |
| 2039 | // generic, this still optimizes correctly on MSVC. |
| 2040 | z = x + y; |
| 2041 | overflow = z < x; |
| 2042 | return z; |
| 2043 | } |
| 2044 | |
| 2045 | // multiply two small integers, getting both the high and low bits. |
| 2046 | fastfloat_really_inline FASTFLOAT_CONSTEXPR20 |
no test coverage detected