// code by gynvael.coldwind//vx // http://gynvael.coldwind.pl/ #include // External function. extern int find_range(char *dst, const char *str, const char *ranges); // rdtsc by Kazutomo Yoshii. // http://www.mcs.anl.gov/~kazutomo/rdtsc.html #if defined(__i386__) static __inline__ unsigned long long rdtsc(void) { unsigned long long int x; __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); return x; } #elif defined(__x86_64__) static __inline__ unsigned long long rdtsc(void) { unsigned hi, lo; __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 ); } #endif // Testing main. int main(void) { static char dst[1024]; int i; const char *str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed aliquet nibh vel lacus iaculis dignissim. Donec eget tempor erat. Integer nisl erat, auctor eu facilisis a, convallis non ipsum. Integer eget gravida sapien. Fusce sit amet sodales neque. In ornare vulputate velit, vel aliquet libero egestas et. Suspendisse metus velit, tempus commodo iaculis ac, ornare auctor erat. Ut sem urna, tincidunt sed accumsan non, ultrices sed nulla. In fermentum, massa a mollis viverra, odio est venenatis ipsum, a iaculis mi sem commodo lorem. Cras ut dictum libero. Ut eleifend mollis nulla, vel sollicitudin neque tempor eget. Pellentesque lacus risus, bibendum eu tincidunt et, convallis eget risus. Nunc auctor, purus sed ullamcorper porta, risus libero vehicula nisi, vitae ornare lectus dolor ut sapien. Nunc eget metus sed orci viverra aliquam. Suspendisse at quam tellus, sed accumsan lorem. In ullamcorper blandit tortor a mattis. Cras iaculis vulputate turpis id mattis."; //str = "Ala ma kota. Kot ma ale."; int ret; unsigned long long t1, t2; const char *range = "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; range = "az""\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; t1 = rdtsc(); ret = find_range(dst, str, range); t2 = rdtsc(); printf("Ret: %.8x\n", ret); printf("Str: %s\n" "Out: ", str); for(i = 0; str[i]; i++) { if(dst[i]) putchar('*'); else putchar('.'); } putchar('\n'); printf("Idx: "); for(i = 0; str[i]; i++) { printf("%1x", i & 0xf); } putchar('\n'); printf("Time: %u\n", (unsigned int)(t2 - t1)); return 0; }