//= lib/fp_trunc_impl.inc - high precision -> low precision conversion *-*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements a fairly generic conversion from a wider to a narrower // IEEE-754 floating-point type in the default (round to nearest, ties to even) // rounding mode. The constants and types defined following the includes below // parameterize the conversion. // // This routine can be trivially adapted to support conversions to // half-precision or from quad-precision. It does not support types that don't // use the usual IEEE-754 interchange formats; specifically, some work would be // needed to adapt it to (for example) the Intel 80-bit format or PowerPC // double-double format. // // Note please, however, that this implementation is only intended to support // *narrowing* operations; if you need to convert to a *wider* floating-point // type (e.g. float -> double), then this routine will not do what you want it // to. // // It also requires that integer types at least as large as both formats // are available on the target platform; this may pose a problem when trying // to add support for quad on some 32-bit systems, for example. // // Finally, the following assumptions are made: // // 1. Floating-point types and integer types have the same endianness on the // target platform. // // 2. Quiet NaNs, if supported, are indicated by the leading bit of the // significand field being set. // //===----------------------------------------------------------------------===// #include "fp_trunc.h" // The destination type may use a usual IEEE-754 interchange format or Intel // 80-bit format. In particular, for the destination type dstSigFracBits may be // not equal to dstSigBits. The source type is assumed to be one of IEEE-754 // standard types. static __inline dst_t __truncXfYf2__(src_t a) { … }