"ANY CPU" compilation - what gives?
-
The Any CPU option is not optimised for a specific processor. It will give you good general all round performance that works across any of the target processors. If you absolutely must have all the performance you want then target the appropriate processor. [ADDITIONAL] First Addition:: There seems to be a lot of confusion about this. MSDN says one thing. The C# compiler command line help says another. Second Addition: See Guffa's post as he links to an article that explains exactly what is happening, and contradicts the MSDN article I used as the source of my original answer. [/ADDITIONAL]
* Developer Day Scotland 2 - Free community conference * The Blog of Colin Angus Mackay
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
modified on Friday, January 9, 2009 1:24 PM
-
Hello, a 3rd party supplier informs me their components are compiled for "ANY CPU", so they'll run x86 or x64 based on the platform to which they're deployed. This confuses me a bit; I had thought a select choice of x64 compilation would ensure the best performance, which is why so many companies these days deliver product-installers for both x86 and x64. But if I'm to take his word for good measure, there's no need (at least .net-wise) to ever compile to a specific CPU architecture, as the "ANY CPU" option will always ensure the assemblies run as fast as possible, given the host CPU? Hope someone might be able to clarify on this, thanks in advance, Morten
The IL code in your assembly isn't specific to any processor at all. Regardless of what CPU target you choose, the IL code could still be used on any processor. The CPU target is simply information that the code should only be allowed to be used on a specific type of CPU. You can use the CPU target for example to specify that your assembly only can be used in x86 mode as you are calling methods in an unmanaged x86-dll. It's the JIT compiler that creates the machine code from the IL code when your assembly is loaded. It can create different code depending on the actual processor that will run the code, so that it will take advantage of the capabilities or that specific processor.
Despite everything, the person most likely to be fooling you next is yourself.
-
The Any CPU option is not optimised for a specific processor. It will give you good general all round performance that works across any of the target processors. If you absolutely must have all the performance you want then target the appropriate processor. [ADDITIONAL] First Addition:: There seems to be a lot of confusion about this. MSDN says one thing. The C# compiler command line help says another. Second Addition: See Guffa's post as he links to an article that explains exactly what is happening, and contradicts the MSDN article I used as the source of my original answer. [/ADDITIONAL]
* Developer Day Scotland 2 - Free community conference * The Blog of Colin Angus Mackay
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
modified on Friday, January 9, 2009 1:24 PM
Colin Angus Mackay wrote:
It will give you good general all round performance that works across any of the target processors. If you absolutely must have all the performance you want then target the appropriate processor.
That is not correct. The IL code generated is the same regardless of which CPU target you specify.
Despite everything, the person most likely to be fooling you next is yourself.
-
Hello Colin, this was also my impression. Thanks a lot for clearing this up for me. best, Morten
-
Colin Angus Mackay wrote:
It will give you good general all round performance that works across any of the target processors. If you absolutely must have all the performance you want then target the appropriate processor.
That is not correct. The IL code generated is the same regardless of which CPU target you specify.
Despite everything, the person most likely to be fooling you next is yourself.
Guffa wrote:
That is not correct. The IL code generated is the same regardless of which CPU target you specify.
Really? I was just paraphrasing this article in MSDN: How to: Optimize an Application for a Specific CPU Type[^]
* Developer Day Scotland 2 - Free community conference * The Blog of Colin Angus Mackay
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
-
The IL code in your assembly isn't specific to any processor at all. Regardless of what CPU target you choose, the IL code could still be used on any processor. The CPU target is simply information that the code should only be allowed to be used on a specific type of CPU. You can use the CPU target for example to specify that your assembly only can be used in x86 mode as you are calling methods in an unmanaged x86-dll. It's the JIT compiler that creates the machine code from the IL code when your assembly is loaded. It can create different code depending on the actual processor that will run the code, so that it will take advantage of the capabilities or that specific processor.
Despite everything, the person most likely to be fooling you next is yourself.
Guffa wrote:
The IL code in your assembly isn't specific to any processor at all.
That was also my thought until the OP asked the question and it got me thinking. I then looked at MSDN and this article suggests (although not explicitly to do with the IL output) otherwise: http://msdn.microsoft.com/en-us/library/5b4eyb0k.aspx[^]
* Developer Day Scotland 2 - Free community conference * The Blog of Colin Angus Mackay
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
-
Guffa wrote:
The IL code in your assembly isn't specific to any processor at all.
That was also my thought until the OP asked the question and it got me thinking. I then looked at MSDN and this article suggests (although not explicitly to do with the IL output) otherwise: http://msdn.microsoft.com/en-us/library/5b4eyb0k.aspx[^]
* Developer Day Scotland 2 - Free community conference * The Blog of Colin Angus Mackay
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
c:\> csc /?
...
/platform:
Limit which platforms this code can run on: x86, Itanium, x64, or anycpu. The default is anycpu.It has nothing to do with optimization. As usual, MSDN is wrong.
-
Hello, a 3rd party supplier informs me their components are compiled for "ANY CPU", so they'll run x86 or x64 based on the platform to which they're deployed. This confuses me a bit; I had thought a select choice of x64 compilation would ensure the best performance, which is why so many companies these days deliver product-installers for both x86 and x64. But if I'm to take his word for good measure, there's no need (at least .net-wise) to ever compile to a specific CPU architecture, as the "ANY CPU" option will always ensure the assemblies run as fast as possible, given the host CPU? Hope someone might be able to clarify on this, thanks in advance, Morten
harleydk wrote:
I had thought a select choice of x64 compilation would ensure the best performance
Wrong. Selecting x64 does NOT give the best performance. This only forces the code to work on a 64-bit processor using the 64-bit .NET Framework. This also give you coding options that are specific to 64-bit. Performance really has nothing to do with it.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Guffa wrote:
The IL code in your assembly isn't specific to any processor at all.
That was also my thought until the OP asked the question and it got me thinking. I then looked at MSDN and this article suggests (although not explicitly to do with the IL output) otherwise: http://msdn.microsoft.com/en-us/library/5b4eyb0k.aspx[^]
* Developer Day Scotland 2 - Free community conference * The Blog of Colin Angus Mackay
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
nice one:[^] - the title is "How to: Optimize an Application for a Specific CPU Type" - for C# the page says "Choose a CPU type from the Platform target list. The options are ..." - and Guffa rightfully says "The IL code in your assembly isn't specific to any processor at all" So the page not only fails to tell you how to decide on the right platform, it also leads you to believe that by choosing you would be optimizing the application. The whole page is crap :~
Luc Pattyn [Forum Guidelines] [My Articles]
Love, happiness and fewer bugs for 2009!
-
nice one:[^] - the title is "How to: Optimize an Application for a Specific CPU Type" - for C# the page says "Choose a CPU type from the Platform target list. The options are ..." - and Guffa rightfully says "The IL code in your assembly isn't specific to any processor at all" So the page not only fails to tell you how to decide on the right platform, it also leads you to believe that by choosing you would be optimizing the application. The whole page is crap :~
Luc Pattyn [Forum Guidelines] [My Articles]
Love, happiness and fewer bugs for 2009!
Yes, very confusing. It even got me and I should have known better. :doh:
* Developer Day Scotland 2 - Free community conference * The Blog of Colin Angus Mackay
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
-
Guffa wrote:
That is not correct. The IL code generated is the same regardless of which CPU target you specify.
Really? I was just paraphrasing this article in MSDN: How to: Optimize an Application for a Specific CPU Type[^]
* Developer Day Scotland 2 - Free community conference * The Blog of Colin Angus Mackay
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
-
harleydk wrote:
I had thought a select choice of x64 compilation would ensure the best performance
Wrong. Selecting x64 does NOT give the best performance. This only forces the code to work on a 64-bit processor using the 64-bit .NET Framework. This also give you coding options that are specific to 64-bit. Performance really has nothing to do with it.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008