-
Notifications
You must be signed in to change notification settings - Fork 1
/
pushtest.c
130 lines (112 loc) · 3.79 KB
/
pushtest.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "abce.h"
/*
Invoke this file with the following change:
diff --git a/engine.c b/engine.c
index 1f3242f..7e8aa33 100644
--- a/engine.c
+++ b/engine.c
@@ -1442,7 +1442,20 @@ int abce_engine(struct abce *abce, unsigned char *addcode, size_t addsz)
switch (ins)
{
case ABCE_OPCODE_NOP:
+ {
+ uint8_t b;
+ if (abce_fetch_b(&b, abce, addcode, addsz) != 0)
+ {
+ ret = -EFAULT;
+ break;
+ }
+ if (abce_push_double(abce, (double)(char)b) != 0)
+ {
+ ret = -EFAULT;
+ break;
+ }
break;
+ }
case ABCE_OPCODE_PUSH_DBL:
{
double dbl;
..to prove that a byte-push instruction is not worth it, only giving
approximately 15% speedup.
*/
int main(int argc, char **argv)
{
struct abce abce = {};
abce_init(&abce);
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 1000000);
abce_add_ins(&abce, ABCE_OPCODE_PUSH_TRUE); // stack: iter bool
#if 1
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 10);
abce_add_ins(&abce, ABCE_OPCODE_POP_MANY);
#else
abce_add_ins(&abce, ABCE_OPCODE_NOP);
abce_add_ins(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_NOP);
abce_add_ins(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_NOP);
abce_add_ins(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_NOP);
abce_add_ins(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_NOP);
abce_add_ins(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_NOP);
abce_add_ins(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_NOP);
abce_add_ins(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_NOP);
abce_add_ins(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_NOP);
abce_add_ins(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_NOP);
abce_add_ins(&abce, 5);
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 10);
abce_add_ins(&abce, ABCE_OPCODE_POP_MANY);
#endif
#if 0
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 0);
abce_add_ins(&abce, ABCE_OPCODE_PUSH_STACK); // old val
abce_add_ins(&abce, ABCE_OPCODE_DUMP); // old val
#endif
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 0); // set stack arg 0 // stack: iter bool 0
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 0); // stack: iter bool 0 0
abce_add_ins(&abce, ABCE_OPCODE_PUSH_STACK); // stack: iter bool 0 iter
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 1); // stack: iter bool 0 iter 1
abce_add_ins(&abce, ABCE_OPCODE_SUB); // stack: iter bool 0 iter-1
abce_add_ins(&abce, ABCE_OPCODE_SET_STACK); // stack: iter bool
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 0);
abce_add_ins(&abce, ABCE_OPCODE_PUSH_STACK); // stack: iter bool iter
abce_add_ins(&abce, ABCE_OPCODE_LOGICAL_NOT);
abce_add_ins(&abce, ABCE_OPCODE_PUSH_DBL);
abce_add_double(&abce, 10); // jmp addr, stack: iter bool iter 10
abce_add_ins(&abce, ABCE_OPCODE_IF_NOT_JMP); // stack: iter bool
printf("ret %d\n", abce_engine(&abce, NULL, 0));
return 0;
}