Division by a constant value is done quickly by doing a 64bit-multiply and shift-right, for example, like this:
LDR R3, =0xA151C331
UMULL R3, R2, R1, R3
MOV R0, R2,LSR#10
here R1 is divided by 1625.
The calculation is done like this: 64bitreg(R2:R3) = R1*0xA151C331, then the result is the upper 32bit right shifted by 10:
R1*0xA151C331/2^(32+10) = R1*0.00061538461545751488 = R1/1624.99999980
You can calculate your own constants from this formula:
x / N == (x*A)/2^(32+n) --> A = 2^(32+n)/N
select the largest n, for which A < 2^32
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…