From: "Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr>
Subject: Re: GNAT not generating any code for sub‑program: known bug?
Date: Sun, 28 Apr 2013 19:52:18 +0200
Date: 2013-04-28T19:52:18+02:00 [thread overview]
Message-ID: <op.wv9ilgizule2fv@cardamome> (raw)
In-Reply-To: lyhairrus0.fsf@pushface.org
Le Sun, 28 Apr 2013 09:14:55 +0200, Simon Wright <simon@pushface.org> a
écrit:
> and I think that the problem is that Template actually has to use the
> inputs and outputs! So, while optimising, the compiler says
>
> "int $0x80" doesn't use any of the inputs, so I can ignore them
> "int $0x80" doesn't write to any of the outputs, so I can ignore them
> Result isn't changed, so it's undefined
> Therefore I don't need to do anything.
I thought about the same previously (not my first attempt), and retried
what I tried before, with the same result:
function Syscall_3
(N : Number_Type;
P1 : P1_Type;
P2 : P2_Type;
P3 : P3_Type)
return Result_Type
is
use System.Machine_Code;
Result : Result_Type;
begin
Asm
(Template =>
"movl %1, %%eax" & ASCII.LF &
"movl %2, %%ebx" & ASCII.LF &
"movl %3, %%ecx" & ASCII.LF &
"movl %4, %%edx" & ASCII.LF &
"int $0x80" & ASCII.LF &
"movl %%eax, %0" & ASCII.LF,
Outputs => Result_Type'Asm_Output ("=g", Result),
Inputs =>
(Number_Type'Asm_Input ("g", N),
P1_Type'Asm_Input ("g", P1),
P2_Type'Asm_Input ("g", P2),
P3_Type'Asm_Input ("g", P3)),
Clobber => "eax, ebx, ecx, edx",
Volatile => True);
return Result;
end Syscall_3;
Here (except it's a generic to avoid error while copying similar things),
the template contains all of the instructions loading registers, to be
clear about the inputs the template uses. Then, I used a `Clobber` list
[1][3] to explicitly notify the compiler of the registers used in the
template and which must remains untouched, then I also added `Volatile =>
True` [2][3] to notify the compiler it should avoid unwanted optimization.
The result is still the same, and so, even if the generic instantiation is
not inlined (the generic declaration is not inlined neither). That's
enough for a a caller to be inlined for everything to be dropped, even if
the above subprogram itself not inlined. I agree I must tell the compiler
what it is dealing with and what not to do with it, but so far, I still
feel that looks like a compiler bug (GCC's fault or GNAT's fault?). Will
try something else later.
Side note: with the `type Low_High is array (Half) of
Interfaces.Unsigned_32;` in your snippet, shouldn't you specify the array
should be packed? Or may be that's already implied by the component type…
will have to check the RM.
[1]: http://docs.adacore.com/gnat-unw-docs/html/gnat_ugn_38.html#SEC382
[2]: http://docs.adacore.com/gnat-unw-docs/html/gnat_ugn_38.html#SEC383
[3]: http://docs.adacore.com/gnat-unw-docs/html/gnat_rm_15.html#SEC626
--
“Syntactic sugar causes cancer of the semi-colons.” [1]
“Structured Programming supports the law of the excluded muddle.” [1]
[1]: Epigrams on Programming — Alan J. — P. Yale University
next prev parent reply other threads:[~2013-04-28 17:52 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-27 21:08 GNAT not generating any code for sub‑program: known bug? Yannick Duchêne (Hibou57)
2013-04-27 22:22 ` Yannick Duchêne (Hibou57)
2013-04-27 23:48 ` Yannick Duchêne (Hibou57)
2013-04-28 7:14 ` Simon Wright
2013-04-28 17:52 ` Yannick Duchêne (Hibou57) [this message]
2013-04-28 19:27 ` Yannick Duchêne (Hibou57)
2013-04-28 20:46 ` Simon Wright
2013-04-28 20:43 ` Simon Wright
2013-04-28 22:35 ` Erroneous code generation from GNAT or GCC? Yannick Duchêne (Hibou57)
2013-04-28 22:49 ` Yannick Duchêne (Hibou57)
2013-04-28 23:52 ` Yannick Duchêne (Hibou57)
2013-04-29 1:35 ` Yannick Duchêne (Hibou57)
2013-04-30 0:48 ` Yannick Duchêne (Hibou57)
2013-04-30 6:40 ` Simon Wright
2013-04-30 17:04 ` Yannick Duchêne (Hibou57)
2013-04-30 19:06 ` Simon Wright
2013-04-30 21:28 ` Yannick Duchêne (Hibou57)
2013-04-30 22:22 ` Simon Wright
2013-05-01 18:19 ` J-P. Rosen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox