1/** 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16// Gcc lib-helpers: 17#ifdef __arm__ 18// defined in libgcc_s.so 19extern "C" uint64_t __aeabi_uldivmod(uint64_t numerator, uint64_t denominator); // NOLINT(misc-definitions-in-headers) 20extern "C" int64_t __aeabi_ldivmod(int64_t numerator, int64_t denominator); // NOLINT(misc-definitions-in-headers) 21 22extern "C" uint32_t __aeabi_uidivmod(uint32_t numerator, uint32_t denominator); // NOLINT(misc-definitions-in-headers) 23extern "C" int32_t __aeabi_idivmod(int32_t numerator, int32_t denominator); // NOLINT(misc-definitions-in-headers) 24 25extern "C" float __aeabi_l2f(int64_t data); // NOLINT(misc-definitions-in-headers) 26extern "C" float __aeabi_ul2f(uint64_t data); // NOLINT(misc-definitions-in-headers) 27extern "C" double __aeabi_l2d(int64_t data); // NOLINT(misc-definitions-in-headers) 28extern "C" double __aeabi_ul2d(uint64_t data); // NOLINT(misc-definitions-in-headers) 29 30extern "C" int64_t __aeabi_f2lz(float data); // NOLINT(misc-definitions-in-headers) 31extern "C" uint64_t __aeabi_f2ulz(float data); // NOLINT(misc-definitions-in-headers) 32extern "C" int64_t __aeabi_d2lz(double data); // NOLINT(misc-definitions-in-headers) 33extern "C" uint64_t __aeabi_d2ulz(double data); // NOLINT(misc-definitions-in-headers) 34#else 35struct DivLUResult { 36 uint64_t quotient; 37 uint64_t remainder; 38}; 39 40struct DivLSResult { 41 int64_t quotient; 42 int64_t remainder; 43}; 44 45// NOLINTNEXTLINE(readability-identifier-naming,misc-definitions-in-headers) 46DivLUResult __aeabi_uldivmod(uint64_t numerator, uint64_t denominator) 47{ 48 DivLUResult res {0, 0}; 49 res.quotient = numerator / denominator; 50 res.remainder = numerator % denominator; 51 return res; 52} 53// NOLINTNEXTLINE(readability-identifier-naming,misc-definitions-in-headers) 54DivLSResult __aeabi_ldivmod(int64_t numerator, int64_t denominator) 55{ 56 DivLSResult res {0, 0}; 57 res.quotient = numerator / denominator; 58 res.remainder = numerator % denominator; 59 return res; 60} 61 62struct DivUResult { 63 uint32_t quotient; 64 uint32_t remainder; 65}; 66 67struct DivSResult { 68 int32_t quotient; 69 int32_t remainder; 70}; 71 72// NOLINTNEXTLINE(readability-identifier-naming,misc-definitions-in-headers) 73DivUResult __aeabi_uidivmod(uint32_t numerator, uint32_t denominator) 74{ 75 DivUResult res {0, 0}; 76 res.quotient = numerator / denominator; 77 res.remainder = numerator % denominator; 78 return res; 79} 80// NOLINTNEXTLINE(readability-identifier-naming,misc-definitions-in-headers) 81DivSResult __aeabi_idivmod(int32_t numerator, int32_t denominator) 82{ 83 DivSResult res {0, 0}; 84 res.quotient = numerator / denominator; 85 res.remainder = numerator % denominator; 86 return res; 87} 88 89// NOLINTNEXTLINE(readability-identifier-naming,misc-definitions-in-headers) 90float __aeabi_l2f(int64_t data) 91{ 92 return static_cast<float>(data); 93} 94 95// NOLINTNEXTLINE(readability-identifier-naming,misc-definitions-in-headers) 96float __aeabi_ul2f(uint64_t data) 97{ 98 return static_cast<float>(data); 99} 100 101// NOLINTNEXTLINE(readability-identifier-naming,misc-definitions-in-headers) 102double __aeabi_l2d(int64_t data) 103{ 104 return static_cast<double>(data); 105} 106 107// NOLINTNEXTLINE(readability-identifier-naming,misc-definitions-in-headers) 108double __aeabi_ul2d(uint64_t data) 109{ 110 return static_cast<double>(data); 111} 112 113// NOLINTNEXTLINE(readability-identifier-naming,misc-definitions-in-headers) 114int64_t __aeabi_f2lz(float data) 115{ 116 return static_cast<int64_t>(data); 117} 118 119// NOLINTNEXTLINE(readability-identifier-naming,misc-definitions-in-headers) 120uint64_t __aeabi_f2ulz(float data) 121{ 122 return static_cast<uint64_t>(data); 123} 124 125// NOLINTNEXTLINE(readability-identifier-naming,misc-definitions-in-headers) 126int64_t __aeabi_d2lz(double data) 127{ 128 return static_cast<int64_t>(data); 129} 130 131// NOLINTNEXTLINE(readability-identifier-naming,misc-definitions-in-headers) 132uint64_t __aeabi_d2ulz(double data) 133{ 134 return static_cast<uint64_t>(data); 135} 136#endif 137 138// defined in libm.so, fmodf function from math.h 139extern "C" float fmodf(float a, float b); // NOLINT(misc-definitions-in-headers,readability-identifier-naming) 140// defined in libm.so, fmod function from math.h 141extern "C" double fmod(double a, double b); // NOLINT(misc-definitions-in-headers,readability-identifier-naming) 142