Skip to content

Commit fdd7f3e

Browse files
committed
Implement fxbits
1 parent c485ee1 commit fdd7f3e

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

+880
-2
lines changed

libc/config/baremetal/arm/entrypoints.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
455455
libc.src.stdfix.sqrtulr
456456
libc.src.stdfix.uhksqrtus
457457
libc.src.stdfix.uksqrtui
458+
libc.src.stdfix.hrbits
459+
libc.src.stdfix.uhrbits
460+
libc.src.stdfix.rbits
461+
libc.src.stdfix.urbits
462+
libc.src.stdfix.lrbits
463+
libc.src.stdfix.ulrbits
464+
libc.src.stdfix.hkbits
465+
libc.src.stdfix.uhkbits
466+
libc.src.stdfix.kbits
467+
libc.src.stdfix.ukbits
468+
libc.src.stdfix.lkbits
469+
libc.src.stdfix.ulkbits
458470
)
459471
endif()
460472

libc/config/baremetal/riscv/entrypoints.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
450450
libc.src.stdfix.sqrtulr
451451
libc.src.stdfix.uhksqrtus
452452
libc.src.stdfix.uksqrtui
453+
libc.src.stdfix.hrbits
454+
libc.src.stdfix.uhrbits
455+
libc.src.stdfix.rbits
456+
libc.src.stdfix.urbits
457+
libc.src.stdfix.lrbits
458+
libc.src.stdfix.ulrbits
459+
libc.src.stdfix.hkbits
460+
libc.src.stdfix.uhkbits
461+
libc.src.stdfix.kbits
462+
libc.src.stdfix.ukbits
463+
libc.src.stdfix.lkbits
464+
libc.src.stdfix.ulkbits
453465
)
454466
endif()
455467

libc/config/linux/riscv/entrypoints.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
704704
libc.src.stdfix.sqrtulr
705705
libc.src.stdfix.uhksqrtus
706706
libc.src.stdfix.uksqrtui
707+
libc.src.stdfix.hrbits
708+
libc.src.stdfix.uhrbits
709+
libc.src.stdfix.rbits
710+
libc.src.stdfix.urbits
711+
libc.src.stdfix.lrbits
712+
libc.src.stdfix.ulrbits
713+
libc.src.stdfix.hkbits
714+
libc.src.stdfix.uhkbits
715+
libc.src.stdfix.kbits
716+
libc.src.stdfix.ukbits
717+
libc.src.stdfix.lkbits
718+
libc.src.stdfix.ulkbits
707719
)
708720
endif()
709721

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
808808
libc.src.stdfix.sqrtulr
809809
libc.src.stdfix.uhksqrtus
810810
libc.src.stdfix.uksqrtui
811+
libc.src.stdfix.hrbits
812+
libc.src.stdfix.uhrbits
813+
libc.src.stdfix.rbits
814+
libc.src.stdfix.urbits
815+
libc.src.stdfix.lrbits
816+
libc.src.stdfix.ulrbits
817+
libc.src.stdfix.hkbits
818+
libc.src.stdfix.uhkbits
819+
libc.src.stdfix.kbits
820+
libc.src.stdfix.ukbits
821+
libc.src.stdfix.lkbits
822+
libc.src.stdfix.ulkbits
811823
)
812824
endif()
813825

libc/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ add_header_macro(
178178
stdfix.h
179179
DEPENDS
180180
.llvm-libc-macros.stdfix_macros
181+
.llvm-libc-types.stdfix-types
181182
)
182183

183184
# TODO: This should be conditional on POSIX networking being included.

libc/include/llvm-libc-types/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,4 @@ DEPENDS
154154
)
155155
add_header(locale_t HDR locale_t.h)
156156
add_header(struct_lconv HDR struct_lconv.h)
157+
add_header(stdfix-types HDR stdfix-types.h)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef LLVM_LIBC_TYPES_STDFIX_TYPES_H
2+
#define LLVM_LIBC_TYPES_STDFIX_TYPES_H
3+
4+
typedef signed char int_hr_t;
5+
typedef signed short int int_r_t;
6+
typedef signed int int_lr_t;
7+
typedef signed short int_hk_t;
8+
typedef signed int int_k_t;
9+
typedef signed long int_lk_t;
10+
typedef unsigned char uint_uhr_t;
11+
typedef unsigned short int uint_ur_t;
12+
typedef unsigned int uint_ulr_t;
13+
typedef unsigned short int uint_uhk_t;
14+
typedef unsigned int uint_uk_t;
15+
typedef unsigned long uint_ulk_t;
16+
17+
#endif // LLVM_LIBC_TYPES_STDFIX_TYPES_H

