joeldipops / gbz80-pseudoOps

Set of rgbasm macros and constants to facilitate readability for modern programmers
MIT License
9 stars 1 forks source link

mult op questionable performance #11

Closed joeldipops closed 5 years ago

joeldipops commented 5 years ago

Try to improve mult op by using example here: http://wikiti.brandonw.net/index.php?title=Z80_Routines:Math:Multiplication

originally here: https://github.com/joeldipops/gbz80-pseudoOps/pull/8

'Now constant time, and uses less regs' eg.

;;; ; mult r16, r8 ; Multiples an 8-bit number (in LOW(\1)) with H, result in HL ; @param \2 A temporary register. Make SURE it's not one of H, L, HIGH(\1), or LOW(\1). ; @return HL The result ; @return HIGH(\1) 0 ; @return \2 0 ; @return ZF Set ; @destroy CF ;;; mult: macro ld L, 0 ld HIGH(\2), L ld \2, 7

; Optimized first iteration
sla H
jr NC, .loop\@
ld L, LOW(\2)

.loop\@ add HL, HL jr NC, .noAdd\@ add HL, DE .noAdd dec \2 jr NZ, .loop\@ endm

joeldipops commented 5 years ago

Replaced previous mult macro with code similar to the above. Will multiple A with the first term, result in HL. Should work with any 8-bit value eg

mult B
mult [BC]
mult [$1234]
mult $32