Skip to content

Commit 764e81e

Browse files
committed
portable rotate (idiom recognised & optimised by gcc/clang)
1 parent b9482fd commit 764e81e

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

jsrc/j.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,9 @@ extern I CTLZI_(UI,UI4*);
22582258
#define BLSR(x) ((x)&~BLSI(x))
22592259
#endif
22602260

2261+
static inline UI4 rol32(UI4 x,I s){ R (x<<s)|(x>>(32-x)); }
2262+
static inline UI4 ror32(UI4 x,I s){ R (x>>s)|(x<<(32-x)); }
2263+
22612264
// Set these switches for testing
22622265
#define AUDITBP 0 // Verify that bp() returns expected data
22632266
#define AUDITCOMPILER 0 // Verify compiler features CTTZ, signed >>

jsrc/viavx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static I hashallo(IH * RESTRICT hh,UI p,UI asct,I md){
177177
// CRC32L takes UIL (8 bytes)
178178

179179
// obsolete #define RETCRC3 R CRC32L(crc0,CRC32L(crc1,crc2))
180-
#define RETCRC3 R CRC32L(crc0,(UI)__builtin_rotateleft32(crc1,9)+((UI)__builtin_rotateleft32(crc2,21)<<32))
180+
#define RETCRC3 R CRC32L(crc0,(UI)rol32(crc1,9)+((UI)rol32(crc2,21)<<32))
181181
// Create CRC32 of the k bytes in *v. Uses CRC32L to process 8 bytes at a time
182182
// We may fetch past the end of the input, but only up to the next SZI-byte block
183183
UI hic(I k, UC *v) {

0 commit comments

Comments
 (0)