JIT support for inexact->exact', add unsafe-fl->fx', etc.

This commit is contained in:
Matthew Flatt 2010-06-28 14:58:34 -06:00
parent c320d63f01
commit 47c7c1a27b
16 changed files with 245 additions and 74 deletions

View File

@ -1,7 +1,7 @@
#lang scheme/base
(require '#%flfxnum)
(provide fx->fl
(provide fx->fl fl->fx
fxabs
fx+ fx- fx*
fxquotient fxremainder fxmodulo

View File

@ -6,6 +6,6 @@
flsin flcos fltan flasin flacos flatan
flfloor flceiling flround fltruncate
fl= fl< fl<= fl> fl>= flmin flmax
->fl
->fl fl->exact-integer
flvector? flvector make-flvector
flvector-length flvector-ref flvector-set!)

View File

@ -1012,10 +1012,19 @@ the range @racket[-1.0] to @racket[1.0] is given to @racket[flasin] or
@racket[flacos], or when a negative number is given to @racket[fllog]
or @racket[flsqrt].}
@defproc[(->fl [a exact-integer?]) inexact-real?]{
Like @racket[exact->inexact], but constrained to consume exact integers,
so the result is always a @tech{flonum}.
}
Like @racket[exact->inexact], but constrained to consume exact
integers, so the result is always a @tech{flonum}.}
@defproc[(fl->exact-integer [a inexact-real?]) exact-integer?]{
Like @racket[inexact->exact], but constrained to consume an
@tech{integer} @tech{flonum}, so the result is always an exact
integer.}
@subsection{Flonum Vectors}
@ -1142,6 +1151,12 @@ Safe versions of @racket[unsafe-fx=], @racket[unsafe-fx<],
@racket[unsafe-fx>], @racket[unsafe-fx<=], @racket[unsafe-fx>=],
@racket[unsafe-fxmin], and @racket[unsafe-fxmax].}
@deftogether[(
@defproc[(fx->fl [a fixnum?]) inexact-real?]
@defproc[(fl->fx [a inexact-real?]) fixnum?]
)]{
Safe versions of @racket[unsafe-fx->fl] and @racket[unsafe-fl->fx].}
@; ------------------------------------------------------------------------

View File

