Lines Matching +full:high +full:- +full:to +full:- +full:low

1 //===-- lib/builtins/ppc/fixunstfti.c - Convert long double->int128 *-C -*-===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements converting the 128bit IBM/PowerPC long double (double-
10 // double) data type to an unsigned 128 bit integer.
12 //===----------------------------------------------------------------------===//
17 // Convert long double into an unsigned 128-bit integer.
20 // If we are trying to convert a NaN, return the NaN bit pattern. in __fixunstfti()
28 // The long double representation, with the high and low portions of in __fixunstfti()
32 double d[2]; // [0] is the high double, [1] is the low double. in __fixunstfti()
33 unsigned long long ull[2]; // High and low doubles as 64-bit integers. in __fixunstfti()
41 // Retrieve the 64-bit patterns of high and low doubles. in __fixunstfti()
42 // Compute the unbiased exponent of both high and low doubles by in __fixunstfti()
46 hiExponent = ((ldUnion.ull[0] & 0x7FFFFFFFFFFFFFFFll) >> 52) - BIAS; in __fixunstfti()
47 loExponent = ((ldUnion.ull[1] & 0x7FFFFFFFFFFFFFFFll) >> 52) - BIAS; in __fixunstfti()
49 // Convert each double into int64; they will be added to the int128 result. in __fixunstfti()
50 // CASE 1: High or low double fits in int64 in __fixunstfti()
51 // - Convert the each double normally into int64. in __fixunstfti()
53 // CASE 2: High or low double does not fit in int64 in __fixunstfti()
54 // - Scale the double to fit within a 64-bit integer in __fixunstfti()
55 // - Calculate the shift (amount to scale the double by in the int128) in __fixunstfti()
56 // - Clear all the bits of the exponent (with 0x800FFFFFFFFFFFFF) in __fixunstfti()
57 // - Add BIAS+53 (0x4350000000000000) to exponent to correct the value in __fixunstfti()
58 // - Scale (move) the double to the correct place in the int128 in __fixunstfti()
61 // Note: If the high double is assumed to be positive, an unsigned conversion in __fixunstfti()
62 // from long double to 64-bit integer is needed. The low double can be either in __fixunstfti()
63 // positive or negative, so a signed conversion is needed to retain the result in __fixunstfti()
64 // of the low double and to ensure it does not simply get converted to 0. in __fixunstfti()
66 // CASE 1 - High double fits in int64. in __fixunstfti()
70 // CASE 2 - High double does not fit in int64, scale and convert it. in __fixunstfti()
71 shift = hiExponent - 54; in __fixunstfti()
77 // Detect cases for overflow. When the exponent of the high in __fixunstfti()
79 // input is positive, return the max 128-bit integer. in __fixunstfti()
90 // CASE 1 - Low double fits in int64. in __fixunstfti()
94 // CASE 2 - Low double does not fit in int64, scale and convert it. in __fixunstfti()
95 shift = loExponent - 54; in __fixunstfti()
102 // If the low double is negative, it may change the integer value of the in __fixunstfti()
104 // the fractional part of the high double. Because both doubles cannot in __fixunstfti()
105 // overlap, this situation only occurs when the high double has no in __fixunstfti()
110 loResult--; in __fixunstfti()
112 // Add the high and low doublewords together to form a 128 bit integer. in __fixunstfti()