| 982 | } |
| 983 | |
| 984 | int32_t libdivide_s32_branchfree_do(int32_t numer, const struct libdivide_s32_branchfree_t *denom) { |
| 985 | uint8_t more = denom->more; |
| 986 | uint8_t shift = more & LIBDIVIDE_32_SHIFT_MASK; |
| 987 | // must be arithmetic shift and then sign extend |
| 988 | int32_t sign = (int8_t)more >> 7; |
| 989 | int32_t magic = denom->magic; |
| 990 | int32_t q = libdivide_mullhi_s32(magic, numer); |
| 991 | q += numer; |
| 992 | |
| 993 | // If q is non-negative, we have nothing to do |
| 994 | // If q is negative, we want to add either (2**shift)-1 if d is a power of |
| 995 | // 2, or (2**shift) if it is not a power of 2 |
| 996 | uint32_t is_power_of_2 = (magic == 0); |
| 997 | uint32_t q_sign = (uint32_t)(q >> 31); |
| 998 | q += q_sign & ((1U << shift) - is_power_of_2); |
| 999 | |
| 1000 | // Now arithmetic right shift |
| 1001 | q >>= shift; |
| 1002 | // Negate if needed |
| 1003 | q = (q ^ sign) - sign; |
| 1004 | |
| 1005 | return q; |
| 1006 | } |
| 1007 | |
| 1008 | int32_t libdivide_s32_recover(const struct libdivide_s32_t *denom) { |
| 1009 | uint8_t more = denom->more; |
nothing calls this directly
no test coverage detected