Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Unaligned read/write only when NO_UNALIGNED_ACCESS is set #91813

Merged
merged 6 commits into from
Sep 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading