Re: A86: simple math optimization
[Prev][Next][Index][Thread]
Re: A86: simple math optimization
At 16:52 1998-05-11 -0500, you wrote:
>> What's the fastest way to do
>>
>> hl = (16 * d) + e
>ld (D_temp), d ; 13
>ld hl, D_temp ; 10
>xor a ; 4
>rld ; 18
>ld d, a ; 4
>ld a, (D_temp) ; 13
>add a, e ; 4
>ld l, a ; 4
>ld a, d ; 4
>adc a, 0 ; 7
>ld h, a ; 4
Slow - 85 T cycles. The idea could be optimized though
>ld h, 0
>ld l, d
>add hl, hl
>add hl, hl
>add hl, hl
>add hl, hl ; now hl = 16 * d
>ld d, 0
>add hl, de ; and then we add the e
That would be 7+4+11*4+7+11 = 73 T cycles, but could be made 3 T cycles
faster if "ld d,0" was replaced by "ld d,h" after the "ld l,d" instruction.
This is faster (fastest?)
ld a,d ; 4
rlca ; 4
rlca ; 4
rlca ; 4
rlca ; 4
ld l,a ; 4
and 15 ; 7
ld h,a ; 4
ld a,l ; 4
xor h ; 4
or e ; 4
ld l,a ; 4
51 T cycles
This assumes E<16, but I guess that is the case (else 16*D+E is a strange
operation to make). Could be changed to support E>=16 as well, without
losing that many T cycles.
--
Real name: Jimmy Mårdell "can't go mucking with a 'void *'"
IRC......: Yarin // Apple's MPW C compiler
Email....: mailto:yarin@acc.umu.se
Homepage.: http://www.algonet.se/~mja/
References: