-
Notifications
You must be signed in to change notification settings - Fork 2
/
asm_optimize.c
32 lines (25 loc) · 940 Bytes
/
asm_optimize.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "asm_common.h"
#define INSERT_HERE(i, x) vector_insert(*data, n - vector_begin(*data) + (i), (x))
#define ERASE_HERE(i) vector_erase(*data, n - vector_begin(*data) + (i))
#define HAS(x) ((uintptr_t) (n - vector_begin(*data) - (x)) > vector_size(*data))
// optlevel = 1: optimize for size
// optlevel = 2: optimize for speed
void asm_optimize(vector(struct node_t) * data, int optlevel) {
uint8_t changed = 1;
while(changed) {
changed = 0;
for(uint32_t idx = 0; idx < vector_size(*data); idx++) {
struct node_t * n = (*data) + idx;
switch(n->type) {
case XCHG:
if(HAS(1) && n[1].type == XCHG) {
// cancel out XCHG / XCHG
ERASE_HERE(0);
ERASE_HERE(0);
changed = 1;
}
break;
}
}
}
}