1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/device/xps/SkConstexprMath.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,54 @@ 1.4 +/* 1.5 + * Copyright 2011 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef SkConstexprMath_DEFINED 1.12 +#define SkConstexprMath_DEFINED 1.13 + 1.14 +#include "SkTypes.h" 1.15 +#include <limits.h> 1.16 + 1.17 +template <uintmax_t N, uintmax_t B> 1.18 +struct SK_LOG { 1.19 + //! Compile-time constant ceiling(logB(N)). 1.20 + static const uintmax_t value = 1 + SK_LOG<N/B, B>::value; 1.21 +}; 1.22 +template <uintmax_t B> 1.23 +struct SK_LOG<1, B> { 1.24 + static const uintmax_t value = 0; 1.25 +}; 1.26 +template <uintmax_t B> 1.27 +struct SK_LOG<0, B> { 1.28 + static const uintmax_t value = 0; 1.29 +}; 1.30 + 1.31 +template<uintmax_t N> 1.32 +struct SK_2N1 { 1.33 + //! Compile-time constant (2^N)-1. 1.34 + static const uintmax_t value = (SK_2N1<N-1>::value << 1) + 1; 1.35 +}; 1.36 +template<> 1.37 +struct SK_2N1<1> { 1.38 + static const uintmax_t value = 1; 1.39 +}; 1.40 + 1.41 +/** Compile-time constant number of base n digits in type t 1.42 + if the bits of type t are considered as unsigned base two. 1.43 +*/ 1.44 +#define SK_BASE_N_DIGITS_IN(n, t) (\ 1.45 + SK_LOG<SK_2N1<(sizeof(t) * CHAR_BIT)>::value, n>::value\ 1.46 +) 1.47 +/** Compile-time constant number of base 10 digits in type t 1.48 + if the bits of type t are considered as unsigned base two. 1.49 +*/ 1.50 +#define SK_DIGITS_IN(t) SK_BASE_N_DIGITS_IN(10, (t)) 1.51 + 1.52 +// Compile-time constant maximum value of two unsigned values. 1.53 +template <uintmax_t a, uintmax_t b> struct SkTUMax { 1.54 + static const uintmax_t value = (b < a) ? a : b; 1.55 +}; 1.56 + 1.57 +#endif