Skip to content

Commit 0ee439b

Browse files
atrosinenkoasl
authored andcommitted
[builtins] Change si_int to int in some helper declarations
This patch changes types of some integer function arguments or return values from `si_int` to the default `int` type to make it more compatible with `libgcc`. The compiler-rt/lib/builtins/README.txt has a link to the [libgcc specification](http://gcc.gnu.org/onlinedocs/gccint/Libgcc.html#Libgcc). This specification has an explicit note on `int`, `float` and other such types being just illustrations in some cases while the actual types are expressed with machine modes. Such usage of always-32-bit-wide integer type may lead to issues on 16-bit platforms such as MSP430. Provided [libgcc2.h](https://gcc.gnu.org/git/?p=gcc.git;a=blob_plain;f=libgcc/libgcc2.h;hb=HEAD) can be used as a reference for all targets supported by the libgcc, this patch fixes some existing differences in helper declarations. This patch is expected to not change behavior at all for targets with 32-bit `int` type. Differential Revision: https://reviews.llvm.org/D81285
1 parent 19e7571 commit 0ee439b

33 files changed

+183
-178
lines changed

compiler-rt/lib/builtins/README.txt

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ Here is the specification for this library:
2020

2121
http://gcc.gnu.org/onlinedocs/gccint/Libgcc.html#Libgcc
2222

23+
Please note that the libgcc specification explicitly mentions actual types of
24+
arguments and returned values being expressed with machine modes.
25+
In some cases particular types such as "int", "unsigned", "long long", etc.
26+
may be specified just as examples there.
27+
2328
Here is a synopsis of the contents of this library:
2429

25-
typedef int si_int;
26-
typedef unsigned su_int;
30+
typedef int32_t si_int;
31+
typedef uint32_t su_int;
2732

28-
typedef long long di_int;
29-
typedef unsigned long long du_int;
33+
typedef int64_t di_int;
34+
typedef uint64_t du_int;
3035

3136
// Integral bit manipulation
3237

@@ -38,24 +43,24 @@ ti_int __ashrti3(ti_int a, si_int b); // a >> b arithmetic (sign fill)
3843
di_int __lshrdi3(di_int a, si_int b); // a >> b logical (zero fill)
3944
ti_int __lshrti3(ti_int a, si_int b); // a >> b logical (zero fill)
4045

41-
si_int __clzsi2(si_int a); // count leading zeros
42-
si_int __clzdi2(di_int a); // count leading zeros
43-
si_int __clzti2(ti_int a); // count leading zeros
44-
si_int __ctzsi2(si_int a); // count trailing zeros
45-
si_int __ctzdi2(di_int a); // count trailing zeros
46-
si_int __ctzti2(ti_int a); // count trailing zeros
46+
int __clzsi2(si_int a); // count leading zeros
47+
int __clzdi2(di_int a); // count leading zeros
48+
int __clzti2(ti_int a); // count leading zeros
49+
int __ctzsi2(si_int a); // count trailing zeros
50+
int __ctzdi2(di_int a); // count trailing zeros
51+
int __ctzti2(ti_int a); // count trailing zeros
4752

48-
si_int __ffssi2(si_int a); // find least significant 1 bit
49-
si_int __ffsdi2(di_int a); // find least significant 1 bit
50-
si_int __ffsti2(ti_int a); // find least significant 1 bit
53+
int __ffssi2(si_int a); // find least significant 1 bit
54+
int __ffsdi2(di_int a); // find least significant 1 bit
55+
int __ffsti2(ti_int a); // find least significant 1 bit
5156

52-
si_int __paritysi2(si_int a); // bit parity
53-
si_int __paritydi2(di_int a); // bit parity
54-
si_int __parityti2(ti_int a); // bit parity
57+
int __paritysi2(si_int a); // bit parity
58+
int __paritydi2(di_int a); // bit parity
59+
int __parityti2(ti_int a); // bit parity
5560

56-
si_int __popcountsi2(si_int a); // bit population
57-
si_int __popcountdi2(di_int a); // bit population
58-
si_int __popcountti2(ti_int a); // bit population
61+
int __popcountsi2(si_int a); // bit population
62+
int __popcountdi2(di_int a); // bit population
63+
int __popcountti2(ti_int a); // bit population
5964

6065
uint32_t __bswapsi2(uint32_t a); // a byteswapped
6166
uint64_t __bswapdi2(uint64_t a); // a byteswapped
@@ -169,10 +174,10 @@ long double __floatuntixf(tu_int a);
169174

170175
// Floating point raised to integer power
171176

172-
float __powisf2( float a, si_int b); // a ^ b
173-
double __powidf2( double a, si_int b); // a ^ b
174-
long double __powixf2(long double a, si_int b); // a ^ b
175-
long double __powitf2(long double a, si_int b); // ppc only, a ^ b
177+
float __powisf2( float a, int b); // a ^ b
178+
double __powidf2( double a, int b); // a ^ b
179+
long double __powixf2(long double a, int b); // a ^ b
180+
long double __powitf2(long double a, int b); // ppc only, a ^ b
176181

177182
// Complex arithmetic
178183

compiler-rt/lib/builtins/clzdi2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
// ctz instruction, gcc resolves __builtin_clz to __clzdi2 rather than
2222
// __clzsi2, leading to infinite recursion.
2323
#define __builtin_clz(a) __clzsi2(a)
24-
extern si_int __clzsi2(si_int);
24+
extern int __clzsi2(si_int);
2525
#endif
2626

2727
// Precondition: a != 0
2828

29-
COMPILER_RT_ABI si_int __clzdi2(di_int a) {
29+
COMPILER_RT_ABI int __clzdi2(di_int a) {
3030
dwords x;
3131
x.all = a;
3232
const si_int f = -(x.s.high == 0);

compiler-rt/lib/builtins/clzsi2.c

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

1717
// Precondition: a != 0
1818

19-
COMPILER_RT_ABI si_int __clzsi2(si_int a) {
19+
COMPILER_RT_ABI int __clzsi2(si_int a) {
2020
su_int x = (su_int)a;
2121
si_int t = ((x & 0xFFFF0000) == 0) << 4; // if (x is small) t = 16 else 0
2222
x >>= 16 - t; // x = [0 - 0xFFFF]

compiler-rt/lib/builtins/clzti2.c

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

1919
// Precondition: a != 0
2020

21-
COMPILER_RT_ABI si_int __clzti2(ti_int a) {
21+
COMPILER_RT_ABI int __clzti2(ti_int a) {
2222
twords x;
2323
x.all = a;
2424
const di_int f = -(x.s.high == 0);

compiler-rt/lib/builtins/ctzdi2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// ctz instruction, gcc resolves __builtin_ctz to __ctzdi2 rather than
2222
// __ctzsi2, leading to infinite recursion.
2323
#define __builtin_ctz(a) __ctzsi2(a)
24-
extern si_int __ctzsi2(si_int);
24+
extern int __ctzsi2(si_int);
2525
#endif
2626

2727
// Precondition: a != 0

compiler-rt/lib/builtins/ctzsi2.c

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

1717
// Precondition: a != 0
1818

19-
COMPILER_RT_ABI si_int __ctzsi2(si_int a) {
19+
COMPILER_RT_ABI int __ctzsi2(si_int a) {
2020
su_int x = (su_int)a;
2121
si_int t = ((x & 0x0000FFFF) == 0)
2222
<< 4; // if (x has no small bits) t = 16 else 0

compiler-rt/lib/builtins/ctzti2.c

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

1919
// Precondition: a != 0
2020

21-
COMPILER_RT_ABI si_int __ctzti2(ti_int a) {
21+
COMPILER_RT_ABI int __ctzti2(ti_int a) {
2222
twords x;
2323
x.all = a;
2424
const di_int f = -(x.s.low == 0);

compiler-rt/lib/builtins/ffsti2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// Returns: the index of the least significant 1-bit in a, or
1818
// the value zero if a is zero. The least significant bit is index one.
1919

20-
COMPILER_RT_ABI si_int __ffsti2(ti_int a) {
20+
COMPILER_RT_ABI int __ffsti2(ti_int a) {
2121
twords x;
2222
x.all = a;
2323
if (x.s.low == 0) {

compiler-rt/lib/builtins/int_lib.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@
9292
// Include internal utility function declarations.
9393
#include "int_util.h"
9494

95-
COMPILER_RT_ABI si_int __paritysi2(si_int a);
96-
COMPILER_RT_ABI si_int __paritydi2(di_int a);
95+
COMPILER_RT_ABI int __paritysi2(si_int a);
96+
COMPILER_RT_ABI int __paritydi2(di_int a);
9797

9898
COMPILER_RT_ABI di_int __divdi3(di_int a, di_int b);
9999
COMPILER_RT_ABI si_int __divsi3(si_int a, si_int b);
@@ -102,37 +102,37 @@ COMPILER_RT_ABI su_int __udivsi3(su_int n, su_int d);
102102
COMPILER_RT_ABI su_int __udivmodsi4(su_int a, su_int b, su_int *rem);
103103
COMPILER_RT_ABI du_int __udivmoddi4(du_int a, du_int b, du_int *rem);
104104
#ifdef CRT_HAS_128BIT
105-
COMPILER_RT_ABI si_int __clzti2(ti_int a);
105+
COMPILER_RT_ABI int __clzti2(ti_int a);
106106
COMPILER_RT_ABI tu_int __udivmodti4(tu_int a, tu_int b, tu_int *rem);
107107
#endif
108108

109109
// Definitions for builtins unavailable on MSVC
110110
#if defined(_MSC_VER) && !defined(__clang__)
111111
#include <intrin.h>
112112

113-
uint32_t __inline __builtin_ctz(uint32_t value) {
113+
int __inline __builtin_ctz(uint32_t value) {
114114
unsigned long trailing_zero = 0;
115115
if (_BitScanForward(&trailing_zero, value))
116116
return trailing_zero;
117117
return 32;
118118
}
119119

120-
uint32_t __inline __builtin_clz(uint32_t value) {
120+
int __inline __builtin_clz(uint32_t value) {
121121
unsigned long leading_zero = 0;
122122
if (_BitScanReverse(&leading_zero, value))
123123
return 31 - leading_zero;
124124
return 32;
125125
}
126126

127127
#if defined(_M_ARM) || defined(_M_X64)
128-
uint32_t __inline __builtin_clzll(uint64_t value) {
128+
int __inline __builtin_clzll(uint64_t value) {
129129
unsigned long leading_zero = 0;
130130
if (_BitScanReverse64(&leading_zero, value))
131131
return 63 - leading_zero;
132132
return 64;
133133
}
134134
#else
135-
uint32_t __inline __builtin_clzll(uint64_t value) {
135+
int __inline __builtin_clzll(uint64_t value) {
136136
if (value == 0)
137137
return 64;
138138
uint32_t msh = (uint32_t)(value >> 32);

compiler-rt/lib/builtins/paritydi2.c

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

1515
// Returns: 1 if number of bits is odd else returns 0
1616

17-
COMPILER_RT_ABI si_int __paritydi2(di_int a) {
17+
COMPILER_RT_ABI int __paritydi2(di_int a) {
1818
dwords x;
1919
x.all = a;
2020
return __paritysi2(x.s.high ^ x.s.low);

compiler-rt/lib/builtins/paritysi2.c

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

1515
// Returns: 1 if number of bits is odd else returns 0
1616

17-
COMPILER_RT_ABI si_int __paritysi2(si_int a) {
17+
COMPILER_RT_ABI int __paritysi2(si_int a) {
1818
su_int x = (su_int)a;
1919
x ^= x >> 16;
2020
x ^= x >> 8;

compiler-rt/lib/builtins/parityti2.c

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

1717
// Returns: 1 if number of bits is odd else returns 0
1818

19-
COMPILER_RT_ABI si_int __parityti2(ti_int a) {
19+
COMPILER_RT_ABI int __parityti2(ti_int a) {
2020
twords x;
2121
x.all = a;
2222
return __paritydi2(x.s.high ^ x.s.low);

compiler-rt/lib/builtins/popcountsi2.c

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

1515
// Returns: count of 1 bits
1616

17-
COMPILER_RT_ABI si_int __popcountsi2(si_int a) {
17+
COMPILER_RT_ABI int __popcountsi2(si_int a) {
1818
su_int x = (su_int)a;
1919
x = x - ((x >> 1) & 0x55555555);
2020
// Every 2 bits holds the sum of every pair of bits

compiler-rt/lib/builtins/popcountti2.c

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

1818
// Returns: count of 1 bits
1919

20-
COMPILER_RT_ABI si_int __popcountti2(ti_int a) {
20+
COMPILER_RT_ABI int __popcountti2(ti_int a) {
2121
tu_int x3 = (tu_int)a;
2222
x3 = x3 - ((x3 >> 1) &
2323
(((tu_int)0x5555555555555555uLL << 64) | 0x5555555555555555uLL));

compiler-rt/lib/builtins/powidf2.c

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

1515
// Returns: a ^ b
1616

17-
COMPILER_RT_ABI double __powidf2(double a, si_int b) {
17+
COMPILER_RT_ABI double __powidf2(double a, int b) {
1818
const int recip = b < 0;
1919
double r = 1;
2020
while (1) {

compiler-rt/lib/builtins/powisf2.c

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

1515
// Returns: a ^ b
1616

17-
COMPILER_RT_ABI float __powisf2(float a, si_int b) {
17+
COMPILER_RT_ABI float __powisf2(float a, int b) {
1818
const int recip = b < 0;
1919
float r = 1;
2020
while (1) {

compiler-rt/lib/builtins/powitf2.c

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

1818
// Returns: a ^ b
1919

20-
COMPILER_RT_ABI long double __powitf2(long double a, si_int b) {
20+
COMPILER_RT_ABI long double __powitf2(long double a, int b) {
2121
const int recip = b < 0;
2222
long double r = 1;
2323
while (1) {

compiler-rt/lib/builtins/powixf2.c

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

1717
// Returns: a ^ b
1818

19-
COMPILER_RT_ABI long double __powixf2(long double a, si_int b) {
19+
COMPILER_RT_ABI long double __powixf2(long double a, int b) {
2020
const int recip = b < 0;
2121
long double r = 1;
2222
while (1) {

compiler-rt/test/builtins/Unit/clzdi2_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
// Precondition: a != 0
1010

11-
COMPILER_RT_ABI si_int __clzdi2(di_int a);
11+
COMPILER_RT_ABI int __clzdi2(di_int a);
1212

13-
int test__clzdi2(di_int a, si_int expected)
13+
int test__clzdi2(di_int a, int expected)
1414
{
15-
si_int x = __clzdi2(a);
15+
int x = __clzdi2(a);
1616
if (x != expected)
1717
printf("error in __clzdi2(0x%llX) = %d, expected %d\n", a, x, expected);
1818
return x != expected;

compiler-rt/test/builtins/Unit/clzsi2_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
// Precondition: a != 0
1010

11-
COMPILER_RT_ABI si_int __clzsi2(si_int a);
11+
COMPILER_RT_ABI int __clzsi2(si_int a);
1212

13-
int test__clzsi2(si_int a, si_int expected)
13+
int test__clzsi2(si_int a, int expected)
1414
{
15-
si_int x = __clzsi2(a);
15+
int x = __clzsi2(a);
1616
if (x != expected)
1717
printf("error in __clzsi2(0x%X) = %d, expected %d\n", a, x, expected);
1818
return x != expected;

compiler-rt/test/builtins/Unit/clzti2_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
// Precondition: a != 0
1313

14-
COMPILER_RT_ABI si_int __clzti2(ti_int a);
14+
COMPILER_RT_ABI int __clzti2(ti_int a);
1515

16-
int test__clzti2(ti_int a, si_int expected)
16+
int test__clzti2(ti_int a, int expected)
1717
{
18-
si_int x = __clzti2(a);
18+
int x = __clzti2(a);
1919
if (x != expected)
2020
{
2121
twords at;

compiler-rt/test/builtins/Unit/ctzsi2_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
// Precondition: a != 0
1010

11-
COMPILER_RT_ABI si_int __ctzsi2(si_int a);
11+
COMPILER_RT_ABI int __ctzsi2(si_int a);
1212

13-
int test__ctzsi2(si_int a, si_int expected)
13+
int test__ctzsi2(si_int a, int expected)
1414
{
15-
si_int x = __ctzsi2(a);
15+
int x = __ctzsi2(a);
1616
if (x != expected)
1717
printf("error in __ctzsi2(0x%X) = %d, expected %d\n", a, x, expected);
1818
return x != expected;

compiler-rt/test/builtins/Unit/ctzti2_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
// Precondition: a != 0
1313

14-
COMPILER_RT_ABI si_int __ctzti2(ti_int a);
14+
COMPILER_RT_ABI int __ctzti2(ti_int a);
1515

16-
int test__ctzti2(ti_int a, si_int expected)
16+
int test__ctzti2(ti_int a, int expected)
1717
{
18-
si_int x = __ctzti2(a);
18+
int x = __ctzti2(a);
1919
if (x != expected)
2020
{
2121
twords at;

compiler-rt/test/builtins/Unit/ffsti2_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
// Returns: the index of the least significant 1-bit in a, or
1111
// the value zero if a is zero. The least significant bit is index one.
1212

13-
COMPILER_RT_ABI si_int __ffsti2(ti_int a);
13+
COMPILER_RT_ABI int __ffsti2(ti_int a);
1414

15-
int test__ffsti2(ti_int a, si_int expected)
15+
int test__ffsti2(ti_int a, int expected)
1616
{
17-
si_int x = __ffsti2(a);
17+
int x = __ffsti2(a);
1818
if (x != expected)
1919
{
2020
twords at;

compiler-rt/test/builtins/Unit/paritydi2_test.c

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

88
// Returns: 1 if number of bits is odd else returns 0
99

10-
COMPILER_RT_ABI si_int __paritydi2(di_int a);
10+
COMPILER_RT_ABI int __paritydi2(di_int a);
1111

1212
int naive_parity(di_int a)
1313
{

compiler-rt/test/builtins/Unit/paritysi2_test.c

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

88
// Returns: 1 if number of bits is odd else returns 0
99

10-
COMPILER_RT_ABI si_int __paritysi2(si_int a);
10+
COMPILER_RT_ABI int __paritysi2(si_int a);
1111

1212
int naive_parity(si_int a)
1313
{

compiler-rt/test/builtins/Unit/parityti2_test.c

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

1111
// Returns: 1 if number of bits is odd else returns 0
1212

13-
COMPILER_RT_ABI si_int __parityti2(ti_int a);
13+
COMPILER_RT_ABI int __parityti2(ti_int a);
1414

1515
int naive_parity(ti_int a)
1616
{

0 commit comments

Comments
 (0)