Skip to content

Commit

Permalink
[builtins] Support architectures with 16-bit int in __ashlti3, __ashr…
Browse files Browse the repository at this point in the history
…ti3 and __lshrti3

The amount to shift should be specified by the int type not a 32-bit integer
type.

This patch change the functions for 128-bit shifts in compiler-rt the same way
as was done for 64-bit shifts in D78662.

The README.txt is updated with the shift builtins signatures from this patch and D78662.

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D146960
  • Loading branch information
karka228 committed Mar 31, 2023
1 parent c53d807 commit 3834b04
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 68 deletions.
12 changes: 6 additions & 6 deletions compiler-rt/lib/builtins/README.txt
Expand Up @@ -35,13 +35,13 @@ typedef uint64_t du_int;

// Integral bit manipulation

di_int __ashldi3(di_int a, si_int b); // a << b
ti_int __ashlti3(ti_int a, si_int b); // a << b
di_int __ashldi3(di_int a, int b); // a << b
ti_int __ashlti3(ti_int a, int b); // a << b

di_int __ashrdi3(di_int a, si_int b); // a >> b arithmetic (sign fill)
ti_int __ashrti3(ti_int a, si_int b); // a >> b arithmetic (sign fill)
di_int __lshrdi3(di_int a, si_int b); // a >> b logical (zero fill)
ti_int __lshrti3(ti_int a, si_int b); // a >> b logical (zero fill)
di_int __ashrdi3(di_int a, int b); // a >> b arithmetic (sign fill)
ti_int __ashrti3(ti_int a, int b); // a >> b arithmetic (sign fill)
di_int __lshrdi3(di_int a, int b); // a >> b logical (zero fill)
ti_int __lshrti3(ti_int a, int b); // a >> b logical (zero fill)

int __clzsi2(si_int a); // count leading zeros
int __clzdi2(di_int a); // count leading zeros
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/builtins/ashlti3.c
Expand Up @@ -18,7 +18,7 @@

// Precondition: 0 <= b < bits_in_tword

