File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change 55 ffi/unsafe)
66
77(require "../core/rival.rkt "
8+ "../config.rkt "
89 "types.rkt " )
910
1011(provide from-rival
2425
2526; ----------------------- RIVAL GENERATOR ---------------------------
2627
27- (define-generator ((from-rival) spec ctx)
28+ (define/reset caches
29+ '()
30+ (lambda ()
31+ (for ([cache (caches)])
32+ (hash-clear! cache))))
33+
34+ (define-generator ((from-rival #:cache? [cache? #t ]) spec ctx)
2835 (define compiler (make-real-compiler (list spec) (list ctx)))
2936 (define fail ((representation-bf->repr (context-repr ctx)) +nan.bf))
30- (lambda pt
37+ (define (compute . pt)
3138 (define-values (_ exs) (real-apply compiler (list->vector pt)))
3239 (if exs
3340 (first exs)
34- fail)))
41+ fail))
42+ (cond
43+ [cache?
44+ (define cache (make-hash))
45+ (caches (cons cache (caches)))
46+ (lambda pt (hash-ref! cache pt (lambda () (apply compute pt))))]
47+ [else compute]))
3548
3649; ----------------------- FFI GENERATOR -----------------------------
3750
Original file line number Diff line number Diff line change @@ -409,7 +409,10 @@ <h3>Hard-to-emulate Operations</h3>
409409 operation's specification. Compilation is usually < em > much</ em >
410410 slower than with a native floating-point implementation, but for
411411 unusual operations that are difficult to implement otherwise, it can
412- still allow compilation to proceed.</ p >
412+ still allow compilation to proceed. There is an
413+ optional < code > #:cache?</ code > argument to < code > from-rival</ code > ,
414+ on by default. The cache makes Herbie much faster but uses a lot of
415+ memory.</ p >
413416
414417 < p > Note that < code > from-rival</ code > implementations are always
415418 "correctly-rounded", meaning as accurate as possible. Most targets
You can’t perform that action at this time.
0 commit comments