File: dpml_exception.c

package info (click to toggle)
intelrdfpmath 2.0u3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 27,088 kB
  • sloc: ansic: 310,558; makefile: 446; sh: 3
file content (262 lines) | stat: -rw-r--r-- 7,899 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/******************************************************************************
  Copyright (c) 2007-2024, Intel Corp.
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of Intel Corporation nor the names of its contributors
      may be used to endorse or promote products derived from this software
      without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/

#if !defined(DPML_DO_SIDE_EFFECTS_NAME)
#    define DPML_DO_SIDE_EFFECTS_NAME	__INTERNAL_NAME(do_side_effects)
#endif

#if !defined(DPML_GET_ENVIRONMENT_NAME)
#   define  DPML_GET_ENVIRONMENT_NAME	__INTERNAL_NAME(get_environment)
#endif

#if !defined(DPML_SIGNAL_NAME)
#   define  DPML_SIGNAL_NAME		__INTERNAL_NAME(signal)
#endif

#define GLOBAL_TABLE_VALUES
#include "dpml_private.h"
#include "dpml_error_codes.h"

/*
 * Include platform specific headers.  Anything not defined in them will
 * be defaulted below.
 */

#if defined(PLATFORM_SPECIFIC_HEADER_FILE)
#   include PLATFORM_SPECIFIC_HEADER_FILE
#endif

/*
 * The follow macros and code are used to to define the default exception
 * model.  If no exception definitions were made in the above files then
 * the default behavior will be determined by whether or not IEEE floating
 * point is defined.
 *
 * If IEEE floating point is defined, the exception handler assumes the
 * existance of a control register and a set of routines to read and write
 * it.  Otherwise the default behavior is defined to signal all exceptions
 * except underflow which is flushed to zero.  The default exception behaviors
 * do not allow for the mixing of IEEE behavior and non-IEEE.  I.e. by default
 * you get one or the other.
 *
 *
 *
 * If IEEE exception behavior make sure things that are supposed to be
 * defined, are defined
 */

#if IEEE_EXCEPTION_BEHAVIOR
#   if !defined(DPML_GET_FPCSR)
#       error "DPML_GET_FPCSR must be defined for IEEE exception behavior"
#   endif
#   if !defined(DPML_SET_FPCSR)
#       error "DPML_SET_FPCSR must be defined for IEEE exception behavior"
#   endif

    /*
     * The data type of the FPCSR needs to be known.  If not specified,
     * assume it has the same type as the basic integer type on the platform.
     */

#   if !defined(FP_CSR_TYPE)
#       define FP_CSR_TYPE	WORD
#   endif

    /*
     * We need to be able to map the five basic DPML exceptions onto the bit
     * positions of the sticky bits in the FPCSR.  If no mapping function is
     * provided assume that the DPML exception enumerations match the bit
     * positions of the sticky bits in the FPCSR
     */

#   if !defined(DPML_FPCSR_STICKY_BITS)
#       define DPML_FPCSR_STICKY_BITS(d)	SET_BIT(d)
#   endif

#endif


/*
 * If no user exception environment is defined, read the enviornment from
 * the exception enable in the FPCSR for the IEEE case and just set to
 * signal everything except underflow otherwise.
 */

#if !defined(DPML_GET_ENVIRONMENT)

#   if IEEE_EXCEPTION_BEHAVIOR
#       define DPML_GET_ENVIRONMENT(e) \
			P_EXCPT_REC_ENVIRONMENT(p, DPML_GET_FPCSR(e))
#   else
#       define DPML_GET_ENVIRONMENT(e) \
			P_EXCPT_REC_ENVIRONMENT(p, ( ENABLE_FLUSH_TO_ZERO \
						   | ENABLE_SINGULARITY \
						   | ENABLE_OVERFLOW \
						   | ENABLE_INVALID \
						   | ENABLE_LOST_SIGNIFICANCE ))
#   endif
#endif

/*
 * If no user supplied signal mechanism, use the ANSI C raise() to generate
 * signal
 */

extern int raise(int);
#if !defined(DPML_SIGNAL) && !defined(MINIMAL_SILENT_MODE_EXCEPTION_HANDLER) && \
    !defined(wnt)

#   include <sys/signal.h>
#   define DPML_SIGNAL(p)	 raise(SIGFPE)

#else

#   define DPML_SIGNAL(p)

#endif


/*
 * If no side effects are specified then set errno, signal if the envirnment
 * indicates a signal and for the IEEE case update the sticky bits
 */

