Re: A 6502 divide routine
Posted: Tue Jan 07, 2025 10:40 pm
The worst cases in the divide routine that I have presented occur, ironically enough, when the divisor is a power of two. And the worst of the worst occurs when the divisor is 1 and the dividend is 32767. This case requires almost 2000 cycles to produce the result. For this reason, it seems necessary to prefix the routine I have presented with a check looking for divide by 1. It may also be useful to check for the case of divide by (small) powers of 2.
What I dislike about the routine is the wide variability in execution speed and the excessively large cycle counts for certain "bad" inputs (divisor is a small power of 2). What I like about the routine is the conceptual simplicity of its operation and the very small cycle counts for certain "good" inputs (divisor > dividend is an example of "good" inputs)..
I hope to post an updated version later this week or early next week.
What I dislike about the routine is the wide variability in execution speed and the excessively large cycle counts for certain "bad" inputs (divisor is a small power of 2). What I like about the routine is the conceptual simplicity of its operation and the very small cycle counts for certain "good" inputs (divisor > dividend is an example of "good" inputs)..
I hope to post an updated version later this week or early next week.