Skip to content

Commit 2a4cb94

Browse files
committed
Implement fxbits
1 parent c485ee1 commit 2a4cb94

Some content is hidden

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

46 files changed

+863
-1
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/llvm-libc-macros/stdfix-macros.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,19 @@
323323
#define ULACCUM_EPSILON 0x1.0p-32ULK
324324
#endif // ULACCUM_EPSILON
325325

326+
typedef signed char int_hr_t;
327+
typedef signed short int int_r_t;
328+
typedef signed int int_lr_t;
329+
typedef signed short int_hk_t;
330+
typedef signed int int_k_t;
331+
typedef signed long int_lk_t;
332+
typedef unsigned char uint_uhr_t;
333+
typedef unsigned short int uint_ur_t;
334+
typedef unsigned int uint_ulr_t;
335+
typedef unsigned short int uint_uhk_t;
336+
typedef unsigned int uint_uk_t;
337+
typedef unsigned long uint_ulk_t;
338+
326339
#endif // LIBC_COMPILER_HAS_FIXED_POINT
327340

328341
#endif // LLVM_LIBC_MACROS_STDFIX_MACROS_H

libc/newhdrgen/yaml/stdfix.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,90 @@ functions:
6262
arguments:
6363
- type: accum
6464
guard: LIBC_COMPILER_HAS_FIXED_POINT
65+
- name: hrbits
66+
standards:
67+
- stdc_ext
68+
return_type: short fract
69+
arguments:
70+
- type: int_hr_t
71+
guard: LIBC_COMPILER_HAS_FIXED_POINT
72+
- name: uhrbits
73+
standards:
74+
- stdc_ext
75+
return_type: unsigned short fract
76+
arguments:
77+
- type: uint_uhr_t
78+
guard: LIBC_COMPILER_HAS_FIXED_POINT
79+
- name: rbits
80+
standards:
81+
- stdc_ext
82+
return_type: fract
83+
arguments:
84+
- type: int_r_t
85+
guard: LIBC_COMPILER_HAS_FIXED_POINT
86+
- name: urbits
87+
standards:
88+
- stdc_ext
89+
return_type: unsigned fract
90+
arguments:
91+
- type: uint_ur_t
92+
guard: LIBC_COMPILER_HAS_FIXED_POINT
93+
- name: lrbits
94+
standards:
95+
- stdc_ext
96+
return_type: long fract
97+
arguments:
98+
- type: int_lr_t
99+
guard: LIBC_COMPILER_HAS_FIXED_POINT
100+
- name: ulrbits
101+
standards:
102+
- stdc_ext
103+
return_type: unsigned long fract
104+
arguments:
105+
- type: uint_ulr_t
106+
guard: LIBC_COMPILER_HAS_FIXED_POINT
107+
- name: hkbits
108+
standards:
109+
- stdc_ext
110+
return_type: short accum
111+
arguments:
112+
- type: int_hk_t
113+
guard: LIBC_COMPILER_HAS_FIXED_POINT
114+
- name: uhkbits
115+
standards:
116+
- stdc_ext
117+
return_type: unsigned short accum
118+
arguments:
119+
- type: uint_uhk_t
120+
guard: LIBC_COMPILER_HAS_FIXED_POINT
121+
- name: kbits
122+
standards:
123+
- stdc_ext
124+
return_type: accum
125+
arguments:
126+
- type: int_k_t
127+
guard: LIBC_COMPILER_HAS_FIXED_POINT
128+
- name: ukbits
129+
standards:
130+
- stdc_ext
131+
return_type: unsigned accum
132+
arguments:
133+
- type: uint_uk_t
134+
guard: LIBC_COMPILER_HAS_FIXED_POINT
135+
- name: lkbits
136+
standards:
137+
- stdc_ext
138+
return_type: long accum
139+
arguments:
140+
- type: uint_ulr_t
141+
guard: LIBC_COMPILER_HAS_FIXED_POINT
142+
- name: ulkbits
143+
standards:
144+
- stdc_ext
145+
return_type: unsigned long accum
146+
arguments:
147+
- type: uint_ulk_t
148+
guard: LIBC_COMPILER_HAS_FIXED_POINT
65149
- name: roundhk
66150
standards:
67151
- 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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
4444
)
4545
endforeach()
4646

47+
foreach(prefix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
48+
add_entrypoint_object(
49+
${prefix}bits
50+
HDRS
51+
${prefix}bits.h
52+
SRCS
53+
${prefix}bits.cpp
54+
COMPILE_OPTIONS
55+
-O3
56+
DEPENDS
57+
libc.src.__support.CPP.bit
58+
libc.src.__support.fixed_point.fx_bits
59+
)
60+
endforeach()
61+
4762
add_entrypoint_object(
4863
uhksqrtus
4964
HDRS

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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
short accum hkbits(int_hk_t x);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
short fract hrbits(int_hr_t x);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
accum kbits(int_k_t x);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#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

libc/src/stdfix/lkbits.h

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

0 commit comments

Comments
 (0)