diff options
author | Allan MacKinnon <allanmac@google.com> | 2018-06-19 13:57:04 -0700 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-06-20 01:19:18 +0000 |
commit | 4359d529121fc1f39f882693d641c0133d138d41 (patch) | |
tree | d2c3239162e68d24d5c2cebc8a4f6659860cc2a0 /src/compute/common/util.c | |
parent | 47c29fa64b3ffc1eec7723d40e9862b2d2a8443f (diff) |
Skia Compute core files
Bug: skia:
Change-Id: I4bba49cf20eff013e581800a3f114c85acd8498c
Reviewed-on: https://skia-review.googlesource.com/135782
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
Diffstat (limited to 'src/compute/common/util.c')
-rw-r--r-- | src/compute/common/util.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/compute/common/util.c b/src/compute/common/util.c new file mode 100644 index 0000000000..69710125a3 --- /dev/null +++ b/src/compute/common/util.c @@ -0,0 +1,86 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + */ + +#include <intrin.h> + +// +// +// + +#include "util.h" + +// +// +// + +bool +is_pow2_u32(uint32_t n) +{ + return (n & (n-1)) == 0; +} + +// +// +// + +uint32_t +pow2_ru_u32(uint32_t n) +{ + n--; + n |= n >> 1; + n |= n >> 2; + n |= n >> 4; + n |= n >> 8; + n |= n >> 16; + n++; + + return n; +} + +// +// +// + +uint32_t +pow2_rd_u32(uint32_t n) +{ + return 1u << msb_idx_u32(n); +} + +// +// ASSUMES NON-ZERO +// + +uint32_t +msb_idx_u32(uint32_t n) +{ + +#ifdef _MSC_VER + + uint32_t index; + + _BitScanReverse(&index,n); + + return index; + +#elif defined(__GNUC__) + +#error "BUSTED msb_index()" + return 31 - __builtin_clz(mask); + +#else + +#error "No msb_index()" + +#endif + +} + +// +// +// |