Skip to content

Commit b9e2b53

Browse files
committed
Implement fxbits
1 parent c485ee1 commit b9e2b53

Some content is hidden

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

49 files changed

+911
-3
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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===-- Definition of stdfix integer types --------------------------------===//
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_TYPES_STDFIX_TYPES_H
10+
#define LLVM_LIBC_TYPES_STDFIX_TYPES_H
11+
12+
typedef signed char int_hr_t;
13+
typedef signed short int int_r_t;
14+
typedef signed int int_lr_t;
15+
typedef signed short int_hk_t;
16+
typedef signed int int_k_t;
17+
typedef signed long int_lk_t;
18+
typedef unsigned char uint_uhr_t;
19+
typedef unsigned short int uint_ur_t;
20+
typedef unsigned int uint_ulr_t;
21+
typedef unsigned short int uint_uhk_t;
22+
typedef unsigned int uint_uk_t;
23+
typedef unsigned long uint_ulk_t;
24+
25+
#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/spec/stdc_ext.td

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,26 @@ def UnsignedShortAccumType : NamedType<"unsigned short accum">;
1515
def UnsignedAccumType : NamedType<"unsigned accum">;
1616
def UnsignedLongAccumType : NamedType<"unsigned long accum">;
1717

18+
def IntHrT : NamedType <"int_hr_t">;
19+
def IntRT : NamedTypes<"int_r_t">;
20+
def IntLrT : NamedType<"int_lr_t">;
21+
def IntHkT : NamedType<"int_hk_t">;
22+
def IntKT : NamedType<"int_k_t">;
23+
def IntLkT : NamedType<"int_lk_t">;
24+
def UIntUhrT : NamedType<"uint_uhr_t">;
25+
def UIntUrT : NamedType<"uint_ur_t">;
26+
def UIntUlrT : NamedType<"uint_ulr_t">;
27+
def UIntUhkT : NamedType<"uint_uhk_t">;
28+
def UIntUkT : NamedType<"uint_uk_t">;
29+
def UIntUlkT : NamedType<"uint_ulk_t">;
30+
1831
def StdcExt : StandardSpec<"stdc_ext"> {
1932
// From ISO/IEC TR 18037:2008 standard:
2033
// https://standards.iso.org/ittf/PubliclyAvailableStandards/c051126_ISO_IEC_TR_18037_2008.zip
2134
HeaderSpec StdFix = HeaderSpec<
2235
"stdfix.h",
2336
[], // macros
24-
[], // types
37+
[IntHrT,IntRT, IntLrT, IntHkT, IntKT, IntLkT, UIntUhrT, UIntUrT, UIntUlrT, UIntUhkT, UIntUkT, UIntUlkT], // types
2538
[], // enums
2639
[ // functions
2740
GuardedFunctionSpec<"abshr", RetValSpec<ShortFractType>, [ArgSpec<ShortFractType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
@@ -47,6 +60,19 @@ def StdcExt : StandardSpec<"stdc_ext"> {
4760
GuardedFunctionSpec<"rounduhk", RetValSpec<UnsignedShortAccumType>, [ArgSpec<UnsignedShortAccumType>, ArgSpec<IntType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
4861
GuardedFunctionSpec<"rounduk", RetValSpec<UnsignedAccumType>, [ArgSpec<UnsignedAccumType>, ArgSpec<IntType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
4962
GuardedFunctionSpec<"roundulk", RetValSpec<UnsignedLongAccumType>, [ArgSpec<UnsignedLongAccumType>, ArgSpec<IntType>], "LIBC_COMPILER_HAS_FIXED_POINT">,
63+
64+
GuardedFunctionSpec<"hrbits", RetValSpec<ShortFractType>, [ArgSpec<IntHrT>], "LIBC_COMPILER_HAS_FIXED_POINT">,
65+
GuardedFunctionSpec<"rbits", RetValSpec<FractType>, [ArgSpec<IntRT>], "LIBC_COMPILER_HAS_FIXED_POINT">,
66+
GuardedFunctionSpec<"lrbits", RetValSpec<LongFractType>, [ArgSpec<IntLrT>], "LIBC_COMPILER_HAS_FIXED_POINT">,
67+
GuardedFunctionSpec<"hkbits", RetValSpec<ShortAccumType>, [ArgSpec<IntHkT>], "LIBC_COMPILER_HAS_FIXED_POINT">,
68+
GuardedFunctionSpec<"kbits", RetValSpec<AccumType>, [ArgSpec<IntKT>], "LIBC_COMPILER_HAS_FIXED_POINT">,
69+
GuardedFunctionSpec<"lkbits", RetValSpec<LongAccumType>, [ArgSpec<IntLkT>], "LIBC_COMPILER_HAS_FIXED_POINT">,
70+
GuardedFunctionSpec<"uhrbits", RetValSpec<UnsignedShortFractType>, [ArgSpec<UIntUhrT>], "LIBC_COMPILER_HAS_FIXED_POINT">,
71+
GuardedFunctionSpec<"urbits", RetValSpec<UnsignedFractType>, [ArgSpec<UIntUrT>], "LIBC_COMPILER_HAS_FIXED_POINT">,
72+
GuardedFunctionSpec<"ukbits", RetValSpec<UnsignedAccumType>, [ArgSpec<UIntUkT>], "LIBC_COMPILER_HAS_FIXED_POINT">
73+
GuardedFunctionSpec<"ulrbits", RetValSpec<UnsignedLongFractType>, [ArgSpec<UIntUlrT>], "LIBC_COMPILER_HAS_FIXED_POINT">,
74+
GuardedFunctionSpec<"uhkbits", RetValSpec<UnsignedShortAccumType>, [ArgSpec<UIntUhkT>], "LIBC_COMPILER_HAS_FIXED_POINT">
75+
GuardedFunctionSpec<"ulkbits", RetValSpec<UnsignedLongAccumType>, [ArgSpec<UIntUlkT>], "LIBC_COMPILER_HAS_FIXED_POINT">
5076
]
5177
>;
5278

libc/src/__support/fixed_point/fx_bits.h

Lines changed: 1 addition & 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"

libc/src/stdfix/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ 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+
DEPENDS
55+
libc.src.__support.CPP.bit
56+
libc.src.__support.fixed_point.fx_bits
57+
)
58+
endforeach()
59+
4760
add_entrypoint_object(
4861
uhksqrtus
4962
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 cpp::bit_cast<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 cpp::bit_cast<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 cpp::bit_cast<accum, int_k_t>(x);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)