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

repair fx-/wraparound with 0 first argument, allow one argument #899

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions csug/numeric.stex
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,11 @@ dividing \var{fixnum_1} by the product of the remaining arguments

%----------------------------------------------------------------------------
\entryheader
\formdef{fx+/wraparound}{\categoryprocedure}{(fx+/wraparound \var{fixnum} \dots)}
\formdef{fx-/wraparound}{\categoryprocedure}{(fx-/wraparound \var{fixnum} \dots)}
\formdef{fx*/wraparound}{\categoryprocedure}{(fx*/wraparound \var{fixnum} \dots)}
\formdef{fxsll/wraparound}{\categoryprocedure}{(fxsll/wraparound \var{fixnum} \dots)}
\formdef{fx+/wraparound}{\categoryprocedure}{(fx+/wraparound \var{fixnum} \var{fixnum})}
\formdef{fx-/wraparound}{\categoryprocedure}{(fx-/wraparound \var{fixnum} \var{fixnum})}
\formdef{fx-/wraparound}{\categoryprocedure}{(fx-/wraparound \var{fixnum})}
\formdef{fx*/wraparound}{\categoryprocedure}{(fx*/wraparound \var{fixnum} \var{fixnum})}
\formdef{fxsll/wraparound}{\categoryprocedure}{(fxsll/wraparound \var{fixnum} \var{fixnum})}
\returns the arithmetic result, wrapping on overflow
\listlibraries
\endentryheader
Expand Down
2 changes: 2 additions & 0 deletions mats/fx.ms
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,9 @@
(mat fx-/wraparound
(eqv? (fx-/wraparound 3 0) 3)
(eqv? (fx-/wraparound 3 1) 2)
(eqv? (fx-/wraparound 0 3) -3)
(eqv? (fx-/wraparound -3 4) -7)
(eqv? (fx-/wraparound 3) -3)
(error? (fx-/wraparound '(a . b) 0))
(error? (fx- (add1 (most-positive-fixnum)) 1))
(error? (fx- 1 (add1 (most-positive-fixnum))))
Expand Down
13 changes: 13 additions & 0 deletions release_notes/release_notes.stex
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ Online versions of both books can be found at
The type recovery pass has improved support for \scheme{abs} with a fixnum argument
and added support for \scheme{1+}, \scheme{1-}, and \scheme{-1+}.

\subsection{Single-argument \scheme{fx-/wraparound} (10.2.0)}

The \scheme{fx-/wraparound} function changed to accept a single
argument, which makes it more consistent with the R6RS \scheme{fx-}
function.

\subsection{Constrain signal delivery to the main thread (10.1.0)}

Signals are now always delivered to the main Scheme thread to avoid crashes when a signal
Expand Down Expand Up @@ -2769,6 +2775,13 @@ in fasl files does not generally make sense.
%-----------------------------------------------------------------------------
\section{Bug Fixes}\label{section:bugfixes}

\subsection{Fix \scheme{fx-/wraparound} with \scheme{0} first argument (10.2.0)}

When \scheme{fx-/wraparound} was called with \scheme{0} as its first
argument, the call could be rewritten to have a single argument, even though
\scheme{fx-/wraparound} required two arguments. As part of the repair,
\scheme{fx-/wraparound} changed to accept a single argument.

\subsection{Performance regression for \scheme{fxdiv-and-mod} at optimize-level 3 (10.2.0)}

At optimize-level 3, the source optimizer (cp0) could replace calls to
Expand Down
6 changes: 6 additions & 0 deletions s/cpprim.ss
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,7 @@
[(e) (%inline - (immediate 0) ,e)]
[(e1 e2) (%inline - ,e1 ,e2)])
(define-inline 3 fx-/wraparound
[(e) (%inline - (immediate 0) ,e)]
[(e1 e2) (%inline - ,e1 ,e2)])
(define-inline 3 fx1-
[(e) (%inline - ,e (immediate ,(fix 1)))])
Expand Down Expand Up @@ -1840,6 +1841,11 @@
[(e) (go src sexpr `(immediate ,(fix 0)) e)]
[(e1 e2) (go src sexpr e1 e2)])
(define-inline 2 fx-/wraparound
[(e)
(bind #t (e)
`(if ,(build-fixnums? (list e))
,(%inline - (immediate 0) ,e)
,(build-libcall #t src sexpr fx-/wraparound `(immediate 0) e)))]
[(e1 e2)
(bind #t (e1 e2)
`(if ,(build-fixnums? (list e1 e2))
Expand Down
7 changes: 5 additions & 2 deletions s/mathprims.ss
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,11 @@
(#2%fx+/wraparound x1 x2)))

(set-who! fx-/wraparound
(lambda (x1 x2)
(#2%fx-/wraparound x1 x2)))
(case-lambda
[(x)
(#2%fx-/wraparound x)]
[(x1 x2)
(#2%fx-/wraparound x1 x2)]))

(set! fx1-
(lambda (x)
Expand Down
2 changes: 1 addition & 1 deletion s/primdata.ss
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@
(fx+ [sig [(fixnum ...) -> (fixnum)]] [flags arith-op partial-folder]) ; not restricted to 2 arguments
(fx+/wraparound [sig [(fixnum fixnum) -> (fixnum)]] [flags arith-op partial-folder safeongoodargs])
(fx- [sig [(fixnum fixnum ...) -> (fixnum)]] [flags arith-op partial-folder]) ; not restricted to 1 or 2 arguments
(fx-/wraparound [sig [(fixnum fixnum) -> (fixnum)]] [flags arith-op partial-folder safeongoodargs])
(fx-/wraparound [sig [(fixnum) -> (fixnum)] [(fixnum fixnum) -> (fixnum)]] [flags arith-op partial-folder safeongoodargs])
(fx/ [sig [(fixnum fixnum ...) -> (fixnum)]] [flags arith-op partial-folder]) ; not restricted to 1 or 2 arguments
(fx1+ [sig [(fixnum) -> (fixnum)]] [flags arith-op cp02])
(fx1- [sig [(fixnum) -> (fixnum)]] [flags arith-op cp02])
Expand Down