| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
(define (run-bench name count ok? run) |
| 5 |
(let loop ((i 0) (result (list 'undefined))) |
| 6 |
(if (< i count) |
| 7 |
(loop (+ i 1) (run)) |
| 8 |
result))) |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
(define (run-benchmark name count ok? run-maker . args) |
| 13 |
(newline) |
| 14 |
(let* ((run (apply run-maker args)) |
| 15 |
(t0 (runtime)) |
| 16 |
(result (run-bench name count ok? run)) |
| 17 |
(t1 (runtime)) |
| 18 |
(t (inexact->exact (round (* 1000 (- t1 t0)))))) |
| 19 |
|
| 20 |
(display "cpu time: ") |
| 21 |
(write t) |
| 22 |
(display " real time: ") |
| 23 |
(write t) |
| 24 |
(newline) |
| 25 |
|
| 26 |
(if (not (ok? result)) |
| 27 |
(begin |
| 28 |
(display "*** wrong result ***") |
| 29 |
(newline) |
| 30 |
(display "*** got: ") |
| 31 |
(write result) |
| 32 |
(newline)))) |
| 33 |
(exit 0)) |
| 34 |
|
| 35 |
(define (fatal-error . args) |
| 36 |
(apply error #f args)) |
| 37 |
|
| 38 |
(define (call-with-output-file/truncate filename proc) |
| 39 |
(call-with-output-file filename proc 'truncate)) |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
(if-fixflo |
| 46 |
|
| 47 |
(begin |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
(define-syntax FLOATvector-const |
| 52 |
(syntax-rules () |
| 53 |
((FLOATvector-const x ...) '#(x ...)))) |
| 54 |
|
| 55 |
(define-syntax FLOATvector? |
| 56 |
(syntax-rules () |
| 57 |
((FLOATvector? x) (vector? x)))) |
| 58 |
|
| 59 |
(define-syntax FLOATvector |
| 60 |
(syntax-rules () |
| 61 |
((FLOATvector x ...) (vector x ...)))) |
| 62 |
|
| 63 |
(define-syntax FLOATmake-vector |
| 64 |
(syntax-rules () |
| 65 |
((FLOATmake-vector n) (make-vector n 0.0)) |
| 66 |
((FLOATmake-vector n init) (make-vector n init)))) |
| 67 |
|
| 68 |
(define-syntax FLOATvector-ref |
| 69 |
(syntax-rules () |
| 70 |
((FLOATvector-ref v i) (vector-ref v i)))) |
| 71 |
|
| 72 |
(define-syntax FLOATvector-set! |
| 73 |
(syntax-rules () |
| 74 |
((FLOATvector-set! v i x) (vector-set! v i x)))) |
| 75 |
|
| 76 |
(define-syntax FLOATvector-length |
| 77 |
(syntax-rules () |
| 78 |
((FLOATvector-length v) (vector-length v)))) |
| 79 |
|
| 80 |
(define-syntax nuc-const |
| 81 |
(syntax-rules () |
| 82 |
((FLOATnuc-const x ...) '#(x ...)))) |
| 83 |
|
| 84 |
(define-syntax FLOAT+ |
| 85 |
(syntax-rules () |
| 86 |
((FLOAT+ x ...) (fl+ x ...)))) |
| 87 |
|
| 88 |
(define-syntax FLOAT- |
| 89 |
(syntax-rules () |
| 90 |
((FLOAT- x ...) (fl- x ...)))) |
| 91 |
|
| 92 |
(define-syntax FLOAT* |
| 93 |
(syntax-rules () |
| 94 |
((FLOAT* x ...) (fl* x ...)))) |
| 95 |
|
| 96 |
(define-syntax FLOAT/ |
| 97 |
(syntax-rules () |
| 98 |
((FLOAT/ x ...) (/ x ...)))) |
| 99 |
|
| 100 |
(define-syntax FLOAT= |
| 101 |
(syntax-rules () |
| 102 |
((FLOAT= x y) (fl= x y)))) |
| 103 |
|
| 104 |
(define-syntax FLOAT< |
| 105 |
(syntax-rules () |
| 106 |
((FLOAT< x y) (fl< x y)))) |
| 107 |
|
| 108 |
(define-syntax FLOAT<= |
| 109 |
(syntax-rules () |
| 110 |
((FLOAT<= x y) (fl<= x y)))) |
| 111 |
|
| 112 |
(define-syntax FLOAT> |
| 113 |
(syntax-rules () |
| 114 |
((FLOAT> x y) (fl> x y)))) |
| 115 |
|
| 116 |
(define-syntax FLOAT>= |
| 117 |
(syntax-rules () |
| 118 |
((FLOAT>= x y) (fl>= x y)))) |
| 119 |
|
| 120 |
(define-syntax FLOATnegative? |
| 121 |
(syntax-rules () |
| 122 |
((FLOATnegative? x) (fl< x 0.0)))) |
| 123 |
|
| 124 |
(define-syntax FLOATpositive? |
| 125 |
(syntax-rules () |
| 126 |
((FLOATpositive? x) (fl< 0.0 x)))) |
| 127 |
|
| 128 |
(define-syntax FLOATzero? |
| 129 |
(syntax-rules () |
| 130 |
((FLOATzero? x) (fl= 0.0 x)))) |
| 131 |
|
| 132 |
(define-syntax FLOATabs |
| 133 |
(syntax-rules () |
| 134 |
((FLOATabs x) (abs x)))) |
| 135 |
|
| 136 |
(define-syntax FLOATsin |
| 137 |
(syntax-rules () |
| 138 |
((FLOATsin x) (sin x)))) |
| 139 |
|
| 140 |
(define-syntax FLOATcos |
| 141 |
(syntax-rules () |
| 142 |
((FLOATcos x) (cos x)))) |
| 143 |
|
| 144 |
(define-syntax FLOATatan |
| 145 |
(syntax-rules () |
| 146 |
((FLOATatan x) (atan x)))) |
| 147 |
|
| 148 |
(define-syntax FLOATsqrt |
| 149 |
(syntax-rules () |
| 150 |
((FLOATsqrt x) (sqrt x)))) |
| 151 |
|
| 152 |
(define-syntax FLOATmin |
| 153 |
(syntax-rules () |
| 154 |
((FLOATmin x y) (min x y)))) |
| 155 |
|
| 156 |
(define-syntax FLOATmax |
| 157 |
(syntax-rules () |
| 158 |
((FLOATmax x y) (max x y)))) |
| 159 |
|
| 160 |
(define-syntax FLOATround |
| 161 |
(syntax-rules () |
| 162 |
((FLOATround x) (round x)))) |
| 163 |
|
| 164 |
(define-syntax FLOATinexact->exact |
| 165 |
(syntax-rules () |
| 166 |
((FLOATinexact->exact x) (inexact->exact x)))) |
| 167 |
|
| 168 |
(define (GENERIC+ x y) (+ x y)) |
| 169 |
(define (GENERIC- x y) (- x y)) |
| 170 |
(define (GENERIC* x y) (* x y)) |
| 171 |
(define (GENERIC/ x y) (/ x y)) |
| 172 |
(define (GENERICquotient x y) (quotient x y)) |
| 173 |
(define (GENERICremainder x y) (remainder x y)) |
| 174 |
(define (GENERICmodulo x y) (modulo x y)) |
| 175 |
(define (GENERIC= x y) (= x y)) |
| 176 |
(define (GENERIC< x y) (< x y)) |
| 177 |
(define (GENERIC<= x y) (<= x y)) |
| 178 |
(define (GENERIC> x y) (> x y)) |
| 179 |
(define (GENERIC>= x y) (>= x y)) |
| 180 |
(define (GENERICexpt x y) (expt x y)) |
| 181 |
|
| 182 |
(define-syntax + |
| 183 |
(syntax-rules () |
| 184 |
((+ x ...) (fx+ x ...)))) |
| 185 |
|
| 186 |
(define-syntax - |
| 187 |
(syntax-rules () |
| 188 |
((- x ...) (fx- x ...)))) |
| 189 |
|
| 190 |
(define-syntax * |
| 191 |
(syntax-rules () |
| 192 |
((* x ...) (fx* x ...)))) |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
(define-syntax = |
| 207 |
(syntax-rules () |
| 208 |
((= x y) (fx= x y)))) |
| 209 |
|
| 210 |
(define-syntax < |
| 211 |
(syntax-rules () |
| 212 |
((< x y) (fx< x y)))) |
| 213 |
|
| 214 |
(define-syntax <= |
| 215 |
(syntax-rules () |
| 216 |
((<= x y) (fx<= x y)))) |
| 217 |
|
| 218 |
(define-syntax > |
| 219 |
(syntax-rules () |
| 220 |
((> x y) (fx> x y)))) |
| 221 |
|
| 222 |
(define-syntax >= |
| 223 |
(syntax-rules () |
| 224 |
((>= x y) (fx>= x y)))) |
| 225 |
|
| 226 |
(define-syntax negative? |
| 227 |
(syntax-rules () |
| 228 |
((negative? x) (fxnegative? x)))) |
| 229 |
|
| 230 |
(define-syntax positive? |
| 231 |
(syntax-rules () |
| 232 |
((positive? x) (fxpositive? x)))) |
| 233 |
|
| 234 |
(define-syntax zero? |
| 235 |
(syntax-rules () |
| 236 |
((zero? x) (fxzero? x)))) |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
(define-syntax bitwise-or |
| 247 |
(syntax-rules () |
| 248 |
((bitwise-or x y) (fxlogior x y)))) |
| 249 |
|
| 250 |
(define-syntax bitwise-and |
| 251 |
(syntax-rules () |
| 252 |
((bitwise-and x y) (fxlogand x y)))) |
| 253 |
|
| 254 |
(define-syntax bitwise-not |
| 255 |
(syntax-rules () |
| 256 |
((bitwise-not x) (fxlognot x)))) |
| 257 |
) |
| 258 |
|
| 259 |
(begin |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
(define-syntax FLOATvector-const |
| 264 |
(syntax-rules () |
| 265 |
((FLOATvector-const x ...) '#(x ...)))) |
| 266 |
|
| 267 |
(define-syntax FLOATvector? |
| 268 |
(syntax-rules () |
| 269 |
((FLOATvector? x) (vector? x)))) |
| 270 |
|
| 271 |
(define-syntax FLOATvector |
| 272 |
(syntax-rules () |
| 273 |
((FLOATvector x ...) (vector x ...)))) |
| 274 |
|
| 275 |
(define-syntax FLOATmake-vector |
| 276 |
(syntax-rules () |
| 277 |
((FLOATmake-vector n) (make-vector n 0.0)) |
| 278 |
((FLOATmake-vector n init) (make-vector n init)))) |
| 279 |
|
| 280 |
(define-syntax FLOATvector-ref |
| 281 |
(syntax-rules () |
| 282 |
((FLOATvector-ref v i) (vector-ref v i)))) |
| 283 |
|
| 284 |
(define-syntax FLOATvector-set! |
| 285 |
(syntax-rules () |
| 286 |
((FLOATvector-set! v i x) (vector-set! v i x)))) |
| 287 |
|
| 288 |
(define-syntax FLOATvector-length |
| 289 |
(syntax-rules () |
| 290 |
((FLOATvector-length v) (vector-length v)))) |
| 291 |
|
| 292 |
(define-syntax nuc-const |
| 293 |
(syntax-rules () |
| 294 |
((FLOATnuc-const x ...) '#(x ...)))) |
| 295 |
|
| 296 |
(define-syntax FLOAT+ |
| 297 |
(syntax-rules () |
| 298 |
((FLOAT+ x ...) (+ x ...)))) |
| 299 |
|
| 300 |
(define-syntax FLOAT- |
| 301 |
(syntax-rules () |
| 302 |
((FLOAT- x ...) (- x ...)))) |
| 303 |
|
| 304 |
(define-syntax FLOAT* |
| 305 |
(syntax-rules () |
| 306 |
((FLOAT* x ...) (* x ...)))) |
| 307 |
|
| 308 |
(define-syntax FLOAT/ |
| 309 |
(syntax-rules () |
| 310 |
((FLOAT/ x ...) (/ x ...)))) |
| 311 |
|
| 312 |
(define-syntax FLOAT= |
| 313 |
(syntax-rules () |
| 314 |
((FLOAT= x y) (= x y)))) |
| 315 |
|
| 316 |
(define-syntax FLOAT< |
| 317 |
(syntax-rules () |
| 318 |
((FLOAT< x y) (< x y)))) |
| 319 |
|
| 320 |
(define-syntax FLOAT<= |
| 321 |
(syntax-rules () |
| 322 |
((FLOAT<= x y) (<= x y)))) |
| 323 |
|
| 324 |
(define-syntax FLOAT> |
| 325 |
(syntax-rules () |
| 326 |
((FLOAT> x y) (> x y)))) |
| 327 |
|
| 328 |
(define-syntax FLOAT>= |
| 329 |
(syntax-rules () |
| 330 |
((FLOAT>= x y) (>= x y)))) |
| 331 |
|
| 332 |
(define-syntax FLOATnegative? |
| 333 |
(syntax-rules () |
| 334 |
((FLOATnegative? x) (negative? x)))) |
| 335 |
|
| 336 |
(define-syntax FLOATpositive? |
| 337 |
(syntax-rules () |
| 338 |
((FLOATpositive? x) (positive? x)))) |
| 339 |
|
| 340 |
(define-syntax FLOATzero? |
| 341 |
(syntax-rules () |
| 342 |
((FLOATzero? x) (zero? x)))) |
| 343 |
|
| 344 |
(define-syntax FLOATabs |
| 345 |
(syntax-rules () |
| 346 |
((FLOATabs x) (abs x)))) |
| 347 |
|
| 348 |
(define-syntax FLOATsin |
| 349 |
(syntax-rules () |
| 350 |
((FLOATsin x) (sin x)))) |
| 351 |
|
| 352 |
(define-syntax FLOATcos |
| 353 |
(syntax-rules () |
| 354 |
((FLOATcos x) (cos x)))) |
| 355 |
|
| 356 |
(define-syntax FLOATatan |
| 357 |
(syntax-rules () |
| 358 |
((FLOATatan x) (atan x)))) |
| 359 |
|
| 360 |
(define-syntax FLOATsqrt |
| 361 |
(syntax-rules () |
| 362 |
((FLOATsqrt x) (sqrt x)))) |
| 363 |
|
| 364 |
(define-syntax FLOATmin |
| 365 |
(syntax-rules () |
| 366 |
((FLOATmin x y) (min x y)))) |
| 367 |
|
| 368 |
(define-syntax FLOATmax |
| 369 |
(syntax-rules () |
| 370 |
((FLOATmax x y) (max x y)))) |
| 371 |
|
| 372 |
(define-syntax FLOATround |
| 373 |
(syntax-rules () |
| 374 |
((FLOATround x) (round x)))) |
| 375 |
|
| 376 |
(define-syntax FLOATinexact->exact |
| 377 |
(syntax-rules () |
| 378 |
((FLOATinexact->exact x) (inexact->exact x)))) |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
(define-syntax GENERIC+ |
| 383 |
(syntax-rules () |
| 384 |
((GENERIC+ x ...) (+ x ...)))) |
| 385 |
|
| 386 |
(define-syntax GENERIC- |
| 387 |
(syntax-rules () |
| 388 |
((GENERIC- x ...) (- x ...)))) |
| 389 |
|
| 390 |
(define-syntax GENERIC* |
| 391 |
(syntax-rules () |
| 392 |
((GENERIC* x ...) (* x ...)))) |
| 393 |
|
| 394 |
(define-syntax GENERIC/ |
| 395 |
(syntax-rules () |
| 396 |
((GENERIC/ x ...) (/ x ...)))) |
| 397 |
|
| 398 |
(define-syntax GENERICquotient |
| 399 |
(syntax-rules () |
| 400 |
((GENERICquotient x y) (quotient x y)))) |
| 401 |
|
| 402 |
(define-syntax GENERICremainder |
| 403 |
(syntax-rules () |
| 404 |
((GENERICremainder x y) (remainder x y)))) |
| 405 |
|
| 406 |
(define-syntax GENERICmodulo |
| 407 |
(syntax-rules () |
| 408 |
((GENERICmodulo x y) (modulo x y)))) |
| 409 |
|
| 410 |
(define-syntax GENERIC= |
| 411 |
(syntax-rules () |
| 412 |
((GENERIC= x y) (= x y)))) |
| 413 |
|
| 414 |
(define-syntax GENERIC< |
| 415 |
(syntax-rules () |
| 416 |
((GENERIC< x y) (< x y)))) |
| 417 |
|
| 418 |
(define-syntax GENERIC<= |
| 419 |
(syntax-rules () |
| 420 |
((GENERIC<= x y) (<= x y)))) |
| 421 |
|
| 422 |
(define-syntax GENERIC> |
| 423 |
(syntax-rules () |
| 424 |
((GENERIC> x y) (> x y)))) |
| 425 |
|
| 426 |
(define-syntax GENERIC>= |
| 427 |
(syntax-rules () |
| 428 |
((GENERIC>= x y) (>= x y)))) |
| 429 |
|
| 430 |
(define-syntax GENERICexpt |
| 431 |
(syntax-rules () |
| 432 |
((GENERICexpt x y) (expt x y)))) |
| 433 |
) |
| 434 |
) |
| 435 |
|
| 436 |
|