1 /* 2 * Copyright © 2022 Imagination Technologies Ltd. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a copy 5 * of this software and associated documentation files (the "Software"), to deal 6 * in the Software without restriction, including without limitation the rights 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 * copies of the Software, and to permit persons to whom the Software is 9 * furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 * SOFTWARE. 22 */ 23 24 #include "pvr_util.h" 25 26 /* Generated by floor(n/log2(10)). This is a compact representation of a 27 * log10(2**n) estimation. Estimations of log2(n) +1/-0 are very fast on modern 28 * CPUs with clz (or equivalent) instructions, which makes this log2-indexed 29 * lookup both compact and fast. Assuming an input of log2(x) +1/-0; this lut 30 * should produce an output of ceil(log10(x)) +0/-1. 31 */ 32 const uint8_t est_log10_from_log2[64 + 1] = { 33 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 34 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 35 10, 10, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 36 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 18, 19, 37 }; 38 39 /* Generated by 10**n with one exception: we make the first power of ten 0 40 * (instead of 1) to ensure a 0-input produces a single digit (instead of no 41 * digits). 42 */ 43 const uint32_t u32_powers_of_ten[10] = { 44 UINT32_C(0), UINT32_C(10), UINT32_C(100), 45 UINT32_C(1000), UINT32_C(10000), UINT32_C(100000), 46 UINT32_C(1000000), UINT32_C(10000000), UINT32_C(100000000), 47 UINT32_C(1000000000), 48 }; 49 50 /* This is an extension of u32_powers_of_ten to include all possible 64-bit 51 * values. 52 */ 53 const uint64_t u64_powers_of_ten[20] = { 54 UINT64_C(0), 55 UINT64_C(10), 56 UINT64_C(100), 57 UINT64_C(1000), 58 UINT64_C(10000), 59 UINT64_C(100000), 60 UINT64_C(1000000), 61 UINT64_C(10000000), 62 UINT64_C(100000000), 63 UINT64_C(1000000000), 64 UINT64_C(10000000000), 65 UINT64_C(100000000000), 66 UINT64_C(1000000000000), 67 UINT64_C(10000000000000), 68 UINT64_C(100000000000000), 69 UINT64_C(1000000000000000), 70 UINT64_C(10000000000000000), 71 UINT64_C(100000000000000000), 72 UINT64_C(1000000000000000000), 73 UINT64_C(10000000000000000000), 74 }; 75