Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / devices / common / regdef / include / Math.h
CommitLineData
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
32static inline bool ispow2 (int64 v)
33{
34 return (v <= 0) ? false : ((v & (v-1)) == 0);
35}
36
37static inline int64 log2 (int64 v)
38{
39 int64 i=0;
40 while (v > 1) { v >>= 1; i++; }
41 return i;
42}
43
44static inline int64 pow2 (int64 v)
45{
46 return 1 << v;
47}
48
49
50static inline int min (int a, int b)
51{
52 return (a < b) ? a : b;
53}
54
55static inline int max (int a, int b)
56{
57 return (a > b) ? a : b;
58}
59
60static inline unsigned min (unsigned a, unsigned b)
61{
62 return (a < b) ? a : b;
63}
64
65static inline unsigned max (unsigned a, unsigned b)
66{
67 return (a > b) ? a : b;
68}
69
70static inline long min (long a, long b)
71{
72 return (a < b) ? a : b;
73}
74
75static inline long max (long a, long b)
76{
77 return (a > b) ? a : b;
78}
79
80static inline unsigned long min (unsigned long a, unsigned long b)
81{
82 return (a < b) ? a : b;
83}
84
85static inline unsigned long max (unsigned long a, unsigned long b)
86{
87 return (a > b) ? a : b;
88}
89
90static inline long long min (long long a, long long b)
91{
92 return (a < b) ? a : b;
93}
94
95static inline long long max (long long a, long long b)
96{
97 return (a > b) ? a : b;
98}
99
100static inline unsigned long long min (unsigned long long a,
101 unsigned long long b)
102{
103 return (a < b) ? a : b;
104}
105
106static inline unsigned long long max (unsigned long long a,
107 unsigned long long b)
108{
109 return (a > b) ? a : b;
110}
111
112static inline float min (float a, float b)
113{
114 return (a < b) ? a : b;
115}
116
117static inline float max (float a, float b)
118{
119 return (a > b) ? a : b;
120}
121
122static inline double min (double a, double b)
123{
124 return (a < b) ? a : b;
125}
126
127static inline double max (double a, double b)
128{
129 return (a > b) ? a : b;
130}
131
132#endif