* Re: question about functions (bis)
2000-01-21 0:00 question about functions (bis) Pascal LEJEUNE
2000-01-21 0:00 ` David C. Hoos, Sr.
@ 2000-01-21 0:00 ` Philip Anderson
2000-01-21 0:00 ` Jeff Creem
2000-01-24 0:00 ` Nick Roberts
2 siblings, 1 reply; 5+ messages in thread
From: Philip Anderson @ 2000-01-21 0:00 UTC (permalink / raw)
Pascal LEJEUNE wrote:
>
> function ADD (A, B : in T) return T is
> tmp : system.address;
> begin
> << find the address of the result (that's my problem !!) >> and
> put it in a local variable (tmp)
>
> call a procedure which use directly the hardware :
> proc (a'address, b'address, tmp);
> end ADD;
>
> So, the problem is quite simple : the type T is a "numerical" type
> on which it is normal to have operators ... but the hardware need
> to have the address of the arguments and the address of the result !!!
Can't you simply write:
function ADD (A, B : in T) return T is
tmp : T;
begin
-- call a procedure which directly uses the hardware :
--
proc (a'address, b'address, tmp'address);
return tmp;
end ADD;
--
hwyl/cheers,
Philip Anderson
Alenia Marconi Systems
Cwmbr�n, Cymru/Wales
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: question about functions (bis)
2000-01-21 0:00 question about functions (bis) Pascal LEJEUNE
@ 2000-01-21 0:00 ` David C. Hoos, Sr.
2000-01-21 0:00 ` Philip Anderson
2000-01-24 0:00 ` Nick Roberts
2 siblings, 0 replies; 5+ messages in thread
From: David C. Hoos, Sr. @ 2000-01-21 0:00 UTC (permalink / raw)
Pascal LEJEUNE <pascal.lejeune@matra-transport.fr> wrote in message
news:8690s0$8tq$1@news.mgn.net...
> Hello everybody,
>
> Thank you for your replies !!!!
> What I want to do, is to give my user the possibility of operators
> to a type (for example C := A + B, C := A - B, C := A < B ...). This
> type is not very complex (a record of 4 bytes).
> Then, my operator is a rename of a function, for example :
> function "+" (A, B : in T) return T renames ADD;
>
> Finaly, my function ADD use a hardware component which do
> the operation with the addresses (it's an asic which needs
> to know on which variable the operation is done) :
>
> function ADD (A, B : in T) return T is
> tmp : system.address;
> begin
> << find the address of the result (that's my problem !!) >> and
> put it in a local variable (tmp)
>
> call a procedure which use directly the hardware :
> proc (a'address, b'address, tmp);
> end ADD;
>
> So, the problem is quite simple : the type T is a "numerical" type
> on which it is normal to have operators ... but the hardware need
> to have the address of the arguments and the address of the result !!!
>
> I hope i'll find a "nice" solution (ie in Ada or C), but if it is
> impossible,
> i'll use ASM !
Why don't you declare a local variable for the result, then after the
hardware has done its job, return the value of the result to the caller,
say, as follows:
function ADD (A, B : in T) return T is
tmp : T;
begin
call a procedure which use directly the hardware :
proc (a'address, b'address, tmp'address);
return tmp;
end ADD;
^ permalink raw reply [flat|nested] 5+ messages in thread
* question about functions (bis)
@ 2000-01-21 0:00 Pascal LEJEUNE
2000-01-21 0:00 ` David C. Hoos, Sr.
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Pascal LEJEUNE @ 2000-01-21 0:00 UTC (permalink / raw)
Hello everybody,
Thank you for your replies !!!!
What I want to do, is to give my user the possibility of operators
to a type (for example C := A + B, C := A - B, C := A < B ...). This
type is not very complex (a record of 4 bytes).
Then, my operator is a rename of a function, for example :
function "+" (A, B : in T) return T renames ADD;
Finaly, my function ADD use a hardware component which do
the operation with the addresses (it's an asic which needs
to know on which variable the operation is done) :
function ADD (A, B : in T) return T is
tmp : system.address;
begin
<< find the address of the result (that's my problem !!) >> and
put it in a local variable (tmp)
call a procedure which use directly the hardware :
proc (a'address, b'address, tmp);
end ADD;
So, the problem is quite simple : the type T is a "numerical" type
on which it is normal to have operators ... but the hardware need
to have the address of the arguments and the address of the result !!!
I hope i'll find a "nice" solution (ie in Ada or C), but if it is
impossible,
i'll use ASM !
Thank you !!!
Pascal LEJEUNE
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: question about functions (bis)
2000-01-21 0:00 ` Philip Anderson
@ 2000-01-21 0:00 ` Jeff Creem
0 siblings, 0 replies; 5+ messages in thread
From: Jeff Creem @ 2000-01-21 0:00 UTC (permalink / raw)
Philip Anderson <phil.anderson@gecm.com> wrote in message
news:38883285.AB6ED64C@gecm.com...
> Pascal LEJEUNE wrote:
> >
> > function ADD (A, B : in T) return T is
> > tmp : system.address;
> > begin
> > << find the address of the result (that's my problem !!) >> and
> > put it in a local variable (tmp)
> >
> > call a procedure which use directly the hardware :
> > proc (a'address, b'address, tmp);
> > end ADD;
> >
> > So, the problem is quite simple : the type T is a "numerical" type
> > on which it is normal to have operators ... but the hardware need
> > to have the address of the arguments and the address of the result !!!
>
>
> Can't you simply write:
>
> function ADD (A, B : in T) return T is
> tmp : T;
> begin
> -- call a procedure which directly uses the hardware :
> --
> proc (a'address, b'address, tmp'address);
> return tmp;
> end ADD;
>
Which by the way when you do this, in certain cases, GNAT actually does not
even really create a new
variable tmp. In certain instances tmp is optimized out and 'address tmp =
'address of location of return
value.
(At least it looked that way to me compiling some test code on x86 and
looking at resulting code)
Jeff Creem
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: question about functions (bis)
2000-01-21 0:00 question about functions (bis) Pascal LEJEUNE
2000-01-21 0:00 ` David C. Hoos, Sr.
2000-01-21 0:00 ` Philip Anderson
@ 2000-01-24 0:00 ` Nick Roberts
2 siblings, 0 replies; 5+ messages in thread
From: Nick Roberts @ 2000-01-24 0:00 UTC (permalink / raw)
The 'nice' solution is simple: declare a temporary of the return type, pass
its address to the hardware, and return it at the end of the function.
function Add (Left, Right: in T) return T is
Result: T;
begin
ASIC_Add(Left'Address,Right'Address,Result'Address);
return Result;
end;
pragma Inline(Add);
Couldn't be easier!
Note the use of a 'pragma Inline' to (hopefully) help with speed (which I
presume matters in this situation). With a bit of luck, the compiler will
optimise reasonably.
--
Nick Roberts
http://www.adapower.com/lab/adaos
"Pascal LEJEUNE" <pascal.lejeune@matra-transport.fr> wrote in message
news:8690s0$8tq$1@news.mgn.net...
> ...
> Finaly, my function ADD use a hardware component which do
> the operation with the addresses (it's an asic which needs
> to know on which variable the operation is done) :
>
> function ADD (A, B : in T) return T is
> tmp : system.address;
> begin
> << find the address of the result (that's my problem !!) >> and
> put it in a local variable (tmp)
>
> call a procedure which use directly the hardware :
> proc (a'address, b'address, tmp);
> end ADD;
>
> So, the problem is quite simple : the type T is a "numerical" type
> on which it is normal to have operators ... but the hardware need
> to have the address of the arguments and the address of the result !!!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2000-01-24 0:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-21 0:00 question about functions (bis) Pascal LEJEUNE
2000-01-21 0:00 ` David C. Hoos, Sr.
2000-01-21 0:00 ` Philip Anderson
2000-01-21 0:00 ` Jeff Creem
2000-01-24 0:00 ` Nick Roberts
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox