spin2cpp
                                
                                 spin2cpp copied to clipboard
                                
                                    spin2cpp copied to clipboard
                            
                            
                            
                        Memory consistency?
While looking through the optimizer, there's kinda been a question in the back of my mind: Is it ok if memory consistency isn't perfectly maintained? (ie. results don't match an unoptimized program due to memory-related optimization) It partially isn't as-is, but currently the optimizations to that extent are somewhat restricted (i.e. in most cases can't cross branches), though I can still get it to screw up:
CON
_CLKFREQ = 200_000_000
DEBUG_COGS = %01
VAR
long a,b,stack[100]
PUB main() | lock,x,y,z,p,q
p := @a
q := @b
lock := locknew()
x:=locktry(lock)
cogspin(NEWCOG,cog(lock),@stack)
lockrel(lock)
x := long[p]
debug("Just wasting some tiiiiiiiiiiiiimmmmmmmmmmmmeeeeeeeee...")
y := long[q]
z := long[p]
debug(sdec(x,y,z))
PRI cog(lock)
repeat until locktry(lock)
a := 1337
b := 11880
In C this sort of thing is explicitly ok (relatedly: do we even handle volatile right now?), idk about BASIC, but Spin may actually be written with the expectation of consistent memory in some cases.
Spin definitely expects memory consistency, and we probably should try to preserve it as much as possible. Which conflicts with the desire to optimize code that's using globals / member variables and stack offsets :(.