Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- #include <stdio.h>
- #include <x86intrin.h>
- #define ISODD(n) (n) & 1
- unsigned char max2(unsigned char * x, int n) {
- unsigned char m = *x++;
- for(int i = 0; i < n; i++, x++)
- if(m < *x)
- m = *x;
- return m;
- }
- unsigned char m1(const unsigned char* u8x, int n)
- {
- const uint64_t* u64x = (u8x);
- int i, j;
- unsigned char max = 0;
- for(i = 0, j = 0; i < n; i += 8, j++)
- {
- //"or" and "bitor" are keywords, of course
- uint64_t oR = u64x[j];
- oR |= oR >> 32;
- oR |= oR >> 16;
- oR |= oR >> 8;
- if(oR > (uint64_t)max)
- {
- for(int off = 0; off < 8; off++)
- max = max > u8x[i + off] ? max : u8x[i + off];
- }
- }
- i -= 8;
- for(; i < n; i++)
- max = max > u8x[i] ? max : u8x[i];
- return max;
- }
- int main(void) {
- uint64_t a, b;
- unsigned char ret, array[4096];
- srand(time(NULL));
- for(int i = 0; i < 4096; i++)
- array[i] = rand();
- a = __rdtsc();
- ret = m1(array, 4096);
- printf("you: %llu ", __rdtsc() - a, ret);
- a = __rdtsc();
- ret = max2(array, 4096);
- printf("Hui: %llu", __rdtsc() - a, ret);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement