|
5 | 5 |
|
6 | 6 | (require math/bigfloat |
7 | 7 | math/flonum |
8 | | - "runtime/float32.rkt" ; float representation helper functions |
9 | 8 | "runtime/libm.rkt" ; libm wrapper |
10 | 9 | "../utils/float.rkt" ; for shift/unshift |
11 | 10 | "../syntax/platform.rkt") |
|
16 | 15 | (define 32bit-move-cost 0.12961999999999974) |
17 | 16 | (define boolean-move-cost 0.1) |
18 | 17 |
|
19 | | -(define c-platform |
| 18 | +(define platform |
20 | 19 | (make-empty-platform 'c #:if-cost boolean-move-cost)) |
21 | 20 |
|
22 | 21 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; BOOLEAN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
34 | 33 | #:total-bits 1 |
35 | 34 | #:special-value? (const #f))) |
36 | 35 |
|
37 | | -(platform-register-representation! c-platform #:repr bool #:cost boolean-move-cost) |
| 36 | +(platform-register-representation! platform #:repr bool #:cost boolean-move-cost) |
38 | 37 |
|
39 | 38 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; constants ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
40 | 39 |
|
41 | 40 | (platform-register-implementations! |
42 | | - c-platform |
| 41 | + platform |
43 | 42 | ([TRUE () bool (TRUE) (const true) (! TRUE) boolean-move-cost] |
44 | 43 | [FALSE () bool (FALSE) (const false) (! FALSE) boolean-move-cost])) |
45 | 44 |
|
|
51 | 50 | (ormap identity as)) |
52 | 51 |
|
53 | 52 | (platform-register-implementations! |
54 | | - c-platform |
| 53 | + platform |
55 | 54 | ([not ([x : bool]) bool (not x) not (not x) boolean-move-cost] |
56 | 55 | [and ([x : bool] [y : bool]) bool (and x y) and-fn (and x y) boolean-move-cost] |
57 | 56 | [or ([x : bool] [y : bool]) bool (or x y) or-fn (or x y) boolean-move-cost])) |
|
71 | 70 | #:total-bits 32 |
72 | 71 | #:special-value? nan?)) |
73 | 72 |
|
74 | | -(platform-register-representation! c-platform #:repr binary32 #:cost 32bit-move-cost) |
| 73 | +(platform-register-representation! platform #:repr binary32 #:cost 32bit-move-cost) |
75 | 74 |
|
76 | 75 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; constants ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
77 | 76 |
|
78 | 77 | (platform-register-implementations! |
79 | | - c-platform |
| 78 | + platform |
80 | 79 | ([PI.f32 () binary32 (PI) (const (flsingle pi)) (! :precision binary32 (PI)) 32bit-move-cost] |
81 | 80 | [E.f32 () binary32 (E) (const (flsingle (exp 1.0))) (! :precision binary32 (E)) 32bit-move-cost] |
82 | 81 | [INFINITY.f32 () binary32 (INFINITY) (const +inf.0) (! :precision binary32 (INFINITY)) 32bit-move-cost] |
|
86 | 85 |
|
87 | 86 | ; ([name ([var : repr] ...) otype spec fl fpcore cost]) |
88 | 87 | (platform-register-implementations! |
89 | | - c-platform |
| 88 | + platform |
90 | 89 | ([neg.f32 ([x : binary32]) binary32 (neg x) fl32- (! :precision binary32 (- x)) 0.11567699999999992] |
91 | 90 | [+.f32 ([x : binary32] [y : binary32]) binary32 (+ x y) fl32+ (! :precision binary32 (+ x y)) 0.200445] |
92 | 91 | [-.f32 ([x : binary32] [y : binary32]) binary32 (- x y) fl32- (! :precision binary32 (- x y)) 0.19106800000000014] |
|
144 | 143 | [remainder 1.030245])])) |
145 | 144 |
|
146 | 145 | (for ([libm-impl.f32 (in-list libm-impls.f32)]) |
147 | | - (platform-register-implementation! c-platform libm-impl.f32)) |
| 146 | + (platform-register-implementation! platform libm-impl.f32)) |
148 | 147 |
|
149 | 148 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; libm accelerators ;;;;;;;;;;;;;;;;;;;;; |
150 | 149 |
|
|
156 | 155 |
|
157 | 156 | ; ([name ([var : repr] ...) otype spec fl fpcore cost]) |
158 | 157 | (platform-register-implementations! |
159 | | - c-platform |
| 158 | + platform |
160 | 159 | ([erfc.f32 ([x : binary32]) binary32 (- 1 (erf x)) c_erfcf (! :precision binary32 (erfc x)) 0.907758] |
161 | 160 | [expm1.f32 ([x : binary32]) binary32 (- (exp x) 1) c_expm1f (! :precision binary32 (expm1 x)) 0.906484] |
162 | 161 | [log1p.f32 ([x : binary32]) binary32 (log (+ 1 x)) c_log1pf (! :precision binary32 (log1p x)) 1.302969] |
|
178 | 177 | #:total-bits 64 |
179 | 178 | #:special-value? nan?)) |
180 | 179 |
|
181 | | -(platform-register-representation! c-platform #:repr binary64 #:cost 64bit-move-cost) |
| 180 | +(platform-register-representation! platform #:repr binary64 #:cost 64bit-move-cost) |
182 | 181 |
|
183 | 182 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; constants ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
184 | 183 |
|
185 | 184 | (platform-register-implementations! |
186 | | - c-platform |
| 185 | + platform |
187 | 186 | ([PI.f64 () binary64 (PI) (const pi) (! :precision binary64 (PI)) 64bit-move-cost] |
188 | 187 | [E.f64 () binary64 (E) (const (exp 1.0)) (! :precision binary64 (E)) 64bit-move-cost] |
189 | 188 | [INFINITY.f64 () binary64 (INFINITY) (const +inf.0) (! :precision binary64 (INFINITY)) 64bit-move-cost] |
|
192 | 191 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; operators ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
193 | 192 |
|
194 | 193 | (platform-register-implementations! |
195 | | - c-platform |
| 194 | + platform |
196 | 195 | ([neg.f64 ([x : binary64]) binary64 (neg x) - (! :precision binary64 (- x)) 0.12114199999999964] |
197 | 196 | [+.f64 ([x : binary64] [y : binary64]) binary64 (+ x y) + (! :precision binary64 (+ x y)) 0.2174189999999998] |
198 | 197 | [-.f64 ([x : binary64] [y : binary64]) binary64 (- x y) - (! :precision binary64 (- x y)) 0.20265700000000008] |
|
250 | 249 | [remainder 0.9494380000000005])])) |
251 | 250 |
|
252 | 251 | (for ([libm-impl.f64 (in-list libm-impls.f64)]) |
253 | | - (platform-register-implementation! c-platform libm-impl.f64)) |
| 252 | + (platform-register-implementation! platform libm-impl.f64)) |
254 | 253 |
|
255 | 254 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; libm accelerators ;;;;;;;;;;;;;;;;;;;;; |
256 | 255 |
|
|
262 | 261 |
|
263 | 262 | ; ([name ([var : repr] ...) otype spec fl fpcore cost]) |
264 | 263 | (platform-register-implementations! |
265 | | - c-platform |
| 264 | + platform |
266 | 265 | ([erfc.f64 ([x : binary64]) binary64 (- 1 (erf x)) c_erfc (! :precision binary64 (erfc x)) 0.8588620000000002] |
267 | 266 | [expm1.f64 ([x : binary64]) binary64 (- (exp x) 1) c_expm1 (! :precision binary64 (expm1 x)) 0.8483490000000002] |
268 | 267 | [log1p.f64 ([x : binary64]) binary64 (log (+ 1 x)) c_log1p (! :precision binary64 (log1p x)) 1.2416829999999997] |
|
271 | 270 |
|
272 | 271 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; additional converters ;;;;;;;;;;;;;;;;; |
273 | 272 |
|
274 | | -#;(platform-register-implementation! c-platform |
| 273 | +#;(platform-register-implementation! platform |
275 | 274 | (make-operator-impl (binary64->binary32 [x : binary64]) |
276 | 275 | binary32 |
277 | 276 | #:spec x |
278 | 277 | #:fpcore (! :precision binary32 (cast x)) |
279 | 278 | #:fl flsingle |
280 | 279 | #:cost 32bit-move-cost)) |
281 | 280 |
|
282 | | -#;(platform-register-implementation! c-platform |
| 281 | +#;(platform-register-implementation! platform |
283 | 282 | (make-operator-impl (binary32->binary64 [x : binary32]) |
284 | 283 | binary64 |
285 | 284 | #:spec x |
|
289 | 288 |
|
290 | 289 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; REGISTER PLATFORM ;;;;;;;;;;;;;;;;;;;;; |
291 | 290 |
|
292 | | -(register-platform! c-platform) |
| 291 | +(register-platform! platform) |
293 | 292 |
|
294 | 293 | (module+ main |
295 | | - (display-platform c-platform)) |
| 294 | + (display-platform platform)) |
296 | 295 |
|
297 | 296 | ;; Do not run this file during testing |
298 | 297 | (module test racket/base |
|
0 commit comments