[libc-commits] [libc] [libc][stdfix] Implement mulifx functions (PR #235602)

Jaeyong Lee via libc-commits libc-commits at lists.llvm.org
Wed Nov 4 11:51:38 PST 2026


https://github.com/npmania updated https://github.com/llvm/llvm-project/pull/235602

>From c87af30d366e037a3fb6f29c9e3306a03926586b Mon Sep 17 00:00:00 2001
From: Jaeyong Lee <jay at glendalab.com>
Date: Mon, 26 Oct 2026 00:30:22 +0900
Subject: [PATCH 01/15] [libc][stdfix] Implement mulik function

---
 libc/config/baremetal/arm/entrypoints.txt     |   1 +
 libc/config/baremetal/hexagon/entrypoints.txt |   1 +
 libc/config/baremetal/riscv/entrypoints.txt   |   1 +
 libc/config/linux/riscv/entrypoints.txt       |   1 +
 libc/config/linux/x86_64/entrypoints.txt      |   1 +
 libc/docs/headers/stdfix.md                   |   2 +-
 libc/include/stdfix.yaml                      |   8 +
 libc/src/__support/fixed_point/fx_bits.h      |  42 +++++
 libc/src/stdfix/CMakeLists.txt                |  12 ++
 libc/src/stdfix/mulik.cpp                     |  21 +++
 libc/src/stdfix/mulik.h                       |  21 +++
 libc/test/src/stdfix/CMakeLists.txt           |  15 ++
 libc/test/src/stdfix/MuliFxTest.h             | 154 ++++++++++++++++++
 libc/test/src/stdfix/mulik_test.cpp           |  14 ++
 14 files changed, 293 insertions(+), 1 deletion(-)
 create mode 100644 libc/src/stdfix/mulik.cpp
 create mode 100644 libc/src/stdfix/mulik.h
 create mode 100644 libc/test/src/stdfix/MuliFxTest.h
 create mode 100644 libc/test/src/stdfix/mulik_test.cpp

diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index ab84c92f5c03c9..f40a2a53d89820 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -1014,6 +1014,7 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
     libc.src.stdfix.ulrdivi
     libc.src.stdfix.ukdivi
     libc.src.stdfix.ulkdivi
+    libc.src.stdfix.mulik
   )
 endif()
 
diff --git a/libc/config/baremetal/hexagon/entrypoints.txt b/libc/config/baremetal/hexagon/entrypoints.txt
index a7617ec243e278..a18c7603558719 100644
--- a/libc/config/baremetal/hexagon/entrypoints.txt
+++ b/libc/config/baremetal/hexagon/entrypoints.txt
@@ -995,6 +995,7 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
     libc.src.stdfix.diviulr
     libc.src.stdfix.diviuk
     libc.src.stdfix.diviulk
+    libc.src.stdfix.mulik
   )
 endif()
 
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 01a7251e35b447..5240c48230e265 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -1006,6 +1006,7 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
     libc.src.stdfix.ulrdivi
     libc.src.stdfix.ukdivi
     libc.src.stdfix.ulkdivi
+    libc.src.stdfix.mulik
   )
 endif()
 
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 3b42f020cf750e..728964f44323d8 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1320,6 +1320,7 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
     libc.src.stdfix.diviulr
     libc.src.stdfix.diviuk
     libc.src.stdfix.diviulk
+    libc.src.stdfix.mulik
   )
 endif()
 
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 0ec5d8f73a8a4d..0f307978d5ee58 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1342,6 +1342,7 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
     libc.src.stdfix.diviulr
     libc.src.stdfix.diviuk
     libc.src.stdfix.diviulk
+    libc.src.stdfix.mulik
   )
 endif()
 
diff --git a/libc/docs/headers/stdfix.md b/libc/docs/headers/stdfix.md
index b689312642cdb1..3307bc05033014 100644
--- a/libc/docs/headers/stdfix.md
+++ b/libc/docs/headers/stdfix.md
@@ -60,7 +60,7 @@ The following functions are included in the ISO/IEC TR 18037:2008 standard.
 +---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
 | idiv\*        |                |             | ✅            | ✅         | ✅             | ✅          |                |             | ✅            | ✅         | ✅             | ✅          |
 +---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
-| muli          |                |             |               |            |                |             |                |             |               |            |                |             |
+| muli\*        |                |             |               |            |                |             |                |             |               | ✅         |                |             |
 +---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
 | \*divi        |                |             | ✅            | ✅         | ✅             | ✅          |                |             | ✅            | ✅         | ✅             | ✅          |
 +---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
diff --git a/libc/include/stdfix.yaml b/libc/include/stdfix.yaml
index 739805ea2a39a7..2af1dac6468bb2 100644
--- a/libc/include/stdfix.yaml
+++ b/libc/include/stdfix.yaml
@@ -685,3 +685,11 @@ functions:
       - type: unsigned long int
       - type: unsigned long accum
     guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: mulik
+    standards:
+      - stdc_ext
+    return_type: int
+    arguments:
+      - type: int
+      - type: accum
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index 5c3b39d5a64aad..6e91092adfed3e 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -404,6 +404,48 @@ divifx(IntType n, FXType d) {
   return static_cast<IntType>(result);
 }
 
+// Multiply an integer operand by a fixed-point operand and return the
+// mathematically exact result as an IntType rounded towards 0. Assumes
+// signedness of IntType matches the signedness of FXType.
+template <typename IntType, typename FXType>
+LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_fixed_point_v<FXType>, IntType>
+mulifx(IntType n, FXType m) {
+  using FXBits = FXBits<FXType>;
+  using FXRep = FXRep<FXType>;
+  using CompType = typename FXRep::CompType;
+
+  static_assert(cpp::is_signed_v<IntType> == (FXRep::SIGN_LEN > 0),
+                "IntType and FXType must have matching signedness");
+
+  if (LIBC_UNLIKELY(n == 0)) {
+    return static_cast<IntType>(0);
+  }
+
+  CompType m_comp = static_cast<CompType>(FXBits(m).get_bits());
+
+  constexpr int F = FXRep::FRACTION_LEN;
+
+  constexpr int INTERMEDIATE_BITS =
+      sizeof(IntType) * 8 - cpp::is_signed_v<IntType> + FXRep::VALUE_LEN;
+
+  using WideType = cpp::conditional_t<
+      cpp::is_signed_v<IntType>,
+      cpp::conditional_t<INTERMEDIATE_BITS <= 64, int64_t, Int128>,
+      cpp::conditional_t<INTERMEDIATE_BITS <= 64, uint64_t, UInt128>>;
+
+  WideType unscaled_result = n * static_cast<WideType>(m_comp);
+
+  if constexpr (FXRep::SIGN_LEN > 0) {
+    constexpr WideType MASK = (WideType(1) << F) - 1;
+    constexpr int SIGN_OFFSET = cpp::numeric_limits<WideType>::digits;
+    WideType result =
+        (unscaled_result + ((unscaled_result >> SIGN_OFFSET) & MASK)) >> F;
+    return static_cast<IntType>(result);
+  }
+  WideType result = unscaled_result >> F;
+  return static_cast<IntType>(result);
+}
+
 } // namespace fixed_point
 } // namespace LIBC_NAMESPACE_DECL
 
diff --git a/libc/src/stdfix/CMakeLists.txt b/libc/src/stdfix/CMakeLists.txt
index de171113993057..660f908aed458f 100644
--- a/libc/src/stdfix/CMakeLists.txt
+++ b/libc/src/stdfix/CMakeLists.txt
@@ -106,6 +106,18 @@ foreach(suffix IN ITEMS r lr k lk ur ulr uk ulk)
   )
 endforeach()
 
+foreach(suffix IN ITEMS k)
+  add_entrypoint_object(
+    muli${suffix}
+    HDRS
+      muli${suffix}.h
+    SRCS
+      muli${suffix}.cpp
+    DEPENDS
+      libc.src.__support.fixed_point.fx_bits
+  )
+endforeach()
+
 add_entrypoint_object(
   uhksqrtus
   HDRS
diff --git a/libc/src/stdfix/mulik.cpp b/libc/src/stdfix/mulik.cpp
new file mode 100644
index 00000000000000..4673d9fca76b2c
--- /dev/null
+++ b/libc/src/stdfix/mulik.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of mulik function ----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "mulik.h"
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, mulik, (int n, accum m)) {
+  return fixed_point::mulifx<int, accum>(n, m);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/mulik.h b/libc/src/stdfix/mulik.h
new file mode 100644
index 00000000000000..001a2ebed1cdc2
--- /dev/null
+++ b/libc/src/stdfix/mulik.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for mulik -------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_MULIK_H
+#define LLVM_LIBC_SRC_STDFIX_MULIK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int mulik(int n, accum m);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_MULIK_H
diff --git a/libc/test/src/stdfix/CMakeLists.txt b/libc/test/src/stdfix/CMakeLists.txt
index 391339cf3fbf5c..e1b5e8db4f5d28 100644
--- a/libc/test/src/stdfix/CMakeLists.txt
+++ b/libc/test/src/stdfix/CMakeLists.txt
@@ -156,6 +156,21 @@ foreach(suffix IN ITEMS r lr k lk ur ulr uk ulk)
   )
 endforeach()
 
