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