160
158
#endif /* HAVE_GETHRTIME */
162
#ifdef HAVE_GETHRVTIME
163
# define sys_gethrvtime() gethrvtime()
160
#if (defined(HAVE_GETHRVTIME) || defined(HAVE_CLOCK_GETTIME))
161
typedef long long SysCpuTime;
162
typedef struct timespec SysTimespec;
164
#if defined(HAVE_GETHRVTIME)
165
#define sys_gethrvtime() gethrvtime()
166
#define sys_get_proc_cputime(t,tp) (t) = sys_gethrvtime(), \
167
(tp).tv_sec = (time_t)((t)/1000000000LL), \
168
(tp).tv_nsec = (long)((t)%1000000000LL)
164
169
int sys_start_hrvtime(void);
165
170
int sys_stop_hrvtime(void);
166
#endif /* HAVE_GETHRVTIME */
172
#elif defined(HAVE_CLOCK_GETTIME)
173
#define sys_clock_gettime(cid,tp) clock_gettime((cid),&(tp))
174
#define sys_get_proc_cputime(t,tp) sys_clock_gettime(CLOCK_PROCESS_CPUTIME_ID,(tp))
168
179
/* No use in having other resolutions than 1 Ms. */
169
180
#define SYS_CLOCK_RESOLUTION 1
184
195
* Handling of floating point exceptions.
187
extern volatile int erl_fp_exception;
189
198
#ifdef USE_ISINF_ISNAN /* simulate finite() */
190
199
# define finite(f) (!isinf(f) && !isnan(f))
191
200
# define HAVE_FINITE
194
203
#ifdef NO_FPE_SIGNALS
195
# define ERTS_FP_CHECK_INIT() do {} while (0)
196
# define ERTS_FP_ERROR(f, Action) if (!finite(f)) { Action; } else {}
197
# define ERTS_SAVE_FP_EXCEPTION()
198
# define ERTS_RESTORE_FP_EXCEPTION()
200
# define ERTS_FP_CHECK_INIT() do {erl_fp_exception = 0;} while (0)
201
# if defined(__i386__) && defined(__GNUC__)
202
extern void erts_restore_x87(void);
203
static __inline__ int erts_check_x87(double f)
204
#define erts_get_current_fp_exception() NULL
206
#define erts_thread_init_fp_exception() do{}while(0)
208
# define __ERTS_FP_CHECK_INIT(fpexnp) do {} while (0)
209
# define __ERTS_FP_ERROR(fpexnp, f, Action) if (!finite(f)) { Action; } else {}
210
# define __ERTS_FP_ERROR_THOROUGH(fpexnp, f, Action) __ERTS_FP_ERROR(fpexnp, f, Action)
211
# define __ERTS_SAVE_FP_EXCEPTION(fpexnp)
212
# define __ERTS_RESTORE_FP_EXCEPTION(fpexnp)
214
#else /* !NO_FPE_SIGNALS */
216
extern volatile int *erts_get_current_fp_exception(void);
218
extern void erts_thread_init_fp_exception(void);
220
# if (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__)
221
# define erts_fwait(fpexnp,f) \
222
__asm__ __volatile__("fwait" : "=m"(*(fpexnp)) : "m"(f))
223
# elif (defined(__powerpc__) || defined(__ppc__)) && defined(__GNUC__)
224
# define erts_fwait(fpexnp,f) \
225
__asm__ __volatile__("" : "=m"(*(fpexnp)) : "fm"(f))
226
# elif defined(__sparc__) && defined(__linux__) && defined(__GNUC__)
227
# define erts_fwait(fpexnp,f) \
228
__asm__ __volatile__("" : "=m"(*(fpexnp)) : "em"(f))
230
# define erts_fwait(fpexnp,f) \
231
__asm__ __volatile__("" : "=m"(*(fpexnp)) : "g"(f))
233
# if (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__)
234
extern void erts_restore_fpu(void);
236
# define erts_restore_fpu() /*empty*/
238
# if (!defined(__GNUC__) || \
240
(__GNUC__ == 2 && __GNUC_MINOR < 96)) && \
241
!defined(__builtin_expect)
242
# define __builtin_expect(x, expected_value) (x)
244
static __inline__ int erts_check_fpe(volatile int *fp_exception, double f)
205
__asm__ __volatile__("fwait" : "=m"(erl_fp_exception) : "m"(f));
206
if( !erl_fp_exception )
246
erts_fwait(fp_exception, f);
247
if (__builtin_expect(!*fp_exception, 1))
211
# define ERTS_FP_ERROR(f, Action) do { if( erts_check_x87((f)) ) { Action; } } while (0)
213
static __inline__ int erts_check_fpe(double f)
253
# undef erts_restore_fpu
254
# define __ERTS_FP_CHECK_INIT(fpexnp) do { *(fpexnp) = 0; } while (0)
255
# define __ERTS_FP_ERROR(fpexnp, f, Action) do { if (erts_check_fpe((fpexnp),(f))) { Action; } } while (0)
256
# define __ERTS_SAVE_FP_EXCEPTION(fpexnp) int old_erl_fp_exception = *(fpexnp)
257
# define __ERTS_RESTORE_FP_EXCEPTION(fpexnp) \
258
do { *(fpexnp) = old_erl_fp_exception; } while (0)
259
/* This is for library calls where we don't trust the external
260
code to always throw floating-point exceptions on errors. */
261
static __inline__ int erts_check_fpe_thorough(volatile int *fp_exception, double f)
215
__asm__ __volatile__("" : "=m"(erl_fp_exception) : "g"(f));
216
return erl_fp_exception;
263
return erts_check_fpe(fp_exception, f) || !finite(f);
218
# define ERTS_FP_ERROR(f, Action) do { if( erts_check_fpe((f)) ) { Action; } } while (0)
220
# define ERTS_SAVE_FP_EXCEPTION() int old_erl_fp_exception = erl_fp_exception
221
# define ERTS_RESTORE_FP_EXCEPTION() \
222
do {erl_fp_exception = old_erl_fp_exception;} while (0)
265
# define __ERTS_FP_ERROR_THOROUGH(fpexnp, f, Action) \
266
do { if (erts_check_fpe_thorough((fpexnp),(f))) { Action; } } while (0)
268
#endif /* !NO_FPE_SIGNALS */
270
#define ERTS_FP_CHECK_INIT(p) __ERTS_FP_CHECK_INIT(&(p)->fp_exception)
271
#define ERTS_FP_ERROR(p, f, A) __ERTS_FP_ERROR(&(p)->fp_exception, f, A)
272
#define ERTS_FP_ERROR_THOROUGH(p, f, A) __ERTS_FP_ERROR_THOROUGH(&(p)->fp_exception, f, A)
226
275
#ifdef NEED_CHILD_SETUP_DEFINES