Skip to content

Commit 780fd3a

Browse files
committed
fix: buildbot failures
Signed-off-by: krishna2803 <[email protected]>
1 parent 659170d commit 780fd3a

File tree

5 files changed

+51
-31
lines changed

5 files changed

+51
-31
lines changed

libc/src/__support/fixed_point/fx_bits.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,23 +177,20 @@ template <typename T> LIBC_INLINE constexpr T round(T x, int n) {
177177
}
178178

179179
// count leading sign bits
180+
// TODO: support fixed_point_padding
180181
template <typename T>
181182
LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_fixed_point_v<T>, int>
182183
countls(T f) {
183184
using FXRep = FXRep<T>;
184185
using BitType = typename FXRep::StorageType;
185186
using FXBits = FXBits<T>;
186187

187-
constexpr int CONTAIN_LEN = cpp::numeric_limits<BitType>::digits;
188-
constexpr int PADDING_LEN = CONTAIN_LEN - FXRep::TOTAL_LEN;
188+
if constexpr (FXRep::SIGN_LEN > 0)
189+
if (f < 0)
190+
f = bit_not(f);
189191

190-
if constexpr (FXRep::SIGN_LEN != 0) {
191-
if (x < 0)
192-
x = bit_not(x);
193-
}
194-
195-
BitType value_bits = FXBits(x)::get_bits();
196-
return cpp::countl_zero(value_bits) - PADDING_LEN;
192+
BitType value_bits = FXBits(f).get_bits();
193+
return cpp::countl_zero(value_bits) - FXRep::SIGN_LEN;
197194
}
198195

199196
} // namespace fixed_point

