Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. "ANY CPU" compilation - what gives?

"ANY CPU" compilation - what gives?

Scheduled Pinned Locked Moved C#
csharparchitectureperformancequestion
14 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    harleydk
    wrote on last edited by
    #1

    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

    C G D 3 Replies Last reply
    0
    • H harleydk

      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

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      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

      H G 2 Replies Last reply
      0
      • C Colin Angus Mackay

        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

        H Offline
        H Offline
        harleydk
        wrote on last edited by
        #3

        Hello Colin, this was also my impression. Thanks a lot for clearing this up for me. best, Morten

        G 1 Reply Last reply
        0
        • H harleydk

          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

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          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.

          C 1 Reply Last reply
          0
          • C Colin Angus Mackay

            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

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            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.

            C 1 Reply Last reply
            0
            • H harleydk

              Hello Colin, this was also my impression. Thanks a lot for clearing this up for me. best, Morten

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              harleydk wrote:

              Hello Colin, this was also my impression. Thanks a lot for clearing this up for me.

              Then your impression was also wrong.

              Despite everything, the person most likely to be fooling you next is yourself.

              1 Reply Last reply
              0
              • G Guffa

                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.

                C Offline
                C Offline
                Colin Angus Mackay
                wrote on last edited by
                #7

                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.

                G 1 Reply Last reply
                0
                • G Guffa

                  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.

                  C Offline
                  C Offline
                  Colin Angus Mackay
                  wrote on last edited by
                  #8

                  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.

                  D L 2 Replies Last reply
                  0
                  • C Colin Angus Mackay

                    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.

                    D Offline
                    D Offline
                    Daniel Grunwald
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • H harleydk

                      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

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #10

                      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

                      H 1 Reply Last reply
                      0
                      • C Colin Angus Mackay

                        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.

                        L Offline
                        L Offline
                        Luc Pattyn
                        wrote on last edited by
                        #11

                        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!


                        C 1 Reply Last reply
                        0
                        • L Luc Pattyn

                          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!


                          C Offline
                          C Offline
                          Colin Angus Mackay
                          wrote on last edited by
                          #12

                          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.

                          1 Reply Last reply
                          0
                          • C Colin Angus Mackay

                            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.

                            G Offline
                            G Offline
                            Guffa
                            wrote on last edited by
                            #13

                            I saw that one. It doesn't go ino any depth, and I don't think that it's correct. Have a look at this, for example: Visual Studio .NET Platform Target Explained[^]

                            Despite everything, the person most likely to be fooling you next is yourself.

                            1 Reply Last reply
                            0
                            • D Dave Kreskowiak

                              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

                              H Offline
                              H Offline
                              harleydk
                              wrote on last edited by
                              #14

                              Thank you, everyone, for your insight on this issue. Can I ask you, now, how I should go about optimizing my code for x64 processors? Any links you would recommend would be much appreciated. Many thanks, Morten

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups