Skip to content

Commit ad83325

Browse files
krishna2803joaosaffran
authored and
joaosaffran
committed
[libc][stdfix] Implement fixed point bitsfx functions in llvm libc (llvm#128413)
Fixes llvm#113359 --------- Signed-off-by: krishna2803 <[email protected]>
1 parent c154a4b commit ad83325

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+972
-1
lines changed

libc/config/baremetal/arm/entrypoints.txt

+12
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
509509
libc.src.stdfix.ukbits
510510
libc.src.stdfix.lkbits
511511
libc.src.stdfix.ulkbits
512+
libc.src.stdfix.bitshr
513+
libc.src.stdfix.bitsr
514+
libc.src.stdfix.bitslr
515+
libc.src.stdfix.bitshk
516+
libc.src.stdfix.bitsk
517+
libc.src.stdfix.bitslk
518+
libc.src.stdfix.bitsuhr
519+
libc.src.stdfix.bitsur
520+
libc.src.stdfix.bitsulr
521+
libc.src.stdfix.bitsuhk
522+
libc.src.stdfix.bitsuk
523+
libc.src.stdfix.bitsulk
512524
libc.src.stdfix.countlshr
513525
libc.src.stdfix.countlsr
514526
libc.src.stdfix.countlslr

libc/config/baremetal/riscv/entrypoints.txt

+12
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
504504
libc.src.stdfix.ukbits
505505
libc.src.stdfix.lkbits
506506
libc.src.stdfix.ulkbits
507+
libc.src.stdfix.bitshr
508+
libc.src.stdfix.bitsr
509+
libc.src.stdfix.bitslr
510+
libc.src.stdfix.bitshk
511+
libc.src.stdfix.bitsk
512+
libc.src.stdfix.bitslk
513+
libc.src.stdfix.bitshr
514+
libc.src.stdfix.bitsur
515+
libc.src.stdfix.bitsulr
516+
libc.src.stdfix.bitsuhk
517+
libc.src.stdfix.bitsuk
518+
libc.src.stdfix.bitsulk
507519
libc.src.stdfix.countlshr
508520
libc.src.stdfix.countlsr
509521
libc.src.stdfix.countlslr

libc/config/linux/riscv/entrypoints.txt

+12
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
748748
# TODO: https://github.com/llvm/llvm-project/issues/115778
749749
libc.src.stdfix.lkbits
750750
libc.src.stdfix.ulkbits
751+
libc.src.stdfix.bitshr
752+
libc.src.stdfix.bitsr
753+
libc.src.stdfix.bitslr
754+
libc.src.stdfix.bitshk
755+
libc.src.stdfix.bitsk
756+
libc.src.stdfix.bitslk
757+
libc.src.stdfix.bitsuhr
758+
libc.src.stdfix.bitsur
759+
libc.src.stdfix.bitsulr
760+
libc.src.stdfix.bitsuhk
761+
libc.src.stdfix.bitsuk
762+
libc.src.stdfix.bitsulk
751763
libc.src.stdfix.countlshr
752764
libc.src.stdfix.countlsr
753765
libc.src.stdfix.countlslr

libc/config/linux/x86_64/entrypoints.txt

+12
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
876876
libc.src.stdfix.ukbits
877877
libc.src.stdfix.lkbits
878878
libc.src.stdfix.ulkbits
879+
libc.src.stdfix.bitshr
880+
libc.src.stdfix.bitsr
881+
libc.src.stdfix.bitslr
882+
libc.src.stdfix.bitshk
883+
libc.src.stdfix.bitsk
884+
libc.src.stdfix.bitslk
885+
libc.src.stdfix.bitsuhr
886+
libc.src.stdfix.bitsur
887+
libc.src.stdfix.bitsulr
888+
libc.src.stdfix.bitsuhk
889+
libc.src.stdfix.bitsuk
890+
libc.src.stdfix.bitsulk
879891
libc.src.stdfix.countlshr
880892
libc.src.stdfix.countlsr
881893
libc.src.stdfix.countlslr

libc/docs/headers/math/stdfix.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ The following functions are included in the ISO/IEC TR 18037:2008 standard.
6969
+===============+================+=============+===============+============+================+=============+================+=============+===============+============+================+=============+
7070
| abs | | |check| | | |check| | | |check| | | |check| | | |check| | | |check| |
7171
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
72-
| bits\* | | | | | | | | | | | | |
72+
| bits\* | |check| | |check| | |check| | |check| | |check| | |check| | |check| | |check| | |check| | |check| | |check| | |check| |
7373
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
7474
| \*bits | | | | | | | | | | | | |
7575
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+

libc/include/stdfix.yaml

+84
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,90 @@ functions:
148148
arguments:
149149
- type: uint_ulk_t
150150
guard: LIBC_COMPILER_HAS_FIXED_POINT
151+
- name: bitshr
152+
standards:
153+
- stdc_ext
154+
return_type: int_hr_t
155+
arguments:
156+
- type: short fract
157+
guard: LIBC_COMPILER_HAS_FIXED_POINT
158+
- name: bitsuhr
159+
standards:
160+
- stdc_ext
161+
return_type: uint_uhr_t
162+
arguments:
163+
- type: unsigned short fract
164+
guard: LIBC_COMPILER_HAS_FIXED_POINT
165+
- name: bitsr
166+
standards:
167+
- stdc_ext
168+
return_type: int_r_t
169+
arguments:
170+
- type: fract
171+
guard: LIBC_COMPILER_HAS_FIXED_POINT
172+
- name: bitsur
173+
standards:
174+
- stdc_ext
175+
return_type: uint_ur_t
176+
arguments:
177+
- type: unsigned fract
178+
guard: LIBC_COMPILER_HAS_FIXED_POINT
179+
- name: bitslr
180+
standards:
181+
- stdc_ext
182+
return_type: int_lr_t
183+
arguments:
184+
- type: long fract
185+
guard: LIBC_COMPILER_HAS_FIXED_POINT
186+
- name: bitsulr
187+
standards:
188+
- stdc_ext
189+
return_type: uint_ulr_t
190+
arguments:
191+
- type: unsigned long fract
192+
guard: LIBC_COMPILER_HAS_FIXED_POINT
193+
- name: bitshk
194+
standards:
195+
- stdc_ext
196+
return_type: int_hk_t
197+
arguments:
198+
- type: short accum
199+
guard: LIBC_COMPILER_HAS_FIXED_POINT
200+
- name: bitsuhk
201+
standards:
202+
- stdc_ext
203+
return_type: uint_uhk_t
204+
arguments:
205+
- type: unsigned short accum
206+
guard: LIBC_COMPILER_HAS_FIXED_POINT
207+
- name: bitsk
208+
standards:
209+
- stdc_ext
210+
return_type: int_k_t
211+
arguments:
212+
- type: accum
213+
guard: LIBC_COMPILER_HAS_FIXED_POINT
214+
- name: bitsuk
215+
standards:
216+
- stdc_ext
217+
return_type: uint_uk_t
218+
arguments:
219+
- type: unsigned accum
220+
guard: LIBC_COMPILER_HAS_FIXED_POINT
221+
- name: bitslk
222+
standards:
223+
- stdc_ext
224+
return_type: int_lk_t
225+
arguments:
226+
- type: long accum
227+
guard: LIBC_COMPILER_HAS_FIXED_POINT
228+
- name: bitsulk
229+
standards:
230+
- stdc_ext
231+
return_type: uint_ulk_t
232+
arguments:
233+
- type: unsigned long accum
234+
guard: LIBC_COMPILER_HAS_FIXED_POINT
151235
- name: roundhk
152236
standards:
153237
- stdc_ext

libc/src/__support/fixed_point/fx_bits.h

+7
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ countls(T f) {
194194
return cpp::countl_zero(value_bits) - FXRep::SIGN_LEN;
195195
}
196196

197+
// fixed-point to integer conversion
198+
template <typename T, typename XType>
199+
LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_fixed_point_v<T>, XType>
200+
bitsfx(T f) {
201+
return cpp::bit_cast<XType, T>(f);
202+
}
203+
197204
} // namespace fixed_point
198205
} // namespace LIBC_NAMESPACE_DECL
199206

