Posted: Tue Jul 15, 2003 7:38 pm
You need to go look at my post in the General forum:
"Inline ASM slower than equivalent PB code..."
The extra MUL and SUB insturction add only 3.2 milliseconds of overhead over a million iterations! Maybe not on an old 8086, but on today's CPU's with multiple pipelines, the PB code is almost as effiecient as the raw ASM code.
I wrote several MOD functions that I'm including in a math library for PB, here they are if you like. If you use the ASM versions you need to make sure the "inline assembly" option is set in your compiler options.
Matthew
"Inline ASM slower than equivalent PB code..."
The extra MUL and SUB insturction add only 3.2 milliseconds of overhead over a million iterations! Maybe not on an old 8086, but on today's CPU's with multiple pipelines, the PB code is almost as effiecient as the raw ASM code.
I wrote several MOD functions that I'm including in a math library for PB, here they are if you like. If you use the ASM versions you need to make sure the "inline assembly" option is set in your compiler options.
Matthew
Code: Select all
;
; FISHLIB MATH
;
; Matthew Hagerty - 2003.07.10
;
; Math Function Summary
Declare.l fl_mod(dividend.l, divisor.l)
Declare.l fl_mod_asm(dividend.l, divisor.l)
Declare.l fl_mod_asm_u(dividend.l, divisor.l)
;
; Returns the remainder (modulus) obtained by dividing
; one numeric expression into another. The return
; value will have the same sign (+/-) as the dividend.
;
; Examples:
;
; mod(6, 10) returns: 6
; mod(10, 10) returns: 0
; mod(-67, 10) returns: -7
;
Procedure.l fl_mod(dividend.l, divisor.l)
; Division by zero is illegal.
If divisor = 0
ProcedureReturn 0
EndIf
ProcedureReturn dividend - ((dividend / divisor) * divisor)
EndProcedure
; fl_mod()
;
; Same as fl_mod(), but implemented with inline assembly instead
; of PB code.
;
Procedure.l fl_mod_asm(dividend.l, divisor.l)
; Division by zero is illegal.
If divisor = 0
ProcedureReturn 0
EndIf
; Oh yeah, assembly is great! Saves a whole
; multiplication and subtraction!
MOV eax, dividend
CDQ
IDIV divisor
MOV dividend, edx
ProcedureReturn dividend
EndProcedure
; fl_mod_asm()
;
; Returns the remainder (modulus) obtained by dividing
; one numeric expression into another. This is the
; UNSIGNED version of the mod() function and will ignore
; any sign a number might have.
;
; Until PB supports unsigned vars, this function is only
; implemented with ASM.
;
; Examples:
;
; mod(6, 10) returns: 6
; mod(10, 10) returns: 0
; mod(-67, 10) returns: 9 <-- This is correct, since -67 unsigned is 4294967229.
;
Procedure.l fl_mod_asm_u(dividend.l, divisor.l)
; Division by zero is illegal.
If divisor = 0
ProcedureReturn 0
EndIf
; Oh yeah, assembly is great! Saves a whole
; multiplication and subtraction!
MOV eax, dividend
XOR edx, edx
DIV divisor
MOV dividend, edx
ProcedureReturn dividend
EndProcedure
; fl_mod_asm_u()