#if !defined(SET_ERRNO)

#   include  <errno.h>
#   define SET_ERRNO(p)	errno = ERRNO_VALUE(G_EXCPT_REC_DPML_ECODE(p))

#endif

#if defined(IEEE_EXCEPTION_BEHAVIOR)
#   if  !defined(DPML_UPDATE_STICKY_BITS)

#       define DPML_UPDATE_STICKY_BITS(p)	\
		    { \
		    FP_CSR_TYPE fpcsr; \
		    DPML_GET_FPCSR(fpcsr); \
		    fpcsr |= FPCSR_STICKY_BITS(G_EXCPT_REC_DPML_ECODE(p)); \
		    DPML_SET_FPCSR(fpcsr); \
		    }
#   endif
#else
#    define DPML_UPDATE_STICKY_BITS(p)
#endif

#if !defined(DPML_DO_SIDE_EFFECTS)

#   define DPML_DO_SIDE_EFFECTS(p)	DPML_DO_SIDE_EFFECTS_NAME(p)

    static void
    DPML_DO_SIDE_EFFECTS_NAME(DPML_EXCEPTION_RECORD *p)
        {
        SET_ERRNO(p);

#     if !defined (MINIMAL_SILENT_MODE_EXCEPTION_HANDLER)

        /* set ieee sticky bit before signaling exception */
        DPML_UPDATE_STICKY_BITS(p);

        if (G_EXCPT_REC_ENVIRONMENT(p) & SET_BIT(G_EXCPT_REC_DPML_ECODE(p)))
            DPML_SIGNAL(p);
#     endif

        }

#endif /* !defined(DPML_DO_SIDE_EFFECTS) */

#define RET_VAL(type,val)      GLOBAL_ADDR(type,val)


#if !defined(GET_DPML_EXCEPTION_AND_VALUE)

	/*
	 * NOTE: This should be fixed.  The response table should
	 * have only one set of (err,value) pairs if only one
	 * behavior is supportted.
	 */

#   if IEEE_EXCEPTION_BEHAVIOR

#       define	GET_DPML_EXCEPTION_AND_VALUE(p) \
			{ \
			WORD e, v, t; \
			e = G_EXCPT_REC_FUNC_ECODE(p); \
			P_EXCPT_REC_DPML_ECODE(p, GET_IEEE_ERROR(e)); \
			v = GET_IEEE_VALUE(e); \
			t = G_EXCPT_REC_DATA_TYPE(p); \
			P_EXCPT_REC_RET_VAL_PTR(p, RET_VAL(t,v)); \
			}
#   else

#       define	GET_DPML_EXCEPTION_AND_VALUE(p) \
			{ \
			WORD e, v, t; \
			e = G_EXCPT_REC_FUNC_ECODE(p); \
			P_EXCPT_REC_DPML_ECODE(p, GET_FAST_ERROR(e)); \
			v = GET_FAST_VALUE(e); \
			t = G_EXCPT_REC_DATA_TYPE(p); \
			P_EXCPT_REC_RET_VAL_PTR(p, RET_VAL(t,v)); \
			}
#   endif

#endif

#if (EXCEPTION_INTERFACE_RECEIVE == receive_exception_record)
#   define EXCPTN_ARG	DPML_EXCEPTION_RECORD *p
#   define DECLARATIONS	WORD err = G_EXCPT_REC_FUNC_ECODE(p)
#else
#   define EXCPTN_ARG	WORD err
#   define DECLARATIONS	DPML_EXCEPTION_RECORD __tmp, *p = &__tmp;
#endif

#if !defined(DPML_EXCEPTION)

    void * DPML_EXCEPTION_NAME(EXCPTN_ARG)
        {
        DECLARATIONS;

        /* Split input error code into type, and base error */
        P_EXCPT_REC_DATA_TYPE(p, GET_ERR_CODE_TYPE(err));
        P_EXCPT_REC_FUNC_ECODE(p, GET_TYPELESS_ERR_CODE(err));

        DPML_GET_ENVIRONMENT(p);
        if (err < 0)
            /* Just a request for info */
            return (void *) G_EXCPT_REC_ENVIRONMENT(p);

        GET_DPML_EXCEPTION_AND_VALUE(p);

        if (G_EXCPT_REC_DPML_ECODE(p) != DPML_NO_ERROR)
            DPML_DO_SIDE_EFFECTS(p);

        return G_EXCPT_REC_RET_VAL_PTR(p);
        }

#endif