@ -90,11 +90,6 @@ For @tech{fixnums}: Like @scheme[=], @scheme[<], @scheme[>],
constrained to consume @tech{fixnums}.}
@defproc[(unsafe-fx->fl [a fixnum?]) inexact-real?]{
Unchecked version of @scheme[->fl].
}
@deftogether[(
@defproc[(unsafe-fl+ [a inexact-real?] [b inexact-real?]) inexact-real?]
@defproc[(unsafe-fl- [a inexact-real?] [b inexact-real?]) inexact-real?]
@ -153,6 +148,15 @@ For @tech{flonums}: Unchecked (potentially) versions of
@scheme[flsqrt]. Currently, some of these bindings are simply aliases
for the corresponding safe bindings.}
@deftogether[(
@defproc[(unsafe-fx->fl [a fixnum?]) inexact-real?]
@defproc[(unsafe-fl->fx [a inexact-real?]) fixnum?]
)]{
Unchecked conversion of a fixnum to an integer flonum and vice versa.
These are similar to the safe bindings @scheme[->fl] and @scheme[fl->exact-integer],
but further constrained to consume or produce a fixnum.
}
@section{Unsafe Data Extraction}

View File

@ -7,7 +7,9 @@
(define unary-table
(list (list fxnot unsafe-fxnot)
(list fxabs unsafe-fxabs)
(list fx->fl unsafe-fx->fl)))
(list fx->fl unsafe-fx->fl)
(list (lambda (v) (fl->fx (exact->inexact x)))
(lambda (v) (unsafe-fl->fx (exact->inexact x))))))
(define binary-table
(list (list fx+ unsafe-fx+)

View File

@ -337,6 +337,12 @@
(un-exact 10.0 '->fl 10)
(un-exact 10.0 'fx->fl 10)
(un-exact 11 'fl->exact-integer 11.0)
(un-exact -1 'fl->exact-integer -1.0)
(un-exact (inexact->exact 5e200) 'fl->exact-integer 5e200)
(un-exact 11 'fl->fx 11.0)
(un-exact -11 'fl->fx -11.0)
(bin 11 '+ 4 7)
(bin -3 '+ 4 -7)
(bin (expt 2 30) '+ (expt 2 29) (expt 2 29))

View File

@ -172,6 +172,9 @@
(test-un 8.0 'unsafe-fx->fl 8)
(test-un -8.0 'unsafe-fx->fl -8)
(test-un 8 'unsafe-fl->fx 8.0)
(test-un -8 'unsafe-fl->fx -8.0)
(test-bin 3.7 'unsafe-flmin 3.7 4.1)
(test-bin 2.1 'unsafe-flmin 3.7 2.1)
(test-bin +nan.0 'unsafe-flmin +nan.0 2.1)

View File

@ -1,44 +1,44 @@
{
SHARED_OK static MZCOMPILED_STRING_FAR unsigned char expr[] = {35,126,7,53,46,48,46,48,46,49,51,0,0,0,1,0,0,10,0,13,0,
22,0,26,0,33,0,36,0,41,0,48,0,61,0,66,0,71,0,78,0,82,
SHARED_OK static MZCOMPILED_STRING_FAR unsigned char expr[] = {35,126,7,53,46,48,46,48,46,50,51,0,0,0,1,0,0,10,0,13,0,
22,0,29,0,32,0,36,0,41,0,45,0,52,0,57,0,64,0,77,0,82,
0,88,0,102,0,116,0,119,0,125,0,129,0,131,0,142,0,144,0,158,0,
165,0,187,0,189,0,203,0,14,1,43,1,54,1,65,1,75,1,111,1,144,
1,177,1,236,1,46,2,124,2,190,2,195,2,215,2,106,3,126,3,177,3,
243,3,128,4,14,5,66,5,89,5,168,5,0,0,109,7,0,0,69,35,37,
109,105,110,45,115,116,120,29,11,11,68,104,101,114,101,45,115,116,120,63,108,
101,116,66,100,101,102,105,110,101,62,111,114,64,108,101,116,42,66,117,110,108,
101,115,115,72,112,97,114,97,109,101,116,101,114,105,122,101,64,99,111,110,100,
64,119,104,101,110,66,108,101,116,114,101,99,63,97,110,100,65,113,117,111,116,
109,105,110,45,115,116,120,29,11,11,68,104,101,114,101,45,115,116,120,66,108,
101,116,114,101,99,62,111,114,63,97,110,100,64,108,101,116,42,63,108,101,116,
66,117,110,108,101,115,115,64,119,104,101,110,66,100,101,102,105,110,101,72,112,
97,114,97,109,101,116,101,114,105,122,101,64,99,111,110,100,65,113,117,111,116,
101,29,94,2,14,68,35,37,107,101,114,110,101,108,11,29,94,2,14,68,35,
37,112,97,114,97,109,122,11,62,105,102,65,98,101,103,105,110,63,115,116,120,
61,115,70,108,101,116,45,118,97,108,117,101,115,61,120,73,108,101,116,114,101,
99,45,118,97,108,117,101,115,66,108,97,109,98,100,97,1,20,112,97,114,97,
109,101,116,101,114,105,122,97,116,105,111,110,45,107,101,121,61,118,73,100,101,
102,105,110,101,45,118,97,108,117,101,115,97,36,11,8,240,128,81,0,0,95,
159,2,16,36,36,159,2,15,36,36,159,2,15,36,36,16,20,2,4,2,2,
2,5,2,2,2,12,2,2,2,6,2,2,2,7,2,2,2,8,2,2,2,
9,2,2,2,10,2,2,2,11,2,2,2,13,2,2,97,37,11,8,240,128,
81,0,0,93,159,2,15,36,37,16,2,2,3,161,2,2,37,2,3,2,2,
2,3,96,38,11,8,240,128,81,0,0,16,0,96,11,11,8,240,128,81,0,
102,105,110,101,45,118,97,108,117,101,115,97,36,11,8,240,139,80,0,0,95,
159,2,16,36,36,159,2,15,36,36,159,2,15,36,36,16,20,2,5,2,2,
2,6,2,2,2,4,2,2,2,8,2,2,2,7,2,2,2,9,2,2,2,
10,2,2,2,11,2,2,2,12,2,2,2,13,2,2,97,37,11,8,240,139,
80,0,0,93,159,2,15,36,37,16,2,2,3,161,2,2,37,2,3,2,2,
2,3,96,38,11,8,240,139,80,0,0,16,0,96,11,11,8,240,139,80,0,
0,16,0,13,16,4,36,29,11,11,2,2,11,18,16,2,99,64,104,101,114,
101,8,32,8,31,8,30,8,29,8,28,93,8,224,135,81,0,0,95,9,8,
224,135,81,0,0,2,2,27,248,22,147,4,195,249,22,140,4,80,158,39,36,
101,8,32,8,31,8,30,8,29,8,28,93,8,224,146,80,0,0,95,9,8,
224,146,80,0,0,2,2,27,248,22,147,4,195,249,22,140,4,80,158,39,36,
251,22,81,2,17,248,22,96,199,12,249,22,71,2,18,248,22,98,201,27,248,
22,147,4,195,249,22,140,4,80,158,39,36,251,22,81,2,17,248,22,96,199,
249,22,71,2,18,248,22,98,201,12,27,248,22,73,248,22,147,4,196,28,248,
22,79,193,20,15,159,37,36,37,28,248,22,79,248,22,73,194,248,22,72,193,
249,22,140,4,80,158,39,36,251,22,81,2,17,248,22,72,199,249,22,71,2,
13,248,22,73,201,11,18,16,2,101,10,8,32,8,31,8,30,8,29,8,28,
16,4,11,11,2,19,3,1,8,101,110,118,49,50,56,50,48,16,4,11,11,
2,20,3,1,8,101,110,118,49,50,56,50,49,93,8,224,136,81,0,0,95,
9,8,224,136,81,0,0,2,2,27,248,22,73,248,22,147,4,196,28,248,22,
6,248,22,73,201,11,18,16,2,101,10,8,32,8,31,8,30,8,29,8,28,
16,4,11,11,2,19,3,1,8,101,110,118,49,50,52,54,57,16,4,11,11,
2,20,3,1,8,101,110,118,49,50,52,55,48,93,8,224,147,80,0,0,95,
9,8,224,147,80,0,0,2,2,27,248,22,73,248,22,147,4,196,28,248,22,
79,193,20,15,159,37,36,37,28,248,22,79,248,22,73,194,248,22,72,193,249,
22,140,4,80,158,39,36,250,22,81,2,21,248,22,81,249,22,81,248,22,81,
2,22,248,22,72,201,251,22,81,2,17,2,22,2,22,249,22,71,2,6,248,
2,22,248,22,72,201,251,22,81,2,17,2,22,2,22,249,22,71,2,5,248,
22,73,204,18,16,2,101,11,8,32,8,31,8,30,8,29,8,28,16,4,11,
11,2,19,3,1,8,101,110,118,49,50,56,50,51,16,4,11,11,2,20,3,
1,8,101,110,118,49,50,56,50,52,93,8,224,137,81,0,0,95,9,8,224,
137,81,0,0,2,2,248,22,147,4,193,27,248,22,147,4,194,249,22,71,248,
11,2,19,3,1,8,101,110,118,49,50,52,55,50,16,4,11,11,2,20,3,
1,8,101,110,118,49,50,52,55,51,93,8,224,148,80,0,0,95,9,8,224,
148,80,0,0,2,2,248,22,147,4,193,27,248,22,147,4,194,249,22,71,248,
22,81,248,22,72,196,248,22,73,195,27,248,22,73,248,22,147,4,23,197,1,
249,22,140,4,80,158,39,36,28,248,22,56,248,22,141,4,248,22,72,23,198,
2,27,249,22,2,32,0,89,162,8,44,37,43,9,222,33,40,248,22,147,4,
@ -52,7 +52,7 @@
37,47,9,222,33,43,248,22,147,4,248,22,72,201,248,22,73,198,27,248,22,
73,248,22,147,4,196,27,248,22,147,4,248,22,72,195,249,22,140,4,80,158,
40,36,28,248,22,79,195,250,22,82,2,21,9,248,22,73,199,250,22,81,2,
4,248,22,81,248,22,72,199,250,22,82,2,7,248,22,73,201,248,22,73,202,
8,248,22,81,248,22,72,199,250,22,82,2,7,248,22,73,201,248,22,73,202,
27,248,22,73,248,22,147,4,23,197,1,27,249,22,1,22,85,249,22,2,22,
147,4,248,22,147,4,248,22,72,199,249,22,140,4,80,158,40,36,251,22,81,
1,22,119,105,116,104,45,99,111,110,116,105,110,117,97,116,105,111,110,45,109,
@ -63,13 +63,13 @@
147,4,196,28,248,22,79,193,20,15,159,37,36,37,249,22,140,4,80,158,39,
36,27,248,22,147,4,248,22,72,197,28,249,22,182,8,62,61,62,248,22,141,
4,248,22,96,196,250,22,81,2,21,248,22,81,249,22,81,21,93,2,26,248,
22,72,199,250,22,82,2,10,249,22,81,2,26,249,22,81,248,22,105,203,2,
22,72,199,250,22,82,2,13,249,22,81,2,26,249,22,81,248,22,105,203,2,
26,248,22,73,202,251,22,81,2,17,28,249,22,182,8,248,22,141,4,248,22,
72,200,64,101,108,115,101,10,248,22,72,197,250,22,82,2,21,9,248,22,73,
200,249,22,71,2,10,248,22,73,202,100,8,32,8,31,8,30,8,29,8,28,
16,4,11,11,2,19,3,1,8,101,110,118,49,50,56,52,54,16,4,11,11,
2,20,3,1,8,101,110,118,49,50,56,52,55,93,8,224,138,81,0,0,18,
16,2,158,94,10,64,118,111,105,100,8,48,95,9,8,224,138,81,0,0,2,
200,249,22,71,2,13,248,22,73,202,100,8,32,8,31,8,30,8,29,8,28,
16,4,11,11,2,19,3,1,8,101,110,118,49,50,52,57,53,16,4,11,11,
2,20,3,1,8,101,110,118,49,50,52,57,54,93,8,224,149,80,0,0,18,
16,2,158,94,10,64,118,111,105,100,8,48,95,9,8,224,149,80,0,0,2,
2,27,248,22,73,248,22,147,4,196,249,22,140,4,80,158,39,36,28,248,22,
56,248,22,141,4,248,22,72,197,250,22,81,2,27,248,22,81,248,22,72,199,
248,22,96,198,27,248,22,141,4,248,22,72,197,250,22,81,2,27,248,22,81,
@ -81,25 +81,25 @@
11,11,11,11,16,10,2,4,2,5,2,6,2,7,2,8,2,9,2,10,2,
11,2,12,2,13,36,46,37,11,11,11,16,0,16,0,16,0,36,36,11,11,
11,11,16,0,16,0,16,0,36,36,16,11,16,5,2,3,20,15,159,36,36,
36,36,20,105,159,36,16,0,16,1,33,33,10,16,5,2,8,89,162,8,44,
36,36,20,105,159,36,16,0,16,1,33,33,10,16,5,2,9,89,162,8,44,
37,53,9,223,0,33,34,36,20,105,159,36,16,1,2,3,16,0,11,16,5,
2,11,89,162,8,44,37,53,9,223,0,33,35,36,20,105,159,36,16,1,2,
3,16,0,11,16,5,2,13,89,162,8,44,37,53,9,223,0,33,36,36,20,
105,159,36,16,1,2,3,16,1,33,37,11,16,5,2,6,89,162,8,44,37,
2,10,89,162,8,44,37,53,9,223,0,33,35,36,20,105,159,36,16,1,2,
3,16,0,11,16,5,2,6,89,162,8,44,37,53,9,223,0,33,36,36,20,
105,159,36,16,1,2,3,16,1,33,37,11,16,5,2,5,89,162,8,44,37,
56,9,223,0,33,38,36,20,105,159,36,16,1,2,3,16,1,33,39,11,16,
5,2,4,89,162,8,44,37,58,9,223,0,33,42,36,20,105,159,36,16,1,
2,3,16,0,11,16,5,2,12,89,162,8,44,37,53,9,223,0,33,44,36,
5,2,8,89,162,8,44,37,58,9,223,0,33,42,36,20,105,159,36,16,1,
2,3,16,0,11,16,5,2,4,89,162,8,44,37,53,9,223,0,33,44,36,
20,105,159,36,16,1,2,3,16,0,11,16,5,2,7,89,162,8,44,37,54,
9,223,0,33,45,36,20,105,159,36,16,1,2,3,16,0,11,16,5,2,9,
9,223,0,33,45,36,20,105,159,36,16,1,2,3,16,0,11,16,5,2,12,
89,162,8,44,37,55,9,223,0,33,46,36,20,105,159,36,16,1,2,3,16,
0,11,16,5,2,10,89,162,8,44,37,58,9,223,0,33,47,36,20,105,159,
36,16,1,2,3,16,1,33,49,11,16,5,2,5,89,162,8,44,37,54,9,
0,11,16,5,2,13,89,162,8,44,37,58,9,223,0,33,47,36,20,105,159,
36,16,1,2,3,16,1,33,49,11,16,5,2,11,89,162,8,44,37,54,9,
223,0,33,50,36,20,105,159,36,16,1,2,3,16,0,11,16,0,94,2,15,
2,16,93,2,15,9,9,36,0};
EVAL_ONE_SIZED_STR((char *)expr, 2024);
}
{
SHARED_OK static MZCOMPILED_STRING_FAR unsigned char expr[] = {35,126,7,53,46,48,46,48,46,49,65,0,0,0,1,0,0,8,0,21,0,
SHARED_OK static MZCOMPILED_STRING_FAR unsigned char expr[] = {35,126,7,53,46,48,46,48,46,50,65,0,0,0,1,0,0,8,0,21,0,
26,0,43,0,58,0,76,0,92,0,102,0,120,0,140,0,156,0,174,0,205,
0,234,0,0,1,14,1,20,1,34,1,39,1,49,1,57,1,85,1,117,1,
123,1,168,1,213,1,237,1,20,2,22,2,188,2,22,4,63,4,136,5,222,
@ -400,13 +400,13 @@
EVAL_ONE_SIZED_STR((char *)expr, 6245);
}
{
SHARED_OK static MZCOMPILED_STRING_FAR unsigned char expr[] = {35,126,7,53,46,48,46,48,46,49,9,0,0,0,1,0,0,10,0,16,0,
SHARED_OK static MZCOMPILED_STRING_FAR unsigned char expr[] = {35,126,7,53,46,48,46,48,46,50,9,0,0,0,1,0,0,10,0,16,0,
29,0,44,0,58,0,72,0,86,0,128,0,0,0,57,1,0,0,69,35,37,
98,117,105,108,116,105,110,65,113,117,111,116,101,29,94,2,2,67,35,37,117,
116,105,108,115,11,29,94,2,2,69,35,37,110,101,116,119,111,114,107,11,29,
94,2,2,68,35,37,112,97,114,97,109,122,11,29,94,2,2,68,35,37,101,
120,112,111,98,115,11,29,94,2,2,68,35,37,107,101,114,110,101,108,11,97,
36,11,8,240,6,82,0,0,98,159,2,3,36,36,159,2,4,36,36,159,2,
36,11,8,240,17,81,0,0,98,159,2,3,36,36,159,2,4,36,36,159,2,
5,36,36,159,2,6,36,36,159,2,7,36,36,159,2,7,36,36,16,0,159,
36,20,105,159,36,16,1,11,16,0,83,158,42,20,103,145,2,1,2,1,29,
11,11,11,11,11,18,96,11,44,44,44,36,80,158,36,36,20,105,159,36,16,
@ -420,7 +420,7 @@
EVAL_ONE_SIZED_STR((char *)expr, 352);
}
{
SHARED_OK static MZCOMPILED_STRING_FAR unsigned char expr[] = {35,126,7,53,46,48,46,48,46,49,74,0,0,0,1,0,0,7,0,18,0,
SHARED_OK static MZCOMPILED_STRING_FAR unsigned char expr[] = {35,126,7,53,46,48,46,48,46,50,74,0,0,0,1,0,0,7,0,18,0,
45,0,51,0,64,0,73,0,80,0,102,0,124,0,150,0,162,0,180,0,200,
0,212,0,228,0,251,0,7,1,38,1,45,1,50,1,55,1,60,1,65,1,
70,1,79,1,84,1,88,1,94,1,101,1,107,1,115,1,124,1,145,1,166,

View File

@ -2994,6 +2994,7 @@ int scheme_wants_flonum_arguments(Scheme_Object *rator, int argpos, int rotate_m
|| IS_NAMED_PRIM(rator, "unsafe-fl>=")
|| IS_NAMED_PRIM(rator, "unsafe-flmin")
|| IS_NAMED_PRIM(rator, "unsafe-flmax")
|| (!rotate_mode && IS_NAMED_PRIM(rator, "unsafe-fl->fx"))
|| (rotate_mode && IS_NAMED_PRIM(rator, "unsafe-flvector-ref"))
|| (rotate_mode && IS_NAMED_PRIM(rator, "unsafe-fx->fl")))
return 1;

View File

@ -4255,7 +4255,7 @@ static int can_unbox_inline(Scheme_Object *obj, int fuel, int regs, int unsafely
&& (IS_NAMED_PRIM(app->rator, "unsafe-f64vector-ref")
|| IS_NAMED_PRIM(app->rator, "unsafe-flvector-ref"))) {
if (is_unboxing_immediate(app->rand1, 1)
&& is_unboxing_immediate(app->rand1, 2)) {
&& is_unboxing_immediate(app->rand2, 1)) {
return 1;
}
}
@ -4326,7 +4326,7 @@ static jit_insn *generate_arith_slow_path(mz_jit_state *jitter, Scheme_Object *r
Branch_Info *for_branch,
int orig_args, int reversed, int arith, int use_v, int v)
/* *_ref4 is place to set for where to jump (for true case, if for_branch) after completing;
*_ref is place to set for where to jump for false if for_branch;
*_ref is place to set for where to jump for false if for_branch, result if !for_branch;
result is place to jump to start slow path if fixnum attempt fails */
{
jit_insn *ref, *ref4, *refslow;
@ -4409,7 +4409,8 @@ static int can_fast_double(int arith, int cmp, int two_args)
|| (arith == 11)
|| (arith == 12)
|| (arith == 13)
|| (arith == 14))
|| (arith == 14)
|| (arith == 15))
return 1;
#endif
#ifdef INLINE_FP_COMP
@ -4461,7 +4462,9 @@ static int can_fast_double(int arith, int cmp, int two_args)
#define jit_beqr_d_fppop(d, s1, s2) jit_beqr_d(d, s1, s2)
#define jit_bantieqr_d_fppop(d, s1, s2) jit_bantieqr_d(d, s1, s2)
#define jit_extr_l_d_fppush(rd, rs) jit_extr_l_d(rd, rs)
#define jit_roundr_d_l_fppop(rd, rs) jit_roundr_d_l(rd, rs)
#define jit_movr_d_rel(rd, rs) jit_movr_d(rd, rs)
#define jit_movr_d_fppush(rd, rs) jit_movr_d(rd, rs)
#define R0_FP_ADJUST(x) /* empty */
#else
#define R0_FP_ADJUST(x) x
@ -4535,7 +4538,7 @@ static int generate_double_arith(mz_jit_state *jitter, Scheme_Object *rator,
and second is in JIT_FPR1+depth (which is backward). */
{
#if defined(INLINE_FP_OPS) || defined(INLINE_FP_COMP)
GC_CAN_IGNORE jit_insn *ref8, *ref9, *ref10, *refd, *refdt;
GC_CAN_IGNORE jit_insn *ref8, *ref9, *ref10, *refd, *refdt, *refs = NULL, *refs2 = NULL;
int no_alloc = unboxed_result, need_post_pop = 0;
if (!unsafe_fl) {
@ -4584,6 +4587,8 @@ static int generate_double_arith(mz_jit_state *jitter, Scheme_Object *rator,
/* flround, flsin, etc. needs no extra number */
} else if (arith == 12) {
/* exact->inexact needs no extra number */
} else if (arith == 15) {
/* inexact->exact needs no extra number */
} else {
double d = second_const;
mz_movi_d_fppush(fpr1, d, JIT_R2);
@ -4672,6 +4677,33 @@ static int generate_double_arith(mz_jit_state *jitter, Scheme_Object *rator,
jit_abs_d_fppop(fpr0, fpr0);
break;
case 12: /* exact->inexact */
/* no work to do, because argument is already inexact;
no need to allocate, because argument is never unboxed,
and it therefore already resides in R0 */
no_alloc = 1;
break;
case 15: /* inexact->exact */
if (!unsafe_fl) {
jit_movr_d_fppush(fpr1, fpr0);
}
jit_roundr_d_l_fppop(JIT_R1, fpr0);
if (!unsafe_fl) {
/* to check whether it fits in a fixnum, we
need to convert back and check whether it
is the same */
jit_extr_l_d_fppush(fpr0, JIT_R1);
__START_TINY_JUMPS__(1);
refs = jit_bantieqr_d_fppop(jit_forward(), fpr0, fpr1);
__END_TINY_JUMPS__(1);
/* result still may not fit in a fixnum */
jit_lshi_l(JIT_R2, JIT_R1, 1);
jit_rshi_l(JIT_R2, JIT_R2, 1);
__START_TINY_JUMPS__(1);
refs2 = jit_bner_l(jit_forward(), JIT_R1, JIT_R2);
__END_TINY_JUMPS__(1);
}
jit_lshi_l(JIT_R0, JIT_R1, 1);
jit_ori_l(JIT_R0, JIT_R0, 0x1);
no_alloc = 1;
break;
case 13: /* sqrt */
@ -4786,13 +4818,18 @@ static int generate_double_arith(mz_jit_state *jitter, Scheme_Object *rator,
}
if (!unsafe_fl) {
/* No, they're not both doubles. */
/* No, they're not both doubles, or slow path is needed
for some other reason. */
__START_TINY_JUMPS__(1);
if (two_args) {
mz_patch_branch(ref8);
mz_patch_branch(ref10);
}
mz_patch_branch(ref9);
if (refs)
mz_patch_branch(refs);
if (refs2)
mz_patch_branch(refs2);
__END_TINY_JUMPS__(1);
}
#endif
@ -4874,6 +4911,7 @@ static int generate_arith(mz_jit_state *jitter, Scheme_Object *rator, Scheme_Obj
arith = 12 -> exact->inexact
arith = 13 -> sqrt
arith = 14 -> unary floating-point op (consult `rator')
arith = 15 -> inexact->exact
cmp = 0 -> = or zero?
cmp = +/-1 -> >=/<=
cmp = +/-2 -> >/< or positive/negative?
@ -4886,7 +4924,8 @@ static int generate_arith(mz_jit_state *jitter, Scheme_Object *rator, Scheme_Obj
For unsafe_fx or unsafe_fl, -1 means safe but specific to the type.
*/
{
GC_CAN_IGNORE jit_insn *ref, *ref2, *ref3, *ref4, *refd = NULL, *refdt = NULL, *refslow;
GC_CAN_IGNORE jit_insn *ref, *ref2, *ref3, *ref4, *refd = NULL, *refdt = NULL;
GC_CAN_IGNORE jit_insn *refslow;
int skipped, simple_rand, simple_rand2, reversed = 0;
int has_fixnum_fast = 1, has_flonum_fast = 1;
int inlined_flonum1, inlined_flonum2;
@ -4923,7 +4962,8 @@ static int generate_arith(mz_jit_state *jitter, Scheme_Object *rator, Scheme_Obj
int args_unboxed = (((arith != 9) && (arith != 10)) || rand);
int flonum_depth, fl_reversed = 0, can_direct1, can_direct2;
if (inlined_flonum1 && inlined_flonum2) /* safe can be implemented as unsafe */
if (inlined_flonum1 && inlined_flonum2 && (arith != 15))
/* safe can be implemented as unsafe */
unsafe_fl = 1;
if (!args_unboxed && rand)
@ -5035,13 +5075,24 @@ static int generate_arith(mz_jit_state *jitter, Scheme_Object *rator, Scheme_Obj
mz_rs_sync(); /* needed if arguments were unboxed */
generate_double_arith(jitter, rator, arith, cmp, reversed, !!rand2, 0,
&refd, &refdt, for_branch, branch_short, 1,
&refd, &refdt, for_branch, branch_short,
(arith == 15) ? (unsafe_fl > 0) : 1,
args_unboxed, jitter->unbox);
CHECK_LIMIT();
ref3 = NULL;
ref = NULL;
ref4 = NULL;
if ((arith == 15) && (unsafe_fl < 1)) {
/* need a slow path */
generate_arith_slow_path(jitter, rator, &ref, &ref4, for_branch, orig_args, reversed, arith, 0, 0);
/* assert: !ref4, since not for_branch */
jit_patch_movi(ref, (_jit.x.pc));
__START_SHORT_JUMPS__(branch_short);
mz_patch_ucbranch(refdt);
__END_SHORT_JUMPS__(branch_short);
}
__START_SHORT_JUMPS__(branch_short);
} else {
int unbox = jitter->unbox;
@ -5676,6 +5727,9 @@ static int generate_arith(mz_jit_state *jitter, Scheme_Object *rator, Scheme_Obj
jitter->unbox_depth++;
}
CHECK_LIMIT();
} else if (arith == 15) {
/* inexact->exact */
/* no work to do, since fixnum is already exact */
}
}
}
@ -6841,6 +6895,16 @@ static int generate_inlined_unary(mz_jit_state *jitter, Scheme_App2_Rec *app, in
|| IS_NAMED_PRIM(rator, "fx->fl")) {
generate_arith(jitter, rator, app->rand, NULL, 1, 12, 0, 0, NULL, 1, -1, 0, NULL);
return 1;
} else if (IS_NAMED_PRIM(rator, "inexact->exact")) {
generate_arith(jitter, rator, app->rand, NULL, 1, 15, 0, 0, NULL, 1, 0, 0, NULL);
return 1;
} else if (IS_NAMED_PRIM(rator, "unsafe-fl->fx")) {
generate_arith(jitter, rator, app->rand, NULL, 1, 15, 0, 0, NULL, 1, 0, 1, NULL);
return 1;
} else if (IS_NAMED_PRIM(rator, "fl->exact-integer")
|| IS_NAMED_PRIM(rator, "fl->fx")) {
generate_arith(jitter, rator, app->rand, NULL, 1, 15, 0, 0, NULL, 1, 0, -1, NULL);
return 1;
} else if (IS_NAMED_PRIM(rator, "bitwise-not")) {
generate_arith(jitter, rator, app->rand, NULL, 1, 7, 0, 9, NULL, 1, 0, 0, NULL);
return 1;

View File

@ -1164,7 +1164,11 @@ typedef _uc jit_insn;
#define FLDTm(D,B,I,S) ESCmi(D,B,I,S,035) /* fld m80real */
#define FILDQm(D,B,I,S) ESCmi(D,B,I,S,075) /* fild m64int */
#define FSTPTm(D,B,I,S) ESCmi(D,B,I,S,037) /* fstp m80real */
#define FISTPQm(D,B,I,S) ESCmi(D,B,I,S,077) /* fistp m64int */
#ifdef JIT_X86_64
# define FISTPQm(D,B,I,S) ESCmi(D,B,I,S,077) /* fistp m64int */
#else
# define FISTPQm(D,B,I,S) FISTPLm(D,B,I,S)
#endif
#define FADDrr(RS,RD) ESCrri(RS,RD,000)
#define FMULrr(RS,RD) ESCrri(RS,RD,001)

View File

@ -105,6 +105,7 @@
: (FLDr ((s1)), FSTPr ((rd)+1)))
#define jit_movr_d_rel(rd,s1) ((rd < s1) ? (FSTPr(0), FLDr(0)) : (FSTr(1)))
#define jit_movr_d_fppush(rd,s1) (FLDr(s1))
/* - loads:
@ -308,6 +309,15 @@ union jit_double_imm {
(PUSHLr(_EAX), \
jit_fxch ((rs), FISTPLm(0, _ESP, 0, 0)), \
POPLr((rd)))
#define jit_roundr_d_l(rd, rs) \
(PUSHQr(_EAX), \
jit_fxch ((rs), FISTPQm(0, _ESP, 0, 0)), \
POPQr((rd)))
#define jit_roundr_d_l_fppop(rd, rs) \
(PUSHQr(_EAX), \
FISTPQm(0, _ESP, 0, 0), \
POPQr((rd)))
#define jit_fp_test(d, s1, s2, n, _and, res) \
(((s1) == 0 ? FUCOMr((s2)) : (FLDr((s1)), FUCOMPr((s2) + 1))), \

View File

@ -215,6 +215,7 @@
MOVEIri(JIT_AUX,-4), \
STFIWXrrr(7,JIT_SP,JIT_AUX), \
LWZrm((rd),-4,JIT_SP))
#define jit_roundr_d_l(rd,rs) jit_roundr_d_i(rd,rs)
#define jit_truncr_d_i(rd,rs) (FCTIWZrr(7,(rs)), \
MOVEIri(JIT_AUX,-4), \

View File

@ -101,6 +101,7 @@ static Scheme_Object *flvector_length (int argc, Scheme_Object *argv[]);
static Scheme_Object *make_flvector (int argc, Scheme_Object *argv[]);
static Scheme_Object *integer_to_fl (int argc, Scheme_Object *argv[]);
static Scheme_Object *fl_to_integer (int argc, Scheme_Object *argv[]);
static Scheme_Object *fx_and (int argc, Scheme_Object *argv[]);
static Scheme_Object *fx_or (int argc, Scheme_Object *argv[]);
@ -109,6 +110,7 @@ static Scheme_Object *fx_not (int argc, Scheme_Object *argv[]);
static Scheme_Object *fx_lshift (int argc, Scheme_Object *argv[]);
static Scheme_Object *fx_rshift (int argc, Scheme_Object *argv[]);
static Scheme_Object *fx_to_fl (int argc, Scheme_Object *argv[]);
static Scheme_Object *fl_to_fx (int argc, Scheme_Object *argv[]);
static Scheme_Object *fl_floor (int argc, Scheme_Object *argv[]);
static Scheme_Object *fl_ceiling (int argc, Scheme_Object *argv[]);
@ -130,6 +132,7 @@ static Scheme_Object *unsafe_fx_not (int argc, Scheme_Object *argv[]);
static Scheme_Object *unsafe_fx_lshift (int argc, Scheme_Object *argv[]);
static Scheme_Object *unsafe_fx_rshift (int argc, Scheme_Object *argv[]);
static Scheme_Object *unsafe_fx_to_fl (int argc, Scheme_Object *argv[]);
static Scheme_Object *unsafe_fl_to_fx (int argc, Scheme_Object *argv[]);
static Scheme_Object *fl_ref (int argc, Scheme_Object *argv[]);
static Scheme_Object *fl_set (int argc, Scheme_Object *argv[]);
@ -516,22 +519,18 @@ scheme_init_number (Scheme_Env *env)
1, 1, 1),
env);
p = scheme_make_folding_prim(scheme_exact_to_inexact,
"exact->inexact",
1, 1, 1);
p = scheme_make_folding_prim(scheme_exact_to_inexact, "exact->inexact", 1, 1, 1);
if (scheme_can_inline_fp_op())
SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_UNARY_INLINED;
else
SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_SOMETIMES_INLINED;
scheme_add_global_constant("exact->inexact", p, env);
scheme_add_global_constant("inexact->exact",
scheme_make_folding_prim(scheme_inexact_to_exact,
"inexact->exact",
1, 1, 1),
env);
p = scheme_make_folding_prim(scheme_inexact_to_exact, "inexact->exact", 1, 1, 1);
SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_UNARY_INLINED;
scheme_add_global_constant("inexact->exact", p, env);
}
void scheme_init_flfxnum_number(Scheme_Env *env)
{
Scheme_Object *p;
@ -578,6 +577,13 @@ void scheme_init_flfxnum_number(Scheme_Env *env)
SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_SOMETIMES_INLINED;
scheme_add_global_constant("->fl", p, env);
p = scheme_make_folding_prim(fl_to_integer, "fl->exact-integer", 1, 1, 1);
if (scheme_can_inline_fp_comp())
SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_UNARY_INLINED;
else
SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_SOMETIMES_INLINED;
scheme_add_global_constant("fl->exact-integer", p, env);
p = scheme_make_folding_prim(fx_and, "fxand", 2, 2, 1);
SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_BINARY_INLINED;
@ -610,6 +616,13 @@ void scheme_init_flfxnum_number(Scheme_Env *env)
SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_SOMETIMES_INLINED;
scheme_add_global_constant("fx->fl", p, env);
p = scheme_make_folding_prim(fl_to_fx, "fl->fx", 1, 1, 1);
if (scheme_can_inline_fp_comp())
SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_UNARY_INLINED;
else
SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_SOMETIMES_INLINED;
scheme_add_global_constant("fl->fx", p, env);
p = scheme_make_folding_prim(fl_truncate, "fltruncate", 1, 1, 1);
if (scheme_can_inline_fp_op())
@ -738,6 +751,11 @@ void scheme_init_unsafe_number(Scheme_Env *env)
SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_UNSAFE_FUNCTIONAL;
scheme_add_global_constant("unsafe-fx->fl", p, env);
p = scheme_make_folding_prim(unsafe_fl_to_fx, "unsafe-fl->fx", 1, 1, 1);
SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_UNARY_INLINED;
SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_UNSAFE_FUNCTIONAL;
scheme_add_global_constant("unsafe-fl->fx", p, env);
p = scheme_make_immed_prim(fl_ref, "unsafe-f64vector-ref",
2, 2);
if (scheme_can_inline_fp_op())
@ -3260,6 +3278,28 @@ static Scheme_Object *fx_to_fl (int argc, Scheme_Object *argv[])
return scheme_make_double(v);
}
static Scheme_Object *fl_to_fx (int argc, Scheme_Object *argv[])
{
double d;
long v;
Scheme_Object *o;
if (!SCHEME_DBLP(argv[0])
|| !scheme_is_integer(argv[0]))
scheme_wrong_type("fl->fx", "inexact-real integer", 0, argc, argv);
d = SCHEME_DBL_VAL(argv[0]);
v = (long)d;
if ((double)v == d) {
o = scheme_make_integer_value(v);
if (SCHEME_INTP(o))
return o;
}
scheme_arg_mismatch("fl->fx", "no fixnum representation: ", argv[0]);
return NULL;
}
#define SAFE_FL(op) \
static Scheme_Object * fl_ ## op (int argc, Scheme_Object *argv[]) \
{ \
@ -3315,6 +3355,14 @@ static Scheme_Object *unsafe_fx_to_fl (int argc, Scheme_Object *argv[])
return scheme_make_double(v);
}
static Scheme_Object *unsafe_fl_to_fx (int argc, Scheme_Object *argv[])
{
long v;
if (scheme_current_thread->constant_folding) return scheme_inexact_to_exact(argc, argv);
v = (long)(SCHEME_DBL_VAL(argv[0]));
return scheme_make_integer(v);
}
static Scheme_Object *fl_ref (int argc, Scheme_Object *argv[])
{
double v;
@ -3368,3 +3416,16 @@ static Scheme_Object *integer_to_fl (int argc, Scheme_Object *argv[])
return NULL;
}
}
static Scheme_Object *fl_to_integer (int argc, Scheme_Object *argv[])
{
if (SCHEME_DBLP(argv[0])) {
Scheme_Object *o;
o = scheme_inexact_to_exact(argc, argv);
if (SCHEME_INTP(o) || SCHEME_BIGNUMP(o))
return o;
}
scheme_wrong_type("fl->exact-integer", "inexact-real integer", 0, argc, argv);
return NULL;
}

View File

@ -14,8 +14,8 @@
#define USE_COMPILED_STARTUP 1
#define EXPECTED_PRIM_COUNT 996
#define EXPECTED_UNSAFE_COUNT 65
#define EXPECTED_FLFXNUM_COUNT 53
#define EXPECTED_UNSAFE_COUNT 66
#define EXPECTED_FLFXNUM_COUNT 55
#ifdef MZSCHEME_SOMETHING_OMITTED
# undef USE_COMPILED_STARTUP

View File

@ -13,12 +13,12 @@
consistently.)
*/
#define MZSCHEME_VERSION "5.0.0.1"
#define MZSCHEME_VERSION "5.0.0.2"
#define MZSCHEME_VERSION_X 5
#define MZSCHEME_VERSION_Y 0
#define MZSCHEME_VERSION_Z 0
#define MZSCHEME_VERSION_W 1
#define MZSCHEME_VERSION_W 2
#define MZSCHEME_VERSION_MAJOR ((MZSCHEME_VERSION_X * 100) + MZSCHEME_VERSION_Y)
#define MZSCHEME_VERSION_MINOR ((MZSCHEME_VERSION_Z * 1000) + MZSCHEME_VERSION_W)