Thumb2 assembler for JNI compiler and optimizing compiler
This provides a programmatic assembler for the thumb2 instruction set for
ARM. The interface is the same as the ARM assembler and the ARM assembler has
been moved into Arm32Assembler. The assembler handles most 16 and 32 bit instructions
and also allows relocations due to branch expansion. It will also rewrite cbz/cbnz
instructions if they go out of range.
It also changes the JNI compiler to use the thumb2 assembler as opposed
to forcing it to use ARM32. The trampoline compiler still uses ARM due to the
way it returns the address of its generated code. A trampoline in thumb2 is the
same size as that in ARM anyway (8 bytes).
Provides gtest for testing the thumb2 instruction output. This gtest only runs
on the host as it uses arm-eabi-objdump to disassemble the generated code. On the
target the output is not checked but the assembler will still be run to perform
all its checks.
Change-Id: Icd9742b6f13541bec5b23097896727392e3a6fb6
diff --git a/compiler/utils/assembler.h b/compiler/utils/assembler.h
index 19239e1..f72f5e5 100644
--- a/compiler/utils/assembler.h
+++ b/compiler/utils/assembler.h
@@ -38,6 +38,8 @@
namespace arm {
class ArmAssembler;
+ class Arm32Assembler;
+ class Thumb2Assembler;
}
namespace arm64 {
class Arm64Assembler;
@@ -87,7 +89,7 @@
int LinkPosition() const {
CHECK(IsLinked());
- return position_ - kWordSize;
+ return position_ - kPointerSize;
}
bool IsBound() const { return position_ < 0; }
@@ -114,6 +116,8 @@
}
friend class arm::ArmAssembler;
+ friend class arm::Arm32Assembler;
+ friend class arm::Thumb2Assembler;
friend class mips::MipsAssembler;
friend class x86::X86Assembler;
friend class x86_64::X86_64Assembler;
@@ -189,6 +193,15 @@
*reinterpret_cast<T*>(contents_ + position) = value;
}
+ void Move(size_t newposition, size_t oldposition) {
+ CHECK(HasEnsuredCapacity());
+ // Move the contents of the buffer from oldposition to
+ // newposition by nbytes.
+ size_t nbytes = Size() - oldposition;
+ memmove(contents_ + newposition, contents_ + oldposition, nbytes);
+ cursor_ += newposition - oldposition;
+ }
+
// Emit a fixup at the current location.
void EmitFixup(AssemblerFixup* fixup) {
fixup->set_previous(fixup_);