Hacker News new | past | comments | ask | show | jobs | submit login

I have plenty of compiler design experience and I don't know that. What I have seen is in line with my comment.

But I'd be happy to discover something new.

Care to show me a real-world, working example of compiler-optimisable assembly inlines with something that isn't using the GCC extension?

If by DMD you mean the Digital Mars D compiler (which is called DMD), then:

No. I checked the online documentation just now for DMD x86 just to be sure. According to that documentation, its inline assembly doesn't provide any of the flexibility that I listed.

You can see that easily by the way DMD requires you to name the exact registers in the inline asm, and the way the operands syntax is fixed as either a register, memory, memory with base and offset etc (the usual Intel things).

But DMD doesn't let you say "pick any suitable operand type". With GCC the compiler will select among possible operand types according to what fits best with the surrounding code. This way it avoids unnecessary loads, stores, register transfers etc. when interleaving C with asm, intrinsics with asm, or even asm with other asm from different inline functions.

You certainly can't do any of the fancy stuff the Linux kernel relies on, with asm directives like '.pushsection/.popsection', memory fault fixup tables, asm goto, inline lock hot paths and cold paths, etc.




If I want the optimizer to play tricks with inline Assembly I will use C instead.

As for the rest, I am more than happy with VC++ inline Assembly and compiler intrinsics (which then VC++ can play register games if that is what you're after), as another example.

The widespread of GCC hieroglyphics inside strings, is an unfortunate state of affairs in what concerns inline Assembly.


Of course, use whatever you prefer.

But the techniques I listed, which Linux kernel (and other software) relies on for performance, can't be done in C, can't be done with compiler intrinsics, and can't be done with basic asm in the style of DMD and MSVC either.

A feature to add new program-specific intrinsics to the compiler would work, but I don't know of any compiler which offers that, and it would probably look like extended asm anyway.

The GCC syntax isn't pretty. But I can't agree that it's inferior unless someone points to a better alternative that achieves similar results.

I've written programs that were portable to both GCC and MSVC, using the inline asm syntax of both compilers. The MSVC version produced slower code, because there was no way to produce the asm I wanted using MSVC.


If you cannot write the Assembly you want there is certainly a problem. /s


:-)

Well it turns out I can't, and neither can anyone else if they are looking for the fastest performance, because the fastest assembly depends on the context it is called from.

I had this problem going all the way back to the 8-bit machines, which is why I took an interest in compilers and dynamic code generation. To get the best :-)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: