Skip to content

Commit 2159334

Browse files
committed
really good optimizations
1 parent 0137ff0 commit 2159334

File tree

4 files changed

+92
-78
lines changed

4 files changed

+92
-78
lines changed

eval/adjust.rkt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
(define vbest-precs (rival-machine-best-known-precisions machine))
149149
(define current-iter (rival-machine-iteration machine))
150150
(define bumps (rival-machine-bumps machine))
151+
(define vinfo (rival-machine-tuning-info machine))
151152

152153
(define varc (vector-length args))
153154
(define vprecs-new (make-vector (vector-length ivec) 0)) ; new vprecs vector
@@ -178,7 +179,7 @@
178179
(vector-set! vrepeats (- arg varc) #f))]))
179180

180181
; Step 2. Precision tuning
181-
(precision-tuning ivec vregs vprecs-new varc vstart-precs vrepeats vhint)
182+
(precision-tuning ivec vregs vprecs-new varc vstart-precs vrepeats vhint vinfo)
182183

183184
; Step 3. Repeating precisions check + Assigning if a operation should be computed again at all
184185
; vrepeats[i] = #t if the node has the same precision as an iteration before and children have #t flag as well
@@ -217,12 +218,17 @@
217218
; clean progress of the current tuning pass and start over
218219
(vector-fill! vprecs-new 0)
219220
(vector-fill! vrepeats #f)
220-
(precision-tuning ivec vregs vprecs-new varc vstart-precs vrepeats vhint)
221+
(precision-tuning ivec vregs vprecs-new varc vstart-precs vrepeats vhint vinfo)
221222
(repeats)) ; do repeats again
222223

223224
; Step 5. Copying new precisions into vprecs
224225
(vector-copy! vprecs 0 vprecs-new))
225226

227+
(define (get-info! vinfo vregs)
228+
(for ([reg (in-vector vregs)]
229+
[n (in-naturals)])
230+
(vector-set! vinfo n (ival-info reg))))
231+
226232
; Usually, add-bang instructions have a pointer to itself that is needed to be dropped
227233
(define (drop-self-pointer tail-regs n)
228234
(if (empty? tail-regs)
@@ -235,15 +241,12 @@
235241
; Roughly speaking, the upper precision bound is calculated as:
236242
; vprecs-max[i] = (+ max-prec vstart-precs[i]), where min-prec < (+ max-prec vstart-precs[i]) < max-prec
237243
; max-prec = (car (get-bounds parent))
238-
(define (precision-tuning ivec vregs vprecs-max varc vstart-precs vrepeats vhint)
244+
(define (precision-tuning ivec vregs vprecs-max varc vstart-precs vrepeats vhint vinfo)
245+
(get-info! vinfo vregs)
239246
(define vprecs-min (make-vector (vector-length ivec) 0))
240-
241-
(define slack (get-slack))
242-
(define vinfo (vector-map (curryr ival+minlog+maxlog+logspan slack) vregs))
243-
244247
(for ([instr (in-vector ivec (- (vector-length ivec) 1) -1 -1)]
245248
[repeat? (in-vector vrepeats (- (vector-length vrepeats) 1) -1 -1)]
246-
[n (in-range (- (vector-length vregs) 1) -1 -1)]
249+
[n (in-range (- (vector-length vinfo) 1) -1 -1)]
247250
[hint (in-vector vhint (- (vector-length vhint) 1) -1 -1)]
248251
[output (in-vector vinfo (- (vector-length vinfo) 1) -1 -1)]
249252
#:when (and hint (not repeat?)))

eval/compile.rkt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@
278278
(define ivec-length (- (vector-length nodes) num-vars))
279279
(define register-count (+ (length vars) ivec-length))
280280
(define registers (make-vector register-count))
281+
(define tuning-info
282+
(make-vector register-count)) ; this vector will store maxlog, minlog, logspan info
281283

282284
(define instructions
283285
(for/vector #:length ivec-length
@@ -311,6 +313,7 @@
311313
best-known-precisions
312314
(make-vector (vector-length roots))
313315
default-hint
316+
tuning-info
314317
0
315318
0
316319
0

eval/machine.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
best-known-precisions
3434
output-distance
3535
default-hint
36+
tuning-info
3637
[iteration #:mutable]
3738
[bumps #:mutable]
3839
[profile-ptr #:mutable]

0 commit comments

Comments
 (0)