+foreach(suffix IN ITEMS k)
+  add_libc_test(
+    muli${suffix}_test
+    SUITE
+      libc-stdfix-tests
+    HDRS
+      MuliFxTest.h
+    SRCS
+      muli${suffix}_test.cpp
+    DEPENDS
+      libc.src.stdfix.muli${suffix}
+      libc.src.__support.fixed_point.fx_rep
+  )
+endforeach()
+
 add_libc_test(
   uhksqrtus_test
   SUITE
diff --git a/libc/test/src/stdfix/MuliFxTest.h b/libc/test/src/stdfix/MuliFxTest.h
new file mode 100644
index 00000000000000..7404e48575bbfa
--- /dev/null
+++ b/libc/test/src/stdfix/MuliFxTest.h
@@ -0,0 +1,154 @@
+//===-- Utility class to test mulifx functions ------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "test/UnitTest/Test.h"
+
+#include "llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/CPP/limits.h"
+#include "src/__support/fixed_point/fx_rep.h"
+
+namespace cpp = LIBC_NAMESPACE::cpp;
+
+template <typename IntType, typename FXType>
+class MuliFxTest : public LIBC_NAMESPACE::testing::Test {
+
+  using FXRep = LIBC_NAMESPACE::fixed_point::FXRep<FXType>;
+
+  static constexpr FXType max = FXRep::MAX();
+  static constexpr FXType min = FXRep::MIN();
+  static constexpr FXType epsilon = FXRep::EPS();
+  static constexpr FXType one_half = FXRep::ONE_HALF();
+  static constexpr FXType one_fourth = FXRep::ONE_FOURTH();
+  static constexpr FXType one_eighth = FXRep::ONE_EIGHTH();
+
+  static constexpr bool is_signed = (FXRep::SIGN_LEN > 0);
+  static constexpr bool has_integral = (FXRep::INTEGRAL_LEN > 0);
+
+public:
+  typedef IntType (*MuliFxFunc)(IntType, FXType);
+
+  void testBasicNumbers(MuliFxFunc func) {
+
+    EXPECT_EQ(func(0, epsilon), static_cast<IntType>(0));
+    EXPECT_EQ(func(0, max), static_cast<IntType>(0));
+
+    EXPECT_EQ(func(1, one_eighth), static_cast<IntType>(0));
+    EXPECT_EQ(func(7, one_eighth), static_cast<IntType>(0));
+    EXPECT_EQ(func(8, one_eighth), static_cast<IntType>(1));
+    EXPECT_EQ(func(9, one_eighth), static_cast<IntType>(1));
+    EXPECT_EQ(func(16, one_eighth), static_cast<IntType>(2));
+    EXPECT_EQ(func(4, one_fourth), static_cast<IntType>(1));
+    EXPECT_EQ(func(8, one_fourth), static_cast<IntType>(2));
+    EXPECT_EQ(func(1, one_half), static_cast<IntType>(0));
+    EXPECT_EQ(func(3, one_half), static_cast<IntType>(1));
+    EXPECT_EQ(func(4, one_half), static_cast<IntType>(2));
+
+    // Verify rounding towards 0.
+    EXPECT_EQ(func(1, 3 * one_fourth), static_cast<IntType>(0));
+    EXPECT_EQ(func(2, 3 * one_fourth), static_cast<IntType>(1));
+    EXPECT_EQ(func(3, 3 * one_fourth), static_cast<IntType>(2));
+
+    if constexpr (is_signed) {
+      EXPECT_EQ(func(-1, one_half), static_cast<IntType>(0));
+      EXPECT_EQ(func(-3, one_half), static_cast<IntType>(-1));
+      EXPECT_EQ(func(3, -one_half), static_cast<IntType>(-1));
+      EXPECT_EQ(func(-3, -one_half), static_cast<IntType>(1));
+      EXPECT_EQ(func(-8, one_eighth), static_cast<IntType>(-1));
+      EXPECT_EQ(func(-9, one_eighth), static_cast<IntType>(-1));
+      EXPECT_EQ(func(-1, 3 * one_fourth), static_cast<IntType>(0));
+      EXPECT_EQ(func(-2, 3 * one_fourth), static_cast<IntType>(-1));
+      EXPECT_EQ(func(-3, 3 * one_fourth), static_cast<IntType>(-2));
+    }
+
+    if constexpr (has_integral) {
+      EXPECT_EQ(func(1, static_cast<FXType>(1)), static_cast<IntType>(1));
+      EXPECT_EQ(func(2, static_cast<FXType>(2)), static_cast<IntType>(4));
+
+      if constexpr (is_signed) {
+        EXPECT_EQ(func(1, static_cast<FXType>(-1)), static_cast<IntType>(-1));
+        EXPECT_EQ(func(-1, static_cast<FXType>(1)), static_cast<IntType>(-1));
+        EXPECT_EQ(func(-1, static_cast<FXType>(-1)), static_cast<IntType>(1));
+      }
+
+      // Only run these tests for accum types that can represent these operands.
+      constexpr FXType max_test_operand = static_cast<FXType>(4);
+
+      if constexpr (max >= max_test_operand) {
+        EXPECT_EQ(func(3, 2.5), static_cast<IntType>(7));
+        EXPECT_EQ(func(4, 1.5), static_cast<IntType>(6));
+
+        if constexpr (is_signed) {
+          EXPECT_EQ(func(-3, 2.5), static_cast<IntType>(-7));
+          EXPECT_EQ(func(-3, -2.5), static_cast<IntType>(7));
+        }
+      }
+    }
+  }
+
+  void testEdgeCases(MuliFxFunc func) {
+
+    constexpr IntType int_max = cpp::numeric_limits<IntType>::max();
+    constexpr IntType int_min = cpp::numeric_limits<IntType>::min();
+
+    if constexpr (has_integral) {
+      EXPECT_EQ(func(int_max, static_cast<FXType>(1)), int_max);
+
+      if constexpr (is_signed) {
+        EXPECT_EQ(func(int_max, static_cast<FXType>(-1)), -int_max);
+      }
+    }
+
+    EXPECT_EQ(func(int_max, one_half), int_max / 2);
+
+    if constexpr (is_signed) {
+      EXPECT_EQ(func(int_min, one_half), int_min / 2);
+    }
+
+    if constexpr (FXRep::FRACTION_LEN < cpp::numeric_limits<IntType>::digits) {
+      constexpr IntType epsilon_reciprocal = static_cast<IntType>(1)
+                                             << FXRep::FRACTION_LEN;
+      EXPECT_EQ(func(epsilon_reciprocal, epsilon), static_cast<IntType>(1));
+
+      if constexpr (is_signed) {
+        EXPECT_EQ(func(-epsilon_reciprocal, epsilon), static_cast<IntType>(-1));
+        EXPECT_EQ(func(epsilon_reciprocal, -epsilon), static_cast<IntType>(-1));
+        EXPECT_EQ(func(-epsilon_reciprocal, -epsilon), static_cast<IntType>(1));
+      }
+    }
+
+    if constexpr (has_integral &&
+                  FXRep::INTEGRAL_LEN < cpp::numeric_limits<IntType>::digits) {
+      constexpr IntType integral_max =
+          (static_cast<IntType>(1) << FXRep::INTEGRAL_LEN) - 1;
+
+      EXPECT_EQ(func(1, max), integral_max);
+
+      if constexpr (is_signed) {
+        EXPECT_EQ(func(1, min), -static_cast<IntType>(integral_max + 1));
+        EXPECT_EQ(func(-1, max), -integral_max);
+      }
+    }
+
+    if constexpr (!has_integral) {
+      EXPECT_EQ(func(1, max), static_cast<IntType>(0));
+      EXPECT_EQ(func(2, max), static_cast<IntType>(1));
+
+      if constexpr (is_signed) {
+        EXPECT_EQ(func(1, min), static_cast<IntType>(-1));
+        EXPECT_EQ(func(-1, max), static_cast<IntType>(0));
+        EXPECT_EQ(func(-1, min), static_cast<IntType>(1));
+      }
+    }
+  }
+};
+
+#define LIST_MULIFX_TESTS(Name, IntType, FXType, func)                         \
+  using LlvmLibcMuli##Name##Test = MuliFxTest<IntType, FXType>;                \
+  TEST_F(LlvmLibcMuli##Name##Test, BasicNumbers) { testBasicNumbers(&func); }  \
+  TEST_F(LlvmLibcMuli##Name##Test, EdgeCases) { testEdgeCases(&func); }        \
+  static_assert(true, "Require semicolon.")
diff --git a/libc/test/src/stdfix/mulik_test.cpp b/libc/test/src/stdfix/mulik_test.cpp
new file mode 100644
index 00000000000000..e8971c4ab6babc
--- /dev/null
+++ b/libc/test/src/stdfix/mulik_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for mulik -----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MuliFxTest.h"
+
+#include "llvm-libc-macros/stdfix-macros.h"
+#include "src/stdfix/mulik.h"
+
+LIST_MULIFX_TESTS(k, int, accum, LIBC_NAMESPACE::mulik);

>From 70f47ab661da3cdf8d8454a189b9069335257399 Mon Sep 17 00:00:00 2001
From: Jaeyong Lee <jay at glendalab.com>
Date: Mon, 26 Oct 2026 18:28:48 +0900
Subject: [PATCH 02/15] n == 0 early return is not worth it on multiply

---
 libc/src/__support/fixed_point/fx_bits.h | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index 6e91092adfed3e..264cda957a504e 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -417,10 +417,6 @@ mulifx(IntType n, FXType m) {
   static_assert(cpp::is_signed_v<IntType> == (FXRep::SIGN_LEN > 0),
                 "IntType and FXType must have matching signedness");
 
-  if (LIBC_UNLIKELY(n == 0)) {
-    return static_cast<IntType>(0);
-  }
-
   CompType m_comp = static_cast<CompType>(FXBits(m).get_bits());
 
   constexpr int F = FXRep::FRACTION_LEN;

>From a32937e7f7cd47bd5903d97a5c150cdf8761545a Mon Sep 17 00:00:00 2001
From: Jaeyong Lee <jay at glendalab.com>
Date: Mon, 26 Oct 2026 18:38:13 +0900
Subject: [PATCH 03/15] Use a comparison for the mulifx rounding bias

---
 libc/src/__support/fixed_point/fx_bits.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index 264cda957a504e..e3f034cf8d59e0 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -432,10 +432,9 @@ mulifx(IntType n, FXType m) {
   WideType unscaled_result = n * static_cast<WideType>(m_comp);
 
   if constexpr (FXRep::SIGN_LEN > 0) {
-    constexpr WideType MASK = (WideType(1) << F) - 1;
-    constexpr int SIGN_OFFSET = cpp::numeric_limits<WideType>::digits;
+    constexpr WideType BIAS = (WideType(1) << F) - 1;
     WideType result =
-        (unscaled_result + ((unscaled_result >> SIGN_OFFSET) & MASK)) >> F;
+        (unscaled_result + (unscaled_result < 0 ? BIAS : WideType(0))) >> F;
     return static_cast<IntType>(result);
   }
   WideType result = unscaled_result >> F;

>From e4d94125e606f7545e1b00861ea28d8b1e42e008 Mon Sep 17 00:00:00 2001
From: Jaeyong Lee <jay at glendalab.com>
Date: Mon, 26 Oct 2026 18:45:45 +0900
Subject: [PATCH 04/15] static_cast n to WideType before multiplying

---
 libc/src/__support/fixed_point/fx_bits.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index e3f034cf8d59e0..639944e4aaae2c 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -429,7 +429,8 @@ mulifx(IntType n, FXType m) {
       cpp::conditional_t<INTERMEDIATE_BITS <= 64, int64_t, Int128>,
       cpp::conditional_t<INTERMEDIATE_BITS <= 64, uint64_t, UInt128>>;
 
-  WideType unscaled_result = n * static_cast<WideType>(m_comp);
+  WideType unscaled_result =
+      static_cast<WideType>(n) * static_cast<WideType>(m_comp);
 
   if constexpr (FXRep::SIGN_LEN > 0) {
     constexpr WideType BIAS = (WideType(1) << F) - 1;

>From cf4b3884aedc87f930443c34bcf80dd498d719aa Mon Sep 17 00:00:00 2001
From: Jaeyong Lee <jay at glendalab.com>
Date: Mon, 26 Oct 2026 21:36:51 +0900
Subject: [PATCH 05/15] Use cpp::numeric_limits<T>::digits for WideType
 condition

---
 libc/src/__support/fixed_point/fx_bits.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index 639944e4aaae2c..f9de1952ff08b5 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -426,8 +426,12 @@ mulifx(IntType n, FXType m) {
 
   using WideType = cpp::conditional_t<
       cpp::is_signed_v<IntType>,
-      cpp::conditional_t<INTERMEDIATE_BITS <= 64, int64_t, Int128>,
-      cpp::conditional_t<INTERMEDIATE_BITS <= 64, uint64_t, UInt128>>;
+      cpp::conditional_t<INTERMEDIATE_BITS <=
+                             cpp::numeric_limits<int64_t>::digits,
+                         int64_t, Int128>,
+      cpp::conditional_t<INTERMEDIATE_BITS <=
+                             cpp::numeric_limits<uint64_t>::digits,
+                         uint64_t, UInt128>>;
 
   WideType unscaled_result =
       static_cast<WideType>(n) * static_cast<WideType>(m_comp);

>From 2a2febe737a3540f83a908886cd937dc809f79a8 Mon Sep 17 00:00:00 2001
From: Jaeyong Lee <jay at glendalab.com>
Date: Mon, 26 Oct 2026 22:45:56 +0900
Subject: [PATCH 06/15] Use cpp::numeric_limits<IntType>::digits for counting
 INTERMEDIATE_BITS

---
 libc/src/__support/fixed_point/fx_bits.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index f9de1952ff08b5..0037f000915fc9 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -422,7 +422,7 @@ mulifx(IntType n, FXType m) {
   constexpr int F = FXRep::FRACTION_LEN;
 
   constexpr int INTERMEDIATE_BITS =
-      sizeof(IntType) * 8 - cpp::is_signed_v<IntType> + FXRep::VALUE_LEN;
+      cpp::numeric_limits<IntType>::digits + FXRep::VALUE_LEN;
 
   using WideType = cpp::conditional_t<
       cpp::is_signed_v<IntType>,

>From 81e403d52024b9d327cb1c1a7d9f3f97680c8b5d Mon Sep 17 00:00:00 2001
From: Jaeyong Lee <jay at glendalab.com>
Date: Tue, 27 Oct 2026 11:49:39 +0900
Subject: [PATCH 07/15] Implement all the remaining mulifx functions

---
 libc/config/baremetal/arm/entrypoints.txt     |  7 +++
 libc/config/baremetal/hexagon/entrypoints.txt |  7 +++
 libc/config/baremetal/riscv/entrypoints.txt   |  7 +++
 libc/config/linux/riscv/entrypoints.txt       |  7 +++
 libc/config/linux/x86_64/entrypoints.txt      |  7 +++
 libc/docs/headers/stdfix.md                   |  2 +-
 libc/include/stdfix.yaml                      | 56 +++++++++++++++++++
 libc/src/stdfix/CMakeLists.txt                |  2 +-
 libc/src/stdfix/mulilk.cpp                    | 21 +++++++
 libc/src/stdfix/mulilk.h                      | 21 +++++++
 libc/src/stdfix/mulilr.cpp                    | 21 +++++++
 libc/src/stdfix/mulilr.h                      | 21 +++++++
 libc/src/stdfix/mulir.cpp                     | 21 +++++++
 libc/src/stdfix/mulir.h                       | 21 +++++++
 libc/src/stdfix/muliuk.cpp                    | 21 +++++++
 libc/src/stdfix/muliuk.h                      | 21 +++++++
 libc/src/stdfix/muliulk.cpp                   | 22 ++++++++
 libc/src/stdfix/muliulk.h                     | 21 +++++++
 libc/src/stdfix/muliulr.cpp                   | 22 ++++++++
 libc/src/stdfix/muliulr.h                     | 21 +++++++
 libc/src/stdfix/muliur.cpp                    | 21 +++++++
 libc/src/stdfix/muliur.h                      | 21 +++++++
 libc/test/src/stdfix/CMakeLists.txt           |  2 +-
 libc/test/src/stdfix/mulilk_test.cpp          | 14 +++++
 libc/test/src/stdfix/mulilr_test.cpp          | 14 +++++
 libc/test/src/stdfix/mulir_test.cpp           | 14 +++++
 libc/test/src/stdfix/muliuk_test.cpp          | 14 +++++
 libc/test/src/stdfix/muliulk_test.cpp         | 15 +++++
 libc/test/src/stdfix/muliulr_test.cpp         | 15 +++++
 libc/test/src/stdfix/muliur_test.cpp          | 14 +++++
 30 files changed, 490 insertions(+), 3 deletions(-)
 create mode 100644 libc/src/stdfix/mulilk.cpp
 create mode 100644 libc/src/stdfix/mulilk.h
 create mode 100644 libc/src/stdfix/mulilr.cpp
 create mode 100644 libc/src/stdfix/mulilr.h
 create mode 100644 libc/src/stdfix/mulir.cpp
 create mode 100644 libc/src/stdfix/mulir.h
 create mode 100644 libc/src/stdfix/muliuk.cpp
 create mode 100644 libc/src/stdfix/muliuk.h
 create mode 100644 libc/src/stdfix/muliulk.cpp
 create mode 100644 libc/src/stdfix/muliulk.h
 create mode 100644 libc/src/stdfix/muliulr.cpp
 create mode 100644 libc/src/stdfix/muliulr.h
 create mode 100644 libc/src/stdfix/muliur.cpp
 create mode 100644 libc/src/stdfix/muliur.h
 create mode 100644 libc/test/src/stdfix/mulilk_test.cpp
 create mode 100644 libc/test/src/stdfix/mulilr_test.cpp
 create mode 100644 libc/test/src/stdfix/mulir_test.cpp
 create mode 100644 libc/test/src/stdfix/muliuk_test.cpp
 create mode 100644 libc/test/src/stdfix/muliulk_test.cpp
 create mode 100644 libc/test/src/stdfix/muliulr_test.cpp
 create mode 100644 libc/test/src/stdfix/muliur_test.cpp

diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index f40a2a53d89820..f903bfe1fca988 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -1014,7 +1014,14 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
     libc.src.stdfix.ulrdivi
     libc.src.stdfix.ukdivi
     libc.src.stdfix.ulkdivi
+    libc.src.stdfix.mulir
+    libc.src.stdfix.mulilr
     libc.src.stdfix.mulik
+    libc.src.stdfix.mulilk
+    libc.src.stdfix.muliur
+    libc.src.stdfix.muliulr
+    libc.src.stdfix.muliuk
+    libc.src.stdfix.muliulk
   )
 endif()
 
diff --git a/libc/config/baremetal/hexagon/entrypoints.txt b/libc/config/baremetal/hexagon/entrypoints.txt
index a18c7603558719..4f64f77065e183 100644
--- a/libc/config/baremetal/hexagon/entrypoints.txt
+++ b/libc/config/baremetal/hexagon/entrypoints.txt
@@ -995,7 +995,14 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
     libc.src.stdfix.diviulr
     libc.src.stdfix.diviuk
     libc.src.stdfix.diviulk
+    libc.src.stdfix.mulir
+    libc.src.stdfix.mulilr
     libc.src.stdfix.mulik
+    libc.src.stdfix.mulilk
+    libc.src.stdfix.muliur
+    libc.src.stdfix.muliulr
+    libc.src.stdfix.muliuk
+    libc.src.stdfix.muliulk
   )
 endif()
 
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 5240c48230e265..5013d611a2bf74 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -1006,7 +1006,14 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
     libc.src.stdfix.ulrdivi
     libc.src.stdfix.ukdivi
     libc.src.stdfix.ulkdivi
+    libc.src.stdfix.mulir
+    libc.src.stdfix.mulilr
     libc.src.stdfix.mulik
+    libc.src.stdfix.mulilk
+    libc.src.stdfix.muliur
+    libc.src.stdfix.muliulr
+    libc.src.stdfix.muliuk
+    libc.src.stdfix.muliulk
   )
 endif()
 
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 728964f44323d8..60d7248609833e 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1320,7 +1320,14 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
     libc.src.stdfix.diviulr
     libc.src.stdfix.diviuk
     libc.src.stdfix.diviulk
+    libc.src.stdfix.mulir
+    libc.src.stdfix.mulilr
     libc.src.stdfix.mulik
+    libc.src.stdfix.mulilk
+    libc.src.stdfix.muliur
+    libc.src.stdfix.muliulr
+    libc.src.stdfix.muliuk
+    libc.src.stdfix.muliulk
   )
 endif()
 
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 0f307978d5ee58..b3a45dc2f9f9fa 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1342,7 +1342,14 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
     libc.src.stdfix.diviulr
     libc.src.stdfix.diviuk
     libc.src.stdfix.diviulk
+    libc.src.stdfix.mulir
+    libc.src.stdfix.mulilr
     libc.src.stdfix.mulik
+    libc.src.stdfix.mulilk
+    libc.src.stdfix.muliur
+    libc.src.stdfix.muliulr
+    libc.src.stdfix.muliuk
+    libc.src.stdfix.muliulk
   )
 endif()
 
diff --git a/libc/docs/headers/stdfix.md b/libc/docs/headers/stdfix.md
index 3307bc05033014..3ce859367aa760 100644
--- a/libc/docs/headers/stdfix.md
+++ b/libc/docs/headers/stdfix.md
@@ -60,7 +60,7 @@ The following functions are included in the ISO/IEC TR 18037:2008 standard.
 +---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
 | idiv\*        |                |             | ✅            | ✅         | ✅             | ✅          |                |             | ✅            | ✅         | ✅             | ✅          |
 +---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
-| muli\*        |                |             |               |            |                |             |                |             |               | ✅         |                |             |
+| muli\*        |                |             | ✅            | ✅         | ✅             | ✅          |                |             | ✅            | ✅         | ✅             | ✅          |
 +---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
 | \*divi        |                |             | ✅            | ✅         | ✅             | ✅          |                |             | ✅            | ✅         | ✅             | ✅          |
 +---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
diff --git a/libc/include/stdfix.yaml b/libc/include/stdfix.yaml
index 2af1dac6468bb2..416e5c2acdd345 100644
--- a/libc/include/stdfix.yaml
+++ b/libc/include/stdfix.yaml
@@ -685,6 +685,22 @@ functions:
       - type: unsigned long int
       - type: unsigned long accum
     guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: mulir
+    standards:
+      - stdc_ext
+    return_type: int
+    arguments:
+      - type: int
+      - type: fract
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: mulilr
+    standards:
+      - stdc_ext
+    return_type: long int
+    arguments:
+      - type: long int
+      - type: long fract
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
   - name: mulik
     standards:
       - stdc_ext
@@ -693,3 +709,43 @@ functions:
       - type: int
       - type: accum
     guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: mulilk
+    standards:
+      - stdc_ext
+    return_type: long int
+    arguments:
+      - type: long int
+      - type: long accum
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: muliur
+    standards:
+      - stdc_ext
+    return_type: unsigned int
+    arguments:
+      - type: unsigned int
+      - type: unsigned fract
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: muliulr
+    standards:
+      - stdc_ext
+    return_type: unsigned long int
+    arguments:
+      - type: unsigned long int
+      - type: unsigned long fract
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: muliuk
+    standards:
+      - stdc_ext
+    return_type: unsigned int
+    arguments:
+      - type: unsigned int
+      - type: unsigned accum
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: muliulk
+    standards:
+      - stdc_ext
+    return_type: unsigned long int
+    arguments:
+      - type: unsigned long int
+      - type: unsigned long accum
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
diff --git a/libc/src/stdfix/CMakeLists.txt b/libc/src/stdfix/CMakeLists.txt
index 660f908aed458f..621a6dbb961842 100644
--- a/libc/src/stdfix/CMakeLists.txt
+++ b/libc/src/stdfix/CMakeLists.txt
@@ -106,7 +106,7 @@ foreach(suffix IN ITEMS r lr k lk ur ulr uk ulk)
   )
 endforeach()
 
-foreach(suffix IN ITEMS k)
+foreach(suffix IN ITEMS r lr k lk ur ulr uk ulk)
   add_entrypoint_object(
     muli${suffix}
     HDRS
diff --git a/libc/src/stdfix/mulilk.cpp b/libc/src/stdfix/mulilk.cpp
new file mode 100644
index 00000000000000..ea2d7fa371d351
--- /dev/null
+++ b/libc/src/stdfix/mulilk.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of mulilk function ---------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "mulilk.h"
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(long int, mulilk, (long int n, long accum m)) {
+  return fixed_point::mulifx<long int, long accum>(n, m);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/mulilk.h b/libc/src/stdfix/mulilk.h
new file mode 100644
index 00000000000000..d53fa68122e9da
--- /dev/null
+++ b/libc/src/stdfix/mulilk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for mulilk ------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_MULILK_H
+#define LLVM_LIBC_SRC_STDFIX_MULILK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+long int mulilk(long int n, long accum m);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_MULILK_H
diff --git a/libc/src/stdfix/mulilr.cpp b/libc/src/stdfix/mulilr.cpp
new file mode 100644
index 00000000000000..26dc499eccfec8
--- /dev/null
+++ b/libc/src/stdfix/mulilr.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of mulilr function ---------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "mulilr.h"
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(long int, mulilr, (long int n, long fract m)) {
+  return fixed_point::mulifx<long int, long fract>(n, m);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/mulilr.h b/libc/src/stdfix/mulilr.h
new file mode 100644
index 00000000000000..c3106b44e9679e
--- /dev/null
+++ b/libc/src/stdfix/mulilr.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for mulilr ------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_MULILR_H
+#define LLVM_LIBC_SRC_STDFIX_MULILR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+long int mulilr(long int n, long fract m);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_MULILR_H
diff --git a/libc/src/stdfix/mulir.cpp b/libc/src/stdfix/mulir.cpp
new file mode 100644
index 00000000000000..558ccd61d9911d
--- /dev/null
+++ b/libc/src/stdfix/mulir.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of mulir function ----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "mulir.h"
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, mulir, (int n, fract m)) {
+  return fixed_point::mulifx<int, fract>(n, m);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/mulir.h b/libc/src/stdfix/mulir.h
new file mode 100644
index 00000000000000..912cbedce8bf98
--- /dev/null
+++ b/libc/src/stdfix/mulir.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for mulir -------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_MULIR_H
+#define LLVM_LIBC_SRC_STDFIX_MULIR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int mulir(int n, fract m);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_MULIR_H
diff --git a/libc/src/stdfix/muliuk.cpp b/libc/src/stdfix/muliuk.cpp
new file mode 100644
index 00000000000000..0db558faef92ce
--- /dev/null
+++ b/libc/src/stdfix/muliuk.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of muliuk function ---------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "muliuk.h"
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(unsigned int, muliuk, (unsigned int n, unsigned accum m)) {
+  return fixed_point::mulifx<unsigned int, unsigned accum>(n, m);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/muliuk.h b/libc/src/stdfix/muliuk.h
new file mode 100644
index 00000000000000..a8726242f70b0c
--- /dev/null
+++ b/libc/src/stdfix/muliuk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for muliuk ------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_MULIUK_H
+#define LLVM_LIBC_SRC_STDFIX_MULIUK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+unsigned int muliuk(unsigned int n, unsigned accum m);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_MULIUK_H
diff --git a/libc/src/stdfix/muliulk.cpp b/libc/src/stdfix/muliulk.cpp
new file mode 100644
index 00000000000000..7434cf0096afec
--- /dev/null
+++ b/libc/src/stdfix/muliulk.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of muliulk function --------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "muliulk.h"
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(unsigned long int, muliulk,
+                   (unsigned long int n, unsigned long accum m)) {
+  return fixed_point::mulifx<unsigned long int, unsigned long accum>(n, m);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/muliulk.h b/libc/src/stdfix/muliulk.h
new file mode 100644
index 00000000000000..af75b1af946c8e
--- /dev/null
+++ b/libc/src/stdfix/muliulk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for muliulk -----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_MULIULK_H
+#define LLVM_LIBC_SRC_STDFIX_MULIULK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+unsigned long int muliulk(unsigned long int n, unsigned long accum m);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_MULIULK_H
diff --git a/libc/src/stdfix/muliulr.cpp b/libc/src/stdfix/muliulr.cpp
new file mode 100644
index 00000000000000..757b551aea1fb3
--- /dev/null
+++ b/libc/src/stdfix/muliulr.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of muliulr function --------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "muliulr.h"
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(unsigned long int, muliulr,
+                   (unsigned long int n, unsigned long fract m)) {
+  return fixed_point::mulifx<unsigned long int, unsigned long fract>(n, m);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/muliulr.h b/libc/src/stdfix/muliulr.h
new file mode 100644
index 00000000000000..342a7a3e90fb67
--- /dev/null
+++ b/libc/src/stdfix/muliulr.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for muliulr -----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_MULIULR_H
+#define LLVM_LIBC_SRC_STDFIX_MULIULR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+unsigned long int muliulr(unsigned long int n, unsigned long fract m);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_MULIULR_H
diff --git a/libc/src/stdfix/muliur.cpp b/libc/src/stdfix/muliur.cpp
new file mode 100644
index 00000000000000..4b1b3a84e81ec6
--- /dev/null
+++ b/libc/src/stdfix/muliur.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of muliur function ---------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "muliur.h"
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(unsigned int, muliur, (unsigned int n, unsigned fract m)) {
+  return fixed_point::mulifx<unsigned int, unsigned fract>(n, m);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/muliur.h b/libc/src/stdfix/muliur.h
new file mode 100644
index 00000000000000..f66ba90af970e4
--- /dev/null
+++ b/libc/src/stdfix/muliur.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for muliur ------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_MULIUR_H
+#define LLVM_LIBC_SRC_STDFIX_MULIUR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+unsigned int muliur(unsigned int n, unsigned fract m);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_MULIUR_H
diff --git a/libc/test/src/stdfix/CMakeLists.txt b/libc/test/src/stdfix/CMakeLists.txt
index e1b5e8db4f5d28..9a58d8bd1d5a37 100644
--- a/libc/test/src/stdfix/CMakeLists.txt
+++ b/libc/test/src/stdfix/CMakeLists.txt
@@ -156,7 +156,7 @@ foreach(suffix IN ITEMS r lr k lk ur ulr uk ulk)
   )
 endforeach()
 
-foreach(suffix IN ITEMS k)
+foreach(suffix IN ITEMS r lr k lk ur ulr uk ulk)
   add_libc_test(
     muli${suffix}_test
     SUITE
diff --git a/libc/test/src/stdfix/mulilk_test.cpp b/libc/test/src/stdfix/mulilk_test.cpp
new file mode 100644
index 00000000000000..1610ca7595f294
--- /dev/null
+++ b/libc/test/src/stdfix/mulilk_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for mulilk ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MuliFxTest.h"
+
+#include "llvm-libc-macros/stdfix-macros.h"
+#include "src/stdfix/mulilk.h"
+
+LIST_MULIFX_TESTS(lk, long int, long accum, LIBC_NAMESPACE::mulilk);
diff --git a/libc/test/src/stdfix/mulilr_test.cpp b/libc/test/src/stdfix/mulilr_test.cpp
new file mode 100644
index 00000000000000..13d3d46e33a7df
--- /dev/null
+++ b/libc/test/src/stdfix/mulilr_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for mulilr ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MuliFxTest.h"
+
+#include "llvm-libc-macros/stdfix-macros.h"
+#include "src/stdfix/mulilr.h"
+
+LIST_MULIFX_TESTS(lr, long int, long fract, LIBC_NAMESPACE::mulilr);
diff --git a/libc/test/src/stdfix/mulir_test.cpp b/libc/test/src/stdfix/mulir_test.cpp
new file mode 100644
index 00000000000000..a51a6480d9fdc9
--- /dev/null
+++ b/libc/test/src/stdfix/mulir_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for mulir -----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MuliFxTest.h"
+
+#include "llvm-libc-macros/stdfix-macros.h"
+#include "src/stdfix/mulir.h"
+
+LIST_MULIFX_TESTS(r, int, fract, LIBC_NAMESPACE::mulir);
diff --git a/libc/test/src/stdfix/muliuk_test.cpp b/libc/test/src/stdfix/muliuk_test.cpp
new file mode 100644
index 00000000000000..2624bdf21b0906
--- /dev/null
+++ b/libc/test/src/stdfix/muliuk_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for muliuk ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MuliFxTest.h"
+
+#include "llvm-libc-macros/stdfix-macros.h"
+#include "src/stdfix/muliuk.h"
+
+LIST_MULIFX_TESTS(uk, unsigned int, unsigned accum, LIBC_NAMESPACE::muliuk);
diff --git a/libc/test/src/stdfix/muliulk_test.cpp b/libc/test/src/stdfix/muliulk_test.cpp
new file mode 100644
index 00000000000000..48a3c88c96b2f6
--- /dev/null
+++ b/libc/test/src/stdfix/muliulk_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for muliulk ---------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MuliFxTest.h"
+
+#include "llvm-libc-macros/stdfix-macros.h"
+#include "src/stdfix/muliulk.h"
+
+LIST_MULIFX_TESTS(ulk, unsigned long int, unsigned long accum,
+                  LIBC_NAMESPACE::muliulk);
diff --git a/libc/test/src/stdfix/muliulr_test.cpp b/libc/test/src/stdfix/muliulr_test.cpp
new file mode 100644
index 00000000000000..cf9396f5756f60
--- /dev/null
+++ b/libc/test/src/stdfix/muliulr_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for muliulr ---------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MuliFxTest.h"
+
+#include "llvm-libc-macros/stdfix-macros.h"
+#include "src/stdfix/muliulr.h"
+
+LIST_MULIFX_TESTS(ulr, unsigned long int, unsigned long fract,
+                  LIBC_NAMESPACE::muliulr);
diff --git a/libc/test/src/stdfix/muliur_test.cpp b/libc/test/src/stdfix/muliur_test.cpp
new file mode 100644
index 00000000000000..d96f4a103580c4
--- /dev/null
+++ b/libc/test/src/stdfix/muliur_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for muliur ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MuliFxTest.h"
+
+#include "llvm-libc-macros/stdfix-macros.h"
+#include "src/stdfix/muliur.h"
+
+LIST_MULIFX_TESTS(ur, unsigned int, unsigned fract, LIBC_NAMESPACE::muliur);

>From 2704cacc87338a53ea47763c2308a539ea1c5f62 Mon Sep 17 00:00:00 2001
From: Jaeyong Lee <jay at glendalab.com>
Date: Wed, 4 Nov 2026 13:08:05 +0900
Subject: [PATCH 08/15] nit: remove blank line

---
 libc/test/src/stdfix/MuliFxTest.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libc/test/src/stdfix/MuliFxTest.h b/libc/test/src/stdfix/MuliFxTest.h
index 7404e48575bbfa..18f5b6421e11c3 100644
--- a/libc/test/src/stdfix/MuliFxTest.h
+++ b/libc/test/src/stdfix/MuliFxTest.h
@@ -33,7 +33,6 @@ class MuliFxTest : public LIBC_NAMESPACE::testing::Test {
   typedef IntType (*MuliFxFunc)(IntType, FXType);
 
   void testBasicNumbers(MuliFxFunc func) {
-
     EXPECT_EQ(func(0, epsilon), static_cast<IntType>(0));
     EXPECT_EQ(func(0, max), static_cast<IntType>(0));
 
@@ -91,7 +90,6 @@ class MuliFxTest : public LIBC_NAMESPACE::testing::Test {
   }
 
   void testEdgeCases(MuliFxFunc func) {
-
     constexpr IntType int_max = cpp::numeric_limits<IntType>::max();
     constexpr IntType int_min = cpp::numeric_limits<IntType>::min();
 

>From de47052e10dc5b6ca900632b680d496cf853483f Mon Sep 17 00:00:00 2001
From: Jaeyong Lee <jay at glendalab.com>
Date: Wed, 4 Nov 2026 13:17:17 +0900
Subject: [PATCH 09/15] Use new LLVM file headers

---
 libc/src/stdfix/mulik.cpp             | 7 ++++++-
 libc/src/stdfix/mulik.h               | 7 ++++++-
 libc/src/stdfix/mulilk.cpp            | 7 ++++++-
 libc/src/stdfix/mulilk.h              | 7 ++++++-
 libc/src/stdfix/mulilr.cpp            | 7 ++++++-
 libc/src/stdfix/mulilr.h              | 7 ++++++-
 libc/src/stdfix/mulir.cpp             | 7 ++++++-
 libc/src/stdfix/mulir.h               | 7 ++++++-
 libc/src/stdfix/muliuk.cpp            | 7 ++++++-
 libc/src/stdfix/muliuk.h              | 7 ++++++-
 libc/src/stdfix/muliulk.cpp           | 7 ++++++-
 libc/src/stdfix/muliulk.h             | 7 ++++++-
 libc/src/stdfix/muliulr.cpp           | 7 ++++++-
 libc/src/stdfix/muliulr.h             | 7 ++++++-
 libc/src/stdfix/muliur.cpp            | 7 ++++++-
 libc/src/stdfix/muliur.h              | 7 ++++++-
 libc/test/src/stdfix/MuliFxTest.h     | 7 ++++++-
 libc/test/src/stdfix/mulik_test.cpp   | 7 ++++++-
 libc/test/src/stdfix/mulilk_test.cpp  | 7 ++++++-
 libc/test/src/stdfix/mulilr_test.cpp  | 7 ++++++-
 libc/test/src/stdfix/mulir_test.cpp   | 7 ++++++-
 libc/test/src/stdfix/muliuk_test.cpp  | 7 ++++++-
 libc/test/src/stdfix/muliulk_test.cpp | 7 ++++++-
 libc/test/src/stdfix/muliulr_test.cpp | 7 ++++++-
 libc/test/src/stdfix/muliur_test.cpp  | 7 ++++++-
 25 files changed, 150 insertions(+), 25 deletions(-)

diff --git a/libc/src/stdfix/mulik.cpp b/libc/src/stdfix/mulik.cpp
index 4673d9fca76b2c..74269d39149ca1 100644
--- a/libc/src/stdfix/mulik.cpp
+++ b/libc/src/stdfix/mulik.cpp
@@ -1,10 +1,15 @@
-//===-- Implementation of mulik function ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of mulik function.
+///
+//===----------------------------------------------------------------------===//
 
 #include "mulik.h"
 #include "include/llvm-libc-macros/stdfix-macros.h"
diff --git a/libc/src/stdfix/mulik.h b/libc/src/stdfix/mulik.h
index 001a2ebed1cdc2..b5c1bcffbeed70 100644
--- a/libc/src/stdfix/mulik.h
+++ b/libc/src/stdfix/mulik.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for mulik -------------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for mulik.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC_STDFIX_MULIK_H
 #define LLVM_LIBC_SRC_STDFIX_MULIK_H
diff --git a/libc/src/stdfix/mulilk.cpp b/libc/src/stdfix/mulilk.cpp
index ea2d7fa371d351..829fcc782508a5 100644
--- a/libc/src/stdfix/mulilk.cpp
+++ b/libc/src/stdfix/mulilk.cpp
@@ -1,10 +1,15 @@
-//===-- Implementation of mulilk function ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of mulilk function.
+///
+//===----------------------------------------------------------------------===//
 
 #include "mulilk.h"
 #include "include/llvm-libc-macros/stdfix-macros.h"
diff --git a/libc/src/stdfix/mulilk.h b/libc/src/stdfix/mulilk.h
index d53fa68122e9da..c4bfd63bcee076 100644
--- a/libc/src/stdfix/mulilk.h
+++ b/libc/src/stdfix/mulilk.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for mulilk ------------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for mulilk.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC_STDFIX_MULILK_H
 #define LLVM_LIBC_SRC_STDFIX_MULILK_H
diff --git a/libc/src/stdfix/mulilr.cpp b/libc/src/stdfix/mulilr.cpp
index 26dc499eccfec8..e2d0d0264a553e 100644
--- a/libc/src/stdfix/mulilr.cpp
+++ b/libc/src/stdfix/mulilr.cpp
@@ -1,10 +1,15 @@
-//===-- Implementation of mulilr function ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of mulilr function.
+///
+//===----------------------------------------------------------------------===//
 
 #include "mulilr.h"
 #include "include/llvm-libc-macros/stdfix-macros.h"
diff --git a/libc/src/stdfix/mulilr.h b/libc/src/stdfix/mulilr.h
index c3106b44e9679e..02317a82c02c28 100644
--- a/libc/src/stdfix/mulilr.h
+++ b/libc/src/stdfix/mulilr.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for mulilr ------------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for mulilr.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC_STDFIX_MULILR_H
 #define LLVM_LIBC_SRC_STDFIX_MULILR_H
diff --git a/libc/src/stdfix/mulir.cpp b/libc/src/stdfix/mulir.cpp
index 558ccd61d9911d..4bed8546fa9a56 100644
--- a/libc/src/stdfix/mulir.cpp
+++ b/libc/src/stdfix/mulir.cpp
@@ -1,10 +1,15 @@
-//===-- Implementation of mulir function ----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of mulir function.
+///
+//===----------------------------------------------------------------------===//
 
 #include "mulir.h"
 #include "include/llvm-libc-macros/stdfix-macros.h"
diff --git a/libc/src/stdfix/mulir.h b/libc/src/stdfix/mulir.h
index 912cbedce8bf98..b0195773b28221 100644
--- a/libc/src/stdfix/mulir.h
+++ b/libc/src/stdfix/mulir.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for mulir -------------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for mulir.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC_STDFIX_MULIR_H
 #define LLVM_LIBC_SRC_STDFIX_MULIR_H
diff --git a/libc/src/stdfix/muliuk.cpp b/libc/src/stdfix/muliuk.cpp
index 0db558faef92ce..8c83aef918224f 100644
--- a/libc/src/stdfix/muliuk.cpp
+++ b/libc/src/stdfix/muliuk.cpp
@@ -1,10 +1,15 @@
-//===-- Implementation of muliuk function ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of muliuk function.
+///
+//===----------------------------------------------------------------------===//
 
 #include "muliuk.h"
 #include "include/llvm-libc-macros/stdfix-macros.h"
diff --git a/libc/src/stdfix/muliuk.h b/libc/src/stdfix/muliuk.h
index a8726242f70b0c..d5085fce6550fa 100644
--- a/libc/src/stdfix/muliuk.h
+++ b/libc/src/stdfix/muliuk.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for muliuk ------------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for muliuk.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC_STDFIX_MULIUK_H
 #define LLVM_LIBC_SRC_STDFIX_MULIUK_H
diff --git a/libc/src/stdfix/muliulk.cpp b/libc/src/stdfix/muliulk.cpp
index 7434cf0096afec..55e3ea6720bc23 100644
--- a/libc/src/stdfix/muliulk.cpp
+++ b/libc/src/stdfix/muliulk.cpp
@@ -1,10 +1,15 @@
-//===-- Implementation of muliulk function --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of muliulk function.
+///
+//===----------------------------------------------------------------------===//
 
 #include "muliulk.h"
 #include "include/llvm-libc-macros/stdfix-macros.h"
diff --git a/libc/src/stdfix/muliulk.h b/libc/src/stdfix/muliulk.h
index af75b1af946c8e..b144153a2f066d 100644
--- a/libc/src/stdfix/muliulk.h
+++ b/libc/src/stdfix/muliulk.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for muliulk -----------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for muliulk.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC_STDFIX_MULIULK_H
 #define LLVM_LIBC_SRC_STDFIX_MULIULK_H
diff --git a/libc/src/stdfix/muliulr.cpp b/libc/src/stdfix/muliulr.cpp
index 757b551aea1fb3..edd3381239e06d 100644
--- a/libc/src/stdfix/muliulr.cpp
+++ b/libc/src/stdfix/muliulr.cpp
@@ -1,10 +1,15 @@
-//===-- Implementation of muliulr function --------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of muliulr function.
+///
+//===----------------------------------------------------------------------===//
 
 #include "muliulr.h"
 #include "include/llvm-libc-macros/stdfix-macros.h"
diff --git a/libc/src/stdfix/muliulr.h b/libc/src/stdfix/muliulr.h
index 342a7a3e90fb67..7559fd2ad5921d 100644
--- a/libc/src/stdfix/muliulr.h
+++ b/libc/src/stdfix/muliulr.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for muliulr -----------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for muliulr.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC_STDFIX_MULIULR_H
 #define LLVM_LIBC_SRC_STDFIX_MULIULR_H
diff --git a/libc/src/stdfix/muliur.cpp b/libc/src/stdfix/muliur.cpp
index 4b1b3a84e81ec6..5d3c195a6a4f46 100644
--- a/libc/src/stdfix/muliur.cpp
+++ b/libc/src/stdfix/muliur.cpp
@@ -1,10 +1,15 @@
-//===-- Implementation of muliur function ---------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of muliur function.
+///
+//===----------------------------------------------------------------------===//
 
 #include "muliur.h"
 #include "include/llvm-libc-macros/stdfix-macros.h"
diff --git a/libc/src/stdfix/muliur.h b/libc/src/stdfix/muliur.h
index f66ba90af970e4..0d9ebfd206fa63 100644
--- a/libc/src/stdfix/muliur.h
+++ b/libc/src/stdfix/muliur.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for muliur ------------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for muliur.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC_STDFIX_MULIUR_H
 #define LLVM_LIBC_SRC_STDFIX_MULIUR_H
diff --git a/libc/test/src/stdfix/MuliFxTest.h b/libc/test/src/stdfix/MuliFxTest.h
index 18f5b6421e11c3..d8a9046d95db97 100644
--- a/libc/test/src/stdfix/MuliFxTest.h
+++ b/libc/test/src/stdfix/MuliFxTest.h
@@ -1,10 +1,15 @@
-//===-- Utility class to test mulifx functions ------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Utility class to test mulifx functions.
+///
+//===----------------------------------------------------------------------===//
 
 #include "test/UnitTest/Test.h"
 
diff --git a/libc/test/src/stdfix/mulik_test.cpp b/libc/test/src/stdfix/mulik_test.cpp
index e8971c4ab6babc..944aebb5fd110e 100644
--- a/libc/test/src/stdfix/mulik_test.cpp
+++ b/libc/test/src/stdfix/mulik_test.cpp
@@ -1,10 +1,15 @@
-//===-- Unittests for mulik -----------------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for mulik.
+///
+//===----------------------------------------------------------------------===//
 
 #include "MuliFxTest.h"
 
diff --git a/libc/test/src/stdfix/mulilk_test.cpp b/libc/test/src/stdfix/mulilk_test.cpp
index 1610ca7595f294..a4dd95d16249b9 100644
--- a/libc/test/src/stdfix/mulilk_test.cpp
+++ b/libc/test/src/stdfix/mulilk_test.cpp
@@ -1,10 +1,15 @@
-//===-- Unittests for mulilk ----------------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for mulilk.
+///
+//===----------------------------------------------------------------------===//
 
 #include "MuliFxTest.h"
 
diff --git a/libc/test/src/stdfix/mulilr_test.cpp b/libc/test/src/stdfix/mulilr_test.cpp
index 13d3d46e33a7df..322adb550e4362 100644
--- a/libc/test/src/stdfix/mulilr_test.cpp
+++ b/libc/test/src/stdfix/mulilr_test.cpp
@@ -1,10 +1,15 @@
-//===-- Unittests for mulilr ----------------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for mulilr.
+///
+//===----------------------------------------------------------------------===//
 
 #include "MuliFxTest.h"
 
diff --git a/libc/test/src/stdfix/mulir_test.cpp b/libc/test/src/stdfix/mulir_test.cpp
index a51a6480d9fdc9..61707898575a61 100644
--- a/libc/test/src/stdfix/mulir_test.cpp
+++ b/libc/test/src/stdfix/mulir_test.cpp
@@ -1,10 +1,15 @@
-//===-- Unittests for mulir -----------------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for mulir.
+///
+//===----------------------------------------------------------------------===//
 
 #include "MuliFxTest.h"
 
diff --git a/libc/test/src/stdfix/muliuk_test.cpp b/libc/test/src/stdfix/muliuk_test.cpp
index 2624bdf21b0906..abf3d1cec516af 100644
--- a/libc/test/src/stdfix/muliuk_test.cpp
+++ b/libc/test/src/stdfix/muliuk_test.cpp
@@ -1,10 +1,15 @@
-//===-- Unittests for muliuk ----------------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for muliuk.
+///
+//===----------------------------------------------------------------------===//
 
 #include "MuliFxTest.h"
 
diff --git a/libc/test/src/stdfix/muliulk_test.cpp b/libc/test/src/stdfix/muliulk_test.cpp
index 48a3c88c96b2f6..7282c12ca7b4fc 100644
--- a/libc/test/src/stdfix/muliulk_test.cpp
+++ b/libc/test/src/stdfix/muliulk_test.cpp
@@ -1,10 +1,15 @@
-//===-- Unittests for muliulk ---------------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for muliulk.
+///
+//===----------------------------------------------------------------------===//
 
 #include "MuliFxTest.h"
 
diff --git a/libc/test/src/stdfix/muliulr_test.cpp b/libc/test/src/stdfix/muliulr_test.cpp
index cf9396f5756f60..9f2d29514cb704 100644
--- a/libc/test/src/stdfix/muliulr_test.cpp
+++ b/libc/test/src/stdfix/muliulr_test.cpp
@@ -1,10 +1,15 @@
-//===-- Unittests for muliulr ---------------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for muliulr.
+///
+//===----------------------------------------------------------------------===//
 
 #include "MuliFxTest.h"
 
diff --git a/libc/test/src/stdfix/muliur_test.cpp b/libc/test/src/stdfix/muliur_test.cpp
index d96f4a103580c4..0c4bccef7bf516 100644
--- a/libc/test/src/stdfix/muliur_test.cpp
+++ b/libc/test/src/stdfix/muliur_test.cpp
@@ -1,10 +1,15 @@
-//===-- Unittests for muliur ----------------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for muliur.
+///
+//===----------------------------------------------------------------------===//
 
 #include "MuliFxTest.h"
 

>From 18af9e6155074798a53de6a29a29612d6bc052de Mon Sep 17 00:00:00 2001
From: Jaeyong Lee <jay at glendalab.com>
Date: Wed, 4 Nov 2026 13:23:05 +0900
Subject: [PATCH 10/15] Improve testEdgeCases

---
 libc/test/src/stdfix/MuliFxTest.h | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/libc/test/src/stdfix/MuliFxTest.h b/libc/test/src/stdfix/MuliFxTest.h
index d8a9046d95db97..9faec7ef9cb006 100644
--- a/libc/test/src/stdfix/MuliFxTest.h
+++ b/libc/test/src/stdfix/MuliFxTest.h
@@ -100,16 +100,15 @@ class MuliFxTest : public LIBC_NAMESPACE::testing::Test {
 
     if constexpr (has_integral) {
       EXPECT_EQ(func(int_max, static_cast<FXType>(1)), int_max);
-
-      if constexpr (is_signed) {
-        EXPECT_EQ(func(int_max, static_cast<FXType>(-1)), -int_max);
-      }
+      EXPECT_EQ(func(int_min / 2, static_cast<FXType>(2)), int_min);
     }
 
     EXPECT_EQ(func(int_max, one_half), int_max / 2);
+    EXPECT_EQ(func(int_min, one_half), int_min / 2);
 
     if constexpr (is_signed) {
-      EXPECT_EQ(func(int_min, one_half), int_min / 2);
+      EXPECT_EQ(func(int_max, static_cast<FXType>(-1)), -int_max);
+      EXPECT_EQ(func(int_min + 1, one_half), (int_min + 1) / 2);
     }
 
     if constexpr (FXRep::FRACTION_LEN < cpp::numeric_limits<IntType>::digits) {

>From 38b4966a46f93f9c5155173378e155224e86c8bd Mon Sep 17 00:00:00 2001
From: Jaeyong Lee <jay at glendalab.com>
Date: Wed, 4 Nov 2026 13:27:59 +0900
Subject: [PATCH 11/15] Add test cases for multiplying with zero

---
 libc/test/src/stdfix/MuliFxTest.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libc/test/src/stdfix/MuliFxTest.h b/libc/test/src/stdfix/MuliFxTest.h
index 9faec7ef9cb006..b3bb283df72350 100644
--- a/libc/test/src/stdfix/MuliFxTest.h
+++ b/libc/test/src/stdfix/MuliFxTest.h
@@ -26,6 +26,7 @@ class MuliFxTest : public LIBC_NAMESPACE::testing::Test {
 
   static constexpr FXType max = FXRep::MAX();
   static constexpr FXType min = FXRep::MIN();
+  static constexpr FXType zero = FXRep::ZERO();
   static constexpr FXType epsilon = FXRep::EPS();
   static constexpr FXType one_half = FXRep::ONE_HALF();
   static constexpr FXType one_fourth = FXRep::ONE_FOURTH();
@@ -38,6 +39,8 @@ class MuliFxTest : public LIBC_NAMESPACE::testing::Test {
   typedef IntType (*MuliFxFunc)(IntType, FXType);
 
   void testBasicNumbers(MuliFxFunc func) {
+    EXPECT_EQ(func(0, zero), static_cast<IntType>(0));
+    EXPECT_EQ(func(1, zero), static_cast<IntType>(0));
     EXPECT_EQ(func(0, epsilon), static_cast<IntType>(0));
     EXPECT_EQ(func(0, max), static_cast<IntType>(0));
 
@@ -103,6 +106,8 @@ class MuliFxTest : public LIBC_NAMESPACE::testing::Test {
       EXPECT_EQ(func(int_min / 2, static_cast<FXType>(2)), int_min);
     }
 
+    EXPECT_EQ(func(int_max, zero), static_cast<IntType>(0));
+    EXPECT_EQ(func(int_min, zero), static_cast<IntType>(0));
     EXPECT_EQ(func(int_max, one_half), int_max / 2);
     EXPECT_EQ(func(int_min, one_half), int_min / 2);
 

>From f5c237516addd7f5cddc99bb96a34df0dcea4b35 Mon Sep 17 00:00:00 2001
From: Jaeyong Lee <jay at glendalab.com>
Date: Wed, 4 Nov 2026 14:45:02 +0900
Subject: [PATCH 12/15] Rewrite mulifx to drop WideType

---
 libc/src/__support/fixed_point/fx_bits.h | 41 +++++++++++-------------
 1 file changed, 19 insertions(+), 22 deletions(-)

diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index 0037f000915fc9..586105067ae286 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -417,33 +417,30 @@ mulifx(IntType n, FXType m) {
   static_assert(cpp::is_signed_v<IntType> == (FXRep::SIGN_LEN > 0),
                 "IntType and FXType must have matching signedness");
 
-  CompType m_comp = static_cast<CompType>(FXBits(m).get_bits());
-
   constexpr int F = FXRep::FRACTION_LEN;
 
-  constexpr int INTERMEDIATE_BITS =
-      cpp::numeric_limits<IntType>::digits + FXRep::VALUE_LEN;
+  using LargerType = cpp::make_unsigned_t<cpp::conditional_t<
+      (sizeof(IntType) >= sizeof(CompType)), IntType, CompType>>;
+  using CalcType =
+      cpp::conditional_t<(2 * F <= cpp::numeric_limits<LargerType>::digits),
+                         LargerType, uint64_t>;
 
-  using WideType = cpp::conditional_t<
-      cpp::is_signed_v<IntType>,
-      cpp::conditional_t<INTERMEDIATE_BITS <=
-                             cpp::numeric_limits<int64_t>::digits,
-                         int64_t, Int128>,
-      cpp::conditional_t<INTERMEDIATE_BITS <=
-                             cpp::numeric_limits<uint64_t>::digits,
-                         uint64_t, UInt128>>;
+  CompType m_comp = static_cast<CompType>(FXBits(m).get_bits());
+  bool is_negative = (n < 0) != (m_comp < 0);
 
-  WideType unscaled_result =
-      static_cast<WideType>(n) * static_cast<WideType>(m_comp);
+  CalcType n_mag =
+      (n < 0) ? -static_cast<CalcType>(n) : static_cast<CalcType>(n);
+  CalcType m_mag = (m_comp < 0) ? -static_cast<CalcType>(m_comp)
+                                : static_cast<CalcType>(m_comp);
 
-  if constexpr (FXRep::SIGN_LEN > 0) {
-    constexpr WideType BIAS = (WideType(1) << F) - 1;
-    WideType result =
-        (unscaled_result + (unscaled_result < 0 ? BIAS : WideType(0))) >> F;
-    return static_cast<IntType>(result);
-  }
-  WideType result = unscaled_result >> F;
-  return static_cast<IntType>(result);
+  constexpr CalcType LOW_MASK = mask_trailing_ones<CalcType, F>();
+  CalcType n_hi = n_mag >> F;
+  CalcType n_lo = n_mag & LOW_MASK;
+  CalcType m_hi = m_mag >> F;
+  CalcType m_lo = m_mag & LOW_MASK;
+
+  CalcType result = m_hi * n_mag + n_hi * m_lo + ((n_lo * m_lo) >> F);
+  return static_cast<IntType>(is_negative ? -result : result);
 }
 
 } // namespace fixed_point

>From 38f6702e60838f9327e125d187cd230da4fb8c8f Mon Sep 17 00:00:00 2001
From: Jaeyong Lee <jay at glendalab.com>
Date: Thu, 5 Nov 2026 04:37:07 +0900
Subject: [PATCH 13/15] nit: rm empty line between class start and body

---
 libc/test/src/stdfix/MuliFxTest.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libc/test/src/stdfix/MuliFxTest.h b/libc/test/src/stdfix/MuliFxTest.h
index b3bb283df72350..97dfc7ce112206 100644
--- a/libc/test/src/stdfix/MuliFxTest.h
+++ b/libc/test/src/stdfix/MuliFxTest.h
@@ -21,7 +21,6 @@ namespace cpp = LIBC_NAMESPACE::cpp;
 
 template <typename IntType, typename FXType>
 class MuliFxTest : public LIBC_NAMESPACE::testing::Test {
-
   using FXRep = LIBC_NAMESPACE::fixed_point::FXRep<FXType>;
 
   static constexpr FXType max = FXRep::MAX();

>From b495bed826f70abe0db6ca3eb841478fdf962ec8 Mon Sep 17 00:00:00 2001
From: Jaeyong Lee <jay at glendalab.com>
Date: Thu, 5 Nov 2026 04:42:53 +0900
Subject: [PATCH 14/15] Ensure the CalcType is actually large enough

---
 libc/src/__support/fixed_point/fx_bits.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index 586105067ae286..2770df95379b69 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -424,6 +424,8 @@ mulifx(IntType n, FXType m) {
   using CalcType =
       cpp::conditional_t<(2 * F <= cpp::numeric_limits<LargerType>::digits),
                          LargerType, uint64_t>;
+  static_assert(sizeof(CalcType) >= sizeof(LargerType) &&
+                2 * F <= cpp::numeric_limits<CalcType>::digits);
 
   CompType m_comp = static_cast<CompType>(FXBits(m).get_bits());
   bool is_negative = (n < 0) != (m_comp < 0);

>From e2c5c5c54c7883a05df8f077814ce85bab911a33 Mon Sep 17 00:00:00 2001
From: Jaeyong Lee <jay at glendalab.com>
Date: Thu, 5 Nov 2026 04:49:14 +0900
Subject: [PATCH 15/15] Guard sign handling with if constexpr

---
 libc/src/__support/fixed_point/fx_bits.h | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index 2770df95379b69..47798d0f6730ab 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -428,12 +428,17 @@ mulifx(IntType n, FXType m) {
                 2 * F <= cpp::numeric_limits<CalcType>::digits);
 
   CompType m_comp = static_cast<CompType>(FXBits(m).get_bits());
-  bool is_negative = (n < 0) != (m_comp < 0);
-
-  CalcType n_mag =
-      (n < 0) ? -static_cast<CalcType>(n) : static_cast<CalcType>(n);
-  CalcType m_mag = (m_comp < 0) ? -static_cast<CalcType>(m_comp)
-                                : static_cast<CalcType>(m_comp);
+  bool is_negative = false;
+  CalcType n_mag, m_mag;
+  if constexpr (FXRep::SIGN_LEN > 0) {
+    is_negative = (n < 0) != (m_comp < 0);
+    n_mag = (n < 0) ? -static_cast<CalcType>(n) : static_cast<CalcType>(n);
+    m_mag = (m_comp < 0) ? -static_cast<CalcType>(m_comp)
+                         : static_cast<CalcType>(m_comp);
+  } else {
+    n_mag = static_cast<CalcType>(n);
+    m_mag = static_cast<CalcType>(m_comp);
+  }
 
   constexpr CalcType LOW_MASK = mask_trailing_ones<CalcType, F>();
   CalcType n_hi = n_mag >> F;
@@ -442,7 +447,10 @@ mulifx(IntType n, FXType m) {
   CalcType m_lo = m_mag & LOW_MASK;
 
   CalcType result = m_hi * n_mag + n_hi * m_lo + ((n_lo * m_lo) >> F);
-  return static_cast<IntType>(is_negative ? -result : result);
+  if constexpr (FXRep::SIGN_LEN > 0)
+    result = is_negative ? -result : result;
+
+  return static_cast<IntType>(result);
 }
 
 } // namespace fixed_point



More information about the libc-commits mailing list