[libc-commits] [libc] [libc][stdfix] Implement `idivfx` functions in LLVM libc (PR #133005)
via libc-commits
libc-commits at lists.llvm.org
Wed Mar 26 11:19:05 PDT 2025
================
@@ -201,6 +201,30 @@ bitsfx(T f) {
return cpp::bit_cast<XType, T>(f);
}
+// divide the two fixed-point types and return an integer result
+template <typename T, typename XType>
+LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_fixed_point_v<T>, XType>
+idiv(T x, T y) {
+ using FXBits = FXBits<T>;
+ using FXRep = FXRep<T>;
+ using CompType = typename FXRep::CompType;
+
+ if (y == FXRep::ZERO()) {
+ // If the value of the second operand of the / operator is zero, the
+ // behavior is undefined. Ref: ISO/IEC TR 18037:2008(E) p.g. 16
+ return static_cast<XType>(0);
+ }
----------------
PiJoules wrote:
Since it's UB, I'm wondering if we could just omit this check and instead have a debug assert.
Thoughts @lntue?
https://github.com/llvm/llvm-project/pull/133005
More information about the libc-commits
mailing list