Opened 4 years ago

#1339 new enhancement

Avoid boxing / unboxing when copying array elements

Reported by: alms Owned by: gb
Priority: normal Milestone:
Component: Compiler Version: trunk
Keywords: Cc:

Description

GB:

I think that the shift instruction in question could be avoided by a compiler change. Unless and until that compiler change is made, I don't want to stop distinguishing between immediate and boxed/node values.

Bob is correct that it is pointless to read an array element, box it, unbox it, and store it into another element. If the value read or stored is returned from a function or passed as an argument. it needs to be boxed but in many other cases (arithmetic involving floats) we can avoid the overhead of boxing and unboxing the arguments just to add thimgs together.

I don't know if all cases of AREF assume that every element is a node or if only cases involving FIXNUM arrays assume that and I just didn't care much about the cost of shifts when fixnums were involved.

Forwarded Message:

There is no reason to be doing the shlq and the sarq stuff here.

In the code below, the shifting stems from a misguided, in my view, attitude that one has to use FIXNUM type arrays to get certain efficiencies out of CCL.

It is not so! If one just gets the right FIXNUM declarations in the right places in the code, then one can move a fixnum from one CCL array location to another location. In an array of type T. Without shifting. At all.

 (load "copy-test-file-2.lisp")
    (recover-fn-from-rip)                   ;  [0/15]
    (popq (@ 16 (% rsp)))                   ;  [7/22]
    (popq (% arg_w))                        ; [11/26]
    (addq ($ 8) (% rsp))                    ; [13/28]

    (:align 4)
L17
    (cmpq (% arg_x) (% arg_w))              ; [17/32]
    (jl L33)                                ; [20/35]
    (retq)                                  ; [22/37]

    (:align 4)
L33
    (movq (@ -5 (% arg_z)) (% temp3))       ; [33/48]
    (movq (@ -5 (% temp3) (% arg_w)) (% imm1)) ; [37/52]
    (shlq ($ 3) (% imm1))                   ; [42/57]                          <= DUMB!!
    (movq (% imm1) (% temp1))               ; [46/61]
    (movq (@ -5 (% arg_z)) (% temp3))       ; [49/64]
    (movq (% temp1) (% imm1))               ; [53/68]
    (sarq ($ 3) (% imm1))                   ; [56/71]                          <=  DUMB!!
    (movq (% imm1) (@ -5 (% temp3) (% arg_y))) ; [60/75]
    (addq ($ 8) (% arg_w))                  ; [65/80]
    (addq ($ 8) (% arg_y))                  ; [69/84]
    (jmp L17)                               ; [73/88]

Change History (0)

Note: See TracTickets for help on using tickets.