1117119Stmm
2117119Stmm/*============================================================================
3117119Stmm
4117119StmmThis C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
5117119StmmPackage, Release 3e, by John R. Hauser.
6200921Smarius
7117119StmmCopyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
8117119StmmCalifornia.  All rights reserved.
9117119Stmm
10117119StmmRedistribution and use in source and binary forms, with or without
11117119Stmmmodification, are permitted provided that the following conditions are met:
12117119Stmm
13117119Stmm 1. Redistributions of source code must retain the above copyright notice,
14117119Stmm    this list of conditions, and the following disclaimer.
15117119Stmm
16117119Stmm 2. Redistributions in binary form must reproduce the above copyright notice,
17117119Stmm    this list of conditions, and the following disclaimer in the documentation
18117119Stmm    and/or other materials provided with the distribution.
19117119Stmm
20117119Stmm 3. Neither the name of the University nor the names of its contributors may
21117119Stmm    be used to endorse or promote products derived from this software without
22117119Stmm    specific prior written permission.
23117119Stmm
24117119StmmTHIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
25117119StmmEXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26117119StmmWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
27117119StmmDISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
28117119StmmDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29117119Stmm(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30117119StmmLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31152684SmariusON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32152684Smarius(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33152684SmariusSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34117119Stmm
35133589Smarius=============================================================================*/
36117119Stmm
37117119Stmm#include <stdint.h>
38117119Stmm#include "platform.h"
39117119Stmm#include "internals.h"
40117119Stmm#include "softfloat.h"
41117119Stmm
42117119Stmm#ifdef SOFTFLOAT_FAST_INT64
43133589Smarius
44133589Smariusvoid i32_to_f128M( int32_t a, float128_t *zPtr )
45117119Stmm{
46117119Stmm
47117119Stmm    *zPtr = i32_to_f128( a );
48178728Smarius
49117119Stmm}
50169793Smarius
51163146Skmacy#else
52117119Stmm
53117119Stmmvoid i32_to_f128M( int32_t a, float128_t *zPtr )
54117119Stmm{
55117119Stmm    uint32_t *zWPtr;
56117119Stmm    uint32_t uiZ96, uiZ64;
57117119Stmm    bool sign;
58117119Stmm    uint32_t absA;
59117119Stmm    int_fast8_t shiftDist;
60117119Stmm    uint64_t normAbsA;
61117119Stmm
62117119Stmm    zWPtr = (uint32_t *) zPtr;
63182020Smarius    uiZ96 = 0;
64182108Smarius    uiZ64 = 0;
65182108Smarius    if ( a ) {
66117119Stmm        sign = (a < 0);
67182020Smarius        absA = sign ? -(uint32_t) a : (uint32_t) a;
68200920Smarius        shiftDist = softfloat_countLeadingZeros32( absA ) + 17;
69200920Smarius        normAbsA = (uint64_t) absA<<shiftDist;
70117119Stmm        uiZ96 = packToF128UI96( sign, 0x402E - shiftDist, normAbsA>>32 );
71200920Smarius        uiZ64 = normAbsA;
72117119Stmm    }
73117119Stmm    zWPtr[indexWord( 4, 3 )] = uiZ96;
74117119Stmm    zWPtr[indexWord( 4, 2 )] = uiZ64;
75117119Stmm    zWPtr[indexWord( 4, 1 )] = 0;
76117119Stmm    zWPtr[indexWord( 4, 0 )] = 0;
77117119Stmm
78117119Stmm}
79117119Stmm
80190113Smarius#endif
81117119Stmm
82117119Stmm