Skip to content

Commit 4d41df6

Browse files
committed
[builtins] Support architectures with 16-bit int
This is the first patch in a series to add support for the AVR target. This patch includes changes to make compiler-rt more target independent by not relying on the width of an int or long. Differential Revision: https://reviews.llvm.org/D78662
1 parent c1cb733 commit 4d41df6

25 files changed

+60
-51
lines changed

compiler-rt/lib/builtins/absvsi2.c

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

1919
COMPILER_RT_ABI si_int __absvsi2(si_int a) {
2020
const int N = (int)(sizeof(si_int) * CHAR_BIT);
21-
if (a == (1 << (N - 1)))
21+
if (a == ((si_int)1 << (N - 1)))
2222
compilerrt_abort();
2323
const si_int t = a >> (N - 1);
2424
return (a ^ t) - t;

compiler-rt/lib/builtins/ashldi3.c

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

1717
// Precondition: 0 <= b < bits_in_dword
1818

19-
COMPILER_RT_ABI di_int __ashldi3(di_int a, si_int b) {
19+
COMPILER_RT_ABI di_int __ashldi3(di_int a, int b) {
2020
const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT);
2121
dwords input;
2222
dwords result;

compiler-rt/lib/builtins/ashrdi3.c

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

1717
// Precondition: 0 <= b < bits_in_dword
1818

19-
COMPILER_RT_ABI di_int __ashrdi3(di_int a, si_int b) {
19+
COMPILER_RT_ABI di_int __ashrdi3(di_int a, int b) {
2020
const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT);
2121
dwords input;
2222
dwords result;

compiler-rt/lib/builtins/clzdi2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ COMPILER_RT_ABI si_int __clzdi2(di_int a) {
3030
dwords x;
3131
x.all = a;
3232
const si_int f = -(x.s.high == 0);
33-
return __builtin_clz((x.s.high & ~f) | (x.s.low & f)) +
33+
return clzsi((x.s.high & ~f) | (x.s.low & f)) +
3434
(f & ((si_int)(sizeof(si_int) * CHAR_BIT)));
3535
}

compiler-rt/lib/builtins/ctzdi2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ extern si_int __ctzsi2(si_int);
2626

2727
// Precondition: a != 0
2828

29-
COMPILER_RT_ABI si_int __ctzdi2(di_int a) {
29+
COMPILER_RT_ABI int __ctzdi2(di_int a) {
3030
dwords x;
3131
x.all = a;
3232
const si_int f = -(x.s.low == 0);
33-
return __builtin_ctz((x.s.high & f) | (x.s.low & ~f)) +
33+
return ctzsi((x.s.high & f) | (x.s.low & ~f)) +
3434
(f & ((si_int)(sizeof(si_int) * CHAR_BIT)));
3535
}

compiler-rt/lib/builtins/ffsdi2.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
// Returns: the index of the least significant 1-bit in a, or
1616
// the value zero if a is zero. The least significant bit is index one.
1717

18-
COMPILER_RT_ABI si_int __ffsdi2(di_int a) {
18+
COMPILER_RT_ABI int __ffsdi2(di_int a) {
1919
dwords x;
2020
x.all = a;
2121
if (x.s.low == 0) {
2222
if (x.s.high == 0)
2323
return 0;
24-
return __builtin_ctz(x.s.high) + (1 + sizeof(si_int) * CHAR_BIT);
24+
return ctzsi(x.s.high) + (1 + sizeof(si_int) * CHAR_BIT);
2525
}
26-
return __builtin_ctz(x.s.low) + 1;
26+
return ctzsi(x.s.low) + 1;
2727
}

compiler-rt/lib/builtins/ffssi2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
// Returns: the index of the least significant 1-bit in a, or
1616
// the value zero if a is zero. The least significant bit is index one.
1717

18-
COMPILER_RT_ABI si_int __ffssi2(si_int a) {
18+
COMPILER_RT_ABI int __ffssi2(si_int a) {
1919
if (a == 0) {
2020
return 0;
2121
}
22-
return __builtin_ctz(a) + 1;
22+
return ctzsi(a) + 1;
2323
}

compiler-rt/lib/builtins/floatdisf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ COMPILER_RT_ABI float __floatdisf(di_int a) {
2626
const di_int s = a >> (N - 1);
2727
a = (a ^ s) - s;
2828
int sd = N - __builtin_clzll(a); // number of significant digits
29-
int e = sd - 1; // exponent
29+
si_int e = sd - 1; // exponent
3030
if (sd > FLT_MANT_DIG) {
3131
// start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
3232
// finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR

compiler-rt/lib/builtins/floatsidf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include "int_lib.h"
1919

20-
COMPILER_RT_ABI fp_t __floatsidf(int a) {
20+
COMPILER_RT_ABI fp_t __floatsidf(si_int a) {
2121

2222
const int aWidth = sizeof a * CHAR_BIT;
2323

@@ -33,14 +33,14 @@ COMPILER_RT_ABI fp_t __floatsidf(int a) {
3333
}
3434

3535
// Exponent of (fp_t)a is the width of abs(a).
36-
const int exponent = (aWidth - 1) - __builtin_clz(a);
36+
const int exponent = (aWidth - 1) - clzsi(a);
3737
rep_t result;
3838

3939
// Shift a into the significand field and clear the implicit bit. Extra
4040
// cast to unsigned int is necessary to get the correct behavior for
4141
// the input INT_MIN.
4242
const int shift = significandBits - exponent;
43-
result = (rep_t)(unsigned int)a << shift ^ implicitBit;
43+
result = (rep_t)(su_int)a << shift ^ implicitBit;
4444

4545
// Insert the exponent
4646
result += (rep_t)(exponent + exponentBias) << significandBits;
@@ -50,7 +50,7 @@ COMPILER_RT_ABI fp_t __floatsidf(int a) {
5050

5151
#if defined(__ARM_EABI__)
5252
#if defined(COMPILER_RT_ARMHF_TARGET)
53-
AEABI_RTABI fp_t __aeabi_i2d(int a) { return __floatsidf(a); }
53+
AEABI_RTABI fp_t __aeabi_i2d(si_int a) { return __floatsidf(a); }
5454
#else
5555
COMPILER_RT_ALIAS(__floatsidf, __aeabi_i2d)
5656
#endif

compiler-rt/lib/builtins/floatundisf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ COMPILER_RT_ABI float __floatundisf(du_int a) {
2424
return 0.0F;
2525
const unsigned N = sizeof(du_int) * CHAR_BIT;
2626
int sd = N - __builtin_clzll(a); // number of significant digits
27-
int e = sd - 1; // 8 exponent
27+
si_int e = sd - 1; // 8 exponent
2828
if (sd > FLT_MANT_DIG) {
2929
// start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
3030
// finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR

0 commit comments

Comments
 (0)