From: Rodrigo Kumpera Date: Mon, 1 May 2017 20:50:22 +0000 (-0700) Subject: [jit] Move memcpy and memset emmiters to new file called memory-access.c X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=897fb5025abc0db79831e13d9bca5a04a9b81860;p=mono.git [jit] Move memcpy and memset emmiters to new file called memory-access.c --- diff --git a/mono/mini/Makefile.am.in b/mono/mini/Makefile.am.in index 79041633ffa..4e8d1bfd97a 100755 --- a/mono/mini/Makefile.am.in +++ b/mono/mini/Makefile.am.in @@ -485,7 +485,8 @@ common_sources = \ llvm-runtime.h \ type-checking.c \ lldb.h \ - lldb.c + lldb.c \ + memory-access.c test_sources = \ basic-calls.cs \ diff --git a/mono/mini/memory-access.c b/mono/mini/memory-access.c new file mode 100644 index 00000000000..2f25005a0ca --- /dev/null +++ b/mono/mini/memory-access.c @@ -0,0 +1,150 @@ +/** + * Emit memory access for the front-end. + * + */ + +#include +#include + +#ifndef DISABLE_JIT + +#include "mini.h" +#include "ir-emit.h" + +void +mini_emit_memset (MonoCompile *cfg, int destreg, int offset, int size, int val, int align) +{ + int val_reg; + + g_assert (val == 0); + + if (align == 0) + align = 4; + + if ((size <= SIZEOF_REGISTER) && (size <= align)) { + switch (size) { + case 1: + MONO_EMIT_NEW_STORE_MEMBASE_IMM (cfg, OP_STOREI1_MEMBASE_IMM, destreg, offset, val); + return; + case 2: + MONO_EMIT_NEW_STORE_MEMBASE_IMM (cfg, OP_STOREI2_MEMBASE_IMM, destreg, offset, val); + return; + case 4: + MONO_EMIT_NEW_STORE_MEMBASE_IMM (cfg, OP_STOREI4_MEMBASE_IMM, destreg, offset, val); + return; +#if SIZEOF_REGISTER == 8 + case 8: + MONO_EMIT_NEW_STORE_MEMBASE_IMM (cfg, OP_STOREI8_MEMBASE_IMM, destreg, offset, val); + return; +#endif + } + } + + val_reg = alloc_preg (cfg); + + if (SIZEOF_REGISTER == 8) + MONO_EMIT_NEW_I8CONST (cfg, val_reg, val); + else + MONO_EMIT_NEW_ICONST (cfg, val_reg, val); + + if (align < 4) { + /* This could be optimized further if neccesary */ + while (size >= 1) { + MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI1_MEMBASE_REG, destreg, offset, val_reg); + offset += 1; + size -= 1; + } + return; + } + + if (!cfg->backend->no_unaligned_access && SIZEOF_REGISTER == 8) { + if (offset % 8) { + MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI4_MEMBASE_REG, destreg, offset, val_reg); + offset += 4; + size -= 4; + } + while (size >= 8) { + MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI8_MEMBASE_REG, destreg, offset, val_reg); + offset += 8; + size -= 8; + } + } + + while (size >= 4) { + MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI4_MEMBASE_REG, destreg, offset, val_reg); + offset += 4; + size -= 4; + } + while (size >= 2) { + MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI2_MEMBASE_REG, destreg, offset, val_reg); + offset += 2; + size -= 2; + } + while (size >= 1) { + MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI1_MEMBASE_REG, destreg, offset, val_reg); + offset += 1; + size -= 1; + } +} + +void +mini_emit_memcpy (MonoCompile *cfg, int destreg, int doffset, int srcreg, int soffset, int size, int align) +{ + int cur_reg; + + if (align == 0) + align = 4; + + /*FIXME arbitrary hack to avoid unbound code expansion.*/ + g_assert (size < 10000); + + if (align < 4) { + /* This could be optimized further if neccesary */ + while (size >= 1) { + cur_reg = alloc_preg (cfg); + MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADI1_MEMBASE, cur_reg, srcreg, soffset); + MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI1_MEMBASE_REG, destreg, doffset, cur_reg); + doffset += 1; + soffset += 1; + size -= 1; + } + } + + if (!cfg->backend->no_unaligned_access && SIZEOF_REGISTER == 8) { + while (size >= 8) { + cur_reg = alloc_preg (cfg); + MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADI8_MEMBASE, cur_reg, srcreg, soffset); + MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI8_MEMBASE_REG, destreg, doffset, cur_reg); + doffset += 8; + soffset += 8; + size -= 8; + } + } + + while (size >= 4) { + cur_reg = alloc_preg (cfg); + MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADI4_MEMBASE, cur_reg, srcreg, soffset); + MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI4_MEMBASE_REG, destreg, doffset, cur_reg); + doffset += 4; + soffset += 4; + size -= 4; + } + while (size >= 2) { + cur_reg = alloc_preg (cfg); + MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADI2_MEMBASE, cur_reg, srcreg, soffset); + MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI2_MEMBASE_REG, destreg, doffset, cur_reg); + doffset += 2; + soffset += 2; + size -= 2; + } + while (size >= 1) { + cur_reg = alloc_preg (cfg); + MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADI1_MEMBASE, cur_reg, srcreg, soffset); + MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI1_MEMBASE_REG, destreg, doffset, cur_reg); + doffset += 1; + soffset += 1; + size -= 1; + } +} + +#endif diff --git a/mono/mini/method-to-ir.c b/mono/mini/method-to-ir.c index ac86126e9b7..066b05b972f 100644 --- a/mono/mini/method-to-ir.c +++ b/mono/mini/method-to-ir.c @@ -1579,142 +1579,6 @@ mini_emit_runtime_constant (MonoCompile *cfg, MonoJumpInfoType patch_type, gpoin return ins; } -static void -mini_emit_memset (MonoCompile *cfg, int destreg, int offset, int size, int val, int align) -{ - int val_reg; - - g_assert (val == 0); - - if (align == 0) - align = 4; - - if ((size <= SIZEOF_REGISTER) && (size <= align)) { - switch (size) { - case 1: - MONO_EMIT_NEW_STORE_MEMBASE_IMM (cfg, OP_STOREI1_MEMBASE_IMM, destreg, offset, val); - return; - case 2: - MONO_EMIT_NEW_STORE_MEMBASE_IMM (cfg, OP_STOREI2_MEMBASE_IMM, destreg, offset, val); - return; - case 4: - MONO_EMIT_NEW_STORE_MEMBASE_IMM (cfg, OP_STOREI4_MEMBASE_IMM, destreg, offset, val); - return; -#if SIZEOF_REGISTER == 8 - case 8: - MONO_EMIT_NEW_STORE_MEMBASE_IMM (cfg, OP_STOREI8_MEMBASE_IMM, destreg, offset, val); - return; -#endif - } - } - - val_reg = alloc_preg (cfg); - - if (SIZEOF_REGISTER == 8) - MONO_EMIT_NEW_I8CONST (cfg, val_reg, val); - else - MONO_EMIT_NEW_ICONST (cfg, val_reg, val); - - if (align < 4) { - /* This could be optimized further if neccesary */ - while (size >= 1) { - MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI1_MEMBASE_REG, destreg, offset, val_reg); - offset += 1; - size -= 1; - } - return; - } - - if (!cfg->backend->no_unaligned_access && SIZEOF_REGISTER == 8) { - if (offset % 8) { - MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI4_MEMBASE_REG, destreg, offset, val_reg); - offset += 4; - size -= 4; - } - while (size >= 8) { - MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI8_MEMBASE_REG, destreg, offset, val_reg); - offset += 8; - size -= 8; - } - } - - while (size >= 4) { - MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI4_MEMBASE_REG, destreg, offset, val_reg); - offset += 4; - size -= 4; - } - while (size >= 2) { - MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI2_MEMBASE_REG, destreg, offset, val_reg); - offset += 2; - size -= 2; - } - while (size >= 1) { - MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI1_MEMBASE_REG, destreg, offset, val_reg); - offset += 1; - size -= 1; - } -} - -void -mini_emit_memcpy (MonoCompile *cfg, int destreg, int doffset, int srcreg, int soffset, int size, int align) -{ - int cur_reg; - - if (align == 0) - align = 4; - - /*FIXME arbitrary hack to avoid unbound code expansion.*/ - g_assert (size < 10000); - - if (align < 4) { - /* This could be optimized further if neccesary */ - while (size >= 1) { - cur_reg = alloc_preg (cfg); - MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADI1_MEMBASE, cur_reg, srcreg, soffset); - MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI1_MEMBASE_REG, destreg, doffset, cur_reg); - doffset += 1; - soffset += 1; - size -= 1; - } - } - - if (!cfg->backend->no_unaligned_access && SIZEOF_REGISTER == 8) { - while (size >= 8) { - cur_reg = alloc_preg (cfg); - MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADI8_MEMBASE, cur_reg, srcreg, soffset); - MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI8_MEMBASE_REG, destreg, doffset, cur_reg); - doffset += 8; - soffset += 8; - size -= 8; - } - } - - while (size >= 4) { - cur_reg = alloc_preg (cfg); - MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADI4_MEMBASE, cur_reg, srcreg, soffset); - MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI4_MEMBASE_REG, destreg, doffset, cur_reg); - doffset += 4; - soffset += 4; - size -= 4; - } - while (size >= 2) { - cur_reg = alloc_preg (cfg); - MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADI2_MEMBASE, cur_reg, srcreg, soffset); - MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI2_MEMBASE_REG, destreg, doffset, cur_reg); - doffset += 2; - soffset += 2; - size -= 2; - } - while (size >= 1) { - cur_reg = alloc_preg (cfg); - MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADI1_MEMBASE, cur_reg, srcreg, soffset); - MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREI1_MEMBASE_REG, destreg, doffset, cur_reg); - doffset += 1; - soffset += 1; - size -= 1; - } -} - static MonoInst* mono_create_fast_tls_getter (MonoCompile *cfg, MonoTlsKey key) { diff --git a/mono/mini/mini.h b/mono/mini/mini.h index 0d40bc137ed..e4a594183a4 100644 --- a/mono/mini/mini.h +++ b/mono/mini/mini.h @@ -2625,6 +2625,7 @@ MonoInst *mono_branch_optimize_exception_target (MonoCompile *cfg, MonoB void mono_remove_critical_edges (MonoCompile *cfg); gboolean mono_is_regsize_var (MonoType *t); void mini_emit_memcpy (MonoCompile *cfg, int destreg, int doffset, int srcreg, int soffset, int size, int align); +void mini_emit_memset (MonoCompile *cfg, int destreg, int offset, int size, int val, int align); void mini_emit_stobj (MonoCompile *cfg, MonoInst *dest, MonoInst *src, MonoClass *klass, gboolean native); void mini_emit_initobj (MonoCompile *cfg, MonoInst *dest, const guchar *ip, MonoClass *klass); MonoInst* mini_emit_ldelema_1_ins (MonoCompile *cfg, MonoClass *klass, MonoInst *arr, MonoInst *index, gboolean bcheck);