comp.lang.ada
 help / color / mirror / Atom feed
* Re: Or
       [not found] <vhioga2t8wa.fsf@ljod.ifi.uio.no>
                   ` (2 preceding siblings ...)
  2000-01-31  0:00 ` Or David Starner
@ 2000-01-31  0:00 ` tmoran
  2000-01-31  0:00 ` Or Vladimir Olensky
  4 siblings, 0 replies; 5+ messages in thread
From: tmoran @ 2000-01-31  0:00 UTC (permalink / raw)


>I need bitwise or on Interfaces.C.Int. I couldn't find any
>direct or operator in Ada,
   What are you using for a manual for Ada?

-- assuming Interfaces.C.Int and Unsigned are the same size:
function Ignore_Sign is new Ada.Unchecked_Conversion
   (source=>Interfaces.C.Int, target=>Interfaces.C.Unsigned);
function Xlate_Sign is new Ada.Unchecked_Conversion
   (source=>Interfaces.C.Unsigned, target=>Interfaces.C.Int);
A, B, Result : Interfaces.C.Int;
...
Result := Xlate_Sign(Ignore_Sign(A) or Ignore_Sign(B));

But if you really want to do ORs, presumably your variables
are all Unsigned, not Int, anyway, so
A, B, Result : Interfaces.C.Unsigned;
...
Result := A or B;

