home *** CD-ROM | disk | FTP | other *** search
- --
- -- Copyright (C) 1996 Ada Resource Association (ARA), Columbus, Ohio.
- -- Author: Gilles Demailly
- --
- --
- -- Permission to use, copy, modify, and distribute this software and its
- -- documentation for any purpose and without fee is hereby granted,
- -- provided that the above copyright and authorship notice appear in all
- -- copies and that both that copyright notice and this permission notice
- -- appear in supporting documentation.
- --
- -- The ARA makes no representations about the suitability of this software
- -- for any purpose. It is provided "as is" without express
- -- or implied warranty.
- --
-
- --
- -- Package Basic_Definitions is designed to provide portable basic numeric
- -- types such as Integer, Natural, Positive and Unsigned Integers.
- -- All of these types are provided on 8, 16, 32 and 64 bits.
- -- Basic portable floats types are provided (32 and 64 bits).
- -- Basic bit manipulation functions on unsigned integers are provided
- --
- -- Note on the Unsigned integers representation and portability :
- -----------------------------------------------------------------
- -- We considerer that all Unsigned integers representation to follow
- -- the following rules (regardless of the platform) :
- --
- -- - Most significant bit is always 0.
- --
- -- - Bit numbers :
- --
- -- ----------
- -- |01234567| eight bit wide unsigned integer
- -- ----------
- --
- -- ---------------
- -- |0123456789 ... larger than eight bit wide unsigned integer
- -- ---------------
- --
- -- Portability accross platforms is guaranted by this logical (rather
- -- than physical) representation rule.
- --
- --
- --
- -- Example :
- --
- -- on a Sun workstation Unsigned_8 has the following physical representation :
- -- ----------
- -- |00000001|
- -- ----------
- --
- -- on a PC-Intel platform it has the following physical representation :
- -- ----------
- -- |10000000|
- -- ----------
- --
- -- If you try the function Bit_At (One, 7) you will get True on both
- -- platforms (because our representation takes others the underlying one).
-
-
-
- package Basic_Definitions is
-
- pragma Pure (Basic_Definitions);
-
- Integer_8_Size : constant := 8;
- Integer_16_Size : constant := 16;
- Integer_32_Size : constant := 32;
- Integer_64_Size : constant := 64;
-
- --
- -- basic Integer types definitions
- --
-
- type Integer_8 is range -2 ** 7 .. 2 ** 7 - 1;
- for Integer_8'Size use Integer_8_Size;
-
- subtype Natural_8 is Integer_8 range 0..Integer_8'Last;
- subtype Positive_8 is Integer_8 range 1..Integer_8'Last;
-
- type Integer_16 is range -2 ** 15 .. 2 ** 15 - 1;
- for Integer_16'Size use Integer_16_Size;
-
- subtype Natural_16 is Integer_16 range 0..Integer_16'Last;
- subtype Positive_16 is Integer_16 range 1..Integer_16'Last;
-
- type Integer_32 is range -2 ** 31 .. 2 ** 31 - 1;
- for Integer_32'Size use Integer_32_Size;
-
- subtype Natural_32 is Integer_32 range 0..Integer_32'Last;
- subtype Positive_32 is Integer_32 range 1..Integer_32'Last;
-
- type Integer_64 is range -2 ** 63 .. 2 ** 63 - 1;
- for Integer_64'Size use Integer_64_Size;
-
- subtype Natural_64 is Integer_64 range 0..Integer_64'Last;
- subtype Positive_64 is Integer_64 range 1..Integer_64'Last;
-
- type Unsigned_8 is mod 2 ** 8;
- for Unsigned_8'Size use Integer_8_Size;
-
- type Unsigned_16 is mod 2 ** 16;
- for Unsigned_16'Size use Integer_16_Size;
-
- type Unsigned_32 is mod 2 ** 32;
- for Unsigned_32'Size use Integer_32_Size;
-
- type Unsigned_64 is mod 2 ** 64;
- for Unsigned_64'Size use Integer_64_Size;
-
-
- --
- -- basic Float types definitions
- --
-
- type Float_64 is digits 15;
- for Float_64'Size use 64;
-
- subtype positive_or_null_float_64 is float_64 range 0.0 .. float_64'Last;
-
- subtype positive_float_64 is float_64
- range float_64'Model_Small .. float_64'Last;
-
- type float_32 is digits 6;
- for float_32'Size use 32;
-
- subtype positive_or_null_float_32 is float_32 range 0.0 .. float_32'Last;
-
- subtype positive_float_32 is float_32
- range float_32'Model_Small .. float_32'Last;
-
- --
- -- Shift unsigned integers functions
- --
-
- function Shift_Left
- (Value : Unsigned_8;
- Amount : Natural)
- return Unsigned_8;
-
- function Shift_Right
- (Value : Unsigned_8;
- Amount : Natural)
- return Unsigned_8;
-
-
- function Shift_Left
- (Value : Unsigned_16;
- Amount : Natural)
- return Unsigned_16;
-
- function Shift_Right
- (Value : Unsigned_16;
- Amount : Natural)
- return Unsigned_16;
-
-
- function Shift_Left
- (Value : Unsigned_32;
- Amount : Natural)
- return Unsigned_32;
-
- function Shift_Right
- (Value : Unsigned_32;
- Amount : Natural)
- return Unsigned_32;
-
- function Shift_Left
- (Value : Unsigned_64;
- Amount : Natural)
- return Unsigned_64;
-
- function Shift_Right
- (Value : Unsigned_64;
- Amount : Natural)
- return Unsigned_64;
-
-
- pragma Inline (Shift_Left);
- pragma Inline (Shift_Right);
-
- --
- -- Logical Operators
- --
-
- function "and" (Left, Right : Unsigned_8) return Unsigned_8;
- function "and" (Left, Right : Unsigned_16) return Unsigned_16;
- function "and" (Left, Right : Unsigned_32) return Unsigned_32;
- function "and" (Left, Right : Unsigned_64) return Unsigned_64;
-
- pragma Inline ("and");
-
- function "or" (Left, Right : Unsigned_8) return Unsigned_8;
- function "or" (Left, Right : Unsigned_16) return Unsigned_16;
- function "or" (Left, Right : Unsigned_32) return Unsigned_32;
- function "or" (Left, Right : Unsigned_64) return Unsigned_64;
-
- pragma Inline ("or");
-
- function "xor" (Left, Right : Unsigned_8) return Unsigned_8;
- function "xor" (Left, Right : Unsigned_16) return Unsigned_16;
- function "xor" (Left, Right : Unsigned_32) return Unsigned_32;
- function "xor" (Left, Right : Unsigned_64) return Unsigned_64;
-
- pragma Inline ("xor");
-
- function "not" (Right : Unsigned_8) return Unsigned_8;
- function "not" (Right : Unsigned_16) return Unsigned_16;
- function "not" (Right : Unsigned_32) return Unsigned_32;
- function "not" (Right : Unsigned_64) return Unsigned_64;
-
- pragma Inline ("not");
-
- --
- -- bit manipulation
- --
-
- --
- -- one bit access functions
- --
- function Bit_At (Value : Unsigned_8; Index : Natural) return Boolean;
- function Bit_At (Value : Unsigned_16; Index : Natural) return Boolean;
- function Bit_At (Value : Unsigned_32; Index : Natural) return Boolean;
- function Bit_At (Value : Unsigned_64; Index : Natural) return Boolean;
-
-
- --
- -- bits extraction functions
- --
- function Extract_Bits
- (Value : Unsigned_8;
- Start : Natural;
- Amount : Natural)
- return Unsigned_8;
-
- function Extract_Bits
- (Value : Unsigned_16;
- Start : Natural;
- Amount : Natural)
- return Unsigned_16;
-
- function Extract_Bits
- (Value : Unsigned_32;
- Start : Natural;
- Amount : Natural)
- return Unsigned_32;
-
- function Extract_Bits
- (Value : Unsigned_64;
- Start : Natural;
- Amount : Natural)
- return Unsigned_64;
-
-
- --
- -- bits replacement functions
- --
- function Replace_Bits
- (Value : Unsigned_8;
- Start : Natural;
- Amount : Natural;
- Source : Unsigned_8)
- return Unsigned_8;
-
- function Replace_Bits
- (Value : Unsigned_16;
- Start : Natural;
- Amount : Natural;
- Source : Unsigned_16)
- return Unsigned_16;
-
- function Replace_Bits
- (Value : Unsigned_32;
- Start : Natural;
- Amount : Natural;
- Source : Unsigned_32)
- return Unsigned_32;
-
- function Replace_Bits
- (Value : Unsigned_64;
- Start : Natural;
- Amount : Natural;
- Source : Unsigned_64)
- return Unsigned_64;
-
-
- end Basic_Definitions;
-