Skip to content

Commit

Permalink
removed %ifnull in favor if %ifeq with nil
Browse files Browse the repository at this point in the history
This simplifies the compiler a bit but makes it generate slightly
worse code, like this:

@@ -4605,10 +4626,13 @@
         jnz argument_count_wrong
         # discarding useless value in %eax
         pop %eax
-        # %ifnull
+        # %ifeq
         push %eax
         movl 4(%ebp), %eax
-        cmpl $2 + 256<<2, %eax
+        push %eax
+        movl $2 + 256<<2, %eax
+        cmpl %eax, (%esp)
+        pop %eax
         pop %eax
         jnz _reverse_plus_4
         push %eax

I could imagine peephole optimizations that replace the pushconst,
cmp, pop sequence with a single cmpconst, and that would benefit
ordinary eq? tests too.

It doesn't seem to make much of a performance difference.

darcs-hash:20080224021843-c0035-38a715dd5d73b6e2a3dac2ae0dde3278c0c74dde
  • Loading branch information
Kragen Javier Sitaker committed Feb 24, 2008
1 parent 0dba20b commit 7f2a07b
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions compiler.scm
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@
((not (pair? expr)) '())
(else (case (car expr)
((lambda) (free-vars-lambda (cadr expr) (cddr expr)))
((%if %begin %ifeq %ifnull)
((%if %begin %ifeq)
(all-free-vars (cdr expr)))
((quote) '())
((set!) (add-if-not-present (cadr expr)
Expand Down Expand Up @@ -1629,19 +1629,6 @@
env
tail?)))

(define (compile-ifnull rands env tail?)
(let ((cond-expr (car rands)) (then (cadr rands)) (else-expr (caddr rands)))
(comment "%ifnull")
(compile-conditional (lambda (falselabel)
(compile-expr cond-expr env #f)
(cmp (const nil-value) tos)
(pop)
(jnz falselabel))
then
else-expr
env
tail?)))

(define (compile-ifeq rands env tail?)
(let ((a (car rands))
(b (cadr rands))
Expand Down Expand Up @@ -1692,7 +1679,6 @@
((+ - 1+ 1- car cdr integer->char char->integer string-length
symbol->string)
(inline-primitive rator rands env))
((%ifnull)(compile-ifnull rands env tail?))
((%ifeq) (compile-ifeq rands env tail?))
(else (let ((nargs (compile-args rands env)))
(comment "get procedure")
Expand Down Expand Up @@ -1801,7 +1787,8 @@
((eq? eqv? =)
(list '%ifeq (cadar args) (caddar args) (cadr args) (caddr args)))
((null?)
(list '%ifnull (cadar args) (cadr args) (caddr args)))
(list '%ifeq (cadar args) (list 'quote '())
(cadr args) (caddr args)))
((not)
(list 'if (cadar args) (caddr args) (cadr args)))
(else
Expand Down Expand Up @@ -1830,7 +1817,7 @@
(assert-equal (totally-macroexpand '(if (a) b c)) '(%if (a) b c))
(assert-equal (totally-macroexpand '(if (a) b)) '(%if (a) b #f))
(assert-equal (totally-macroexpand '(if (not a) b c)) '(%if a c b))
(assert-equal (totally-macroexpand '(if (null? a) b c)) '(%ifnull a b c))
(assert-equal (totally-macroexpand '(if (null? a) b c)) '(%ifeq a '() b c))
(assert-equal (totally-macroexpand '(cond ((eq? x 3) 4 '(cond 3))
((eq? x 4) 8)
(else 6 7)))
Expand Down

0 comments on commit 7f2a07b

Please sign in to comment.