From 6a80a6ae9aeb0c4cac1489909960e1468457c3c3 Mon Sep 17 00:00:00 2001 From: Guillaume Le Vaillant Date: Mon, 26 Feb 2024 10:09:15 +0100 Subject: [PATCH] Improve rol and ror code for ECL It should avoid undefined behavior with some C compilers. --- src/common.lisp | 8 ++++---- 1 file 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)