inline assembley

I’am migrating my x86 code base to x64 and I have some code in assembley which I created a seperate .asm file for. I am accessing the functions exported from asm file into my c /c++ file, which I have no issues with but wondering here is if I could make those asm functions as forceinlined or similar this is just for performance… I have heard that this can’t be done but just want to make sure if that’s correct…

Thanks in advance…

Do you mean inline assembler, or __forceinline C/C++?

You can’t do the former.

Mm
On Oct 29, 2010 3:26 PM, wrote:
> I’am migrating my x86 code base to x64 and I have some code in assembley
which I created a seperate .asm file for. I am accessing the functions
exported from asm file into my c /c++ file, which I have no issues with but
wondering here is if I could make those asm functions as forceinlined or
similar this is just for performance… I have heard that this can’t be done
but just want to make sure if that’s correct…
>
> Thanks in advance…
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

xxxxx@yahoo.com wrote:

I’am migrating my x86 code base to x64 and I have some code in assembley which I created a seperate .asm file for. I am accessing the functions exported from asm file into my c /c++ file, which I have no issues with but wondering here is if I could make those asm functions as forceinlined or similar this is just for performance… I have heard that this can’t be done but just want to make sure if that’s correct…

Microsoft’s 64-bit compilers do not support inline assembler. You need
to stay with the separate .asm.

What are you doing in these files? There are compiler intrinsic
functions for many of the things people use asm for, like rdtsc and rdmsr.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

How about forceinline… how can I do that … Yeah I did check compiler intrinsics which I am using where ever I can but in some cases I can’t…so this case falls under such kind of scenerio…

Thanks much again…

xxxxx@yahoo.com wrote:

How about forceinline… how can I do that … Yeah I did check compiler intrinsics which I am using where ever I can but in some cases I can’t…so this case falls under such kind of scenerio…

“forceinline” tells the compiler that this function should be compiled
inline, instead of compiled separately and invoked with a “call”
instruction. It’s a win for very short functions, because you avoid the
overhead of a “call”, but that overhead is insignificant once the code
becomes more than a couple of lines.

“forceinline” cannot force an external function to be inlined. It only
applies to function definitions, which means functions where you are
supplying the code.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Then what’s the best way for me as such call instruction is ommited in the cases where I need to use an external function defined within asm file. Or am I asking something impossible…

You are asking for the impossible. But then again, many uses of
assembler in X86 were not needed so take another look.

Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

xxxxx@yahoo.com” wrote in message
news:xxxxx@ntdev:

> Then what’s the best way for me as such call instruction is ommited in the cases where I need to use an external function defined within asm file. Or am I asking something impossible…

xxxxx@yahoo.com wrote:

I’am migrating my x86 code base to x64 and I have some code in assembley
which I created a seperate .asm file for. I am accessing the functions
exported from asm file into my c /c++ file, which I have no issues with
but wondering here is if I could make those asm functions as forceinlined
or similar this is just for performance… I have heard that this can’t be
done but just want to make sure if that’s correct…

What performance improvement do you see by using assembler?

This is a good question.

If you haven’t yet measured the difference between your assembler and a
c/c++ version (optimized, of course), you might want to do so, as the
compiler generally does an excellent job.

Moreover, you CAN forceinline your c/c++ versions, which seems to be what
you want.

Good luck,

mm

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of J. J. Farrell
Sent: Friday, October 29, 2010 6:36 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] inline assembley

xxxxx@yahoo.com wrote:

I’am migrating my x86 code base to x64 and I have some code in assembley
which I created a seperate .asm file for. I am accessing the functions
exported from asm file into my c /c++ file, which I have no issues with
but wondering here is if I could make those asm functions as forceinlined
or similar this is just for performance… I have heard that this can’t be
done but just want to make sure if that’s correct…

What performance improvement do you see by using assembler?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Yes true you can certainly foreinline c/c++ but here my function is defined within my .asm file so how to do so…
When I avoid calling a “CALL” instruction then I do see better perf bcoz of caching and what not…With limitation of x64 that does not support inlining of ASMs I have two choices either go with instrinsics supported and/or completely port over my tast to seperate asm file and invoke it via CALL. In my case I’am using compiler instrinsics where I can but there are certain pieces where I those intrinsics are not available for which I was wondering what’s the best option…

I was suggesting that it might be possible to replace your assembler with
C/C++ and use forceinline there.

It’s all a matter of what your profiling reveals.

Good luck,

mm

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com
Sent: Monday, November 01, 2010 11:41 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] inline assembley

Yes true you can certainly foreinline c/c++ but here my function is defined
within my .asm file so how to do so…
When I avoid calling a “CALL” instruction then I do see better perf bcoz of
caching and what not…With limitation of x64 that does not support inlining
of ASMs I have two choices either go with instrinsics supported and/or
completely port over my tast to seperate asm file and invoke it via CALL. In
my case I’am using compiler instrinsics where I can but there are certain
pieces where I those intrinsics are not available for which I was wondering
what’s the best option…


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Sounds to me like you answered your own question, no? You have 2 options:

  1. Use intrinsics
  2. use a separate ASM file and invoke the routines therein via CALL.

You’re using intrinsics where you can, but apparently they aren’t sufficient. That just leaves you with one choice.

Just BE SURE you understand the x64 calling conventions (http://msdn.microsoft.com/en-us/library/7kcdt6fy.aspx) and generate the appropriate function prologues/epilogues. Note the NESTED__ENTRY and LEAF_ENTRY macros, which IIRC live in macamd64.inc

Peter
OSR