David Gibson <da...@gibson.dropbear.id.au> writes: >> diff --git a/target-ppc/int_helper.c b/target-ppc/int_helper.c >> index dca4798..b54cd7c 100644 >> --- a/target-ppc/int_helper.c >> +++ b/target-ppc/int_helper.c >> @@ -1717,6 +1717,52 @@ void helper_vrsqrtefp(CPUPPCState *env, ppc_avr_t *r, >> ppc_avr_t *b) >> } >> } >> >> +#define MASK(size, max_val) \ >> +static inline uint##size##_t mask_u##size(uint##size##_t start, \ >> + uint##size##_t end) \ >> +{ \ >> + uint##size##_t ret, max_bit = size - 1; \ >> + \ >> + if (likely(start == 0)) { \ >> + ret = max_val << (max_bit - end); \ >> + } else if (likely(end == max_bit)) { \ >> + ret = max_val >> start; \ >> + } else { \ >> + ret = (((uint##size##_t)(-1ULL)) >> (start)) ^ \ >> + (((uint##size##_t)(-1ULL) >> (end)) >> 1); \ >> + if (unlikely(start > end)) { \ >> + return ~ret; \ >> + } \ >> + } \ >> + \ >> + return ret; \ >> +} >> + >> +MASK(32, UINT32_MAX); >> +MASK(64, UINT64_MAX); > > It would be nicer to merge this mask generation with the > implementation in target-ppc/translate.c (called MASK()).
How about something like this in target-ppc/cpu.h #define FUNC_MASK(name, ret_type, size, max_val) \ static inline ret_type name (uint##size##_t start, \ uint##size##_t end) \ { \ ret_type ret, max_bit = size - 1; \ \ if (likely(start == 0)) { \ ret = max_val << (max_bit - end); \ } else if (likely(end == max_bit)) { \ ret = max_val >> start; \ } else { \ ret = (((uint##size##_t)(-1ULL)) >> (start)) ^ \ (((uint##size##_t)(-1ULL) >> (end)) >> 1); \ if (unlikely(start > end)) { \ return ~ret; \ } \ } \ \ return ret; \ } #if defined(TARGET_PPC64) FUNC_MASK(MASK, target_ulong, 64, UINT64_MAX); #else FUNC_MASK(MASK, target_ulong, 32, UINT32_MAX); #endif FUNC_MASK(mask_u32, uint32_t, 32, UINT32_MAX); FUNC_MASK(mask_u64, uint64_t, 64, UINT64_MAX); Regards Nikunj