Optimisation of division in gcc

前端 未结 4 1077
無奈伤痛
無奈伤痛 2021-01-17 19:43

Here\'s some code (full program follows later in the question):

template 
T fizzbuzz(T n) {
    T count(0);
    #if CONST
        const T d         


        
4条回答
  •  星月不相逢
    2021-01-17 20:01

    Try combining const int v in your WrappedInt class with const T in your fizzbuzz function and see if the compiler can optimize that.

    By declaring const int you've created a special case - a compile time constant. The compiler knows what the value is, and can optimize it more heavily than a value that could possibly change during the run of the program.

提交回复
热议问题