123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- ;INSERTCODE
- ;------------------------------------------------------------------------------
- (define (run-bench name count ok? run)
- (let loop ((i 0) (result (list 'undefined)))
- (if (< i count)
- (loop (+ i 1) (run))
- result)))
- (define (run-benchmark name count ok? run-maker . args)
- (newline)
- (let* ((run (apply run-maker args))
- (result (time (run-bench name count ok? run))))
- (if (not (ok? result))
- (begin
- (display "*** wrong result ***")
- (newline)
- (display "*** got: ")
- (write result)
- (newline))))
- (exit 0))
- (define (fatal-error . args)
- (apply error #f args))
- (define (call-with-output-file/truncate filename proc)
- (call-with-output-file filename proc 'truncate))
- ;------------------------------------------------------------------------------
- ; Macros...
- (if-fixflo
- (begin
- ; Specialize fixnum and flonum arithmetic.
- (define-syntax FLOATvector-const
- (syntax-rules ()
- ((FLOATvector-const x ...) '#(x ...))))
- (define-syntax FLOATvector?
- (syntax-rules ()
- ((FLOATvector? x) (vector? x))))
- (define-syntax FLOATvector
- (syntax-rules ()
- ((FLOATvector x ...) (vector x ...))))
- (define-syntax FLOATmake-vector
- (syntax-rules ()
- ((FLOATmake-vector n) (make-vector n 0.0))
- ((FLOATmake-vector n init) (make-vector n init))))
- (define-syntax FLOATvector-ref
- (syntax-rules ()
- ((FLOATvector-ref v i) (vector-ref v i))))
- (define-syntax FLOATvector-set!
- (syntax-rules ()
- ((FLOATvector-set! v i x) (vector-set! v i x))))
- (define-syntax FLOATvector-length
- (syntax-rules ()
- ((FLOATvector-length v) (vector-length v))))
- (define-syntax nuc-const
- (syntax-rules ()
- ((FLOATnuc-const x ...) '#(x ...))))
- (define-syntax FLOAT+
- (syntax-rules ()
- ((FLOAT+ x ...) (fl+ x ...))))
- (define-syntax FLOAT-
- (syntax-rules ()
- ((FLOAT- x ...) (fl- x ...))))
- (define-syntax FLOAT*
- (syntax-rules ()
- ((FLOAT* x ...) (fl* x ...))))
- (define-syntax FLOAT/
- (syntax-rules ()
- ((FLOAT/ x ...) (fl/ x ...))))
- (define-syntax FLOAT=
- (syntax-rules ()
- ((FLOAT= x y) (fl= x y))))
- (define-syntax FLOAT<
- (syntax-rules ()
- ((FLOAT< x y) (fl< x y))))
- (define-syntax FLOAT<=
- (syntax-rules ()
- ((FLOAT<= x y) (fl<= x y))))
- (define-syntax FLOAT>
- (syntax-rules ()
- ((FLOAT> x y) (fl> x y))))
- (define-syntax FLOAT>=
- (syntax-rules ()
- ((FLOAT>= x y) (fl>= x y))))
- (define-syntax FLOATnegative?
- (syntax-rules ()
- ((FLOATnegative? x) (flnegative? x))))
- (define-syntax FLOATpositive?
- (syntax-rules ()
- ((FLOATpositive? x) (flpositive? x))))
- (define-syntax FLOATzero?
- (syntax-rules ()
- ((FLOATzero? x) (flzero? x))))
- (define-syntax FLOATabs
- (syntax-rules ()
- ((FLOATabs x) (flabs x))))
- (define-syntax FLOATsin
- (syntax-rules ()
- ((FLOATsin x) (flsin x))))
- (define-syntax FLOATcos
- (syntax-rules ()
- ((FLOATcos x) (flcos x))))
- (define-syntax FLOATatan
- (syntax-rules ()
- ((FLOATatan x) (flatan x))))
- (define-syntax FLOATsqrt
- (syntax-rules ()
- ((FLOATsqrt x) (flsqrt x))))
- (define-syntax FLOATmin
- (syntax-rules ()
- ((FLOATmin x y) (flmin x y))))
- (define-syntax FLOATmax
- (syntax-rules ()
- ((FLOATmax x y) (flmax x y))))
- (define-syntax FLOATround
- (syntax-rules ()
- ((FLOATround x) (flround x))))
- (define-syntax FLOATinexact->exact
- (syntax-rules ()
- ((FLOATinexact->exact x) (inexact->exact x))))
- (define (GENERIC+ x y) (+ x y))
- (define (GENERIC- x y) (- x y))
- (define (GENERIC* x y) (* x y))
- (define (GENERIC/ x y) (/ x y))
- (define (GENERICquotient x y) (quotient x y))
- (define (GENERICremainder x y) (remainder x y))
- (define (GENERICmodulo x y) (modulo x y))
- (define (GENERIC= x y) (= x y))
- (define (GENERIC< x y) (< x y))
- (define (GENERIC<= x y) (<= x y))
- (define (GENERIC> x y) (> x y))
- (define (GENERIC>= x y) (>= x y))
- (define (GENERICexpt x y) (expt x y))
- (define-syntax +
- (syntax-rules ()
- ((+ x ...) (fx+ x ...))))
- (define-syntax -
- (syntax-rules ()
- ((- x ...) (fx- x ...))))
- (define-syntax *
- (syntax-rules ()
- ((* x ...) (fx* x ...))))
- (define-syntax quotient
- (syntax-rules ()
- ((quotient x ...) (fxquotient x ...))))
- (define-syntax modulo
- (syntax-rules ()
- ((modulo x ...) (fxmodulo x ...))))
- (define-syntax remainder
- (syntax-rules ()
- ((remainder x ...) (fxremainder x ...))))
- (define-syntax =
- (syntax-rules ()
- ((= x y) (fx= x y))))
- (define-syntax <
- (syntax-rules ()
- ((< x y) (fx< x y))))
- (define-syntax <=
- (syntax-rules ()
- ((<= x y) (fx<= x y))))
- (define-syntax >
- (syntax-rules ()
- ((> x y) (fx> x y))))
- (define-syntax >=
- (syntax-rules ()
- ((>= x y) (fx>= x y))))
- (define-syntax negative?
- (syntax-rules ()
- ((negative? x) (fxnegative? x))))
- (define-syntax positive?
- (syntax-rules ()
- ((positive? x) (fxpositive? x))))
- (define-syntax zero?
- (syntax-rules ()
- ((zero? x) (fxzero? x))))
- (define-syntax odd?
- (syntax-rules ()
- ((odd? x) (fxodd? x))))
- (define-syntax even?
- (syntax-rules ()
- ((even? x) (fxeven? x))))
- (define-syntax bitwise-or
- (syntax-rules ()
- ((bitwise-or x y) (fxior x y))))
- (define-syntax bitwise-and
- (syntax-rules ()
- ((bitwise-and x y) (fxand x y))))
- (define-syntax bitwise-not
- (syntax-rules ()
- ((bitwise-not x) (fxnot x))))
- )
- (begin
- ; Don't specialize fixnum and flonum arithmetic.
- (define-syntax FLOATvector-const
- (syntax-rules ()
- ((FLOATvector-const x ...) '#(x ...))))
- (define-syntax FLOATvector?
- (syntax-rules ()
- ((FLOATvector? x) (vector? x))))
- (define-syntax FLOATvector
- (syntax-rules ()
- ((FLOATvector x ...) (vector x ...))))
- (define-syntax FLOATmake-vector
- (syntax-rules ()
- ((FLOATmake-vector n) (make-vector n 0.0))
- ((FLOATmake-vector n init) (make-vector n init))))
- (define-syntax FLOATvector-ref
- (syntax-rules ()
- ((FLOATvector-ref v i) (vector-ref v i))))
- (define-syntax FLOATvector-set!
- (syntax-rules ()
- ((FLOATvector-set! v i x) (vector-set! v i x))))
- (define-syntax FLOATvector-length
- (syntax-rules ()
- ((FLOATvector-length v) (vector-length v))))
- (define-syntax nuc-const
- (syntax-rules ()
- ((FLOATnuc-const x ...) '#(x ...))))
- (define-syntax FLOAT+
- (syntax-rules ()
- ((FLOAT+ x ...) (+ x ...))))
- (define-syntax FLOAT-
- (syntax-rules ()
- ((FLOAT- x ...) (- x ...))))
- (define-syntax FLOAT*
- (syntax-rules ()
- ((FLOAT* x ...) (* x ...))))
- (define-syntax FLOAT/
- (syntax-rules ()
- ((FLOAT/ x ...) (/ x ...))))
- (define-syntax FLOAT=
- (syntax-rules ()
- ((FLOAT= x y) (= x y))))
- (define-syntax FLOAT<
- (syntax-rules ()
- ((FLOAT< x y) (< x y))))
- (define-syntax FLOAT<=
- (syntax-rules ()
- ((FLOAT<= x y) (<= x y))))
- (define-syntax FLOAT>
- (syntax-rules ()
- ((FLOAT> x y) (> x y))))
- (define-syntax FLOAT>=
- (syntax-rules ()
- ((FLOAT>= x y) (>= x y))))
- (define-syntax FLOATnegative?
- (syntax-rules ()
- ((FLOATnegative? x) (negative? x))))
- (define-syntax FLOATpositive?
- (syntax-rules ()
- ((FLOATpositive? x) (positive? x))))
- (define-syntax FLOATzero?
- (syntax-rules ()
- ((FLOATzero? x) (zero? x))))
- (define-syntax FLOATabs
- (syntax-rules ()
- ((FLOATabs x) (abs x))))
- (define-syntax FLOATsin
- (syntax-rules ()
- ((FLOATsin x) (sin x))))
- (define-syntax FLOATcos
- (syntax-rules ()
- ((FLOATcos x) (cos x))))
- (define-syntax FLOATatan
- (syntax-rules ()
- ((FLOATatan x) (atan x))))
- (define-syntax FLOATsqrt
- (syntax-rules ()
- ((FLOATsqrt x) (sqrt x))))
- (define-syntax FLOATmin
- (syntax-rules ()
- ((FLOATmin x y) (min x y))))
- (define-syntax FLOATmax
- (syntax-rules ()
- ((FLOATmax x y) (max x y))))
- (define-syntax FLOATround
- (syntax-rules ()
- ((FLOATround x) (round x))))
- (define-syntax FLOATinexact->exact
- (syntax-rules ()
- ((FLOATinexact->exact x) (inexact->exact x))))
- ; Generic arithmetic.
- (define-syntax GENERIC+
- (syntax-rules ()
- ((GENERIC+ x ...) (+ x ...))))
- (define-syntax GENERIC-
- (syntax-rules ()
- ((GENERIC- x ...) (- x ...))))
- (define-syntax GENERIC*
- (syntax-rules ()
- ((GENERIC* x ...) (* x ...))))
- (define-syntax GENERIC/
- (syntax-rules ()
- ((GENERIC/ x ...) (/ x ...))))
- (define-syntax GENERICquotient
- (syntax-rules ()
- ((GENERICquotient x y) (quotient x y))))
- (define-syntax GENERICremainder
- (syntax-rules ()
- ((GENERICremainder x y) (remainder x y))))
- (define-syntax GENERICmodulo
- (syntax-rules ()
- ((GENERICmodulo x y) (modulo x y))))
- (define-syntax GENERIC=
- (syntax-rules ()
- ((GENERIC= x y) (= x y))))
- (define-syntax GENERIC<
- (syntax-rules ()
- ((GENERIC< x y) (< x y))))
- (define-syntax GENERIC<=
- (syntax-rules ()
- ((GENERIC<= x y) (<= x y))))
- (define-syntax GENERIC>
- (syntax-rules ()
- ((GENERIC> x y) (> x y))))
- (define-syntax GENERIC>=
- (syntax-rules ()
- ((GENERIC>= x y) (>= x y))))
- (define-syntax GENERICexpt
- (syntax-rules ()
- ((GENERICexpt x y) (expt x y))))
- )
- )
- ;------------------------------------------------------------------------------
|