1285206Sdes
2255581Sdes/*============================================================================
3255581Sdes
4255581SdesThis C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
5255581SdesPackage, Release 3e, by John R. Hauser.
6255581Sdes
7255581SdesCopyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
8255581SdesCalifornia.  All rights reserved.
9255581Sdes
10255581SdesRedistribution and use in source and binary forms, with or without
11255581Sdesmodification, are permitted provided that the following conditions are met:
12255581Sdes
13255581Sdes 1. Redistributions of source code must retain the above copyright notice,
14255581Sdes    this list of conditions, and the following disclaimer.
15255581Sdes
16255581Sdes 2. Redistributions in binary form must reproduce the above copyright notice,
17255581Sdes    this list of conditions, and the following disclaimer in the documentation
18255581Sdes    and/or other materials provided with the distribution.
19255581Sdes
20255581Sdes 3. Neither the name of the University nor the names of its contributors may
21255581Sdes    be used to endorse or promote products derived from this software without
22255581Sdes    specific prior written permission.
23255581Sdes
24255581SdesTHIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
25255581SdesEXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26255581SdesWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
27255581SdesDISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
28255581SdesDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29255581Sdes(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30255581SdesLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31255581SdesON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32255581Sdes(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33255581SdesSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34255581Sdes
35255840Sdes=============================================================================*/
36255581Sdes
37255581Sdes#include <stdbool.h>
38255581Sdes#include <stdint.h>
39255581Sdes#include "platform.h"
40255581Sdes#include "internals.h"
41255581Sdes
42255581SdesextFloat80_t
43255581Sdes softfloat_normRoundPackToExtF80(
44255581Sdes     bool sign,
45255581Sdes     int_fast32_t exp,
46255581Sdes     uint_fast64_t sig,
47255581Sdes     uint_fast64_t sigExtra,
48255581Sdes     uint_fast8_t roundingPrecision
49255581Sdes )
50255581Sdes{
51255581Sdes    int_fast8_t shiftDist;
52255581Sdes    struct uint128 sig128;
53255581Sdes
54255581Sdes    if ( ! sig ) {
55255581Sdes        exp -= 64;
56255581Sdes        sig = sigExtra;
57255581Sdes        sigExtra = 0;
58255581Sdes    }
59255581Sdes    shiftDist = softfloat_countLeadingZeros64( sig );
60255581Sdes    exp -= shiftDist;
61255581Sdes    if ( shiftDist ) {
62255581Sdes        sig128 = softfloat_shortShiftLeft128( sig, sigExtra, shiftDist );
63255581Sdes        sig = sig128.v64;
64255581Sdes        sigExtra = sig128.v0;
65255581Sdes    }
66255581Sdes    return
67255581Sdes        softfloat_roundPackToExtF80(
68255581Sdes            sign, exp, sig, sigExtra, roundingPrecision );
69255581Sdes
70255581Sdes}
71255581Sdes
72255581Sdes