From: Simon Wright <simon@pushface.org>
Subject: Re: Pass by reference
Date: 14 Apr 2004 18:27:24 +0100
Date: 2004-04-14T18:27:24+01:00 [thread overview]
Message-ID: <x7vsmf6jwqr.fsf@smaug.pushface.org> (raw)
In-Reply-To: 4hen70p62fq82m89cc52t6kutg44k757tf@jellix.jlfencey.com
Vinzent 'Gadget' Hoefler <nntp-2004-04@t-domaingrabbing.de> writes:
> Simon Wright wrote:
>
> >Vinzent 'Gadget' Hoefler <nntp-2004-04@t-domaingrabbing.de> 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.
next prev parent reply other threads:[~2004-04-14 17:27 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-08 14:52 Pass by reference Dan McLeran
2004-04-08 18:21 ` Martin Krischik
2004-04-09 12:53 ` Dan McLeran
2004-04-13 12:42 ` Martin Krischik
2004-04-08 19:04 ` Jim Rogers
2004-04-09 3:24 ` Dan McLeran
2004-04-09 0:01 ` Stephen Leake
2004-04-09 12:38 ` Dan McLeran
2004-04-09 13:03 ` Dmitry A. Kazakov
2004-04-09 19:09 ` Dan McLeran
2004-04-10 10:49 ` Dmitry A. Kazakov
2004-04-11 12:43 ` Florian Weimer
2004-04-12 10:29 ` Dmitry A. Kazakov
2004-04-12 12:29 ` Samuel Tardieu
2004-04-13 8:46 ` Dmitry A. Kazakov
2004-04-10 1:42 ` Stephen Leake
2004-04-10 16:05 ` chris
2004-04-09 12:44 ` Dan McLeran
2004-04-09 22:44 ` Randy Brukardt
2004-04-09 14:44 ` Simon Wright
2004-04-09 1:15 ` Jeffrey Carter
2004-04-09 1:28 ` Pat Rogers
2004-04-10 1:05 ` Jeffrey Carter
2004-04-09 12:57 ` Dan McLeran
2004-04-10 1:16 ` Jeffrey Carter
2004-04-09 4:03 ` Steve
2004-04-09 14:50 ` Simon Wright
2004-04-09 17:12 ` Pat Rogers
2004-04-09 19:33 ` Vinzent 'Gadget' Hoefler
2004-04-10 6:33 ` Simon Wright
2004-04-13 10:26 ` Vinzent 'Gadget' Hoefler
2004-04-14 17:27 ` Simon Wright [this message]
2004-04-15 9:43 ` Vinzent 'Gadget' Hoefler
2004-04-17 7:59 ` Simon Wright
2004-04-11 12:45 ` Florian Weimer
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox