FAQ  •  Register  •  Login

Another optimizer bug (*solved*)

<<

einar

Posts: 84

Joined: Sun Apr 08, 2012 9:33 pm

Post Tue Nov 04, 2014 1:47 am

Another optimizer bug (*solved*)

Ouch! This bug gave me a headache! It took me some time to figure out the reason my game was crashing...

Take a look at this sample:

  Code:
sub test()
    asm
        call    $fc12
        di
        ld      a, $fe
        ld      i, a
        im      2
        ei
    end asm
end sub

test()


Try compiling this sample above using:

  Code:
zxb.exe -A -O2 prog.bas


And it will produce the expected result:

  Code:
_test:
   push ix
   ld ix, 0
   add ix, sp
#line 1
      call    $fc12
      di
      ld      a, $fe
      ld      i, a
      im      2
      ei
#line 7
_test__leave:
   ld sp, ix
   pop ix
   ret


However try compiling it again using:

  Code:
zxb.exe -A -O3 prog.bas


Now the result won't make sense anymore:

  Code:
_test:
   push ix
   ld ix, 0
   add ix, sp
#line 1
   call    $fc12
   di
   im      2
   ei
#line 7
_test__leave:
   ld sp, ix
   pop ix
   ret


The problem is, the optimizer is supposed to try to optimize its own generated code only, not someone else's assembly code that it doesn't have enough information to understand!
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat Dec 27, 2014 2:15 pm

Re: Another optimizer bug

Try and download the new version ZX BASIC 1.4.0s1902.

It's true the compiler should not optimize user's asm code. But at the moment it's not implemented.
However, the bug was it was not taking into account neither the I register nor the IM instruction. So it was a bug anyway. ;)
Now your example works ok for me.

Can you try it, please??
<<

einar

Posts: 84

Joined: Sun Apr 08, 2012 9:33 pm

Post Sat Dec 27, 2014 4:43 pm

Re: Another optimizer bug

It works, thanks a lot!
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat Dec 27, 2014 6:17 pm

Re: Another optimizer bug

einar wrote:It works, thanks a lot!

You're welcome! :)
A trick to avoid the compiler to optimize your code is to encode the asm using DEFB, DEFW (the bytes) but it's a so hard task... :roll:

Return to Bug Reports

Who is online

Users browsing this forum: No registered users and 4 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO