Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory consistency? #237

Open
Wuerfel21 opened this issue Mar 25, 2022 · 1 comment
Open

Memory consistency? #237

Wuerfel21 opened this issue Mar 25, 2022 · 1 comment

Comments

@Wuerfel21
Copy link
Contributor

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.

@totalspectrum
Copy link
Owner

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 :(.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants