Skip to content

Commit

Permalink
[Feat] Configure global state at compile-time
Browse files Browse the repository at this point in the history
This patch adds preprocessor facilities to enable choosing between
global state (SoftFloatv3 default) and adding a "state" parameter
to all functions. This has been discussed already by John Hauser
at: ucb-bar#5

This patch takes the position of enabling both options using a
preprocessor macro named "SOFTFLOAT_USE_GLOBAL_STATE". If the macro
is defined, then it uses global state as it does already. If the
macro is undefined, then it adds a state parameter which is a struct
defined in softfloat_types.h
  • Loading branch information
Mohamed A. Bamakhrama committed May 23, 2019
1 parent b64af41 commit 8ae3372
Show file tree
Hide file tree
Showing 305 changed files with 1,690 additions and 1,275 deletions.
4 changes: 2 additions & 2 deletions source/8086-SSE/s_extF80MToCommonNaN.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*----------------------------------------------------------------------------*/
void
softfloat_extF80MToCommonNaN(
const struct extFloat80M *aSPtr, struct commonNaN *zPtr )
const struct extFloat80M *aSPtr, struct commonNaN *zPtr STATE_PARAM )
{

if ( extF80M_isSignalingNaN( (const extFloat80_t *) aSPtr ) ) {
softfloat_raiseFlags( softfloat_flag_invalid );
softfloat_raiseFlags( softfloat_flag_invalid STATE_VAR );
}
zPtr->sign = signExtF80UI64( aSPtr->signExp );
zPtr->v64 = aSPtr->signif<<1;
Expand Down
5 changes: 3 additions & 2 deletions source/8086-SSE/s_extF80UIToCommonNaN.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*----------------------------------------------------------------------------*/
void
softfloat_extF80UIToCommonNaN(
uint_fast16_t uiA64, uint_fast64_t uiA0, struct commonNaN *zPtr )
uint_fast16_t uiA64, uint_fast64_t uiA0, struct commonNaN *zPtr
STATE_PARAM )
{

if ( softfloat_isSigNaNExtF80UI( uiA64, uiA0 ) ) {
softfloat_raiseFlags( softfloat_flag_invalid );
softfloat_raiseFlags( softfloat_flag_invalid STATE_VAR );
}
zPtr->sign = uiA64>>15;
zPtr->v64 = uiA0<<1;
Expand Down
5 changes: 3 additions & 2 deletions source/8086-SSE/s_f128MToCommonNaN.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
| to form a 128-bit floating-point value.
*----------------------------------------------------------------------------*/
void
softfloat_f128MToCommonNaN( const uint32_t *aWPtr, struct commonNaN *zPtr )
softfloat_f128MToCommonNaN(
const uint32_t *aWPtr, struct commonNaN *zPtr STATE_PARAM )
{

if ( f128M_isSignalingNaN( (const float128_t *) aWPtr ) ) {
softfloat_raiseFlags( softfloat_flag_invalid );
softfloat_raiseFlags( softfloat_flag_invalid STATE_VAR );
}
zPtr->sign = aWPtr[indexWordHi( 4 )]>>31;
softfloat_shortShiftLeft128M( aWPtr, 16, (uint32_t *) &zPtr->v0 );
Expand Down
5 changes: 3 additions & 2 deletions source/8086-SSE/s_f128UIToCommonNaN.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*----------------------------------------------------------------------------*/
void
softfloat_f128UIToCommonNaN(
uint_fast64_t uiA64, uint_fast64_t uiA0, struct commonNaN *zPtr )
uint_fast64_t uiA64, uint_fast64_t uiA0, struct commonNaN *zPtr
STATE_PARAM )
{
struct uint128 NaNSig;

if ( softfloat_isSigNaNF128UI( uiA64, uiA0 ) ) {
softfloat_raiseFlags( softfloat_flag_invalid );
softfloat_raiseFlags( softfloat_flag_invalid STATE_VAR );
}
NaNSig = softfloat_shortShiftLeft128( uiA64, uiA0, 16 );
zPtr->sign = uiA64>>63;
Expand Down
5 changes: 3 additions & 2 deletions source/8086-SSE/s_f16UIToCommonNaN.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
| location pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid
| exception is raised.
*----------------------------------------------------------------------------*/
void softfloat_f16UIToCommonNaN( uint_fast16_t uiA, struct commonNaN *zPtr )
void softfloat_f16UIToCommonNaN(
uint_fast16_t uiA, struct commonNaN *zPtr STATE_PARAM )
{

if ( softfloat_isSigNaNF16UI( uiA ) ) {
softfloat_raiseFlags( softfloat_flag_invalid );
softfloat_raiseFlags( softfloat_flag_invalid STATE_VAR );
}
zPtr->sign = uiA>>15;
zPtr->v64 = (uint_fast64_t) uiA<<54;
Expand Down
5 changes: 3 additions & 2 deletions source/8086-SSE/s_f32UIToCommonNaN.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
| location pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid
| exception is raised.
*----------------------------------------------------------------------------*/
void softfloat_f32UIToCommonNaN( uint_fast32_t uiA, struct commonNaN *zPtr )
void softfloat_f32UIToCommonNaN(
uint_fast32_t uiA, struct commonNaN *zPtr STATE_PARAM )
{

if ( softfloat_isSigNaNF32UI( uiA ) ) {
softfloat_raiseFlags( softfloat_flag_invalid );
softfloat_raiseFlags( softfloat_flag_invalid STATE_VAR );
}
zPtr->sign = uiA>>31;
zPtr->v64 = (uint_fast64_t) uiA<<41;
Expand Down
5 changes: 3 additions & 2 deletions source/8086-SSE/s_f64UIToCommonNaN.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
| location pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid
| exception is raised.
*----------------------------------------------------------------------------*/
void softfloat_f64UIToCommonNaN( uint_fast64_t uiA, struct commonNaN *zPtr )
void softfloat_f64UIToCommonNaN(
uint_fast64_t uiA, struct commonNaN *zPtr STATE_PARAM )
{

if ( softfloat_isSigNaNF64UI( uiA ) ) {
softfloat_raiseFlags( softfloat_flag_invalid );
softfloat_raiseFlags( softfloat_flag_invalid STATE_VAR );
}
zPtr->sign = uiA>>63;
zPtr->v64 = uiA<<12;
Expand Down
6 changes: 4 additions & 2 deletions source/8086-SSE/s_propagateNaNExtF80M.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void
const struct extFloat80M *aSPtr,
const struct extFloat80M *bSPtr,
struct extFloat80M *zSPtr
STATE_PARAM
)
{
bool isSigNaNA;
Expand All @@ -66,12 +67,13 @@ void
isSigNaNA = extF80M_isSignalingNaN( (const extFloat80_t *) aSPtr );
sPtr = aSPtr;
if ( ! bSPtr ) {
if ( isSigNaNA ) softfloat_raiseFlags( softfloat_flag_invalid );
if ( isSigNaNA ) softfloat_raiseFlags(
softfloat_flag_invalid STATE_VAR );
goto copy;
}
isSigNaNB = extF80M_isSignalingNaN( (const extFloat80_t *) bSPtr );
if ( isSigNaNA | isSigNaNB ) {
softfloat_raiseFlags( softfloat_flag_invalid );
softfloat_raiseFlags( softfloat_flag_invalid STATE_VAR );
if ( isSigNaNA ) {
uiB64 = bSPtr->signExp;
if ( isSigNaNB ) goto returnLargerUIMag;
Expand Down
3 changes: 2 additions & 1 deletion source/8086-SSE/s_propagateNaNExtF80UI.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct uint128
uint_fast64_t uiA0,
uint_fast16_t uiB64,
uint_fast64_t uiB0
STATE_PARAM
)
{
bool isSigNaNA, isSigNaNB;
Expand All @@ -75,7 +76,7 @@ struct uint128
/*------------------------------------------------------------------------
*------------------------------------------------------------------------*/
if ( isSigNaNA | isSigNaNB ) {
softfloat_raiseFlags( softfloat_flag_invalid );
softfloat_raiseFlags( softfloat_flag_invalid STATE_VAR );
if ( isSigNaNA ) {
if ( isSigNaNB ) goto returnLargerMag;
if ( isNaNExtF80UI( uiB64, uiB0 ) ) goto returnB;
Expand Down
4 changes: 2 additions & 2 deletions source/8086-SSE/s_propagateNaNF128M.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*----------------------------------------------------------------------------*/
void
softfloat_propagateNaNF128M(
const uint32_t *aWPtr, const uint32_t *bWPtr, uint32_t *zWPtr )
const uint32_t *aWPtr, const uint32_t *bWPtr, uint32_t *zWPtr STATE_PARAM )
{
bool isSigNaNA;
const uint32_t *ptr;
Expand All @@ -62,7 +62,7 @@ void
isSigNaNA
|| (bWPtr && f128M_isSignalingNaN( (const float128_t *) bWPtr ))
) {
softfloat_raiseFlags( softfloat_flag_invalid );
softfloat_raiseFlags( softfloat_flag_invalid STATE_VAR );
if ( isSigNaNA ) goto copy;
}
if ( ! softfloat_isNaNF128M( aWPtr ) ) ptr = bWPtr;
Expand Down
3 changes: 2 additions & 1 deletion source/8086-SSE/s_propagateNaNF128UI.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ struct uint128
uint_fast64_t uiA0,
uint_fast64_t uiB64,
uint_fast64_t uiB0
STATE_PARAM
)
{
bool isSigNaNA;
struct uint128 uiZ;

isSigNaNA = softfloat_isSigNaNF128UI( uiA64, uiA0 );
if ( isSigNaNA || softfloat_isSigNaNF128UI( uiB64, uiB0 ) ) {
softfloat_raiseFlags( softfloat_flag_invalid );
softfloat_raiseFlags( softfloat_flag_invalid STATE_VAR );
if ( isSigNaNA ) goto returnNonsigA;
}
if ( isNaNF128UI( uiA64, uiA0 ) ) {
Expand Down
4 changes: 2 additions & 2 deletions source/8086-SSE/s_propagateNaNF16UI.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
| signaling NaN, the invalid exception is raised.
*----------------------------------------------------------------------------*/
uint_fast16_t
softfloat_propagateNaNF16UI( uint_fast16_t uiA, uint_fast16_t uiB )
softfloat_propagateNaNF16UI( uint_fast16_t uiA, uint_fast16_t uiB STATE_PARAM )
{
bool isSigNaNA;

isSigNaNA = softfloat_isSigNaNF16UI( uiA );
if ( isSigNaNA || softfloat_isSigNaNF16UI( uiB ) ) {
softfloat_raiseFlags( softfloat_flag_invalid );
softfloat_raiseFlags( softfloat_flag_invalid STATE_VAR );
if ( isSigNaNA ) return uiA | 0x0200;
}
return (isNaNF16UI( uiA ) ? uiA : uiB) | 0x0200;
Expand Down
4 changes: 2 additions & 2 deletions source/8086-SSE/s_propagateNaNF32UI.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
| signaling NaN, the invalid exception is raised.
*----------------------------------------------------------------------------*/
uint_fast32_t
softfloat_propagateNaNF32UI( uint_fast32_t uiA, uint_fast32_t uiB )
softfloat_propagateNaNF32UI( uint_fast32_t uiA, uint_fast32_t uiB STATE_PARAM )
{
bool isSigNaNA;

isSigNaNA = softfloat_isSigNaNF32UI( uiA );
if ( isSigNaNA || softfloat_isSigNaNF32UI( uiB ) ) {
softfloat_raiseFlags( softfloat_flag_invalid );
softfloat_raiseFlags( softfloat_flag_invalid STATE_VAR );
if ( isSigNaNA ) return uiA | 0x00400000;
}
return (isNaNF32UI( uiA ) ? uiA : uiB) | 0x00400000;
Expand Down
4 changes: 2 additions & 2 deletions source/8086-SSE/s_propagateNaNF64UI.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
| signaling NaN, the invalid exception is raised.
*----------------------------------------------------------------------------*/
uint_fast64_t
softfloat_propagateNaNF64UI( uint_fast64_t uiA, uint_fast64_t uiB )
softfloat_propagateNaNF64UI( uint_fast64_t uiA, uint_fast64_t uiB STATE_PARAM )
{
bool isSigNaNA;

isSigNaNA = softfloat_isSigNaNF64UI( uiA );
if ( isSigNaNA || softfloat_isSigNaNF64UI( uiB ) ) {
softfloat_raiseFlags( softfloat_flag_invalid );
softfloat_raiseFlags( softfloat_flag_invalid STATE_VAR );
if ( isSigNaNA ) return uiA | UINT64_C( 0x0008000000000000 );
}
return (isNaNF64UI( uiA ) ? uiA : uiB) | UINT64_C( 0x0008000000000000 );
Expand Down
4 changes: 2 additions & 2 deletions source/8086-SSE/softfloat_raiseFlags.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
| to substitute a result value. If traps are not implemented, this routine
| should be simply `softfloat_exceptionFlags |= flags;'.
*----------------------------------------------------------------------------*/
void softfloat_raiseFlags( uint_fast8_t flags )
void softfloat_raiseFlags( uint_fast8_t flags STATE_PARAM )
{

softfloat_exceptionFlags |= flags;
STATE(exceptionFlags) |= flags;

}

35 changes: 24 additions & 11 deletions source/8086-SSE/specialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ struct commonNaN {
| location pointed to by 'zPtr'. If the NaN is a signaling NaN, the invalid
| exception is raised.
*----------------------------------------------------------------------------*/
void softfloat_f16UIToCommonNaN( uint_fast16_t uiA, struct commonNaN *zPtr );
void softfloat_f16UIToCommonNaN(
uint_fast16_t uiA, struct commonNaN *zPtr STATE_PARAM );

/*----------------------------------------------------------------------------
| Converts the common NaN pointed to by 'aPtr' into a 16-bit floating-point
Expand All @@ -115,7 +116,8 @@ uint_fast16_t softfloat_commonNaNToF16UI( const struct commonNaN *aPtr );
| signaling NaN, the invalid exception is raised.
*----------------------------------------------------------------------------*/
uint_fast16_t
softfloat_propagateNaNF16UI( uint_fast16_t uiA, uint_fast16_t uiB );
softfloat_propagateNaNF16UI(
uint_fast16_t uiA, uint_fast16_t uiB STATE_PARAM );

/*----------------------------------------------------------------------------
| The bit pattern for a default generated 32-bit floating-point NaN.
Expand All @@ -135,7 +137,8 @@ uint_fast16_t
| location pointed to by 'zPtr'. If the NaN is a signaling NaN, the invalid
| exception is raised.
*----------------------------------------------------------------------------*/
void softfloat_f32UIToCommonNaN( uint_fast32_t uiA, struct commonNaN *zPtr );
void softfloat_f32UIToCommonNaN(
uint_fast32_t uiA, struct commonNaN *zPtr STATE_PARAM );

/*----------------------------------------------------------------------------
| Converts the common NaN pointed to by 'aPtr' into a 32-bit floating-point
Expand All @@ -150,7 +153,8 @@ uint_fast32_t softfloat_commonNaNToF32UI( const struct commonNaN *aPtr );
| signaling NaN, the invalid exception is raised.
*----------------------------------------------------------------------------*/
uint_fast32_t
softfloat_propagateNaNF32UI( uint_fast32_t uiA, uint_fast32_t uiB );
softfloat_propagateNaNF32UI(
uint_fast32_t uiA, uint_fast32_t uiB STATE_PARAM );

/*----------------------------------------------------------------------------
| The bit pattern for a default generated 64-bit floating-point NaN.
Expand All @@ -170,7 +174,8 @@ uint_fast32_t
| location pointed to by 'zPtr'. If the NaN is a signaling NaN, the invalid
| exception is raised.
*----------------------------------------------------------------------------*/
void softfloat_f64UIToCommonNaN( uint_fast64_t uiA, struct commonNaN *zPtr );
void softfloat_f64UIToCommonNaN(
uint_fast64_t uiA, struct commonNaN *zPtr STATE_PARAM );

/*----------------------------------------------------------------------------
| Converts the common NaN pointed to by 'aPtr' into a 64-bit floating-point
Expand All @@ -185,7 +190,8 @@ uint_fast64_t softfloat_commonNaNToF64UI( const struct commonNaN *aPtr );
| signaling NaN, the invalid exception is raised.
*----------------------------------------------------------------------------*/
uint_fast64_t
softfloat_propagateNaNF64UI( uint_fast64_t uiA, uint_fast64_t uiB );
softfloat_propagateNaNF64UI(
uint_fast64_t uiA, uint_fast64_t uiB STATE_PARAM );

/*----------------------------------------------------------------------------
| The bit pattern for a default generated 80-bit extended floating-point NaN.
Expand Down Expand Up @@ -217,7 +223,8 @@ uint_fast64_t
*----------------------------------------------------------------------------*/
void
softfloat_extF80UIToCommonNaN(
uint_fast16_t uiA64, uint_fast64_t uiA0, struct commonNaN *zPtr );
uint_fast16_t uiA64, uint_fast64_t uiA0, struct commonNaN *zPtr
STATE_PARAM );

/*----------------------------------------------------------------------------
| Converts the common NaN pointed to by 'aPtr' into an 80-bit extended
Expand All @@ -241,6 +248,7 @@ struct uint128
uint_fast64_t uiA0,
uint_fast16_t uiB64,
uint_fast64_t uiB0
STATE_PARAM
);

/*----------------------------------------------------------------------------
Expand All @@ -266,7 +274,8 @@ struct uint128
*----------------------------------------------------------------------------*/
void
softfloat_f128UIToCommonNaN(
uint_fast64_t uiA64, uint_fast64_t uiA0, struct commonNaN *zPtr );
uint_fast64_t uiA64, uint_fast64_t uiA0, struct commonNaN *zPtr
STATE_PARAM );

/*----------------------------------------------------------------------------
| Converts the common NaN pointed to by 'aPtr' into a 128-bit floating-point
Expand All @@ -289,6 +298,7 @@ struct uint128
uint_fast64_t uiA0,
uint_fast64_t uiB64,
uint_fast64_t uiB0
STATE_PARAM
);

#else
Expand All @@ -306,7 +316,7 @@ struct uint128
*----------------------------------------------------------------------------*/
void
softfloat_extF80MToCommonNaN(
const struct extFloat80M *aSPtr, struct commonNaN *zPtr );
const struct extFloat80M *aSPtr, struct commonNaN *zPtr STATE_PARAM );

/*----------------------------------------------------------------------------
| Converts the common NaN pointed to by 'aPtr' into an 80-bit extended
Expand All @@ -328,6 +338,7 @@ void
const struct extFloat80M *aSPtr,
const struct extFloat80M *bSPtr,
struct extFloat80M *zSPtr
STATE_PARAM
);

/*----------------------------------------------------------------------------
Expand All @@ -347,7 +358,8 @@ void
| to form a 128-bit floating-point value.
*----------------------------------------------------------------------------*/
void
softfloat_f128MToCommonNaN( const uint32_t *aWPtr, struct commonNaN *zPtr );
softfloat_f128MToCommonNaN( const uint32_t *aWPtr, struct commonNaN *zPtr
STATE_PARAM );

/*----------------------------------------------------------------------------
| Converts the common NaN pointed to by 'aPtr' into a 128-bit floating-point
Expand All @@ -368,7 +380,8 @@ void
*----------------------------------------------------------------------------*/
void
softfloat_propagateNaNF128M(
const uint32_t *aWPtr, const uint32_t *bWPtr, uint32_t *zWPtr );
const uint32_t *aWPtr, const uint32_t *bWPtr, uint32_t *zWPtr
STATE_PARAM );

#endif

Expand Down
4 changes: 2 additions & 2 deletions source/8086/s_extF80MToCommonNaN.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*----------------------------------------------------------------------------*/
void
softfloat_extF80MToCommonNaN(
const struct extFloat80M *aSPtr, struct commonNaN *zPtr )
const struct extFloat80M *aSPtr, struct commonNaN *zPtr STATE_PARAM )
{

if ( extF80M_isSignalingNaN( (const extFloat80_t *) aSPtr ) ) {
softfloat_raiseFlags( softfloat_flag_invalid );
softfloat_raiseFlags( softfloat_flag_invalid STATE_VAR );
}
zPtr->sign = signExtF80UI64( aSPtr->signExp );
zPtr->v64 = aSPtr->signif<<1;
Expand Down
Loading

0 comments on commit 8ae3372

Please sign in to comment.