[libc-commits] [libc] [libc][stdfix] Implement fixed point bitsfx functions in llvm-libc (PR #116599)
via libc-commits
libc-commits at lists.llvm.org
Wed Nov 20 05:42:55 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: None (braw-lee)
<details>
<summary>Changes</summary>
Fixes #<!-- -->113359
---
Patch is 41.19 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/116599.diff
45 Files Affected:
- (modified) libc/config/baremetal/arm/entrypoints.txt (+12)
- (modified) libc/config/baremetal/riscv/entrypoints.txt (+12)
- (modified) libc/config/linux/riscv/entrypoints.txt (+13)
- (modified) libc/config/linux/x86_64/entrypoints.txt (+12)
- (modified) libc/newhdrgen/yaml/stdfix.yaml (+84)
- (modified) libc/spec/stdc_ext.td (+13)
- (modified) libc/src/stdfix/CMakeLists.txt (+12)
- (added) libc/src/stdfix/bitshk.cpp (+19)
- (added) libc/src/stdfix/bitshk.h (+21)
- (added) libc/src/stdfix/bitshr.cpp (+19)
- (added) libc/src/stdfix/bitshr.h (+22)
- (added) libc/src/stdfix/bitsk.cpp (+19)
- (added) libc/src/stdfix/bitsk.h (+22)
- (added) libc/src/stdfix/bitslk.cpp (+19)
- (added) libc/src/stdfix/bitslk.h (+22)
- (added) libc/src/stdfix/bitslr.cpp (+19)
- (added) libc/src/stdfix/bitslr.h (+22)
- (added) libc/src/stdfix/bitsr.cpp (+19)
- (added) libc/src/stdfix/bitsr.h (+22)
- (added) libc/src/stdfix/bitsuhk.cpp (+19)
- (added) libc/src/stdfix/bitsuhk.h (+21)
- (added) libc/src/stdfix/bitsuhr.cpp (+19)
- (added) libc/src/stdfix/bitsuhr.h (+22)
- (added) libc/src/stdfix/bitsuk.cpp (+19)
- (added) libc/src/stdfix/bitsuk.h (+22)
- (added) libc/src/stdfix/bitsulk.cpp (+19)
- (added) libc/src/stdfix/bitsulk.h (+22)
- (added) libc/src/stdfix/bitsulr.cpp (+19)
- (added) libc/src/stdfix/bitsulr.h (+22)
- (added) libc/src/stdfix/bitsur.cpp (+19)
- (added) libc/src/stdfix/bitsur.h (+22)
- (added) libc/test/src/stdfix/BitsFxTest.h (+54)
- (modified) libc/test/src/stdfix/CMakeLists.txt (+16)
- (added) libc/test/src/stdfix/bitshk_test.cpp (+12)
- (added) libc/test/src/stdfix/bitshr_test.cpp (+12)
- (added) libc/test/src/stdfix/bitsk_test.cpp (+12)
- (added) libc/test/src/stdfix/bitslk_test.cpp (+12)
- (added) libc/test/src/stdfix/bitslr_test.cpp (+12)
- (added) libc/test/src/stdfix/bitsr_test.cpp (+12)
- (added) libc/test/src/stdfix/bitsuhk_test.cpp (+13)
- (added) libc/test/src/stdfix/bitsuhr_test.cpp (+13)
- (added) libc/test/src/stdfix/bitsuk_test.cpp (+12)
- (added) libc/test/src/stdfix/bitsulk_test.cpp (+12)
- (added) libc/test/src/stdfix/bitsulr_test.cpp (+12)
- (added) libc/test/src/stdfix/bitsur_test.cpp (+12)
``````````diff
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index b85ae1119345dd..cc98a53a1a38c0 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -467,6 +467,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.ukbits
libc.src.stdfix.lkbits
libc.src.stdfix.ulkbits
+ libc.src.stdfix.bitshr
+ libc.src.stdfix.bitsuhr
+ libc.src.stdfix.bitsr
+ libc.src.stdfix.bitsur
+ libc.src.stdfix.bitslr
+ libc.src.stdfix.bitsulr
+ libc.src.stdfix.bitshk
+ libc.src.stdfix.bitsuhk
+ libc.src.stdfix.bitsk
+ libc.src.stdfix.bitsuk
+ libc.src.stdfix.bitslk
+ libc.src.stdfix.bitsulk
)
endif()
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 199a030ee6371e..79e0498d7cd52a 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -462,6 +462,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.ukbits
libc.src.stdfix.lkbits
libc.src.stdfix.ulkbits
+ libc.src.stdfix.bitshr
+ libc.src.stdfix.bitsuhr
+ libc.src.stdfix.bitsr
+ libc.src.stdfix.bitsur
+ libc.src.stdfix.bitslr
+ libc.src.stdfix.bitsulr
+ libc.src.stdfix.bitshk
+ libc.src.stdfix.bitsuhk
+ libc.src.stdfix.bitsk
+ libc.src.stdfix.bitsuk
+ libc.src.stdfix.bitslk
+ libc.src.stdfix.bitsulk
)
endif()
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 5419462d4f5b3b..162ce7e31299a5 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -730,6 +730,19 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
# TODO: https://github.com/llvm/llvm-project/issues/115778
libc.src.stdfix.lkbits
libc.src.stdfix.ulkbits
+ libc.src.stdfix.bitshr
+ libc.src.stdfix.bitsuhr
+ libc.src.stdfix.bitsr
+ libc.src.stdfix.bitsur
+ libc.src.stdfix.bitslr
+ libc.src.stdfix.bitsulr
+ libc.src.stdfix.bitshk
+ libc.src.stdfix.bitsuhk
+ libc.src.stdfix.bitsk
+ libc.src.stdfix.bitsuk
+ libc.src.stdfix.bitslk
+ libc.src.stdfix.bitsulk
+
)
endif()
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 957e28bd66cc4c..c887bfd9a677b1 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -841,6 +841,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
libc.src.stdfix.ukbits
libc.src.stdfix.lkbits
libc.src.stdfix.ulkbits
+ libc.src.stdfix.bitshr
+ libc.src.stdfix.bitsuhr
+ libc.src.stdfix.bitsr
+ libc.src.stdfix.bitsur
+ libc.src.stdfix.bitslr
+ libc.src.stdfix.bitsulr
+ libc.src.stdfix.bitshk
+ libc.src.stdfix.bitsuhk
+ libc.src.stdfix.bitsk
+ libc.src.stdfix.bitsuk
+ libc.src.stdfix.bitslk
+ libc.src.stdfix.bitsulk
)
endif()
diff --git a/libc/newhdrgen/yaml/stdfix.yaml b/libc/newhdrgen/yaml/stdfix.yaml
index 9787eaba45e4ed..0da7ea6ad06c91 100644
--- a/libc/newhdrgen/yaml/stdfix.yaml
+++ b/libc/newhdrgen/yaml/stdfix.yaml
@@ -147,6 +147,90 @@ functions:
arguments:
- type: uint_ulk_t
guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: bitshr
+ standards:
+ - stdc_ext
+ return_type: int_hr_t
+ arguments:
+ - type: short fract
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: bitsuhr
+ standards:
+ - stdc_ext
+ return_type: uint_uhr_t
+ arguments:
+ - type: unsigned short fract
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: bitsr
+ standards:
+ - stdc_ext
+ return_type: int_r_t
+ arguments:
+ - type: fract
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: bitsur
+ standards:
+ - stdc_ext
+ return_type: uint_ur_t
+ arguments:
+ - type: unsigned fract
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: bitslr
+ standards:
+ - stdc_ext
+ return_type: int_lr_t
+ arguments:
+ - type: long fract
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: bitsulr
+ standards:
+ - stdc_ext
+ return_type: uint_ulr_t
+ arguments:
+ - type: unsigned long fract
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: bitshk
+ standards:
+ - stdc_ext
+ return_type: int_hk_t
+ arguments:
+ - type: short accum
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: bitsuhk
+ standards:
+ - stdc_ext
+ return_type: uint_uhk_t
+ arguments:
+ - type: unsigned short accum
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: bitsk
+ standards:
+ - stdc_ext
+ return_type: int_k_t
+ arguments:
+ - type: accum
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: bitsuk
+ standards:
+ - stdc_ext
+ return_type: uint_uk_t
+ arguments:
+ - type: unsigned accum
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: bitslk
+ standards:
+ - stdc_ext
+ return_type: uint_ulr_t
+ arguments:
+ - type: long accum
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
+ - name: bitsulk
+ standards:
+ - stdc_ext
+ return_type: uint_ulk_t
+ arguments:
+ - type: unsigned long accum
+ guard: LIBC_COMPILER_HAS_FIXED_POINT
- name: roundhk
standards:
- stdc_ext
diff --git a/libc/spec/stdc_ext.td b/libc/spec/stdc_ext.td
index dee3b8bdf6feeb..144d1f7dfd75e7 100644
--- a/libc/spec/stdc_ext.td
+++ b/libc/spec/stdc_ext.td
@@ -73,6 +73,19 @@ def StdcExt : StandardSpec<"stdc_ext"> {
GuardedFunctionSpec<"ulrbits", RetValSpec<UnsignedLongFractType>, [ArgSpec<UIntUlrT>], "LIBC_COMPILER_HAS_FIXED_POINT">,
GuardedFunctionSpec<"uhkbits", RetValSpec<UnsignedShortAccumType>, [ArgSpec<UIntUhkT>], "LIBC_COMPILER_HAS_FIXED_POINT">,
GuardedFunctionSpec<"ulkbits", RetValSpec<UnsignedLongAccumType>, [ArgSpec<UIntUlkT>], "LIBC_COMPILER_HAS_FIXED_POINT">,
+
+ GuardedFunctionSpec<"bitshr", RetValSpec<IntHrT>, [ArgSpec<ShortFractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
+ GuardedFunctionSpec<"bitsr", RetValSpec<IntRT>, [ArgSpec<FractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
+ GuardedFunctionSpec<"bitslr", RetValSpec<IntLrT>, [ArgSpec<LongFractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
+ GuardedFunctionSpec<"bitshk", RetValSpec<IntHkT>, [ArgSpec<ShortAccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
+ GuardedFunctionSpec<"bitsk", RetValSpec<IntKT>, [ArgSpec<AccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
+ GuardedFunctionSpec<"bitslk", RetValSpec<IntLkT>, [ArgSpec<LongAccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
+ GuardedFunctionSpec<"bitsuhr", RetValSpec<UIntUhrT>, [ArgSpec<UnsignedShortFractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
+ GuardedFunctionSpec<"bitsur", RetValSpec<UIntUrI>, [ArgSpec<UnsignedFractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
+ GuardedFunctionSpec<"bitsuk", RetValSpec<UIntUkT>, [ArgSpec<UnsignedAccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
+ GuardedFunctionSpec<"bitsulr", RetValSpec<UIntUlrT>, [ArgSpec<UnsignedLongFractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
+ GuardedFunctionSpec<"bitsuhk", RetValSpec<UIntUhkT>, [ArgSpec<UnsignedShortAccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
+ GuardedFunctionSpec<"bitsulk", RetValSpec<UIntUlkT>, [ArgSpec<UnsignedLongAccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
]
>;
diff --git a/libc/src/stdfix/CMakeLists.txt b/libc/src/stdfix/CMakeLists.txt
index 238b86728188ad..2e6ecdc4937a3e 100644
--- a/libc/src/stdfix/CMakeLists.txt
+++ b/libc/src/stdfix/CMakeLists.txt
@@ -53,6 +53,18 @@ foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
libc.src.__support.CPP.bit
libc.src.__support.fixed_point.fx_bits
)
+
+ add_entrypoint_object(
+ bits${suffix}
+ HDRS
+ bits${suffix}.h
+ SRCS
+ bits${suffix}.cpp
+ DEPENDS
+ libc.src.__support.CPP.bit
+ libc.src.__support.fixed_point.fx_bits
+ )
+
endforeach()
add_entrypoint_object(
diff --git a/libc/src/stdfix/bitshk.cpp b/libc/src/stdfix/bitshk.cpp
new file mode 100644
index 00000000000000..d152f964a476e0
--- /dev/null
+++ b/libc/src/stdfix/bitshk.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of bitshk 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 "include/llvm-libc-types/stdfix-types.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_hk_t, bitshk, (short accum x)) {
+ return cpp::bit_cast<int_hk_t, short accum>(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/bitshk.h b/libc/src/stdfix/bitshk.h
new file mode 100644
index 00000000000000..3fa9261bb5a695
--- /dev/null
+++ b/libc/src/stdfix/bitshk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for bitshk ------------------------*- 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_BITSHK_H
+#define LLVM_LIBC_SRC_STDFIX_BITSHK_H
+
+#include "include/llvm-libc-types/stdfix-types.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int_hk_t bitshk(short accum x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_BITSHK_H
diff --git a/libc/src/stdfix/bitshr.cpp b/libc/src/stdfix/bitshr.cpp
new file mode 100644
index 00000000000000..36c9a1a2940c49
--- /dev/null
+++ b/libc/src/stdfix/bitshr.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of bitshr 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 "bitshr.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_hr_t, bitshr, (short fract x)) {
+ return cpp::bit_cast<int_hr_t, short fract>(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/bitshr.h b/libc/src/stdfix/bitshr.h
new file mode 100644
index 00000000000000..911e0d9524dda4
--- /dev/null
+++ b/libc/src/stdfix/bitshr.h
@@ -0,0 +1,22 @@
+//===-- Implementation header for bitshr ------------------------*- 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_BITSHR_H
+#define LLVM_LIBC_SRC_STDFIX_BITSHR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "include/llvm-libc-types/stdfix-types.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int_hr_t bitshr(short fract x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_BITSHR_H
diff --git a/libc/src/stdfix/bitsk.cpp b/libc/src/stdfix/bitsk.cpp
new file mode 100644
index 00000000000000..dedfa8e66bb53d
--- /dev/null
+++ b/libc/src/stdfix/bitsk.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of bitsk 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 "bitsk.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_k_t, bitsk, (accum x)) {
+ return cpp::bit_cast<int_k_t, accum>(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/bitsk.h b/libc/src/stdfix/bitsk.h
new file mode 100644
index 00000000000000..cd89a2cdc303f1
--- /dev/null
+++ b/libc/src/stdfix/bitsk.h
@@ -0,0 +1,22 @@
+//===-- Implementation header for bitsk -------------------------*- 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_BITSK_H
+#define LLVM_LIBC_SRC_STDFIX_BITSK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "include/llvm-libc-types/stdfix-types.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int_k_t bitsk(accum x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_BITSK_H
diff --git a/libc/src/stdfix/bitslk.cpp b/libc/src/stdfix/bitslk.cpp
new file mode 100644
index 00000000000000..db235f417db060
--- /dev/null
+++ b/libc/src/stdfix/bitslk.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of bitslk 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 "bitslk.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_lk_t, bitslk, (long accum x)) {
+ return cpp::bit_cast<int_lk_t, long accum>(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/bitslk.h b/libc/src/stdfix/bitslk.h
new file mode 100644
index 00000000000000..3ddfdbc0d77d16
--- /dev/null
+++ b/libc/src/stdfix/bitslk.h
@@ -0,0 +1,22 @@
+//===-- Implementation header for bitslk ------------------------*- 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_BITSLK_H
+#define LLVM_LIBC_SRC_STDFIX_BITSLK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "include/llvm-libc-types/stdfix-types.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int_lk_t bitslk(long accum x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_BITSLK_H
diff --git a/libc/src/stdfix/bitslr.cpp b/libc/src/stdfix/bitslr.cpp
new file mode 100644
index 00000000000000..6af9e36d823048
--- /dev/null
+++ b/libc/src/stdfix/bitslr.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of bitslr 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 "bitslr.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_lr_t, bitslr, (long fract x)) {
+ return cpp::bit_cast<int_lr_t, long fract>(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/bitslr.h b/libc/src/stdfix/bitslr.h
new file mode 100644
index 00000000000000..ec80cc87b4d8bc
--- /dev/null
+++ b/libc/src/stdfix/bitslr.h
@@ -0,0 +1,22 @@
+//===-- Implementation header for bitslr ------------------------*- 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_BITSLR_H
+#define LLVM_LIBC_SRC_STDFIX_BITSLR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "include/llvm-libc-types/stdfix-types.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int_lr_t bitslr(long fract x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_BITSLR_H
diff --git a/libc/src/stdfix/bitsr.cpp b/libc/src/stdfix/bitsr.cpp
new file mode 100644
index 00000000000000..22a4d9653cefd3
--- /dev/null
+++ b/libc/src/stdfix/bitsr.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of bitsr 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 "bitsr.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_r_t, bitsr, (fract x)) {
+ return cpp::bit_cast<int_r_t, fract>(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/bitsr.h b/libc/src/stdfix/bitsr.h
new file mode 100644
index 00000000000000..5b6587b17ea3df
--- /dev/null
+++ b/libc/src/stdfix/bitsr.h
@@ -0,0 +1,22 @@
+//===-- Implementation header for bitsr -------------------------*- 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_BITSR_H
+#define LLVM_LIBC_SRC_STDFIX_BITSR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "include/llvm-libc-types/stdfix-types.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int_r_t bitsr(fract x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_BITSR_H
diff --git a/libc/src/stdfix/bitsuhk.cpp b/libc/src/stdfix/bitsuhk.cpp
new file mode 100644
index 00000000000000..f6e3da16d1608c
--- /dev/null
+++ b/libc/src/stdfix/bitsuhk.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of bitsuhk 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 "include/llvm-libc-types/stdfix-types.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(uint_uhk_t, bitsuhk, (short accum x)) {
+ return cpp::bit_cast<uint_uhk_t, short accum>(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/bitsuhk.h b/libc/src/stdfix/bitsuhk.h
new file mode 100644
index 00000000000000..47a7918c1736bb
--- /dev/null
+++ b/libc/src/stdfix/bitsuhk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for bitsuhk -----------------------*- 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
+//
+//===-----------------------...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/116599
More information about the libc-commits
mailing list