OK, I think I've figured out the correct algorithm. Code below, with some example ASM.
In fact, looking at the ASM that PB currently produces it converts the long to a quad, then performs the division. So the same code works for longs and quads quite easily. I don't know how to do this shifting nicely for quads so perhaps thats another issue doing it this way.
Code: Select all
Define.l b
Define.l a
#MAX_RANGE = 100000000
;#MAX_RANGE = 10
#DIVIDE_BY = 2
#SHIFT_BY = 1
st=GetTickCount_()
For a = -#MAX_RANGE To #MAX_RANGE
b = a / #DIVIDE_BY
Next
et=GetTickCount_()
MessageRequester("Duration", Str(et-st))
st=GetTickCount_()
For a = -#MAX_RANGE To #MAX_RANGE
;b = a >> #SHIFT_BY
;If b < 0 And (a & ((1 << #SHIFT_BY)-1))
; b + 1
;EndIf
#ADJUST_MASK = (1 << #SHIFT_BY)-1
;Debug #ADJUST_MASK
MOV ebx, dword [v_a]
MOV eax, ebx
AND eax, #ADJUST_MASK
SETNZ al
AND eax, 1
ROL ebx, 1
AND eax, ebx
ROR ebx, 1
SAR ebx, #SHIFT_BY
ADD ebx, eax
MOV dword [v_b],ebx
Debug b
Next
et=GetTickCount_()
MessageRequester("Duration", Str(et-st))
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)