1 // SPDX-License-Identifier: BSD-3-Clause
2 
3 /*============================================================================
4 
5 This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
6 Package, Release 3a, by John R. Hauser.
7 
8 Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
9 All rights reserved.
10 
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
13 
14  1. Redistributions of source code must retain the above copyright notice,
15     this list of conditions, and the following disclaimer.
16 
17  2. Redistributions in binary form must reproduce the above copyright notice,
18     this list of conditions, and the following disclaimer in the documentation
19     and/or other materials provided with the distribution.
20 
21  3. Neither the name of the University nor the names of its contributors may
22     be used to endorse or promote products derived from this software without
23     specific prior written permission.
24 
25 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
26 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
28 DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
29 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 
36 =============================================================================*/
37 
38 #include <stdbool.h>
39 #include <stdint.h>
40 #include "platform.h"
41 #include "internals.h"
42 #include "specialize.h"
43 #include "softfloat.h"
44 
45 /*----------------------------------------------------------------------------
46 | Interpreting `uiA' and `uiB' as the bit patterns of two 32-bit floating-
47 | point values, at least one of which is a NaN, returns the bit pattern of
48 | the combined NaN result.  If either `uiA' or `uiB' has the pattern of a
49 | signaling NaN, the invalid exception is raised.
50 *----------------------------------------------------------------------------*/
51 uint_fast32_t
softfloat_propagateNaNF32UI(uint_fast32_t uiA,uint_fast32_t uiB)52  softfloat_propagateNaNF32UI( uint_fast32_t uiA, uint_fast32_t uiB )
53 {
54     bool isSigNaNA, isSigNaNB;
55     uint_fast32_t uiNonsigA, uiNonsigB, uiMagA, uiMagB;
56 
57     /*------------------------------------------------------------------------
58     *------------------------------------------------------------------------*/
59     isSigNaNA = softfloat_isSigNaNF32UI( uiA );
60     isSigNaNB = softfloat_isSigNaNF32UI( uiB );
61     /*------------------------------------------------------------------------
62     | Make NaNs non-signaling.
63     *------------------------------------------------------------------------*/
64     uiNonsigA = uiA | 0x00400000;
65     uiNonsigB = uiB | 0x00400000;
66     /*------------------------------------------------------------------------
67     *------------------------------------------------------------------------*/
68     if ( isSigNaNA | isSigNaNB ) {
69         softfloat_raiseFlags( softfloat_flag_invalid );
70         if ( isSigNaNA ) {
71             if ( isSigNaNB ) goto returnLargerMag;
72             return isNaNF32UI( uiB ) ? uiNonsigB : uiNonsigA;
73         } else {
74             return isNaNF32UI( uiA ) ? uiNonsigA : uiNonsigB;
75         }
76     }
77  returnLargerMag:
78     uiMagA = uiNonsigA & 0x7FFFFFFF;
79     uiMagB = uiNonsigB & 0x7FFFFFFF;
80     if ( uiMagA < uiMagB ) return uiNonsigB;
81     if ( uiMagB < uiMagA ) return uiNonsigA;
82     return (uiNonsigA < uiNonsigB) ? uiNonsigA : uiNonsigB;
83 
84 }
85 
86