comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Pass by reference
Date: 17 Apr 2004 08:59:20 +0100
Date: 2004-04-17T08:59:20+01:00	[thread overview]
Message-ID: <x7vzn9bqbl3.fsf@smaug.pushface.org> (raw)
In-Reply-To: 22js70he63r733ip61lqt4amgcp6c8btp1@jellix.jlfencey.com

Vinzent 'Gadget' Hoefler <nntp-2004-04@t-domaingrabbing.de> writes:

> Simon Wright wrote:

> >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
> [...]
> >   #APP
> >           movl #01000000, -65536
> >           movl #00000000, -65536
> >   #NO_APP
> 
> (Despite the fact that this code is not valid, i386 can't load two
> constants in one instruction, your intention is clear and would
> work).

Yes, more work needed (and next time, Simon, go the whole way and
don't just stop with a -S compilation). I too will only use asm when
it's _necessary_, so it's a new learning experience each time ...

> That's why I declared the procedure to take an access parameter
> instead of "in out" and now everything is working fine as
> expected. It is just the fact that I now use access types in the
> interface (IMO: unnecessarily from the point of logic) that bugs me
> a little bit.

Another possibility would be to pass System.Address. On the whole,
access is a lot safer I would have thought -- especially if you can
encapsulate this low-level stuff (including the calls to your wrapper
procedure) to a restricted area of the code.

> Eventually I should try to switch to use limited types instead to
> circumvent this problem?

I had a play with this, and for GNAT 3.15p (and 3.16a1, 5.02a) this

   package Wrapper is
      type Register is limited private;
      procedure Write (Value : Interfaces.Unsigned_16; To : in out Register);
   private
      type Actual_Register is mod 256;
      for Actual_Register'Size use 8;
      pragma Volatile (Actual_Register);
      type Register is limited record
         Actual : Actual_Register;
      end record;
      for Register'Size use 8;
   end Wrapper;

used pass-by-reference.

The asm for 5.02a (-gnatp -O2) is

	.type	access_memory_mapped_register__wrapper__write.0,@function
access_memory_mapped_register__wrapper__write.0:
.LFB1:
	pushl	%ebp
.LCFI0:
	movl	%esp, %ebp
.LCFI1:
	subl	$4, %esp
.LCFI2:
	movzwl	8(%ebp), %eax
	movl	12(%ebp), %edx
	movb	%al, (%edx)
	shrl	$8, %eax
	movb	%al, (%edx)
	movl	%ebp, %esp
	popl	%ebp
	ret

which looks as though it at least stands a chance; I don't understand
the 3.15p code,

	.type	 access_memory_mapped_register__wrapper__write.0,@function
access_memory_mapped_register__wrapper__write.0:
	pushl %ebp
	movl %esp,%ebp
	subl $4,%esp
	movl %ecx,-4(%ebp)
	movl 12(%ebp),%edx
	movzbw 9(%ebp),%ax
	movb %al,(%edx)
	movl %ebp,%esp
	popl %ebp
	ret

-- 
Simon Wright                               100% Ada, no bugs.



  reply	other threads:[~2004-04-17  7:59 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
2004-04-15  9:43               ` Vinzent 'Gadget' Hoefler
2004-04-17  7:59                 ` Simon Wright [this message]
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