#include <math.h>
-static void*
+#include "jit-icalls.h"
+
+void*
mono_ldftn (MonoMethod *method)
{
gpointer addr;
addr = mono_create_jump_trampoline (mono_domain_get (), method, TRUE);
- return addr;
+ return mono_create_ftnptr (mono_domain_get (), addr);
}
/*
* Same as mono_ldftn, but do not add a synchronized wrapper. Used in the
* synchronized wrappers to avoid infinite recursion.
*/
-static void*
+void*
mono_ldftn_nosync (MonoMethod *method)
{
gpointer addr;
addr = mono_create_jump_trampoline (mono_domain_get (), method, FALSE);
- return addr;
+ return mono_create_ftnptr (mono_domain_get (), addr);
}
-static void*
+void*
mono_ldvirtfn (MonoObject *obj, MonoMethod *method)
{
MONO_ARCH_SAVE_REGS;
+ if (obj == NULL)
+ mono_raise_exception (mono_get_exception_null_reference ());
+
method = mono_object_get_virtual_method (obj, method);
return mono_ldftn (method);
}
-static void
-helper_initobj (void *addr, int size)
-{
- MONO_ARCH_SAVE_REGS;
-
- memset (addr, 0, size);
-}
-
-static void
-helper_memcpy (void *addr, void *src, int size)
-{
- MONO_ARCH_SAVE_REGS;
-
- memcpy (addr, src, size);
-}
-
-static void
-helper_memset (void *addr, int val, int size)
-{
- MONO_ARCH_SAVE_REGS;
-
- memset (addr, val, size);
-}
-
-static void
-helper_stelem_ref (MonoArray *array, int index, MonoObject *val)
+void
+mono_helper_stelem_ref (MonoArray *array, int index, MonoObject *val)
{
MONO_ARCH_SAVE_REGS;
mono_array_set (array, gpointer, index, val);
}
-static void
-helper_stelem_ref_check (MonoArray *array, MonoObject *val)
+void
+mono_helper_stelem_ref_check (MonoArray *array, MonoObject *val)
{
MONO_ARCH_SAVE_REGS;
mono_raise_exception (mono_get_exception_array_type_mismatch ());
}
-static gint64
+#ifndef MONO_ARCH_NO_EMULATE_LONG_MUL_OPTS
+
+gint64
mono_llmult (gint64 a, gint64 b)
{
/* no need, no exceptions: MONO_ARCH_SAVE_REGS;*/
return a * b;
}
-static guint64
+guint64
mono_llmult_ovf_un (guint64 a, guint64 b)
{
guint32 al = a;
return 0;
}
-
-static guint64
+guint64
mono_llmult_ovf (gint64 a, gint64 b)
{
guint32 al = a;
*/
sign = ah ^ bh;
if (ah < 0) {
+ if (((guint32)ah == 0x80000000) && (al == 0)) {
+ /* This has no two's complement */
+ if (b == 0)
+ return 0;
+ else if (b == 1)
+ return a;
+ else
+ goto raise_exception;
+ }
+
/* flip the bits and add 1 */
ah ^= ~0;
if (al == 0)
}
if (bh < 0) {
+ if (((guint32)bh == 0x80000000) && (bl == 0)) {
+ /* This has no two's complement */
+ if (a == 0)
+ return 0;
+ else if (a == 1)
+ return b;
+ else
+ goto raise_exception;
+ }
+
/* flip the bits and add 1 */
bh ^= ~0;
if (bl == 0)
in a 64 bit result */
if (ah && bh)
goto raise_exception;
+ if ((gint64)((gint64)ah * (gint64)bl) > (gint64)0x80000000 || (gint64)((gint64)al * (gint64)bh) > (gint64)0x80000000)
+ goto raise_exception;
/* do the AlBl term first */
t1 = (gint64)al * (gint64)bl;
/* now do the [(Ah-Al)(Bl-Bh)+AlBl]R term */
t1 += (gint64)(ah - al) * (gint64)(bl - bh);
- t1 <<= 32;
/* check for overflow */
+ t1 <<= 32;
if (t1 > (0x7FFFFFFFFFFFFFFFLL - res))
goto raise_exception;
return 0;
}
-static gint64
+#if defined(MONO_ARCH_EMULATE_MUL_DIV) || defined(MONO_ARCH_EMULATE_DIV)
+
+gint32
+mono_idiv (gint32 a, gint32 b)
+{
+ MONO_ARCH_SAVE_REGS;
+
+#ifdef MONO_ARCH_NEED_DIV_CHECK
+ if (!b)
+ mono_raise_exception (mono_get_exception_divide_by_zero ());
+ else if (b == -1 && a == (0x80000000))
+ mono_raise_exception (mono_get_exception_arithmetic ());
+#endif
+ return a / b;
+}
+
+guint32
+mono_idiv_un (guint32 a, guint32 b)
+{
+ MONO_ARCH_SAVE_REGS;
+
+#ifdef MONO_ARCH_NEED_DIV_CHECK
+ if (!b)
+ mono_raise_exception (mono_get_exception_divide_by_zero ());
+#endif
+ return a / b;
+}
+
+gint32
+mono_irem (gint32 a, gint32 b)
+{
+ MONO_ARCH_SAVE_REGS;
+
+#ifdef MONO_ARCH_NEED_DIV_CHECK
+ if (!b)
+ mono_raise_exception (mono_get_exception_divide_by_zero ());
+ else if (b == -1 && a == (0x80000000))
+ mono_raise_exception (mono_get_exception_arithmetic ());
+#endif
+
+ return a % b;
+}
+
+guint32
+mono_irem_un (guint32 a, guint32 b)
+{
+ MONO_ARCH_SAVE_REGS;
+
+#ifdef MONO_ARCH_NEED_DIV_CHECK
+ if (!b)
+ mono_raise_exception (mono_get_exception_divide_by_zero ());
+#endif
+ return a % b;
+}
+
+#endif
+
+#ifdef MONO_ARCH_EMULATE_MUL_DIV
+
+gint32
+mono_imul (gint32 a, gint32 b)
+{
+ MONO_ARCH_SAVE_REGS;
+
+ return a * b;
+}
+
+gint32
+mono_imul_ovf (gint32 a, gint32 b)
+{
+ gint64 res;
+
+ MONO_ARCH_SAVE_REGS;
+
+ res = (gint64)a * (gint64)b;
+
+ if ((res > 0x7fffffffL) || (res < -2147483648))
+ mono_raise_exception (mono_get_exception_overflow ());
+
+ return res;
+}
+
+gint32
+mono_imul_ovf_un (guint32 a, guint32 b)
+{
+ guint64 res;
+
+ MONO_ARCH_SAVE_REGS;
+
+ res = (guint64)a * (guint64)b;
+
+ if ((res >> 32))
+ mono_raise_exception (mono_get_exception_overflow ());
+
+ return res;
+}
+
+double
+mono_fdiv (double a, double b)
+{
+ MONO_ARCH_SAVE_REGS;
+
+ return a / b;
+}
+#endif
+
+gint64
mono_lldiv (gint64 a, gint64 b)
{
MONO_ARCH_SAVE_REGS;
+#ifdef MONO_ARCH_NEED_DIV_CHECK
+ if (!b)
+ mono_raise_exception (mono_get_exception_divide_by_zero ());
+ else if (b == -1 && a == (-9223372036854775807LL - 1LL))
+ mono_raise_exception (mono_get_exception_arithmetic ());
+#endif
return a / b;
}
-static gint64
+gint64
mono_llrem (gint64 a, gint64 b)
{
MONO_ARCH_SAVE_REGS;
+#ifdef MONO_ARCH_NEED_DIV_CHECK
+ if (!b)
+ mono_raise_exception (mono_get_exception_divide_by_zero ());
+ else if (b == -1 && a == (-9223372036854775807LL - 1LL))
+ mono_raise_exception (mono_get_exception_arithmetic ());
+#endif
return a % b;
}
-static guint64
+guint64
mono_lldiv_un (guint64 a, guint64 b)
{
MONO_ARCH_SAVE_REGS;
+#ifdef MONO_ARCH_NEED_DIV_CHECK
+ if (!b)
+ mono_raise_exception (mono_get_exception_divide_by_zero ());
+#endif
return a / b;
}
-static guint64
+guint64
mono_llrem_un (guint64 a, guint64 b)
{
MONO_ARCH_SAVE_REGS;
+#ifdef MONO_ARCH_NEED_DIV_CHECK
+ if (!b)
+ mono_raise_exception (mono_get_exception_divide_by_zero ());
+#endif
return a % b;
}
-static guint64
+#endif
+
+#ifndef MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS
+
+guint64
mono_lshl (guint64 a, gint32 shamt)
{
guint64 res;
return res;
}
-static guint64
+guint64
mono_lshr_un (guint64 a, gint32 shamt)
{
guint64 res;
return res;
}
-static gint64
+gint64
mono_lshr (gint64 a, gint32 shamt)
{
gint64 res;
return res;
}
+#endif
+
/**
* ves_array_element_address:
* @this: a pointer to the array object
*
* Returns: the address of an array element.
*/
-static gpointer
+gpointer
ves_array_element_address (MonoArray *this, ...)
{
MonoClass *class;
}
esize *= ind;
- ea = (gpointer*)((char*)this->vector + esize);
+ ea = (gpointer*)(gpointer)((char*)this->vector + esize);
va_end(ap);
return ea;
}
-static MonoArray *
+MonoArray *
mono_array_new_va (MonoMethod *cm, ...)
{
MonoDomain *domain = mono_domain_get ();
MONO_ARCH_SAVE_REGS;
- pcount = cm->signature->param_count;
+ pcount = mono_method_signature (cm)->param_count;
rank = cm->klass->rank;
va_start (ap, cm);
if (rank == pcount) {
/* Only lengths provided. */
- lower_bounds = NULL;
+ if (cm->klass->byval_arg.type == MONO_TYPE_ARRAY) {
+ lower_bounds = alloca (sizeof (guint32) * rank);
+ memset (lower_bounds, 0, sizeof (guint32) * rank);
+ } else {
+ lower_bounds = NULL;
+ }
} else {
g_assert (pcount == (rank * 2));
/* lower bounds are first. */
return mono_array_new_full (domain, cm->klass, lengths, lower_bounds);
}
-static gpointer
+gpointer
mono_class_static_field_address (MonoDomain *domain, MonoClassField *field)
{
MonoVTable *vtable;
return addr;
}
-static gpointer
-mono_ldtoken_wrapper (MonoImage *image, int token)
+gpointer
+mono_ldtoken_wrapper (MonoImage *image, int token, MonoGenericContext *context)
{
MonoClass *handle_class;
gpointer res;
MONO_ARCH_SAVE_REGS;
- res = mono_ldtoken (image, token, &handle_class);
+ res = mono_ldtoken (image, token, &handle_class, context);
mono_class_init (handle_class);
return res;
}
-static guint64
+guint64
mono_fconv_u8 (double v)
{
- /* no need, no exceptions: MONO_ARCH_SAVE_REGS;*/
return (guint64)v;
}
#ifdef MONO_ARCH_EMULATE_FCONV_TO_I8
-static gint64
+gint64
mono_fconv_i8 (double v)
{
/* no need, no exceptions: MONO_ARCH_SAVE_REGS;*/
}
#endif
-static guint32
+guint32
mono_fconv_u4 (double v)
{
/* no need, no exceptions: MONO_ARCH_SAVE_REGS;*/
return (guint32)v;
}
-#ifndef HAVE_TRUNCL
-/* should mostly work */
-static double
-truncl (double x)
-{
- if (x < 0)
- x += 1.0;
- return floor (x);
-}
-
+#ifndef HAVE_TRUNC
+/* Solaris doesn't have trunc */
+#ifdef HAVE_AINTL
+extern long double aintl (long double);
+#define trunc aintl
+#else
+/* FIXME: This means we will never throw overflow exceptions */
+#define trunc(v) res
#endif
+#endif /* HAVE_TRUNC */
-static gint64
+gint64
mono_fconv_ovf_i8 (double v)
{
gint64 res;
res = (gint64)v;
- if (isnan(v) || truncl (v) != res) {
+ if (isnan(v) || trunc (v) != res) {
mono_raise_exception (mono_get_exception_overflow ());
}
return res;
}
-static guint64
+guint64
mono_fconv_ovf_u8 (double v)
{
guint64 res;
res = (guint64)v;
- if (isnan(v) || truncl (v) != res) {
+ if (isnan(v) || trunc (v) != res) {
mono_raise_exception (mono_get_exception_overflow ());
}
return res;
}
#ifdef MONO_ARCH_EMULATE_LCONV_TO_R8
-static double
+double
mono_lconv_to_r8 (gint64 a)
{
return (double)a;
#endif
#ifdef MONO_ARCH_EMULATE_LCONV_TO_R4
-static float
+float
mono_lconv_to_r4 (gint64 a)
{
return (float)a;
}
#endif
+#ifdef MONO_ARCH_EMULATE_CONV_R8_UN
+double
+mono_conv_to_r8_un (guint32 a)
+{
+ return (double)a;
+}
+#endif
+
#ifdef MONO_ARCH_EMULATE_LCONV_TO_R8_UN
-static double
+double
mono_lconv_to_r8_un (guint64 a)
{
return (double)a;
}
#endif
+gpointer
+mono_helper_compile_generic_method (MonoObject *obj, MonoMethod *method, MonoGenericContext *context)
+{
+ MonoMethod *vmethod, *inflated;
+ gpointer addr;
+
+ if (obj == NULL)
+ mono_raise_exception (mono_get_exception_null_reference ());
+ vmethod = mono_object_get_virtual_method (obj, method);
+
+ /* 'vmethod' is partially inflated. All the blanks corresponding to the type parameters of the
+ declaring class have been inflated. We still need to fully inflate the method parameters.
+
+ FIXME: This code depends on the declaring class being fully inflated, since we inflate it twice with
+ the same context.
+ */
+ g_assert (!vmethod->klass->generic_container);
+ g_assert (!vmethod->klass->generic_class || !vmethod->klass->generic_class->inst->is_open);
+ g_assert (!context->gmethod || !context->gmethod->inst->is_open);
+ inflated = mono_class_inflate_generic_method (vmethod, context);
+ inflated = mono_get_inflated_method (inflated);
+ addr = mono_compile_method (inflated);
+
+ return addr;
+}
+
+MonoString*
+mono_helper_ldstr (MonoImage *image, guint32 idx)
+{
+ return mono_ldstr (mono_domain_get (), image, idx);
+}
+
+MonoString*
+mono_helper_ldstr_mscorlib (guint32 idx)
+{
+ return mono_ldstr (mono_domain_get (), mono_defaults.corlib, idx);
+}
+
+MonoObject*
+mono_helper_newobj_mscorlib (guint32 idx)
+{
+ MonoClass *klass = mono_class_get (mono_defaults.corlib, MONO_TOKEN_TYPE_DEF | idx);
+
+ g_assert (klass);
+
+ return mono_object_new (mono_domain_get (), klass);
+}