Fast search of some nibbles in two ints at same offset (C, microoptimisation)

前端 未结 6 873
囚心锁ツ
囚心锁ツ 2021-02-09 01:16

My task is to check (>trillions checks), does two int contain any of predefined pairs of nibbles (first pair 0x2 0x7; second 0xd 0x8). For example:

bit offset:           


        
6条回答
  •  隐瞒了意图╮
    2021-02-09 01:59

    You could possibly throw out some non-matching candidates earlier:

    int nibble_check (uint32_t A, uint32_t B) 
    {
        if ( !(A & B & 0x22222222) && !(A & B & 0x88888888))
           return 0;
        //rest of checking here...
    }
    

提交回复
热议问题