Loading ...
Sorry, an error occurred while loading the content.

Re: How fast is your GCD code? Here's mine...

Expand Messages
  • WarrenS
    Yes, as per Brennan s bug fix, the ctz s should be ctzll s. That also speeds it up to 139 nanosec.
    Message 1 of 12 , Jan 3, 2012
    • 0 Attachment
      Yes, as per Brennan's bug fix, the ctz's should be ctzll's.

      That also speeds it up to 139 nanosec.
    • Phil Carmody
      From: WarrenS ... I think Bob S posted his highly tuned code to sci.math, or just possibly the Mersenne Forum, about 5 years ago. It had special cases for
      Message 2 of 12 , Jan 4, 2012
      • 0 Attachment
        From: WarrenS
        > Yes, as per Brennan's bug fix, the
        > ctz's should be ctzll's.
        >
        > That also speeds it up to 139 nanosec.

        I think Bob S posted his highly tuned code to sci.math, or just possibly the Mersenne Forum, about 5 years ago. It had special cases for removing small multiples of the smaller number, which looked like it would annoy branch prediction units, which in theory he should have been taking into account. (I was on an Alpha in those days, and branch prediction was everything, so I was more hypersensitive to such bubbles. However, perhaps the code was good because the ifs were actually quite predictable; you'd need to try it out on a modern machine.)

        Phil
      • Phil Carmody
        From: Jack Brennen ... Which is classic UB. Nacked-by: Phil
        Message 3 of 12 , Jan 4, 2012
        • 0 Attachment
          From: Jack Brennen <jfb@...>
          > Apologies once again, but I don't
          > want to leave broken code out there...

          A noble aim. So why did you overlook this:

          > >>     int64 d;
          > >>       d&= d>>63;     //where 63+1=wordsize of uint64s

          Which is classic UB.

          Nacked-by: Phil
        • Phil Carmody
          From: WarrenS ... It s a sparse enough inner loop that I can easily imagine the increased dependency makes it slower. What s the latency
          Message 4 of 12 , Jan 4, 2012
          • 0 Attachment
            From: WarrenS <warren.wds@...>
            > > > b -= d+d+a;
            > > > a += d; //the obvious "optimization" of this
            > & previous line... makes it slower!
            > > > (...)
            > >
            > >
            > > I can't imagine that
            > > a += d ; b -= d+a
            > > would be slower.
            >
            > --it is slower! On my computer, anyhow.

            It's a sparse enough inner loop that I can easily imagine the increased dependency makes it slower. What's the latency of an add nowadays? I know it's crept up to about 6 in the past decade (at least on the SIMD units). Something like that's a huge bubble, and should definitely be avoided.

            Phil
          Your message has been successfully submitted and would be delivered to recipients shortly.