Note:
The shifts often can be combined with shifts that might surround subsequent arithmetic operations (for example, to produce word overflow from the high end of a register).
In the common case, the intended sequence for loading and
LDL | R1,D.lw(Rx) | ! |
EXTBL | R1,#D.mod,R1 | ! |
In the common case, the intended sequence for loading and
LDL | R1,D.lw(Rx) | ! |
SLL | ! | |
SRA | R1,#56,R1 | ! |
In the common case, the intended sequence for storing an aligned word R5 is:
LDL | R1,D.lw(Rx) | ! |
INSWL | R5,#D.mod,R3 | ! |
MSKWL | R1,#D.mod,R1 | ! |
BIS | R3,R1,R1 | ! |
STL | R1,D.lw(Rx) | ! |
In the common case, the intended sequence for storing a byte R5 is:
LDL | R1,D.lw(Rx) | ! |
INSBL | R5,#D.mod,R3 | ! |
MSKBL | R1,#D.mod,R1 | ! |
BIS | R3,R1,R1 | ! |
STL | R1,D.lw(Rx) | ! |
A.4.2 Division
In all implementations,
Thus, any division by a constant power of two should be compiled as a multiply by the exact reciprocal, if it is representable without overflow or underflow. If language rules or surround- ing context allow, multiplication by the reciprocal can closely approximate other divisions by constants.
Integer division does not exist as a hardware opcode. Division by a constant can always be done via UMULH of another appropriate constant, followed by a right shift. A subroutine can do general quadword division by true variables. The subroutine could test for small divisors (less than about 1000 in absolute value) and for those, do a table lookup on the exact constant and shift count for an UMULH/shift sequence. For the remaining cases, a table lookup on about a
Using this approximation, a multiply and a