home *** CD-ROM | disk | FTP | other *** search
/ Hacker / Hacker.iso / HACKER / DECOMP / DECAF / basidefi.ads < prev    next >
Encoding:
Text File  |  1996-09-19  |  8.2 KB  |  289 lines

  1. --
  2. -- Copyright (C) 1996 Ada Resource Association (ARA), Columbus, Ohio.
  3. -- Author: Gilles Demailly
  4. --
  5. --
  6. -- Permission to use, copy, modify, and distribute this software and its
  7. -- documentation for any purpose and without fee is hereby granted,
  8. -- provided that the above copyright and authorship notice appear in all
  9. -- copies and that both that copyright notice and this permission notice
  10. -- appear in supporting documentation.
  11. -- 
  12. -- The ARA makes no representations about the suitability of this software
  13. -- for any purpose.  It is provided "as is" without express
  14. -- or implied warranty.
  15. -- 
  16.  
  17. --
  18. -- Package Basic_Definitions is designed to provide portable basic numeric
  19. -- types such as Integer, Natural, Positive and Unsigned Integers.
  20. -- All of these types are provided on 8, 16, 32 and 64 bits.
  21. -- Basic portable floats types are provided (32 and 64 bits).
  22. -- Basic bit manipulation functions on unsigned integers are provided
  23. --
  24. -- Note on the Unsigned integers representation and portability :
  25. -----------------------------------------------------------------
  26. -- We considerer that all Unsigned integers representation to follow
  27. -- the following rules (regardless of the platform) :
  28. --
  29. --    - Most significant bit is always 0.
  30. --
  31. --    - Bit numbers :
  32. --
  33. --       ----------
  34. --       |01234567| eight bit wide unsigned integer
  35. --       ----------
  36. --
  37. --       ---------------
  38. --       |0123456789 ... larger than eight bit wide unsigned integer
  39. --       ---------------
  40. --
  41. -- Portability accross platforms is guaranted by this logical (rather
  42. -- than physical) representation rule.
  43. -- 
  44. -- 
  45. --
  46. -- Example :
  47. --
  48. -- on a Sun workstation Unsigned_8 has the following physical representation :
  49. --    ----------
  50. --    |00000001|
  51. --    ----------
  52. --
  53. -- on a PC-Intel platform it has the following physical representation :
  54. --    ----------
  55. --    |10000000|
  56. --    ----------
  57. -- 
  58. -- If you try the function Bit_At (One, 7) you will get True on both
  59. -- platforms (because our representation takes others the underlying one).
  60.  
  61.  
  62.  
  63. package Basic_Definitions is
  64.  
  65.    pragma Pure (Basic_Definitions);
  66.  
  67.    Integer_8_Size  : constant := 8;
  68.    Integer_16_Size : constant := 16;
  69.    Integer_32_Size : constant := 32;
  70.    Integer_64_Size : constant := 64;
  71.  
  72.    --
  73.    -- basic Integer types definitions
  74.    --
  75.    
  76.    type Integer_8  is range -2 **  7 .. 2 **  7 - 1;
  77.    for Integer_8'Size use  Integer_8_Size;
  78.    
  79.    subtype Natural_8  is Integer_8 range 0..Integer_8'Last;
  80.    subtype Positive_8 is Integer_8 range 1..Integer_8'Last;
  81.  
  82.    type Integer_16 is range -2 ** 15 .. 2 ** 15 - 1;
  83.    for Integer_16'Size use Integer_16_Size;
  84.  
  85.    subtype Natural_16  is Integer_16 range 0..Integer_16'Last;
  86.    subtype Positive_16 is Integer_16 range 1..Integer_16'Last;
  87.  
  88.    type Integer_32 is range -2 ** 31 .. 2 ** 31 - 1;
  89.    for Integer_32'Size use Integer_32_Size;
  90.  
  91.    subtype Natural_32  is Integer_32 range 0..Integer_32'Last;
  92.    subtype Positive_32 is Integer_32 range 1..Integer_32'Last;
  93.  
  94.    type Integer_64 is range -2 ** 63 .. 2 ** 63 - 1;
  95.    for Integer_64'Size use Integer_64_Size;
  96.  
  97.    subtype Natural_64  is Integer_64 range 0..Integer_64'Last;
  98.    subtype Positive_64 is Integer_64 range 1..Integer_64'Last;
  99.  
  100.    type Unsigned_8  is mod 2 **  8;
  101.    for Unsigned_8'Size use  Integer_8_Size;
  102.  
  103.    type Unsigned_16 is mod 2 ** 16;
  104.    for Unsigned_16'Size use Integer_16_Size;
  105.  
  106.    type Unsigned_32 is mod 2 ** 32;
  107.    for Unsigned_32'Size use Integer_32_Size;
  108.  
  109.    type Unsigned_64 is mod 2 ** 64;
  110.    for Unsigned_64'Size use Integer_64_Size;
  111.    
  112.    
  113.    -- 
  114.    -- basic Float types definitions
  115.    -- 
  116.    
  117.    type Float_64 is digits 15;
  118.    for  Float_64'Size use 64;
  119.  
  120.    subtype positive_or_null_float_64 is float_64 range 0.0 .. float_64'Last;
  121.  
  122.    subtype positive_float_64 is float_64 
  123.       range float_64'Model_Small .. float_64'Last;
  124.  
  125.    type float_32 is digits 6;
  126.    for  float_32'Size use 32;
  127.  
  128.    subtype positive_or_null_float_32 is float_32 range 0.0 .. float_32'Last;
  129.  
  130.    subtype positive_float_32 is float_32
  131.       range float_32'Model_Small .. float_32'Last;
  132.  
  133.    --
  134.    -- Shift unsigned integers functions
  135.    --
  136.    
  137.    function Shift_Left
  138.                (Value  : Unsigned_8;
  139.                 Amount : Natural)
  140.             return Unsigned_8;
  141.  
  142.    function Shift_Right
  143.                (Value  : Unsigned_8;
  144.                 Amount : Natural)
  145.             return Unsigned_8;
  146.  
  147.  
  148.    function Shift_Left
  149.                (Value  : Unsigned_16;
  150.                 Amount : Natural)
  151.             return Unsigned_16;
  152.  
  153.    function Shift_Right
  154.                (Value  : Unsigned_16;
  155.                 Amount : Natural)
  156.             return Unsigned_16;
  157.  
  158.  
  159.    function Shift_Left
  160.                (Value  : Unsigned_32;
  161.                 Amount : Natural)
  162.             return Unsigned_32;
  163.  
  164.    function Shift_Right
  165.                (Value  : Unsigned_32;
  166.                 Amount : Natural)
  167.             return Unsigned_32;
  168.  
  169.    function Shift_Left
  170.                (Value  : Unsigned_64;
  171.                 Amount : Natural)
  172.             return Unsigned_64;
  173.  
  174.    function Shift_Right
  175.                (Value  : Unsigned_64;
  176.                 Amount : Natural)
  177.             return Unsigned_64;
  178.  
  179.       
  180.    pragma Inline (Shift_Left);
  181.    pragma Inline (Shift_Right);
  182.    
  183.    --
  184.    -- Logical Operators
  185.    --
  186.  
  187.    function "and" (Left, Right : Unsigned_8)  return Unsigned_8;
  188.    function "and" (Left, Right : Unsigned_16) return Unsigned_16;
  189.    function "and" (Left, Right : Unsigned_32) return Unsigned_32;
  190.    function "and" (Left, Right : Unsigned_64) return Unsigned_64;
  191.  
  192.    pragma Inline ("and");
  193.    
  194.    function "or" (Left, Right : Unsigned_8)  return Unsigned_8;
  195.    function "or" (Left, Right : Unsigned_16) return Unsigned_16;
  196.    function "or" (Left, Right : Unsigned_32) return Unsigned_32;
  197.    function "or" (Left, Right : Unsigned_64) return Unsigned_64;
  198.  
  199.    pragma Inline ("or");
  200.    
  201.    function "xor" (Left, Right : Unsigned_8)  return Unsigned_8;
  202.    function "xor" (Left, Right : Unsigned_16) return Unsigned_16;
  203.    function "xor" (Left, Right : Unsigned_32) return Unsigned_32;
  204.    function "xor" (Left, Right : Unsigned_64) return Unsigned_64;
  205.  
  206.    pragma Inline ("xor");
  207.    
  208.    function "not" (Right : Unsigned_8)  return Unsigned_8;
  209.    function "not" (Right : Unsigned_16) return Unsigned_16;
  210.    function "not" (Right : Unsigned_32) return Unsigned_32;
  211.    function "not" (Right : Unsigned_64) return Unsigned_64;
  212.  
  213.    pragma Inline ("not");
  214.    
  215.    --
  216.    -- bit manipulation
  217.    --
  218.    
  219.    --
  220.    -- one bit access functions
  221.    --
  222.    function Bit_At (Value : Unsigned_8;  Index : Natural) return Boolean;
  223.    function Bit_At (Value : Unsigned_16; Index : Natural) return Boolean;
  224.    function Bit_At (Value : Unsigned_32; Index : Natural) return Boolean;
  225.    function Bit_At (Value : Unsigned_64; Index : Natural) return Boolean;
  226.    
  227.  
  228.    --
  229.    -- bits extraction functions
  230.    --
  231.    function Extract_Bits
  232.                (Value  : Unsigned_8;
  233.                 Start  : Natural;
  234.                 Amount : Natural)
  235.             return Unsigned_8;
  236.    
  237.    function Extract_Bits
  238.                (Value  : Unsigned_16;
  239.                 Start  : Natural;
  240.                 Amount : Natural)
  241.             return Unsigned_16;
  242.    
  243.    function Extract_Bits
  244.                (Value  : Unsigned_32;
  245.                 Start  : Natural;
  246.                 Amount : Natural)
  247.             return Unsigned_32;
  248.    
  249.    function Extract_Bits
  250.                (Value  : Unsigned_64;
  251.                 Start  : Natural;
  252.                 Amount : Natural)
  253.             return Unsigned_64;
  254.   
  255.   
  256.    --
  257.    -- bits replacement functions
  258.    --
  259.    function Replace_Bits
  260.                (Value  : Unsigned_8;
  261.                 Start  : Natural;
  262.                 Amount : Natural;
  263.                 Source : Unsigned_8)
  264.             return Unsigned_8;
  265.    
  266.    function Replace_Bits
  267.                (Value  : Unsigned_16;
  268.                 Start  : Natural;
  269.                 Amount : Natural;
  270.                 Source : Unsigned_16)
  271.             return Unsigned_16;
  272.    
  273.    function Replace_Bits
  274.                (Value  : Unsigned_32;
  275.                 Start  : Natural;
  276.                 Amount : Natural;
  277.                 Source : Unsigned_32)
  278.             return Unsigned_32;
  279.    
  280.    function Replace_Bits
  281.                (Value  : Unsigned_64;
  282.                 Start  : Natural;
  283.                 Amount : Natural;
  284.                 Source : Unsigned_64)
  285.             return Unsigned_64;
  286.    
  287.  
  288. end Basic_Definitions;
  289.