Emulating variable bit-shift using only constant shifts?

后端 未结 8 1253
清歌不尽
清歌不尽 2020-12-09 19:19

I\'m trying to find a way to perform an indirect shift-left/right operation without actually using the variable shift op or any branches.

The particular PowerPC pro

8条回答
  •  攒了一身酷
    2020-12-09 19:57

    Here's something that is trivially unrollable:

    int result= value;
    
    int shift_accumulator= value;
    
    for (int i= 0; i<5; ++i)
    {
        result += shift_accumulator & (-(k & 1)); // replace with isel if appropriate
        shift_accumulator += shift_accumulator;
        k >>= 1;
    }
    

提交回复
热议问题