// SPDX-License-Identifier: Apache-2.0 // ---------------------------------------------------------------------------- // Copyright 2011-2021 Arm Limited // // Licensed under the Apache License, Version 2.0 (the "License"); you may not // use this file except in compliance with the License. You may obtain a copy // of the License at: // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the // License for the specific language governing permissions and limitations // under the License. // ---------------------------------------------------------------------------- /** * @brief Soft-float library for IEEE-754. */ #if (ASTCENC_F16C == 0) && (ASTCENC_NEON == 0) #include "astcenc_mathlib.h" /* sized soft-float types. These are mapped to the sized integer types of C99, instead of C's floating-point types; this is because the library needs to maintain exact, bit-level control on all operations on these data types. */ sf16; sf32; /****************************************** helper functions and their lookup tables ******************************************/ /* count leading zeros functions. Only used when the input is nonzero. */ #if defined(__GNUC__) && (defined(__i386) || defined(__amd64)) #elif defined(__arm__) && defined(__ARMCC_VERSION) #elif defined(__arm__) && defined(__GNUC__) #else /* table used for the slow default versions. */ static const uint8_t clz_table[256] = { 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; #endif /* 32-bit count-leading-zeros function: use the Assembly instruction whenever possible. */ static uint32_t clz32(uint32_t inp) { … } /* the five rounding modes that IEEE-754r defines */ roundmode; static uint32_t rtne_shift32(uint32_t inp, uint32_t shamt) { … } static uint32_t rtna_shift32(uint32_t inp, uint32_t shamt) { … } static uint32_t rtup_shift32(uint32_t inp, uint32_t shamt) { … } /* convert from FP16 to FP32. */ static sf32 sf16_to_sf32(sf16 inp) { … } /* Conversion routine that converts from FP32 to FP16. It supports denormals and all rounding modes. If a NaN is given as input, it is quietened. */ static sf16 sf32_to_sf16(sf32 inp, roundmode rmode) { … } /* convert from soft-float to native-float */ float sf16_to_float(uint16_t p) { … } /* convert from native-float to soft-float */ uint16_t float_to_sf16(float p) { … } #endif