MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / scalar_add

Function scalar_add

Source/external/fast_float.h:2026–2043  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

2024// we don't have built-in intrinsics, this is still
2025// pretty fast.
2026fastfloat_really_inline FASTFLOAT_CONSTEXPR20
2027limb 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.
2046fastfloat_really_inline FASTFLOAT_CONSTEXPR20

Callers 3

scalar_mulFunction · 0.85
small_add_fromFunction · 0.85
large_add_fromFunction · 0.85

Calls 1

cpp20_and_in_constexprFunction · 0.85

Tested by

no test coverage detected