[compiler-rt] 3834b04 - [builtins] Support architectures with 16-bit int in __ashlti3, __ashrti3 and __lshrti3

Karl-Johan Karlsson via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 30 22:09:51 PDT 2023


Author: Karl-Johan Karlsson
Date: 2023-03-31T07:02:55+02:00
New Revision: 3834b0467ddc97ce0595e98eab805cd306ba4069

URL: https://github.com/llvm/llvm-project/commit/3834b0467ddc97ce0595e98eab805cd306ba4069
DIFF: https://github.com/llvm/llvm-project/commit/3834b0467ddc97ce0595e98eab805cd306ba4069.diff

LOG: [builtins] Support architectures with 16-bit int in __ashlti3, __ashrti3 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

Added: 
    

Modified: 
    compiler-rt/lib/builtins/README.txt
    compiler-rt/lib/builtins/ashlti3.c
    compiler-rt/lib/builtins/ashrti3.c
    compiler-rt/lib/builtins/lshrti3.c
    compiler-rt/test/builtins/Unit/ashlti3_test.c
    compiler-rt/test/builtins/Unit/ashrti3_test.c
    compiler-rt/test/builtins/Unit/lshrti3_test.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/builtins/README.txt b/compiler-rt/lib/builtins/README.txt
index 53d656d5086d..5637183cc3b4 100644
--- a/compiler-rt/lib/builtins/README.txt
+++ b/compiler-rt/lib/builtins/README.txt
@@ -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

diff  --git a/compiler-rt/lib/builtins/ashlti3.c b/compiler-rt/lib/builtins/ashlti3.c
index 2d7bd4a89380..99a133ffa22f 100644
--- a/compiler-rt/lib/builtins/ashlti3.c
+++ b/compiler-rt/lib/builtins/ashlti3.c
@@ -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;

diff  --git a/compiler-rt/lib/builtins/ashrti3.c b/compiler-rt/lib/builtins/ashrti3.c
index f573b6d6ccba..b306051df028 100644
--- a/compiler-rt/lib/builtins/ashrti3.c
+++ b/compiler-rt/lib/builtins/ashrti3.c
@@ -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;

diff  --git a/compiler-rt/lib/builtins/lshrti3.c b/compiler-rt/lib/builtins/lshrti3.c
index d00a22095993..5dc8a0a2347f 100644
--- a/compiler-rt/lib/builtins/lshrti3.c
+++ b/compiler-rt/lib/builtins/lshrti3.c
@@ -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;

diff  --git a/compiler-rt/test/builtins/Unit/ashlti3_test.c b/compiler-rt/test/builtins/Unit/ashlti3_test.c
index 2e810090703c..3dfa4118b119 100644
--- a/compiler-rt/test/builtins/Unit/ashlti3_test.c
+++ b/compiler-rt/test/builtins/Unit/ashlti3_test.c
@@ -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};

diff  --git a/compiler-rt/test/builtins/Unit/ashrti3_test.c b/compiler-rt/test/builtins/Unit/ashrti3_test.c
index 7ea3ccde4350..c17143bb3b1a 100644
--- a/compiler-rt/test/builtins/Unit/ashrti3_test.c
+++ b/compiler-rt/test/builtins/Unit/ashrti3_test.c
@@ -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};

diff  --git a/compiler-rt/test/builtins/Unit/lshrti3_test.c b/compiler-rt/test/builtins/Unit/lshrti3_test.c
index e6e441bcc218..625726fe647d 100644
--- a/compiler-rt/test/builtins/Unit/lshrti3_test.c
+++ b/compiler-rt/test/builtins/Unit/lshrti3_test.c
@@ -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};


        


More information about the llvm-commits mailing list