-
Notifications
You must be signed in to change notification settings - Fork 1k
Add exact and inexact to cptypes #991
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -742,14 +742,14 @@ | |
| (set! ,(%mref ,t ,offset) ,(car args)) | ||
| ,(f (cdr args) (fx+ offset (constant ptr-bytes))))))))))))) | ||
| (define build-$real->flonum | ||
| (lambda (src sexpr x who) | ||
| (lambda (src sexpr who x) | ||
| (if (known-flonum-result? x) | ||
| x | ||
| (bind #t (x) | ||
| (bind #f (who) | ||
| (bind #f (who) | ||
| (bind #t (x) | ||
| `(if ,(%type-check mask-flonum type-flonum ,x) | ||
| ,x | ||
| ,(build-libcall #t src sexpr real->flonum x who))))))) | ||
| ,(build-libcall #t src sexpr $real->flonum who x))))))) | ||
| (define build-$inexactnum-real-part | ||
| (lambda (e) | ||
| (%lea ,e (fx+ (constant inexactnum-real-disp) | ||
|
|
@@ -5408,9 +5408,46 @@ | |
| ,(build-fixnum->flonum e-x values) | ||
| (if ,(%type-check mask-flonum type-flonum ,e-x) | ||
| ,e-x | ||
| ,(build-libcall #t src sexpr real->flonum e-x `(quote real->flonum))))))])) | ||
| (define-inline 3 $real->flonum | ||
| [(x who) (build-$real->flonum src sexpr x who)]) | ||
| ,(build-libcall #t src sexpr $real->flonum `(quote real->flonum) e-x)))))]) | ||
| (define-inline 3 $real->flonum | ||
| [(who x) (build-$real->flonum src sexpr who x)]) | ||
| (define-inline 2 inexact | ||
| [(e-x) | ||
| (if (known-flonum-result? e-x) | ||
| e-x | ||
| (bind #t (e-x) | ||
| `(if ,(%type-check mask-fixnum type-fixnum ,e-x) | ||
| ,(build-fixnum->flonum e-x values) | ||
| (if ,(build-simple-or | ||
| (%type-check mask-flonum type-flonum ,e-x) | ||
| (%typed-object-check mask-inexactnum type-inexactnum ,e-x)) | ||
| ,e-x | ||
| ,(build-libcall #t src sexpr inexact e-x)))))]) | ||
| (define-inline 2 exact->inexact | ||
| [(e-x) | ||
| (if (known-flonum-result? e-x) | ||
| e-x | ||
| (bind #t (e-x) | ||
| `(if ,(%type-check mask-fixnum type-fixnum ,e-x) | ||
| ,(build-fixnum->flonum e-x values) | ||
| (if ,(build-simple-or | ||
| (%type-check mask-flonum type-flonum ,e-x) | ||
| (%typed-object-check mask-inexactnum type-inexactnum ,e-x)) | ||
| ,e-x | ||
| ,(build-libcall #t src sexpr exact->inexact e-x)))))]) | ||
| ) | ||
| (define-inline 2 exact | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I share your reluctance about these. Maybe if they included conversion from integer flonums that are small enough to fit into a fixnum? Otherwise, I'd be inclined to leave them out until motivated by a use.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something like (copiying from I'll try tomorrow, because I prefer to see the code to think about it, but I'm still not sure.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code should check that it's an integer flonum. I'll try to add the most interesting cases to cptypes instead. |
||
| [(e-x) | ||
| (bind #t (e-x) | ||
| `(if ,(%type-check mask-fixnum type-fixnum ,e-x) | ||
| ,e-x | ||
| ,(build-libcall #t src sexpr exact e-x)))]) | ||
| (define-inline 2 inexact->exact | ||
| [(e-x) | ||
| (bind #t (e-x) | ||
| `(if ,(%type-check mask-fixnum type-fixnum ,e-x) | ||
| ,e-x | ||
| ,(build-libcall #t src sexpr inexact->exact e-x)))]) | ||
| (define-inline 2 $record | ||
| [(tag . args) (build-$record tag args)]) | ||
| (define-inline 3 $object-address | ||
|
|
@@ -7136,7 +7173,7 @@ | |
| (let-values ([(e-index imm-offset) (bv-index-offset e-offset)]) | ||
| (bind #f (e-bv e-index) | ||
| (build-object-set! 'type e-bv e-index imm-offset | ||
| (build-$real->flonum src sexpr e-val `(quote name)))))])]))) | ||
| (build-$real->flonum src sexpr `(quote name) e-val))))])]))) | ||
|
|
||
| (define-bv-native-ieee-set!-inline bytevector-ieee-single-native-set! single-float) | ||
| (define-bv-native-ieee-set!-inline bytevector-ieee-double-native-set! double-float) | ||
|
|
@@ -7264,8 +7301,7 @@ | |
| (let-values ([(e-index imm-offset) (bv-index-offset e-offset)]) | ||
| (bind #f (e-bv e-index) | ||
| (build-object-set! 'type e-bv e-index imm-offset | ||
| (build-$real->flonum src sexpr e-value | ||
| `(quote name))))))])]))) | ||
| (build-$real->flonum src sexpr `(quote name) e-value)))))])]))) | ||
|
|
||
| (define-bv-ieee-set!-inline bytevector-ieee-single-set! single-float 3) | ||
| (define-bv-ieee-set!-inline bytevector-ieee-double-set! double-float 7)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like too much code duplication. Add a
build-exact->inexactparameterized over the library entry to call?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The (small) problem is that
build-libcallis a macro that expect an not-quoted version of the name of the library call. Sobuild-exact->inexactmust be a macro too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or pass in a function like
(lambda (e-x) (build-libcall #t src sexpr inexact e-x)). I'd say the goal isn't to avoid every bit of duplication, but to get most of it.