Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: Math.h | |
5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
7 | * | |
8 | * The above named program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public | |
10 | * License version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * The above named program is distributed in the hope that it will be | |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public | |
18 | * License along with this work; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | * | |
21 | * ========== Copyright Header End ============================================ | |
22 | */ | |
23 | #ifndef __Math_h | |
24 | #define __Math_h | |
25 | ||
26 | #include "Datatype.h" | |
27 | ||
28 | /** @file Math.h | |
29 | * Math.h defines common simple math functions. | |
30 | */ | |
31 | ||
32 | static inline bool ispow2 (int64 v) | |
33 | { | |
34 | return (v <= 0) ? false : ((v & (v-1)) == 0); | |
35 | } | |
36 | ||
37 | static inline int64 log2 (int64 v) | |
38 | { | |
39 | int64 i=0; | |
40 | while (v > 1) { v >>= 1; i++; } | |
41 | return i; | |
42 | } | |
43 | ||
44 | static inline int64 pow2 (int64 v) | |
45 | { | |
46 | return 1 << v; | |
47 | } | |
48 | ||
49 | ||
50 | static inline int min (int a, int b) | |
51 | { | |
52 | return (a < b) ? a : b; | |
53 | } | |
54 | ||
55 | static inline int max (int a, int b) | |
56 | { | |
57 | return (a > b) ? a : b; | |
58 | } | |
59 | ||
60 | static inline unsigned min (unsigned a, unsigned b) | |
61 | { | |
62 | return (a < b) ? a : b; | |
63 | } | |
64 | ||
65 | static inline unsigned max (unsigned a, unsigned b) | |
66 | { | |
67 | return (a > b) ? a : b; | |
68 | } | |
69 | ||
70 | static inline long min (long a, long b) | |
71 | { | |
72 | return (a < b) ? a : b; | |
73 | } | |
74 | ||
75 | static inline long max (long a, long b) | |
76 | { | |
77 | return (a > b) ? a : b; | |
78 | } | |
79 | ||
80 | static inline unsigned long min (unsigned long a, unsigned long b) | |
81 | { | |
82 | return (a < b) ? a : b; | |
83 | } | |
84 | ||
85 | static inline unsigned long max (unsigned long a, unsigned long b) | |
86 | { | |
87 | return (a > b) ? a : b; | |
88 | } | |
89 | ||
90 | static inline long long min (long long a, long long b) | |
91 | { | |
92 | return (a < b) ? a : b; | |
93 | } | |
94 | ||
95 | static inline long long max (long long a, long long b) | |
96 | { | |
97 | return (a > b) ? a : b; | |
98 | } | |
99 | ||
100 | static inline unsigned long long min (unsigned long long a, | |
101 | unsigned long long b) | |
102 | { | |
103 | return (a < b) ? a : b; | |
104 | } | |
105 | ||
106 | static inline unsigned long long max (unsigned long long a, | |
107 | unsigned long long b) | |
108 | { | |
109 | return (a > b) ? a : b; | |
110 | } | |
111 | ||
112 | static inline float min (float a, float b) | |
113 | { | |
114 | return (a < b) ? a : b; | |
115 | } | |
116 | ||
117 | static inline float max (float a, float b) | |
118 | { | |
119 | return (a > b) ? a : b; | |
120 | } | |
121 | ||
122 | static inline double min (double a, double b) | |
123 | { | |
124 | return (a < b) ? a : b; | |
125 | } | |
126 | ||
127 | static inline double max (double a, double b) | |
128 | { | |
129 | return (a > b) ? a : b; | |
130 | } | |
131 | ||
132 | #endif |