xref: /titanic_44/usr/src/uts/common/io/bnxe/577xx/drivers/common/include/cyclic_oper.h (revision d14abf155341d55053c76eeec58b787a456b753b)
1 /*******************************************************************************
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  *
21  * Copyright 2014 QLogic Corporation
22  * The contents of this file are subject to the terms of the
23  * QLogic End User License (the "License").
24  * You may not use this file except in compliance with the License.
25  *
26  * You can obtain a copy of the License at
27  * http://www.qlogic.com/Resources/Documents/DriverDownloadHelp/
28  * QLogic_End_User_Software_License.txt
29  * See the License for the specific language governing permissions
30  * and limitations under the License.
31  *
32  *
33  * Module Description:
34  *  This file should include pure ANSI C defines
35  *
36  * History:
37  *    25/04/10 Shay Haroush        Inception.
38  ******************************************************************************/
39 #ifndef CYCLIC_OPERATIONS
40 #define CYCLIC_OPERATIONS
41 
42 /********	Cyclic Operators Macros	********/
43 
44 #define _ABS_DIFF(x, y) ((x) > (y) ? (x) - (y) : (y) - (x))
45 
_cyclic_lt(u32_t x,u32_t y,u32_t d)46 static __inline u8_t _cyclic_lt(u32_t x, u32_t y, u32_t d)
47 {
48 	u32_t diff = _ABS_DIFF(x,y);
49 	return (diff < d) ? x < y : x > y;
50 }
51 
_cyclic_le(u32_t x,u32_t y,u32_t d)52 static __inline u8_t _cyclic_le(u32_t x, u32_t y, u32_t d)
53 {
54 	u32_t diff = _ABS_DIFF(x,y);
55 	return (diff < d) ? x <= y : x >= y;
56 }
57 
58 #define CYCLIC_LT_8(x, y)  (_cyclic_lt(x, y, 128))
59 #define CYCLIC_LT_16(x, y) (_cyclic_lt(x, y, 32768))
60 #define CYCLIC_LT_24(x, y) (_cyclic_lt(x, y, 8388608))
61 #define CYCLIC_LT_32(x, y) (_cyclic_lt(x, y, 2147483648))
62 
63 #define CYCLIC_LE_8(x, y)  (_cyclic_le(x, y, 128))
64 #define CYCLIC_LE_16(x, y) (_cyclic_le(x, y, 32768))
65 #define CYCLIC_LE_24(x, y) (_cyclic_le(x, y, 8388608))
66 #define CYCLIC_LE_32(x, y) (_cyclic_le(x, y, 2147483648))
67 
68 #define CYCLIC_GT_8(x, y)  (!(CYCLIC_LE_8(x, y)))
69 #define CYCLIC_GT_16(x, y) (!(CYCLIC_LE_16(x, y)))
70 #define CYCLIC_GT_24(x, y) (!(CYCLIC_LE_24(x, y)))
71 #define CYCLIC_GT_32(x, y) (!(CYCLIC_LE_32(x, y)))
72 
73 #define CYCLIC_GE_8(x, y)  (!(CYCLIC_LT_8(x, y)))
74 #define CYCLIC_GE_16(x, y) (!(CYCLIC_LT_16(x, y)))
75 #define CYCLIC_GE_24(x, y) (!(CYCLIC_LT_24(x, y)))
76 #define CYCLIC_GE_32(x, y) (!(CYCLIC_LT_32(x, y)))
77 
78 // bits = number of bits in x, y (i.e., sizeof_x)
79 #define CYCLIC_LT_BITS(x, y, bits)	_cyclic_lt(x, y, 1 << ((bits)-1))
80 #define CYCLIC_LE_BITS(x, y, bits)	_cyclic_le(x, y, 1 << ((bits)-1))
81 #define CYCLIC_GT_BITS(x, y, bits)	(!(CYCLIC_LE_BITS(x, y, bits)))
82 #define CYCLIC_GE_BITS(x, y, bits)	(!(CYCLIC_LT_BITS(x, y, bits)))
83 
84 /********	End	Cyclic Operators Macros	********/
85 
86 #endif // CYCLIC_OPERATIONS
87