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.adb b/common/hw.adb
new file mode 100644
index 0000000..b8f1e52
--- /dev/null
+++ b/common/hw.adb
@@ -0,0 +1,37 @@
+--
+-- 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;