-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[libc][stdfix] Implement fixed point bitsfx functions in llvm-libc #116599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
48441ec to
3e2b7ad
Compare
|
@llvm/pr-subscribers-libc Author: None (braw-lee) ChangesFixes #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:
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]
|
89e07ac to
9fc9f65
Compare
|
I am getting a linker error for just one test file the problematic test file is similar to other test files (which are working fine) |
|
We seemingly don't have an explicit template instantiation of llvm-project/libc/test/UnitTest/LibcTest.cpp Line 220 in b8eef18
|
|
@overmighty nice find, thank you |
Signed-off-by: Kushal Pal <[email protected]>
9fc9f65 to
a81ccb7
Compare
|
@michaelrj-google @PiJoules @nickdesaulniers @lntue |
PiJoules
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good so far! Just a few comments:
- Would you be able to also add some tests explicitly testing with
-fpadding-on-unsigned-fixed-point? I added a comment somewhere in this PR regarding padding for unsigned types with some context. You can probably copy the cmake logic in #114318 for adding this.
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
| LLVM_LIBC_FUNCTION(int_hk_t, bitshk, (short accum x)) { | ||
| return cpp::bit_cast<int_hk_t, short accum>(x); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, so I didn't notice this with the fxbits patch, but I think a simple bitcast won't suffice if the fixed point representation has padding bits since the padding could be any value. By default the only upstream representation for fx types doesn't use padding, but anyone use -fpadding-on-unsigned-fixed-point might be affected by this. I believe this could be addressed by just masking out the padding bits for the unsigned types after the bit_cast.
https://github.com/llvm/llvm-project/pull/114318/files#diff-aa94f9761108563a2750a9c9be57772371129073ff15c1b4e0a9ab6790a2c260R55 added the mask in FXBits which could be borrowed for this patch.
| func(half)); | ||
| // Occupy the bit to the left of the fixed point for Accum types | ||
| // Saturate fraction portion for Fract types | ||
| EXPECT_EQ(get_one_or_saturated_fraction(), func(one)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is me being pedantic, but could you also add some test cases for more boring, non-corner case numbers? Values like 5, 16, -10.25, etc.
Fixes #113359