COMPILER_RT_ABI ti_int __ashlti3(ti_int a, si_int b) {
COMPILER_RT_ABI ti_int __ashlti3(ti_int a, int b) {
const int bits_in_dword = (int)(sizeof(di_int) * CHAR_BIT);
twords input;
twords result;
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/builtins/ashrti3.c
Expand Up @@ -18,7 +18,7 @@

// Precondition: 0 <= b < bits_in_tword

COMPILER_RT_ABI ti_int __ashrti3(ti_int a, si_int b) {
COMPILER_RT_ABI ti_int __ashrti3(ti_int a, int b) {
const int bits_in_dword = (int)(sizeof(di_int) * CHAR_BIT);
twords input;
twords result;
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/builtins/lshrti3.c
Expand Up @@ -18,7 +18,7 @@

// Precondition: 0 <= b < bits_in_tword

COMPILER_RT_ABI ti_int __lshrti3(ti_int a, si_int b) {
COMPILER_RT_ABI ti_int __lshrti3(ti_int a, int b) {
const int bits_in_dword = (int)(sizeof(di_int) * CHAR_BIT);
utwords input;
utwords result;
Expand Down
40 changes: 19 additions & 21 deletions compiler-rt/test/builtins/Unit/ashlti3_test.c
Expand Up @@ -11,27 +11,25 @@

// Precondition: 0 <= b < bits_in_tword

COMPILER_RT_ABI ti_int __ashlti3(ti_int a, si_int b);

int test__ashlti3(ti_int a, si_int b, ti_int expected)
{
ti_int x = __ashlti3(a, b);
if (x != expected)
{
twords at;
at.all = a;
twords bt;
bt.all = b;
twords xt;
xt.all = x;
twords expectedt;
expectedt.all = expected;
printf("error in __ashlti3: 0x%llX%.16llX << %d = 0x%llX%.16llX,"
" expected 0x%llX%.16llX\n",
at.s.high, at.s.low, b, xt.s.high, xt.s.low,
expectedt.s.high, expectedt.s.low);
}
return x != expected;
COMPILER_RT_ABI ti_int __ashlti3(ti_int a, int b);

int test__ashlti3(ti_int a, int b, ti_int expected) {
ti_int x = __ashlti3(a, b);
if (x != expected) {
twords at;
at.all = a;
twords bt;
bt.all = b;
twords xt;
xt.all = x;
twords expectedt;
expectedt.all = expected;
printf("error in __ashlti3: 0x%llX%.16llX << %d = 0x%llX%.16llX,"
" expected 0x%llX%.16llX\n",
at.s.high, at.s.low, b, xt.s.high, xt.s.low, expectedt.s.high,
expectedt.s.low);
}
return x != expected;
}

char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
Expand Down
36 changes: 17 additions & 19 deletions compiler-rt/test/builtins/Unit/ashrti3_test.c
Expand Up @@ -11,25 +11,23 @@

// Precondition: 0 <= b < bits_in_tword

COMPILER_RT_ABI ti_int __ashrti3(ti_int a, si_int b);

int test__ashrti3(ti_int a, si_int b, ti_int expected)
{
ti_int x = __ashrti3(a, b);
if (x != expected)
{
twords at;
at.all = a;
twords xt;
xt.all = x;
twords expectedt;
expectedt.all = expected;
printf("error in __ashrti3: 0x%llX%.16llX >> %d = 0x%llX%.16llX,"
" expected 0x%llX%.16llX\n",
at.s.high, at.s.low, b, xt.s.high, xt.s.low,
expectedt.s.high, expectedt.s.low);
}
return x != expected;
COMPILER_RT_ABI ti_int __ashrti3(ti_int a, int b);

int test__ashrti3(ti_int a, int b, ti_int expected) {
ti_int x = __ashrti3(a, b);
if (x != expected) {
twords at;
at.all = a;
twords xt;
xt.all = x;
twords expectedt;
expectedt.all = expected;
printf("error in __ashrti3: 0x%llX%.16llX >> %d = 0x%llX%.16llX,"
" expected 0x%llX%.16llX\n",
at.s.high, at.s.low, b, xt.s.high, xt.s.low, expectedt.s.high,
expectedt.s.low);
}
return x != expected;
}

char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
Expand Down
36 changes: 17 additions & 19 deletions compiler-rt/test/builtins/Unit/lshrti3_test.c
Expand Up @@ -11,25 +11,23 @@

// Precondition: 0 <= b < bits_in_dword

COMPILER_RT_ABI ti_int __lshrti3(ti_int a, si_int b);

int test__lshrti3(ti_int a, si_int b, ti_int expected)
{
ti_int x = __lshrti3(a, b);
if (x != expected)
{
twords at;
at.all = a;
twords xt;
xt.all = x;
twords expectedt;
expectedt.all = expected;
printf("error in __lshrti3: 0x%llX%.16llX >> %d = 0x%llX%.16llX,"
" expected 0x%llX%.16llX\n",
at.s.high, at.s.low, b, xt.s.high, xt.s.low,
expectedt.s.high, expectedt.s.low);
}
return x != expected;
COMPILER_RT_ABI ti_int __lshrti3(ti_int a, int b);

int test__lshrti3(ti_int a, int b, ti_int expected) {
ti_int x = __lshrti3(a, b);
if (x != expected) {
twords at;
at.all = a;
twords xt;
xt.all = x;
twords expectedt;
expectedt.all = expected;
printf("error in __lshrti3: 0x%llX%.16llX >> %d = 0x%llX%.16llX,"
" expected 0x%llX%.16llX\n",
at.s.high, at.s.low, b, xt.s.high, xt.s.low, expectedt.s.high,
expectedt.s.low);
}
return x != expected;
}

char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
Expand Down

0 comments on commit 3834b04

Please sign in to comment.