2
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3
// Use of this source code is governed by a BSD-style license that can be
4
// found in the LICENSE file.
7
// mathutil.h: Math and bit manipulation functions.
9
#ifndef LIBGLESV2_MATHUTIL_H_
10
#define LIBGLESV2_MATHUTIL_H_
18
inline bool isPow2(int x)
20
return (x & (x - 1)) == 0 && (x != 0);
23
inline int log2(int x)
26
while ((x >> r) > 1) r++;
30
inline unsigned int ceilPow2(unsigned int x)
43
template<typename T, typename MIN, typename MAX>
44
inline T clamp(T x, MIN min, MAX max)
46
return x < min ? min : (x > max ? max : x);
49
inline float clamp01(float x)
51
return clamp(x, 0.0f, 1.0f);
55
inline unsigned int unorm(float x)
57
const unsigned int max = 0xFFFFFFFF >> (32 - n);
69
return (unsigned int)(max * x + 0.5f);
73
inline bool supportsSSE2()
75
static bool checked = false;
76
static bool supports = false;
90
supports = (info[3] >> 26) & 1;
99
#endif // LIBGLESV2_MATHUTIL_H_