xref: /freebsd/contrib/ofed/opensm/include/complib/cl_math.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1 /*
2  * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
3  * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5  *
6  * This software is available to you under a choice of one of two
7  * licenses.  You may choose to be licensed under the terms of the GNU
8  * General Public License (GPL) Version 2, available from the file
9  * COPYING in the main directory of this source tree, or the
10  * OpenIB.org BSD license below:
11  *
12  *     Redistribution and use in source and binary forms, with or
13  *     without modification, are permitted provided that the following
14  *     conditions are met:
15  *
16  *      - Redistributions of source code must retain the above
17  *        copyright notice, this list of conditions and the following
18  *        disclaimer.
19  *
20  *      - Redistributions in binary form must reproduce the above
21  *        copyright notice, this list of conditions and the following
22  *        disclaimer in the documentation and/or other materials
23  *        provided with the distribution.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32  * SOFTWARE.
33  *
34  */
35 
36 /*
37  * Abstract:
38  *	Defines standard math related macros and functions.
39  */
40 
41 #ifndef _CL_MATH_H_
42 #define _CL_MATH_H_
43 
44 #include <complib/cl_types.h>
45 
46 #ifdef __cplusplus
47 #  define BEGIN_C_DECLS extern "C" {
48 #  define END_C_DECLS   }
49 #else				/* !__cplusplus */
50 #  define BEGIN_C_DECLS
51 #  define END_C_DECLS
52 #endif				/* __cplusplus */
53 
54 BEGIN_C_DECLS
55 /****d* Component Library: Math/MAX
56 * NAME
57 *	MAX
58 *
59 * DESCRIPTION
60 *	The MAX macro returns the greater of two values.
61 *
62 * SYNOPSIS
63 *	MAX( x, y );
64 *
65 * PARAMETERS
66 *	x
67 *		[in] First of two values to compare.
68 *
69 *	y
70 *		[in] Second of two values to compare.
71 *
72 * RETURN VALUE
73 *	Returns the greater of the x and y parameters.
74 *
75 * SEE ALSO
76 *	MIN, ROUNDUP
77 *********/
78 #ifndef MAX
79 #define MAX(x,y)	((x) > (y) ? (x) : (y))
80 #endif
81 /****d* Component Library: Math/MIN
82 * NAME
83 *	MIN
84 *
85 * DESCRIPTION
86 *	The MIN macro returns the greater of two values.
87 *
88 * SYNOPSIS
89 *	MIN( x, y );
90 *
91 * PARAMETERS
92 *	x
93 *		[in] First of two values to compare.
94 *
95 *	y
96 *		[in] Second of two values to compare.
97 *
98 * RETURN VALUE
99 *	Returns the lesser of the x and y parameters.
100 *
101 * SEE ALSO
102 *	MAX, ROUNDUP
103 *********/
104 #ifndef MIN
105 #define MIN(x,y)	((x) < (y) ? (x) : (y))
106 #endif
107 /****d* Component Library: Math/ROUNDUP
108 * NAME
109 *	ROUNDUP
110 *
111 * DESCRIPTION
112 *	The ROUNDUP macro rounds a value up to a given multiple.
113 *
114 * SYNOPSIS
115 *	ROUNDUP( val, align );
116 *
117 * PARAMETERS
118 *	val
119 *		[in] Value that is to be rounded up. The type of the value is
120 *		indeterminate, but must be at most the size of a natural integer
121 *		for the platform.
122 *
123 *	align
124 *		[in] Multiple to which the val parameter must be rounded up.
125 *
126 * RETURN VALUE
127 *	Returns a value that is the input value specified by val rounded up to
128 *	the nearest multiple of align.
129 *
130 * NOTES
131 *	The value provided must be of a type at most the size of a natural integer.
132 *********/
133 #ifndef ROUNDUP
134 #define ROUNDUP(val, align)	\
135 	((((val) / (align))*(align)) + (((val) % (align)) ? (align) : 0))
136 #endif
137 END_C_DECLS
138 #endif				/* _CL_MATH_H_ */
139