/**************************************************************************/
/*                                                                        */
/*                                 Sources                                */
/*                                from  the                               */
/*                           XSC SOFTWARE PACKAGE                         */
/*                                                                        */
/*                Copyright (c) 1997 University of Karlsruhe              */
/*                     Institute for Appl. Mathematics                    */
/*                                                                        */
/* This program is free software for non-commercial use. For details, see */
/* the file LICENSE.XSC, distributed with this software package.          */
/*                                                                        */
/* This program is distributed WITHOUT ANY WARRANTY. For details, see the */
/* file LICENSE.XSC, distributed with this software package.              */
/*                                                                        */
/**************************************************************************/

/* RCS $Id: e_defs.h,v 1.7 1997/09/25 16:43:34 ae59 Exp $ */
/*
$Log: e_defs.h,v $
 * Revision 1.7  1997/09/25  16:43:34  ae59
 * Copyright-message
 *
 * Revision 1.6  1996/03/22  15:13:39  ae59
 * Hardware support for RS6000 with precise and imprecise (default) traps
 *
 * Revision 1.5  1996/03/18  12:06:31  ae59
 * Hardware support for sparc solaris
 *
 * Revision 1.4  1995/09/04  16:48:05  ae59
 * hardware support for ibm_emx_c similar to ibm_linux
 *
 * Revision 1.3  1995/08/17  12:36:48  ae59
 * support for linux-387 added by CB
 *
 * Revision 1.2  1994/10/25  11:08:31  ae59
 * add shortabtyp for 64 bit systems
 *
 * Revision 1.1  1994/01/27  13:22:14  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : e_defs.h                              */
/*                                                              */
/*      Date            : 1993-02-16                            */
/*      1995-08-10 cb : i486 linux hardware                     */
/*      1993-02-16 : update from Dr. cordes =b=                 */
/*      1992-12-26 : E_TLNG defined for extended long format    */
/*      1992-07-21 : add sun4_gnuc and sun4_cpp switch =b=      */
/*      1992-06-09 : new macro SET_SIGNAL (r_valu)              */
/*      1992-02-26 : (char *) in e_push() =b=                   */
/*      1992-01-22 : (a_char *) in e_push()                     */
/*      1992-01-16 : replace e_renv by o_text[6]                */
/*      1991-11-14 : new macros E_SPUSH(),E_SPOPP()             */
/*      1991-04-33 : MANT_INFINITY for infinity detection       */
/*      1991-02-13 : new data characterization E_TSTG           */
/*      1991-01-23 : E_TEXT must be defined with E_TRES         */
/****************************************************************/

/*    Macro for testing for a signaling NaN                     */
#ifdef IEEE_HARDWARE
#if IBM_RT_C+IBM_RS6000_C+SUN4_OS4_C+SUN4_GNU_C+SUN4_CPP_C+SUN4_OS5_GNU_C
#define SIGNAL_BIT              ((a_btyp)0x00080000L)
#define SIGNALING(a)            (!((a) & SIGNAL_BIT))
#define SET_QUIET(a)            ((a) | SIGNAL_BIT)
#define SET_SIGNAL(a)		((a) & ~SIGNAL_BIT)
#endif
#if HP_9000_C
#define SIGNAL_BIT              ((a_btyp)0x00080000L)
#define SIGNALING(a)            ((a) & SIGNAL_BIT)
#define SET_QUIET(a)            ((a) & ~SIGNAL_BIT)
#define SET_SIGNAL(a)		((a) | SIGNAL_BIT)
#endif
#if IBM_LINUX_C+IBM_EMX_C
#define SIGNAL_BIT              ((a_btyp)0x00080000L)
#define SIGNALING(a)            (!((a) & SIGNAL_BIT))
#define SET_QUIET(a)            ((a) | SIGNAL_BIT)
#define SET_SIGNAL(a)		((a) & ~SIGNAL_BIT)
#endif
#else	/* IEEE_HARDWARE */
#if SHORTABTYP
#define SIGNAL_BIT              ((a_btyp)0x00080000)
#else
#define SIGNAL_BIT              ((a_btyp)0x00080000L)
#endif
#define SIGNALING(a)            ((a) & SIGNAL_BIT)
#define SET_QUIET(a)            ((a) & ~SIGNAL_BIT)
#define SET_SIGNAL(a)		((a) | SIGNAL_BIT)
#endif

/*    Macro for testing for a mantissa used for infinity        */
#define MANT_INFINITY(a)        ((a)[0]==HIDDEN_BIT && (a)[1]==ZERO)

/*    Constants for trap handling routines.                     */
#if SHORTABTYP
#define E_CHNG                  ((a_btyp)0x00004000)
#define E_POPP                  ((a_btyp)0x00002000)
#define E_PUSH                  ((a_btyp)0x00001000)

#define E_ACTIVE                ((a_btyp)0x00000100)
#define E_BACK                  ((a_btyp)0x00000080)
#define E_CONT                  ((a_btyp)0x00000040)
#define E_DEFAULT               ((a_btyp)0x00000020)
#else
#define E_CHNG                  ((a_btyp)0x00004000L)
#define E_POPP                  ((a_btyp)0x00002000L)
#define E_PUSH                  ((a_btyp)0x00001000L)

#define E_ACTIVE                ((a_btyp)0x00000100L)
#define E_BACK                  ((a_btyp)0x00000080L)
#define E_CONT                  ((a_btyp)0x00000040L)
#define E_DEFAULT               ((a_btyp)0x00000020L)
#endif

