Comment 0 for bug 676414

Revision history for this message
Heka Treep (zena-treep) wrote :

Currently, Python does not reduce the constants in expressions such as:

  (+ 3 a 5 b 7 c)

For fixnums this gives:

  ; A7: 83C203 ADD EDX, 3
  ; AA: 83C205 ADD EDX, 5
  ; AD: C1FF02 SAR EDI, 2
  ; B0: 01FA ADD EDX, EDI
  ; B2: 83C207 ADD EDX, 7
  ; B5: C1FE02 SAR ESI, 2
  ; B8: 8D0432 LEA EAX, [EDX+ESI]
  ; BB: 6BD004 IMUL EDX, EAX, 4
  ; BE: 7107 JNO L0
  ; C0: 8BD0 MOV EDX, EAX

and for generic numbers this generate five calls to GENERIC-+.

It would be nice to collect all numbers at compile-time, doing the following transformation:

  (+ 3 a 5 b 7 c) -> (+ 15 a b c)

schematically:

  (+ list) -> `(+ ,(fold-left '+ identity (filter const-p list)) ,@(filter not-const-p list))