From: "Quôc Peyrot" <chojin@lrde.epita.fr>
To: caml-list@inria.fr
Subject: time profiling and nested function inlining
Date: Tue, 5 Dec 2006 19:43:08 -0800 [thread overview]
Message-ID: <4C40AFBA-AE30-4C22-B2A5-170FDA130B64@lrde.epita.fr> (raw)
Hello, I have two questions, sorry if they have already been asked,
but I searched
through the archives and couldn't find the answers:
- I tried to do some time profiling (Mac OS X, ppc G4) but for some
reasons it doesn't
seem to work. I compiled with OCamlMakefile using the command line
"make profiling-native-code".
When I execute the program, it does generate gmon.out, but when I run
gprof the only thing I get is:
called/total parents
index %time self descendents called+self name index
called/total children
0.00 0.00 1/1 ___fixunsdfdi
[476]
[21] 0.0 0.00 0.00 1 ___stub_getrealaddr
[21]
-----------------------------------------------
and
% cumulative self self total
time seconds seconds calls ms/call ms/call name
0.0 0.00 0.00 1 0.00 0.00
___stub_getrealaddr [21]
Thus, I'm wondering whether or not time profiling is supported on PPC
G4.
And if it is, can someone give me some clue to debug this issue?
If it isn't, I would appreciate if someone could give me alternative
solutions (apart from using an intel computer ;) )
- I was looking at the asm output to get familiar with efficient
coding style, and I tried the following example:
let rec log2_acc value acc =
if value = 0
then acc
else log2_acc (value lsr 1) (acc + 1)
let log2 value =
log2_acc value 0
which compiles to (using "ocamlopt -inline 100 -unsafe -S)
_camlTest_regular__log2_acc_57:
L101:
cmpwi r3, 1
bne L100
mr r3, r4
blr
L100:
srwi r5, r3, 1
ori r3, r5, 1
addi r4, r4, 2
b L101
.globl _camlTest_regular__log2_60
.text
.align 2
_camlTest_regular__log2_60:
L102:
li r4, 1
b _camlTest_regular__log2_acc_57
Although log2_acc could have been inlined (which might not be
beneficial in this case anyway), it looks quite ok.
But when I tried with a nested function:
let log2 value =
let rec log2_acc value acc =
if value = 0
then acc
else log2_acc (value lsr 1) (acc + 1)
in
log2_acc value 0
I got the following output:
_camlTest_nested__2:
.long _caml_curry2
.long 5
.long _camlTest_nested__log2_acc_59
.globl _camlTest_nested__log2_acc_59
.text
.align 2
_camlTest_nested__log2_acc_59:
L101:
cmpwi r3, 1
bne L100
mr r3, r4
blr
L100:
srwi r5, r3, 1
ori r3, r5, 1
addi r4, r4, 2
b L101
.globl _camlTest_nested__log2_57
.text
.align 2
_camlTest_nested__log2_57:
L102:
addis r4, 0, ha16(_camlTest_nested__2)
addi r4, r4, lo16(_camlTest_nested__2)
li r4, 1
b _camlTest_nested__log2_acc_59
I'm wondering what these computations before the call are (frame?)
and why the compiler couldn't get rid of them.
Not that I am utterly concerned by these small extra computations...
I'm just curious.
Thanks for the help/explanations,
--
Best Regards,
Quôc
next reply other threads:[~2006-12-06 3:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-06 3:43 Quôc Peyrot [this message]
2006-12-06 8:55 ` [Caml-list] " Daniel Bünzli
2006-12-06 9:01 ` Daniel Bünzli
2006-12-07 10:43 ` Quôc Peyrot
2006-12-07 12:14 ` Jon Harrop
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C40AFBA-AE30-4C22-B2A5-170FDA130B64@lrde.epita.fr \
--to=chojin@lrde.epita.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox