Add Div_Round_Closest() for positive integer types

Change-Id: Ic8d398902947bf18d97c9ab3c6ca6204aa0629f0
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.coreboot.org/18356
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Tested-by: Nico Huber <nico.h@gmx.de>
diff --git a/common/hw.ads b/common/hw.ads
index 9adb794..6537542 100644
--- a/common/hw.ads
+++ b/common/hw.ads
@@ -1,5 +1,5 @@
 --
--- Copyright (C) 2015 secunet Security Networks AG
+-- Copyright (C) 2015-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
@@ -53,6 +53,30 @@
    subtype Pos32 is Interfaces.Integer_32 range 1 .. Interfaces.Integer_32'Last;
    subtype Pos64 is Interfaces.Integer_64 range 1 .. Interfaces.Integer_64'Last;
 
+   use type Pos8;
+   function Div_Round_Closest (N, M : Pos8) return Int8
+   with
+      Pre => N <= Pos8'Last - M / 2,
+      Post => Div_Round_Closest'Result = (N + M / 2) / M;
+
+   use type Pos16;
+   function Div_Round_Closest (N, M : Pos16) return Int16
+   with
+      Pre => N <= Pos16'Last - M / 2,
+      Post => Div_Round_Closest'Result = (N + M / 2) / M;
+
+   use type Pos32;
+   function Div_Round_Closest (N, M : Pos32) return Int32
+   with
+      Pre => N <= Pos32'Last - M / 2,
+      Post => Div_Round_Closest'Result = (N + M / 2) / M;
+
+   use type Pos64;
+   function Div_Round_Closest (N, M : Pos64) return Int64
+   with
+      Pre => N <= Pos64'Last - M / 2,
+      Post => Div_Round_Closest'Result = (N + M / 2) / M;
+
    subtype Buffer_Range is Natural range 0 .. Natural'Last - 1;
    type Buffer is array (Buffer_Range range <>) of Byte;