This will help you get started.
lowp ivec4 imod4_2(lowp ivec4 x) { return x - (2 * (x/2)); } lowp ivec4 parselowbits(lowp int x) { // Implement (x % y) where y is known to be the constant 2 // by first dividing x by (8, 4, 2, 1) and then doing a mod // by (2, 2, 2, 2) to generate an int vector. lowp ivec4 numerator = ivec4(x); lowp ivec4 denominator = ivec4(8, 4, 2, 1); lowp ivec4 modNumerator = numerator / denominator; lowp ivec4 modResult = imod4_2(modNumerator); return modResult; } lowp ivec4 parsehighbits(lowp int x) { // Implement (x % y) where y is known to be the constant 2 // by first dividing by (8*16, 4*16, 2*16, 1*16) and then doing a mod // by (2, 2, 2, 2) to generate an int vector. lowp ivec4 numerator = ivec4(x); lowp ivec4 denominator = ivec4(8*16, 4*16, 2*16, 1*16); lowp ivec4 modNumerator = numerator / denominator; lowp ivec4 modResult = imod4_2(modNumerator); return modResult; }
The above functions work on a high low (4 bit) component, such as .rg input vector. Of course, you will need to read the values ββand multiply by 255 to denormalize. Then the AND implementation is simple:
lowp ivec4 and4(lowp ivec4 a, lowp ivec4 b) { lowp ivec4 a_and_b = a * b; return a_and_b; }
Moj
source share