Alien-LibJIT

 view release on metacpan or  search on metacpan

libjit/jit/jit-intrinsic.c  view on Meta::CPAN

 * <http://www.gnu.org/licenses/>.
 */

#include "jit-internal.h"
#if defined(HAVE_TGMATH_H) && !defined(JIT_NFLOAT_IS_DOUBLE)
	#include <tgmath.h>
#elif defined(HAVE_MATH_H)
	#include <math.h>
#endif
#ifdef JIT_WIN32_NATIVE
#include <float.h>
#if !defined(isnan)
#define isnan(value)	_isnan((value))
#endif
#if !defined(isfinite)
#define isfinite(value)	_finite((value))
#endif
#ifndef HAVE_ISNAN
#define HAVE_ISNAN 1
#endif
#undef	HAVE_ISNANF
#undef	HAVE_ISNANL
#else
#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
#endif
#endif

/*@

@cindex jit-intrinsic.h

Intrinsics are functions that are provided to ease code generation
on platforms that may not be able to perform all operations natively.

For example, on a CPU without a floating-point unit, the back end code
generator will output a call to an intrinsic function when a floating-point
operation is performed.  CPU's with a floating-point unit would use
a native instruction instead.

Some platforms may already have appropriate intrinsics (e.g. the ARM
floating-point emulation routines).  The back end code generator may choose
to use either the system-supplied intrinsics or the ones supplied by
this library.  We supply all of them in our library just in case a
particular platform lacks an appropriate intrinsic.

Some intrinsics have no equivalent in existing system libraries;
particularly those that deal with overflow checking.

Functions that perform overflow checking or which divide integer operands
return a built-in exception code to indicate the type of exception
to be thrown (the caller is responsible for throwing the actual
exception).  @xref{Exceptions}, for a list of built-in exception codes.

The following functions are defined in @code{<jit/jit-intrinsic.h>}:

@*/

/*
 * Special values that indicate "not a number" for floating-point types.
 * Visual C++ won't let us compute NaN's at compile time, so we have to
 * work around it with a run-time hack.
 */
#if defined(_MSC_VER) && defined(_M_IX86)
static unsigned int const float32_nan = 0x7FC00000;
static unsigned __int64 const float64_nan = 0x7FF8000000000000LL;
#define	jit_float32_nan	(*((jit_float32 *)&float32_nan))
#define	jit_float64_nan	(*((jit_float64 *)&float64_nan))
#define	jit_nfloat_nan	((jit_nfloat)(*((jit_float64 *)&float64_nan)))
#else
#define	jit_float32_nan	((jit_float32)(0.0 / 0.0))
#define	jit_float64_nan	((jit_float64)(0.0 / 0.0))
#define	jit_nfloat_nan	((jit_nfloat)(0.0 / 0.0))
#endif

/*@
 * @deftypefun jit_int jit_int_add (jit_int @var{value1}, jit_int @var{value2})
 * @deftypefunx jit_int jit_int_sub (jit_int @var{value1}, jit_int @var{value2})
 * @deftypefunx jit_int jit_int_mul (jit_int @var{value1}, jit_int @var{value2})
 * @deftypefunx jit_int jit_int_neg (jit_int @var{value1})
 * @deftypefunx jit_int jit_int_and (jit_int @var{value1}, jit_int @var{value2})
 * @deftypefunx jit_int jit_int_or (jit_int @var{value1}, jit_int @var{value2})
 * @deftypefunx jit_int jit_int_xor (jit_int @var{value1}, jit_int @var{value2})
 * @deftypefunx jit_int jit_int_not (jit_int @var{value1})
 * @deftypefunx jit_int jit_int_not (jit_int @var{value1})
 * @deftypefunx jit_int jit_int_shl (jit_int @var{value1}, jit_uint @var{value2})
 * @deftypefunx jit_int jit_int_shr (jit_int @var{value1}, jit_uint @var{value2})
 * Perform an arithmetic operation on signed 32-bit integers.
 * @end deftypefun
 *
 * @deftypefun jit_int jit_int_add_ovf (jit_int *@var{result}, jit_int @var{value1}, jit_int @var{value2})
 * @deftypefunx jit_int jit_int_sub_ovf (jit_int *@var{result}, jit_int @var{value1}, jit_int @var{value2})
 * @deftypefunx jit_int jit_int_mul_ovf (jit_int *@var{result}, jit_int @var{value1}, jit_int @var{value2})
 * Perform an arithmetic operation on two signed 32-bit integers,
 * with overflow checking.  Returns @code{JIT_RESULT_OK}
 * or @code{JIT_RESULT_OVERFLOW}.
 * @end deftypefun
 *
 * @deftypefun jit_int jit_int_div_ovf (jit_int *@var{result}, jit_int @var{value1}, jit_int @var{value2})
 * @deftypefunx jit_int jit_int_rem_ovf (jit_int *@var{result}, jit_int @var{value1}, jit_int @var{value2})
 * Perform a division or remainder operation on two signed 32-bit integers.
 * Returns @code{JIT_RESULT_OK}, @code{JIT_RESULT_DIVISION_BY_ZERO},
 * or @code{JIT_RESULT_ARITHMETIC}.
 * @end deftypefun
 *
 * @deftypefun jit_int jit_int_eq (jit_int @var{value1}, jit_int @var{value2})
 * @deftypefunx jit_int jit_int_ne (jit_int @var{value1}, jit_int @var{value2})
 * @deftypefunx jit_int jit_int_lt (jit_int @var{value1}, jit_int @var{value2})
 * @deftypefunx jit_int jit_int_le (jit_int @var{value1}, jit_int @var{value2})
 * @deftypefunx jit_int jit_int_gt (jit_int @var{value1}, jit_int @var{value2})
 * @deftypefunx jit_int jit_int_ge (jit_int @var{value1}, jit_int @var{value2})
 * Compare two signed 32-bit integers, returning 0 or 1 based
 * on their relationship.
 * @end deftypefun
 *
 * @deftypefun jit_int jit_int_cmp (jit_int @var{value1}, jit_int @var{value2})
 * Compare two signed 32-bit integers and return -1, 0, or 1 based
 * on their relationship.
 * @end deftypefun
 *
 * @deftypefun jit_int jit_int_abs (jit_int @var{value1})



( run in 0.571 second using v1.01-cache-2.11-cpan-97f6503c9c8 )