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>
diff --git a/common/Makefile.inc b/common/Makefile.inc
index cc88032..d6ec728 100644
--- a/common/Makefile.inc
+++ b/common/Makefile.inc
@@ -1,4 +1,3 @@
-hw-y += hw.adb
 hw-y += hw.ads
 hw-y += hw-mmio_range.ads
 hw-y += hw-mmio_regs.adb
diff --git a/common/hw.adb b/common/hw.adb
deleted file mode 100644
index b8f1e52..0000000
--- a/common/hw.adb
+++ /dev/null
@@ -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;
diff --git a/common/hw.ads b/common/hw.ads
index 6537542..56debab 100644
--- a/common/hw.ads
+++ b/common/hw.ads
@@ -54,28 +54,36 @@
    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;