libc/newhdrgen/yaml/stdfix.yaml

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
header: stdfix.h
22
macros: []
3-
types: []
3+
types:
4+
- type_name: stdfix-types
45
enums: []
56
objects: []
67
functions:
@@ -62,6 +63,90 @@ functions:
6263
arguments:
6364
- type: accum
6465
guard: LIBC_COMPILER_HAS_FIXED_POINT
66+
- name: hrbits
67+
standards:
68+
- stdc_ext
69+
return_type: short fract
70+
arguments:
71+
- type: int_hr_t
72+
guard: LIBC_COMPILER_HAS_FIXED_POINT
73+
- name: uhrbits
74+
standards:
75+
- stdc_ext
76+
return_type: unsigned short fract
77+
arguments:
78+
- type: uint_uhr_t
79+
guard: LIBC_COMPILER_HAS_FIXED_POINT
80+
- name: rbits
81+
standards:
82+
- stdc_ext
83+
return_type: fract
84+
arguments:
85+
- type: int_r_t
86+
guard: LIBC_COMPILER_HAS_FIXED_POINT
87+
- name: urbits
88+
standards:
89+
- stdc_ext
90+
return_type: unsigned fract
91+
arguments:
92+
- type: uint_ur_t
93+
guard: LIBC_COMPILER_HAS_FIXED_POINT
94+
- name: lrbits
95+
standards:
96+
- stdc_ext
97+
return_type: long fract
98+
arguments:
99+
- type: int_lr_t
100+
guard: LIBC_COMPILER_HAS_FIXED_POINT
101+
- name: ulrbits
102+
standards:
103+
- stdc_ext
104+
return_type: unsigned long fract
105+
arguments:
106+
- type: uint_ulr_t
107+
guard: LIBC_COMPILER_HAS_FIXED_POINT
108+
- name: hkbits
109+
standards:
110+
- stdc_ext
111+
return_type: short accum
112+
arguments:
113+
- type: int_hk_t
114+
guard: LIBC_COMPILER_HAS_FIXED_POINT
115+
- name: uhkbits
116+
standards:
117+
- stdc_ext
118+
return_type: unsigned short accum
119+
arguments:
120+
- type: uint_uhk_t
121+
guard: LIBC_COMPILER_HAS_FIXED_POINT
122+
- name: kbits
123+
standards:
124+
- stdc_ext
125+
return_type: accum
126+
arguments:
127+
- type: int_k_t
128+
guard: LIBC_COMPILER_HAS_FIXED_POINT
129+
- name: ukbits
130+
standards:
131+
- stdc_ext
132+
return_type: unsigned accum
133+
arguments:
134+
- type: uint_uk_t
135+
guard: LIBC_COMPILER_HAS_FIXED_POINT
136+
- name: lkbits
137+
standards:
138+
- stdc_ext
139+
return_type: long accum
140+
arguments:
141+
- type: uint_ulr_t
142+
guard: LIBC_COMPILER_HAS_FIXED_POINT
143+
- name: ulkbits
144+
standards:
145+
- stdc_ext
146+
return_type: unsigned long accum
147+
arguments:
148+
- type: uint_ulk_t
149+
guard: LIBC_COMPILER_HAS_FIXED_POINT
65150
- name: roundhk
66151
standards:
67152
- stdc_ext

libc/src/__support/fixed_point/fx_bits.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "include/llvm-libc-macros/stdfix-macros.h"
1313
#include "src/__support/CPP/bit.h"
1414
#include "src/__support/CPP/type_traits.h"
15-
#include "src/__support/macros/attributes.h" // LIBC_INLINE
15+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1616
#include "src/__support/macros/config.h"
1717
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
1818
#include "src/__support/math_extras.h"
@@ -163,6 +163,10 @@ template <typename T> LIBC_INLINE constexpr T round(T x, int n) {
163163
return bit_and((x + round_bit), rounding_mask);
164164
}
165165

166+
template <typename T, typename XType> LIBC_INLINE constexpr T fx_bits(XType x) {
167+
return cpp::bit_cast<T, XType>(x);
168+
}
169+
166170
} // namespace fixed_point
167171
} // namespace LIBC_NAMESPACE_DECL
168172

libc/src/stdfix/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,22 @@ foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
3737
round${suffix}.h
3838
SRCS
3939
round${suffix}.cpp
40+
DEPENDS
41+
libc.src.__support.fixed_point.fx_bits
42+
)
43+
endforeach()
44+
45+
foreach(prefix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
46+
add_entrypoint_object(
47+
${prefix}bits
48+
HDRS
49+
${prefix}bits.h
50+
SRCS
51+
${prefix}bits.cpp
4052
COMPILE_OPTIONS
4153
-O3
4254
DEPENDS
55+
libc.src.__support.CPP.bit
4356
libc.src.__support.fixed_point.fx_bits
4457
)
4558
endforeach()

libc/src/stdfix/hkbits.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of hkbits 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 "hkbits.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(short accum, hkbits, (int_hk_t x)) {
16+
return fixed_point::fx_bits<short accum, int_hk_t>(x);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE_DECL

libc/src/stdfix/hkbits.h

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

libc/src/stdfix/hrbits.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of hrbits 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 "hrbits.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(short fract, hrbits, (int_hr_t x)) {
16+
return fixed_point::fx_bits<short fract, int_hr_t>(x);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE_DECL

libc/src/stdfix/hrbits.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation header for hrbits ------------------------*- 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_HRBITS_H
10+
#define LLVM_LIBC_SRC_STDFIX_HRBITS_H
11+
12+
#include "include/llvm-libc-macros/stdfix-macros.h"
13+
#include "include/llvm-libc-types/stdfix-types.h"
14+
#include "src/__support/macros/config.h"
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
short fract hrbits(int_hr_t x);
19+
20+
} // namespace LIBC_NAMESPACE_DECL
21+
22+
#endif // LLVM_LIBC_SRC_STDFIX_HRBITS_H

libc/src/stdfix/kbits.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of kbits 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 "kbits.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(accum, kbits, (int_k_t x)) {
16+
return fixed_point::fx_bits<accum, int_k_t>(x);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE_DECL

libc/src/stdfix/kbits.h

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

libc/src/stdfix/lkbits.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of lkbits 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 "lkbits.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(long accum, lkbits, (int_lk_t x)) {
16+
return fixed_point::fx_bits<long accum, int_lk_t>(x);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)