Cleanup x86_patch and amd64_patch. (mono/mono#16474)
authorJay Krell <jaykrell@microsoft.com>
Fri, 30 Aug 2019 21:45:55 +0000 (14:45 -0700)
committerVlad Brezae <brezaevlad@gmail.com>
Fri, 30 Aug 2019 21:45:55 +0000 (00:45 +0300)
commite32751850508005a4ee13e4375797f104430a3d7
treec77d8d34e3a1557954d65444b84a50490bf28c1e
parent9685cd7b0cc8ed9a7d0dcd5db2bb39edf4febadb
Cleanup x86_patch and amd64_patch. (mono/mono#16474)

* Cleanup x86_patch and amd64_patch.

amd64_patch has two incorrect looking probably unused cases.
 g_assert(0) and fix them.
 call and jmp indirect (one case)
 move reg RIP relative

x86_patch is large-ish inline macro.
Presumably for sharing with amd64, not inlining.
Restructure as an inline function, called once.
Try to make the code a little clearer also, with same functionality and efficiency
 (modulo the optimized perf of "if i == 4" vs. "if i")
i.e. speak of instruction_size and offset_size, not pos and boolean size.

Add to x86_patch the ability to patch jmp/call indirect,
as amd64_patch has, but which was incorrect.
This would seem useful for a later change (using "thunks"
to patch nearby data instead of patching aligned instructions,
indirect call/jmp vs. direct).

amd64_patch largely delegates to x86_patch.
One case asserts and delegates.
Move the assert to the x86 side, where an optimizing
compiler should know to remove it for x86 anyway.

Change some assert to g_assert.

Remove some unnecessary casts.

Fix an assert (https://github.com/mono/mono/pull/16471).

* Change g_assert back to assert except where making larger changes
and less expansion.

Commit migrated from https://github.com/mono/mono/commit/f735571f27738e3354f6d92650a0517d0482039d
src/mono/mono/arch/x86/x86-codegen.h
src/mono/mono/mini/mini-amd64.c
src/mono/mono/mini/mini-x86.c
src/mono/mono/mini/mini-x86.h