| Nico Huber | 5e9b1b5 | 2016-10-08 22:09:33 +0200 | [diff] [blame] | 1 | -- |
| Nico Huber | a5c8ba2 | 2017-02-09 16:35:33 +0100 | [diff] [blame] | 2 | -- Copyright (C) 2015-2017 secunet Security Networks AG |
| Nico Huber | 5e9b1b5 | 2016-10-08 22:09:33 +0200 | [diff] [blame] | 3 | -- |
| 4 | -- This program is free software; you can redistribute it and/or modify |
| 5 | -- it under the terms of the GNU General Public License as published by |
| Nico Huber | aab715f | 2016-10-18 00:22:25 +0200 | [diff] [blame] | 6 | -- the Free Software Foundation; either version 2 of the License, or |
| 7 | -- (at your option) any later version. |
| Nico Huber | 5e9b1b5 | 2016-10-08 22:09:33 +0200 | [diff] [blame] | 8 | -- |
| 9 | -- This program is distributed in the hope that it will be useful, |
| 10 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | -- GNU General Public License for more details. |
| 13 | -- |
| 14 | |
| 15 | with Interfaces; |
| 16 | |
| 17 | package HW is |
| 18 | |
| 19 | type Bit is mod 2 ** 1; |
| 20 | |
| 21 | subtype Byte is Interfaces.Unsigned_8; |
| 22 | subtype Word8 is Byte; |
| 23 | function Shift_Left (Value : Word8; Amount : Natural) return Word8 |
| 24 | renames Interfaces.Shift_Left; |
| 25 | function Shift_Right (Value : Word8; Amount : Natural) return Word8 |
| 26 | renames Interfaces.Shift_Right; |
| 27 | |
| 28 | subtype Word16 is Interfaces.Unsigned_16; |
| 29 | function Shift_Left (Value : Word16; Amount : Natural) return Word16 |
| 30 | renames Interfaces.Shift_Left; |
| 31 | function Shift_Right (Value : Word16; Amount : Natural) return Word16 |
| 32 | renames Interfaces.Shift_Right; |
| 33 | |
| 34 | subtype Word32 is Interfaces.Unsigned_32; |
| 35 | function Shift_Left (Value : Word32; Amount : Natural) return Word32 |
| 36 | renames Interfaces.Shift_Left; |
| 37 | function Shift_Right (Value : Word32; Amount : Natural) return Word32 |
| 38 | renames Interfaces.Shift_Right; |
| 39 | |
| 40 | subtype Word64 is Interfaces.Unsigned_64; |
| 41 | function Shift_Left (Value : Word64; Amount : Natural) return Word64 |
| 42 | renames Interfaces.Shift_Left; |
| 43 | function Shift_Right (Value : Word64; Amount : Natural) return Word64 |
| 44 | renames Interfaces.Shift_Right; |
| 45 | |
| 46 | subtype Int8 is Interfaces.Integer_8; |
| 47 | subtype Int16 is Interfaces.Integer_16; |
| 48 | subtype Int32 is Interfaces.Integer_32; |
| 49 | subtype Int64 is Interfaces.Integer_64; |
| 50 | |
| 51 | subtype Pos8 is Interfaces.Integer_8 range 1 .. Interfaces.Integer_8'Last; |
| 52 | subtype Pos16 is Interfaces.Integer_16 range 1 .. Interfaces.Integer_16'Last; |
| 53 | subtype Pos32 is Interfaces.Integer_32 range 1 .. Interfaces.Integer_32'Last; |
| 54 | subtype Pos64 is Interfaces.Integer_64 range 1 .. Interfaces.Integer_64'Last; |
| 55 | |
| Nico Huber | a5c8ba2 | 2017-02-09 16:35:33 +0100 | [diff] [blame] | 56 | use type Pos8; |
| Nico Huber | 4a10482 | 2017-07-09 22:13:14 +0200 | [diff] [blame^] | 57 | function Div_Round_Up (N, M : Pos8) return Pos8 is ((N + (M - 1)) / M) |
| Nico Huber | a5c8ba2 | 2017-02-09 16:35:33 +0100 | [diff] [blame] | 58 | with |
| Nico Huber | 4a10482 | 2017-07-09 22:13:14 +0200 | [diff] [blame^] | 59 | Pre => N <= Pos8'Last - (M - 1); |
| 60 | function Div_Round_Closest (N, M : Pos8) return Int8 is ((N + M / 2) / M) |
| 61 | with |
| 62 | Pre => N <= Pos8'Last - M / 2; |
| Nico Huber | a5c8ba2 | 2017-02-09 16:35:33 +0100 | [diff] [blame] | 63 | |
| 64 | use type Pos16; |
| Nico Huber | 4a10482 | 2017-07-09 22:13:14 +0200 | [diff] [blame^] | 65 | function Div_Round_Up (N, M : Pos16) return Pos16 is ((N + (M - 1)) / M) |
| Nico Huber | a5c8ba2 | 2017-02-09 16:35:33 +0100 | [diff] [blame] | 66 | with |
| Nico Huber | 4a10482 | 2017-07-09 22:13:14 +0200 | [diff] [blame^] | 67 | Pre => N <= Pos16'Last - (M - 1); |
| 68 | function Div_Round_Closest (N, M : Pos16) return Int16 is ((N + M / 2) / M) |
| 69 | with |
| 70 | Pre => N <= Pos16'Last - M / 2; |
| Nico Huber | a5c8ba2 | 2017-02-09 16:35:33 +0100 | [diff] [blame] | 71 | |
| 72 | use type Pos32; |
| Nico Huber | 4a10482 | 2017-07-09 22:13:14 +0200 | [diff] [blame^] | 73 | function Div_Round_Up (N, M : Pos32) return Pos32 is ((N + (M - 1)) / M) |
| Nico Huber | a5c8ba2 | 2017-02-09 16:35:33 +0100 | [diff] [blame] | 74 | with |
| Nico Huber | 4a10482 | 2017-07-09 22:13:14 +0200 | [diff] [blame^] | 75 | Pre => N <= Pos32'Last - (M - 1); |
| 76 | function Div_Round_Closest (N, M : Pos32) return Int32 is ((N + M / 2) / M) |
| 77 | with |
| 78 | Pre => N <= Pos32'Last - M / 2; |
| Nico Huber | a5c8ba2 | 2017-02-09 16:35:33 +0100 | [diff] [blame] | 79 | |
| 80 | use type Pos64; |
| Nico Huber | 4a10482 | 2017-07-09 22:13:14 +0200 | [diff] [blame^] | 81 | function Div_Round_Up (N, M : Pos64) return Pos64 is ((N + (M - 1)) / M) |
| Nico Huber | a5c8ba2 | 2017-02-09 16:35:33 +0100 | [diff] [blame] | 82 | with |
| Nico Huber | 4a10482 | 2017-07-09 22:13:14 +0200 | [diff] [blame^] | 83 | Pre => N <= Pos64'Last - (M - 1); |
| 84 | function Div_Round_Closest (N, M : Pos64) return Int64 is ((N + M / 2) / M) |
| 85 | with |
| 86 | Pre => N <= Pos64'Last - M / 2; |
| Nico Huber | a5c8ba2 | 2017-02-09 16:35:33 +0100 | [diff] [blame] | 87 | |
| Nico Huber | 5e9b1b5 | 2016-10-08 22:09:33 +0200 | [diff] [blame] | 88 | subtype Buffer_Range is Natural range 0 .. Natural'Last - 1; |
| 89 | type Buffer is array (Buffer_Range range <>) of Byte; |
| 90 | |
| 91 | end HW; |