Skip to content

Commit

Permalink
ROTL/ROTR: avoid shift exponents larger than integer width
Browse files Browse the repository at this point in the history
ubsan complains. iirc they are implementation-defined.
  • Loading branch information
yamt committed Apr 24, 2023
1 parent 2d2d43d commit f07718a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/insn_op_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@
#define SHR_S(N, a, b) ((int##N##_t)a >> (b % N))
#define SHR_U(N, a, b) (a >> (b % N))
#define SHL(N, a, b) (a << (b % N))
#define ROTL(N, a, b) ((a << (b % N)) | (a >> (N - (b % N))))
#define ROTR(N, a, b) ((a >> (b % N)) | (a << (N - (b % N))))
#define ROTL(N, a, b) \
((b % N) == 0 ? a : ((a << (b % N)) | (a >> (N - (b % N)))))
#define ROTR(N, a, b) \
((b % N) == 0 ? a : ((a >> (b % N)) | (a << (N - (b % N)))))

#define FDIV(N, a, b) ((a) / (b))

Expand Down

0 comments on commit f07718a

Please sign in to comment.