10b57cec5SDimitry Andric //===-- fixunsxfdi.c - Implement __fixunsxfdi -----------------------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file implements __fixunsxfdi for the compiler_rt library. 100b57cec5SDimitry Andric // 110b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric #if !_ARCH_PPC 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric #include "int_lib.h" 160b57cec5SDimitry Andric 170b57cec5SDimitry Andric // Returns: convert a to a unsigned long long, rounding toward zero. 180b57cec5SDimitry Andric // Negative values all become zero. 190b57cec5SDimitry Andric 200b57cec5SDimitry Andric // Assumption: long double is an intel 80 bit floating point type padded with 6 210b57cec5SDimitry Andric // bytes du_int is a 64 bit integral type value in long double is representable 220b57cec5SDimitry Andric // in du_int or is negative (no range checking performed) 230b57cec5SDimitry Andric 240b57cec5SDimitry Andric // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee 250b57cec5SDimitry Andric // eeee | 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm 260b57cec5SDimitry Andric // mmmm mmmm mmmm 270b57cec5SDimitry Andric 2868d75effSDimitry Andric #if defined(_MSC_VER) && !defined(__clang__) 29349cc55cSDimitry Andric // MSVC throws a warning about 'uninitialized variable use' here, 3068d75effSDimitry Andric // disable it for builds that warn-as-error 3168d75effSDimitry Andric #pragma warning(push) 3268d75effSDimitry Andric #pragma warning(disable : 4700) 3368d75effSDimitry Andric #endif 3468d75effSDimitry Andric 35*5f757f3fSDimitry Andric COMPILER_RT_ABI du_int __fixunsxfdi(xf_float a) { 36*5f757f3fSDimitry Andric xf_bits fb; 370b57cec5SDimitry Andric fb.f = a; 380b57cec5SDimitry Andric int e = (fb.u.high.s.low & 0x00007FFF) - 16383; 390b57cec5SDimitry Andric if (e < 0 || (fb.u.high.s.low & 0x00008000)) 400b57cec5SDimitry Andric return 0; 410b57cec5SDimitry Andric if ((unsigned)e > sizeof(du_int) * CHAR_BIT) 420b57cec5SDimitry Andric return ~(du_int)0; 430b57cec5SDimitry Andric return fb.u.low.all >> (63 - e); 440b57cec5SDimitry Andric } 450b57cec5SDimitry Andric 4668d75effSDimitry Andric #if defined(_MSC_VER) && !defined(__clang__) 4768d75effSDimitry Andric #pragma warning(pop) 480b57cec5SDimitry Andric #endif 4968d75effSDimitry Andric 5068d75effSDimitry Andric #endif //!_ARCH_PPC 51