Created
July 21, 2018 15:52
-
-
Save firatsarlar/59c4ef75459510a6d8d67e6a3c34c53c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint32_t _bperm(const uint32_t a, const uint32_t b, const uint32_t s) { | |
unsigned char input[8], selector[4]; | |
input[0] = a & 0xFF;// x<7:0> | |
input[1] = ( a >> 8 ) & 0xFF; //x<15:8> | |
input[2] = ( a >> 16 ) & 0xFF; //x<23:16> | |
input[3] = ( a >> 24 ) & 0xFF; //x<31:24> | |
input[4] = b & 0xFF;// y<7:0> | |
input[5] = ( b >> 8 ) & 0xFF; //y<15:8> | |
input[6] = ( b >> 16 ) & 0xFF; //y<23:16> | |
input[7] = ( b >> 24 ) & 0xFF; //y<31:24> | |
selector[0] = s & 0x07; // s<2 : 0> | |
selector[1] = ( s >> 4 ) & 0x07; // s<6 : 4> | |
selector[2] = ( s >> 8 ) & 0x07; //s<10 : 8> | |
selector[3] = ( s >> 12 ) & 0x07; //s<14 : 12> | |
uint32_t v = input[selector[3]]; | |
v = (v << 8) + input[selector[2]]; | |
v = (v << 8) + input[selector[1]]; | |
v = (v << 8) + input[selector[0]]; | |
return v; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment