Browse thread
The Implicit Accumulator: a design pattern using optional arguments
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jon Harrop <jon@f...> |
| Subject: | Re: [Caml-list] The Implicit Accumulator: a design pattern using optional arguments |
On Thursday 28 June 2007 12:42:57 Joel Reymont wrote:
> Where does the 65% speed-up come from?
Good question.
> Just from using match?
Yes, or you can reorder the branches of the "if" statement, putting the common
branch first.
My code gives:
camlTest__work_58:
.L101:
cmpq $1, %rbx
je .L100
movq %rbx, %rdi
addq $-2, %rdi
leaq -1(%rax, %rbx), %rax
movq %rdi, %rbx
jmp .L101
.align 4
.L100:
ret
.text
.align 16
.globl camlTest__sum_nums3_61
camlTest__sum_nums3_61:
.L102:
movq %rax, %rbx
movq $1, %rax
jmp camlTest__work_58
.text
.align 16
.globl camlTest__entry
So it branches out of the loop when todo=0 and does one branch per loop.
Both of Thomas' implementations give:
camlTest__work_60:
.L101:
cmpq $1, %rbx
jne .L100
ret
.align 4
.L100:
movq %rbx, %rdi
addq $-2, %rdi
leaq -1(%rax, %rbx), %rax
movq %rdi, %rbx
jmp .L101
.text
.align 16
.globl camlTest__sum_nums_58
camlTest__sum_nums_58:
.L102:
movq %rax, %rbx
leaq camlTest__2(%rip), %rax
movq $1, %rax
jmp camlTest__work_60
.text
.align 16
.globl camlTest__entry
which branches within the loop if todo<>0 and then back to the start of the
loop. So this branches twice per loop.
PS: This has nothing to do with consing or continuations.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The OCaml Journal
http://www.ffconsultancy.com/products/ocaml_journal/?e