From 4f78783ef1d6b7df9d68d8f8a9caf70bf7abaa93 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 5 Oct 2009 14:25:12 +0000 Subject: [PATCH] various bugfixes for SSE-based floating-point support --- src/compile.cpp | 4 ++-- src/compiler.cpp | 22 ++++++++++++---------- src/x86.cpp | 11 ++++++----- test/Floats.java | 3 +++ test/Subroutine.java | 4 +++- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index 2beecba6a0..5d55a2ae2e 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -5357,11 +5357,11 @@ finish(MyThread* t, Allocator* allocator, Context* context) ::strcmp (reinterpret_cast (&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)), - "AllFloats") == 0 and + "Floats") == 0 and ::strcmp (reinterpret_cast (&byteArrayBody(t, methodName(t, context->method), 0)), - "i2d") == 0) + "main") == 0) { trap(); } diff --git a/src/compiler.cpp b/src/compiler.cpp index 86b136c0d5..f3e9cb3dd4 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -17,13 +17,13 @@ namespace { namespace local { -const bool DebugAppend = true; -const bool DebugCompile = true; -const bool DebugResources = true; +const bool DebugAppend = false; +const bool DebugCompile = false; +const bool DebugResources = false; const bool DebugFrame = false; -const bool DebugControl = true; -const bool DebugReads = true; -const bool DebugSites = true; +const bool DebugControl = false; +const bool DebugReads = false; +const bool DebugSites = false; const bool DebugMoves = false; const bool DebugBuddies = false; @@ -3900,8 +3900,9 @@ pop(Context* c, unsigned footprint) low = high->next; } - assert(c, low->value->next == high->value - and ((BytesPerWord == 8) xor (low->value->next != 0))); + assert(c, (BytesPerWord == 8 + and low->value->next == low->value and high->value == 0) + or (BytesPerWord == 4 and low->value->next == high->value)); #endif // not NDEBUG popWord(c); @@ -5739,8 +5740,9 @@ class MyCompiler: public Compiler { low = s->next; } - assert(&c, low->value->next == high->value - and ((BytesPerWord == 8) xor (low->value->next != 0))); + assert(&c, (BytesPerWord == 8 + and low->value->next == low->value and high->value == 0) + or (BytesPerWord == 4 and low->value->next == high->value)); #endif // not NDEBUG if (not bigEndian) { diff --git a/src/x86.cpp b/src/x86.cpp index 5161ee592f..d492285387 100644 --- a/src/x86.cpp +++ b/src/x86.cpp @@ -2169,20 +2169,21 @@ unsignedShiftRightCR(Context* c, unsigned aSize UNUSED, Assembler::Constant* a, } inline void floatRegOp(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b, uint8_t op, uint8_t mod = 0xc0) + unsigned bSize, Assembler::Register* b, uint8_t op, + uint8_t mod = 0xc0) { if(aSize == 4) { opcode(c, 0xf3); } else { opcode(c, 0xf2); } - maybeRex(c, bSize, a, b); + maybeRex(c, bSize, b, a); opcode(c, 0x0f, op); modrm(c, mod, a, b); } inline void floatMemOp(Context* c, unsigned aSize, Assembler::Memory* a, - unsigned bSize UNUSED, Assembler::Register* b, uint8_t op) + unsigned bSize, Assembler::Register* b, uint8_t op) { if(aSize == 4) { opcode(c, 0xf3); @@ -2867,7 +2868,7 @@ class MyArchitecture: public Assembler::Architecture { case Float2Int: if (supportsSSE() and (bSize <= BytesPerWord)) { - *aTypeMask = (1 << RegisterOperand); + *aTypeMask = (1 << RegisterOperand) | (1 << MemoryOperand); *aRegisterMask = (static_cast(FloatRegisterMask) << 32) | FloatRegisterMask; } else { @@ -2877,7 +2878,7 @@ class MyArchitecture: public Assembler::Architecture { case Int2Float: if (supportsSSE()) { - *aTypeMask = (1 << RegisterOperand); + *aTypeMask = (1 << RegisterOperand) | (1 << MemoryOperand); *aRegisterMask = GeneralRegisterMask | (static_cast(GeneralRegisterMask) << 32); } else { diff --git a/test/Floats.java b/test/Floats.java index 20b6584f8b..1620e6a499 100644 --- a/test/Floats.java +++ b/test/Floats.java @@ -49,6 +49,9 @@ public class Floats { double d = 1d; expect(((int) d) == 1); + float f = 1f; + expect(((int) f) == 1); + expect(Math.round(0.4f) == 0); expect(Math.round(0.5f) == 1); expect(Math.round(1.0f) == 1); diff --git a/test/Subroutine.java b/test/Subroutine.java index 1a631e25d5..c7c04d501d 100644 --- a/test/Subroutine.java +++ b/test/Subroutine.java @@ -118,7 +118,7 @@ public class Subroutine { try { switch (path) { case 1: - return 42L; + return 0xFFFFFFFFFFL; case 2: { int a = 42; @@ -186,6 +186,8 @@ public class Subroutine { String.valueOf(test4(1)); String.valueOf(test4(2)); String.valueOf(test4(3)); + + expect(test4(1) == 0xFFFFFFFFFFL); } private static class DummyException extends RuntimeException { }