blob: 56debabc23fe84bf62e0a52e032e76a9c0162cab [file] [log] [blame]
Nico Huber5e9b1b52016-10-08 22:09:33 +02001--
Nico Hubera5c8ba22017-02-09 16:35:33 +01002-- Copyright (C) 2015-2017 secunet Security Networks AG
Nico Huber5e9b1b52016-10-08 22:09:33 +02003--
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 Huberaab715f2016-10-18 00:22:25 +02006-- the Free Software Foundation; either version 2 of the License, or
7-- (at your option) any later version.
Nico Huber5e9b1b52016-10-08 22:09:33 +02008--
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
15with Interfaces;
16
17package 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 Hubera5c8ba22017-02-09 16:35:33 +010056 use type Pos8;
Nico Huber4a104822017-07-09 22:13:14 +020057 function Div_Round_Up (N, M : Pos8) return Pos8 is ((N + (M - 1)) / M)
Nico Hubera5c8ba22017-02-09 16:35:33 +010058 with
Nico Huber4a104822017-07-09 22:13:14 +020059 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 Hubera5c8ba22017-02-09 16:35:33 +010063
64 use type Pos16;
Nico Huber4a104822017-07-09 22:13:14 +020065 function Div_Round_Up (N, M : Pos16) return Pos16 is ((N + (M - 1)) / M)
Nico Hubera5c8ba22017-02-09 16:35:33 +010066 with
Nico Huber4a104822017-07-09 22:13:14 +020067 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 Hubera5c8ba22017-02-09 16:35:33 +010071
72 use type Pos32;
Nico Huber4a104822017-07-09 22:13:14 +020073 function Div_Round_Up (N, M : Pos32) return Pos32 is ((N + (M - 1)) / M)
Nico Hubera5c8ba22017-02-09 16:35:33 +010074 with
Nico Huber4a104822017-07-09 22:13:14 +020075 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 Hubera5c8ba22017-02-09 16:35:33 +010079
80 use type Pos64;
Nico Huber4a104822017-07-09 22:13:14 +020081 function Div_Round_Up (N, M : Pos64) return Pos64 is ((N + (M - 1)) / M)
Nico Hubera5c8ba22017-02-09 16:35:33 +010082 with
Nico Huber4a104822017-07-09 22:13:14 +020083 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 Hubera5c8ba22017-02-09 16:35:33 +010087
Nico Huber5e9b1b52016-10-08 22:09:33 +020088 subtype Buffer_Range is Natural range 0 .. Natural'Last - 1;
89 type Buffer is array (Buffer_Range range <>) of Byte;
90
91end HW;