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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9f3d09bde7b33b5d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-04-14 10:31:41 PST Path: archiver1.google.com!news1.google.com!news.glorb.com!newsgate.cistron.nl!news2.euro.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Pass by reference Date: 14 Apr 2004 18:27:24 +0100 Organization: Pushface Sender: simon@smaug.pushface.org Message-ID: References: <19b0e504.0404080652.4eab9f80@posting.google.com> <5QAdc.7896$Jf6.4030@newssvr23.news.prodigy.com> <4hen70p62fq82m89cc52t6kutg44k757tf@jellix.jlfencey.com> NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1081963900 20690 62.49.19.209 (14 Apr 2004 17:31:40 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Wed, 14 Apr 2004 17:31:40 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 Xref: archiver1.google.com comp.lang.ada:7100 Date: 2004-04-14T18:27:24+01:00 List-Id: Vinzent 'Gadget' Hoefler writes: > Simon Wright wrote: > > >Vinzent 'Gadget' Hoefler writes: > > > >> Pat Rogers wrote: > >> > >> >If you made the type volatile that would also force by-reference. > > > >C.6(18): If a type is atomic or volatile and it is not a by-copy type, > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > Yes, but if I understand that part correctly, this is the point. The > register-type is just a simple Integer-type: Sorry, that's what _I_ was trying to say too! > >> Are you sure? I'm just looking at the assembly ouput of GNAT for a > >> procedure that takes a volatile type (memory mapped register) and it > >> does't seem so. Even worse, it optimizes the sequence of assignment > >> which I need for this register. If you have any idea how can I avoid > >> using access types to make it right, I'd be glad to hear it. > > > >I think you need to use inline assembler to be sure. > > You must be kidding me, I'm just getting away from using assembler. :) > The old system was a 16-bit-CPU programmed entirely in assembly > language, now I am having MaRTE and Ada and you say, I should use > inline assembler instead? ;-) > > Well, there is no general problem in here for me, but even with inline > assembler the fact remains that the procedure would need the _address_ > of the register, and *not* its contents. So using inline assembler > wouldn't help in avoiding access types and if it doesn't, I won't need > it, because in that case the compiler generated code is just fine. > > >And to be really sure you may need to use Volatile => True on the > >call, I had to (this was GNAT/PowerPC, by the way). > > I'm not sure if I understand... can I actually apply that pragma to > a call? Or am I missing something else? I was talking about your "optimizes the sequence of assignment which I need for this register" problem. I don't know whether it's available in GCC C inline assembler, but for GNAT, System.Machine_Code.Asm looks like procedure Asm ( Template : String; Outputs : Asm_Output_Operand_List; Inputs : Asm_Input_Operand_List; Clobber : String := ""; Volatile : Boolean := False); (plus other variants). >From http://gcc.gnu.org/onlinedocs/gnat_ug_unx/The-Volatile-Parameter.html#The%20Volatile%20Parameter Compiler optimizations in the presence of Inline Assembler may sometimes have unwanted effects. For example, when an Asm invocation with an input variable is inside a loop, the compiler might move the loading of the input variable outside the loop, regarding it as a one-time initialization. If this effect is not desired, you can disable such optimizations by setting the Volatile parameter to True; for example: Asm ("movl %0, %%ebx" & LF & HT & "movl %%ebx, %1", Inputs => Unsigned_32'Asm_Input ("g", Var_In), Outputs => Unsigned_32'Asm_Output ("=g", Var_Out), Clobber => "ebx", Volatile => True); I'm not 100% sure on this, but this code with Interfaces; with System.Machine_Code; with System.Storage_Elements; procedure Access_Memory_Mapped_Register is R : Interfaces.Unsigned_32; for R'Address use System.Storage_Elements.To_Address (16#ffff0000#); begin System.Machine_Code.Asm ("movl #01000000, %0", Outputs => Interfaces.Unsigned_32'Asm_Output ("=m", R), Volatile => True); System.Machine_Code.Asm ("movl #00000000, %0", Outputs => Interfaces.Unsigned_32'Asm_Output ("=m", R), Volatile => True); end Access_Memory_Mapped_Register; generates this i86 assembler .file "vinzent.adb" .version "01.01" gcc2_compiled.: .section .rodata .LC0: .string "vinzent.adb" .text .align 4 .globl _ada_access_memory_mapped_register .type _ada_access_memory_mapped_register,@function _ada_access_memory_mapped_register: pushl %ebp movl %esp,%ebp #APP movl #01000000, -65536 movl #00000000, -65536 #NO_APP movl %ebp,%esp popl %ebp ret .Lfe1: .size _ada_access_memory_mapped_register,.Lfe1-_ada_access_memory_mapped_register .ident "GCC: (GNU) 2.8.1" which looks good .. no 'Access anywhere .. -- Simon Wright 100% Ada, no bugs.