>  function C_Or (R: C.Int;
>                 L: C.Int) return C.Int
>  is
>     type Int_Access is access all C.Int;
>     package A2A is new System.Address_To_Access_Conversions(C.Int);
>     X,Y,Result: aliased C.Int;
>     XA,YA,RA: System.Address;
>     RP : Int_Access;
>  begin
>     X := R;
>     Y := L;
>     XA := A2A.To_Address(X'Access);
>     YA := A2A.To_Address(Y'Access);
>     RA := A2A.To_Address(Result'Access);
>     System.Bit_Ops.Bit_Or(XA,32,YA,32,RA);
>     return A2A.To_Pointer(RA).all;
>  end C_Or;
>  pragma Inline(C_Or);

  A good rule of thumb with Ada is "If it's hard, you're approaching
it wrong".




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Or
       [not found] <vhioga2t8wa.fsf@ljod.ifi.uio.no>
@ 2000-01-31  0:00 ` Gisle S�lensminde
  2000-01-31  0:00 ` Or Mark A Biggar
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: Gisle S�lensminde @ 2000-01-31  0:00 UTC (permalink / raw)


In article <vhioga2t8wa.fsf@ljod.ifi.uio.no>, Jan Kroken wrote:
>
>I need bitwise or on Interfaces.C.Int. I couldn't find any
>direct or operator in Ada, so I wrote the following:

<lot of code removed>

The bitwise logical operators is defined in Ada for modular types,
so you don't need C here. Here is an example:

procedure Kroken is

   type Modular is mod 2**32;

   A, B, C : Modular;

begin
   A := 16#00FF#;
   B := 16#FF00#;
   C := A or B;

end; 

If your purpose is interfacing with C, the types unsigned, 
unsigned_short and unsigned_long is defined in interfaces.c

--
Gisle S�lensminde ( gisle@ii.uib.no )   

ln -s /dev/null ~/.netscape/cookies




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Or
       [not found] <vhioga2t8wa.fsf@ljod.ifi.uio.no>
  2000-01-31  0:00 ` Or Gisle S�lensminde
@ 2000-01-31  0:00 ` Mark A Biggar
  2000-01-31  0:00 ` Or David Starner
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: Mark A Biggar @ 2000-01-31  0:00 UTC (permalink / raw)


Jan Kroken wrote:
> 
> I need bitwise or on Interfaces.C.Int. I couldn't find any
> direct or operator in Ada, so I wrote the following:
> 
>    function C_Or (R: C.Int;
>                   L: C.Int) return C.Int
>    is
>       type Int_Access is access all C.Int;
>       package A2A is new System.Address_To_Access_Conversions(C.Int);
>       X,Y,Result: aliased C.Int;
>       XA,YA,RA: System.Address;
>       RP : Int_Access;
>    begin
>       X := R;
>       Y := L;
>       XA := A2A.To_Address(X'Access);
>       YA := A2A.To_Address(Y'Access);
>       RA := A2A.To_Address(Result'Access);
>       System.Bit_Ops.Bit_Or(XA,32,YA,32,RA);
>       return A2A.To_Pointer(RA).all;
>    end C_Or;
>    pragma Inline(C_Or);

You might try something like:

function C_Or (R: C.Int;
               L: C.Int) return C.Int
is
    subtype Unsigned is C.Unsigned;
    function to_Unsigned(X: C.int) return Unsigned is
	new Unchecked_Conversion(C.Int, Unsigned);
    function to_Int(X: Unsigned) return C.Int is
	new Unchecked_conversion(Unsigned, C.Int);
begin
    return to_Int(to_Unsigned(R) or to_Unsigned(L));
end C_Or;
pragma Inline(C_Or);

--
Mark Biggar
mark.a.biggar@lmco.com




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Or
       [not found] <vhioga2t8wa.fsf@ljod.ifi.uio.no>
                   ` (3 preceding siblings ...)
  2000-01-31  0:00 ` Or tmoran
@ 2000-01-31  0:00 ` Vladimir Olensky
  4 siblings, 0 replies; 5+ messages in thread
From: Vladimir Olensky @ 2000-01-31  0:00 UTC (permalink / raw)



Jan Kroken wrote in message ...
>
>I need bitwise or on Interfaces.C.Int. I couldn't find any
>direct or operator in Ada, so I wrote the following:


Ada modular types provide bitwise operations.
So if you need bitwise operations on Integers or C.Int
you should change their view to modular type and then
do bitwise operations.

Something like this:

CIM is new  Ada.Unchecked_Conversion ( Interfaces.C.Int,

Interfaces.C.Unsigned);
CMI is new  Ada.Unchecked_Conversion (  Interfaces.C.Unsigned,

Interfaces.C.Int);

...
a : Interfaces.C.Int;
b : Interfaces.C.Int;
c :  Interfaces.C.Int;


c  := CMI ( CIM(a) or  CIM (b) );

That's all you need.

Regards,
Vladimir Olensky








^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Or
       [not found] <vhioga2t8wa.fsf@ljod.ifi.uio.no>
  2000-01-31  0:00 ` Or Gisle S�lensminde
  2000-01-31  0:00 ` Or Mark A Biggar
@ 2000-01-31  0:00 ` David Starner
  2000-01-31  0:00 ` Or tmoran
  2000-01-31  0:00 ` Or Vladimir Olensky
  4 siblings, 0 replies; 5+ messages in thread
From: David Starner @ 2000-01-31  0:00 UTC (permalink / raw)


On 31 Jan 2000 19:04:37 +0100, Jan Kroken <jankr@nntp.ifi.uio.no> wrote:
>
>I need bitwise or on Interfaces.C.Int. I couldn't find any
>direct or operator in Ada, so I wrote the following:
[Code and stuff]
>
>But how do I implement bit or so that the compiler
>will generate orl instead?

If you really want it to use orl, use a machine code insertion
and specifically put orl there. (Cf. GNAT Refrence Manual on
the rather hairy specifics.) It's not portable, and the Ada
solution (as posted by others) is better, but if you're really
concerned about that level, nothing can be beat writting it
at that level.

-- 
David Starner - dstarner98@aasaa.ofe.org
If you wish to strive for peace of soul then believe; 
if you wish to be a devotee of truth, then inquire.
   -- Friedrich Nietzsche




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2000-01-31  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <vhioga2t8wa.fsf@ljod.ifi.uio.no>
2000-01-31  0:00 ` Or Gisle S�lensminde
2000-01-31  0:00 ` Or Mark A Biggar
2000-01-31  0:00 ` Or David Starner
2000-01-31  0:00 ` Or tmoran
2000-01-31  0:00 ` Or Vladimir Olensky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox