QuadFloat.st
author Claus Gittinger <cg@exept.de>
Thu, 06 Jun 2019 23:31:10 +0200
changeset 4997 55c76587b49c
parent 4994 246159e1784d
child 4998 1ed27f918576
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"{ Package: 'stx:libbasic2' }"
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"{ NameSpace: Smalltalk }"
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
LimitedPrecisionReal variableByteSubclass:#QuadFloat
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
	instanceVariableNames:''
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
	classVariableNames:'QuadFloatZero QuadFloatOne Pi E Epsilon NaN PositiveInfinity
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
		NegativeInfinity Halfpi HalfpiNegative'
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
	poolDictionaries:''
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
	category:'Magnitude-Numbers'
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
!
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
4991
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
    13
!QuadFloat primitiveDefinitions!
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
    14
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
    15
%{
4993
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
    16
#if __POINTER_SIZE__ == 8
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
    17
# define SUPPORT_QUADFLOAT
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
    18
#endif
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
    19
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
    20
#ifdef SUPPORT_QUADFLOAT
4992
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    21
/*----------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    22
| Software floating-point underflow tininess-detection mode.
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    23
*----------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    24
enum {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    25
    softfloat_tininess_beforeRounding = 0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    26
    softfloat_tininess_afterRounding  = 1
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    27
};
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    28
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    29
/*----------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    30
| Software floating-point exception flags.
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    31
*----------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    32
enum {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    33
    softfloat_flag_inexact   =  1,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    34
    softfloat_flag_underflow =  2,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    35
    softfloat_flag_overflow  =  4,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    36
    softfloat_flag_infinite  =  8,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    37
    softfloat_flag_invalid   = 16
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    38
};
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    39
/*----------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    40
| Software floating-point rounding mode.  (Mode "odd" is supported only if
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    41
| SoftFloat is compiled with macro 'SOFTFLOAT_ROUND_ODD' defined.)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    42
*----------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    43
enum {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    44
    softfloat_round_near_even   = 0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    45
    softfloat_round_minMag      = 1,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    46
    softfloat_round_min         = 2,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    47
    softfloat_round_max         = 3,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    48
    softfloat_round_near_maxMag = 4,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    49
    softfloat_round_odd         = 6
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    50
};
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    51
#define init_detectTininess softfloat_tininess_afterRounding
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    52
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    53
#if defined(LITTLEENDIAN) || defined(__LSB_FIRST__)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    54
struct uint128          { uint64_t v0, v64; };
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    55
struct uint64_extra     { uint64_t extra, v; };
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    56
struct uint128_extra    { uint64_t extra; struct uint128 v; };
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    57
#else
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    58
struct uint128          { uint64_t v64, v0; };
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    59
struct uint64_extra     { uint64_t v, extra; };
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    60
struct uint128_extra    { struct uint128 v; uint64_t extra; };
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    61
#endif
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    62
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    63
typedef unsigned char bool;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    64
typedef double float64_t;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    65
union ui64_f64   { uint64_t ui; float64_t f; };
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    66
union ui128_f128 { struct uint128 ui; float128_t f; };
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    67
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    68
/*----------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    69
| The bit pattern for a default generated 128-bit floating-point NaN.
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    70
*----------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    71
#define defaultNaNF128UI96 0xFFFF8000
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    72
#define defaultNaNF128UI64 0
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    73
#define defaultNaNF128UI32 0
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    74
#define defaultNaNF128UI0  0
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    75
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    76
struct commonNaN {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    77
    bool sign;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    78
#ifdef LITTLEENDIAN
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    79
    uint64_t v0, v64;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    80
#else
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    81
    uint64_t v64, v0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    82
#endif
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    83
};
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    84
struct exp16_sig64 { int_fast16_t exp; uint_fast64_t sig; };
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    85
4993
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
    86
#endif // SUPPORT_QUADFLOAT
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
    87
4992
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    88
%}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    89
! !
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    90
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    91
!QuadFloat primitiveVariables!
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    92
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    93
%{
4993
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
    94
#ifdef SUPPORT_QUADFLOAT
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
    95
4992
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    96
uint_fast8_t softfloat_exceptionFlags;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    97
uint_fast8_t softfloat_roundingMode = softfloat_round_near_even;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    98
uint_fast8_t softfloat_detectTininess = init_detectTininess;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
    99
uint_fast8_t softfloat_exceptionFlags = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   100
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   101
const uint_least8_t softfloat_countLeadingZeros8[256] = {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   102
    8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   103
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   104
    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   105
    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   106
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   107
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   108
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   109
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   110
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   111
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   112
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   113
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   114
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   115
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   116
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   117
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   118
};
4993
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
   119
#endif // SUPPORT_QUADFLOAT
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
   120
4991
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   121
%}
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   122
! !
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   123
4992
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   124
!QuadFloat primitiveFunctions!
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   125
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   126
%{
4993
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
   127
#ifdef SUPPORT_QUADFLOAT
4992
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   128
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   129
#if defined(LITTLEENDIAN) || defined(__LSB_FIRST__)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   130
#define wordIncr 1
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   131
#define indexWord( total, n ) (n)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   132
#define indexWordHi( total ) ((total) - 1)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   133
#define indexWordLo( total ) 0
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   134
#define indexMultiword( total, m, n ) (n)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   135
#define indexMultiwordHi( total, n ) ((total) - (n))
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   136
#define indexMultiwordLo( total, n ) 0
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   137
#define indexMultiwordHiBut( total, n ) (n)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   138
#define indexMultiwordLoBut( total, n ) 0
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   139
#define INIT_UINTM4( v3, v2, v1, v0 ) { v0, v1, v2, v3 }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   140
#else
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   141
#define wordIncr -1
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   142
#define indexWord( total, n ) ((total) - 1 - (n))
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   143
#define indexWordHi( total ) 0
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   144
#define indexWordLo( total ) ((total) - 1)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   145
#define indexMultiword( total, m, n ) ((total) - 1 - (m))
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   146
#define indexMultiwordHi( total, n ) 0
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   147
#define indexMultiwordLo( total, n ) ((total) - (n))
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   148
#define indexMultiwordHiBut( total, n ) 0
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   149
#define indexMultiwordLoBut( total, n ) (n)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   150
#define INIT_UINTM4( v3, v2, v1, v0 ) { v3, v2, v1, v0 }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   151
#endif
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   152
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   153
#define signF64UI( a ) ((bool) ((uint64_t) (a)>>63))
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   154
#define expF64UI( a ) ((int_fast16_t) ((a)>>52) & 0x7FF)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   155
#define fracF64UI( a ) ((a) & UINT64_C( 0x000FFFFFFFFFFFFF ))
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   156
#define softfloat_f64UIToCommonNaN( uiA, zPtr ) if ( ! ((uiA) & UINT64_C( 0x0008000000000000 )) ) softfloat_raiseFlags( softfloat_flag_invalid )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   157
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   158
#define signF128UI64( a64 ) ((bool) ((uint64_t) (a64)>>63))
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   159
#define expF128UI64( a64 ) ((int_fast32_t) ((a64)>>48) & 0x7FFF)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   160
#define fracF128UI64( a64 ) ((a64) & UINT64_C( 0x0000FFFFFFFFFFFF ))
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   161
#define packToF128UI64( sign, exp, sig64 ) (((uint_fast64_t) (sign)<<63) + ((uint_fast64_t) (exp)<<48) + (sig64))
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   162
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   163
#define signF128UI96( a96 ) ((bool) ((uint32_t) (a96)>>31))
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   164
#define expF128UI96( a96 ) ((int32_t) ((a96)>>16) & 0x7FFF)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   165
#define fracF128UI96( a96 ) ((a96) & 0x0000FFFF)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   166
#define packToF128UI96( sign, exp, sig96 ) (((uint32_t) (sign)<<31) + ((uint32_t) (exp)<<16) + (sig96))
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   167
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   168
#define isNaNF128UI( a64, a0 ) (((~(a64) & UINT64_C( 0x7FFF000000000000 )) == 0) && (a0 || ((a64) & UINT64_C( 0x0000FFFFFFFFFFFF ))))
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   169
#define softfloat_isSigNaNF128UI( uiA64, uiA0 ) ((((uiA64) & UINT64_C( 0x7FFF800000000000 )) == UINT64_C( 0x7FFF000000000000 )) && ((uiA0) || ((uiA64) & UINT64_C( 0x00007FFFFFFFFFFF ))))
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   170
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   171
#if 0
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   172
static inline
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   173
void
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   174
 softfloat_commonNaNToF128M( const struct commonNaN *aPtr, uint32_t *zWPtr )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   175
{
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   176
    zWPtr[indexWord( 4, 3 )] = defaultNaNF128UI96;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   177
    zWPtr[indexWord( 4, 2 )] = defaultNaNF128UI64;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   178
    zWPtr[indexWord( 4, 1 )] = defaultNaNF128UI32;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   179
    zWPtr[indexWord( 4, 0 )] = defaultNaNF128UI0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   180
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   181
#else
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   182
# define softfloat_commonNaNToF128M( aPtr, zWPtr ) \
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   183
{ \
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   184
    (zWPtr)[indexWord( 4, 3 )] = defaultNaNF128UI96; \
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   185
    (zWPtr)[indexWord( 4, 2 )] = defaultNaNF128UI64; \
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   186
    (zWPtr)[indexWord( 4, 1 )] = defaultNaNF128UI32; \
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   187
    (zWPtr)[indexWord( 4, 0 )] = defaultNaNF128UI0; \
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   188
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   189
#endif
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   190
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   191
void
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   192
softfloat_raiseFlags( uint_fast8_t flags ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   193
    softfloat_exceptionFlags |= flags;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   194
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   195
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   196
bool
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   197
softfloat_eq128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ){
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   198
    return (a64 == b64) && (a0 == b0);
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   199
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   200
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   201
bool
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   202
softfloat_lt128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ){
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   203
    return (a64 < b64) || ((a64 == b64) && (a0 < b0));
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   204
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   205
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   206
uint_fast8_t
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   207
softfloat_countLeadingZeros64( uint64_t a )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   208
{
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   209
    uint_fast8_t count;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   210
    uint32_t a32;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   211
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   212
    count = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   213
    a32 = a>>32;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   214
    if ( ! a32 ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   215
	count = 32;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   216
	a32 = a;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   217
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   218
    /*------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   219
    | From here, result is current count + count leading zeros of `a32'.
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   220
    *------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   221
    if ( a32 < 0x10000 ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   222
	count += 16;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   223
	a32 <<= 16;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   224
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   225
    if ( a32 < 0x1000000 ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   226
	count += 8;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   227
	a32 <<= 8;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   228
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   229
    count += softfloat_countLeadingZeros8[a32>>24];
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   230
    return count;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   231
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   232
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   233
struct exp16_sig64
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   234
softfloat_normSubnormalF64Sig( uint_fast64_t sig )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   235
{
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   236
    int_fast8_t shiftDist;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   237
    struct exp16_sig64 z;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   238
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   239
    shiftDist = softfloat_countLeadingZeros64( sig ) - 11;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   240
    z.exp = 1 - shiftDist;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   241
    z.sig = sig<<shiftDist;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   242
    return z;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   243
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   244
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   245
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   246
struct uint128_extra
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   247
softfloat_shiftRightJam128Extra(
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   248
     uint64_t a64, uint64_t a0, uint64_t extra, uint_fast32_t dist )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   249
{
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   250
    uint_fast8_t u8NegDist;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   251
    struct uint128_extra z;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   252
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   253
    u8NegDist = -dist;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   254
    if ( dist < 64 ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   255
	z.v.v64 = a64>>dist;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   256
	z.v.v0 = a64<<(u8NegDist & 63) | a0>>dist;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   257
	z.extra = a0<<(u8NegDist & 63);
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   258
    } else {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   259
	z.v.v64 = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   260
	if ( dist == 64 ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   261
	    z.v.v0 = a64;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   262
	    z.extra = a0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   263
	} else {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   264
	    extra |= a0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   265
	    if ( dist < 128 ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   266
		z.v.v0 = a64>>(dist & 63);
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   267
		z.extra = a64<<(u8NegDist & 63);
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   268
	    } else {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   269
		z.v.v0 = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   270
		z.extra = (dist == 128) ? a64 : (a64 != 0);
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   271
	    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   272
	}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   273
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   274
    z.extra |= (extra != 0);
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   275
    return z;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   276
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   277
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   278
struct uint128_extra
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   279
softfloat_shortShiftRightJam128Extra(
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   280
     uint64_t a64, uint64_t a0, uint64_t extra, uint_fast8_t dist )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   281
{
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   282
    uint_fast8_t negDist = -dist;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   283
    struct uint128_extra z;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   284
    z.v.v64 = a64>>dist;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   285
    z.v.v0 = a64<<(negDist & 63) | a0>>dist;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   286
    z.extra = a0<<(negDist & 63) | (extra != 0);
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   287
    return z;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   288
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   289
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   290
struct uint128
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   291
 softfloat_shiftRightJam128( uint64_t a64, uint64_t a0, uint_fast32_t dist )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   292
{
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   293
    uint_fast8_t u8NegDist;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   294
    struct uint128 z;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   295
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   296
    if ( dist < 64 ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   297
	u8NegDist = -dist;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   298
	z.v64 = a64>>dist;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   299
	z.v0 =
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   300
	    a64<<(u8NegDist & 63) | a0>>dist
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   301
		| ((uint64_t) (a0<<(u8NegDist & 63)) != 0);
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   302
    } else {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   303
	z.v64 = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   304
	z.v0 =
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   305
	    (dist < 127)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   306
		? a64>>(dist & 63)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   307
		      | (((a64 & (((uint_fast64_t) 1<<(dist & 63)) - 1)) | a0)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   308
			     != 0)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   309
		: ((a64 | a0) != 0);
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   310
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   311
    return z;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   312
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   313
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   314
struct uint128
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   315
softfloat_shortShiftLeft128( uint64_t a64, uint64_t a0, uint_fast8_t dist )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   316
{
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   317
    struct uint128 z;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   318
    z.v64 = a64<<dist | a0>>(-dist & 63);
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   319
    z.v0 = a0<<dist;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   320
    return z;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   321
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   322
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   323
struct uint128
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   324
softfloat_add128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   325
{
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   326
    struct uint128 z;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   327
    z.v0 = a0 + b0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   328
    z.v64 = a64 + b64 + (z.v0 < a0);
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   329
    return z;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   330
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   331
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   332
struct uint128
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   333
 softfloat_sub128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   334
{
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   335
    struct uint128 z;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   336
    z.v0 = a0 - b0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   337
    z.v64 = a64 - b64;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   338
    z.v64 -= (a0 < b0);
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   339
    return z;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   340
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   341
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   342
float128_t
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   343
softfloat_roundPackToF128(
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   344
     bool sign,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   345
     int_fast32_t exp,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   346
     uint_fast64_t sig64,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   347
     uint_fast64_t sig0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   348
     uint_fast64_t sigExtra
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   349
 )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   350
{
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   351
    uint_fast8_t roundingMode;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   352
    bool roundNearEven, doIncrement, isTiny;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   353
    struct uint128_extra sig128Extra;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   354
    uint_fast64_t uiZ64, uiZ0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   355
    struct uint128 sig128;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   356
    union ui128_f128 uZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   357
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   358
    /*------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   359
    *------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   360
    roundingMode = softfloat_roundingMode;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   361
    roundNearEven = (roundingMode == softfloat_round_near_even);
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   362
    doIncrement = (UINT64_C( 0x8000000000000000 ) <= sigExtra);
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   363
    if ( ! roundNearEven && (roundingMode != softfloat_round_near_maxMag) ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   364
	doIncrement =
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   365
	    (roundingMode
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   366
		 == (sign ? softfloat_round_min : softfloat_round_max))
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   367
		&& sigExtra;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   368
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   369
    /*------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   370
    *------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   371
    if ( 0x7FFD <= (uint32_t) exp ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   372
	if ( exp < 0 ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   373
	    /*----------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   374
	    *----------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   375
	    isTiny =
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   376
		   (softfloat_detectTininess
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   377
			== softfloat_tininess_beforeRounding)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   378
		|| (exp < -1)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   379
		|| ! doIncrement
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   380
		|| softfloat_lt128(
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   381
		       sig64,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   382
		       sig0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   383
		       UINT64_C( 0x0001FFFFFFFFFFFF ),
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   384
		       UINT64_C( 0xFFFFFFFFFFFFFFFF )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   385
		   );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   386
	    sig128Extra =
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   387
		softfloat_shiftRightJam128Extra( sig64, sig0, sigExtra, -exp );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   388
	    sig64 = sig128Extra.v.v64;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   389
	    sig0  = sig128Extra.v.v0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   390
	    sigExtra = sig128Extra.extra;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   391
	    exp = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   392
	    if ( isTiny && sigExtra ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   393
		softfloat_raiseFlags( softfloat_flag_underflow );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   394
	    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   395
	    doIncrement = (UINT64_C( 0x8000000000000000 ) <= sigExtra);
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   396
	    if (
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   397
		   ! roundNearEven
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   398
		&& (roundingMode != softfloat_round_near_maxMag)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   399
	    ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   400
		doIncrement =
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   401
		    (roundingMode
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   402
			 == (sign ? softfloat_round_min : softfloat_round_max))
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   403
			&& sigExtra;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   404
	    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   405
	} else if (
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   406
	       (0x7FFD < exp)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   407
	    || ((exp == 0x7FFD)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   408
		    && softfloat_eq128(
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   409
			   sig64,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   410
			   sig0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   411
			   UINT64_C( 0x0001FFFFFFFFFFFF ),
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   412
			   UINT64_C( 0xFFFFFFFFFFFFFFFF )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   413
		       )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   414
		    && doIncrement)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   415
	) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   416
	    /*----------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   417
	    *----------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   418
	    softfloat_raiseFlags(
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   419
		softfloat_flag_overflow | softfloat_flag_inexact );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   420
	    if (
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   421
		   roundNearEven
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   422
		|| (roundingMode == softfloat_round_near_maxMag)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   423
		|| (roundingMode
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   424
			== (sign ? softfloat_round_min : softfloat_round_max))
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   425
	    ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   426
		uiZ64 = packToF128UI64( sign, 0x7FFF, 0 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   427
		uiZ0  = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   428
	    } else {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   429
		uiZ64 =
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   430
		    packToF128UI64(
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   431
			sign, 0x7FFE, UINT64_C( 0x0000FFFFFFFFFFFF ) );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   432
		uiZ0 = UINT64_C( 0xFFFFFFFFFFFFFFFF );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   433
	    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   434
	    goto uiZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   435
	}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   436
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   437
    /*------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   438
    *------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   439
    if ( sigExtra ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   440
	softfloat_exceptionFlags |= softfloat_flag_inexact;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   441
#ifdef SOFTFLOAT_ROUND_ODD
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   442
	if ( roundingMode == softfloat_round_odd ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   443
	    sig0 |= 1;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   444
	    goto packReturn;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   445
	}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   446
#endif
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   447
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   448
    if ( doIncrement ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   449
	sig128 = softfloat_add128( sig64, sig0, 0, 1 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   450
	sig64 = sig128.v64;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   451
	sig0 =
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   452
	    sig128.v0
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   453
		& ~(uint64_t)
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   454
		       (! (sigExtra & UINT64_C( 0x7FFFFFFFFFFFFFFF ))
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   455
			    & roundNearEven);
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   456
    } else {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   457
	if ( ! (sig64 | sig0) ) exp = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   458
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   459
    /*------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   460
    *------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   461
 packReturn:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   462
    uiZ64 = packToF128UI64( sign, exp, sig64 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   463
    uiZ0  = sig0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   464
 uiZ:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   465
    uZ.ui.v64 = uiZ64;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   466
    uZ.ui.v0  = uiZ0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   467
    return uZ.f;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   468
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   469
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   470
float128_t
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   471
 softfloat_normRoundPackToF128(
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   472
     bool sign, int_fast32_t exp, uint_fast64_t sig64, uint_fast64_t sig0 )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   473
{
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   474
    int_fast8_t shiftDist;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   475
    struct uint128 sig128;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   476
    union ui128_f128 uZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   477
    uint_fast64_t sigExtra;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   478
    struct uint128_extra sig128Extra;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   479
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   480
    if ( ! sig64 ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   481
	exp -= 64;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   482
	sig64 = sig0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   483
	sig0 = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   484
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   485
    shiftDist = softfloat_countLeadingZeros64( sig64 ) - 15;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   486
    exp -= shiftDist;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   487
    if ( 0 <= shiftDist ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   488
	if ( shiftDist ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   489
	    sig128 = softfloat_shortShiftLeft128( sig64, sig0, shiftDist );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   490
	    sig64 = sig128.v64;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   491
	    sig0  = sig128.v0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   492
	}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   493
	if ( (uint32_t) exp < 0x7FFD ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   494
	    uZ.ui.v64 = packToF128UI64( sign, sig64 | sig0 ? exp : 0, sig64 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   495
	    uZ.ui.v0  = sig0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   496
	    return uZ.f;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   497
	}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   498
	sigExtra = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   499
    } else {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   500
	sig128Extra =
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   501
	    softfloat_shortShiftRightJam128Extra( sig64, sig0, 0, -shiftDist );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   502
	sig64 = sig128Extra.v.v64;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   503
	sig0  = sig128Extra.v.v0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   504
	sigExtra = sig128Extra.extra;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   505
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   506
    return softfloat_roundPackToF128( sign, exp, sig64, sig0, sigExtra );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   507
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   508
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   509
struct uint128
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   510
softfloat_propagateNaNF128UI(
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   511
     uint_fast64_t uiA64,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   512
     uint_fast64_t uiA0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   513
     uint_fast64_t uiB64,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   514
     uint_fast64_t uiB0
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   515
 )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   516
{
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   517
    bool isSigNaNA, isSigNaNB;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   518
    uint_fast64_t uiNonsigA64, uiNonsigB64, uiMagA64, uiMagB64;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   519
    struct uint128 uiZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   520
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   521
    /*------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   522
    *------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   523
    isSigNaNA = softfloat_isSigNaNF128UI( uiA64, uiA0 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   524
    isSigNaNB = softfloat_isSigNaNF128UI( uiB64, uiB0 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   525
    /*------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   526
    | Make NaNs non-signaling.
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   527
    *------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   528
    uiNonsigA64 = uiA64 | UINT64_C( 0x0000800000000000 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   529
    uiNonsigB64 = uiB64 | UINT64_C( 0x0000800000000000 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   530
    /*------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   531
    *------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   532
    if ( isSigNaNA | isSigNaNB ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   533
	softfloat_raiseFlags( softfloat_flag_invalid );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   534
	if ( isSigNaNA ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   535
	    if ( isSigNaNB ) goto returnLargerMag;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   536
	    if ( isNaNF128UI( uiB64, uiB0 ) ) goto returnB;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   537
	    goto returnA;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   538
	} else {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   539
	    if ( isNaNF128UI( uiA64, uiA0 ) ) goto returnA;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   540
	    goto returnB;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   541
	}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   542
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   543
 returnLargerMag:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   544
    uiMagA64 = uiA64 & UINT64_C( 0x7FFFFFFFFFFFFFFF );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   545
    uiMagB64 = uiB64 & UINT64_C( 0x7FFFFFFFFFFFFFFF );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   546
    if ( uiMagA64 < uiMagB64 ) goto returnB;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   547
    if ( uiMagB64 < uiMagA64 ) goto returnA;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   548
    if ( uiA0 < uiB0 ) goto returnB;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   549
    if ( uiB0 < uiA0 ) goto returnA;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   550
    if ( uiNonsigA64 < uiNonsigB64 ) goto returnA;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   551
 returnB:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   552
    uiZ.v64 = uiNonsigB64;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   553
    uiZ.v0  = uiB0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   554
    return uiZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   555
 returnA:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   556
    uiZ.v64 = uiNonsigA64;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   557
    uiZ.v0  = uiA0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   558
    return uiZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   559
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   560
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   561
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   562
void
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   563
f64_to_f128M( float64_t a, float128_t *zPtr )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   564
{
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   565
    uint32_t *zWPtr;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   566
    union ui64_f64 uA;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   567
    uint64_t uiA;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   568
    bool sign;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   569
    int_fast16_t exp;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   570
    uint64_t frac;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   571
    struct commonNaN commonNaN;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   572
    uint32_t uiZ96;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   573
    struct exp16_sig64 normExpSig;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   574
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   575
    /*------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   576
    *------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   577
    zWPtr = (uint32_t *) zPtr;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   578
    /*------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   579
    *------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   580
    uA.f = a;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   581
    uiA = uA.ui;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   582
    sign = signF64UI( uiA );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   583
    exp  = expF64UI( uiA );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   584
    frac = fracF64UI( uiA );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   585
    /*------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   586
    *------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   587
    zWPtr[indexWord( 4, 0 )] = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   588
    if ( exp == 0x7FF ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   589
	if ( frac ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   590
	    softfloat_f64UIToCommonNaN( uiA, &commonNaN );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   591
	    softfloat_commonNaNToF128M( &commonNaN, zWPtr );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   592
	    return;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   593
	}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   594
	uiZ96 = packToF128UI96( sign, 0x7FFF, 0 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   595
	goto uiZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   596
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   597
    /*------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   598
    *------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   599
    if ( ! exp ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   600
	if ( ! frac ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   601
	    uiZ96 = packToF128UI96( sign, 0, 0 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   602
	    goto uiZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   603
	}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   604
	normExpSig = softfloat_normSubnormalF64Sig( frac );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   605
	exp = normExpSig.exp - 1;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   606
	frac = normExpSig.sig;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   607
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   608
    /*------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   609
    *------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   610
    zWPtr[indexWord( 4, 1 )] = (uint32_t) frac<<28;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   611
    frac >>= 4;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   612
    zWPtr[indexWordHi( 4 )] = packToF128UI96( sign, exp + 0x3C00, frac>>32 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   613
    zWPtr[indexWord( 4, 2 )] = frac;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   614
    return;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   615
    /*------------------------------------------------------------------------
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   616
    *------------------------------------------------------------------------*/
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   617
 uiZ:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   618
    zWPtr[indexWord( 4, 3 )] = uiZ96;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   619
    zWPtr[indexWord( 4, 2 )] = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   620
    zWPtr[indexWord( 4, 1 )] = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   621
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   622
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   623
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   624
static float128_t
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   625
softfloat_addMagsF128(
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   626
     uint64_t uiA64,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   627
     uint64_t uiA0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   628
     uint64_t uiB64,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   629
     uint64_t uiB0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   630
     bool signZ
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   631
 )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   632
{
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   633
    int32_t expA;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   634
    struct uint128 sigA;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   635
    int32_t expB;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   636
    struct uint128 sigB;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   637
    int32_t expDiff;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   638
    struct uint128 uiZ, sigZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   639
    int32_t expZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   640
    uint64_t sigZExtra;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   641
    struct uint128_extra sig128Extra;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   642
    union ui128_f128 uZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   643
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   644
    expA = expF128UI64( uiA64 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   645
    sigA.v64 = fracF128UI64( uiA64 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   646
    sigA.v0  = uiA0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   647
    expB = expF128UI64( uiB64 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   648
    sigB.v64 = fracF128UI64( uiB64 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   649
    sigB.v0  = uiB0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   650
    expDiff = expA - expB;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   651
    if ( ! expDiff ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   652
	if ( expA == 0x7FFF ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   653
	    if ( sigA.v64 | sigA.v0 | sigB.v64 | sigB.v0 ) goto propagateNaN;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   654
	    uiZ.v64 = uiA64;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   655
	    uiZ.v0  = uiA0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   656
	    goto uiZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   657
	}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   658
	sigZ = softfloat_add128( sigA.v64, sigA.v0, sigB.v64, sigB.v0 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   659
	if ( ! expA ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   660
	    uiZ.v64 = packToF128UI64( signZ, 0, sigZ.v64 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   661
	    uiZ.v0  = sigZ.v0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   662
	    goto uiZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   663
	}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   664
	expZ = expA;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   665
	sigZ.v64 |= UINT64_C( 0x0002000000000000 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   666
	sigZExtra = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   667
	goto shiftRight1;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   668
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   669
    if ( expDiff < 0 ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   670
	if ( expB == 0x7FFF ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   671
	    if ( sigB.v64 | sigB.v0 ) goto propagateNaN;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   672
	    uiZ.v64 = packToF128UI64( signZ, 0x7FFF, 0 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   673
	    uiZ.v0  = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   674
	    goto uiZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   675
	}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   676
	expZ = expB;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   677
	if ( expA ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   678
	    sigA.v64 |= UINT64_C( 0x0001000000000000 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   679
	} else {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   680
	    ++expDiff;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   681
	    sigZExtra = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   682
	    if ( ! expDiff ) goto newlyAligned;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   683
	}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   684
	sig128Extra =
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   685
	    softfloat_shiftRightJam128Extra( sigA.v64, sigA.v0, 0, -expDiff );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   686
	sigA = sig128Extra.v;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   687
	sigZExtra = sig128Extra.extra;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   688
    } else {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   689
	if ( expA == 0x7FFF ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   690
	    if ( sigA.v64 | sigA.v0 ) goto propagateNaN;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   691
	    uiZ.v64 = uiA64;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   692
	    uiZ.v0  = uiA0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   693
	    goto uiZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   694
	}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   695
	expZ = expA;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   696
	if ( expB ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   697
	    sigB.v64 |= UINT64_C( 0x0001000000000000 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   698
	} else {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   699
	    --expDiff;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   700
	    sigZExtra = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   701
	    if ( ! expDiff ) goto newlyAligned;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   702
	}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   703
	sig128Extra =
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   704
	    softfloat_shiftRightJam128Extra( sigB.v64, sigB.v0, 0, expDiff );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   705
	sigB = sig128Extra.v;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   706
	sigZExtra = sig128Extra.extra;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   707
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   708
 newlyAligned:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   709
    sigZ =
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   710
	softfloat_add128(
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   711
	    sigA.v64 | UINT64_C( 0x0001000000000000 ),
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   712
	    sigA.v0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   713
	    sigB.v64,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   714
	    sigB.v0
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   715
	);
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   716
    --expZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   717
    if ( sigZ.v64 < UINT64_C( 0x0002000000000000 ) ) goto roundAndPack;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   718
    ++expZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   719
 shiftRight1:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   720
    sig128Extra =
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   721
	softfloat_shortShiftRightJam128Extra(
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   722
	    sigZ.v64, sigZ.v0, sigZExtra, 1 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   723
    sigZ = sig128Extra.v;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   724
    sigZExtra = sig128Extra.extra;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   725
 roundAndPack:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   726
    return
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   727
	softfloat_roundPackToF128( signZ, expZ, sigZ.v64, sigZ.v0, sigZExtra );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   728
 propagateNaN:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   729
    uiZ = softfloat_propagateNaNF128UI( uiA64, uiA0, uiB64, uiB0 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   730
 uiZ:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   731
    uZ.ui = uiZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   732
    return uZ.f;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   733
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   734
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   735
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   736
float128_t
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   737
softfloat_subMagsF128(
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   738
     uint_fast64_t uiA64,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   739
     uint_fast64_t uiA0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   740
     uint_fast64_t uiB64,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   741
     uint_fast64_t uiB0,
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   742
     bool signZ
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   743
 )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   744
{
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   745
    int_fast32_t expA;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   746
    struct uint128 sigA;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   747
    int_fast32_t expB;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   748
    struct uint128 sigB, sigZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   749
    int_fast32_t expDiff, expZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   750
    struct uint128 uiZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   751
    union ui128_f128 uZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   752
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   753
    expA = expF128UI64( uiA64 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   754
    sigA.v64 = fracF128UI64( uiA64 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   755
    sigA.v0  = uiA0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   756
    expB = expF128UI64( uiB64 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   757
    sigB.v64 = fracF128UI64( uiB64 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   758
    sigB.v0  = uiB0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   759
    sigA = softfloat_shortShiftLeft128( sigA.v64, sigA.v0, 4 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   760
    sigB = softfloat_shortShiftLeft128( sigB.v64, sigB.v0, 4 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   761
    expDiff = expA - expB;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   762
    if ( 0 < expDiff ) goto expABigger;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   763
    if ( expDiff < 0 ) goto expBBigger;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   764
    if ( expA == 0x7FFF ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   765
	if ( sigA.v64 | sigA.v0 | sigB.v64 | sigB.v0 ) goto propagateNaN;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   766
	softfloat_raiseFlags( softfloat_flag_invalid );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   767
	uiZ.v64 = defaultNaNF128UI64;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   768
	uiZ.v0  = defaultNaNF128UI0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   769
	goto uiZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   770
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   771
    expZ = expA;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   772
    if ( ! expZ ) expZ = 1;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   773
    if ( sigB.v64 < sigA.v64 ) goto aBigger;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   774
    if ( sigA.v64 < sigB.v64 ) goto bBigger;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   775
    if ( sigB.v0 < sigA.v0 ) goto aBigger;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   776
    if ( sigA.v0 < sigB.v0 ) goto bBigger;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   777
    uiZ.v64 =
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   778
	packToF128UI64(
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   779
	    (softfloat_roundingMode == softfloat_round_min), 0, 0 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   780
    uiZ.v0 = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   781
    goto uiZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   782
 expBBigger:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   783
    if ( expB == 0x7FFF ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   784
	if ( sigB.v64 | sigB.v0 ) goto propagateNaN;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   785
	uiZ.v64 = packToF128UI64( signZ ^ 1, 0x7FFF, 0 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   786
	uiZ.v0  = 0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   787
	goto uiZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   788
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   789
    if ( expA ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   790
	sigA.v64 |= UINT64_C( 0x0010000000000000 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   791
    } else {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   792
	++expDiff;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   793
	if ( ! expDiff ) goto newlyAlignedBBigger;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   794
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   795
    sigA = softfloat_shiftRightJam128( sigA.v64, sigA.v0, -expDiff );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   796
 newlyAlignedBBigger:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   797
    expZ = expB;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   798
    sigB.v64 |= UINT64_C( 0x0010000000000000 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   799
 bBigger:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   800
    signZ = ! signZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   801
    sigZ = softfloat_sub128( sigB.v64, sigB.v0, sigA.v64, sigA.v0 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   802
    goto normRoundPack;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   803
 expABigger:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   804
    if ( expA == 0x7FFF ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   805
	if ( sigA.v64 | sigA.v0 ) goto propagateNaN;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   806
	uiZ.v64 = uiA64;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   807
	uiZ.v0  = uiA0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   808
	goto uiZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   809
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   810
    if ( expB ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   811
	sigB.v64 |= UINT64_C( 0x0010000000000000 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   812
    } else {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   813
	--expDiff;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   814
	if ( ! expDiff ) goto newlyAlignedABigger;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   815
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   816
    sigB = softfloat_shiftRightJam128( sigB.v64, sigB.v0, expDiff );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   817
 newlyAlignedABigger:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   818
    expZ = expA;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   819
    sigA.v64 |= UINT64_C( 0x0010000000000000 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   820
 aBigger:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   821
    sigZ = softfloat_sub128( sigA.v64, sigA.v0, sigB.v64, sigB.v0 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   822
 normRoundPack:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   823
    return softfloat_normRoundPackToF128( signZ, expZ - 5, sigZ.v64, sigZ.v0 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   824
 propagateNaN:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   825
    uiZ = softfloat_propagateNaNF128UI( uiA64, uiA0, uiB64, uiB0 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   826
 uiZ:
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   827
    uZ.ui = uiZ;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   828
    return uZ.f;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   829
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   830
}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   831
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   832
void
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   833
f128M_add( const float128_t *aPtr, const float128_t *bPtr, float128_t *zPtr )
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   834
{
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   835
    const uint64_t *aWPtr, *bWPtr;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   836
    uint64_t uiA64, uiA0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   837
    int signA;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   838
    uint64_t uiB64, uiB0;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   839
    int signB;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   840
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   841
    aWPtr = (const uint64_t *) aPtr;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   842
    bWPtr = (const uint64_t *) bPtr;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   843
    uiA64 = aWPtr[indexWord( 2, 1 )];
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   844
    uiA0  = aWPtr[indexWord( 2, 0 )];
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   845
    signA = signF128UI64( uiA64 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   846
    uiB64 = bWPtr[indexWord( 2, 1 )];
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   847
    uiB0  = bWPtr[indexWord( 2, 0 )];
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   848
    signB = signF128UI64( uiB64 );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   849
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   850
    if ( signA == signB ) {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   851
	*zPtr = softfloat_addMagsF128( uiA64, uiA0, uiB64, uiB0, signA );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   852
    } else {
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   853
	*zPtr = softfloat_subMagsF128( uiA64, uiA0, uiB64, uiB0, signA );
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   854
    }
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   855
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   856
}
4993
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
   857
#endif // SUPPORT_QUADFLOAT
4992
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   858
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   859
%}
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   860
! !
4991
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   861
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   862
!QuadFloat class methodsFor:'documentation'!
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   863
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   864
documentation
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   865
"
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   866
    QuadFloats represent rational numbers with limited precision
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   867
    and are mapped to IEEE quadruple precision format (128bit).
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   868
    If the underlying cpu supports them natively, the machine format (long double) is
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   869
    used. Otherwise, a software emulation is done, which is much slower.
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   870
    Thus only use them, if you really need the additional precision;
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   871
    if not, use Float (which are doubles) or LongFloats which usually have IEEE extended precision (80bit).
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   872
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   873
    QuadFloats give you definite 128 bit quadruple floats,
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   874
    thus, code using quadFloats is guaranteed to be portable from one architecture to another.
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   875
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   876
    Representation:
4991
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   877
	    128bit quadruple IEEE floats (16bytes);
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   878
	    112 bit mantissa,
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   879
	    16 bit exponent,
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   880
	    34 decimal digits (approx.)
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   881
4992
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   882
    On Sparc CPUs, this is a native supported type (long double) and fast;
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   883
    on x86 CPUs, this is emulated and slow.
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   884
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   885
    Mixed mode arithmetic:
4991
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   886
	quadFloat op anyFloat    -> longFloat
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   887
	longFloat op complex     -> complex
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   888
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   889
    Range and precision of storage formats: see LimitedPrecisionReal >> documentation
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   890
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   891
    [author:]
4991
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   892
	Claus Gittinger
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   893
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   894
    [see also:]
4991
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   895
	Number
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   896
	Float ShortFloat LongFloat Fraction FixedPoint Integer Complex
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   897
	FloatArray DoubleArray
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   898
	https://en.wikipedia.org/wiki/Extended_precision
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   899
"
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   900
! !
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   901
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   902
!QuadFloat class methodsFor:'instance creation'!
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   903
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   904
basicNew
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   905
    "return a new quadFloat - here we return 0.0
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   906
     - QuadFloats are usually NOT created this way ...
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   907
     Its implemented here to allow things like binary store & load
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   908
     of quadFloats.
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   909
     (but it is not a good idea to store the bits of a float - the reader might have a
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   910
      totally different representation - so floats should be
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   911
      binary stored in a device independent format)."
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   912
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   913
%{  /* NOCONTEXT */
4993
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
   914
#ifdef SUPPORT_QUADFLOAT
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   915
    OBJ newFloat;
4991
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   916
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   917
    if (sizeof(long double) == sizeof(float128_t)) {
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   918
	__qMKLFLOAT(newFloat, 0.0);   /* OBJECT ALLOCATION */
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   919
    } else {
4991
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   920
	float128_t qf;
4992
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   921
	f64_to_f128M(0.0, &qf);
4991
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   922
	__qMKQFLOAT(newFloat, qf);   /* OBJECT ALLOCATION */
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   923
    }
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   924
    RETURN (newFloat);
4993
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
   925
#endif /* SUPPORT_QUADFLOAT */
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
   926
%}.
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
   927
    self error:'QuadFloats not supported on this patform'
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   928
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   929
    "Created: / 06-06-2019 / 17:18:58 / Claus Gittinger"
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   930
!
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   931
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   932
fromFloat:aFloat
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   933
    "return a new quadFloat, given a float value"
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   934
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   935
%{  /* NOCONTEXT */
4993
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
   936
#ifdef SUPPORT_QUADFLOAT
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   937
    OBJ newFloat;
4991
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   938
    float128_t f;
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   939
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   940
    if (__isFloatLike(aFloat)) {
4992
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   941
	float64_t f = __floatVal(aFloat);
4991
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   942
	float128_t qf;
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   943
4992
ee1d80769d4c first code for add
Claus Gittinger <cg@exept.de>
parents: 4991
diff changeset
   944
	f64_to_f128M(f, &qf);
4991
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   945
	__qMKQFLOAT(newFloat, qf);   /* OBJECT ALLOCATION */
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   946
	RETURN (newFloat);
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   947
    }
4993
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
   948
#endif /* SUPPORT_QUADFLOAT */
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   949
%}.
4993
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
   950
    aFloat isFloat ifTrue:[
4997
55c76587b49c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4994
diff changeset
   951
	self errorUnsupported
4993
c7956a3ab780 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4992
diff changeset
   952
    ].
4997
55c76587b49c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4994
diff changeset
   953
    ArgumentError raise
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   954
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   955
    "
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   956
     QuadFloat fromFloat:123.0
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   957
     123.0 asQuadFloat
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   958
     123 asQuadFloat
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   959
    "
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   960
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   961
    "Created: / 06-06-2019 / 18:01:03 / Claus Gittinger"
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   962
! !
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   963
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   964
!QuadFloat class methodsFor:'coercing & converting'!
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   965
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   966
coerce:aNumber
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   967
    "convert the argument aNumber into an instance of the receiver's class and return it."
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   968
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   969
    ^ aNumber asQuadFloat.
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   970
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   971
    "Created: / 06-06-2019 / 16:51:01 / Claus Gittinger"
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   972
! !
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   973
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   974
!QuadFloat class methodsFor:'constants'!
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   975
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   976
NaN
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   977
    "return a shortFloat which represents not-a-Number (i.e. an invalid number)"
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   978
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   979
    NaN isNil ifTrue:[
4991
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   980
	NaN := super NaN
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   981
    ].
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   982
    ^ NaN
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   984
    "
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   985
     self NaN
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   986
    "
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   987
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   988
    "Created: / 06-06-2019 / 16:56:09 / Claus Gittinger"
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   989
!
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   990
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   991
e
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   992
    "return the constant e as quadFloat"
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   993
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   994
    E isNil ifTrue:[
4991
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   995
	"/ eDigits has enough digits for 128bit IEEE quads
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   996
	"/ do not use as a literal constant here - we cannot depend on the underlying C-compiler here...
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
   997
	E  := self readFrom:(Number eDigits)
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   998
    ].
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   999
    ^ E
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1000
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1001
    "Created: / 06-06-2019 / 17:01:54 / Claus Gittinger"
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1002
!
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1003
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1004
pi
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1005
    "return the constant pi as quadFloat"
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1006
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1007
    Pi isNil ifTrue:[
4991
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
  1008
	"/ piDigits has enough digits for 128bit IEEE quads
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
  1009
	"/ do not use as a literal constant here - we cannot depend on the underlying C-compiler here...
9d86d1eb2a65 compilable, at least
Claus Gittinger <cg@exept.de>
parents: 4983
diff changeset
  1010
	Pi  := self readFrom:(Number piDigits)
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1011
    ].
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1012
    ^ Pi
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1013
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1014
    "Created: / 06-06-2019 / 17:09:51 / Claus Gittinger"
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1015
! !
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1016
4994
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1017
!QuadFloat methodsFor:'double dispatching'!
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1018
4997
55c76587b49c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4994
diff changeset
  1019
errorUnsupported
55c76587b49c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4994
diff changeset
  1020
    self error:'QuadFloats not supported on this patform'
55c76587b49c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4994
diff changeset
  1021
!
55c76587b49c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4994
diff changeset
  1022
4994
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1023
sumFromQuadFloat:aQuadFloat
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1024
%{
4997
55c76587b49c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4994
diff changeset
  1025
#ifdef SUPPORT_QUADFLOAT
4994
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1026
    OBJ newFloat;
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1027
    float128_t result, myVal, argVal;
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1028
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1029
    myVal = __quadFloatVal(self);
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1030
    argVal = __quadFloatVal(aQuadFloat);
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1031
    f128M_add( &myVal, &argVal, &result );
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1032
    __qMKQFLOAT(newFloat, result);
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1033
    RETURN ( newFloat );
4997
55c76587b49c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4994
diff changeset
  1034
#endif // SUPPORT_QUADFLOAT
55c76587b49c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4994
diff changeset
  1035
%}.
55c76587b49c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4994
diff changeset
  1036
    self errorUnsupported
4994
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1037
! !
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1038
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1039
!QuadFloat methodsFor:'arithmetic'!
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1040
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1041
* aNumber
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1042
    "return the product of the receiver and the argument."
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1043
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1044
    ^ aNumber productFromQuadFloat:self
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1045
!
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1046
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1047
+ aNumber
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1048
    "return the sum of the receiver and the argument, aNumber"
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1049
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1050
    ^ aNumber sumFromQuadFloat:self
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1051
!
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1052
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1053
- aNumber
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1054
    "return the difference of the receiver and the argument, aNumber"
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1055
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1056
    ^ aNumber differenceFromQuadFloat:self
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1057
!
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1058
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1059
/ aNumber
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1060
    "return the quotient of the receiver and the argument, aNumber"
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1061
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1062
    aNumber isZero ifTrue:[
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1063
	"
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1064
	 No, you shalt not divide by zero
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1065
	"
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1066
	^ ZeroDivide raiseRequestWith:thisContext.
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1067
    ].
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1068
    ^ aNumber quotientFromQuadFloat:self
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1069
!
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1070
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1071
rem: aNumber
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1072
    "return the floating point remainder of the receiver and the argument, aNumber"
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1073
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1074
    aNumber isZero ifTrue:[
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1075
	"
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1076
	 No, you shalt not divide by zero
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1077
	"
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1078
	^ ZeroDivide raiseRequestWith:thisContext.
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1079
    ].
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1080
    ^ aNumber remainderFromLongFloat:self
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1081
! !
246159e1784d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4993
diff changeset
  1082
4983
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1083
!QuadFloat class methodsFor:'documentation'!
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1084
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1085
version_CVS
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1086
    ^ '$Header$'
696dd6d07736 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1087
! !