Well, I'll be flabbernackled! (yes, I just made that up - and I stand by it).Jim e wrote:I'd say it be faster than mine on long lines. Mine uses Bresenham line algorithm so its has to do some compares. Other than that the code looks strikingly similar. Actually mine started off using slope but I thought the over head from the div routine would take to long.
Edit: Couldn't that Fraction to fix 8 routine be optimised like this.
Code: Select all
FractionToFix8: .MODULE FractionToFix8 add a, a ; [4] jr c, _overFlow ; [12/7] cp b ; [4] jr nc, _overFlow ; [12/7] sla c ; [8] jp nc, FractionToFix8 ; [10] ret ; [10] _overFlow: sub b ; [4] sll c ; [8] jp nc, FractionToFix8 ; [10] ret ; [10]
I have this thing stuck in my head where I think it's always better to use SUB instead of CP if you might need the result afterwards. This case is obviously an exception. Well spotted! I never even noticed it!
EDIT: Actually, on closer observation, it looks like you have just moved the SUB B after the first JR to a different location. I think the performance benefits would be dependant on the operands... perhaps a case of six of one, half a dozen of the other?
I think I'll just go back to my beer now...

EDIT (AGAIN!): Just checked out your source and you are right:
- the code is amazingly similar (especially the unrolled loop portion) and
- I think my routine will be faster on long lines and yours will be faster on short lines - it's the overhead of the gradiant calculation that kills my routine.