+/** @file\r
+ Utility functions for performing basic math operations constrained within a\r
+ modulus.\r
+\r
+ These functions are intended to simplify small changes to a value which much\r
+ remain within a specified modulus. Changes must be less than or equal to\r
+ the modulus specified by MaxVal.\r
+\r
+ Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>\r
+ This program and the accompanying materials are licensed and made available\r
+ under the terms and conditions of the BSD License which accompanies this\r
+ distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php.\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#ifndef _MODULO_UTIL_H\r
+#define _MODULO_UTIL_H\r
+#include <Uefi.h>\r
+#include <sys/EfiCdefs.h>\r
+\r
+__BEGIN_DECLS\r
+\r
+/** Counter = (Counter + 1) % MaxVal;\r
+\r
+ Counter is always expected to be LESS THAN MaxVal.\r
+ 0 <= Counter < MaxVal\r
+\r
+ @param[in] Counter The value to be incremented.\r
+ @param[in] MaxVal Modulus of the operation.\r
+\r
+ @return Returns the result of incrementing Counter, modulus MaxVal.\r
+ If Counter >= MaxVal, returns -1.\r
+**/\r
+INT32\r
+EFIAPI\r
+ModuloIncrement(\r
+ UINT32 Counter,\r
+ UINT32 MaxVal\r
+ );\r
+\r
+/** Counter = (Counter - 1) % MaxVal;\r
+\r
+ Counter is always expected to be LESS THAN MaxVal.\r
+ 0 <= Counter < MaxVal\r
+\r
+ @param[in] Counter The value to be decremented.\r
+ @param[in] MaxVal Modulus of the operation.\r
+\r
+ @return Returns the result of decrementing Counter, modulus MaxVal.\r
+ If Counter >= MaxVal, returns -1.\r
+**/\r
+INT32\r
+EFIAPI\r
+ModuloDecrement(\r
+ UINT32 Counter,\r
+ UINT32 MaxVal\r
+ );\r
+\r
+/** Counter = (Counter + Increment) % MaxVal;\r
+\r
+ @param[in] Counter The value to be incremented.\r
+ @param[in] Increment The value to add to Counter.\r
+ @param[in] MaxVal Modulus of the operation.\r
+\r
+ @return Returns the result of adding Increment to Counter, modulus MaxVal,\r
+ or -1 if Increment is larger than MaxVal.\r
+**/\r
+INT32\r
+EFIAPI\r
+ModuloAdd (\r
+ UINT32 Counter,\r
+ UINT32 Increment,\r
+ UINT32 MaxVal\r
+ );\r
+\r
+/** Increment Counter but don't increment past MaxVal.\r
+\r
+ @param[in] Counter The value to be decremented.\r
+ @param[in] MaxVal The upper bound for Counter. Counter < MaxVal.\r
+\r
+ @return Returns the result of incrementing Counter.\r
+**/\r
+UINT32\r
+EFIAPI\r
+BoundIncrement(\r
+ UINT32 Counter,\r
+ UINT32 MaxVal\r
+ );\r
+\r
+/** Decrement Counter but don't decrement past zero.\r
+\r
+ @param[in] Counter The value to be decremented.\r
+\r
+ @return Returns the result of decrementing Counter.\r
+**/\r
+UINT32\r
+EFIAPI\r
+BoundDecrement(\r
+ UINT32 Counter\r
+ );\r
+\r
+__END_DECLS\r
+#endif /* _MODULO_UTIL_H */\r