diff -r 000000000000 -r 6474c204b198 gfx/skia/trunk/include/device/xps/SkConstexprMath.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gfx/skia/trunk/include/device/xps/SkConstexprMath.h Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,54 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkConstexprMath_DEFINED +#define SkConstexprMath_DEFINED + +#include "SkTypes.h" +#include + +template +struct SK_LOG { + //! Compile-time constant ceiling(logB(N)). + static const uintmax_t value = 1 + SK_LOG::value; +}; +template +struct SK_LOG<1, B> { + static const uintmax_t value = 0; +}; +template +struct SK_LOG<0, B> { + static const uintmax_t value = 0; +}; + +template +struct SK_2N1 { + //! Compile-time constant (2^N)-1. + static const uintmax_t value = (SK_2N1::value << 1) + 1; +}; +template<> +struct SK_2N1<1> { + static const uintmax_t value = 1; +}; + +/** Compile-time constant number of base n digits in type t + if the bits of type t are considered as unsigned base two. +*/ +#define SK_BASE_N_DIGITS_IN(n, t) (\ + SK_LOG::value, n>::value\ +) +/** Compile-time constant number of base 10 digits in type t + if the bits of type t are considered as unsigned base two. +*/ +#define SK_DIGITS_IN(t) SK_BASE_N_DIGITS_IN(10, (t)) + +// Compile-time constant maximum value of two unsigned values. +template struct SkTUMax { + static const uintmax_t value = (b < a) ? a : b; +}; + +#endif