1219820Sjeff/*
2219820Sjeff * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
3219820Sjeff * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4219820Sjeff * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5219820Sjeff *
6219820Sjeff * This software is available to you under a choice of one of two
7219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
8219820Sjeff * General Public License (GPL) Version 2, available from the file
9219820Sjeff * COPYING in the main directory of this source tree, or the
10219820Sjeff * OpenIB.org BSD license below:
11219820Sjeff *
12219820Sjeff *     Redistribution and use in source and binary forms, with or
13219820Sjeff *     without modification, are permitted provided that the following
14219820Sjeff *     conditions are met:
15219820Sjeff *
16219820Sjeff *      - Redistributions of source code must retain the above
17219820Sjeff *        copyright notice, this list of conditions and the following
18219820Sjeff *        disclaimer.
19219820Sjeff *
20219820Sjeff *      - Redistributions in binary form must reproduce the above
21219820Sjeff *        copyright notice, this list of conditions and the following
22219820Sjeff *        disclaimer in the documentation and/or other materials
23219820Sjeff *        provided with the distribution.
24219820Sjeff *
25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32219820Sjeff * SOFTWARE.
33219820Sjeff *
34219820Sjeff */
35219820Sjeff
36219820Sjeff/*
37219820Sjeff * Abstract:
38219820Sjeff *	Defines standard math related macros and functions.
39219820Sjeff */
40219820Sjeff
41219820Sjeff#ifndef _CL_MATH_H_
42219820Sjeff#define _CL_MATH_H_
43219820Sjeff
44219820Sjeff#include <complib/cl_types.h>
45219820Sjeff
46219820Sjeff#ifdef __cplusplus
47219820Sjeff#  define BEGIN_C_DECLS extern "C" {
48219820Sjeff#  define END_C_DECLS   }
49219820Sjeff#else				/* !__cplusplus */
50219820Sjeff#  define BEGIN_C_DECLS
51219820Sjeff#  define END_C_DECLS
52219820Sjeff#endif				/* __cplusplus */
53219820Sjeff
54219820SjeffBEGIN_C_DECLS
55219820Sjeff/****d* Component Library: Math/MAX
56219820Sjeff* NAME
57219820Sjeff*	MAX
58219820Sjeff*
59219820Sjeff* DESCRIPTION
60219820Sjeff*	The MAX macro returns the greater of two values.
61219820Sjeff*
62219820Sjeff* SYNOPSIS
63219820Sjeff*	MAX( x, y );
64219820Sjeff*
65219820Sjeff* PARAMETERS
66219820Sjeff*	x
67219820Sjeff*		[in] First of two values to compare.
68219820Sjeff*
69219820Sjeff*	y
70219820Sjeff*		[in] Second of two values to compare.
71219820Sjeff*
72219820Sjeff* RETURN VALUE
73219820Sjeff*	Returns the greater of the x and y parameters.
74219820Sjeff*
75219820Sjeff* SEE ALSO
76219820Sjeff*	MIN, ROUNDUP
77219820Sjeff*********/
78219820Sjeff#ifndef MAX
79219820Sjeff#define MAX(x,y)	((x) > (y) ? (x) : (y))
80219820Sjeff#endif
81219820Sjeff/****d* Component Library: Math/MIN
82219820Sjeff* NAME
83219820Sjeff*	MIN
84219820Sjeff*
85219820Sjeff* DESCRIPTION
86219820Sjeff*	The MIN macro returns the greater of two values.
87219820Sjeff*
88219820Sjeff* SYNOPSIS
89219820Sjeff*	MIN( x, y );
90219820Sjeff*
91219820Sjeff* PARAMETERS
92219820Sjeff*	x
93219820Sjeff*		[in] First of two values to compare.
94219820Sjeff*
95219820Sjeff*	y
96219820Sjeff*		[in] Second of two values to compare.
97219820Sjeff*
98219820Sjeff* RETURN VALUE
99219820Sjeff*	Returns the lesser of the x and y parameters.
100219820Sjeff*
101219820Sjeff* SEE ALSO
102219820Sjeff*	MAX, ROUNDUP
103219820Sjeff*********/
104219820Sjeff#ifndef MIN
105219820Sjeff#define MIN(x,y)	((x) < (y) ? (x) : (y))
106219820Sjeff#endif
107219820Sjeff/****d* Component Library: Math/ROUNDUP
108219820Sjeff* NAME
109219820Sjeff*	ROUNDUP
110219820Sjeff*
111219820Sjeff* DESCRIPTION
112219820Sjeff*	The ROUNDUP macro rounds a value up to a given multiple.
113219820Sjeff*
114219820Sjeff* SYNOPSIS
115219820Sjeff*	ROUNDUP( val, align );
116219820Sjeff*
117219820Sjeff* PARAMETERS
118219820Sjeff*	val
119219820Sjeff*		[in] Value that is to be rounded up. The type of the value is
120219820Sjeff*		indeterminate, but must be at most the size of a natural integer
121219820Sjeff*		for the platform.
122219820Sjeff*
123219820Sjeff*	align
124219820Sjeff*		[in] Multiple to which the val parameter must be rounded up.
125219820Sjeff*
126219820Sjeff* RETURN VALUE
127219820Sjeff*	Returns a value that is the input value specified by val rounded up to
128219820Sjeff*	the nearest multiple of align.
129219820Sjeff*
130219820Sjeff* NOTES
131219820Sjeff*	The value provided must be of a type at most the size of a natural integer.
132219820Sjeff*********/
133219820Sjeff#ifndef ROUNDUP
134219820Sjeff#define ROUNDUP(val, align)	\
135219820Sjeff	((((val) / (align))*(align)) + (((val) % (align)) ? (align) : 0))
136219820Sjeff#endif
137219820SjeffEND_C_DECLS
138219820Sjeff#endif				/* _CL_MATH_H_ */
139