spin2cpp
spin2cpp copied to clipboard
CORDIC optimizer bug
The following code:
PUB main(a) : x, y | b
asm
qexp a
neg b, a
qexp b
getqx x
getqx y
endasm
compiles to the following, which is missing the first qexp instruction and therefore produces incorrect results:
_main
neg _var01, arg01
qexp _var01
' asm
getqx result1
getqx result2
_main_ret
ret
I'm running the latest commit e37a63f51defd82a38811e20c0f7819ca76b9fc2, invoked as flexspin -O2 -2 -l
. The program I made this example from works correctly if I disable optimization with org
/end
but fails due to this bug with asm
/endasm
.
Not a bug IMO, code like this (i.e. cordic interleave tricks in non-volatile inline ASM) was never guaranteed to work to begin with (try using the function in a context where it becomes inlined and only one result is used - that will result in brap in any version) It just happened to work most of the time. The change that breaks this isn't an optimization, it's the fix for bug #223
I agree, not a bug, but it would be nice to have a warning in there. I think the optimizer should be able to see these kind of cases and suggest to the user that an "asm const" or something similar is required.
Yeah, that'd probably be good
Also, aren't we missing Spin syntax for volatile-but-not-cogexec flavour inline ASM?
Yes, Spin has no way to do volatile hubexec ASM. It'd be easy to add, but I don't know what the syntax should be. Any suggestions?
ORGH is used now for volatile but not cogexec inline ASM. Still need to look at a warning for CORDIC optimizations though.