Add Div_Round_Up() for positive integer types
Also rewrite Div_Round_Closest() as expression functions. Change-Id: I9f4bb0f2f442510f821d367d8b11d14a4f697a7e Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/20557 Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
This commit is contained in:
parent
ba37830467
commit
4a10482666
|
@ -1,4 +1,3 @@
|
|||
hw-y += hw.adb
|
||||
hw-y += hw.ads
|
||||
hw-y += hw-mmio_range.ads
|
||||
hw-y += hw-mmio_regs.adb
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
--
|
||||
-- Copyright (C) 2017 secunet Security Networks AG
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; either version 2 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
|
||||
package body HW is
|
||||
|
||||
function Div_Round_Closest (N, M : Pos8) return Int8 is
|
||||
begin
|
||||
return (N + M / 2) / M;
|
||||
end Div_Round_Closest;
|
||||
|
||||
function Div_Round_Closest (N, M : Pos16) return Int16 is
|
||||
begin
|
||||
return (N + M / 2) / M;
|
||||
end Div_Round_Closest;
|
||||
|
||||
function Div_Round_Closest (N, M : Pos32) return Int32 is
|
||||
begin
|
||||
return (N + M / 2) / M;
|
||||
end Div_Round_Closest;
|
||||
|
||||
function Div_Round_Closest (N, M : Pos64) return Int64 is
|
||||
begin
|
||||
return (N + M / 2) / M;
|
||||
end Div_Round_Closest;
|
||||
|
||||
end HW;
|
|
@ -54,28 +54,36 @@ package HW is
|
|||
subtype Pos64 is Interfaces.Integer_64 range 1 .. Interfaces.Integer_64'Last;
|
||||
|
||||
use type Pos8;
|
||||
function Div_Round_Closest (N, M : Pos8) return Int8
|
||||
function Div_Round_Up (N, M : Pos8) return Pos8 is ((N + (M - 1)) / M)
|
||||
with
|
||||
Pre => N <= Pos8'Last - M / 2,
|
||||
Post => Div_Round_Closest'Result = (N + M / 2) / M;
|
||||
Pre => N <= Pos8'Last - (M - 1);
|
||||
function Div_Round_Closest (N, M : Pos8) return Int8 is ((N + M / 2) / M)
|
||||
with
|
||||
Pre => N <= Pos8'Last - M / 2;
|
||||
|
||||
use type Pos16;
|
||||
function Div_Round_Closest (N, M : Pos16) return Int16
|
||||
function Div_Round_Up (N, M : Pos16) return Pos16 is ((N + (M - 1)) / M)
|
||||
with
|
||||
Pre => N <= Pos16'Last - M / 2,
|
||||
Post => Div_Round_Closest'Result = (N + M / 2) / M;
|
||||
Pre => N <= Pos16'Last - (M - 1);
|
||||
function Div_Round_Closest (N, M : Pos16) return Int16 is ((N + M / 2) / M)
|
||||
with
|
||||
Pre => N <= Pos16'Last - M / 2;
|
||||
|
||||
use type Pos32;
|
||||
function Div_Round_Closest (N, M : Pos32) return Int32
|
||||
function Div_Round_Up (N, M : Pos32) return Pos32 is ((N + (M - 1)) / M)
|
||||
with
|
||||
Pre => N <= Pos32'Last - M / 2,
|
||||
Post => Div_Round_Closest'Result = (N + M / 2) / M;
|
||||
Pre => N <= Pos32'Last - (M - 1);
|
||||
function Div_Round_Closest (N, M : Pos32) return Int32 is ((N + M / 2) / M)
|
||||
with
|
||||
Pre => N <= Pos32'Last - M / 2;
|
||||
|
||||
use type Pos64;
|
||||
function Div_Round_Closest (N, M : Pos64) return Int64
|
||||
function Div_Round_Up (N, M : Pos64) return Pos64 is ((N + (M - 1)) / M)
|
||||
with
|
||||
Pre => N <= Pos64'Last - M / 2,
|
||||
Post => Div_Round_Closest'Result = (N + M / 2) / M;
|
||||
Pre => N <= Pos64'Last - (M - 1);
|
||||
function Div_Round_Closest (N, M : Pos64) return Int64 is ((N + M / 2) / M)
|
||||
with
|
||||
Pre => N <= Pos64'Last - M / 2;
|
||||
|
||||
subtype Buffer_Range is Natural range 0 .. Natural'Last - 1;
|
||||
type Buffer is array (Buffer_Range range <>) of Byte;
|
||||
|
|
Loading…
Reference in New Issue