June 15, 2013
On Saturday, 15 June 2013 at 21:37:51 UTC, bearophile wrote:
> kink:
>
>> This shouldn't be a problem for Win32 though as x87s should be passed ordinarily by-val.
>
> See the D ABI:
> http://dlang.org/abi.html

… which doesn't fully apply to LDC. ;)

David
June 15, 2013
David Nadlinger:

> … which doesn't fully apply to LDC. ;)

What's the point of not following the ABI of D reals in LDC?

Bye,
bearophile
June 15, 2013
On Saturday, 15 June 2013 at 22:39:17 UTC, bearophile wrote:
> David Nadlinger:
>
>> … which doesn't fully apply to LDC. ;)
>
> What's the point of not following the ABI of D reals in LDC?

The question should be: What's the point of DMD not following the standard C ABI on Win32? ;)

In the case of reals, simple things should work, but DMD packs together 80-bit reals end-to-end (i.e. 10 byte spacing), whereas LLVM chooses 12 byte alignment.

David
June 16, 2013
> In the case of reals, simple things should work, but DMD packs together 80-bit reals end-to-end (i.e. 10 byte spacing), whereas LLVM chooses 12 byte alignment.

For 32-bit LLVM targets that is; sizeof(long double) == 16 bytes for the Win64 targets, so that the required 8-bytes alignment can be enforced.
June 16, 2013
Okay, I finally got the x87 argument passing to work between Clang and LDC after inserting a few lines into Clang's WinX86_64ABIInfo::classify method. Calling foo(666) in D returns 668.5, as expected.
As soon as I've fixed the remaining linking issues for MinGW-w64 CRT (including most modules and most likely all relevant ones), I'll post the required patches for Clang and the CRT so that others can experiment too.
June 22, 2013
I've got to say that I'm not keen on working further on this. I got rid of the linking issues, but the library is surely not 100% functional. My changes to the MinGW-w64 CRT are a messy hack, and that's because the codebase itself is a mess, very ugly and partially from the 80s and 90s of the last century.

I'd really suggest mapping the real type to the double type for Windows targets, ideally in all D compilers of course.

Here's at least the tiny patch for Clang to enable 80-bit long double support on Win64:

diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
index 4968938..f6ac502 100644
--- a/lib/Basic/Targets.cpp
+++ b/lib/Basic/Targets.cpp
@@ -3229,8 +3229,8 @@ class VisualStudioWindowsX86_64TargetInfo : public WindowsX86_64TargetInfo {
 public:
   VisualStudioWindowsX86_64TargetInfo(const std::string& triple)
     : WindowsX86_64TargetInfo(triple) {
-    LongDoubleWidth = LongDoubleAlign = 64;
-    LongDoubleFormat = &llvm::APFloat::IEEEdouble;
+    //LongDoubleWidth = LongDoubleAlign = 64;
+    //LongDoubleFormat = &llvm::APFloat::IEEEdouble;
   }
   virtual void getTargetDefines(const LangOptions &Opts,
                                 MacroBuilder &Builder) const {
diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp
index 4fa0c3b..9fb00a5 100644
--- a/lib/CodeGen/TargetInfo.cpp
+++ b/lib/CodeGen/TargetInfo.cpp
@@ -2584,6 +2584,11 @@ ABIArgInfo WinX86_64ABIInfo::classify(QualType Ty, bool IsReturnType) const {
   if (Ty->isPromotableIntegerType())
     return ABIArgInfo::getExtend();

+  if (!IsReturnType &&                                        // regular function parameter
+      Ty->isRealFloatingType() && Size > 64 &&                // non-complex x87 type (80 bits)
+      getTarget().getTriple().getOS() == llvm::Triple::Win32) // Win64 Visual Studio target
+    return ABIArgInfo::getIndirect(0, /*ByVal=*/false);       // TODO: is that the right ByVal setting?
+
   return ABIArgInfo::getDirect();
 }
June 29, 2013
Hey guys,

I didn't want to let my work be in vain - here's the tailored MinGW-w64 CRT:

https://github.com/kinke/mingw-w64-crt

The Clang patch is included. I cleaned up my changes and the whole source tree; I think the result is not extremely ugly and most of the code should work. ;)
Next ›   Last »
1 2