Skip to content

Commit

Permalink
[mono] Unaligned read/write only when NO_UNALIGNED_ACCESS is set (#91813
Browse files Browse the repository at this point in the history
)

* unaligned read/store only on platforms not supporting it
  • Loading branch information
matouskozak committed Sep 26, 2023
1 parent 867f5d4 commit 169e22c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/mono/mono/mini/memory-access.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ mini_emit_memory_load (MonoCompile *cfg, MonoType *type, MonoInst *src, int offs
/* LLVM can handle unaligned loads and stores, so there's no reason to
* manually decompose an unaligned load here into a memcpy if we're
* using LLVM. */
#ifdef NO_UNALIGNED_ACCESS
if ((ins_flag & MONO_INST_UNALIGNED) && !COMPILE_LLVM (cfg)) {
MonoInst *addr, *tmp_var;
int align;
Expand All @@ -498,9 +499,10 @@ mini_emit_memory_load (MonoCompile *cfg, MonoType *type, MonoInst *src, int offs

mini_emit_memcpy_const_size (cfg, addr, src, size, 1);
EMIT_NEW_TEMPLOAD (cfg, ins, tmp_var->inst_c0);
} else {
} else
#endif
EMIT_NEW_LOAD_MEMBASE_TYPE (cfg, ins, type, src->dreg, offset);
}

ins->flags |= ins_flag;

if (ins_flag & MONO_INST_VOLATILE) {
Expand All @@ -524,14 +526,17 @@ mini_emit_memory_store (MonoCompile *cfg, MonoType *type, MonoInst *dest, MonoIn
if (!(ins_flag & MONO_INST_NONULLCHECK))
MONO_EMIT_NULL_CHECK (cfg, dest->dreg, FALSE);

#ifdef NO_UNALIGNED_ACCESS
if ((ins_flag & MONO_INST_UNALIGNED) && !COMPILE_LLVM (cfg)) {
MonoInst *addr, *mov, *tmp_var;

tmp_var = mono_compile_create_var (cfg, type, OP_LOCAL);
EMIT_NEW_TEMPSTORE (cfg, mov, tmp_var->inst_c0, value);
EMIT_NEW_VARLOADA (cfg, addr, tmp_var, tmp_var->inst_vtype);
mini_emit_memory_copy_internal (cfg, dest, addr, mono_class_from_mono_type_internal (type), 1, FALSE, (ins_flag & MONO_INST_STACK_STORE) != 0);
} else {
} else
#endif
{
MonoInst *ins;

/* FIXME: should check item at sp [1] is compatible with the type of the store. */
Expand Down

0 comments on commit 169e22c

Please sign in to comment.