Announcement

Collapse
No announcement yet.

2*i and i*2

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 2*i and i*2

    Why 2*i is faster than i*2 ?

  • #2
    Indeed, a 2*x is translated to a SHL (shift left), while for a x*2 a normal IMUL is used. It's a "parser" thing, IMHO.

    Bye!
    -- The universe tends toward maximum irony. Don't push it.

    File Extension Seeker - Metasearch engine for file extensions / file types
    Online TrID file identifier | TrIDLib - Identify thousands of file formats

    Comment


    • #3
      I am trying to imagine what made you investigate this phenomenon.

      I am stumped, you win.
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        What difference does it make as to why? He did and was puzzled by the results.

        What I would like to know is how he made the speed comparisons. Just out of idle curiosity, I tried it using TIMER and both came up with zero time. I used the number 5 for the value of I.
        There are no atheists in a fox hole or the morning of a math test.
        If my flag offends you, I'll help you pack.

        Comment


        • #5
          For code that turn into just a couple of Asm instructions, you need to time adequately: either repeating it lots of times, or checking the RTDSC, etc.
          The SHL version turn out about 15% faster, for me (with an Intel Core Duo).

          Bye!
          -- The universe tends toward maximum irony. Don't push it.

          File Extension Seeker - Metasearch engine for file extensions / file types
          Online TrID file identifier | TrIDLib - Identify thousands of file formats

          Comment


          • #6
            If you have PB9/5 you can use TIX too. I got speeds about 2x faster for 2*i.
            Code:
            #COMPILE EXE
            #DIM ALL
            
            FUNCTION PBMAIN () AS LONG
            
                LOCAL i, ii, ii2 AS LONG
                LOCAL t1, t2 AS QUAD, sp AS STRING
                i = 1000000
                TIX t1
                FOR ii = 1 TO 30000000  'warm up loops
                   ii2 = 2 * i
                   ii2 = i * 2
                NEXT
                TIX END t1
            
                TIX t1
                FOR ii = 1 TO 10000000
                   ii2 = 2 * i
                NEXT
                TIX END t1
            
                TIX t2
                FOR ii = 1 TO 10000000
                   ii2 = 2 * i
                NEXT
                TIX END t2
                sp =  "Both 2 * i:" & $CRLF & STR$(t1) & $CRLF & STR$(t2) & $CRLF & "ratio:" & $CRLF & STR$(t2 / t1)
            
                TIX t1
                FOR ii = 1 TO 10000000
                   ii2 = i * 2
                NEXT
                TIX END t1
            
                TIX t2
                FOR ii = 1 TO 10000000
                   ii2 = 2 * i
                NEXT
                TIX END t2
                ? sp & $CRLF & $CRLF & "i * 2 followed by 2 * i:" & $CRLF & STR$(t1) & $CRLF & STR$(t2) & $CRLF & "ratio:" & $CRLF & STR$(t2 / t1)
            
            END FUNCTION

            Comment


            • #7
              Originally posted by Michael Mattias View Post
              I am trying to imagine what made you investigate this phenomenon.

              I am stumped, you win.
              So are you switching to .net?
              I thought the reason most of us used PB was speed, and then knowing how to get the best speed out of it.

              Comment


              • #8
                >I thought the reason most of us used PB was speed,

                I would have guessed the main reason was "ease of use," at least when first getting started.

                I'm sure somewhere in PB's marketing department someone has the totals off the bingo cards you get with every new product where you check off the boxes (please check all which apply, thank you!) in the section, "what made you try this product?"


                MCM
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  'speed'
                  'ease of use'
                  'executable size'
                  '#BLOAT'
                  'No Vapourware'

                  These are a few of our favourite things!
                  Rod
                  I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                  Comment


                  • #10
                    'speed'
                    'ease of use'
                    'executable size'
                    '#BLOAT'
                    'No Vapourware'
                    Shall we also add
                    1. Each concept, not only can a solution be found but the user is willing to share how they found it???
                    2. The deeper you learn, the more you find friends that attempted ideas before you , and after you that can either offer help or need help achieving what they may have long since posted
                    3. PB allows us to "Bridge both worlds" with not only code long forgot vs "Hey HERE is the WIZBANG" and show the reason why each work

                    Personally I think the team at PB has done a PHENOMENAL job at keeping the masses happy, and working on the "Wish-list" and releasing what would best suit the medium, which is why I was drawn to PB and not others given the "New Technology" because the new is REALLY built on the old...but you do not realize it till you get older
                    Engineer's Motto: If it aint broke take it apart and fix it

                    "If at 1st you don't succeed... call it version 1.0"

                    "Half of Programming is coding"....."The other 90% is DEBUGGING"

                    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                    Comment


                    • #11
                      Originally posted by Michael Mattias View Post
                      I am trying to imagine what made you investigate this phenomenon.

                      I am stumped, you win.
                      Gee, haven't you ever been curious? (not to be confused with puzzled)

                      =============================================
                      To be, or not to be: that is the question:
                      Whether 'tis nobler in the mind to suffer
                      The slings and arrows of outrageous fortune,
                      Or to take arms against a sea of troubles ...
                      William Shakespeare (1546-1616)
                      =============================================
                      It's a pretty day. I hope you enjoy it.

                      Gösta

                      JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                      LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                      Comment


                      • #12
                        Gee, haven't you ever been curious? (not to be confused with puzzled)
                        Yes, but not about any potential difference in the way 2*I is compiled versus the way I*2 is compiled.

                        Of course I must confess to having a longtime deep-seated and unshakeable faith in the absolute veracity of the associative law of multiplication.

                        MCM
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          oh god

                          Originally posted by Michael Mattias View Post
                          I am trying to imagine what made you investigate this phenomenon.

                          I am stumped, you win.
                          I've resisted this for a long time, but I finally broke down ... too many grains of sand in the pile.

                          I know you are kind of the big Kahuna around here Michael and respect you for your technical knowledge concerning PB, but you really never give it a rest do you? Consider that not all good ideas, questions (or answers) come from you. I wonder why you feel the need to respond to so many others only to criticize or demean.

                          ok ... before we get into flame wars about who is qualified to say what to who ... I have 3 Engineering degrees too ... you don't see me giving out crap like candy on this site.

                          Now ... I brace and wait for the much expected witty repartee.

                          Comment


                          • #14
                            Originally posted by Rodney Hicks View Post
                            'speed'
                            'ease of use'
                            'executable size'
                            '#BLOAT'
                            'No Vapourware'

                            These are a few of our favourite things!
                            The single "most favorite" thing can be summed up in three word.

                            "Does it work"?

                            If it doesn't work, all other considerations are moot. Get it working first then tweek it later.
                            There are no atheists in a fox hole or the morning of a math test.
                            If my flag offends you, I'll help you pack.

                            Comment


                            • #15
                              What surprised me was how totally out of left field this was.

                              It's like waking up and saying, "today I am going to look for Tupperware on my roof" .. that is, it would never occur to me to look for a performance difference between I*2 and 2*I.

                              I was - and remain - curious as to what inspired this effort.
                              Michael Mattias
                              Tal Systems (retired)
                              Port Washington WI USA
                              [email protected]
                              http://www.talsystems.com

                              Comment


                              • #16
                                Originally posted by Michael Mattias View Post
                                I was - and remain - curious as to what inspired this effort.
                                There are a wide range of possibilities. All the way from +0 to -0. And I don't have any engineering degrees. {grinning needle}

                                =================================
                                "Research is what I'm doing when
                                I don't know what I'm doing."
                                Wernher Von Braun (1912-1977)
                                =================================
                                It's a pretty day. I hope you enjoy it.

                                Gösta

                                JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                                LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                                Comment


                                • #17
                                  I have to agree with Mr. Mattias here; that is an unlikely thing to have looked into. My take on his comment was that he was pleasantly surprised at this find, as was I.

                                  It seems as though everyone is so accustomed to MM's chagrin that when it wasn't there, for a change, you imagined that it was.

                                  Barry

                                  Comment


                                  • #18
                                    Originally posted by Michael Mattias View Post
                                    It's like waking up and saying, "today I am going to look for Tupperware on my roof" .
                                    I get disapointed most days, as I always look on my roof to see if some new gift has arrived, don't you?

                                    Comment


                                    • #19
                                      If PB had just done "multiply" when it sees "*" all this would be moot, you know.

                                      That is, perhaps it should have been a user responsibilty to optimize multiplication and division by integral powers of two using the SHIFT statement provided.
                                      Michael Mattias
                                      Tal Systems (retired)
                                      Port Washington WI USA
                                      [email protected]
                                      http://www.talsystems.com

                                      Comment


                                      • #20
                                        Originally posted by Michael Mattias View Post
                                        If PB had just done "multiply" when it sees "*" all this would be moot, you know.

                                        That is, perhaps it should have been a user responsibilty to optimize multiplication and division by integral powers of two using the SHIFT statement provided.
                                        Sure it's the user's responsibility if the compiler doesn't do it, but it would be nice if the compiler did.

                                        Barry

                                        Comment

                                        Working...
                                        X