Implement long negate instruction in the optimizing compiler.
- Add support for the neg-long (long integer two's
complement negate) instruction in the optimizing compiler.
- Add a 64-bit NEG instruction (negq) to the x86-64
assembler.
- Generate ARM, x86 and x86-64 code for integer HNeg nodes.
- Put neg-related tests into test/415-optimizing-arith-neg.
Change-Id: I1fbe9611e134408a6b8745d1df20ab6ffa5e50f2
diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc
index 61f0750..aa0f06b 100644
--- a/compiler/optimizing/code_generator_x86.cc
+++ b/compiler/optimizing/code_generator_x86.cc
@@ -990,11 +990,11 @@
new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
switch (neg->GetResultType()) {
case Primitive::kPrimInt:
+ case Primitive::kPrimLong:
locations->SetInAt(0, Location::RequiresRegister());
locations->SetOut(Location::SameAsFirstInput());
break;
- case Primitive::kPrimLong:
case Primitive::kPrimFloat:
case Primitive::kPrimDouble:
LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
@@ -1016,6 +1016,17 @@
break;
case Primitive::kPrimLong:
+ DCHECK(in.IsRegisterPair());
+ __ negl(out.AsRegisterPairLow<Register>());
+ // Negation is similar to subtraction from zero. The least
+ // significant byte triggers a borrow when it is different from
+ // zero; to take it into account, add 1 to the most significant
+ // byte if the carry flag (CF) is set to 1 after the first NEGL
+ // operation.
+ __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0));
+ __ negl(out.AsRegisterPairHigh<Register>());
+ break;
+
case Primitive::kPrimFloat:
case Primitive::kPrimDouble:
LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();