GCC 4.4: Avoid range check on switch/case statement in gcc?

前端 未结 6 1114
自闭症患者
自闭症患者 2021-02-05 13:11

This is only an issue on GCC versions prior to 4.4, this was fixed in GCC 4.5.

Is it possible to tell the compiler the variable used in a switch fits within the provided

6条回答
  •  一整个雨季
    2021-02-05 13:49

    This question is certainly interesting from the standpoint of a missed compiler optimization that is seemingly obvious to us, and I did spend considerable time trying to come up with a straightforward solution, largely out of personal curiousity.

    That said, I have to admit I am highly skeptical that this additional instruction will ever result in a measurable performance difference in practice, especially on a new mac. If you have any significant amount of data, you'll be I/O bound, and a single instruction will never be your bottleneck. If you have a tiny amount of data, then you'll need to perform a lot lot lot of calculations repeatedly before a single instruction will become a bottleneck.

    Would you post some code to show that there really is a performance difference? Or describe the code and data your working with?

提交回复
热议问题