/*    Value for non-existing exception handler.                 */
#ifdef LINT_ARGS
#define NO_TRAP                 ((void (*)(a_btyp,int,va_list))0)
#else
#define NO_TRAP                 ((void (*)())0)
#endif

/*------ Error characterizations -------------------------------*/
/*    Splitting of error condition code into error code and     */
/*    error characterization.                                   */
#if SHORTABTYP
#define E_MASK                  ((a_btyp)0xFFFFFF00)

#define E_ECNT                  ((a_btyp)0x00000080)
#define E_EMSG                  ((a_btyp)0x00000040)
#define E_ETBC                  ((a_btyp)0x00000020)
#define E_EXIT                  ((a_btyp)0x00000010)
#define E_EARG                  ((a_btyp)0x00000008)
#define E_EQIE                  ((a_btyp)0x00000004)
#define E_IEEE                  ((a_btyp)0x00000001)

/*------ Error groups ------------------------------------------*/
/*    Do not change the value order of error groups.            */
/*    Changing value order has side effect on file "e_data.c".  */
#define NO_ERROR                ((a_btyp)0x00000000)
#define INV_OP                  ((a_btyp)0x00000100)
#define DIV_BY_ZERO             ((a_btyp)0x00000a00)
#define OVERFLOW                ((a_btyp)0x00000b00)
#define UNDERFLOW               ((a_btyp)0x00000c00)
#define INEXACT                 ((a_btyp)0x00000d00)
#define ALLOCATION              ((a_btyp)0x00000e00)
#define I_O_ERROR               ((a_btyp)0x00001000)
#define I_O_BUFFER              ((a_btyp)0x00001100)
#define INV_ARG                 ((a_btyp)0x00001200)
#define INDEX_RANGE             ((a_btyp)0x00001300)
#else
#define E_MASK                  ((a_btyp)0xFFFFFF00L)

#define E_ECNT                  ((a_btyp)0x00000080L)
#define E_EMSG                  ((a_btyp)0x00000040L)
#define E_ETBC                  ((a_btyp)0x00000020L)
#define E_EXIT                  ((a_btyp)0x00000010L)
#define E_EARG                  ((a_btyp)0x00000008L)
#define E_EQIE                  ((a_btyp)0x00000004L)
#define E_IEEE                  ((a_btyp)0x00000001L)

/*------ Error groups ------------------------------------------*/
/*    Do not change the value order of error groups.            */
/*    Changing value order has side effect on file "e_data.c".  */
#define NO_ERROR                ((a_btyp)0x00000000L)
#define INV_OP                  ((a_btyp)0x00000100L)
#define DIV_BY_ZERO             ((a_btyp)0x00000a00L)
#define OVERFLOW                ((a_btyp)0x00000b00L)
#define UNDERFLOW               ((a_btyp)0x00000c00L)
#define INEXACT                 ((a_btyp)0x00000d00L)
#define ALLOCATION              ((a_btyp)0x00000e00L)
#define I_O_ERROR               ((a_btyp)0x00001000L)
#define I_O_BUFFER              ((a_btyp)0x00001100L)
#define INV_ARG                 ((a_btyp)0x00001200L)
#define INDEX_RANGE             ((a_btyp)0x00001300L)
#endif

/*------ Data type characterization ----------------------------*/
#define E_TCHR                  ((int)1)        /* char *            */
#define E_TDBL                  ((int)2)        /* double *          */
#define E_TDTP                  ((int)3)        /* dotprecision *    */
#define E_TINT                  ((int)4)        /* int *             */
#define E_TMLT                  ((int)5)        /* multiprecision *  */
#define E_TSTR                  ((int)6)        /* char *            */
#define E_TULT                  ((int)7)        /* ultraprecision *  */
#define E_TSTG                  ((int)8)        /* s_trng *          */
#define E_TLNG                  ((int)9)        /* a_long *          */
#define E_TRES                  ((int)0x100)    /* --- result        */
#define E_TMSG                  ((int)0x7e00)   /* --- message       */
                                /* identification of displayed type  */
#define E_TEXT(a)               ((a)*(2*E_TRES))

/*------ Error codes of float arithmetic -----------------------*/

#define DENOR 1         /* denormalized number converted                */
#define MINFI 2         /* -infinity detected                           */
#define NANDE 3         /* NAN detected                                 */
#define OFLOW 4         /* exponent overflow                            */
#define PINFI 5         /* +infinity detected                           */
#define ROUND 6         /* double value is rounded                      */
#define UFLOW 7         /* exponent underflow                           */
#define ZEROD 8         /* divide by zero                               */
#define RANGE 9         /* range error                                  */
#define ALLOC 10        /* allocation error                             */
#define NALLO 11        /* data not allocated                           */

/*------ Macros specifying push and pop in runtime -------------*/

#ifdef RTSTRC_DISABLE
#define E_TPUSH(a)
#define E_TPOPP(a)
#else
#define E_TPUSH(a) \
 {extern char *o_text[]; e_push((char *)a,(char *)o_text[6]);}
#define E_TPOPP(a)      e_popp();
#endif
#ifdef STDTRC_DISABLE
#define E_SPUSH(a)      a_intg flags; e_save(&flags);
#define E_SPOPP(a)      e_rest(flags);
#else
#define E_SPUSH(a) \
 a_intg flags; \
 {extern char *o_text[]; e_push((char *)a,(char *)o_text[6]);} \
 e_save(&flags);
#define E_SPOPP(a)      e_rest(flags); e_popp();
#endif

