]>
Commit | Line | Data |
---|---|---|
6c6c850a | 1 | /** @file\r |
2 | Utility functions for performing basic math operations constrained within a\r | |
3 | modulus.\r | |
4 | \r | |
5 | These functions are intended to simplify small changes to a value which much\r | |
6 | remain within a specified modulus. Changes must be less than or equal to\r | |
7 | the modulus specified by MaxVal.\r | |
8 | \r | |
9 | Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>\r | |
10 | This program and the accompanying materials are licensed and made available\r | |
11 | under the terms and conditions of the BSD License which accompanies this\r | |
12 | distribution. The full text of the license may be found at\r | |
13 | http://opensource.org/licenses/bsd-license.php.\r | |
14 | \r | |
15 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
16 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
17 | **/\r | |
18 | #ifndef _MODULO_UTIL_H\r | |
19 | #define _MODULO_UTIL_H\r | |
20 | #include <Uefi.h>\r | |
21 | #include <sys/EfiCdefs.h>\r | |
22 | \r | |
23 | __BEGIN_DECLS\r | |
24 | \r | |
25 | /** Counter = (Counter + 1) % MaxVal;\r | |
26 | \r | |
27 | Counter is always expected to be LESS THAN MaxVal.\r | |
28 | 0 <= Counter < MaxVal\r | |
29 | \r | |
30 | @param[in] Counter The value to be incremented.\r | |
31 | @param[in] MaxVal Modulus of the operation.\r | |
32 | \r | |
33 | @return Returns the result of incrementing Counter, modulus MaxVal.\r | |
34 | If Counter >= MaxVal, returns -1.\r | |
35 | **/\r | |
36 | INT32\r | |
37 | EFIAPI\r | |
38 | ModuloIncrement(\r | |
39 | UINT32 Counter,\r | |
40 | UINT32 MaxVal\r | |
41 | );\r | |
42 | \r | |
43 | /** Counter = (Counter - 1) % MaxVal;\r | |
44 | \r | |
45 | Counter is always expected to be LESS THAN MaxVal.\r | |
46 | 0 <= Counter < MaxVal\r | |
47 | \r | |
48 | @param[in] Counter The value to be decremented.\r | |
49 | @param[in] MaxVal Modulus of the operation.\r | |
50 | \r | |
51 | @return Returns the result of decrementing Counter, modulus MaxVal.\r | |
52 | If Counter >= MaxVal, returns -1.\r | |
53 | **/\r | |
54 | INT32\r | |
55 | EFIAPI\r | |
56 | ModuloDecrement(\r | |
57 | UINT32 Counter,\r | |
58 | UINT32 MaxVal\r | |
59 | );\r | |
60 | \r | |
61 | /** Counter = (Counter + Increment) % MaxVal;\r | |
62 | \r | |
63 | @param[in] Counter The value to be incremented.\r | |
64 | @param[in] Increment The value to add to Counter.\r | |
65 | @param[in] MaxVal Modulus of the operation.\r | |
66 | \r | |
67 | @return Returns the result of adding Increment to Counter, modulus MaxVal,\r | |
68 | or -1 if Increment is larger than MaxVal.\r | |
69 | **/\r | |
70 | INT32\r | |
71 | EFIAPI\r | |
72 | ModuloAdd (\r | |
73 | UINT32 Counter,\r | |
74 | UINT32 Increment,\r | |
75 | UINT32 MaxVal\r | |
76 | );\r | |
77 | \r | |
78 | /** Increment Counter but don't increment past MaxVal.\r | |
79 | \r | |
80 | @param[in] Counter The value to be decremented.\r | |
81 | @param[in] MaxVal The upper bound for Counter. Counter < MaxVal.\r | |
82 | \r | |
83 | @return Returns the result of incrementing Counter.\r | |
84 | **/\r | |
85 | UINT32\r | |
86 | EFIAPI\r | |
87 | BoundIncrement(\r | |
88 | UINT32 Counter,\r | |
89 | UINT32 MaxVal\r | |
90 | );\r | |
91 | \r | |
92 | /** Decrement Counter but don't decrement past zero.\r | |
93 | \r | |
94 | @param[in] Counter The value to be decremented.\r | |
95 | \r | |
96 | @return Returns the result of decrementing Counter.\r | |
97 | **/\r | |
98 | UINT32\r | |
99 | EFIAPI\r | |
100 | BoundDecrement(\r | |
101 | UINT32 Counter\r | |
102 | );\r | |
103 | \r | |
104 | __END_DECLS\r | |
105 | #endif /* _MODULO_UTIL_H */\r |