Skip to content

Commit 3e2b7ad

Browse files
committed
[libc][stdfix] Implement fixed point bitsfx functions in llvm-libc
Signed-off-by: Kushal Pal <[email protected]>
1 parent 4c4a413 commit 3e2b7ad

Some content is hidden

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

45 files changed

+864
-0
lines changed

libc/config/baremetal/arm/entrypoints.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
467467
libc.src.stdfix.ukbits
468468
libc.src.stdfix.lkbits
469469
libc.src.stdfix.ulkbits
470+
libc.src.stdfix.bitshr
471+
libc.src.stdfix.bitsuhr
472+
libc.src.stdfix.bitsr
473+
libc.src.stdfix.bitsur
474+
libc.src.stdfix.bitslr
475+
libc.src.stdfix.bitsulr
476+
libc.src.stdfix.bitshk
477+
libc.src.stdfix.bitsuhk
478+
libc.src.stdfix.bitsk
479+
libc.src.stdfix.bitsuk
480+
libc.src.stdfix.bitslk
481+
libc.src.stdfix.bitsulk
470482
)
471483
endif()
472484

libc/config/baremetal/riscv/entrypoints.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
462462
libc.src.stdfix.ukbits
463463
libc.src.stdfix.lkbits
464464
libc.src.stdfix.ulkbits
465+
libc.src.stdfix.bitshr
466+
libc.src.stdfix.bitsuhr
467+
libc.src.stdfix.bitsr
468+
libc.src.stdfix.bitsur
469+
libc.src.stdfix.bitslr
470+
libc.src.stdfix.bitsulr
471+
libc.src.stdfix.bitshk
472+
libc.src.stdfix.bitsuhk
473+
libc.src.stdfix.bitsk
474+
libc.src.stdfix.bitsuk
475+
libc.src.stdfix.bitslk
476+
libc.src.stdfix.bitsulk
465477
)
466478
endif()
467479

libc/config/linux/riscv/entrypoints.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,19 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
730730
# TODO: https://github.com/llvm/llvm-project/issues/115778
731731
libc.src.stdfix.lkbits
732732
libc.src.stdfix.ulkbits
733+
libc.src.stdfix.bitshr
734+
libc.src.stdfix.bitsuhr
735+
libc.src.stdfix.bitsr
736+
libc.src.stdfix.bitsur
737+
libc.src.stdfix.bitslr
738+
libc.src.stdfix.bitsulr
739+
libc.src.stdfix.bitshk
740+
libc.src.stdfix.bitsuhk
741+
libc.src.stdfix.bitsk
742+
libc.src.stdfix.bitsuk
743+
libc.src.stdfix.bitslk
744+
libc.src.stdfix.bitsulk
745+
733746
)
734747
endif()
735748

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
841841
libc.src.stdfix.ukbits
842842
libc.src.stdfix.lkbits
843843
libc.src.stdfix.ulkbits
844+
libc.src.stdfix.bitshr
845+
libc.src.stdfix.bitsuhr
846+
libc.src.stdfix.bitsr
847+
libc.src.stdfix.bitsur
848+
libc.src.stdfix.bitslr
849+
libc.src.stdfix.bitsulr
850+
libc.src.stdfix.bitshk
851+
libc.src.stdfix.bitsuhk
852+
libc.src.stdfix.bitsk
853+
libc.src.stdfix.bitsuk
854+
libc.src.stdfix.bitslk
855+
libc.src.stdfix.bitsulk
844856
)
845857
endif()
846858

libc/newhdrgen/yaml/stdfix.yaml

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

libc/spec/stdc_ext.td

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ def StdcExt : StandardSpec<"stdc_ext"> {
7373
GuardedFunctionSpec<"ulrbits", RetValSpec<UnsignedLongFractType>, [ArgSpec<UIntUlrT>], "LIBC_COMPILER_HAS_FIXED_POINT">,
7474
GuardedFunctionSpec<"uhkbits", RetValSpec<UnsignedShortAccumType>, [ArgSpec<UIntUhkT>], "LIBC_COMPILER_HAS_FIXED_POINT">,
7575
GuardedFunctionSpec<"ulkbits", RetValSpec<UnsignedLongAccumType>, [ArgSpec<UIntUlkT>], "LIBC_COMPILER_HAS_FIXED_POINT">,
76+
77+
GuardedFunctionSpec<"bitshr", RetValSpec<IntHrT>, [ArgSpec<ShortFractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
78+
GuardedFunctionSpec<"bitsr", RetValSpec<IntRT>, [ArgSpec<FractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
79+
GuardedFunctionSpec<"bitslr", RetValSpec<IntLrT>, [ArgSpec<LongFractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
80+
GuardedFunctionSpec<"bitshk", RetValSpec<IntHkT>, [ArgSpec<ShortAccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
81+
GuardedFunctionSpec<"bitsk", RetValSpec<IntKT>, [ArgSpec<AccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
82+
GuardedFunctionSpec<"bitslk", RetValSpec<IntLkT>, [ArgSpec<LongAccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
83+
GuardedFunctionSpec<"bitsuhr", RetValSpec<UIntUhrT>, [ArgSpec<UnsignedShortFractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
84+
GuardedFunctionSpec<"bitsur", RetValSpec<UIntUrI>, [ArgSpec<UnsignedFractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
85+
GuardedFunctionSpec<"bitsuk", RetValSpec<UIntUkT>, [ArgSpec<UnsignedAccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
86+
GuardedFunctionSpec<"bitsulr", RetValSpec<UIntUlrT>, [ArgSpec<UnsignedLongFractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
87+
GuardedFunctionSpec<"bitsuhk", RetValSpec<UIntUhkT>, [ArgSpec<UnsignedShortAccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
88+
GuardedFunctionSpec<"bitsulk", RetValSpec<UIntUlkT>, [ArgSpec<UnsignedLongAccumType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
7689
]
7790
>;
7891

libc/src/stdfix/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
5353
libc.src.__support.CPP.bit
5454
libc.src.__support.fixed_point.fx_bits
5555
)
56+
57+
add_entrypoint_object(
58+
bits${suffix}
59+
HDRS
60+
bits${suffix}.h
61+
SRCS
62+
bits${suffix}.cpp
63+
DEPENDS
64+
libc.src.__support.CPP.bit
65+
libc.src.__support.fixed_point.fx_bits
66+
)
67+
5668
endforeach()
5769

5870
add_entrypoint_object(

libc/src/stdfix/bitshk.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 "include/llvm-libc-types/stdfix-types.h"
10+
#include "src/__support/common.h"
11+
#include "src/__support/fixed_point/fx_bits.h"
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
LLVM_LIBC_FUNCTION(int_hk_t, bitshk, (short accum x)) {
16+
return cpp::bit_cast<int_hk_t, short accum>(x);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE_DECL

libc/src/stdfix/bitshk.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for bitshk ------------------------*- 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-types/stdfix-types.h"
13+
#include "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
int_hk_t bitshk(short accum x);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_STDFIX_BITSHK_H

libc/src/stdfix/bitshr.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 "src/__support/common.h"
11+
#include "src/__support/fixed_point/fx_bits.h"
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
LLVM_LIBC_FUNCTION(int_hr_t, bitshr, (short fract x)) {
16+
return cpp::bit_cast<int_hr_t, short fract>(x);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)