0 Members and 1 Guest are viewing this topic.

Signed division by any nontrivial constant, other than 2, including negative numbers?Modulus with any constant that is not a power of 2?

Those multiplications by 128 won't work. Multiplying 256*128 would give 0.

xor a ; resets carry and register rr h rr l ; divide hl by 2 rra ld h,l ld l,a ; multiply hl by 256 (moving low byte to high byte trick);8 bytes, 32 clocks;conventional way is 7 bytes and 77 clocks;it does in less than half the time with only 1 byte cost, substantial speed increase with only 1 byte cost

Axe Parser could improve with a option to make it optimize for speed instead of the size default.

Quote from: Galandros on April 30, 2010, 02:23:29 pmAxe Parser could improve with a option to make it optimize for speed instead of the size default.Yeah, I'm planning to do that eventually.Actually, I found out my optimized signed division by 2 doesn't work, so that's up in the air too now. Also, would multiplying by negative 2 be do-able in 6 bytes? It can certainly be done in 7 so it seems possible maybe using some trick?EDIT: also, is the daa instruction ever useful for optimizations? I can't think of how I would use it other than floating point math.

And I have only found daa useful (other than its intended use) when converting between hex digits and ASCII, I think.

Signed division by 2 is just sra h \ rr l.

Quote from: calc84maniac on April 30, 2010, 03:51:56 pmSigned division by 2 is just sra h \ rr l.But what about -1/2? Shouldn't that give 0? Because if you do that operation to %11111111 11111111 it remains -1. Or does this routine always round up in magnitude instead of down? It might throw some people off since it would be inconsistent with my regular unoptimized signed division routine.

;Divides HL by DE and stores to HLSDiv: ld a,h add a,a jr nc,$+9 xor a sub l ld l,a sbc a,a sub h ld h,a scf rra xor d push af bit 7,d jr z,$+8 xor a sub e ld e,a sbc a,a sub d ld d,a call Divide pop af add a,a ret nc xor a sub l ld l,a sbc a,a sub h ld h,a ret