qemu-riscv
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3 08/19] qemu/bitops.h: Limit rotate amounts


From: Richard Henderson
Subject: Re: [PATCH v3 08/19] qemu/bitops.h: Limit rotate amounts
Date: Tue, 2 May 2023 21:11:16 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0

On 4/28/23 15:47, Lawrence Hunter wrote:
  static inline uint32_t ror32(uint32_t word, unsigned int shift)
  {
-    return (word >> shift) | (word << ((32 - shift) & 31));
+    shift &= 31;
+    return (word >> shift) | (word << (32 - shift));

This is incorrect, because if shift == 0, you are now performing (word << 32).

I agree with your original intent though, to mask and accept any rotation.
I've changed these like so:

-    return (word >> shift) | (word << ((32 - shift) & 31));
+    return (word >> (shift & 31)) | (word << (-shift & 31));

which also eliminates the useless subtract from word-size-before-mask.


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]