comp.lang.ada
 help / color / mirror / Atom feed
* Some idea could be:
@ 2011-08-29 17:14 Per Sandberg
  2011-08-29 19:17 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 2+ messages in thread
From: Per Sandberg @ 2011-08-29 17:14 UTC (permalink / raw)


The whole idea is copied from "System.Storage_Elements".
/P

---------------------------------------------------------
with System; use System;
with System.Storage_Elements; use System.Storage_Elements;
package ops is
    function "and" (Left  : Address;
                    Right : Address) return Address;
    pragma Convention (Intrinsic, "and");
    pragma Inline_Always ("and");
    pragma Pure_Function ("and");

    function "or" (Left  : Address;
                   Right : Address) return Address;
    pragma Convention (Intrinsic, "or");
    pragma Inline_Always ("or");
    pragma Pure_Function ("or");


    function "xor" (Left  : Address;
                    Right : Address) return Address;
    pragma Convention (Intrinsic, "xor");
    pragma Inline_Always ("xor");
    pragma Pure_Function ("xor");

    function "xor"
      (Left  : Address;
       Right : Integer_Address) return Address;
    pragma Convention (Intrinsic, "xor");
    pragma Inline_Always ("xor");
    pragma Pure_Function ("xor");

    function "xor"
      (Left  : Integer_Address;
       Right : Address) return Address;

    pragma Convention (Intrinsic, "xor");
    pragma Inline_Always ("xor");
    pragma Pure_Function ("xor");

end ops;

-----------------------------------------------------
package body ops is

    function "and"
      (Left  : Address;
       Right : Address)
       return Address
    is
    begin
       return To_Address (To_Integer (Left) and To_Integer (Right));
    end "and";


    function "or"
      (Left  : Address;
       Right : Address)
       return Address
    is
    begin
       return To_Address (To_Integer (Left) or To_Integer (Right));
    end "or";


    function "xor"
      (Left  : Address;
       Right : Address)
       return Address
    is
    begin
       return To_Address (To_Integer (Left) xor To_Integer (Right));
    end "xor";

    function "xor"
      (Left  : Address;
       Right : Integer_Address) return Address is
    begin
       return To_Address (To_Integer (Left) xor Right);
    end "xor";

    function "xor"
      (Left  : Integer_Address;
       Right : Address) return Address is
    begin
       return To_Address (Left xor To_Integer (Right));
    end "xor";
end ops;
------------------------------------------------------------
with ops; use ops;
with System.Storage_Elements; use System.Storage_Elements;
procedure My_Address_Ops_Demo is
    a1 : System.Address;
    a2 : System.Address;
    a3 : System.Address;
    pragma Unreferenced (a3);
begin
    a1 := a2'Address;
    a2 := a1'Address;
    a3 := 2#0000_0000_1111_1111# xor a2;
end My_Address_Ops_Demo;
-----------------------------------------------------------



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

* Re: Some idea could be:
  2011-08-29 17:14 Some idea could be: Per Sandberg
@ 2011-08-29 19:17 ` Dmitry A. Kazakov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry A. Kazakov @ 2011-08-29 19:17 UTC (permalink / raw)


On Mon, 29 Aug 2011 19:14:43 +0200, Per Sandberg wrote:

> The whole idea is copied from "System.Storage_Elements".

Integer_Address is not necessarily modular. See 13.7.1(13). Therefore it is
not guaranteed to work. Masking etc should be performed on relative offsets
rather than on absolute addresses or, for that matter, on their integer
equivalents. It is not even required 0 = To_Address (Null_Address).

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

end of thread, other threads:[~2011-08-29 19:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-29 17:14 Some idea could be: Per Sandberg
2011-08-29 19:17 ` Dmitry A. Kazakov

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