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

0= need not be a primitive #8

Open
garysnyder opened this issue Mar 13, 2023 · 0 comments
Open

0= need not be a primitive #8

garysnyder opened this issue Mar 13, 2023 · 0 comments

Comments

@garysnyder
Copy link

We can derive 0= very early in a .f file.

Sweeping all the 1s in a number up ( dup 2* or ), repeatedly, sets bit 15 if non zero.

Since we can look at the stack, at any byte, half way between two 16 bit words, we can swap the upper and lower bytes. This moves bit 15 to bit 7 and bit 8 to bit 0. ( dup sp@ 1 + @ swap drop swap drop )

Shifting the result left by one ( 2* ) moves the original bit 15 to bit 8. Swapping again moves it to bit 0.
Mask only bit 0, invert and add 1 to make it a flag for 0<>
( 1 and invert 1 + )
invert again if you want 0=

It's much slower than a primitive, but saves a little .asm space.

Does that make 6 ?

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

1 participant