www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Inlining a "pure" ASM function

reply "D-ratiseur" <ThisAdressDoesntExist nowhere.fr> writes:
Hello, Is it possible for an ASM function to be inlined in D?
for example I compile with -Release -inline, this function (used 
in a simple console app obviously):

---
int SSERound(double AValue)
{
	asm
	{
		cvtsd2si EAX,[AValue];
	}
}
---

but, under win32, the code generated looks like this:

---
sub_402010      proc near               ; CODE XREF: 
_TEXT:0040209Dp
_TEXT:00402010
_TEXT:00402010 arg_0           = qword ptr  8
_TEXT:00402010
_TEXT:00402010                 push    ebp
_TEXT:00402011                 mov     ebp, esp
_TEXT:00402013                 cvtsd2si eax, [ebp+arg_0]
_TEXT:00402018                 pop     ebp
_TEXT:00402019                 retn    8
_TEXT:00402019 sub_402010      endp
---

Which looks a bit odd as there is a CALL, a PUSH, a POP and a RET 
just for one SSE instruction.

I've tried with "naked", but I've fastly get that this keyword 
simply mean that it's up to the user to clean the regs or to push 
pop the wtacks etc.

Can dmd "inline" this simple function ? the D manual doesn't seem 
to specify that there is a restriction over inlining when a 
function contains an asm block.
Feb 28 2013
next sibling parent reply =?iso-8859-15?Q?Simen_Kj=E6r=E5s?= <simen.kjaras gmail.com> writes:
On Thu, 28 Feb 2013 16:22:49 +0100, D-ratiseur  
<ThisAdressDoesntExist nowhere.fr> wrote:

 Hello, Is it possible for an ASM function to be inlined in D?
Nope. -- Simen
Feb 28 2013
parent reply "D-ratiseur" <ThisAdressDoesntExist nowhere.fr> writes:
On Thursday, 28 February 2013 at 15:35:07 UTC, Simen Kjærås wrote:
 Nope.
Ok, thx, so it's like in Delphi/Fpc. Maybe the manual could contain a remark about this.
Feb 28 2013
parent "bearophile" <bearophileHUGS lycos.com> writes:
D-ratiseur:

 Maybe the manual could contain a remark about this.
I think it's written somewhere in the site. But LDC is able (with a compiler-specific pragma) to inline functions that contain asm. Bye, bearophile
Feb 28 2013
prev sibling parent reply Brad Roberts <braddr puremagic.com> writes:
On Thu, 28 Feb 2013, Simen Kj?r?s wrote:

 On Thu, 28 Feb 2013 16:22:49 +0100, D-ratiseur
 <ThisAdressDoesntExist nowhere.fr> wrote:
 
 Hello, Is it possible for an ASM function to be inlined in D?
Nope.
To be a little more accurate: it's possible in the technical sense. No D compiler today does it automatically. There's no way with DMD to force it, but might be with GDC and/or LDC. The lack of inlining in a number of cases that seem like they should is a quality of implementation issue and not a language definition issue.
Feb 28 2013
parent Johannes Pfau <nospam example.com> writes:
Am Thu, 28 Feb 2013 14:33:15 -0800 (PST)
schrieb Brad Roberts <braddr puremagic.com>:

 On Thu, 28 Feb 2013, Simen Kj?r?s wrote:
 
 On Thu, 28 Feb 2013 16:22:49 +0100, D-ratiseur
 <ThisAdressDoesntExist nowhere.fr> wrote:
 
 Hello, Is it possible for an ASM function to be inlined in D?
Nope.
To be a little more accurate: it's possible in the technical sense. No D compiler today does it automatically. There's no way with DMD to force it, but might be with GDC and/or LDC. The lack of inlining in a number of cases that seem like they should is a quality of implementation issue and not a language definition issue.
IIRC gdc dropped support for dmd-style inline assembly. For gcc style inline assembly inlining should just work.
Mar 01 2013