libc/src/stdfix/CMakeLists.txt

+14
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
4848
libc.src.__support.fixed_point.fx_bits
4949
)
5050

51+
add_entrypoint_object(
52+
bits${suffix}
53+
HDRS
54+
bits${suffix}.h
55+
SRCS
56+
bits${suffix}.cpp
57+
COMPILE_OPTIONS
58+
${libc_opt_high_flag}
59+
DEPENDS
60+
libc.src.__support.fixed_point.fx_bits
61+
libc.include.llvm-libc-types.stdfix-types
62+
libc.include.llvm-libc-macros.stdfix_macros
63+
)
64+
5165
add_entrypoint_object(
5266
countls${suffix}
5367
HDRS

libc/src/stdfix/bitshk.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation of bitshk function --------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "bitshk.h"
10+
#include "include/llvm-libc-macros/stdfix-macros.h" // short accum
11+
#include "include/llvm-libc-types/stdfix-types.h" // int_hk_t
12+
#include "src/__support/common.h" // LLVM_LIBC_FUNCTION
13+
#include "src/__support/fixed_point/fx_bits.h" // fixed_point
14+
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
LLVM_LIBC_FUNCTION(int_hk_t, bitshk, (short accum f)) {
19+
return fixed_point::bitsfx<short accum, int_hk_t>(f);
20+
}
21+
22+
} // namespace LIBC_NAMESPACE_DECL

