47 static const int c[16] = { 0,1,1,2, 1,2,2,3, 1,2,2,3, 2,3,3,4 };
48 return c[x & 15] + c[(x>>4) & 15] +
49 c[(x>>8) & 15] + c[(x>>12) & 15] +
50 c[(x>>16) & 15] + c[(x>>20) & 15] +
51 c[(x>>24) & 15] + c[(x>>28) & 15];
57 int *pa = (
int *) a, *pb = (
int *) b;
67 int n_opcodes,
int bit_mask)
69 int i, maxlen, curlen;
71 for (i=0; i<n_opcodes; i++)
72 tmp_table[i] = opcodes[i] & bit_mask;
74 qsort(tmp_table, n_opcodes,
sizeof(
int),
cmpfunc);
77 for (i=1; i<n_opcodes; i++)
78 if (tmp_table[i] == tmp_table[i-1]) {
89 int main(
int argc,
char *argv[])
91 FILE *
f = fopen(
"cpu_arm_multi.txt",
"r");
93 const int max = 10000;
98 int bit_mask, best_bit_mask, best_bit_mask_len;
101 fprintf(stderr,
"usage: %s n\n", argv[0]);
102 fprintf(stderr,
"where n=6 might be a good choice\n");
109 fprintf(stderr,
"could not open cpu_arm_multi.txt\n");
116 s[0] = s[
sizeof(s)-1] =
'\0';
117 fgets(s,
sizeof(s),
f);
119 if (n_opcodes > max) {
120 fprintf(stderr,
"too many opcodes\n");
123 opcode[n_opcodes++] = strtol(s, NULL, 0);
127 printf(
"nr of opcodes = %i\n", n_opcodes);
129 max_len = malloc(
sizeof(
int) * (1 << 25));
130 if (max_len == NULL) {
131 fprintf(stderr,
"out of memory\n");
135 best_bit_mask_len = -1;
137 for (bit_mask = 0; bit_mask <= 0x01ffffff; bit_mask ++) {
139 if (bit_mask & 0x00400000)
147 tmp_table, n_opcodes, bit_mask);
149 if (best_bit_mask_len == -1 ||
150 max_len[bit_mask] < best_bit_mask_len) {
151 best_bit_mask_len = max_len[bit_mask];
152 best_bit_mask = bit_mask;
153 printf(
"best bit_mask so far: 0x%08x: %i\n",
154 best_bit_mask, best_bit_mask_len);