Created
July 21, 2016 13:38
-
-
Save RoyBellingan/231833ed3510a9fda5fd664270524915 to your computer and use it in GitHub Desktop.
STRCleaner1
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
| #include <emmintrin.h> | |
| void STRCleaner1(char * a, int siz){ | |
| __m64* base; | |
| __m64* mask1; | |
| __m64* mask2; | |
| __m64* res = new __m64(); | |
| quint64* opt; | |
| quint64* mask1_safe; | |
| quint64* mask2_safe; | |
| quint64* base_safe; | |
| quint8* b3; | |
| //For debug | |
| // __m128i* cry; | |
| // __m128i* cry2; | |
| // cry= (__m128i*)res; | |
| base = (__m64*)a; | |
| base_safe = (quint64*)a; | |
| quint8 b1[8] = {92,92,92,92,92,92,92,92}; /* is a \ */ | |
| mask1 = (__m64*)&b1; | |
| mask1_safe = (quint64*)&b1; | |
| quint8 b2[8] = {0}; /* \ */ | |
| mask2 = (__m64*)&b2; | |
| mask2_safe = (quint64*)&b2; | |
| opt = (quint64*)res; | |
| b3 = (quint8*)res; | |
| const char * n = "n"; | |
| const char * r = "r"; | |
| const char * t = "t"; | |
| quint8 byte = 8; | |
| siz=siz / byte; | |
| quint32 off = 0; | |
| for(int i = 0; i < siz; i+=1){ | |
| //Used to debug -.- | |
| //cry2 = (__m128i*) (base+i); | |
| //*/ Normal execution, but valgrind will fail on those instruction -.- | |
| *res = _mm_xor_si64(*(base+i),*mask1); | |
| *res = _mm_cmpeq_pi8(*res,*mask2); | |
| if( *opt > 0){ | |
| for(int j=0; j < byte; j++){ | |
| if(b3[j] == 255){ //if a slash was founded | |
| off = i * byte + j; | |
| if( a[ off + 1] == *n || a[ off + 1] == *r || a[off + 1] == *t ){ | |
| a[off] = 32; | |
| a[++off] = 32; | |
| } | |
| } | |
| } | |
| } | |
| /*/ //Valgrind Safe | |
| *opt = *(base_safe+i) ^ *mask1_safe; | |
| if( *opt > 0){ | |
| for(int j=0; j < byte; j++){ | |
| if(b3[j] == 255){ //if a slash was founded | |
| off = i * byte + j; | |
| if( a[ off + 1] == *n || a[ off + 1] == *r || a[off + 1] == *t ){ | |
| a[off] = 32; | |
| a[++off] = 32; | |
| } | |
| } | |
| } | |
| } | |
| //*/ | |
| } | |
| return; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment