Add support for long-to-float in the optimizing compiler.

- Add support for the long-to-float Dex instruction in the
  optimizing compiler.
- Have art::x86_64::X86_64Assembler::cvtsi2ss work with
  64-bit operands.
- Generate x86, x86-64 and ARM (but not ARM64) code for
  long to float HTypeConversion nodes.
- Add related tests to test/422-type-conversion.

Change-Id: Ic983cbeb1ae2051add40bc519a8f00a6196166c9
diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc
index 705065d..b21abad 100644
--- a/compiler/optimizing/code_generator_x86.cc
+++ b/compiler/optimizing/code_generator_x86.cc
@@ -1435,6 +1435,13 @@
           break;
 
         case Primitive::kPrimLong:
+          // Processing a Dex `long-to-float' instruction.
+          locations->SetInAt(0, Location::RequiresRegister());
+          locations->SetOut(Location::RequiresFpuRegister());
+          locations->AddTemp(Location::RequiresFpuRegister());
+          locations->AddTemp(Location::RequiresFpuRegister());
+          break;
+
         case Primitive::kPrimDouble:
           LOG(FATAL) << "Type conversion from " << input_type
                      << " to " << result_type << " not yet implemented";
@@ -1614,15 +1621,48 @@
 
     case Primitive::kPrimFloat:
       switch (input_type) {
-          // Processing a Dex `int-to-float' instruction.
         case Primitive::kPrimByte:
         case Primitive::kPrimShort:
         case Primitive::kPrimInt:
         case Primitive::kPrimChar:
+          // Processing a Dex `int-to-float' instruction.
           __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>());
           break;
 
-        case Primitive::kPrimLong:
+        case Primitive::kPrimLong: {
+          // Processing a Dex `long-to-float' instruction.
+          Register low = in.AsRegisterPairLow<Register>();
+          Register high = in.AsRegisterPairHigh<Register>();
+          XmmRegister result = out.AsFpuRegister<XmmRegister>();
+          XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>();
+          XmmRegister constant = locations->GetTemp(1).AsFpuRegister<XmmRegister>();
+
+          // Operations use doubles for precision reasons (each 32-bit
+          // half of a long fits in the 53-bit mantissa of a double,
+          // but not in the 24-bit mantissa of a float).  This is
+          // especially important for the low bits.  The result is
+          // eventually converted to float.
+
+          // low = low - 2^31 (to prevent bit 31 of `low` to be
+          // interpreted as a sign bit)
+          __ subl(low, Immediate(0x80000000));
+          // temp = int-to-double(high)
+          __ cvtsi2sd(temp, high);
+          // temp = temp * 2^32
+          __ LoadLongConstant(constant, k2Pow32EncodingForDouble);
+          __ mulsd(temp, constant);
+          // result = int-to-double(low)
+          __ cvtsi2sd(result, low);
+          // result = result + 2^31 (restore the original value of `low`)
+          __ LoadLongConstant(constant, k2Pow31EncodingForDouble);
+          __ addsd(result, constant);
+          // result = result + temp
+          __ addsd(result, temp);
+          // result = double-to-float(result)
+          __ cvtsd2ss(result, result);
+          break;
+        }
+
         case Primitive::kPrimDouble:
           LOG(FATAL) << "Type conversion from " << input_type
                      << " to " << result_type << " not yet implemented";
@@ -1636,11 +1676,11 @@
 
     case Primitive::kPrimDouble:
       switch (input_type) {
-          // Processing a Dex `int-to-double' instruction.
         case Primitive::kPrimByte:
         case Primitive::kPrimShort:
         case Primitive::kPrimInt:
         case Primitive::kPrimChar:
+          // Processing a Dex `int-to-double' instruction.
           __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>());
           break;
 
@@ -1652,23 +1692,18 @@
           XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>();
           XmmRegister constant = locations->GetTemp(1).AsFpuRegister<XmmRegister>();
 
-          // Binary encoding of 2^32 for type double.
-          const int64_t c1 = INT64_C(0x41F0000000000000);
-          // Binary encoding of 2^31 for type double.
-          const int64_t c2 = INT64_C(0x41E0000000000000);
-
           // low = low - 2^31 (to prevent bit 31 of `low` to be
           // interpreted as a sign bit)
           __ subl(low, Immediate(0x80000000));
           // temp = int-to-double(high)
           __ cvtsi2sd(temp, high);
           // temp = temp * 2^32
-          __ LoadLongConstant(constant, c1);
+          __ LoadLongConstant(constant, k2Pow32EncodingForDouble);
           __ mulsd(temp, constant);
           // result = int-to-double(low)
           __ cvtsi2sd(result, low);
           // result = result + 2^31 (restore the original value of `low`)
-          __ LoadLongConstant(constant, c2);
+          __ LoadLongConstant(constant, k2Pow31EncodingForDouble);
           __ addsd(result, constant);
           // result = result + temp
           __ addsd(result, temp);