Skip to content

Commit afeb0d1

Browse files
authored
Merge pull request #1362 from obround/julia-platform
Julia platform implementation
2 parents 8be6c94 + 9d60188 commit afeb0d1

File tree

1 file changed

+222
-0
lines changed

1 file changed

+222
-0
lines changed

src/platforms/julia.rkt

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
#lang s-exp "../syntax/platform-language.rkt"
2+
3+
;; Julia platform
4+
5+
(require math/flonum)
6+
7+
(define 64bit-move-cost 1.000)
8+
(define 32bit-move-cost 1.000)
9+
(define boolean-move-cost 0.100)
10+
11+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; BOOLEAN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12+
13+
(define-representation <bool> #:cost boolean-move-cost)
14+
15+
(define-operations () <bool>
16+
[TRUE #:spec (TRUE) #:impl (const true) #:fpcore TRUE #:cost boolean-move-cost]
17+
[FALSE #:spec (FALSE) #:impl (const false) #:fpcore FALSE #:cost boolean-move-cost])
18+
19+
(define-operations ([x <bool>] [y <bool>]) <bool>
20+
[and #:spec (and x y) #:impl (lambda v (andmap values v)) #:cost boolean-move-cost]
21+
[or #:spec (or x y) #:impl (lambda v (ormap values v)) #:cost boolean-move-cost])
22+
23+
(define-operation (not [x <bool>]) <bool>
24+
#:spec (not x) #:impl not #:cost boolean-move-cost)
25+
26+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; BINARY 32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27+
28+
(define-representation <binary32> #:cost 32bit-move-cost)
29+
30+
(define-operation (if.f32 [c <bool>] [t <binary32>] [f <binary32>]) <binary32>
31+
#:spec (if c t f) #:impl if-impl
32+
#:cost (if-cost boolean-move-cost))
33+
34+
(define-operation (neg.f32 [x <binary32>]) <binary32>
35+
#:spec (neg x) #:impl (compose flsingle -) #:fpcore (! :precision binary32 (- x)) #:cost 1.0)
36+
37+
;; Comparison operations
38+
(define-operations ([x <binary32>] [y <binary32>]) <bool>
39+
[==.f32 #:spec (== x y) #:impl = #:cost boolean-move-cost]
40+
[!=.f32 #:spec (!= x y) #:impl (negate =) #:cost boolean-move-cost]
41+
[<.f32 #:spec (< x y) #:impl < #:cost boolean-move-cost]
42+
[>.f32 #:spec (> x y) #:impl > #:cost boolean-move-cost]
43+
[<=.f32 #:spec (<= x y) #:impl <= #:cost boolean-move-cost]
44+
[>=.f32 #:spec (>= x y) #:impl >= #:cost boolean-move-cost])
45+
46+
;; Constants
47+
(define-operations () <binary32> #:fpcore (! :precision binary32 _)
48+
[PI.f32 #:spec (PI) #:impl (const (flsingle pi)) #:fpcore PI #:cost 32bit-move-cost]
49+
[E.f32 #:spec (E) #:impl (const (flsingle (exp 1))) #:fpcore E #:cost 32bit-move-cost]
50+
[INFINITY.f32 #:spec (INFINITY) #:impl (const +inf.0) #:fpcore INFINITY #:cost 32bit-move-cost]
51+
[NAN.f32 #:spec (NAN) #:impl (const +nan.0) #:fpcore NAN #:cost 32bit-move-cost])
52+
53+
;; Binary operations
54+
(define-operations ([x <binary32>] [y <binary32>]) <binary32> #:fpcore (! :precision binary32 _)
55+
[+.f32 #:spec (+ x y) #:impl (compose flsingle +) #:cost 1.0]
56+
[-.f32 #:spec (- x y) #:impl (compose flsingle -) #:cost 1.0]
57+
[*.f32 #:spec (* x y) #:impl (compose flsingle *) #:cost 1.0]
58+
[/.f32 #:spec (/ x y) #:impl (compose flsingle /) #:cost 1.0]
59+
[fmax.f32 #:spec (fmax x y) #:impl (from-libm 'fmaxf) #:cost 1.0]
60+
[fmin.f32 #:spec (fmin x y) #:impl (from-libm 'fminf) #:cost 1.0]
61+
[hypot.f32 #:spec (sqrt (+ (* x x) (* y y))) #:impl (from-libm 'hypotf) #:cost 4.0 #:fpcore (hypot x y)]
62+
[pow.f32 #:spec (pow x y) #:impl (from-libm 'powf) #:cost 15.5]
63+
[copysign.f32 #:spec (copysign x y) #:impl (from-libm 'copysignf) #:cost 1.0])
64+
65+
;; Unary operations
66+
(define-operations ([x <binary32>]) <binary32> #:fpcore (! :precision binary32 _)
67+
[fabs.f32 #:spec (fabs x) #:impl (from-libm 'fabsf) #:cost 1.0]
68+
[sqrt.f32 #:spec (sqrt x) #:impl (from-libm 'sqrtf) #:cost 1.0]
69+
[exp.f32 #:spec (exp x) #:impl (from-libm 'expf) #:cost 3.5]
70+
[exp2.f32 #:spec (exp2 x) #:impl (from-libm 'exp2f) #:cost 3.5]
71+
[exp10.f32 #:spec (pow 10 x) #:impl (from-rival) #:cost 3.5]
72+
[log.f32 #:spec (log x) #:impl (from-libm 'logf) #:cost 4.5]
73+
[log10.f32 #:spec (log10 x) #:impl (from-libm 'log10f) #:cost 5.0]
74+
[log2.f32 #:spec (log2 x) #:impl (from-libm 'log2f) #:cost 5.5]
75+
[sin.f32 #:spec (sin x) #:impl (from-libm 'sinf) #:cost 3.5]
76+
[cos.f32 #:spec (cos x) #:impl (from-libm 'cosf) #:cost 4.0]
77+
[tan.f32 #:spec (tan x) #:impl (from-libm 'tanf) #:cost 6.0]
78+
[sinh.f32 #:spec (sinh x) #:impl (from-libm 'sinhf) #:cost 4.5]
79+
[cosh.f32 #:spec (cosh x) #:impl (from-libm 'coshf) #:cost 4.5]
80+
[tanh.f32 #:spec (tanh x) #:impl (from-libm 'tanhf) #:cost 5.0]
81+
[asin.f32 #:spec (asin x) #:impl (from-libm 'asinf) #:cost 4.0]
82+
[acos.f32 #:spec (acos x) #:impl (from-libm 'acosf) #:cost 4.0]
83+
[atan.f32 #:spec (atan x) #:impl (from-libm 'atanf) #:cost 6.0]
84+
[atanh.f32 #:spec (atanh x) #:impl (from-libm 'atanhf) #:cost 6.5]
85+
[asinh.f32 #:spec (asinh x) #:impl (from-libm 'asinhf) #:cost 9.5]
86+
[acosh.f32 #:spec (acosh x) #:impl (from-libm 'acoshf) #:cost 7.5]
87+
[cbrt.f32 #:spec (cbrt x) #:impl (from-libm 'cbrtf) #:cost 4.5]
88+
[log1p.f32 #:spec (log (+ 1 x)) #:impl (from-libm 'log1pf) #:cost 5.5 #:fpcore (log1p x)]
89+
[expm1.f32 #:spec (- (exp x) 1) #:impl (from-libm 'expm1f) #:cost 5.5 #:fpcore (expm1 x)]
90+
[deg2rad.f32 #:spec (* x (/ (PI) 180)) #:impl (from-rival) #:cost 1.0 #:fpcore (deg2rad x)]
91+
[rad2deg.f32 #:spec (* x (/ 180 (PI))) #:impl (from-rival) #:cost 1.0 #:fpcore (rad2deg x)]
92+
[abs2.f32 #:spec (* (fabs x) (fabs x)) #:impl (from-rival) #:cost 1.0 #:fpcore (abs2 x)]
93+
[sec.f32 #:spec (/ 1 (cos x)) #:impl (from-rival) #:cost 4.0 #:fpcore (sec x)]
94+
[csc.f32 #:spec (/ 1 (sin x)) #:impl (from-rival) #:cost 3.5 #:fpcore (csc x)]
95+
[cot.f32 #:spec (/ 1 (tan x)) #:impl (from-rival) #:cost 7.5 #:fpcore (cot x)]
96+
[sech.f32 #:spec (/ 1 (cosh x)) #:impl (from-rival) #:cost 8.0 #:fpcore (sech x)]
97+
[csch.f32 #:spec (/ 1 (sinh x)) #:impl (from-rival) #:cost 5.0 #:fpcore (csch x)]
98+
[coth.f32 #:spec (/ (cosh x) (sinh x)) #:impl (from-rival) #:cost 8.0 #:fpcore (coth x)]
99+
[asec.f32 #:spec (acos (/ 1 x)) #:impl (from-rival) #:cost 4.5 #:fpcore (asec x)]
100+
[acsc.f32 #:spec (asin (/ 1 x)) #:impl (from-rival) #:cost 6.5 #:fpcore (acsc x)]
101+
[acot.f32 #:spec (atan (/ 1 x)) #:impl (from-rival) #:cost 7.5 #:fpcore (acot x)]
102+
[asech.f32 #:spec (acosh (/ 1 x)) #:impl (from-rival) #:cost 8.5 #:fpcore (asech x)]
103+
[acsch.f32 #:spec (asinh (/ 1 x)) #:impl (from-rival) #:cost 10.0 #:fpcore (acsch x)]
104+
[acoth.f32 #:spec (atanh (/ 1 x)) #:impl (from-rival) #:cost 7.0 #:fpcore (acoth x)]
105+
[sind.f32 #:spec (sin (* x (/ (PI) 180))) #:impl (from-rival) #:cost 6.0 #:fpcore (sind x)]
106+
[cosd.f32 #:spec (cos (* x (/ (PI) 180))) #:impl (from-rival) #:cost 6.5 #:fpcore (cosd x)]
107+
[tand.f32 #:spec (tan (* x (/ (PI) 180))) #:impl (from-rival) #:cost 13.0 #:fpcore (tand x)]
108+
[cotd.f32 #:spec (/ 1 (tan (* x (/ (PI) 180)))) #:impl (from-rival) #:cost 14.0 #:fpcore (cotd x)]
109+
[asind.f32 #:spec (* (asin x) (/ 180 (PI))) #:impl (from-rival) #:cost 4.5 #:fpcore (asind x)]
110+
[acosd.f32 #:spec (* (acos x) (/ 180 (PI))) #:impl (from-rival) #:cost 4.0 #:fpcore (acosd x)]
111+
[atand.f32 #:spec (* (atan x) (/ 180 (PI))) #:impl (from-rival) #:cost 6.0 #:fpcore (atand x)]
112+
[acotd.f32 #:spec (* (atan (/ 1 x)) (/ 180 (PI))) #:impl (from-rival) #:cost 8.0 #:fpcore (acotd x)]
113+
[asecd.f32 #:spec (* (acos (/ 1 x)) (/ 180 (PI))) #:impl (from-rival) #:cost 5.0 #:fpcore (asecd x)]
114+
[acscd.f32 #:spec (* (asin (/ 1 x)) (/ 180 (PI))) #:impl (from-rival) #:cost 6.5 #:fpcore (acscd x)]
115+
[secd.f32 #:spec (/ 1 (cos (* x (/ (PI) 180)))) #:impl (from-rival) #:cost 8.0 #:fpcore (secd x)]
116+
[cscd.f32 #:spec (/ 1 (sin (* x (/ (PI) 180)))) #:impl (from-rival) #:cost 6.5 #:fpcore (cscd x)]
117+
[sinpi.f32 #:spec (sin (* (* x (PI)) (/ (PI) 180))) #:impl (from-rival) #:cost 5.0 #:fpcore (sinpi x)]
118+
[cospi.f32 #:spec (cos (* (* x (PI)) (/ (PI) 180))) #:impl (from-rival) #:cost 5.0 #:fpcore (cospi x)])
119+
120+
;; Ternary fused multiply-add operation
121+
(define-operation (fma.f32 [x <binary32>] [y <binary32>] [z <binary32>]) <binary32>
122+
#:spec (+ (* x y) z) #:impl (from-libm 'fmaf)
123+
#:fpcore (! :precision binary32 (fma x y z)) #:cost 1.0)
124+
125+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; BINARY 64 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
126+
127+
(define-representation <binary64> #:cost 64bit-move-cost)
128+
129+
(define-operation (if.f64 [c <bool>] [t <binary64>] [f <binary64>]) <binary64>
130+
#:spec (if c t f) #:impl if-impl
131+
#:cost (if-cost boolean-move-cost))
132+
133+
(define-operation (neg.f64 [x <binary64>]) <binary64>
134+
#:spec (neg x) #:impl - #:fpcore (! :precision binary64 (- x)) #:cost 1.0)
135+
136+
;; Comparison operations
137+
(define-operations ([x <binary64>] [y <binary64>]) <bool>
138+
[==.f64 #:spec (== x y) #:impl = #:cost boolean-move-cost]
139+
[!=.f64 #:spec (!= x y) #:impl (negate =) #:cost boolean-move-cost]
140+
[<.f64 #:spec (< x y) #:impl < #:cost boolean-move-cost]
141+
[>.f64 #:spec (> x y) #:impl > #:cost boolean-move-cost]
142+
[<=.f64 #:spec (<= x y) #:impl <= #:cost boolean-move-cost]
143+
[>=.f64 #:spec (>= x y) #:impl >= #:cost boolean-move-cost])
144+
145+
;; Constants
146+
(define-operations () <binary64> #:fpcore (! :precision binary64 _)
147+
[PI.f64 #:spec (PI) #:impl (const pi) #:fpcore PI #:cost 64bit-move-cost]
148+
[E.f64 #:spec (E) #:impl (const (exp 1)) #:fpcore E #:cost 64bit-move-cost]
149+
[INFINITY #:spec (INFINITY) #:impl (const +inf.0) #:fpcore INFINITY #:cost 64bit-move-cost]
150+
[NAN.f64 #:spec (NAN) #:impl (const +nan.0) #:fpcore NAN #:cost 64bit-move-cost])
151+
152+
;; Binary operations
153+
(define-operations ([x <binary64>] [y <binary64>]) <binary64> #:fpcore (! :precision binary64 _)
154+
[+.f64 #:spec (+ x y) #:impl + #:cost 1.0]
155+
[-.f64 #:spec (- x y) #:impl - #:cost 1.0]
156+
[*.f64 #:spec (* x y) #:impl * #:cost 1.0]
157+
[/.f64 #:spec (/ x y) #:impl / #:cost 1.0]
158+
[fmax.f64 #:spec (fmax x y) #:impl (from-libm 'fmax) #:cost 1.0]
159+
[fmin.f64 #:spec (fmin x y) #:impl (from-libm 'fmin) #:cost 1.0]
160+
[hypot.f64 #:spec (sqrt (+ (* x x) (* y y))) #:impl (from-libm 'hypot) #:cost 4.0 #:fpcore (hypot x y)]
161+
[pow.f64 #:spec (pow x y) #:impl (from-libm 'pow) #:cost 15.5]
162+
[copysign.f64 #:spec (copysign x y) #:impl (from-libm 'copysign) #:cost 1.0])
163+
164+
;; Unary operations
165+
(define-operations ([x <binary64>]) <binary64> #:fpcore (! :precision binary64 _)
166+
[fabs.f64 #:spec (fabs x) #:impl (from-libm 'fabs) #:cost 1.0]
167+
[sqrt.f64 #:spec (sqrt x) #:impl (from-libm 'sqrt) #:cost 1.0]
168+
[exp.f64 #:spec (exp x) #:impl (from-libm 'exp) #:cost 3.5]
169+
[exp2.f64 #:spec (exp2 x) #:impl (from-libm 'exp2) #:cost 3.5]
170+
[exp10.f64 #:spec (pow 10 x) #:impl (from-rival) #:cost 3.5]
171+
[log.f64 #:spec (log x) #:impl (from-libm 'log) #:cost 4.5]
172+
[log10.f64 #:spec (log10 x) #:impl (from-libm 'log10) #:cost 5.0]
173+
[log2.f64 #:spec (log2 x) #:impl (from-libm 'log2) #:cost 5.5]
174+
[sin.f64 #:spec (sin x) #:impl (from-libm 'sin) #:cost 3.5]
175+
[cos.f64 #:spec (cos x) #:impl (from-libm 'cos) #:cost 4.0]
176+
[tan.f64 #:spec (tan x) #:impl (from-libm 'tan) #:cost 6.0]
177+
[sinh.f64 #:spec (sinh x) #:impl (from-libm 'sinh) #:cost 4.5]
178+
[cosh.f64 #:spec (cosh x) #:impl (from-libm 'cosh) #:cost 4.5]
179+
[tanh.f64 #:spec (tanh x) #:impl (from-libm 'tanh) #:cost 5.0]
180+
[asin.f64 #:spec (asin x) #:impl (from-libm 'asin) #:cost 4.0]
181+
[acos.f64 #:spec (acos x) #:impl (from-libm 'acos) #:cost 4.0]
182+
[atan.f64 #:spec (atan x) #:impl (from-libm 'atan) #:cost 6.0]
183+
[atanh.f64 #:spec (atanh x) #:impl (from-libm 'atanh) #:cost 6.5]
184+
[asinh.f64 #:spec (asinh x) #:impl (from-libm 'asinh) #:cost 9.5]
185+
[acosh.f64 #:spec (acosh x) #:impl (from-libm 'acosh) #:cost 7.5]
186+
[cbrt.f64 #:spec (cbrt x) #:impl (from-libm 'cbrt) #:cost 4.5]
187+
[log1p.f64 #:spec (log (+ 1 x)) #:impl (from-libm 'log1p) #:cost 5.5 #:fpcore (log1p x)]
188+
[expm1.f64 #:spec (- (exp x) 1) #:impl (from-libm 'expm1) #:cost 5.5 #:fpcore (expm1 x)]
189+
[deg2rad.f64 #:spec (* x (/ (PI) 180)) #:impl (from-rival) #:cost 1.0 #:fpcore (deg2rad x)]
190+
[rad2deg.f64 #:spec (* x (/ 180 (PI))) #:impl (from-rival) #:cost 1.0 #:fpcore (rad2deg x)]
191+
[abs2.f64 #:spec (* (fabs x) (fabs x)) #:impl (from-rival) #:cost 1.0 #:fpcore (abs2 x)]
192+
[sec.f64 #:spec (/ 1 (cos x)) #:impl (from-rival) #:cost 4.0 #:fpcore (sec x)]
193+
[csc.f64 #:spec (/ 1 (sin x)) #:impl (from-rival) #:cost 3.5 #:fpcore (csc x)]
194+
[cot.f64 #:spec (/ 1 (tan x)) #:impl (from-rival) #:cost 7.5 #:fpcore (cot x)]
195+
[sech.f64 #:spec (/ 1 (cosh x)) #:impl (from-rival) #:cost 8.0 #:fpcore (sech x)]
196+
[csch.f64 #:spec (/ 1 (sinh x)) #:impl (from-rival) #:cost 5.0 #:fpcore (csch x)]
197+
[coth.f64 #:spec (/ (cosh x) (sinh x)) #:impl (from-rival) #:cost 8.0 #:fpcore (coth x)]
198+
[asec.f64 #:spec (acos (/ 1 x)) #:impl (from-rival) #:cost 4.5 #:fpcore (asec x)]
199+
[acsc.f64 #:spec (asin (/ 1 x)) #:impl (from-rival) #:cost 6.5 #:fpcore (acsc x)]
200+
[acot.f64 #:spec (atan (/ 1 x)) #:impl (from-rival) #:cost 7.5 #:fpcore (acot x)]
201+
[asech.f64 #:spec (acosh (/ 1 x)) #:impl (from-rival) #:cost 8.5 #:fpcore (asech x)]
202+
[acsch.f64 #:spec (asinh (/ 1 x)) #:impl (from-rival) #:cost 10.0 #:fpcore (acsch x)]
203+
[acoth.f64 #:spec (atanh (/ 1 x)) #:impl (from-rival) #:cost 7.0 #:fpcore (acoth x)]
204+
[sind.f64 #:spec (sin (* x (/ (PI) 180))) #:impl (from-rival) #:cost 6.0 #:fpcore (sind x)]
205+
[cosd.f64 #:spec (cos (* x (/ (PI) 180))) #:impl (from-rival) #:cost 6.5 #:fpcore (cosd x)]
206+
[tand.f64 #:spec (tan (* x (/ (PI) 180))) #:impl (from-rival) #:cost 13.0 #:fpcore (tand x)]
207+
[cotd.f64 #:spec (/ 1 (tan (* x (/ (PI) 180)))) #:impl (from-rival) #:cost 14.0 #:fpcore (cotd x)]
208+
[asind.f64 #:spec (* (asin x) (/ 180 (PI))) #:impl (from-rival) #:cost 4.5 #:fpcore (asind x)]
209+
[acosd.f64 #:spec (* (acos x) (/ 180 (PI))) #:impl (from-rival) #:cost 4.0 #:fpcore (acosd x)]
210+
[atand.f64 #:spec (* (atan x) (/ 180 (PI))) #:impl (from-rival) #:cost 6.0 #:fpcore (atand x)]
211+
[acotd.f64 #:spec (* (atan (/ 1 x)) (/ 180 (PI))) #:impl (from-rival) #:cost 8.0 #:fpcore (acotd x)]
212+
[asecd.f64 #:spec (* (acos (/ 1 x)) (/ 180 (PI))) #:impl (from-rival) #:cost 5.0 #:fpcore (asecd x)]
213+
[acscd.f64 #:spec (* (asin (/ 1 x)) (/ 180 (PI))) #:impl (from-rival) #:cost 6.5 #:fpcore (acscd x)]
214+
[secd.f64 #:spec (/ 1 (cos (* x (/ (PI) 180)))) #:impl (from-rival) #:cost 8.0 #:fpcore (secd x)]
215+
[cscd.f64 #:spec (/ 1 (sin (* x (/ (PI) 180)))) #:impl (from-rival) #:cost 6.5 #:fpcore (cscd x)]
216+
[sinpi.f64 #:spec (sin (* (* x (PI)) (/ (PI) 180))) #:impl (from-rival) #:cost 5.0 #:fpcore (sinpi x)]
217+
[cospi.f64 #:spec (cos (* (* x (PI)) (/ (PI) 180))) #:impl (from-rival) #:cost 5.0 #:fpcore (cospi x)])
218+
219+
;; Ternary fused multiply-add operation
220+
(define-operation (fma.f64 [x <binary64>] [y <binary64>] [z <binary64>]) <binary64>
221+
#:spec (+ (* x y) z) #:impl (from-libm 'fma)
222+
#:fpcore (! :precision binary64 (fma x y z)) #:cost 1.0)

0 commit comments

Comments
 (0)