summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Le Vaillant <glv@posteo.net>2024-02-26 10:09:15 +0100
committerGuillaume Le Vaillant <glv@posteo.net>2024-02-26 10:09:15 +0100
commit6a80a6ae9aeb0c4cac1489909960e1468457c3c3 (patch)
treec9b369036c8a768cf7618b13301478df0369b4c1
parenta0220ba3f0b4fc93ac99bba5680cbace1b95cf70 (diff)
Improve rol and ror code for ECL
It should avoid undefined behavior with some C compilers.
-rw-r--r--src/common.lisp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/common.lisp b/src/common.lisp
index fd2be82..3e9f232 100644
--- a/src/common.lisp
+++ b/src/common.lisp
@@ -555,7 +555,7 @@ uint64_t r = (n << 56)
(ffi:c-inline (a s)
(:uint32-t :uint8-t)
:uint32-t
- "(#0 << #1) | (#0 >> (32 - #1))"
+ "(#0 << #1) | (#0 >> (-#1 & 31))"
:one-liner t
:side-effects nil)
@@ -578,7 +578,7 @@ uint64_t r = (n << 56)
(ffi:c-inline (a s)
(:uint32-t :uint8-t)
:uint32-t
- "(#0 << (32 - #1)) | (#0 >> #1)"
+ "(#0 << (-#1 & 31)) | (#0 >> #1)"
:one-liner t
:side-effects nil)
@@ -720,7 +720,7 @@ uint64_t r = (n << 56)
(ffi:c-inline (a s)
(:uint64-t :uint8-t)
:uint64-t
- "(#0 << #1) | (#0 >> (64 - #1))"
+ "(#0 << #1) | (#0 >> (-#1 & 63))"
:one-liner t
:side-effects nil)
@@ -742,7 +742,7 @@ uint64_t r = (n << 56)
(ffi:c-inline (a s)
(:uint64-t :uint8-t)
:uint64-t
- "(#0 << (64 - #1)) | (#0 >> #1)"
+ "(#0 << (-#1 & 63)) | (#0 >> #1)"
:one-liner t
:side-effects nil)