* Dietmar Maurer (dietmar@ximian.com)
* Patrik Torstensson
* Zoltan Varga (vargaz@gmail.com)
+ * Johan Lorensson (lateralusx.github@gmail.com)
*
* (C) 2003 Ximian, Inc.
* Copyright 2003-2011 Novell, Inc (http://www.novell.com)
#include <mono/utils/mono-mmap.h>
#include <mono/utils/mono-memory-model.h>
#include <mono/utils/mono-tls.h>
-#include <mono/utils/mono-hwcap-x86.h>
+#include <mono/utils/mono-hwcap.h>
#include <mono/utils/mono-threads.h>
#include "trace.h"
return class1;
}
-static int
-count_fields_nested (MonoClass *klass, gboolean pinvoke)
-{
- MonoMarshalType *info;
- int i, count;
-
- count = 0;
- if (pinvoke) {
- info = mono_marshal_load_type_info (klass);
- g_assert(info);
- for (i = 0; i < info->num_fields; ++i) {
- if (MONO_TYPE_ISSTRUCT (info->fields [i].field->type))
- count += count_fields_nested (mono_class_from_mono_type (info->fields [i].field->type), pinvoke);
- else
- count ++;
- }
- } else {
- gpointer iter;
- MonoClassField *field;
-
- iter = NULL;
- while ((field = mono_class_get_fields (klass, &iter))) {
- if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
- continue;
- if (MONO_TYPE_ISSTRUCT (field->type))
- count += count_fields_nested (mono_class_from_mono_type (field->type), pinvoke);
- else
- count ++;
- }
- }
- return count;
-}
-
typedef struct {
MonoType *type;
int size, offset;
*
* Collect field info from KLASS recursively into FIELDS.
*/
-static int
-collect_field_info_nested (MonoClass *klass, StructFieldInfo *fields, int index, int offset, gboolean pinvoke, gboolean unicode)
+static void
+collect_field_info_nested (MonoClass *klass, GArray *fields_array, int offset, gboolean pinvoke, gboolean unicode)
{
MonoMarshalType *info;
int i;
g_assert(info);
for (i = 0; i < info->num_fields; ++i) {
if (MONO_TYPE_ISSTRUCT (info->fields [i].field->type)) {
- index = collect_field_info_nested (mono_class_from_mono_type (info->fields [i].field->type), fields, index, info->fields [i].offset, pinvoke, unicode);
+ collect_field_info_nested (mono_class_from_mono_type (info->fields [i].field->type), fields_array, info->fields [i].offset, pinvoke, unicode);
} else {
guint32 align;
+ StructFieldInfo f;
- fields [index].type = info->fields [i].field->type;
- fields [index].size = mono_marshal_type_size (info->fields [i].field->type,
+ f.type = info->fields [i].field->type;
+ f.size = mono_marshal_type_size (info->fields [i].field->type,
info->fields [i].mspec,
&align, TRUE, unicode);
- fields [index].offset = offset + info->fields [i].offset;
- index ++;
+ f.offset = offset + info->fields [i].offset;
+ if (i == info->num_fields - 1 && f.size + f.offset < info->native_size) {
+ /* This can happen with .pack directives eg. 'fixed' arrays */
+ if (MONO_TYPE_IS_PRIMITIVE (f.type)) {
+ /* Replicate the last field to fill out the remaining place, since the code in add_valuetype () needs type information */
+ g_array_append_val (fields_array, f);
+ while (f.size + f.offset < info->native_size) {
+ f.offset += f.size;
+ g_array_append_val (fields_array, f);
+ }
+ } else {
+ f.size = info->native_size - f.offset;
+ g_array_append_val (fields_array, f);
+ }
+ } else {
+ g_array_append_val (fields_array, f);
+ }
}
}
} else {
if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
continue;
if (MONO_TYPE_ISSTRUCT (field->type)) {
- index = collect_field_info_nested (mono_class_from_mono_type (field->type), fields, index, field->offset - sizeof (MonoObject), pinvoke, unicode);
+ collect_field_info_nested (mono_class_from_mono_type (field->type), fields_array, field->offset - sizeof (MonoObject), pinvoke, unicode);
} else {
int align;
+ StructFieldInfo f;
+
+ f.type = field->type;
+ f.size = mono_type_size (field->type, &align);
+ f.offset = field->offset - sizeof (MonoObject) + offset;
- fields [index].type = field->type;
- fields [index].size = mono_type_size (field->type, &align);
- fields [index].offset = field->offset - sizeof (MonoObject) + offset;
- index ++;
+ g_array_append_val (fields_array, f);
}
}
}
- return index;
}
#ifdef TARGET_WIN32
#define MONO_WIN64_VALUE_TYPE_FITS_REG(arg_size) (arg_size <= SIZEOF_REGISTER && (arg_size == 1 || arg_size == 2 || arg_size == 4 || arg_size == 8))
static gboolean
-allocate_register_for_valuetype_win64 (ArgInfo *arg_info, ArgumentClass arg_class, guint32 arg_size, AMD64_Reg_No int_regs [], int int_reg_count, AMD64_Reg_No float_regs [], int float_reg_count, guint32 *current_int_reg, guint32 *current_float_reg)
+allocate_register_for_valuetype_win64 (ArgInfo *arg_info, ArgumentClass arg_class, guint32 arg_size, AMD64_Reg_No int_regs [], int int_reg_count, AMD64_XMM_Reg_No float_regs [], int float_reg_count, guint32 *current_int_reg, guint32 *current_float_reg)
{
gboolean result = FALSE;
return result;
}
-inline gboolean
+static inline gboolean
allocate_parameter_register_for_valuetype_win64 (ArgInfo *arg_info, ArgumentClass arg_class, guint32 arg_size, guint32 *current_int_reg, guint32 *current_float_reg)
{
return allocate_register_for_valuetype_win64 (arg_info, arg_class, arg_size, param_regs, PARAM_REGS, float_param_regs, FLOAT_PARAM_REGS, current_int_reg, current_float_reg);
}
-inline gboolean
-allocate_return_register_for_valyetype_win64 (ArgInfo *arg_info, ArgumentClass arg_class, guint32 arg_size, guint32 *current_int_reg, guint32 *current_float_reg)
+static inline gboolean
+allocate_return_register_for_valuetype_win64 (ArgInfo *arg_info, ArgumentClass arg_class, guint32 arg_size, guint32 *current_int_reg, guint32 *current_float_reg)
{
return allocate_register_for_valuetype_win64 (arg_info, arg_class, arg_size, return_regs, RETURN_REGS, float_return_regs, FLOAT_RETURN_REGS, current_int_reg, current_float_reg);
}
/* Parameter cases. */
if (arg_class != ARG_CLASS_MEMORY && MONO_WIN64_VALUE_TYPE_FITS_REG (arg_size)) {
-
assert (arg_size == 1 || arg_size == 2 || arg_size == 4 || arg_size == 8);
/* First, try to use registers for parameter. If type is struct it can only be passed by value in integer register. */
arg_info->storage = ArgValuetypeInReg;
if (!allocate_parameter_register_for_valuetype_win64 (arg_info, !MONO_TYPE_ISSTRUCT (type) ? arg_class : ARG_CLASS_INTEGER, arg_size, current_int_reg, current_float_reg)) {
-
/* No more registers, fallback passing parameter on stack as value. */
assert (arg_info->pair_storage [0] == ArgNone && arg_info->pair_storage [1] == ArgNone && arg_info->pair_size [0] == 0 && arg_info->pair_size [1] == 0 && arg_info->nregs == 0);
*stack_size += arg_size;
}
} else {
-
/* Fallback to stack, try to pass address to parameter in register. Always use integer register to represent stack address. */
arg_info->storage = ArgValuetypeAddrInIReg;
if (!allocate_parameter_register_for_valuetype_win64 (arg_info, ARG_CLASS_INTEGER, arg_size, current_int_reg, current_float_reg)) {
-
/* No more registers, fallback passing address to parameter on stack. */
assert (arg_info->pair_storage [0] == ArgNone && arg_info->pair_storage [1] == ArgNone && arg_info->pair_size [0] == 0 && arg_info->pair_size [1] == 0 && arg_info->nregs == 0);
}
}
} else {
-
/* Return value cases. */
if (arg_class != ARG_CLASS_MEMORY && MONO_WIN64_VALUE_TYPE_FITS_REG (arg_size)) {
-
assert (arg_size == 1 || arg_size == 2 || arg_size == 4 || arg_size == 8);
/* Return value fits into return registers. If type is struct it can only be returned by value in integer register. */
arg_info->storage = ArgValuetypeInReg;
- allocate_return_register_for_valyetype_win64 (arg_info, !MONO_TYPE_ISSTRUCT (type) ? arg_class : ARG_CLASS_INTEGER, arg_size, current_int_reg, current_float_reg);
+ allocate_return_register_for_valuetype_win64 (arg_info, !MONO_TYPE_ISSTRUCT (type) ? arg_class : ARG_CLASS_INTEGER, arg_size, current_int_reg, current_float_reg);
- /* Only RAX/XMM0 should be used to return valyetype. */
+ /* Only RAX/XMM0 should be used to return valuetype. */
assert ((arg_info->pair_regs[0] == AMD64_RAX && arg_info->pair_regs[1] == ArgNone) || (arg_info->pair_regs[0] == AMD64_XMM0 && arg_info->pair_regs[1] == ArgNone));
-
} else {
-
/* Return value doesn't fit into return register, return address to allocated stack space (allocated by caller and passed as input). */
arg_info->storage = ArgValuetypeAddrInIReg;
- allocate_return_register_for_valyetype_win64 (arg_info, ARG_CLASS_INTEGER, arg_size, current_int_reg, current_float_reg);
+ allocate_return_register_for_valuetype_win64 (arg_info, ARG_CLASS_INTEGER, arg_size, current_int_reg, current_float_reg);
- /* Only RAX should be used to return valyetype address. */
+ /* Only RAX should be used to return valuetype address. */
assert (arg_info->pair_regs[0] == AMD64_RAX && arg_info->pair_regs[1] == ArgNone);
arg_size = ALIGN_TO (arg_size, sizeof (mgreg_t));
assert (klass != NULL && arg_info != NULL && type != NULL && arg_class != NULL && arg_size != NULL);
- if (pinvoke == TRUE) {
+ if (pinvoke) {
/* Calculate argument class type and size of marshalled type. */
MonoMarshalType *info = mono_marshal_load_type_info (klass);
*arg_size = info->native_size;
/* Calculate argument class type and size of managed type. */
*arg_size = mono_class_value_size (klass, NULL);
}
-
- if (!MONO_WIN64_VALUE_TYPE_FITS_REG (*arg_size)) {
+
+ /* Windows ABI only handle value types on stack or passed in integer register (if it fits register size). */
+ *arg_class = MONO_WIN64_VALUE_TYPE_FITS_REG (*arg_size) ? ARG_CLASS_INTEGER : ARG_CLASS_MEMORY;
+
+ if (*arg_class == ARG_CLASS_MEMORY) {
/* Value type has a size that doesn't seem to fit register according to ABI. Try to used full stack size of type. */
*arg_size = mini_type_stack_size_full (&klass->byval_arg, NULL, pinvoke);
}
- /* Windows ABI only handle value types on stack or passed in integer register (if it fits register size). */
- *arg_class = (*arg_size > SIZEOF_REGISTER) ? ARG_CLASS_MEMORY : ARG_CLASS_INTEGER;
-
/*
* Standard C and C++ doesn't allow empty structs, empty structs will always have a size of 1 byte.
* GCC have an extension to allow empty structs, https://gcc.gnu.org/onlinedocs/gcc/Empty-Structures.html.
if ((arg_size == 0 && !arg_info->pass_empty_struct) || (arg_size == 0 && arg_info->pass_empty_struct && is_return)) {
arg_info->storage = ArgValuetypeInReg;
arg_info->pair_storage [0] = arg_info->pair_storage [1] = ArgNone;
- }
- else
- {
+ } else {
/* Alocate storage for value type. */
allocate_storage_for_valuetype_win64 (arg_info, type, is_return, arg_class, arg_size, current_int_reg, current_float_reg, stack_size);
}
guint32 quadsize [2] = {8, 8};
ArgumentClass args [2];
StructFieldInfo *fields = NULL;
+ GArray *fields_array;
MonoClass *klass;
gboolean pass_on_stack = FALSE;
int struct_size;
* Collect field information recursively to be able to
* handle nested structures.
*/
- nfields = count_fields_nested (klass, sig->pinvoke);
- fields = g_new0 (StructFieldInfo, nfields);
- collect_field_info_nested (klass, fields, 0, 0, sig->pinvoke, klass->unicode);
+ fields_array = g_array_new (FALSE, TRUE, sizeof (StructFieldInfo));
+ collect_field_info_nested (klass, fields_array, 0, sig->pinvoke, klass->unicode);
+ fields = (StructFieldInfo*)fields_array->data;
+ nfields = fields_array->len;
for (i = 0; i < nfields; ++i) {
if ((fields [i].offset < 8) && (fields [i].offset + fields [i].size) > 8) {
if (!is_return)
ainfo->arg_size = ALIGN_TO (size, 8);
- g_free (fields);
+ g_array_free (fields_array, TRUE);
return;
}
if (!is_return)
ainfo->arg_size = ALIGN_TO (struct_size, 8);
- g_free (fields);
+ g_array_free (fields_array, TRUE);
return;
}
}
}
- g_free (fields);
+ g_array_free (fields_array, TRUE);
/* Post merger cleanup */
if ((args [0] == ARG_CLASS_MEMORY) || (args [1] == ARG_CLASS_MEMORY))
mono_aot_register_jit_icall ("mono_amd64_throw_corlib_exception", mono_amd64_throw_corlib_exception);
mono_aot_register_jit_icall ("mono_amd64_resume_unwind", mono_amd64_resume_unwind);
mono_aot_register_jit_icall ("mono_amd64_get_original_ip", mono_amd64_get_original_ip);
+ mono_aot_register_jit_icall ("mono_amd64_handler_block_trampoline_helper", mono_amd64_handler_block_trampoline_helper);
+
#if defined(MONO_ARCH_GSHAREDVT_SUPPORTED)
mono_aot_register_jit_icall ("mono_amd64_start_gsharedvt_call", mono_amd64_start_gsharedvt_call);
#endif
}
#ifdef TARGET_WIN32
+ /* The current SIMD doesn't support the argument used by a LD_ADDR to be of type OP_VTARG_ADDR. */
+ /* This will now be used for value types > 8 or of size 3,5,6,7 as dictated by windows x64 value type ABI. */
+ /* Since OP_VTARG_ADDR needs to be resolved in mono_spill_global_vars and the SIMD implementation optimize */
+ /* away the LD_ADDR in load_simd_vreg, that will cause an error in mono_spill_global_vars since incorrect opcode */
+ /* will now have a reference to an argument that won't be fully decomposed. */
*exclude_mask |= MONO_OPT_SIMD;
#endif
if (cfg->method->save_lmf) {
cfg->lmf_ir = TRUE;
#if !defined(TARGET_WIN32)
- if (mono_get_lmf_tls_offset () != -1 && !optimize_for_xen)
+ if (!optimize_for_xen)
cfg->lmf_ir_mono_lmf = TRUE;
#endif
}
#endif /* DISABLE_JIT */
-#ifdef __APPLE__
+#ifdef TARGET_MACH
static int tls_gs_offset;
#endif
gboolean
-mono_amd64_have_tls_get (void)
+mono_arch_have_fast_tls (void)
{
#ifdef TARGET_MACH
- static gboolean have_tls_get = FALSE;
+ static gboolean have_fast_tls = FALSE;
static gboolean inited = FALSE;
+ guint8 *ins;
+
+ if (mini_get_debug_options ()->use_fallback_tls)
+ return FALSE;
if (inited)
- return have_tls_get;
+ return have_fast_tls;
-#if MONO_HAVE_FAST_TLS
- guint8 *ins = (guint8*)pthread_getspecific;
+ ins = (guint8*)pthread_getspecific;
/*
* We're looking for these two instructions:
* mov %gs:[offset](,%rdi,8),%rax
* retq
*/
- have_tls_get = ins [0] == 0x65 &&
+ have_fast_tls = ins [0] == 0x65 &&
ins [1] == 0x48 &&
ins [2] == 0x8b &&
ins [3] == 0x04 &&
* popq %rbp
* retq
*/
- if (!have_tls_get) {
- have_tls_get = ins [0] == 0x55 &&
+ if (!have_fast_tls) {
+ have_fast_tls = ins [0] == 0x55 &&
ins [1] == 0x48 &&
ins [2] == 0x89 &&
ins [3] == 0xe5 &&
tls_gs_offset = ins[9];
}
-#endif
-
inited = TRUE;
- return have_tls_get;
+ return have_fast_tls;
#elif defined(TARGET_ANDROID)
return FALSE;
#else
+ if (mini_get_debug_options ()->use_fallback_tls)
+ return FALSE;
return TRUE;
#endif
}
*
* Returns: a pointer to the end of the stored code
*/
-guint8*
+static guint8*
mono_amd64_emit_tls_get (guint8* code, int dreg, int tls_offset)
{
#ifdef TARGET_WIN32
amd64_mov_reg_membase (code, dreg, dreg, (tls_offset * 8) - 0x200, 8);
amd64_patch (buf [0], code);
}
-#elif defined(__APPLE__)
+#elif defined(TARGET_MACH)
x86_prefix (code, X86_GS_PREFIX);
amd64_mov_reg_mem (code, dreg, tls_gs_offset + (tls_offset * 8), 8);
#else
return code;
}
-#ifdef TARGET_WIN32
-
-#define MAX_TEB_TLS_SLOTS 64
-#define TEB_TLS_SLOTS_OFFSET 0x1480
-#define TEB_TLS_EXPANSION_SLOTS_OFFSET 0x1780
-
-static guint8*
-emit_tls_get_reg_windows (guint8* code, int dreg, int offset_reg)
-{
- int tmp_reg = -1;
- guint8 * more_than_64_slots = NULL;
- guint8 * empty_slot = NULL;
- guint8 * tls_get_reg_done = NULL;
-
- //Use temporary register for offset calculation?
- if (dreg == offset_reg) {
- tmp_reg = dreg == AMD64_RAX ? AMD64_RCX : AMD64_RAX;
- amd64_push_reg (code, tmp_reg);
- amd64_mov_reg_reg (code, tmp_reg, offset_reg, sizeof (gpointer));
- offset_reg = tmp_reg;
- }
-
- //TEB TLS slot array only contains MAX_TEB_TLS_SLOTS items, if more is used the expansion slots must be addressed.
- amd64_alu_reg_imm (code, X86_CMP, offset_reg, MAX_TEB_TLS_SLOTS);
- more_than_64_slots = code;
- amd64_branch8 (code, X86_CC_GE, 0, TRUE);
-
- //TLS slot array, _TEB.TlsSlots, is at offset TEB_TLS_SLOTS_OFFSET and index is offset * 8 in Windows 64-bit _TEB structure.
- amd64_shift_reg_imm (code, X86_SHL, offset_reg, 3);
- amd64_alu_reg_imm (code, X86_ADD, offset_reg, TEB_TLS_SLOTS_OFFSET);
-
- //TEB pointer is stored in GS segment register on Windows x64. TLS slot is located at calculated offset from that pointer.
- x86_prefix (code, X86_GS_PREFIX);
- amd64_mov_reg_membase (code, dreg, offset_reg, 0, sizeof (gpointer));
-
- tls_get_reg_done = code;
- amd64_jump8 (code, 0);
-
- amd64_patch (more_than_64_slots, code);
-
- //TLS expansion slots, _TEB.TlsExpansionSlots, is at offset TEB_TLS_EXPANSION_SLOTS_OFFSET in Windows 64-bit _TEB structure.
- x86_prefix (code, X86_GS_PREFIX);
- amd64_mov_reg_mem (code, dreg, TEB_TLS_EXPANSION_SLOTS_OFFSET, sizeof (gpointer));
-
- //Check for NULL in _TEB.TlsExpansionSlots.
- amd64_test_reg_reg (code, dreg, dreg);
- empty_slot = code;
- amd64_branch8 (code, X86_CC_EQ, 0, TRUE);
-
- //TLS expansion slots are at index offset into the expansion array.
- //Calculate for the MAX_TEB_TLS_SLOTS offsets, since the interessting offset is offset_reg - MAX_TEB_TLS_SLOTS.
- amd64_alu_reg_imm (code, X86_SUB, offset_reg, MAX_TEB_TLS_SLOTS);
- amd64_shift_reg_imm (code, X86_SHL, offset_reg, 3);
-
- amd64_mov_reg_memindex (code, dreg, dreg, 0, offset_reg, 0, sizeof (gpointer));
-
- amd64_patch (empty_slot, code);
- amd64_patch (tls_get_reg_done, code);
-
- if (tmp_reg != -1)
- amd64_pop_reg (code, tmp_reg);
-
- return code;
-}
-
-#endif
-
-static guint8*
-emit_tls_get_reg (guint8* code, int dreg, int offset_reg)
-{
- /* offset_reg contains a value translated by mono_arch_translate_tls_offset () */
-#ifdef TARGET_OSX
- if (dreg != offset_reg)
- amd64_mov_reg_reg (code, dreg, offset_reg, sizeof (mgreg_t));
- amd64_prefix (code, X86_GS_PREFIX);
- amd64_mov_reg_membase (code, dreg, dreg, 0, sizeof (mgreg_t));
-#elif defined(__linux__)
- int tmpreg = -1;
-
- if (dreg == offset_reg) {
- /* Use a temporary reg by saving it to the redzone */
- tmpreg = dreg == AMD64_RAX ? AMD64_RCX : AMD64_RAX;
- amd64_mov_membase_reg (code, AMD64_RSP, -8, tmpreg, 8);
- amd64_mov_reg_reg (code, tmpreg, offset_reg, sizeof (gpointer));
- offset_reg = tmpreg;
- }
- x86_prefix (code, X86_FS_PREFIX);
- amd64_mov_reg_mem (code, dreg, 0, 8);
- amd64_mov_reg_memindex (code, dreg, dreg, 0, offset_reg, 0, 8);
- if (tmpreg != -1)
- amd64_mov_reg_membase (code, tmpreg, AMD64_RSP, -8, 8);
-#elif defined(TARGET_WIN32)
- code = emit_tls_get_reg_windows (code, dreg, offset_reg);
-#else
- g_assert_not_reached ();
-#endif
- return code;
-}
-
static guint8*
-amd64_emit_tls_set (guint8 *code, int sreg, int tls_offset)
+mono_amd64_emit_tls_set (guint8 *code, int sreg, int tls_offset)
{
#ifdef TARGET_WIN32
g_assert_not_reached ();
-#elif defined(__APPLE__)
+#elif defined(TARGET_MACH)
x86_prefix (code, X86_GS_PREFIX);
amd64_mov_mem_reg (code, tls_gs_offset + (tls_offset * 8), sreg, 8);
#else
return code;
}
-static guint8*
-amd64_emit_tls_set_reg (guint8 *code, int sreg, int offset_reg)
-{
- /* offset_reg contains a value translated by mono_arch_translate_tls_offset () */
-#ifdef TARGET_WIN32
- g_assert_not_reached ();
-#elif defined(__APPLE__)
- x86_prefix (code, X86_GS_PREFIX);
- amd64_mov_membase_reg (code, offset_reg, 0, sreg, 8);
-#else
- x86_prefix (code, X86_FS_PREFIX);
- amd64_mov_membase_reg (code, offset_reg, 0, sreg, 8);
-#endif
- return code;
-}
-
- /*
- * mono_arch_translate_tls_offset:
- *
- * Translate the TLS offset OFFSET computed by MONO_THREAD_VAR_OFFSET () into a format usable by OP_TLS_GET_REG/OP_TLS_SET_REG.
- */
-int
-mono_arch_translate_tls_offset (int offset)
-{
-#ifdef __APPLE__
- return tls_gs_offset + (offset * 8);
-#else
- return offset;
-#endif
-}
-
/*
* emit_setup_lmf:
*
return code;
}
+#ifdef TARGET_WIN32
+
+#define TEB_LAST_ERROR_OFFSET 0x068
+
+static guint8*
+emit_get_last_error (guint8* code, int dreg)
+{
+ /* Threads last error value is located in TEB_LAST_ERROR_OFFSET. */
+ x86_prefix (code, X86_GS_PREFIX);
+ amd64_mov_reg_membase (code, dreg, TEB_LAST_ERROR_OFFSET, 0, sizeof (guint32));
+
+ return code;
+}
+
+#else
+
+static guint8*
+emit_get_last_error (guint8* code, int dreg)
+{
+ g_assert_not_reached ();
+}
+
+#endif
+
/* benchmark and set based on cpu */
#define LOOP_ALIGNMENT 8
#define bb_is_loop_start(bb) ((bb)->loop_body_start && (bb)->nesting)
break;
}
case OP_GENERIC_CLASS_INIT: {
- static int byte_offset = -1;
- static guint8 bitmask;
guint8 *jump;
g_assert (ins->sreg1 == MONO_AMD64_ARG_REG1);
- if (byte_offset < 0)
- mono_marshal_find_bitfield_offset (MonoVTable, initialized, &byte_offset, &bitmask);
-
- amd64_test_membase_imm_size (code, ins->sreg1, byte_offset, bitmask, 1);
+ amd64_test_membase_imm_size (code, ins->sreg1, MONO_STRUCT_OFFSET (MonoVTable, initialized), 1, 1);
jump = code;
amd64_branch8 (code, X86_CC_NZ, -1, 1);
code = mono_amd64_emit_tls_get (code, ins->dreg, ins->inst_offset);
break;
}
- case OP_TLS_GET_REG:
- code = emit_tls_get_reg (code, ins->dreg, ins->sreg1);
- break;
case OP_TLS_SET: {
- code = amd64_emit_tls_set (code, ins->sreg1, ins->inst_offset);
- break;
- }
- case OP_TLS_SET_REG: {
- code = amd64_emit_tls_set_reg (code, ins->sreg1, ins->sreg2);
+ code = mono_amd64_emit_tls_set (code, ins->sreg1, ins->inst_offset);
break;
}
case OP_MEMORY_BARRIER: {
case OP_XZERO:
amd64_sse_pxor_reg_reg (code, ins->dreg, ins->dreg);
break;
+ case OP_XONES:
+ amd64_sse_pcmpeqb_reg_reg (code, ins->dreg, ins->dreg);
+ break;
case OP_ICONV_TO_R4_RAW:
amd64_movd_xreg_reg_size (code, ins->dreg, ins->sreg1, 4);
+ if (!cfg->r4fp)
+ amd64_sse_cvtss2sd_reg_reg (code, ins->dreg, ins->dreg);
break;
case OP_FCONV_TO_R8_X:
ins->backend.pc_offset = code - cfg->native_code;
bb->spill_slot_defs = g_slist_prepend_mempool (cfg->mempool, bb->spill_slot_defs, ins);
break;
+ case OP_GET_LAST_ERROR:
+ emit_get_last_error(code, ins->dreg);
+ break;
default:
g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
g_assert_not_reached ();
if (method->save_lmf) {
/* check if we need to restore protection of the stack after a stack overflow */
- if (!cfg->compile_aot && mono_get_jit_tls_offset () != -1) {
+ if (!cfg->compile_aot && mono_arch_have_fast_tls () && mono_tls_get_tls_offset (TLS_KEY_JIT_TLS) != -1) {
guint8 *patch;
- code = mono_amd64_emit_tls_get (code, AMD64_RCX, mono_get_jit_tls_offset ());
+ code = mono_amd64_emit_tls_get (code, AMD64_RCX, mono_tls_get_tls_offset (TLS_KEY_JIT_TLS));
/* we load the value in a separate instruction: this mechanism may be
* used later as a safer way to do thread interruption
*/
amd64_jump_membase (code, AMD64_RAX, offset);
mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_DELEGATE_INVOKE, NULL);
- if (load_imt_reg)
- tramp_name = g_strdup_printf ("delegate_virtual_invoke_imt_%d", - offset / sizeof (gpointer));
- else
- tramp_name = g_strdup_printf ("delegate_virtual_invoke_%d", offset / sizeof (gpointer));
+ tramp_name = mono_get_delegate_virtual_invoke_impl_name (load_imt_reg, offset);
*info = mono_tramp_info_create (tramp_name, start, code - start, NULL, unwind_ops);
g_free (tramp_name);
res = g_slist_prepend (res, info);
}
- for (i = 0; i <= MAX_VIRTUAL_DELEGATE_OFFSET; ++i) {
+ for (i = 1; i <= MONO_IMT_SIZE; ++i) {
get_delegate_virtual_invoke_impl (&info, TRUE, - i * SIZEOF_VOID_P);
res = g_slist_prepend (res, info);
+ }
+ for (i = 0; i <= MAX_VIRTUAL_DELEGATE_OFFSET; ++i) {
get_delegate_virtual_invoke_impl (&info, FALSE, i * SIZEOF_VOID_P);
res = g_slist_prepend (res, info);
+ get_delegate_virtual_invoke_impl (&info, TRUE, i * SIZEOF_VOID_P);
+ res = g_slist_prepend (res, info);
}
return res;
* LOCKING: called with the domain lock held
*/
gpointer
-mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckItem **imt_entries, int count,
+mono_arch_build_imt_trampoline (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckItem **imt_entries, int count,
gpointer fail_tramp)
{
int i;
size += item->chunk_size;
}
if (fail_tramp)
- code = (guint8 *)mono_method_alloc_generic_virtual_thunk (domain, size);
+ code = (guint8 *)mono_method_alloc_generic_virtual_trampoline (domain, size);
else
code = (guint8 *)mono_domain_code_reserve (domain, size);
start = code;
}
if (!fail_tramp)
- mono_stats.imt_thunks_size += code - start;
+ mono_stats.imt_trampolines_size += code - start;
g_assert (code - start <= size);
mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_IMT_TRAMPOLINE, NULL);