| 1 |
|
| 2 |
|
| 3 |
#ifndef _BITS_H |
| 4 |
#define _BITS_H |
| 5 |
|
| 6 |
#define CONST_POPCOUNT2(x) ((((x) >> 0) & 1) + (((x) >> 1) & 1)) |
| 7 |
#define CONST_POPCOUNT4(x) (CONST_POPCOUNT2(x) + CONST_POPCOUNT2((x)>>2)) |
| 8 |
#define CONST_POPCOUNT8(x) (CONST_POPCOUNT4(x) + CONST_POPCOUNT4((x)>>4)) |
| 9 |
#define CONST_POPCOUNT16(x) (CONST_POPCOUNT8(x) + CONST_POPCOUNT8((x)>>8)) |
| 10 |
#define CONST_POPCOUNT32(x) (CONST_POPCOUNT16(x) + CONST_POPCOUNT16((x)>>16)) |
| 11 |
#define CONST_POPCOUNT64(x) (CONST_POPCOUNT32(x) + CONST_POPCOUNT32((x)>>32)) |
| 12 |
#define CONST_POPCOUNT(x) CONST_POPCOUNT64(x) |
| 13 |
|
| 14 |
#define CONST_CTZ2(x) CONST_POPCOUNT2(((x) & -(x))-1) |
| 15 |
#define CONST_CTZ4(x) CONST_POPCOUNT4(((x) & -(x))-1) |
| 16 |
#define CONST_CTZ8(x) CONST_POPCOUNT8(((x) & -(x))-1) |
| 17 |
#define CONST_CTZ16(x) CONST_POPCOUNT16(((x) & -(x))-1) |
| 18 |
#define CONST_CTZ32(x) CONST_POPCOUNT32(((x) & -(x))-1) |
| 19 |
#define CONST_CTZ64(x) CONST_POPCOUNT64(((x) & -(x))-1) |
| 20 |
#define CONST_CTZ(x) CONST_CTZ64(x) |
| 21 |
|
| 22 |
#define STR(x) XSTR(x) |
| 23 |
#define XSTR(x) #x |
| 24 |
|
| 25 |
#if __riscv_xlen == 64 |
| 26 |
#define SLL32 sllw |
| 27 |
#define STORE sd |
| 28 |
#define LOAD ld |
| 29 |
#define LWU lwu |
| 30 |
#define LOG_REGBYTES 3 |
| 31 |
#else |
| 32 |
#define SLL32 sll |
| 33 |
#define STORE sw |
| 34 |
#define LOAD lw |
| 35 |
#define LWU lw |
| 36 |
#define LOG_REGBYTES 2 |
| 37 |
#endif |
| 38 |
|
| 39 |
#define REGBYTES (1 << LOG_REGBYTES) |
| 40 |
|
| 41 |
#endif |