[Larceny-users] Commutativity
Jed Davis
jdev at panix.com
Fri Feb 9 21:20:39 EST 2007
On Wed, Feb 07, 2007 at 09:56:03PM -0500, Jed Davis wrote:
>
> (Note also the unnecessary soft register, but lamenting that is beyond
> the scope of this message.)
Well, this is... interesting. There are two casualties of the MacScheme
accumulator here, exemplified by:
1. (fx+ x 23) is (reg 1) (op2imm fx+ 23), while
(fx+ 23 x) is (const 23) (op2 fx+ 1).
2. (fx+ (car p) x) is (reg 2 .p|1) (op1 car:pair) (op2 fx+ 1), while
(fx+ x (car p)) is (reg 2 .p|1) (op1 car:pair) (setreg 3) (reg 1 .x|1) (op2 fx+ 3).
2'. More counterintuitively, (fx+ (car x) (cdr x)) is:
(reg 1 .x|1) (op1 car:pair) (setreg 3) (reg 1 .x|1)
(op1 cdr:pair) (setreg 2) (reg 3 .T7) (op2 fx+ 2)
but ((lambda (a d) (fx+ a d)) (car x) (cdr x)) is:
(reg 1 .x|1) (op1 cdr:pair) (setreg 3) (reg 1 .x|1)
(op1 car:pair) (op2 fx+ 3)
Assuming that it's a good idea to transform such calls by exchanging
the arguments (and altering the operator if needed; consider < and >),
though error messages may become somewhat more confusing, then:
1. The op2imm seems to come from cg-integrable-call2 in pass4p2, which
could also check on the constancy and immediate-worthiness of the
first argument.
2. The reuse of RESULT I eventually traced to cg-let1-result and
cg-let-used-once in pass4let, which have enough information to flip
primitives that would benefit from it (and so avoid the allocation
and use of a temporary).
Thoughts?
--
(let ((C call-with-current-continuation)) (apply (lambda (x y) (x y)) (map
((lambda (r) ((C C) (lambda (s) (r (lambda l (apply (s s) l)))))) (lambda
(f) (lambda (l) (if (null? l) C (lambda (k) (display (car l)) ((f (cdr l))
(C k))))))) '((#\J #\d #\D #\v #\s) (#\e #\space #\a #\i #\newline)))))
More information about the Larceny-users
mailing list