Hacker News new | ask | show | jobs
by jart 1590 days ago
That's lovely. I missed it when reading the article. It's also the winner on AMD Zen architecture based on MCA analysis.

    unsigned midpoint(unsigned a, unsigned b) {
      asm("add\t%1,%0\n\t"
          "rcr\t%0"
          : "+r"(a)
          : "r"(b));
      return a;
    }
Although `(a & b) + (a ^ b) / 2` is probably the more conservative choice.