/* Common support for checking that appropriate floating point exceptions
|
/* Common support for checking that appropriate floating point exceptions
|
are raised for decimal float operations. These tests are here to test
|
are raised for decimal float operations. These tests are here to test
|
the software decimal float support in libgcc. */
|
the software decimal float support in libgcc. */
|
|
|
#include "dfp-dbg.h"
|
#include "dfp-dbg.h"
|
#include "dfp-except.h"
|
#include "dfp-except.h"
|
|
|
#if defined(DBG) || defined(DBG2)
|
#if defined(DBG) || defined(DBG2)
|
#include <stdio.h>
|
#include <stdio.h>
|
#undef FAILURE
|
#undef FAILURE
|
#define FAILURE(NUM,KIND,EXCEPT) \
|
#define FAILURE(NUM,KIND,EXCEPT) \
|
{ printf ("failed for test %d: %s %s\n", NUM, KIND, EXCEPT); failures++; }
|
{ printf ("failed for test %d: %s %s\n", NUM, KIND, EXCEPT); failures++; }
|
#else
|
#else
|
#undef FAILURE
|
#undef FAILURE
|
#define FAILURE(N,K,E) __builtin_abort ();
|
#define FAILURE(N,K,E) __builtin_abort ();
|
#endif
|
#endif
|
|
|
/* This is useful when modifying the test to make sure that tests are
|
/* This is useful when modifying the test to make sure that tests are
|
actually run. */
|
actually run. */
|
#if defined(DBG2)
|
#if defined(DBG2)
|
#define SUCCESS(NUM,EXCEPT) \
|
#define SUCCESS(NUM,EXCEPT) \
|
{ printf ("passed for test %d: %s\n", NUM, EXCEPT); }
|
{ printf ("passed for test %d: %s\n", NUM, EXCEPT); }
|
#else
|
#else
|
#define SUCCESS(N,E) ;
|
#define SUCCESS(N,E) ;
|
#endif
|
#endif
|
|
|
#define CHECKFLAG(NUM,EXCEPT,GOT,WANT) \
|
#define CHECKFLAG(NUM,EXCEPT,GOT,WANT) \
|
if ((WANT & EXCEPT) != (GOT & EXCEPT)) \
|
if ((WANT & EXCEPT) != (GOT & EXCEPT)) \
|
{ \
|
{ \
|
if ((WANT & EXCEPT) != 0) \
|
if ((WANT & EXCEPT) != 0) \
|
FAILURE (NUM, "missing", #EXCEPT) \
|
FAILURE (NUM, "missing", #EXCEPT) \
|
else \
|
else \
|
FAILURE (NUM, "unexpected", #EXCEPT) \
|
FAILURE (NUM, "unexpected", #EXCEPT) \
|
} \
|
} \
|
else \
|
else \
|
SUCCESS (NUM, #EXCEPT)
|
SUCCESS (NUM, #EXCEPT)
|
|
|
void
|
void
|
checkflags (int num, int want)
|
checkflags (int num, int want)
|
{
|
{
|
int got = DFP_TEST_EXCEPT (FE_ALL_EXCEPT);
|
int got = DFP_TEST_EXCEPT (FE_ALL_EXCEPT);
|
CHECKFLAG (num, FE_INVALID, got, want)
|
CHECKFLAG (num, FE_INVALID, got, want)
|
CHECKFLAG (num, FE_OVERFLOW, got, want)
|
CHECKFLAG (num, FE_OVERFLOW, got, want)
|
CHECKFLAG (num, FE_UNDERFLOW, got, want)
|
CHECKFLAG (num, FE_UNDERFLOW, got, want)
|
CHECKFLAG (num, FE_DIVBYZERO, got, want)
|
CHECKFLAG (num, FE_DIVBYZERO, got, want)
|
CHECKFLAG (num, FE_INEXACT, got, want)
|
CHECKFLAG (num, FE_INEXACT, got, want)
|
}
|
}
|
|
|
#define BINOP(NUM,OP,VAR1,VAL1,VAR2,VAL2,VAR3,EXCEPT) \
|
#define BINOP(NUM,OP,VAR1,VAL1,VAR2,VAL2,VAR3,EXCEPT) \
|
void \
|
void \
|
binop_##NUM (void) \
|
binop_##NUM (void) \
|
{ \
|
{ \
|
VAR1 = VAL1; \
|
VAR1 = VAL1; \
|
VAR2 = VAL2; \
|
VAR2 = VAL2; \
|
DFP_CLEAR_EXCEPT (FE_ALL_EXCEPT); \
|
DFP_CLEAR_EXCEPT (FE_ALL_EXCEPT); \
|
VAR3 = VAR1 OP VAR2; \
|
VAR3 = VAR1 OP VAR2; \
|
checkflags (NUM, EXCEPT); \
|
checkflags (NUM, EXCEPT); \
|
}
|
}
|
|
|
#define CONVERT(NUM,FROM,TO,VALUE,EXCEPT) \
|
#define CONVERT(NUM,FROM,TO,VALUE,EXCEPT) \
|
void \
|
void \
|
convert_##NUM (void) \
|
convert_##NUM (void) \
|
{ \
|
{ \
|
FROM = VALUE; \
|
FROM = VALUE; \
|
DFP_CLEAR_EXCEPT (FE_ALL_EXCEPT); \
|
DFP_CLEAR_EXCEPT (FE_ALL_EXCEPT); \
|
TO = FROM; \
|
TO = FROM; \
|
checkflags (NUM, EXCEPT); \
|
checkflags (NUM, EXCEPT); \
|
}
|
}
|
|
|