[libc-commits] [libc] [libc][stdfix] Implement divifx functions in LLVM libc (PR #206115)
via libc-commits
libc-commits at lists.llvm.org
Fri Jun 26 08:51:08 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: sohail (sohail103)
<details>
<summary>Changes</summary>
This PR implements the following 8 functions along with unit tests.
```c
int divir(int, fract);
long int divilr(long int, long fract);
int divik(int, accum);
long int divilk(long int, long accum);
unsigned int diviur(unsigned int, unsigned fract);
unsigned long int diviulr(unsigned long int, unsigned long fract);
unsigned int diviuk(unsigned int, unsigned accum);
unsigned long int diviulk(unsigned long int, unsigned long accum);
```
Fixes #<!-- -->129124.
---
Patch is 35.85 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/206115.diff
35 Files Affected:
- (modified) libc/config/baremetal/arm/entrypoints.txt (+8)
- (modified) libc/config/baremetal/riscv/entrypoints.txt (+8)
- (modified) libc/config/linux/riscv/entrypoints.txt (+8)
- (modified) libc/config/linux/x86_64/entrypoints.txt (+8)
- (modified) libc/docs/headers/stdfix.rst (+1-1)
- (modified) libc/include/stdfix.yaml (+64)
- (modified) libc/src/__support/fixed_point/CMakeLists.txt (+1)
- (modified) libc/src/__support/fixed_point/fx_bits.h (+46)
- (modified) libc/src/stdfix/CMakeLists.txt (+14)
- (added) libc/src/stdfix/divik.cpp (+21)
- (added) libc/src/stdfix/divik.h (+21)
- (added) libc/src/stdfix/divilk.cpp (+21)
- (added) libc/src/stdfix/divilk.h (+21)
- (added) libc/src/stdfix/divilr.cpp (+21)
- (added) libc/src/stdfix/divilr.h (+21)
- (added) libc/src/stdfix/divir.cpp (+21)
- (added) libc/src/stdfix/divir.h (+21)
- (added) libc/src/stdfix/diviuk.cpp (+20)
- (added) libc/src/stdfix/diviuk.h (+21)
- (added) libc/src/stdfix/diviulk.cpp (+22)
- (added) libc/src/stdfix/diviulk.h (+21)
- (added) libc/src/stdfix/diviulr.cpp (+21)
- (added) libc/src/stdfix/diviulr.h (+21)
- (added) libc/src/stdfix/diviur.cpp (+21)
- (added) libc/src/stdfix/diviur.h (+21)
- (modified) libc/test/src/stdfix/CMakeLists.txt (+17)
- (added) libc/test/src/stdfix/DiviFxTest.h (+105)
- (added) libc/test/src/stdfix/divik_test.cpp (+14)
- (added) libc/test/src/stdfix/divilk_test.cpp (+14)
- (added) libc/test/src/stdfix/divilr_test.cpp (+14)
- (added) libc/test/src/stdfix/divir_test.cpp (+14)
- (added) libc/test/src/stdfix/diviuk_test.cpp (+14)
- (added) libc/test/src/stdfix/diviulk_test.cpp (+15)
- (added) libc/test/src/stdfix/diviulr_test.cpp (+15)
- (added) libc/test/src/stdfix/diviur_test.cpp (+14)
``````````diff
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index a5c1b20a7a434..894c6dcd760c7 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -970,6 +970,14 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.idivulr
libc.src.stdfix.idivuk
libc.src.stdfix.idivulk
+ libc.src.stdfix.divir
+ libc.src.stdfix.divilr
+ libc.src.stdfix.divik
+ libc.src.stdfix.divilk
+ libc.src.stdfix.diviur
+ libc.src.stdfix.diviulr
+ libc.src.stdfix.diviuk
+ libc.src.stdfix.diviulk
)
endif()
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 60bc924993fc8..4194135f50a0c 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -967,6 +967,14 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.idivulr
libc.src.stdfix.idivuk
libc.src.stdfix.idivulk
+ libc.src.stdfix.divir
+ libc.src.stdfix.divilr
+ libc.src.stdfix.divik
+ libc.src.stdfix.divilk
+ libc.src.stdfix.diviur
+ libc.src.stdfix.diviulr
+ libc.src.stdfix.diviuk
+ libc.src.stdfix.diviulk
)
endif()
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 2508de5cfe5a4..33e588d9aa837 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1102,6 +1102,14 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.idivuk
libc.src.stdfix.idivulk
libc.src.stdfix.rdivi
+ libc.src.stdfix.divir
+ libc.src.stdfix.divilr
+ libc.src.stdfix.divik
+ libc.src.stdfix.divilk
+ libc.src.stdfix.diviur
+ libc.src.stdfix.diviulr
+ libc.src.stdfix.diviuk
+ libc.src.stdfix.diviulk
)
endif()
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 5ace968a739c8..96cbebdfa1609 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1173,6 +1173,14 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.idivuk
libc.src.stdfix.idivulk
libc.src.stdfix.rdivi
+ libc.src.stdfix.divir
+ libc.src.stdfix.divilr
+ libc.src.stdfix.divik
+ libc.src.stdfix.divilk
+ libc.src.stdfix.diviur
+ libc.src.stdfix.diviulr
+ libc.src.stdfix.diviuk
+ libc.src.stdfix.diviulk
)
endif()
diff --git a/libc/docs/headers/stdfix.rst b/libc/docs/headers/stdfix.rst
index 76ac7e7b71c95..efb836f964fa2 100644
--- a/libc/docs/headers/stdfix.rst
+++ b/libc/docs/headers/stdfix.rst
@@ -73,7 +73,7 @@ The following functions are included in the ISO/IEC TR 18037:2008 standard.
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
| countls | |check| | |check| | |check| | |check| | |check| | |check| | |check| | |check| | |check| | |check| | |check| | |check| |
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
-| divi\* | | | | | | | | | | | | |
+| divi\* | | | |check| | |check| | |check| | |check| | | | |check| | |check| | |check| | |check| |
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
| idiv\* | |check| | |check| | |check| | |check| | |check| | |check| | |check| | |check| | |check| | |check| | |check| | |check| |
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
diff --git a/libc/include/stdfix.yaml b/libc/include/stdfix.yaml
index 8b7485555c080..f91e4ea620e3e 100644
--- a/libc/include/stdfix.yaml
+++ b/libc/include/stdfix.yaml
@@ -565,3 +565,67 @@ functions:
- type: int
- type: int
guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: divir
+ standards:
+ - stdc_ext
+ return_type: int
+ arguments:
+ - type: int
+ - type: fract
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: divilr
+ standards:
+ - stdc_ext
+ return_type: long int
+ arguments:
+ - type: long int
+ - type: long fract
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: divik
+ standards:
+ - stdc_ext
+ return_type: int
+ arguments:
+ - type: int
+ - type: accum
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: divilk
+ standards:
+ - stdc_ext
+ return_type: long int
+ arguments:
+ - type: long int
+ - type: long accum
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: diviur
+ standards:
+ - stdc_ext
+ return_type: unsigned int
+ arguments:
+ - type: unsigned int
+ - type: unsigned fract
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: diviulr
+ standards:
+ - stdc_ext
+ return_type: unsigned long int
+ arguments:
+ - type: unsigned long int
+ - type: unsigned long fract
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: diviuk
+ standards:
+ - stdc_ext
+ return_type: unsigned int
+ arguments:
+ - type: unsigned int
+ - type: unsigned accum
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: diviulk
+ 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/__support/fixed_point/CMakeLists.txt b/libc/src/__support/fixed_point/CMakeLists.txt
index 145eedb6ae8e7..c1b0ab30e0307 100644
--- a/libc/src/__support/fixed_point/CMakeLists.txt
+++ b/libc/src/__support/fixed_point/CMakeLists.txt
@@ -23,6 +23,7 @@ add_header_library(
libc.src.__support.CPP.bit
libc.src.__support.CPP.limits
libc.src.__support.math_extras
+ libc.src.__support.uint128
)
add_header_library(
diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index 91814bda7dd7e..8622040e2215e 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -14,12 +14,14 @@
#include "src/__support/CPP/bit.h"
#include "src/__support/CPP/limits.h" // numeric_limits
#include "src/__support/CPP/type_traits.h"
+#include "src/__support/CPP/type_traits/conditional.h"
#include "src/__support/libc_assert.h"
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
#include "src/__support/macros/null_check.h" // LIBC_CRASH_ON_VALUE
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
#include "src/__support/math_extras.h"
+#include "src/__support/uint128.h"
#include "fx_rep.h"
@@ -333,6 +335,50 @@ template <typename XType> LIBC_INLINE constexpr XType divi(int n, int d) {
}
}
+// divide 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. all divifx variants
+// satisfy this requirement.
+template <typename IntType, typename FXType>
+LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_fixed_point_v<FXType>, IntType>
+divifx(IntType n, FXType d) {
+ 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");
+
+ // UB if denominator is 0
+ LIBC_CRASH_ON_VALUE(d, FXRep::ZERO());
+
+ if (LIBC_UNLIKELY(n == 0)) {
+ return static_cast<IntType>(0);
+ }
+
+ // get integer representation of denominator
+ CompType d_comp = static_cast<CompType>(FXBits(d).get_bits());
+
+ constexpr int F = FXRep::FRACTION_LEN;
+
+ // calculating the required number of bits to represent n*2^F without
+ // overflowing
+ constexpr int INTERMEDIATE_BITS =
+ sizeof(IntType) * 8 - cpp::is_signed_v<IntType> + F;
+
+ // use 64 or 128 bit intermediates depending on INTERMEDIATE_BITS
+ 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>>;
+
+ // (n*2^F/d)
+ WideType scaled_n = static_cast<WideType>(n) << F;
+ WideType result = scaled_n / static_cast<WideType>(d_comp);
+
+ 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 e9841cd940315..b7121407e0307 100644
--- a/libc/src/stdfix/CMakeLists.txt
+++ b/libc/src/stdfix/CMakeLists.txt
@@ -102,6 +102,20 @@ foreach(suffix IN ITEMS r)
)
endforeach()
+foreach(suffix IN ITEMS r lr k lk ur ulr uk ulk)
+ add_entrypoint_object(
+ divi${suffix}
+ HDRS
+ divi${suffix}.h
+ SRCS
+ divi${suffix}.cpp
+ COMPILE_OPTIONS
+ ${libc_opt_high_flag}
+ DEPENDS
+ libc.src.__support.fixed_point.fx_bits
+ )
+endforeach()
+
add_entrypoint_object(
uhksqrtus
HDRS
diff --git a/libc/src/stdfix/divik.cpp b/libc/src/stdfix/divik.cpp
new file mode 100644
index 0000000000000..549c091bca617
--- /dev/null
+++ b/libc/src/stdfix/divik.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of divik 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 "divik.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, divik, (int n, accum d)) {
+ return fixed_point::divifx<int, accum>(n, d);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/divik.h b/libc/src/stdfix/divik.h
new file mode 100644
index 0000000000000..3ab530a018026
--- /dev/null
+++ b/libc/src/stdfix/divik.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for divik ------------------------*- 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_DIVIK_H
+#define LLVM_LIBC_SRC_STDFIX_DIVIK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int divik(int n, accum d);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_DIVIK_H
diff --git a/libc/src/stdfix/divilk.cpp b/libc/src/stdfix/divilk.cpp
new file mode 100644
index 0000000000000..50a85c5f0ee29
--- /dev/null
+++ b/libc/src/stdfix/divilk.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of divilk 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 "divilk.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, divilk, (long int n, long accum d)) {
+ return fixed_point::divifx<long int, long accum>(n, d);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/divilk.h b/libc/src/stdfix/divilk.h
new file mode 100644
index 0000000000000..e1ddf9b03ae67
--- /dev/null
+++ b/libc/src/stdfix/divilk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for divilk ------------------------*- 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_DIVILK_H
+#define LLVM_LIBC_SRC_STDFIX_DIVILK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+long int divilk(long int, long accum);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_DIVILK_H
diff --git a/libc/src/stdfix/divilr.cpp b/libc/src/stdfix/divilr.cpp
new file mode 100644
index 0000000000000..174649c4fad45
--- /dev/null
+++ b/libc/src/stdfix/divilr.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of divilr 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 "divilr.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, divilr, (long int n, long fract d)) {
+ return fixed_point::divifx<long int, long fract>(n, d);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/divilr.h b/libc/src/stdfix/divilr.h
new file mode 100644
index 0000000000000..92a93ab484b33
--- /dev/null
+++ b/libc/src/stdfix/divilr.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for divilr -----------------------*- 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_DIVILR_H
+#define LLVM_LIBC_SRC_STDFIX_DIVILR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+long int divilr(long int, long fract);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_DIVILR_H
diff --git a/libc/src/stdfix/divir.cpp b/libc/src/stdfix/divir.cpp
new file mode 100644
index 0000000000000..990db419ef1b6
--- /dev/null
+++ b/libc/src/stdfix/divir.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of divir 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 "divir.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, divir, (int n, fract d)) {
+ return fixed_point::divifx<int, fract>(n, d);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/divir.h b/libc/src/stdfix/divir.h
new file mode 100644
index 0000000000000..f54dcd9e8ca32
--- /dev/null
+++ b/libc/src/stdfix/divir.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for divir ------------------------*- 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_DIVIR_H
+#define LLVM_LIBC_SRC_STDFIX_DIVIR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int divir(int n, fract d);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_DIVIR_H
diff --git a/libc/src/stdfix/diviuk.cpp b/libc/src/stdfix/diviuk.cpp
new file mode 100644
index 0000000000000..9b649cfd3b812
--- /dev/null
+++ b/libc/src/stdfix/diviuk.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of diviUK 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 "diviuk.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, diviuk, (unsigned int n, unsigned accum d)) {
+ return fixed_point::divifx<unsigned int, unsigned accum>(n, d);
+}
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/diviuk.h b/libc/src/stdfix/diviuk.h
new file mode 100644
index 0000000000000..5b3846614bf4a
--- /dev/null
+++ b/libc/src/stdfix/diviuk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for diviuk -----------------------*- 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_DIVIUK_H
+#define LLVM_LIBC_SRC_STDFIX_DIVIUK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+unsigned int diviuk(unsigned int n, unsigned accum d);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_DIVIUK_H
diff --git a/libc/src/stdfix/diviulk.cpp b/libc/src/stdfix/diviulk.cpp
new file mode 100644
index 0000000000000..79411a4b32834
--- /dev/null
+++ b/libc/src/stdfix/diviulk.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of diviULK 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 "diviulk.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, diviulk,
+ (unsigned long int n, unsigned long accum d)) {
+ return fixed_point::divifx<unsigned long int, unsigned long accum>(n, d);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/diviulk.h b/libc/src/stdfix/diviulk.h
new file mode 100644
index 0000000000000..21ebef2394ff2
--- /dev/null
+++ b/libc/src/stdfix/diviulk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for diviulk ----------------------*- C++ -*-===//
+//
+// Part of the LLVM Pro...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/206115
More information about the libc-commits
mailing list