Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / devices / common / regdef / include / Math.h
/*
* ========== Copyright Header Begin ==========================================
*
* OpenSPARC T2 Processor File: Math.h
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
*
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
*
* The above named program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* ========== Copyright Header End ============================================
*/
#ifndef __Math_h
#define __Math_h
#include "Datatype.h"
/** @file Math.h
* Math.h defines common simple math functions.
*/
static inline bool ispow2 (int64 v)
{
return (v <= 0) ? false : ((v & (v-1)) == 0);
}
static inline int64 log2 (int64 v)
{
int64 i=0;
while (v > 1) { v >>= 1; i++; }
return i;
}
static inline int64 pow2 (int64 v)
{
return 1 << v;
}
static inline int min (int a, int b)
{
return (a < b) ? a : b;
}
static inline int max (int a, int b)
{
return (a > b) ? a : b;
}
static inline unsigned min (unsigned a, unsigned b)
{
return (a < b) ? a : b;
}
static inline unsigned max (unsigned a, unsigned b)
{
return (a > b) ? a : b;
}
static inline long min (long a, long b)
{
return (a < b) ? a : b;
}
static inline long max (long a, long b)
{
return (a > b) ? a : b;
}
static inline unsigned long min (unsigned long a, unsigned long b)
{
return (a < b) ? a : b;
}
static inline unsigned long max (unsigned long a, unsigned long b)
{
return (a > b) ? a : b;
}
static inline long long min (long long a, long long b)
{
return (a < b) ? a : b;
}
static inline long long max (long long a, long long b)
{
return (a > b) ? a : b;
}
static inline unsigned long long min (unsigned long long a,
unsigned long long b)
{
return (a < b) ? a : b;
}
static inline unsigned long long max (unsigned long long a,
unsigned long long b)
{
return (a > b) ? a : b;
}
static inline float min (float a, float b)
{
return (a < b) ? a : b;
}
static inline float max (float a, float b)
{
return (a > b) ? a : b;
}
static inline double min (double a, double b)
{
return (a < b) ? a : b;
}
static inline double max (double a, double b)
{
return (a > b) ? a : b;
}
#endif