comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: GNAT not generating any code for sub‑program: known bug?
Date: Sun, 28 Apr 2013 08:14:55 +0100
Date: 2013-04-28T08:14:55+01:00	[thread overview]
Message-ID: <lyhairrus0.fsf@pushface.org> (raw)
In-Reply-To: op.wv70f3m3ule2fv@cardamome

"Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr> writes:

> Here is:
> http://www.les-ziboux.rasama.org/download/2013-04-28-cla-gnat-bug.zip

The code is

   function Syscall
     (Number  : Positive;
      Handle  : Natural;
      Address : System.Address;
      Size    : Natural)
      return Integer
   is
      Result : Integer;
   begin
      System.Machine_Code.Asm
        (Template => "int $0x80",
         Outputs => Integer'Asm_Output ("=a", Result),
         Inputs =>
           (Positive'Asm_Input       ("a", Number),
            Natural'Asm_Input        ("b", Handle),
            System.Address'Asm_Input ("c", Address),
            Natural'Asm_Input        ("d", Size)),
         Volatile => False);
      return Result;
   end;

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.

The assembler generated by GNAT GPL 2012 is different but equally
ineffective:

.globl _library__write
_library__write:
LFB3:
        pushq   %rbp
LCFI0:
        movq    %rsp, %rbp
LCFI1:
        leave
LCFI2:
        ret
LFE3:

I think that you have to write the template to show how the parameters
are set up and returned. Here's one I wrote earlier:

   with Ada.Unchecked_Conversion;
   with System.Machine_Code;

   separate (BC.Support.High_Resolution_Time)
   function Clock return Time is

      type Half is (Low, High);
      type Low_High is array (Half) of Interfaces.Unsigned_32;

      Lower, Upper : Interfaces.Unsigned_32;

      function To_Time is new Ada.Unchecked_Conversion (Low_High, Time);

   begin

      System.Machine_Code.Asm
        ("rdtsc" & ASCII.LF & ASCII.HT &
           "movl %%eax, %0"& ASCII.LF & ASCII.HT &
           "movl %%edx, %1",
         Outputs => (Interfaces.Unsigned_32'Asm_Output ("=g", Lower),
                     Interfaces.Unsigned_32'Asm_Output ("=g", Upper)),
         Clobber => "eax, edx",
         Volatile => True);

      return To_Time ((Low => Lower, High => Upper));

   end Clock;

By the way, this doesn't actually work as intended on kit such as the
Macbook Pro (more than one core? advanced power management?), presumably
because the core's clock is slowed down or stopped. Fortunately,
Ada.Calendar.Clock's resolution is 1 microsecond, good enough for most
purposes.



  parent reply	other threads:[~2013-04-28  7:14 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 [this message]
2013-04-28 17:52     ` Yannick Duchêne (Hibou57)
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