02-20-2012, 12:05 PM
britlion Wrote::oops:LCD Wrote:Though if I was going to, I'd say why bother with a new variable? :mrgreen:Code:function mirror(dowedoit as ubyte, number as ubyte) as ubyte
dim result as ubyte
if dowedoit then
result=(number&1)<<7|(number&2)<<5|(number&4)<<3|(number&8)<<1|(number&16)>>1|(number&32)>>3|(number&64)>>5|(number&128)>>7
Else
result=number
end if
return result
end Function
Code:function mirror(dowedoit as ubyte, number as ubyte) as ubyte
if dowedoit then
number=(number&1)<<7|(number&2)<<5|(number&4)<<3|(number&8)<<1|(number&16)>>1|(number&32)>>3|(number&64)>>5|(number&128)>>7
end if
return number
end Function
That said, if you read the behemoth assembly that makes. Ouch. Hopping on and off the stack like crazy! Not to mention a lot of very expensive reads and writes to (IX+7) - which cost 19 T states each. I wonder if my original beginners algorithm is faster!
I overseen it... It was my mirroring function from my unfinished fractal picture decompressor which I adopted to match yours, mine had no dowedoit, so it was:
Code:
function MirrorByte(num as ubyte) as ubyte
return (num&1)<<7|(num&2)<<5|(num&4)<<3|(num&8)<<1|(num&16)>>1|(num&32)>>3|(num&64)>>5|(num&128)>>7
end function
britlion Wrote:Anyway, I think my suggested optimized version is pretty tight:It is!!!
Code:function fastcall mirror (dowedoit as uByte, number as uByte) as uByte
asm
pop hl
pop bc
AND A
LD A,B
RET Z
ld b,8
ld c,a
XOR A
mirrorLoop:
RR C
RLA
DJNZ mirrorLoop
jp (hl)
end asm
END FUNCTION
Much faster than both compiled codes.
The books looks very good by the way!!! My compliments!
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!