Assuming the machine is little-endian, a reversed chain of contiguous unsigned icmps could be merged. For example,
struct Foo {
unsigned short n;
unsigned char o;
unsigned char p;
};
int compare(struct Foo *f1, struct Foo *f2) {
if (f1->p > f2->p)
return 1;
if (f1->p < f2->p)
return -1;
if (f1->o > f2->o)
return 1;
if (f1->o < f2->o)
return -1;
if (f1->n > f2->n)
return 1;
if (f1->n < f2->n)
return -1;
return 0;
}
the function compare() could be transformed as below,
int compare(struct Foo *f1, struct Foo *f2) {
unsigned int a = *(unsigned int *)&(f1->n);
unsigned int b = *(unsigned int *)&(f2->n);
return a > b ? 1 : a < b ? -1 : 0;
}
This kind of pattern is found in velvet (a de novo genome assembler), more specificly the hot function compareKmers().
Assuming the machine is little-endian, a reversed chain of contiguous unsigned icmps could be merged. For example,
the function
compare()
could be transformed as below,This kind of pattern is found in velvet (a de novo genome assembler), more specificly the hot function
compareKmers()
.