Compiler optimizations

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • user923005

    #16
    Re: Compiler optimizations

    On Jan 16, 11:34 am, Randy Howard <randyhow...@FO OverizonBAR.net >
    wrote:
    On Wed, 16 Jan 2008 05:24:07 -0600, Joachim Schmitz wrote
    (in article <fmkpgn$v3...@o nline.de>):
    >
    >
    >
    >
    >
    Kelsey Bjarnason wrote:
    On Wed, 16 Jan 2008 00:43:25 +0100, sammy wrote:
    >
    >Word up!
    >
    >If there are any gcc users here, maybe you could help me out. I have
    >a program and I've tried compiling it with -O2 and -O3 optimization
    >settings.
    >
    >The wired thing is that it actually runs faster with -O2 than with
    >-O3, even though -O3 is a higher optimization setting.
    >
    >Have I found a bug in gcc? Could I be doing something wrong?
    >
    One point to ponder, which isn't specific to gcc but to optimisation
    in general...
    >
    Many optimisations consume more space than the less optimised code.
    Loop unrolling, for example, can do this.  While this _can_ result in
    faster code, it can _also_ potentially result in side effects such as
    exhausting the cache memory.  The net result can be a significant
    slowdown.
    >
    This sort of thing isn't really a bug; the optimiser has no way to
    know what machines the code will run on.
    If not the compiler/optimizer, who else?
    >
    How can it possibly know which computer(s) you will install and run it
    on after it is compiled?  
    GCC aside:
    -march is supposed to be a promise of that. If you run it on
    something else then you won't get the sort of performance you were
    hoping for. Many other compilers have this same sort of effect (even
    producing code that will only run on certain CPUs in some instances).
    Not every program is something for you to play with for a bit in ~/src
    then forget about.  ;-)
    Rats. How deflating.

    Comment

    • Chris Dollin

      #17
      Re: Compiler optimizations

      Randy Howard wrote:
      On Wed, 16 Jan 2008 05:24:07 -0600, Joachim Schmitz wrote
      (in article <fmkpgn$v36$1@o nline.de>):
      >
      >>This sort of thing isn't really a bug; the optimiser has no way to
      >>know what machines the code will run on.
      >If not the compiler/optimizer, who else?
      >
      How can it possibly know which computer(s) you will install and run it
      on after it is compiled?
      The optimizer could run on the target machine, so "this one"
      would be the appropriate answer.

      [Warning: mere possibility isn't evidence of implementation.]

      --
      Contains Billion-Year-Old Materials Hedgehog
      Otherface: Jena RDF/Owl toolkit http://jena.sourceforge.net/

      Comment

      • jacob navia

        #18
        Re: Compiler optimizations

        Chris Dollin wrote:
        Randy Howard wrote:
        >
        >On Wed, 16 Jan 2008 05:24:07 -0600, Joachim Schmitz wrote
        >(in article <fmkpgn$v36$1@o nline.de>):
        >>
        >>>This sort of thing isn't really a bug; the optimiser has no way to
        >>>know what machines the code will run on.
        >>If not the compiler/optimizer, who else?
        >How can it possibly know which computer(s) you will install and run it
        >on after it is compiled?
        >
        The optimizer could run on the target machine, so "this one"
        would be the appropriate answer.
        >
        [Warning: mere possibility isn't evidence of implementation.]
        >
        Shipping the optimizer with your application?



        --
        jacob navia
        jacob at jacob point remcomp point fr
        logiciels/informatique

        Comment

        • Randy Howard

          #19
          Re: Compiler optimizations

          On Wed, 16 Jan 2008 15:48:56 -0600, user923005 wrote
          (in article
          <d1de1901-7a6b-4e75-b819-ff7be1539cb9@z1 7g2000hsg.googl egroups.com>):
          On Jan 16, 11:34 am, Randy Howard <randyhow...@FO OverizonBAR.net >
          wrote:
          >>
          >>>This sort of thing isn't really a bug; the optimiser has no way to
          >>>know what machines the code will run on.
          >>If not the compiler/optimizer, who else?
          >>
          >How can it possibly know which computer(s) you will install and run it
          >on after it is compiled?  
          >
          GCC aside:
          -march is supposed to be a promise of that. If you run it on
          something else then you won't get the sort of performance you were
          hoping for. Many other compilers have this same sort of effect (even
          producing code that will only run on certain CPUs in some instances).
          >
          I think you missed what I was saying there. You can optimize with
          something like -march for a specific hardware type, but when you move
          that binary to other machines it isn't a promise of anything, it may
          not even run properly.


          --
          Randy Howard (2reply remove FOOBAR)
          "The power of accurate observation is called cynicism by those
          who have not got it." - George Bernard Shaw





          Comment

          • CJ

            #20
            Re: Compiler optimizations

            On 16 Jan 2008 at 22:20, jacob navia wrote:
            Chris Dollin wrote:
            >The optimizer could run on the target machine, so "this one"
            >would be the appropriate answer.
            >>
            >[Warning: mere possibility isn't evidence of implementation.]
            >>
            >
            Shipping the optimizer with your application?
            Yes, though that rather depends on shipping the source code with your
            application too, so it wouldn't be much use for closed-source programs
            like lcc-win for example...

            Comment

            • Rui Maciel

              #21
              Re: Compiler optimizations

              Randy Howard wrote:
              I think you missed what I was saying there.  You can optimize with
              something like -march for a specific hardware type, but when you move
              that binary to other machines it isn't a promise of anything, it may
              not even run properly.
              Where exactly is there a need to run a single, unique binary across a whole
              range of different machines? Why should anyone want that?

              Assuming that open source software isn't even being considered here, I don't
              see how, in this day and age, a distributor of closed-source, proprietary
              software is barred from shipping multiple binaries in the install media or
              even making it available over the internet. I mean, in this day and age,
              software is being distributed through DVD packs and even through the net.
              Where exactly is it impossible to pack a hand full of specialised binaries
              in the install media and then pick the more appropriate binary for the
              current system?


              Rui Maciel

              Comment

              • Rui Maciel

                #22
                Re: Compiler optimizations

                jacob navia wrote:
                Shipping the optimizer with your application?
                There was a time where operating systems also came with a compiler. Heck, it
                is still happening in this very day. Nowadays there are quite a lot of
                operating systems installing compilers in their default configuration. Take
                all those linux distributions, for example. Thanks to that, we see
                companies like nvidia relying on the system's compiler to install their
                software.


                Rui Maciel

                Comment

                • Randy Howard

                  #23
                  Re: Compiler optimizations

                  On Wed, 16 Jan 2008 20:08:54 -0600, Rui Maciel wrote
                  (in article <478eb8b3$0$176 77$a729d347@new s.telepac.pt>):
                  Randy Howard wrote:
                  >
                  >I think you missed what I was saying there.  You can optimize with
                  >something like -march for a specific hardware type, but when you move
                  >that binary to other machines it isn't a promise of anything, it may
                  >not even run properly.
                  >
                  Where exactly is there a need to run a single, unique binary across a whole
                  range of different machines? Why should anyone want that?
                  It's the model that pretty much all ISV's use. <insert list of 20,000
                  canned apps here>
                  Assuming that open source software isn't even being considered here, I don't
                  see how, in this day and age, a distributor of closed-source, proprietary
                  software is barred from shipping multiple binaries in the install media or
                  even making it available over the internet.
                  It's not barred from it, technically. It's cost prohibitive to build
                  and test a lot of versions of the same program just to micro-optimize
                  for a bunch of slightly different processors, cache sizes, etc.


                  --
                  Randy Howard (2reply remove FOOBAR)
                  "The power of accurate observation is called cynicism by those
                  who have not got it." - George Bernard Shaw





                  Comment

                  • Kelsey Bjarnason

                    #24
                    Re: Compiler optimizations

                    On Wed, 16 Jan 2008 12:24:07 +0100, Joachim Schmitz wrote:
                    Kelsey Bjarnason wrote:
                    >On Wed, 16 Jan 2008 00:43:25 +0100, sammy wrote:
                    >>
                    >>Word up!
                    >>>
                    >>If there are any gcc users here, maybe you could help me out. I have a
                    >>program and I've tried compiling it with -O2 and -O3 optimization
                    >>settings.
                    >>>
                    >>The wired thing is that it actually runs faster with -O2 than with
                    >>-O3, even though -O3 is a higher optimization setting.
                    >>>
                    >>Have I found a bug in gcc? Could I be doing something wrong?
                    >>
                    >One point to ponder, which isn't specific to gcc but to optimisation in
                    >general...
                    >>
                    >Many optimisations consume more space than the less optimised code.
                    >Loop unrolling, for example, can do this. While this _can_ result in
                    >faster code, it can _also_ potentially result in side effects such as
                    >exhausting the cache memory. The net result can be a significant
                    >slowdown.
                    >>
                    >This sort of thing isn't really a bug; the optimiser has no way to know
                    >what machines the code will run on.
                    If not the compiler/optimizer, who else?
                    Suppose I write code optimized for, oh, pentiums. There are something
                    like 197 different flavours of pentiums, with different cache sizes,
                    pipleine depths, who knows what sort of differences.

                    How does the optimizer know which of those you're going to run the code
                    on? Perhaps you'll distribute the app and it will have to run on all of
                    them. Tomorrow's "mini pentium" for embedded systems might have the full
                    instruction set, but almost no cache - shall the optimizer predict the
                    future to tell you might, someday, want to run the binary on this chip?

                    All it can do is generate the code, as efficiently as possible... and let
                    _you_, the developer, see whether the code generated really was as
                    efficient as it should have been, then either accept it, or re-compile
                    with different optimization settings.

                    Comment

                    • Gordon Burditt

                      #25
                      Re: Compiler optimizations

                      >I think you missed what I was saying there.  You can optimize with
                      >something like -march for a specific hardware type, but when you move
                      >that binary to other machines it isn't a promise of anything, it may
                      >not even run properly.
                      >
                      >Where exactly is there a need to run a single, unique binary across a whole
                      >range of different machines? Why should anyone want that?
                      It simplifies virus-writing a lot.

                      Comment

                      • Keith Thompson

                        #26
                        Re: [OT] Compiler optimizations

                        Rui Maciel <rui.maciel@gma il.comwrites:
                        [snip]
                        Moreover, please do have in mind that there are quite a few free software
                        projects, even whole operating system distributions, that distribute
                        multiple versions of binaries optimised to specific target platforms? The
                        people behind those projects distribute those binaries on public
                        repositories open to all and we don't see them bankrupting. How exactly are
                        the people behind all those free software distributions able to produce
                        optimised binaries and offer them to everyone interested without charging a
                        single cent for their work while, according to your statement, the cost for
                        proprietary software distributors to do an irrelevant fraction of that same
                        work would be "prohibitiv e", specially when they charge quite a bit over 50
                        euros for each download/DVD?
                        For a free software project, the cost of customized builds for
                        multiple systems is (a) building and testing the software for each
                        variant target and (b) providing multiple versions on the download
                        site. A user who downloaded the wrong variant can just go back and
                        download the right one.

                        To do the same for a commercial product, you'd have added production
                        costs (packaging, keeping track of different versions on DVDs, etc.)
                        -- and a customer who finds he bought the wrong variant is likely to
                        have more trouble straightening it out; in the worst case, he might
                        have to pay for the product again.

                        I'm sure there are ways to work around these issues. I'm also sure
                        there are better places for this discussion.

                        --
                        Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
                        Nokia
                        "We must do something. This is something. Therefore, we must do this."
                        -- Antony Jay and Jonathan Lynn, "Yes Minister"

                        Comment

                        • Rui Maciel

                          #27
                          Re: Compiler optimizations

                          Gordon Burditt wrote:
                          How much do the tech support calls from people who don't know what
                          to download cost?  If you're distributing an OS, this might not be
                          much of a problem, but if you're distributing an application, good
                          luck.  Some people don't know how to tell if their desktop is a PC
                          or a Mac, much less whether it's got an Intel vs. AMD processor,
                          or whether it's dual-core.  And a lot of people know they are
                          running Windows, but don't recognize such terms as "XP", "Vista",
                          "Windows 98", etc.
                          The tech support reference is a bit absurd. We see free software supporting
                          a vast set of architectures but they don't suffer from any support issue.
                          Moreover, there is even absolutely no need for the user to know those
                          details, as even microsoft's windows line of operating systems benefits
                          from automatic package deployment. It's just a matter of checking the
                          relevant system properties and deploy the right binary. So what stops
                          anyone from shipping specialized binaries?


                          Rui Maciel

                          Comment

                          • Randy Howard

                            #28
                            Re: Compiler optimizations

                            On Sun, 20 Jan 2008 16:32:18 -0600, Rui Maciel wrote
                            (in article <4793cc0d$0$165 82$a729d347@new s.telepac.pt>):
                            Gordon Burditt wrote:
                            >
                            >How much do the tech support calls from people who don't know what
                            >to download cost?  If you're distributing an OS, this might not be
                            >much of a problem, but if you're distributing an application, good
                            >luck.  Some people don't know how to tell if their desktop is a PC
                            >or a Mac, much less whether it's got an Intel vs. AMD processor,
                            >or whether it's dual-core.  And a lot of people know they are
                            >running Windows, but don't recognize such terms as "XP", "Vista",
                            >"Windows 98", etc.
                            >
                            The tech support reference is a bit absurd. We see free software supporting
                            a vast set of architectures but they don't suffer from any support issue.
                            Right, because for the bulk of the open source community, no formal
                            support is available at all. It's a non-issue. The rest of the world
                            does not behave identically though.
                            Moreover, there is even absolutely no need for the user to know those
                            details, as even microsoft's windows line of operating systems benefits
                            from automatic package deployment.
                            When it works. It still doesn't make it free to develop 10 packages
                            instead of 1, test them, package them, then test the deployment via
                            package managers, in 10X the number of cases.
                            It's just a matter of checking the
                            relevant system properties and deploy the right binary.
                            It's not that simple.
                            So what stops anyone from shipping specialized binaries?
                            Reality.


                            --
                            Randy Howard (2reply remove FOOBAR)
                            "The power of accurate observation is called cynicism by those
                            who have not got it." - George Bernard Shaw





                            Comment

                            • jacob navia

                              #29
                              Re: Compiler optimizations

                              Rui Maciel wrote:
                              The tech support reference is a bit absurd. We see free software supporting
                              a vast set of architectures but they don't suffer from any support issue.
                              Moreover, there is even absolutely no need for the user to know those
                              details, as even microsoft's windows line of operating systems benefits
                              from automatic package deployment. It's just a matter of checking the
                              relevant system properties and deploy the right binary. So what stops
                              anyone from shipping specialized binaries?
                              >
                              The show stopper is the fact that you would have to TEST each
                              of the binaries before you ship it.


                              --
                              jacob navia
                              jacob at jacob point remcomp point fr
                              logiciels/informatique

                              Comment

                              • Stephen Sprunk

                                #30
                                Re: Compiler optimizations

                                "Rui Maciel" <rui.maciel@gma il.comwrote in message
                                news:4793cc0d$0 $16582$a729d347 @news.telepac.p t...
                                Gordon Burditt wrote:
                                >How much do the tech support calls from people who don't know what
                                >to download cost? If you're distributing an OS, this might not be
                                >much of a problem, but if you're distributing an application, good
                                >luck. Some people don't know how to tell if their desktop is a PC
                                >or a Mac, much less whether it's got an Intel vs. AMD processor,
                                >or whether it's dual-core. And a lot of people know they are
                                >running Windows, but don't recognize such terms as "XP", "Vista",
                                >"Windows 98", etc.
                                >
                                The tech support reference is a bit absurd. We see free software
                                supporting
                                a vast set of architectures but they don't suffer from any support issue.
                                Moreover, there is even absolutely no need for the user to know those
                                details, as even microsoft's windows line of operating systems benefits
                                from automatic package deployment. It's just a matter of checking the
                                relevant system properties and deploy the right binary. So what stops
                                anyone from shipping specialized binaries?
                                Support costs. Even if you can automatically install the correct binary on
                                each machine, you still have to test all of the individual binaries in QA,
                                and you have to troubleshoot the correct ones when customers find problems.
                                This is why many companies are still shipping binaries that are compiled for
                                original Pentiums with low optimization settings and debug symbols -- it's
                                easier to support, and it works, if not optimally, on every system their
                                customers own.

                                The FOSS crowd has it a bit easier since they don't have to support
                                anything, so each user can compile the software however they want. Notice
                                that those for-profit companies that do support FOSS often require customers
                                run the binaries _they_ compiled.

                                S

                                --
                                Stephen Sprunk "God does not play dice." --Albert Einstein
                                CCIE #3723 "God is an inveterate gambler, and He throws the
                                K5SSS dice at every possible opportunity." --Stephen Hawking

                                Comment

                                Working...