digitalmars.D - GDC and leaf functions
- Manu <turkeyman gmail.com> Mar 04 2013
- "David Nadlinger" <see klickverbot.at> Mar 04 2013
- Manu <turkeyman gmail.com> Mar 04 2013
--e89a8fb2054ae2894f04d71af797
Content-Type: text/plain; charset=UTF-8
I'm doing a lot of experiments with GDC, and I'm noticing that leaf
functions are still generating a stack frame and doing pointless work...
int leaf() pure nothrow
{
return 0;
}
compile with -frelease -finline -O3, etc
I expect 2 opcodes, load immediate and return, but I get a whole pointless
function including memory access O_O
Any ideas? Is this normal?
--e89a8fb2054ae2894f04d71af797
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I'm doing a lot of experiments with GDC, and I'm n=
oticing that leaf functions are still generating a stack frame and doing po=
intless work...<div style><br></div><div style>int leaf() pure nothrow</div=
tyle><br></div><div style>compile with -frelease -finline -O3, etc</div><di=
v style><br></div><div style>I expect 2 opcodes, load immediate and return,=
but I get a whole pointless function including memory access O_O</div>
<div style><br></div><div style>Any ideas? Is this normal?</div></div>
--e89a8fb2054ae2894f04d71af797--
Mar 04 2013
On Monday, 4 March 2013 at 15:25:43 UTC, Manu wrote:I'm doing a lot of experiments with GDC, and I'm noticing that leaf functions are still generating a stack frame and doing pointless work... int leaf() pure nothrow { return 0; } compile with -frelease -finline -O3, etc I expect 2 opcodes, load immediate and return, but I get a whole pointless function including memory access O_O Any ideas? Is this normal?
http://d.godbolt.org/#%7B%22version%22%3A3%2C%22filterAsm%22%3A%7B%22labels%22%3Atrue%2C%22directives%22%3Atrue%2C%22commentOnly%22%3Atrue%2C%22intel%22%3Atrue%7D%2C%22compilers%22%3A%5B%7B%22source%22%3A%22int%20leaf()%20pure%20nothrow%5Cn%7B%5Cn%20%20return%200%3B%5Cn%7D%22%2C%22compiler%22%3A%22%2Fusr%2Fbin%2Fgdc%22%2C%22options%22%3A%22-O3%20-march%3Dnative%22%7D%5D%7D The rest is just code for registering the ModuleInfo of the given module in the global list. David
Mar 04 2013
--e89a8fb2054ac2196704d71cf97c
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hmm, it seems PPC is working too.
Actually, maybe it's just SH4. I think my tests on other arch's were thrown
by bad compiler options.
Hmmm...
extern(C) float testfunc(float v, float v2)
{
return v*v2 + v2;
}
PPC:
testfunc:
fmadds 1,1,2,2
blr
MIPS:
testfunc:
j $31
madd.s $f0,$f13,$f12,$f13
SH4 Produces:
testfunc:
mov.l .L3,r1
lds.l r1+,fpscr
add #-4,r1
fmov fr4,fr0
add #4,r1
fmac fr0,fr5,fr0
rts
lds.l r1+,fpscr
But it should be:
testfunc:
fmov fr4,fr0
fmac fr0,fr5,fr0
rts
On 5 March 2013 03:39, David Nadlinger <see klickverbot.at> wrote:
On Monday, 4 March 2013 at 15:25:43 UTC, Manu wrote:
I'm doing a lot of experiments with GDC, and I'm noticing that leaf
functions are still generating a stack frame and doing pointless work...
int leaf() pure nothrow
{
return 0;
}
compile with -frelease -finline -O3, etc
I expect 2 opcodes, load immediate and return, but I get a whole pointle=
function including memory access O_O
Any ideas? Is this normal?
http://d.godbolt.org/#%7B%**22version%22%3A3%2C%**
22filterAsm%22%3A%7B%22labels%**22%3Atrue%2C%22directives%22%**
3Atrue%2C%22commentOnly%22%**3Atrue%2C%22intel%22%3Atrue%**
7D%2C%22compilers%22%3A%5B%7B%**22source%22%3A%22int%20leaf()%**
20pure%20nothrow%5Cn%7B%5Cn%**20%20return%200%3B%5Cn%7D%22%**
2C%22compiler%22%3A%22%2Fusr%**2Fbin%2Fgdc%22%2C%22options%**
22%3A%22-O3%20-march%3Dnative%**22%7D%5D%7D<http://d.godbolt.org/#%7B%22v=
%3Atrue%2C%22commentOnly%22%3Atrue%2C%22intel%22%3Atrue%7D%2C%22compilers%2=
2%3A%5B%7B%22source%22%3A%22int%20leaf()%20pure%20nothrow%5Cn%7B%5Cn%20%20r=
eturn%200%3B%5Cn%7D%22%2C%22compiler%22%3A%22%2Fusr%2Fbin%2Fgdc%22%2C%22opt=
ions%22%3A%22-O3%20-march%3Dnative%22%7D%5D%7D>
The rest is just code for registering the ModuleInfo of the given module
in the global list.
David
--e89a8fb2054ac2196704d71cf97c
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hmm, it seems PPC is working too.<div style>Actually, mayb=
e it's just SH4. I think my tests on other arch's were thrown by ba=
d compiler options.</div><div style>Hmmm...</div><div style><br></div><div =
style>
<div>extern(C) float testfunc(float v, float v2)</div><div>{</div><div><spa=
n class=3D"" style=3D"white-space:pre"> </span>return v*v2 + v2;<br></div><=
div>}</div><div><br></div><div><br></div><div style>PPC:</div><div style><b=
r>
</div><div style><div>testfunc:</div><div><span class=3D"" style=3D"white-s=
pace:pre"> </span>fmadds 1,1,2,2<br></div><div><span class=3D"" style=3D"wh=
ite-space:pre"> </span>blr</div><div><br></div><div><br></div></div><div st=
yle>
MIPS:</div><div style><br></div><div style><div>testfunc:</div><div><span c=
lass=3D"" style=3D"white-space:pre"> </span>j<span class=3D"" style=3D"whit=
e-space:pre"> </span>$31<br></div><div><span class=3D"" style=3D"white-spac=
e:pre"> </span>madd.s<span class=3D"" style=3D"white-space:pre"> </span>$f0=
,$f13,$f12,$f13</div>
<div><br></div></div><div><br></div><div><br></div><div style>SH4 Produces:=
</div><div style><br></div><div><div>testfunc:</div><div><span class=3D"" s=
tyle=3D"white-space:pre"> </span>mov.l<span class=3D"" style=3D"white-space=
:pre"> </span>.L3,r1<br>
</div><div><span class=3D"" style=3D"white-space:pre"> </span>lds.l<span cl=
ass=3D"" style=3D"white-space:pre"> </span> r1+,fpscr</div><div><span class=
=3D"" style=3D"white-space:pre"> </span>add<span class=3D"" style=3D"white-=
space:pre"> </span>#-4,r1</div>
<div><span class=3D"" style=3D"white-space:pre"> </span>fmov<span class=3D"=
" style=3D"white-space:pre"> </span>fr4,fr0</div><div><span class=3D"" styl=
e=3D"white-space:pre"> </span>add<span class=3D"" style=3D"white-space:pre"=
</span>#4,r1</div>
" style=3D"white-space:pre"> </span>fr0,fr5,fr0</div><div><span class=3D"" =
style=3D"white-space:pre"> </span>rts<span class=3D"" style=3D"white-space:=
pre"> </span></div>
<div><span class=3D"" style=3D"white-space:pre"> </span>lds.l<span class=3D=
"" style=3D"white-space:pre"> </span> r1+,fpscr</div></div><div><br></div><=
div><br></div><div style>But it should be:</div><div style><div><br></div><=
div>
testfunc:</div><div><span class=3D"" style=3D"white-space:pre"> </span>fmov=
<span class=3D"" style=3D"white-space:pre"> </span>fr4,fr0<br></div><div><s=
pan class=3D"" style=3D"white-space:pre"> </span>fmac<span class=3D"" style=
=3D"white-space:pre"> </span>fr0,fr5,fr0<br>
</div><div><span class=3D"" style=3D"white-space:pre"> </span>rts<span clas=
s=3D"" style=3D"white-space:pre"> </span></div><div><br></div></div></div><=
/div><div class=3D"gmail_extra"><br><br><div class=3D"gmail_quote">On 5 Mar=
ch 2013 03:39, David Nadlinger <span dir=3D"ltr"><<a href=3D"mailto:see =
klickverbot.at" target=3D"_blank">see klickverbot.at</a>></span> wrote:<=
br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div class=3D"im">On Monday, 4 March 2013 at=
15:25:43 UTC, Manu wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">
I'm doing a lot of experiments with GDC, and I'm noticing that leaf=
<br>
functions are still generating a stack frame and doing pointless work...<br=
int leaf() pure nothrow<br>
{<br>
=C2=A0 return 0;<br>
}<br>
<br>
compile with -frelease -finline -O3, etc<br>
<br>
I expect 2 opcodes, load immediate and return, but I get a whole pointless<=
br>
function including memory access O_O<br>
<br>
Any ideas? Is this normal?<br>
</blockquote>
<br>
</div><a href=3D"http://d.godbolt.org/#%7B%22version%22%3A3%2C%22filterAsm%=
22%3A%7B%22labels%22%3Atrue%2C%22directives%22%3Atrue%2C%22commentOnly%22%3=
Atrue%2C%22intel%22%3Atrue%7D%2C%22compilers%22%3A%5B%7B%22source%22%3A%22i=
nt%20leaf()%20pure%20nothrow%5Cn%7B%5Cn%20%20return%200%3B%5Cn%7D%22%2C%22c=
ompiler%22%3A%22%2Fusr%2Fbin%2Fgdc%22%2C%22options%22%3A%22-O3%20-march%3Dn=
ative%22%7D%5D%7D" target=3D"_blank">http://d.godbolt.org/#%7B%<u></u>22ver=
sion%22%3A3%2C%<u></u>22filterAsm%22%3A%7B%22labels%<u></u>22%3Atrue%2C%22d=
irectives%22%<u></u>3Atrue%2C%22commentOnly%22%<u></u>3Atrue%2C%22intel%22%=
3Atrue%<u></u>7D%2C%22compilers%22%3A%5B%7B%<u></u>22source%22%3A%22int%20l=
eaf()%<u></u>20pure%20nothrow%5Cn%7B%5Cn%<u></u>20%20return%200%3B%5Cn%7D%2=
2%<u></u>2C%22compiler%22%3A%22%2Fusr%<u></u>2Fbin%2Fgdc%22%2C%22options%<u=
</u>22%3A%22-O3%20-march%3Dnative%<u></u>22%7D%5D%7D</a><br>
<br>
The rest is just code for registering the ModuleInfo of the given module in=
the global list.<span class=3D"HOEnZb"><font color=3D"#888888"><br>
<br>
David<br>
</font></span></blockquote></div><br></div>
--e89a8fb2054ac2196704d71cf97c--
Mar 04 2013









"David Nadlinger" <see klickverbot.at> 