Skip to content

Commit

Permalink
Merge pull request #5152 from unisonweb/topic/jit-cont
Browse files Browse the repository at this point in the history
  • Loading branch information
aryairani committed Jun 28, 2024
2 parents c206059 + 907aba9 commit 570db9b
Show file tree
Hide file tree
Showing 17 changed files with 2,410 additions and 1,890 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ At a high level, the CI process is:
Some version numbers that are used during CI:
- `ormolu_version: "0.5.0.1"`
- `racket_version: "8.7"`
- `jit_version: "@unison/internal/releases/0.0.17"`
- `jit_version: "@unison/internal/releases/0.0.18"`

Some cached directories:
- `ucm_local_bin` a temp path for caching a built `ucm`
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
env:
ormolu_version: 0.5.2.0
ucm_local_bin: ucm-local-bin
jit_version: "@unison/internal/releases/0.0.17"
jit_version: "@unison/internal/releases/0.0.18"
jit_src_scheme: unison-jit-src/scheme-libs/racket
jit_dist: unison-jit-dist
jit_generator_os: ubuntu-20.04
Expand Down
105 changes: 69 additions & 36 deletions scheme-libs/racket/unison/arithmetic.rkt
Original file line number Diff line number Diff line change
@@ -1,70 +1,103 @@
#!racket/base

(provide
(prefix-out
builtin-
(combine-out
Nat.toFloat
Nat.increment
Nat.+
Nat.drop
Float.*
Float.fromRepresentation
Float.toRepresentation
Float.ceiling
Int.+
Int.-
Int./
Int.increment
Int.negate
Int.fromRepresentation
Int.toRepresentation
Int.signum
)))
builtin-Nat.+
builtin-Nat.+:termlink
builtin-Nat.toFloat
builtin-Nat.toFloat:termlink
builtin-Nat.increment
builtin-Nat.increment:termlink
builtin-Nat.drop
builtin-Nat.drop:termlink
builtin-Float.*
builtin-Float.*:termlink
builtin-Float.fromRepresentation
builtin-Float.fromRepresentation:termlink
builtin-Float.toRepresentation
builtin-Float.toRepresentation:termlink
builtin-Float.ceiling
builtin-Float.ceiling:termlink
builtin-Int.+
builtin-Int.+:termlink
builtin-Int.-
builtin-Int.-:termlink
builtin-Int./
builtin-Int./:termlink
builtin-Int.increment
builtin-Int.increment:termlink
builtin-Int.negate
builtin-Int.negate:termlink
builtin-Int.fromRepresentation
builtin-Int.fromRepresentation:termlink
builtin-Int.toRepresentation
builtin-Int.toRepresentation:termlink
builtin-Int.signum
builtin-Int.signum:termlink)

(require racket
racket/fixnum
racket/flonum
racket/performance-hint
unison/data
unison/boot)

(begin-encourage-inline
(define-unison (Nat.+ m n) (clamp-natural (+ m n)))
(define-unison (Nat.drop m n) (max 0 (- m n)))
(define-unison-builtin
(builtin-Nat.+ m n)
(clamp-natural (+ m n)))

(define-unison (Nat.increment n) (clamp-natural (add1 n)))
(define-unison (Int.increment i) (clamp-integer (add1 i)))
(define-unison (Int.negate i) (if (> i nbit63) (- i) i))
(define-unison (Int.+ i j) (clamp-integer (+ i j)))
(define-unison (Int.- i j) (clamp-integer (- i j)))
(define-unison (Int./ i j) (floor (/ i j)))
(define-unison (Int.signum i) (sgn i))
(define-unison (Float.* x y) (fl* x y))
(define-unison-builtin
(builtin-Nat.drop m n)
(max 0 (- m n)))

(define-unison (Nat.toFloat n) (->fl n))
(define-unison-builtin
(builtin-Nat.increment n)
(clamp-natural (add1 n)))
(define-unison-builtin
(builtin-Int.increment i) (clamp-integer (add1 i)))
(define-unison-builtin
(builtin-Int.negate i) (if (> i nbit63) (- i) i))
(define-unison-builtin
(builtin-Int.+ i j) (clamp-integer (+ i j)))
(define-unison-builtin
(builtin-Int.- i j) (clamp-integer (- i j)))
(define-unison-builtin
(builtin-Int./ i j) (floor (/ i j)))
(define-unison-builtin
(builtin-Int.signum i) (sgn i))
(define-unison-builtin
(builtin-Float.* x y) (fl* x y))

(define-unison (Float.ceiling f)
(define-unison-builtin
(builtin-Nat.toFloat n) (->fl n))

(define-unison-builtin
(builtin-Float.ceiling f)
(clamp-integer (fl->exact-integer (ceiling f))))

; If someone can suggest a better mechanism for these,
; that would be appreciated.
(define-unison (Float.toRepresentation fl)
(define-unison-builtin
(builtin-Float.toRepresentation fl)
(integer-bytes->integer
(real->floating-point-bytes fl 8 #t) ; big endian
#f ; unsigned
#t)) ; big endian

(define-unison (Float.fromRepresentation n)
(define-unison-builtin
(builtin-Float.fromRepresentation n)
(floating-point-bytes->real
(integer->integer-bytes n 8 #f #t) ; unsigned, big endian
#t)) ; big endian

(define-unison (Int.toRepresentation i)
(define-unison-builtin
(builtin-Int.toRepresentation i)
(integer-bytes->integer
(integer->integer-bytes i 8 #t #t) ; signed, big endian
#f #t)) ; unsigned, big endian

(define-unison (Int.fromRepresentation n)
(define-unison-builtin
(builtin-Int.fromRepresentation n)
(integer-bytes->integer
(integer->integer-bytes n 8 #f #t) ; unsigned, big endian
#t #t)) ; signed, big endian
Expand Down
Loading

0 comments on commit 570db9b

Please sign in to comment.