blob: 65375428d6971e0ca6b4f8b4c06b4b9d4123b551 [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;
57 function Div_Round_Closest (N, M : Pos8) return Int8
58 with
59 Pre => N <= Pos8'Last - M / 2,
60 Post => Div_Round_Closest'Result = (N + M / 2) / M;
61
62 use type Pos16;
63 function Div_Round_Closest (N, M : Pos16) return Int16
64 with
65 Pre => N <= Pos16'Last - M / 2,
66 Post => Div_Round_Closest'Result = (N + M / 2) / M;
67
68 use type Pos32;
69 function Div_Round_Closest (N, M : Pos32) return Int32
70 with
71 Pre => N <= Pos32'Last - M / 2,
72 Post => Div_Round_Closest'Result = (N + M / 2) / M;
73
74 use type Pos64;
75 function Div_Round_Closest (N, M : Pos64) return Int64
76 with
77 Pre => N <= Pos64'Last - M / 2,
78 Post => Div_Round_Closest'Result = (N + M / 2) / M;
79
Nico Huber5e9b1b52016-10-08 22:09:33 +020080 subtype Buffer_Range is Natural range 0 .. Natural'Last - 1;
81 type Buffer is array (Buffer_Range range <>) of Byte;
82
83end HW;