From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,461d464a39a7a30a X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,UTF8 X-Received: by 10.180.76.194 with SMTP id m2mr2909557wiw.4.1367665710713; Sat, 04 May 2013 04:08:30 -0700 (PDT) Path: hg5ni66826wib.1!nntp.google.com!feeder1.cambriumusenet.nl!82.197.223.108.MISMATCH!feeder2.cambriumusenet.nl!feed.tweaknews.nl!85.12.40.138.MISMATCH!xlned.com!feeder5.xlned.com!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!border2.nntp.ams2.giganews.com!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!backlog1.nntp.dca.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsfeed.news.ucla.edu!nrc-news.nrc.ca!News.Dal.Ca!news.litech.org!news.stack.nl!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: GNAT not generating any code for =?utf-8?Q?sub=E2=80=91progra?= =?utf-8?Q?m=3A?= known bug? Date: Sun, 28 Apr 2013 08:14:55 +0100 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Injection-Info: mx05.eternal-september.org; posting-host="abea7aea1fa87bdeaf110ddb7626f1db"; logging-data="4425"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18qAmq1scP6Jtjv1LBAvE5xDskS5PESHwg=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (darwin) Cancel-Lock: sha1:LfnM/u0bQRRej96b5RN5oxMP1Hg= sha1:/wcXcWkLn3SeoU12QHPyjVDS1LE= X-Original-Bytes: 3768 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Date: 2013-04-28T08:14:55+01:00 List-Id: "Yannick DuchĂȘne (Hibou57)" 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.