libc/src/__support/fixed_point/fx_rep.h

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ template <> struct FXRep<short fract> {
4343
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
4444
LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
4545
LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SFRACT_FBIT;
46+
LIBC_INLINE_VAR static constexpr int VALUE_LEN =
47+
INTEGRAL_LEN + FRACTION_LEN;
4648
LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
47-
SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
49+
SIGN_LEN + VALUE_LEN;
4850

4951
LIBC_INLINE static constexpr Type MIN() { return SFRACT_MIN; }
5052
LIBC_INLINE static constexpr Type MAX() { return SFRACT_MAX; }
@@ -63,8 +65,10 @@ template <> struct FXRep<unsigned short fract> {
6365
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
6466
LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
6567
LIBC_INLINE_VAR static constexpr int FRACTION_LEN = USFRACT_FBIT;
68+
LIBC_INLINE_VAR static constexpr int VALUE_LEN =
69+
INTEGRAL_LEN + FRACTION_LEN;
6670
LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
67-
SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
71+
SIGN_LEN + VALUE_LEN;
6872

6973
LIBC_INLINE static constexpr Type MIN() { return USFRACT_MIN; }
7074
LIBC_INLINE static constexpr Type MAX() { return USFRACT_MAX; }
@@ -83,8 +87,10 @@ template <> struct FXRep<fract> {
8387
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
8488
LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
8589
LIBC_INLINE_VAR static constexpr int FRACTION_LEN = FRACT_FBIT;
90+
LIBC_INLINE_VAR static constexpr int VALUE_LEN =
91+
INTEGRAL_LEN + FRACTION_LEN;
8692
LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
87-
SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
93+
SIGN_LEN + VALUE_LEN;
8894

8995
LIBC_INLINE static constexpr Type MIN() { return FRACT_MIN; }
9096
LIBC_INLINE static constexpr Type MAX() { return FRACT_MAX; }
@@ -103,8 +109,10 @@ template <> struct FXRep<unsigned fract> {
103109
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
104110
LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
105111
LIBC_INLINE_VAR static constexpr int FRACTION_LEN = UFRACT_FBIT;
112+
LIBC_INLINE_VAR static constexpr int VALUE_LEN =
113+
INTEGRAL_LEN + FRACTION_LEN;
106114
LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
107-
SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
115+
SIGN_LEN + VALUE_LEN;
108116

109117
LIBC_INLINE static constexpr Type MIN() { return UFRACT_MIN; }
110118
LIBC_INLINE static constexpr Type MAX() { return UFRACT_MAX; }
@@ -123,8 +131,10 @@ template <> struct FXRep<long fract> {
123131
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
124132
LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
125133
LIBC_INLINE_VAR static constexpr int FRACTION_LEN = LFRACT_FBIT;
134+
LIBC_INLINE_VAR static constexpr int VALUE_LEN =
135+
INTEGRAL_LEN + FRACTION_LEN;
126136
LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
127-
SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
137+
SIGN_LEN + VALUE_LEN;
128138

129139
LIBC_INLINE static constexpr Type MIN() { return LFRACT_MIN; }
130140
LIBC_INLINE static constexpr Type MAX() { return LFRACT_MAX; }
@@ -143,8 +153,10 @@ template <> struct FXRep<unsigned long fract> {
143153
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
144154
LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
145155
LIBC_INLINE_VAR static constexpr int FRACTION_LEN = ULFRACT_FBIT;
156+
LIBC_INLINE_VAR static constexpr int VALUE_LEN =
157+
INTEGRAL_LEN + FRACTION_LEN;
146158
LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
147-
SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
159+
SIGN_LEN + VALUE_LEN;
148160

149161
LIBC_INLINE static constexpr Type MIN() { return ULFRACT_MIN; }
150162
LIBC_INLINE static constexpr Type MAX() { return ULFRACT_MAX; }
@@ -163,8 +175,10 @@ template <> struct FXRep<short accum> {
163175
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
164176
LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = SACCUM_IBIT;
165177
LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SACCUM_FBIT;
178+
LIBC_INLINE_VAR static constexpr int VALUE_LEN =
179+
INTEGRAL_LEN + FRACTION_LEN;
166180
LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
167-
SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
181+
SIGN_LEN + VALUE_LEN;
168182

169183
LIBC_INLINE static constexpr Type MIN() { return SACCUM_MIN; }
170184
LIBC_INLINE static constexpr Type MAX() { return SACCUM_MAX; }
@@ -183,8 +197,10 @@ template <> struct FXRep<unsigned short accum> {
183197
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
184198
LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = USACCUM_IBIT;
185199
LIBC_INLINE_VAR static constexpr int FRACTION_LEN = USACCUM_FBIT;
200+
LIBC_INLINE_VAR static constexpr int VALUE_LEN =
201+
INTEGRAL_LEN + FRACTION_LEN;
186202
LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
187-
SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
203+
SIGN_LEN + VALUE_LEN;
188204

189205
LIBC_INLINE static constexpr Type MIN() { return USACCUM_MIN; }
190206
LIBC_INLINE static constexpr Type MAX() { return USACCUM_MAX; }
@@ -203,8 +219,10 @@ template <> struct FXRep<accum> {
203219
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
204220
LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = ACCUM_IBIT;
205221
LIBC_INLINE_VAR static constexpr int FRACTION_LEN = ACCUM_FBIT;
222+
LIBC_INLINE_VAR static constexpr int VALUE_LEN =
223+
INTEGRAL_LEN + FRACTION_LEN;
206224
LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
207-
SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
225+
SIGN_LEN + VALUE_LEN;
208226

209227
LIBC_INLINE static constexpr Type MIN() { return ACCUM_MIN; }
210228
LIBC_INLINE static constexpr Type MAX() { return ACCUM_MAX; }
@@ -223,8 +241,10 @@ template <> struct FXRep<unsigned accum> {
223241
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
224242
LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = UACCUM_IBIT;
225243
LIBC_INLINE_VAR static constexpr int FRACTION_LEN = UACCUM_FBIT;
244+
LIBC_INLINE_VAR static constexpr int VALUE_LEN =
245+
INTEGRAL_LEN + FRACTION_LEN;
226246
LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
227-
SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
247+
SIGN_LEN + VALUE_LEN;
228248

229249
LIBC_INLINE static constexpr Type MIN() { return UACCUM_MIN; }
230250
LIBC_INLINE static constexpr Type MAX() { return UACCUM_MAX; }
@@ -243,8 +263,10 @@ template <> struct FXRep<long accum> {
243263
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
244264
LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = LACCUM_IBIT;
245265
LIBC_INLINE_VAR static constexpr int FRACTION_LEN = LACCUM_FBIT;
266+
LIBC_INLINE_VAR static constexpr int VALUE_LEN =
267+
INTEGRAL_LEN + FRACTION_LEN;
246268
LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
247-
SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
269+
SIGN_LEN + VALUE_LEN;
248270

249271
LIBC_INLINE static constexpr Type MIN() { return LACCUM_MIN; }
250272
LIBC_INLINE static constexpr Type MAX() { return LACCUM_MAX; }
@@ -263,8 +285,10 @@ template <> struct FXRep<unsigned long accum> {
263285
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
264286
LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = ULACCUM_IBIT;
265287
LIBC_INLINE_VAR static constexpr int FRACTION_LEN = ULACCUM_FBIT;
288+
LIBC_INLINE_VAR static constexpr int VALUE_LEN =
289+
INTEGRAL_LEN + FRACTION_LEN;
266290
LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
267-
SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
291+
SIGN_LEN + VALUE_LEN;
268292

269293
LIBC_INLINE static constexpr Type MIN() { return ULACCUM_MIN; }
270294
LIBC_INLINE static constexpr Type MAX() { return ULACCUM_MAX; }

libc/src/stdfix/countlsuhr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

17-
int countlsuhr(unsigned long fract f);
17+
int countlsuhr(unsigned short fract f);
1818

1919
} // namespace LIBC_NAMESPACE_DECL
2020

libc/src/stdfix/countlsuk.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
//===-- Implementation for countlsuhk function ---------------------------===//
1+
//===-- Implementation for countlsuk function ----------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "countlsuhk.h"
9+
#include "countlsuk.h"
1010
#include "src/__support/common.h"
1111
#include "src/__support/fixed_point/fx_bits.h"
1212
#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
1313

1414
namespace LIBC_NAMESPACE_DECL {
1515

16-
LLVM_LIBC_FUNCTION(int, countlsuhk, (unsigned accum f)) {
16+
LLVM_LIBC_FUNCTION(int, countlsuk, (unsigned accum f)) {
1717
return fixed_point::countls(f);
1818
}
1919

libc/test/src/stdfix/CountlsTest.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ template <typename T> class CountlsTest : public LIBC_NAMESPACE::testing::Test {
2020
static constexpr T one_fourth = FXRep::ONE_FOURTH();
2121
static constexpr T eps = FXRep::EPS();
2222

23-
static constexpr auto value_len = FXRep::INTEGRAL_LEN + FXRep::FRACTION_LEN;
24-
2523
public:
2624
typedef int (*CountlsFunc)(T);
2725

@@ -30,13 +28,13 @@ template <typename T> class CountlsTest : public LIBC_NAMESPACE::testing::Test {
3028

3129
EXPECT_EQ(FXRep::INTEGRAL_LEN, func(one_half));
3230
EXPECT_EQ(FXRep::INTEGRAL_LEN + 1, func(one_fourth));
33-
EXPECT_EQ(value_len, func(zero));
34-
EXPECT_EQ(value_len - 1, func(eps));
31+
EXPECT_EQ(FXRep::VALUE_LEN, func(zero));
32+
EXPECT_EQ(FXRep::VALUE_LEN - 1, func(eps));
3533
EXPECT_EQ(0, func(max));
3634
// If signed, left shifting the minimum value will overflow, so countls = 0.
3735
// If unsigned, the minimum value is zero, so countls is the number of value
3836
// bits according to ISO/IEC TR 18037.
39-
EXPECT_EQ(is_signed ? 0 : value_len, func(min));
37+
EXPECT_EQ(is_signed ? 0 : FXRep::VALUE_LEN, func(min));
4038

4139
if (10 <= static_cast<int>(max)) {
4240
EXPECT_EQ(FXRep::INTEGRAL_LEN - 4, func(10));
@@ -47,7 +45,8 @@ template <typename T> class CountlsTest : public LIBC_NAMESPACE::testing::Test {
4745
}
4846

4947
if constexpr (is_signed) {
50-
EXPECT_EQ(value_len, func(-eps));
48+
EXPECT_EQ(FXRep::VALUE_LEN, func(-zero));
49+
EXPECT_EQ(FXRep::VALUE_LEN, func(-eps));
5150
EXPECT_EQ(FXRep::INTEGRAL_LEN + 1, func(-one_half));
5251
if (FXRep::FRACTION_LEN >= 2) {
5352
EXPECT_EQ(FXRep::INTEGRAL_LEN + 2, func(-one_fourth));

0 commit comments

Comments
 (0)