you are viewing a single comment's thread
view the rest of the comments
[–] 3 points 2 years ago (1 child)

Godbolt to the rescue! So gcc 13.2 certainly does produce the same code, though a lot of other versions and compilers do it slightly differently. Surprisingly, clang doesn't optimise this and uses idiv for the modulo version.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 1 point 2 years ago

    Awesome, thank you for that link. I should have guessed this was a thing but it hadn't even occurred to me.

    And yeah, it is surprising that clang doesn't treat mod power of 2 as a special case. It looks like I can't type in code on mobile, does clang handle divide by power of 2 as a idiv or shift?

  • source
  • parent