libc/src/stdfix/bitshk.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation header for bitshk function ---------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_STDFIX_BITSHK_H
10+
#define LLVM_LIBC_SRC_STDFIX_BITSHK_H
11+
12+
#include "include/llvm-libc-macros/stdfix-macros.h" // short accum
13+
#include "include/llvm-libc-types/stdfix-types.h" // int_hk_t
14+
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
int_hk_t bitshk(short accum f);
19+
20+
} // namespace LIBC_NAMESPACE_DECL
21+
22+
#endif // LLVM_LIBC_SRC_STDFIX_BITSHK_H

libc/src/stdfix/bitshr.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation of bitshr function --------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "bitshr.h"
10+
#include "include/llvm-libc-macros/stdfix-macros.h" // short fract
11+
#include "include/llvm-libc-types/stdfix-types.h" // int_hr_t
12+
#include "src/__support/common.h" // LLVM_LIBC_FUNCTION
13+
#include "src/__support/fixed_point/fx_bits.h" // fixed_point
14+
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
LLVM_LIBC_FUNCTION(int_hr_t, bitshr, (short fract f)) {
19+
return fixed_point::bitsfx<short fract, int_hr_t>(f);
20+
}
21+
22+
} // namespace LIBC_NAMESPACE_DECL

libc/src/stdfix/bitshr.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation header for bitshr function ---------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_STDFIX_BITSHR_H
10+
#define LLVM_LIBC_SRC_STDFIX_BITSHR_H
11+
12+
#include "include/llvm-libc-macros/stdfix-macros.h" // short fract
13+
#include "include/llvm-libc-types/stdfix-types.h" // int_hr_t
14+
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
int_hr_t bitshr(short fract f);
19+
20+
} // namespace LIBC_NAMESPACE_DECL
21+
22+
#endif // LLVM_LIBC_SRC_STDFIX_BITSHR_H

libc/src/stdfix/bitsk.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation for bitsk function --------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "bitsk.h"
10+
#include "include/llvm-libc-macros/stdfix-macros.h" // accum
11+
#include "include/llvm-libc-types/stdfix-types.h" // int_k_t
12+
#include "src/__support/common.h" // LLVM_LIBC_FUNCTION
13+
#include "src/__support/fixed_point/fx_bits.h" // fixed_point
14+
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
LLVM_LIBC_FUNCTION(int_k_t, bitsk, (accum f)) {
19+
return fixed_point::bitsfx<accum, int_k_t>(f);
20+
}
21+
22+
} // namespace LIBC_NAMESPACE_DECL

libc/src/stdfix/bitsk.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation header for bitsk function ----------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_STDFIX_BITSK_H
10+
#define LLVM_LIBC_SRC_STDFIX_BITSK_H
11+
12+
#include "include/llvm-libc-macros/stdfix-macros.h" // accum
13+
#include "include/llvm-libc-types/stdfix-types.h" // int_k_t
14+
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
int_k_t bitsk(accum f);
19+
20+
} // namespace LIBC_NAMESPACE_DECL
21+
22+
#endif // LLVM_LIBC_SRC_STDFIX_BITSK_H

libc/src/stdfix/bitslk.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation for bitslk function -------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "bitslk.h"
10+
#include "include/llvm-libc-macros/stdfix-macros.h" // long accum
11+
#include "include/llvm-libc-types/stdfix-types.h" // int_lk_t
12+
#include "src/__support/common.h" // LLVM_LIBC_FUNCTION
13+
#include "src/__support/fixed_point/fx_bits.h" // fixed_point
14+
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
LLVM_LIBC_FUNCTION(int_lk_t, bitslk, (long accum f)) {
19+
return fixed_point::bitsfx<long accum, int_lk_t>(f);
20+
}
21+
22+
} // namespace LIBC_NAMESPACE_DECL

libc/src/stdfix/bitslk.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation header for bitslk function ---------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_STDFIX_BITSLK_H
10+
#define LLVM_LIBC_SRC_STDFIX_BITSLK_H
11+
12+
#include "include/llvm-libc-macros/stdfix-macros.h" // long accum
13+
#include "include/llvm-libc-types/stdfix-types.h" // int_lk_t
14+
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
int_lk_t bitslk(long accum f);
19+
20+
} // namespace LIBC_NAMESPACE_DECL
21+
22+
#endif // LLVM_LIBC_SRC_STDFIX_BITSLK_H

0 commit comments

Comments
 (0)