]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/Include/Containers/ModuloUtil.h
2 Utility functions for performing basic math operations constrained within a
5 These functions are intended to simplify small changes to a value which much
6 remain within a specified modulus. Changes must be less than or equal to
7 the modulus specified by MaxVal.
9 Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
10 This program and the accompanying materials are licensed and made available
11 under the terms and conditions of the BSD License which accompanies this
12 distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php.
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #ifndef _MODULO_UTIL_H
19 #define _MODULO_UTIL_H
21 #include <sys/EfiCdefs.h>
25 /** Counter = (Counter + 1) % MaxVal;
27 Counter is always expected to be LESS THAN MaxVal.
30 @param[in] Counter The value to be incremented.
31 @param[in] MaxVal Modulus of the operation.
33 @return Returns the result of incrementing Counter, modulus MaxVal.
34 If Counter >= MaxVal, returns -1.
43 /** Counter = (Counter - 1) % MaxVal;
45 Counter is always expected to be LESS THAN MaxVal.
48 @param[in] Counter The value to be decremented.
49 @param[in] MaxVal Modulus of the operation.
51 @return Returns the result of decrementing Counter, modulus MaxVal.
52 If Counter >= MaxVal, returns -1.
61 /** Counter = (Counter + Increment) % MaxVal;
63 @param[in] Counter The value to be incremented.
64 @param[in] Increment The value to add to Counter.
65 @param[in] MaxVal Modulus of the operation.
67 @return Returns the result of adding Increment to Counter, modulus MaxVal,
68 or -1 if Increment is larger than MaxVal.
78 /** Increment Counter but don't increment past MaxVal.
80 @param[in] Counter The value to be decremented.
81 @param[in] MaxVal The upper bound for Counter. Counter < MaxVal.
83 @return Returns the result of incrementing Counter.
92 /** Decrement Counter but don't decrement past zero.
94 @param[in] Counter The value to be decremented.
96 @return Returns the result of decrementing Counter.
105 #endif /* _MODULO_UTIL_H */