Hi, Tiezhu On 08/09/2022 10:52 AM, Tiezhu Yang wrote:
+ +static inline bool is_unsigned_imm(unsigned long val, unsigned int bit) +{ + return val >= 0 && val < (1UL << bit); +}
The "val >= 0" condition can be removed because val is of type "unsigned long".
+ +static inline bool is_signed_imm(long val, unsigned int bit) +{ + return -(1L << (bit - 1)) <= val && val < (1L << (bit - 1)); +}
is_{unsigned/signed}_imm() is the same as {signed/unsigned}_imm_check() in module.c, maybe we can move this function to inst.h. Thanks, Youling
+ +#define is_signed_imm12(val) is_signed_imm(val, 12) +#define is_signed_imm16(val) is_signed_imm(val, 16) +#define is_signed_imm26(val) is_signed_imm(val, 26) +#define is_signed_imm32(val) is_signed_imm(val, 32) +#define is_signed_imm52(val) is_signed_imm(val, 52) +#define is_unsigned_imm12(val) is_unsigned_imm(val, 12) +