The following warnings occurred:
Warning [2] Undefined array key 0 - Line: 1677 - File: showthread.php PHP 8.2.31 (Linux)
File Line Function
/inc/class_error.php 157 errorHandler->error
/showthread.php 1677 errorHandler->error_callback
/showthread.php 916 buildtree




Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tutorial: How to put inline assembly functions into ZX Basic
#14
britlion Wrote:
LCD Wrote:
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
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 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!
:oops:
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
Your original beginners function was not faster, it was in fact slower because multiplication and division is allways slower than bitshifting. I'm happy that boriel included it as it is a big help in optimizing programs, so you could use SHR and SHL in place of >> and <<. With this your code will match the ASM version much better, and work faster.
britlion Wrote:Anyway, I think my suggested optimized version is pretty tight:

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
It is!!!
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!
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)