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