mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-01-15 13:52:16 -08:00
In OS X, inline fetestexcept() and feclearexcept().
This commit is contained in:
parent
c0f3320961
commit
7838cb5897
2 changed files with 73 additions and 0 deletions
|
|
@ -13,6 +13,11 @@
|
|||
See file '../Copyright' for full details.
|
||||
*/
|
||||
|
||||
#ifndef ECL_MATH_DISPATCH_H
|
||||
#define ECL_MATH_DISPATCH_H
|
||||
|
||||
#include <ecl/impl/math_fenv.h>
|
||||
|
||||
typedef cl_object (*math_one_arg_fn)(cl_object);
|
||||
|
||||
#ifdef ECL_LONG_FLOAT
|
||||
|
|
@ -41,3 +46,23 @@ typedef cl_object (*math_one_arg_fn)(cl_object);
|
|||
ECL_MATHERR_TEST; \
|
||||
return arg; \
|
||||
}
|
||||
#define MATH_DEF_DISPATCH1_NE(name,id,type,rational,single_float,double_float,long_float,complex) \
|
||||
static cl_object name##failed(cl_object x) { \
|
||||
FEwrong_type_only_arg(id, x, type); \
|
||||
} \
|
||||
static const math_one_arg_fn name##dispatch[t_complex+1]= { \
|
||||
name##failed, /* t_start */ \
|
||||
name##failed, /* t_list */ \
|
||||
name##failed, /* t_character */ \
|
||||
rational, rational, rational, /* t_fixnum, bignum, ratio */ \
|
||||
single_float, double_float, /* t_singlefloat, t_doublefloat */ \
|
||||
MATH_LONG_DOUBLE(long_float) /* t_longfloat, optional */ \
|
||||
complex }; \
|
||||
cl_object ecl_##name(cl_object arg) \
|
||||
{ \
|
||||
int t = type_of(arg); \
|
||||
if (t > t_complex) name##failed(arg); \
|
||||
arg = name##dispatch[t](arg); \
|
||||
return arg; \
|
||||
}
|
||||
#endif /* ECL_MATH_DISPATCH_H */
|
||||
|
|
|
|||
48
src/h/impl/math_fenv.h
Normal file
48
src/h/impl/math_fenv.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/* -*- mode: c; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
math_fenv.h -- inlined versions of fenv.h
|
||||
*/
|
||||
/*
|
||||
Copyright (c) 2010, Juan Jose Garcia Ripoll.
|
||||
|
||||
ECL is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
See file '../Copyright' for full details.
|
||||
*/
|
||||
|
||||
#if !defined(ECL_MATH_FENV_H) && defined(HAVE_FENV_H)
|
||||
#define ECL_MATH_FENV_H
|
||||
|
||||
#if defined(__APPLE__) && defined(__amd64__)
|
||||
#define feclearexcept myfeclearexcept
|
||||
static inline void myfeclearexcept(int flags)
|
||||
{
|
||||
int aux;
|
||||
int f = ~(0x3d);
|
||||
__asm__ (
|
||||
"fnclex \n\t"
|
||||
"stmxcsr %0\n\t"
|
||||
"andl %1,%0\n\t"
|
||||
"ldmxcsr %0\n\t"
|
||||
: "=m"(aux) : "a"(f));
|
||||
}
|
||||
#define fetestexcept myfetestexcept
|
||||
static inline int myfetestexcept(cl_fixnum flags)
|
||||
{
|
||||
cl_fixnum output = (flags & 0x3d);
|
||||
int sw;
|
||||
__asm__ (
|
||||
"fnstsw %0\n\t"
|
||||
"movzwl %0,%%eax\n\t"
|
||||
"stmxcsr %0\n\t"
|
||||
"orl %0,%%eax\n\t"
|
||||
"and %%rax,%1\n\t"
|
||||
: "=m"(sw), "=d"(output) : "d"(output) : "%rax");
|
||||
return output;
|
||||
}
|
||||
#endif /* __APPLE__ && __amd64__ */
|
||||
|
||||
#endif /* !ECL_MATH_FENV_H && HAVE_FENV_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue