-
Notifications
You must be signed in to change notification settings - Fork 1k
Add reductions for + in cptypes #959
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
Conversation
|
Two more questions: In a previous PR I added an implementation of Where is the best place to put this primitive? Is is better to keep the safe version or just assume it will be always call in unsafe mode as expected? I'm wondering if I have been too cautious with the
Is it possible to enable "rounding toward negative" in Chez Scheme? If not, the only way to get a |
|
On On rounding toward negative: I think probably not. R6RS certainly specifies rounding toward even for |
Reduce + with some combinations of values that are known at compile time to be real (+ <fx> <fx> ...) => ($fxx+ <fx> <fx> ...) (+ <fl> <fx> ...) => (fl+ <fl> (fixnum->flonum <fx>) ...) (+ <fl> <real> ...) => (fl+ <fl> (real->flonum <real>) ...) (+ <fl> <fl> ...) => (fl+ <fl> <fl>) with some special cases for 0, in particular (+ <fl> 1 ...) => (fl+ <fl> 1.0 ...) (+ <fl> 0 ...) => (fl+ <fl> -0.0 ...) (+ 1.0 0 ...) => (fl+ 1.0 0.0 ...)
|
A few minor changes, probably not worth reviewing until the final version. In particular a rebase because in a previous PR the internal representation of fixnums changed from A few days ago I asked in HN in case someone there realizes there is another example. Then sparkie@HN replied with an example in C that used Later, the reply explains how to use |
And small changes to the reductions of `abs` and `sub1` in cptypes
Reduce + with some combinations of values that are known at compile time to be real (- <fx> <fx> ...) => ($fxx- <fx> <fx> ...) (- <fl> <fx> ...) => (fl- <fl> (fixnum->flonum <fx>) ...) (- <fl> <real> ...) => (fl- <fl> (real->flonum <real>) ...) (- <fl> <fl> ...) => (fl- <fl> <fl>) with some special cases for 0, in particular (- <fl> 1 ...) => (fl- <fl> 1.0 ...) (- 1 <fl> ...) => (fl- 1.0 <fl> ...) (- <fl> 0 ...) => (fl- <fl> 0.0 ...) (- 0 <fl> ...) => (fl- -0.0 <fl> ...)
|
99% done. But I got a surprising error. add reductions for + in cptypes As discussed before. No changes since the intermediate update. Note that it avoids using Add $fxx- primitive Add the add reductions for - in cptypes Similar to the reduction for Bad fix changing a lot of - to fx- With the previous commit, it compiles finely in Linux and OSX but it breaks the 5 WinNT runs https://github.com/gus-massa/ChezScheme/actions/runs/16943355792 After looking for a while, the problem is that in Now I added some debugging info to the screen to show most of it. So it prints a few weird things until it reach the loop and prints It can be solved changing a few Also, after a successful compilation that change cna be reverted and the code compiles nicely, so I guess that upgrading the bootfiles is enough to fix it. I'm not sure that this fixes the problem or if my code has some very bad assumption. |
|
I do wonder whether it helps to rebuild pb boot files with |
|
I'm optimistic, so I removed [WIP] from the title. I updated the version. Is that ok? Some minor remarks:
are not reduced, in spite is constant folded to a bignum. I may try to fix this, but
that are reduced to but a smart enough compiler could be reduced to that avoids the overflow check, so it's slightly faster. The problem is that cptypes does not distinguish positive and negative fixnums. I'm adding this to my wish list. |
This version is working and reduces a lot of cases of
+, in particular to make(+ x 1)as fast as(add1 x)in some useful common cases. It can be merged after fixing some typos, but I wish to add a similar reduction for-to keep the balance of the universe.The main idea is that if
xis a flonum, then(#3%fl+ x 1.0)is 4 or 6 times faster than(+ x 1)even if we add some corner cases for0,0.0and-0.0. I found too many corner cases, so I wish to share this as an advanced draft to get feedback.I'll update this PR with a version for
-next week, probably, because I'm not sure how many unexpected corner case I'll find. (The version for*is quite different, I'll wait a few months until attempting it. And/has even more cases!)Reduce
+with some combinations of values that are known at compile time to be realwith some special cases for
0, in particularIn particular, I actually had to reduce
in case the first argument is
-0.0. (This case was pointed out by @mflatt.)I fount no version of
(fixnum->flonum <fx>)that return-0.0, and it looks like it's implemented using an assembler function with the same behavior, so the only solution was to use anif. The code tries to avoid adding this check when possible, in particular when the second argument is never0or the first argument is never-0.0.Also, some reductions apply only when the left associativity is enabled.