sljitTest.c revision 1.6 1 /* $NetBSD: sljitTest.c,v 1.6 2015/05/09 13:16:42 christos Exp $ */
2
3 /*
4 * Stack-less Just-In-Time compiler
5 *
6 * Copyright 2009-2010 Zoltan Herczeg (hzmester (at) freemail.hu). All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without modification, are
9 * permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright notice, this list of
12 * conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
15 * of conditions and the following disclaimer in the documentation and/or other materials
16 * provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21 * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
23 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 /* Must be the first one. Must not depend on any other include. */
30 #include "sljitLir.h"
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 #if defined _WIN32 || defined _WIN64
37 #define COLOR_RED
38 #define COLOR_GREEN
39 #define COLOR_ARCH
40 #define COLOR_DEFAULT
41 #else
42 #define COLOR_RED "\33[31m"
43 #define COLOR_GREEN "\33[32m"
44 #define COLOR_ARCH "\33[33m"
45 #define COLOR_DEFAULT "\33[0m"
46 #endif
47
48 union executable_code {
49 void* code;
50 sljit_sw (SLJIT_CALL *func0)(void);
51 sljit_sw (SLJIT_CALL *func1)(sljit_sw a);
52 sljit_sw (SLJIT_CALL *func2)(sljit_sw a, sljit_sw b);
53 sljit_sw (SLJIT_CALL *func3)(sljit_sw a, sljit_sw b, sljit_sw c);
54 };
55 typedef union executable_code executable_code;
56
57 static sljit_si successful_tests = 0;
58 static sljit_si verbose = 0;
59 static sljit_si silent = 0;
60
61 #define FAILED(cond, text) \
62 if (SLJIT_UNLIKELY(cond)) { \
63 printf(text); \
64 return; \
65 }
66
67 #define CHECK(compiler) \
68 do { \
69 if (compiler == NULL) { \
70 printf("Can't create compiler\n"); \
71 return; \
72 } \
73 if (sljit_get_compiler_error(compiler) != SLJIT_ERR_COMPILED) { \
74 printf("Compiler error: %d\n", \
75 sljit_get_compiler_error(compiler)); \
76 sljit_free_compiler(compiler); \
77 return; \
78 } \
79 } while (/*CONSTCOND*/0)
80
81 static void cond_set(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_si type)
82 {
83 /* Testing both sljit_emit_op_flags and sljit_emit_jump. */
84 struct sljit_jump* jump;
85 struct sljit_label* label;
86
87 sljit_emit_op_flags(compiler, SLJIT_MOV, dst, dstw, SLJIT_UNUSED, 0, type);
88 jump = sljit_emit_jump(compiler, type);
89 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_KEEP_FLAGS, dst, dstw, dst, dstw, SLJIT_IMM, 2);
90 label = sljit_emit_label(compiler);
91 sljit_set_label(jump, label);
92 }
93
94 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
95
96 #define MALLOC_EXEC(result, size) \
97 result = SLJIT_MALLOC_EXEC(size); \
98 if (!result) { \
99 printf("Cannot allocate executable memory\n"); \
100 return; \
101 } \
102 memset(result, 255, size);
103
104 static void test_exec_allocator(void)
105 {
106 /* This is not an sljit test. */
107 void *ptr1;
108 void *ptr2;
109 void *ptr3;
110
111 if (verbose)
112 printf("Run executable allocator test\n");
113
114 MALLOC_EXEC(ptr1, 32);
115 MALLOC_EXEC(ptr2, 512);
116 MALLOC_EXEC(ptr3, 512);
117 SLJIT_FREE_EXEC(ptr2);
118 SLJIT_FREE_EXEC(ptr3);
119 SLJIT_FREE_EXEC(ptr1);
120 MALLOC_EXEC(ptr1, 262104);
121 MALLOC_EXEC(ptr2, 32000);
122 SLJIT_FREE_EXEC(ptr1);
123 MALLOC_EXEC(ptr1, 262104);
124 SLJIT_FREE_EXEC(ptr1);
125 SLJIT_FREE_EXEC(ptr2);
126 MALLOC_EXEC(ptr1, 512);
127 MALLOC_EXEC(ptr2, 512);
128 MALLOC_EXEC(ptr3, 512);
129 SLJIT_FREE_EXEC(ptr2);
130 MALLOC_EXEC(ptr2, 512);
131 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
132 sljit_free_unused_memory_exec();
133 #endif
134 SLJIT_FREE_EXEC(ptr3);
135 SLJIT_FREE_EXEC(ptr1);
136 SLJIT_FREE_EXEC(ptr2);
137 #if (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK)
138 /* Just call the global locks. */
139 sljit_grab_lock();
140 sljit_release_lock();
141 #endif
142
143 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
144 sljit_free_unused_memory_exec();
145 #endif
146 }
147
148 #undef MALLOC_EXEC
149
150 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
151
152 static void test1(void)
153 {
154 /* Enter and return from an sljit function. */
155 executable_code code;
156 struct sljit_compiler* compiler = sljit_create_compiler();
157
158 if (verbose)
159 printf("Run test1\n");
160
161 FAILED(!compiler, "cannot create compiler\n");
162
163 /* 3 arguments passed, 3 arguments used. */
164 sljit_emit_enter(compiler, 3, 3, 3, 0);
165 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_SAVED_REG2, 0);
166
167 SLJIT_ASSERT(sljit_get_generated_code_size(compiler) == 0);
168 code.code = sljit_generate_code(compiler);
169 CHECK(compiler);
170 SLJIT_ASSERT(compiler->error == SLJIT_ERR_COMPILED);
171 SLJIT_ASSERT(sljit_get_generated_code_size(compiler) > 0);
172 sljit_free_compiler(compiler);
173
174 FAILED(code.func3(3, -21, 86) != -21, "test1 case 1 failed\n");
175 FAILED(code.func3(4789, 47890, 997) != 47890, "test1 case 2 failed\n");
176
177 sljit_free_code(code.code);
178 successful_tests++;
179 }
180
181 static void test2(void)
182 {
183 /* Test mov. */
184 executable_code code;
185 struct sljit_compiler* compiler = sljit_create_compiler();
186 sljit_sw buf[8];
187 static sljit_sw data[2] = { 0, -9876 };
188
189 if (verbose)
190 printf("Run test2\n");
191
192 FAILED(!compiler, "cannot create compiler\n");
193
194 buf[0] = 5678;
195 buf[1] = 0;
196 buf[2] = 0;
197 buf[3] = 0;
198 buf[4] = 0;
199 buf[5] = 0;
200 buf[6] = 0;
201 buf[7] = 0;
202 sljit_emit_enter(compiler, 1, 3, 2, 0);
203 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_UNUSED, 0, SLJIT_MEM0(), (sljit_sw)&buf);
204 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 9999);
205 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG1, 0);
206 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
207 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, sizeof(sljit_sw));
208 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SCRATCH_REG2), 0);
209 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 2);
210 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SAVED_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SCRATCH_REG2), 0);
211 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 3);
212 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SAVED_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM0(), (sljit_sw)&buf);
213 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
214 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), (sljit_sw)&data);
215 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 4 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
216 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (sljit_sw)&buf - 0x12345678);
217 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), 0x12345678);
218 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 5 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
219 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 3456);
220 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, (sljit_sw)&buf - 0xff890 + 6 * sizeof(sljit_sw));
221 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0xff890, SLJIT_SCRATCH_REG1, 0);
222 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, (sljit_sw)&buf + 0xff890 + 7 * sizeof(sljit_sw));
223 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG2), -0xff890, SLJIT_SCRATCH_REG1, 0);
224 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0);
225
226 code.code = sljit_generate_code(compiler);
227 CHECK(compiler);
228 sljit_free_compiler(compiler);
229
230 FAILED(code.func1((sljit_sw)&buf) != 9999, "test2 case 1 failed\n");
231 FAILED(buf[1] != 9999, "test2 case 2 failed\n");
232 FAILED(buf[2] != 9999, "test2 case 3 failed\n");
233 FAILED(buf[3] != 5678, "test2 case 4 failed\n");
234 FAILED(buf[4] != -9876, "test2 case 5 failed\n");
235 FAILED(buf[5] != 5678, "test2 case 6 failed\n");
236 FAILED(buf[6] != 3456, "test2 case 6 failed\n");
237 FAILED(buf[7] != 3456, "test2 case 6 failed\n");
238
239 sljit_free_code(code.code);
240 successful_tests++;
241 }
242
243 static void test3(void)
244 {
245 /* Test not. */
246 executable_code code;
247 struct sljit_compiler* compiler = sljit_create_compiler();
248 sljit_sw buf[5];
249
250 if (verbose)
251 printf("Run test3\n");
252
253 FAILED(!compiler, "cannot create compiler\n");
254 buf[0] = 1234;
255 buf[1] = 0;
256 buf[2] = 9876;
257 buf[3] = 0;
258 buf[4] = 0x12345678;
259
260 sljit_emit_enter(compiler, 1, 3, 1, 0);
261 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_UNUSED, 0, SLJIT_MEM0(), (sljit_sw)&buf);
262 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
263 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM0(), (sljit_sw)&buf[1], SLJIT_MEM0(), (sljit_sw)&buf[1]);
264 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
265 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 2);
266 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, (sljit_sw)&buf[4] - 0xff0000 - 0x20);
267 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, (sljit_sw)&buf[4] - 0xff0000);
268 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0xff0000 + 0x20, SLJIT_MEM1(SLJIT_SCRATCH_REG3), 0xff0000);
269 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
270
271 code.code = sljit_generate_code(compiler);
272 CHECK(compiler);
273 sljit_free_compiler(compiler);
274
275 FAILED(code.func1((sljit_sw)&buf) != ~1234, "test3 case 1 failed\n");
276 FAILED(buf[1] != ~1234, "test3 case 2 failed\n");
277 FAILED(buf[3] != ~9876, "test3 case 3 failed\n");
278 FAILED(buf[4] != ~0x12345678, "test3 case 4 failed\n");
279
280 sljit_free_code(code.code);
281 successful_tests++;
282 }
283
284 static void test4(void)
285 {
286 /* Test neg. */
287 executable_code code;
288 struct sljit_compiler* compiler = sljit_create_compiler();
289 sljit_sw buf[4];
290
291 if (verbose)
292 printf("Run test4\n");
293
294 FAILED(!compiler, "cannot create compiler\n");
295 buf[0] = 0;
296 buf[1] = 1234;
297 buf[2] = 0;
298 buf[3] = 0;
299
300 sljit_emit_enter(compiler, 2, 3, 2, 0);
301 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
302 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 2, SLJIT_SAVED_REG2, 0);
303 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM0(), (sljit_sw)&buf[0], SLJIT_MEM0(), (sljit_sw)&buf[1]);
304 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_RETURN_REG, 0, SLJIT_SAVED_REG2, 0);
305 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 3, SLJIT_IMM, 299);
306 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
307
308 code.code = sljit_generate_code(compiler);
309 CHECK(compiler);
310 sljit_free_compiler(compiler);
311
312 FAILED(code.func2((sljit_sw)&buf, 4567) != -4567, "test4 case 1 failed\n");
313 FAILED(buf[0] != -1234, "test4 case 2 failed\n");
314 FAILED(buf[2] != -4567, "test4 case 3 failed\n");
315 FAILED(buf[3] != -299, "test4 case 4 failed\n");
316
317 sljit_free_code(code.code);
318 successful_tests++;
319 }
320
321 static void test5(void)
322 {
323 /* Test add. */
324 executable_code code;
325 struct sljit_compiler* compiler = sljit_create_compiler();
326 sljit_sw buf[9];
327
328 if (verbose)
329 printf("Run test5\n");
330
331 FAILED(!compiler, "cannot create compiler\n");
332 buf[0] = 100;
333 buf[1] = 200;
334 buf[2] = 300;
335 buf[3] = 0;
336 buf[4] = 0;
337 buf[5] = 0;
338 buf[6] = 0;
339 buf[7] = 0;
340 buf[8] = 313;
341
342 sljit_emit_enter(compiler, 1, 3, 2, 0);
343 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_UNUSED, 0, SLJIT_IMM, 16, SLJIT_IMM, 16);
344 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_UNUSED, 0, SLJIT_IMM, 255, SLJIT_IMM, 255);
345 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_UNUSED, 0, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0);
346 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
347 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 50);
348 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG1), 1, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG1), 1, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG1), 0);
349 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, sizeof(sljit_sw) + 2);
350 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 50);
351 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
352 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
353 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 4, SLJIT_SCRATCH_REG1, 0);
354 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 50, SLJIT_SCRATCH_REG2, 0);
355 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw), SLJIT_IMM, 50, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw));
356 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0);
357 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_sw));
358 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw));
359 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0);
360 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0x1e7d39f2);
361 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0x23de7c06);
362 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_sw), SLJIT_IMM, 0x3d72e452, SLJIT_SCRATCH_REG2, 0);
363 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_sw), SLJIT_IMM, -43, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_sw));
364 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1000, SLJIT_SCRATCH_REG1, 0);
365 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1430);
366 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -99, SLJIT_SCRATCH_REG1, 0);
367
368 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0);
369
370 code.code = sljit_generate_code(compiler);
371 CHECK(compiler);
372 sljit_free_compiler(compiler);
373
374 FAILED(code.func1((sljit_sw)&buf) != 2437 + 2 * sizeof(sljit_sw), "test5 case 1 failed\n");
375 FAILED(buf[0] != 202 + 2 * sizeof(sljit_sw), "test5 case 2 failed\n");
376 FAILED(buf[2] != 500, "test5 case 3 failed\n");
377 FAILED(buf[3] != 400, "test5 case 4 failed\n");
378 FAILED(buf[4] != 200, "test5 case 5 failed\n");
379 FAILED(buf[5] != 250, "test5 case 6 failed\n");
380 FAILED(buf[6] != 0x425bb5f8, "test5 case 7 failed\n");
381 FAILED(buf[7] != 0x5bf01e44, "test5 case 8 failed\n");
382 FAILED(buf[8] != 270, "test5 case 9 failed\n");
383
384 sljit_free_code(code.code);
385 successful_tests++;
386 }
387
388 static void test6(void)
389 {
390 /* Test addc, sub, subc. */
391 executable_code code;
392 struct sljit_compiler* compiler = sljit_create_compiler();
393 sljit_sw buf[10];
394
395 if (verbose)
396 printf("Run test6\n");
397
398 FAILED(!compiler, "cannot create compiler\n");
399 buf[0] = 0;
400 buf[1] = 0;
401 buf[2] = 0;
402 buf[3] = 0;
403 buf[4] = 0;
404 buf[5] = 0;
405 buf[6] = 0;
406 buf[7] = 0;
407 buf[8] = 0;
408 buf[9] = 0;
409
410 sljit_emit_enter(compiler, 1, 3, 1, 0);
411 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -1);
412 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_C, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -1);
413 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 0, SLJIT_IMM, 0);
414 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_C, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
415 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_IMM, 4);
416 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 100);
417 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 2, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 50);
418 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_C, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 6000);
419 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 3, SLJIT_IMM, 10);
420 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 3, SLJIT_IMM, 5);
421 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 100);
422 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 2);
423 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 4, SLJIT_SCRATCH_REG1, 0);
424 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 5000);
425 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 4, SLJIT_SCRATCH_REG1, 0);
426 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
427 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 5, SLJIT_SCRATCH_REG2, 0);
428 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 5000);
429 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 6000, SLJIT_SCRATCH_REG1, 0);
430 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 6, SLJIT_SCRATCH_REG1, 0);
431 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 100);
432 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 32768);
433 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 7, SLJIT_SCRATCH_REG2, 0);
434 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -32767);
435 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 8, SLJIT_SCRATCH_REG2, 0);
436 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x52cd3bf4);
437 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 9, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x3da297c6);
438 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 10);
439 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_C, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 5);
440 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 2);
441 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, -2220);
442 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
443
444 code.code = sljit_generate_code(compiler);
445 CHECK(compiler);
446 sljit_free_compiler(compiler);
447
448 FAILED(code.func1((sljit_sw)&buf) != 2223, "test6 case 1 failed\n");
449 FAILED(buf[0] != 1, "test6 case 2 failed\n");
450 FAILED(buf[1] != 5, "test6 case 3 failed\n");
451 FAILED(buf[2] != 50, "test6 case 4 failed\n");
452 FAILED(buf[3] != 4, "test6 case 5 failed\n");
453 FAILED(buf[4] != 50, "test6 case 6 failed\n");
454 FAILED(buf[5] != 50, "test6 case 7 failed\n");
455 FAILED(buf[6] != 1000, "test6 case 8 failed\n");
456 FAILED(buf[7] != 100 - 32768, "test6 case 9 failed\n");
457 FAILED(buf[8] != 100 + 32767, "test6 case 10 failed\n");
458 FAILED(buf[9] != 0x152aa42e, "test6 case 11 failed\n");
459
460 sljit_free_code(code.code);
461 successful_tests++;
462 }
463
464 static void test7(void)
465 {
466 /* Test logical operators. */
467 executable_code code;
468 struct sljit_compiler* compiler = sljit_create_compiler();
469 sljit_sw buf[8];
470
471 if (verbose)
472 printf("Run test7\n");
473
474 FAILED(!compiler, "cannot create compiler\n");
475 buf[0] = 0xff80;
476 buf[1] = 0x0f808080;
477 buf[2] = 0;
478 buf[3] = 0xaaaaaa;
479 buf[4] = 0;
480 buf[5] = 0x4040;
481 buf[6] = 0;
482 buf[7] = 0xc43a7f95;
483
484 sljit_emit_enter(compiler, 1, 3, 1, 0);
485 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xf0C000);
486 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 2, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x308f);
487 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw));
488 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 3, SLJIT_IMM, 0xf0f0f0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 3);
489 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xC0F0);
490 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 5);
491 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xff0000);
492 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 4, SLJIT_SCRATCH_REG1, 0);
493 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 0xC0F0);
494 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 5);
495 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 5, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 0xff0000);
496 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_IMM, 0xFFFFFF, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw));
497 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 6, SLJIT_IMM, 0xa56c82c0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 6);
498 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 7);
499 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 7, SLJIT_IMM, 0xff00ff00, SLJIT_SCRATCH_REG1, 0);
500 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xff00ff00);
501 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x0f);
502 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0x888888, SLJIT_SCRATCH_REG2, 0);
503 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
504
505 code.code = sljit_generate_code(compiler);
506 CHECK(compiler);
507 sljit_free_compiler(compiler);
508
509 FAILED(code.func1((sljit_sw)&buf) != 0x8808, "test7 case 1 failed\n");
510 FAILED(buf[0] != 0x0F807F00, "test7 case 2 failed\n");
511 FAILED(buf[1] != 0x0F7F7F7F, "test7 case 3 failed\n");
512 FAILED(buf[2] != 0x00F0F08F, "test7 case 4 failed\n");
513 FAILED(buf[3] != 0x00A0A0A0, "test7 case 5 failed\n");
514 FAILED(buf[4] != 0x00FF80B0, "test7 case 6 failed\n");
515 FAILED(buf[5] != 0x00FF4040, "test7 case 7 failed\n");
516 FAILED(buf[6] != 0xa56c82c0, "test7 case 8 failed\n");
517 FAILED(buf[7] != 0x3b3a8095, "test7 case 9 failed\n");
518
519 sljit_free_code(code.code);
520 successful_tests++;
521 }
522
523 static void test8(void)
524 {
525 /* Test flags (neg, cmp, test). */
526 executable_code code;
527 struct sljit_compiler* compiler = sljit_create_compiler();
528 sljit_sw buf[13];
529
530 if (verbose)
531 printf("Run test8\n");
532
533 FAILED(!compiler, "cannot create compiler\n");
534 buf[0] = 100;
535 buf[1] = 3;
536 buf[2] = 3;
537 buf[3] = 3;
538 buf[4] = 3;
539 buf[5] = 3;
540 buf[6] = 3;
541 buf[7] = 3;
542 buf[8] = 3;
543 buf[9] = 3;
544 buf[10] = 3;
545 buf[11] = 3;
546 buf[12] = 3;
547
548 sljit_emit_enter(compiler, 1, 3, 2, 0);
549 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 20);
550 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 10);
551 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_IMM, 6, SLJIT_IMM, 5);
552 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_C_NOT_EQUAL);
553 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 2, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
554 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 3000);
555 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_SAVED_REG2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
556 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 3, SLJIT_SAVED_REG2, 0);
557 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS);
558 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 4, SLJIT_SCRATCH_REG3, 0);
559 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -15);
560 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_UNUSED, 0, SLJIT_C_SIG_GREATER);
561 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 5, SLJIT_SCRATCH_REG3, 0);
562 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
563 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
564 sljit_emit_op1(compiler, SLJIT_NEG | SLJIT_SET_E | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_IMM, (sljit_sw)1 << ((sizeof(sljit_sw) << 3) - 1));
565 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 6, SLJIT_UNUSED, 0, SLJIT_C_OVERFLOW);
566 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -1);
567 sljit_emit_op1(compiler, SLJIT_NOT | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0);
568 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 7, SLJIT_UNUSED, 0, SLJIT_C_ZERO);
569 sljit_emit_op1(compiler, SLJIT_NOT | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG2, 0);
570 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 8, SLJIT_UNUSED, 0, SLJIT_C_ZERO);
571 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_IMM, 0xffff, SLJIT_SCRATCH_REG1, 0);
572 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xffff);
573 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 9, SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
574 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_IMM, 0xffff, SLJIT_SCRATCH_REG2, 0);
575 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0xffff);
576 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG2, 0);
577 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
578 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
579 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 0x1);
580 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 10, SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
581 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (sljit_sw)1 << ((sizeof(sljit_sw) << 3) - 1));
582 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
583 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0);
584 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 11, SLJIT_UNUSED, 0, SLJIT_C_OVERFLOW);
585 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0);
586 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 12, SLJIT_UNUSED, 0, SLJIT_C_OVERFLOW);
587 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
588
589 code.code = sljit_generate_code(compiler);
590 CHECK(compiler);
591 sljit_free_compiler(compiler);
592
593 code.func1((sljit_sw)&buf);
594 FAILED(buf[1] != 1, "test8 case 1 failed\n");
595 FAILED(buf[2] != 0, "test8 case 2 failed\n");
596 FAILED(buf[3] != 0, "test8 case 3 failed\n");
597 FAILED(buf[4] != 1, "test8 case 4 failed\n");
598 FAILED(buf[5] != 1, "test8 case 5 failed\n");
599 FAILED(buf[6] != 1, "test8 case 6 failed\n");
600 FAILED(buf[7] != 1, "test8 case 7 failed\n");
601 FAILED(buf[8] != 0, "test8 case 8 failed\n");
602 FAILED(buf[9] != 1, "test8 case 9 failed\n");
603 FAILED(buf[10] != 0, "test8 case 10 failed\n");
604 FAILED(buf[11] != 1, "test8 case 11 failed\n");
605 FAILED(buf[12] != 0, "test8 case 12 failed\n");
606
607 sljit_free_code(code.code);
608 successful_tests++;
609 }
610
611 static void test9(void)
612 {
613 /* Test shift. */
614 executable_code code;
615 struct sljit_compiler* compiler = sljit_create_compiler();
616 sljit_sw buf[13];
617
618 if (verbose)
619 printf("Run test9\n");
620
621 FAILED(!compiler, "cannot create compiler\n");
622 buf[0] = 0;
623 buf[1] = 0;
624 buf[2] = 0;
625 buf[3] = 0;
626 buf[4] = 1 << 10;
627 buf[5] = 0;
628 buf[6] = 0;
629 buf[7] = 0;
630 buf[8] = 0;
631 buf[9] = 3;
632 buf[10] = 0;
633 buf[11] = 0;
634 buf[12] = 0;
635
636 sljit_emit_enter(compiler, 1, 3, 2, 0);
637 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xf);
638 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 3);
639 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
640 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
641 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 2);
642 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
643 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
644 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -64);
645 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 2);
646 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 2, SLJIT_SCRATCH_REG1, 0, SLJIT_PREF_SHIFT_REG, 0);
647
648 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 0xff);
649 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 4);
650 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_PREF_SHIFT_REG, 0, SLJIT_PREF_SHIFT_REG, 0, SLJIT_SCRATCH_REG1, 0);
651 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 3, SLJIT_PREF_SHIFT_REG, 0);
652 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 0xff);
653 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 8);
654 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 4, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 4, SLJIT_SCRATCH_REG1, 0);
655 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 5, SLJIT_PREF_SHIFT_REG, 0, SLJIT_SCRATCH_REG1, 0);
656
657 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 0xf);
658 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 2);
659 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_SCRATCH_REG1, 0);
660 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 6, SLJIT_SAVED_REG2, 0);
661 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG2, 0, SLJIT_SCRATCH_REG1, 0);
662 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 7, SLJIT_SCRATCH_REG1, 0);
663 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 0xf00);
664 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 4);
665 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG1, 0);
666 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 8, SLJIT_SCRATCH_REG2, 0);
667
668 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (sljit_sw)buf);
669 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 9);
670 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM2(SLJIT_SCRATCH_REG1, SLJIT_SCRATCH_REG2), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_SCRATCH_REG1, SLJIT_SCRATCH_REG2), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_SCRATCH_REG1, SLJIT_SCRATCH_REG2), SLJIT_WORD_SHIFT);
671
672 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 4);
673 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 2, SLJIT_PREF_SHIFT_REG, 0);
674 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 10, SLJIT_PREF_SHIFT_REG, 0);
675
676 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xa9);
677 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
678 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x7d00);
679 sljit_emit_op2(compiler, SLJIT_ILSHR, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 32);
680 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
681 sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
682 #endif
683 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0);
684 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xe30000);
685 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
686 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xffc0);
687 #else
688 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xffe0);
689 #endif
690 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0);
691 sljit_emit_op1(compiler, SLJIT_MOV_SI | SLJIT_INT_OP, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x25000000);
692 sljit_emit_op2(compiler, SLJIT_ISHL, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xfffe1);
693 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
694 sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
695 #endif
696 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 11, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0);
697
698 SLJIT_ASSERT(SLJIT_SCRATCH_REG3 == SLJIT_PREF_SHIFT_REG);
699 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 0);
700 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x5c);
701 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_PREF_SHIFT_REG, 0);
702 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xf600);
703 sljit_emit_op2(compiler, SLJIT_ILSHR, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_PREF_SHIFT_REG, 0);
704 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
705 /* Alternative form of uint32 type cast. */
706 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xffffffff);
707 #endif
708 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0);
709 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x630000);
710 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_PREF_SHIFT_REG, 0);
711 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 12, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0);
712
713 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
714
715 code.code = sljit_generate_code(compiler);
716 CHECK(compiler);
717 sljit_free_compiler(compiler);
718
719 code.func1((sljit_sw)&buf);
720 FAILED(buf[0] != 0x3c, "test9 case 1 failed\n");
721 FAILED(buf[1] != 0xf0, "test9 case 2 failed\n");
722 FAILED(buf[2] != -16, "test9 case 3 failed\n");
723 FAILED(buf[3] != 0xff0, "test9 case 4 failed\n");
724 FAILED(buf[4] != 4, "test9 case 5 failed\n");
725 FAILED(buf[5] != 0xff00, "test9 case 6 failed\n");
726 FAILED(buf[6] != 0x3c, "test9 case 7 failed\n");
727 FAILED(buf[7] != 0xf0, "test9 case 8 failed\n");
728 FAILED(buf[8] != 0xf0, "test9 case 9 failed\n");
729 FAILED(buf[9] != 0x18, "test9 case 10 failed\n");
730 FAILED(buf[10] != 32, "test9 case 11 failed\n");
731 FAILED(buf[11] != 0x4ae37da9, "test9 case 12 failed\n");
732 FAILED(buf[12] != 0x63f65c, "test9 case 13 failed\n");
733
734 sljit_free_code(code.code);
735 successful_tests++;
736 }
737
738 static void test10(void)
739 {
740 /* Test multiplications. */
741 executable_code code;
742 struct sljit_compiler* compiler = sljit_create_compiler();
743 sljit_sw buf[7];
744
745 if (verbose)
746 printf("Run test10\n");
747
748 FAILED(!compiler, "cannot create compiler\n");
749 buf[0] = 3;
750 buf[1] = 0;
751 buf[2] = 0;
752 buf[3] = 6;
753 buf[4] = -10;
754 buf[5] = 0;
755 buf[6] = 0;
756
757 sljit_emit_enter(compiler, 1, 3, 1, 0);
758
759 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 5);
760 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
761 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
762 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 7);
763 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 8);
764 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
765 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -3, SLJIT_IMM, -4);
766 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 2, SLJIT_SCRATCH_REG1, 0);
767 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -2);
768 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 3, SLJIT_SCRATCH_REG1, 0);
769 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, sizeof(sljit_sw) / 2);
770 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, (sljit_sw)&buf[3]);
771 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM2(SLJIT_SCRATCH_REG2, SLJIT_SCRATCH_REG1), 1, SLJIT_MEM2(SLJIT_SCRATCH_REG2, SLJIT_SCRATCH_REG1), 1, SLJIT_MEM2(SLJIT_SCRATCH_REG2, SLJIT_SCRATCH_REG1), 1);
772 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 9);
773 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
774 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 5, SLJIT_SCRATCH_REG1, 0);
775 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
776 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 3);
777 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, SLJIT_W(0x123456789));
778 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 6, SLJIT_SCRATCH_REG1, 0);
779 #endif
780 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 11, SLJIT_IMM, 10);
781 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
782
783 code.code = sljit_generate_code(compiler);
784 CHECK(compiler);
785 sljit_free_compiler(compiler);
786
787 FAILED(code.func1((sljit_sw)&buf) != 110, "test10 case 1 failed\n");
788 FAILED(buf[0] != 15, "test10 case 2 failed\n");
789 FAILED(buf[1] != 56, "test10 case 3 failed\n");
790 FAILED(buf[2] != 12, "test10 case 4 failed\n");
791 FAILED(buf[3] != -12, "test10 case 5 failed\n");
792 FAILED(buf[4] != 100, "test10 case 6 failed\n");
793 FAILED(buf[5] != 81, "test10 case 7 failed\n");
794 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
795 FAILED(buf[6] != SLJIT_W(0x123456789) * 3, "test10 case 8 failed\n");
796 #endif
797
798 sljit_free_code(code.code);
799 successful_tests++;
800 }
801
802 static void test11(void)
803 {
804 /* Test rewritable constants. */
805 executable_code code;
806 struct sljit_compiler* compiler = sljit_create_compiler();
807 struct sljit_const* const1;
808 struct sljit_const* const2;
809 struct sljit_const* const3;
810 struct sljit_const* const4;
811 void* value;
812 sljit_uw const1_addr;
813 sljit_uw const2_addr;
814 sljit_uw const3_addr;
815 sljit_uw const4_addr;
816 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
817 sljit_sw word_value1 = SLJIT_W(0xaaaaaaaaaaaaaaaa);
818 sljit_sw word_value2 = SLJIT_W(0xfee1deadfbadf00d);
819 #else
820 sljit_sw word_value1 = 0xaaaaaaaal;
821 sljit_sw word_value2 = 0xfbadf00dl;
822 #endif
823 sljit_sw buf[3];
824
825 if (verbose)
826 printf("Run test11\n");
827
828 FAILED(!compiler, "cannot create compiler\n");
829 buf[0] = 0;
830 buf[1] = 0;
831 buf[2] = 0;
832
833 sljit_emit_enter(compiler, 1, 3, 1, 0);
834
835 const1 = sljit_emit_const(compiler, SLJIT_MEM0(), (sljit_sw)&buf[0], -0x81b9);
836 SLJIT_ASSERT(!sljit_alloc_memory(compiler, 0));
837 SLJIT_ASSERT(!sljit_alloc_memory(compiler, 16 * sizeof(sljit_sw) + 1));
838 value = sljit_alloc_memory(compiler, 16 * sizeof(sljit_sw));
839 SLJIT_ASSERT(!((sljit_sw)value & (sizeof(sljit_sw) - 1)));
840 memset(value, 255, 16 * sizeof(sljit_sw));
841 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 2);
842 const2 = sljit_emit_const(compiler, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG1), SLJIT_WORD_SHIFT - 1, -65535);
843 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (sljit_sw)&buf[0] + 2 * sizeof(sljit_sw) - 2);
844 const3 = sljit_emit_const(compiler, SLJIT_MEM1(SLJIT_SCRATCH_REG1), 0, word_value1);
845 value = sljit_alloc_memory(compiler, 17);
846 SLJIT_ASSERT(!((sljit_sw)value & (sizeof(sljit_sw) - 1)));
847 memset(value, 255, 16);
848 const4 = sljit_emit_const(compiler, SLJIT_RETURN_REG, 0, 0xf7afcdb7);
849
850 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
851
852 code.code = sljit_generate_code(compiler);
853 CHECK(compiler);
854 const1_addr = sljit_get_const_addr(const1);
855 const2_addr = sljit_get_const_addr(const2);
856 const3_addr = sljit_get_const_addr(const3);
857 const4_addr = sljit_get_const_addr(const4);
858 sljit_free_compiler(compiler);
859
860 FAILED(code.func1((sljit_sw)&buf) != 0xf7afcdb7, "test11 case 1 failed\n");
861 FAILED(buf[0] != -0x81b9, "test11 case 2 failed\n");
862 FAILED(buf[1] != -65535, "test11 case 3 failed\n");
863 FAILED(buf[2] != word_value1, "test11 case 4 failed\n");
864
865 sljit_set_const(const1_addr, -1);
866 sljit_set_const(const2_addr, word_value2);
867 sljit_set_const(const3_addr, 0xbab0fea1);
868 sljit_set_const(const4_addr, -60089);
869
870 FAILED(code.func1((sljit_sw)&buf) != -60089, "test11 case 5 failed\n");
871 FAILED(buf[0] != -1, "test11 case 6 failed\n");
872 FAILED(buf[1] != word_value2, "test11 case 7 failed\n");
873 FAILED(buf[2] != 0xbab0fea1, "test11 case 8 failed\n");
874
875 sljit_free_code(code.code);
876 successful_tests++;
877 }
878
879 static void test12(void)
880 {
881 /* Test rewriteable jumps. */
882 executable_code code;
883 struct sljit_compiler* compiler = sljit_create_compiler();
884 struct sljit_label *label1;
885 struct sljit_label *label2;
886 struct sljit_label *label3;
887 struct sljit_jump *jump1;
888 struct sljit_jump *jump2;
889 struct sljit_jump *jump3;
890 void* value;
891 sljit_uw jump1_addr;
892 sljit_uw label1_addr;
893 sljit_uw label2_addr;
894 sljit_sw buf[1];
895
896 if (verbose)
897 printf("Run test12\n");
898
899 FAILED(!compiler, "cannot create compiler\n");
900 buf[0] = 0;
901
902 sljit_emit_enter(compiler, 2, 3, 2, 0);
903 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 10);
904 jump1 = sljit_emit_jump(compiler, SLJIT_REWRITABLE_JUMP | SLJIT_C_SIG_GREATER);
905 /* Default handler. */
906 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 5);
907 jump2 = sljit_emit_jump(compiler, SLJIT_JUMP);
908 value = sljit_alloc_memory(compiler, 15);
909 SLJIT_ASSERT(!((sljit_sw)value & (sizeof(sljit_sw) - 1)));
910 memset(value, 255, 15);
911 /* Handler 1. */
912 label1 = sljit_emit_label(compiler);
913 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 6);
914 jump3 = sljit_emit_jump(compiler, SLJIT_JUMP);
915 /* Handler 2. */
916 label2 = sljit_emit_label(compiler);
917 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 7);
918 /* Exit. */
919 label3 = sljit_emit_label(compiler);
920 sljit_set_label(jump2, label3);
921 sljit_set_label(jump3, label3);
922 /* By default, set to handler 1. */
923 sljit_set_label(jump1, label1);
924 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
925
926 value = sljit_alloc_memory(compiler, 8);
927 SLJIT_ASSERT(!((sljit_sw)value & (sizeof(sljit_sw) - 1)));
928 memset(value, 255, 8);
929
930 code.code = sljit_generate_code(compiler);
931 CHECK(compiler);
932 jump1_addr = sljit_get_jump_addr(jump1);
933 label1_addr = sljit_get_label_addr(label1);
934 label2_addr = sljit_get_label_addr(label2);
935 sljit_free_compiler(compiler);
936
937 code.func2((sljit_sw)&buf, 4);
938 FAILED(buf[0] != 5, "test12 case 1 failed\n");
939
940 code.func2((sljit_sw)&buf, 11);
941 FAILED(buf[0] != 6, "test12 case 2 failed\n");
942
943 sljit_set_jump_addr(jump1_addr, label2_addr);
944 code.func2((sljit_sw)&buf, 12);
945 FAILED(buf[0] != 7, "test12 case 3 failed\n");
946
947 sljit_set_jump_addr(jump1_addr, label1_addr);
948 code.func2((sljit_sw)&buf, 13);
949 FAILED(buf[0] != 6, "test12 case 4 failed\n");
950
951 sljit_free_code(code.code);
952 successful_tests++;
953 }
954
955 static void test13(void)
956 {
957 /* Test fpu monadic functions. */
958 executable_code code;
959 struct sljit_compiler* compiler = sljit_create_compiler();
960 sljit_d buf[7];
961 sljit_sw buf2[6];
962
963 if (verbose)
964 printf("Run test13\n");
965
966 if (!sljit_is_fpu_available()) {
967 printf("no fpu available, test13 skipped\n");
968 successful_tests++;
969 if (compiler)
970 sljit_free_compiler(compiler);
971 return;
972 }
973
974 FAILED(!compiler, "cannot create compiler\n");
975 buf[0] = 7.75;
976 buf[1] = -4.5;
977 buf[2] = 0.0;
978 buf[3] = 0.0;
979 buf[4] = 0.0;
980 buf[5] = 0.0;
981 buf[6] = 0.0;
982
983 buf2[0] = 10;
984 buf2[1] = 10;
985 buf2[2] = 10;
986 buf2[3] = 10;
987 buf2[4] = 10;
988 buf2[5] = 10;
989
990 sljit_emit_enter(compiler, 2, 3, 2, 0);
991 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_MEM0(), (sljit_sw)&buf[2], SLJIT_MEM0(), (sljit_sw)&buf[1]);
992 sljit_emit_fop1(compiler, SLJIT_ABSD, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_d), SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d));
993 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG1, 0, SLJIT_MEM0(), (sljit_sw)&buf[0]);
994 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 2 * sizeof(sljit_d));
995 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG2, 0, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG1), 0);
996 sljit_emit_fop1(compiler, SLJIT_NEGD, SLJIT_FLOAT_REG3, 0, SLJIT_FLOAT_REG1, 0);
997 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG4, 0, SLJIT_FLOAT_REG3, 0);
998 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_MEM0(), (sljit_sw)&buf[4], SLJIT_FLOAT_REG4, 0);
999 sljit_emit_fop1(compiler, SLJIT_ABSD, SLJIT_FLOAT_REG5, 0, SLJIT_FLOAT_REG2, 0);
1000 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_d), SLJIT_FLOAT_REG5, 0);
1001 sljit_emit_fop1(compiler, SLJIT_NEGD, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_d), SLJIT_FLOAT_REG5, 0);
1002
1003 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG6, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
1004 sljit_emit_fop1(compiler, SLJIT_CMPD | SLJIT_SET_S, SLJIT_FLOAT_REG6, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d));
1005 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 0, SLJIT_UNUSED, 0, SLJIT_C_FLOAT_GREATER);
1006 sljit_emit_fop1(compiler, SLJIT_CMPD | SLJIT_SET_S, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d), SLJIT_FLOAT_REG6, 0);
1007 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_C_FLOAT_GREATER);
1008 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG2, 0, SLJIT_FLOAT_REG6, 0);
1009 sljit_emit_fop1(compiler, SLJIT_CMPD | SLJIT_SET_E | SLJIT_SET_S, SLJIT_FLOAT_REG2, 0, SLJIT_FLOAT_REG2, 0);
1010 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 2 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_C_FLOAT_EQUAL);
1011 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 3 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_C_FLOAT_LESS);
1012 sljit_emit_fop1(compiler, SLJIT_CMPD | SLJIT_SET_E, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d));
1013 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 4 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_C_FLOAT_EQUAL);
1014 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 5 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_C_FLOAT_NOT_EQUAL);
1015
1016 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1017
1018 code.code = sljit_generate_code(compiler);
1019 CHECK(compiler);
1020 sljit_free_compiler(compiler);
1021
1022 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
1023 FAILED(buf[2] != -4.5, "test13 case 1 failed\n");
1024 FAILED(buf[3] != 4.5, "test13 case 2 failed\n");
1025 FAILED(buf[4] != -7.75, "test13 case 3 failed\n");
1026 FAILED(buf[5] != 4.5, "test13 case 4 failed\n");
1027 FAILED(buf[6] != -4.5, "test13 case 5 failed\n");
1028
1029 FAILED(buf2[0] != 1, "test13 case 6 failed\n");
1030 FAILED(buf2[1] != 0, "test13 case 7 failed\n");
1031 FAILED(buf2[2] != 1, "test13 case 8 failed\n");
1032 FAILED(buf2[3] != 0, "test13 case 9 failed\n");
1033 FAILED(buf2[4] != 0, "test13 case 10 failed\n");
1034 FAILED(buf2[5] != 1, "test13 case 11 failed\n");
1035
1036 sljit_free_code(code.code);
1037 successful_tests++;
1038 }
1039
1040 static void test14(void)
1041 {
1042 /* Test fpu diadic functions. */
1043 executable_code code;
1044 struct sljit_compiler* compiler = sljit_create_compiler();
1045 sljit_d buf[15];
1046
1047 if (verbose)
1048 printf("Run test14\n");
1049
1050 if (!sljit_is_fpu_available()) {
1051 printf("no fpu available, test14 skipped\n");
1052 successful_tests++;
1053 if (compiler)
1054 sljit_free_compiler(compiler);
1055 return;
1056 }
1057 buf[0] = 7.25;
1058 buf[1] = 3.5;
1059 buf[2] = 1.75;
1060 buf[3] = 0.0;
1061 buf[4] = 0.0;
1062 buf[5] = 0.0;
1063 buf[6] = 0.0;
1064 buf[7] = 0.0;
1065 buf[8] = 0.0;
1066 buf[9] = 0.0;
1067 buf[10] = 0.0;
1068 buf[11] = 0.0;
1069 buf[12] = 8.0;
1070 buf[13] = 4.0;
1071 buf[14] = 0.0;
1072
1073 FAILED(!compiler, "cannot create compiler\n");
1074 sljit_emit_enter(compiler, 1, 3, 1, 0);
1075
1076 /* ADD */
1077 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, sizeof(sljit_d));
1078 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d));
1079 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 2);
1080 sljit_emit_fop2(compiler, SLJIT_ADDD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 3, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
1081 sljit_emit_fop2(compiler, SLJIT_ADDD, SLJIT_FLOAT_REG1, 0, SLJIT_FLOAT_REG1, 0, SLJIT_FLOAT_REG2, 0);
1082 sljit_emit_fop2(compiler, SLJIT_ADDD, SLJIT_FLOAT_REG2, 0, SLJIT_FLOAT_REG1, 0, SLJIT_FLOAT_REG2, 0);
1083 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 4, SLJIT_FLOAT_REG1, 0);
1084 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 5, SLJIT_FLOAT_REG2, 0);
1085
1086 /* SUB */
1087 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG3, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
1088 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG4, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 2);
1089 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 2);
1090 sljit_emit_fop2(compiler, SLJIT_SUBD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 6, SLJIT_FLOAT_REG4, 0, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG2), SLJIT_DOUBLE_SHIFT);
1091 sljit_emit_fop2(compiler, SLJIT_SUBD, SLJIT_FLOAT_REG3, 0, SLJIT_FLOAT_REG3, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 2);
1092 sljit_emit_fop2(compiler, SLJIT_SUBD, SLJIT_FLOAT_REG4, 0, SLJIT_FLOAT_REG3, 0, SLJIT_FLOAT_REG4, 0);
1093 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 7, SLJIT_FLOAT_REG3, 0);
1094 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 8, SLJIT_FLOAT_REG4, 0);
1095
1096 /* MUL */
1097 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
1098 sljit_emit_fop2(compiler, SLJIT_MULD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 9, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG2), SLJIT_DOUBLE_SHIFT, SLJIT_FLOAT_REG2, 0);
1099 sljit_emit_fop2(compiler, SLJIT_MULD, SLJIT_FLOAT_REG2, 0, SLJIT_FLOAT_REG2, 0, SLJIT_FLOAT_REG3, 0);
1100 sljit_emit_fop2(compiler, SLJIT_MULD, SLJIT_FLOAT_REG6, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 2, SLJIT_FLOAT_REG3, 0);
1101 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 10, SLJIT_FLOAT_REG2, 0);
1102 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 11, SLJIT_FLOAT_REG6, 0);
1103
1104 /* DIV */
1105 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG6, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 12);
1106 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 13);
1107 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG5, 0, SLJIT_FLOAT_REG6, 0);
1108 sljit_emit_fop2(compiler, SLJIT_DIVD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 12, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 12, SLJIT_FLOAT_REG2, 0);
1109 sljit_emit_fop2(compiler, SLJIT_DIVD, SLJIT_FLOAT_REG6, 0, SLJIT_FLOAT_REG6, 0, SLJIT_FLOAT_REG2, 0);
1110 sljit_emit_fop2(compiler, SLJIT_DIVD, SLJIT_FLOAT_REG5, 0, SLJIT_FLOAT_REG2, 0, SLJIT_FLOAT_REG5, 0);
1111 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 13, SLJIT_FLOAT_REG6, 0);
1112 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d) * 14, SLJIT_FLOAT_REG5, 0);
1113
1114 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1115
1116 code.code = sljit_generate_code(compiler);
1117 CHECK(compiler);
1118 sljit_free_compiler(compiler);
1119
1120 code.func1((sljit_sw)&buf);
1121 FAILED(buf[3] != 10.75, "test14 case 1 failed\n");
1122 FAILED(buf[4] != 5.25, "test14 case 2 failed\n");
1123 FAILED(buf[5] != 7.0, "test14 case 3 failed\n");
1124 FAILED(buf[6] != 0.0, "test14 case 4 failed\n");
1125 FAILED(buf[7] != 5.5, "test14 case 5 failed\n");
1126 FAILED(buf[8] != 3.75, "test14 case 6 failed\n");
1127 FAILED(buf[9] != 24.5, "test14 case 7 failed\n");
1128 FAILED(buf[10] != 38.5, "test14 case 8 failed\n");
1129 FAILED(buf[11] != 9.625, "test14 case 9 failed\n");
1130 FAILED(buf[12] != 2.0, "test14 case 10 failed\n");
1131 FAILED(buf[13] != 2.0, "test14 case 11 failed\n");
1132 FAILED(buf[14] != 0.5, "test14 case 12 failed\n");
1133
1134 sljit_free_code(code.code);
1135 successful_tests++;
1136 }
1137
1138 static sljit_sw SLJIT_CALL func(sljit_sw a, sljit_sw b, sljit_sw c)
1139 {
1140 return a + b + c + 5;
1141 }
1142
1143 static void test15(void)
1144 {
1145 /* Test function call. */
1146 executable_code code;
1147 struct sljit_compiler* compiler = sljit_create_compiler();
1148 struct sljit_jump* jump;
1149 sljit_sw buf[7];
1150
1151 if (verbose)
1152 printf("Run test15\n");
1153
1154 FAILED(!compiler, "cannot create compiler\n");
1155 buf[0] = 0;
1156 buf[1] = 0;
1157 buf[2] = 0;
1158 buf[3] = 0;
1159 buf[4] = 0;
1160 buf[5] = 0;
1161 buf[6] = SLJIT_FUNC_OFFSET(func);
1162
1163 sljit_emit_enter(compiler, 1, 4, 1, 0);
1164
1165 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 5);
1166 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 7);
1167 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, -3);
1168 sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1169 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_RETURN_REG, 0);
1170
1171 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -5);
1172 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, -10);
1173 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2);
1174 jump = sljit_emit_jump(compiler, SLJIT_CALL3 | SLJIT_REWRITABLE_JUMP);
1175 sljit_set_target(jump, (sljit_sw)-1);
1176 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1177
1178 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1179 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 40);
1180 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, -3);
1181 sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_SCRATCH_REG1, 0);
1182 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1183
1184 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -60);
1185 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1186 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, -30);
1187 sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_SCRATCH_REG2, 0);
1188 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1189
1190 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 10);
1191 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 16);
1192 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1193 sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_SCRATCH_REG3, 0);
1194 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1195
1196 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 100);
1197 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 110);
1198 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 120);
1199 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG1, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1200 sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_TEMPORARY_EREG1, 0);
1201 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1202
1203 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -10);
1204 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, -16);
1205 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 6);
1206 sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_sw));
1207 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1208
1209 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1210
1211 code.code = sljit_generate_code(compiler);
1212 CHECK(compiler);
1213 sljit_set_jump_addr(sljit_get_jump_addr(jump), SLJIT_FUNC_OFFSET(func));
1214 sljit_free_compiler(compiler);
1215
1216 FAILED(code.func1((sljit_sw)&buf) != -15, "test15 case 1 failed\n");
1217 FAILED(buf[0] != 14, "test15 case 2 failed\n");
1218 FAILED(buf[1] != -8, "test15 case 3 failed\n");
1219 FAILED(buf[2] != SLJIT_FUNC_OFFSET(func) + 42, "test15 case 4 failed\n");
1220 FAILED(buf[3] != SLJIT_FUNC_OFFSET(func) - 85, "test15 case 5 failed\n");
1221 FAILED(buf[4] != SLJIT_FUNC_OFFSET(func) + 31, "test15 case 6 failed\n");
1222 FAILED(buf[5] != 335, "test15 case 7 failed\n");
1223 FAILED(buf[6] != -15, "test15 case 8 failed\n");
1224
1225 sljit_free_code(code.code);
1226 successful_tests++;
1227 }
1228
1229 static void test16(void)
1230 {
1231 /* Ackermann benchmark. */
1232 executable_code code;
1233 struct sljit_compiler* compiler = sljit_create_compiler();
1234 struct sljit_label *entry;
1235 struct sljit_label *label;
1236 struct sljit_jump *jump;
1237 struct sljit_jump *jump1;
1238 struct sljit_jump *jump2;
1239
1240 if (verbose)
1241 printf("Run test16\n");
1242
1243 FAILED(!compiler, "cannot create compiler\n");
1244
1245 entry = sljit_emit_label(compiler);
1246 sljit_emit_enter(compiler, 2, 3, 2, 0);
1247 /* If x == 0. */
1248 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 0);
1249 jump1 = sljit_emit_jump(compiler, SLJIT_C_EQUAL);
1250 /* If y == 0. */
1251 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 0);
1252 jump2 = sljit_emit_jump(compiler, SLJIT_C_EQUAL);
1253
1254 /* Ack(x,y-1). */
1255 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG1, 0);
1256 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);
1257 jump = sljit_emit_jump(compiler, SLJIT_CALL2);
1258 sljit_set_label(jump, entry);
1259
1260 /* Returns with Ack(x-1, Ack(x,y-1)). */
1261 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_RETURN_REG, 0);
1262 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 1);
1263 jump = sljit_emit_jump(compiler, SLJIT_CALL2);
1264 sljit_set_label(jump, entry);
1265 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1266
1267 /* Returns with y+1. */
1268 label = sljit_emit_label(compiler);
1269 sljit_set_label(jump1, label);
1270 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1, SLJIT_SAVED_REG2, 0);
1271 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1272
1273 /* Returns with Ack(x-1,1) */
1274 label = sljit_emit_label(compiler);
1275 sljit_set_label(jump2, label);
1276 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 1);
1277 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
1278 jump = sljit_emit_jump(compiler, SLJIT_CALL2);
1279 sljit_set_label(jump, entry);
1280 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1281
1282 code.code = sljit_generate_code(compiler);
1283 CHECK(compiler);
1284 sljit_free_compiler(compiler);
1285
1286 FAILED(code.func2(3, 3) != 61, "test16 case 1 failed\n");
1287 /* For benchmarking. */
1288 /* FAILED(code.func2(3, 11) != 16381, "test16 case 1 failed\n"); */
1289
1290 sljit_free_code(code.code);
1291 successful_tests++;
1292 }
1293
1294 static void test17(void)
1295 {
1296 /* Test arm constant pool. */
1297 executable_code code;
1298 struct sljit_compiler* compiler = sljit_create_compiler();
1299 sljit_si i;
1300 sljit_sw buf[5];
1301
1302 if (verbose)
1303 printf("Run test17\n");
1304
1305 FAILED(!compiler, "cannot create compiler\n");
1306 buf[0] = 0;
1307 buf[1] = 0;
1308 buf[2] = 0;
1309 buf[3] = 0;
1310 buf[4] = 0;
1311
1312 sljit_emit_enter(compiler, 1, 3, 1, 0);
1313 for (i = 0; i <= 0xfff; i++) {
1314 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x81818000 | i);
1315 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x81818000 | i);
1316 if ((i & 0x3ff) == 0)
1317 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), (i >> 10) * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
1318 }
1319 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
1320 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1321
1322 code.code = sljit_generate_code(compiler);
1323 CHECK(compiler);
1324 sljit_free_compiler(compiler);
1325
1326 code.func1((sljit_sw)&buf);
1327 FAILED((sljit_uw)buf[0] != 0x81818000, "test17 case 1 failed\n");
1328 FAILED((sljit_uw)buf[1] != 0x81818400, "test17 case 2 failed\n");
1329 FAILED((sljit_uw)buf[2] != 0x81818800, "test17 case 3 failed\n");
1330 FAILED((sljit_uw)buf[3] != 0x81818c00, "test17 case 4 failed\n");
1331 FAILED((sljit_uw)buf[4] != 0x81818fff, "test17 case 5 failed\n");
1332
1333 sljit_free_code(code.code);
1334 successful_tests++;
1335 }
1336
1337 static void test18(void)
1338 {
1339 /* Test 64 bit. */
1340 executable_code code;
1341 struct sljit_compiler* compiler = sljit_create_compiler();
1342 sljit_sw buf[11];
1343
1344 if (verbose)
1345 printf("Run test18\n");
1346
1347 FAILED(!compiler, "cannot create compiler\n");
1348 buf[0] = 0;
1349 buf[1] = 0;
1350 buf[2] = 0;
1351 buf[3] = 0;
1352 buf[4] = 0;
1353 buf[5] = 100;
1354 buf[6] = 100;
1355 buf[7] = 100;
1356 buf[8] = 100;
1357 buf[9] = 0;
1358 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1359 buf[10] = SLJIT_W(1) << 32;
1360 #else
1361 buf[10] = 1;
1362 #endif
1363
1364 sljit_emit_enter(compiler, 1, 3, 2, 0);
1365
1366 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1367 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, SLJIT_W(0x1122334455667788));
1368 sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x1122334455667788));
1369
1370 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(1000000000000));
1371 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 2, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(1000000000000));
1372 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 3, SLJIT_IMM, SLJIT_W(5000000000000), SLJIT_SCRATCH_REG1, 0);
1373
1374 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1375 sljit_emit_op2(compiler, SLJIT_IADD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 4, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1376
1377 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1378 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1379 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_SAVED_REG2, 0, SLJIT_UNUSED, 0, SLJIT_C_ZERO);
1380 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 5, SLJIT_SAVED_REG2, 0);
1381 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
1382 sljit_emit_op2(compiler, SLJIT_IAND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1383 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 6, SLJIT_UNUSED, 0, SLJIT_C_ZERO);
1384
1385 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1386 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(0x2208080808));
1387 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 7, SLJIT_UNUSED, 0, SLJIT_C_LESS);
1388 sljit_emit_op1(compiler, SLJIT_MOV_SI | SLJIT_INT_OP, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
1389 sljit_emit_op2(compiler, SLJIT_IAND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(0x1104040404));
1390 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 8, SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
1391
1392 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 4);
1393 sljit_emit_op2(compiler, SLJIT_ISHL, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 9, SLJIT_IMM, SLJIT_W(0xffff0000), SLJIT_SCRATCH_REG1, 0);
1394
1395 sljit_emit_op2(compiler, SLJIT_IMUL, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 10, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 10, SLJIT_IMM, -1);
1396 #else
1397 /* 32 bit operations. */
1398
1399 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 0x11223344);
1400 sljit_emit_op2(compiler, SLJIT_IADD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_IMM, 0x44332211);
1401
1402 #endif
1403
1404 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1405
1406 code.code = sljit_generate_code(compiler);
1407 CHECK(compiler);
1408 sljit_free_compiler(compiler);
1409
1410 code.func1((sljit_sw)&buf);
1411 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1412 FAILED(buf[0] != SLJIT_W(0x1122334455667788), "test18 case 1 failed\n");
1413 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1414 FAILED(buf[1] != 0x55667788, "test18 case 2 failed\n");
1415 #else
1416 FAILED(buf[1] != SLJIT_W(0x5566778800000000), "test18 case 2 failed\n");
1417 #endif
1418 FAILED(buf[2] != SLJIT_W(2000000000000), "test18 case 3 failed\n");
1419 FAILED(buf[3] != SLJIT_W(4000000000000), "test18 case 4 failed\n");
1420 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1421 FAILED(buf[4] != 0x28282828, "test18 case 5 failed\n");
1422 #else
1423 FAILED(buf[4] != SLJIT_W(0x2828282800000000), "test18 case 5 failed\n");
1424 #endif
1425 FAILED(buf[5] != 0, "test18 case 6 failed\n");
1426 FAILED(buf[6] != 1, "test18 case 7 failed\n");
1427 FAILED(buf[7] != 1, "test18 case 8 failed\n");
1428 FAILED(buf[8] != 0, "test18 case 9 failed\n");
1429 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1430 FAILED(buf[9] != 0xfff00000, "test18 case 10 failed\n");
1431 FAILED(buf[10] != 0xffffffff, "test18 case 11 failed\n");
1432 #else
1433 FAILED(buf[9] != SLJIT_W(0xfff0000000000000), "test18 case 10 failed\n");
1434 FAILED(buf[10] != SLJIT_W(0xffffffff00000000), "test18 case 11 failed\n");
1435 #endif
1436 #else
1437 FAILED(buf[0] != 0x11223344, "test18 case 1 failed\n");
1438 FAILED(buf[1] != 0x44332211, "test18 case 2 failed\n");
1439 #endif
1440
1441 sljit_free_code(code.code);
1442 successful_tests++;
1443 }
1444
1445 static void test19(void)
1446 {
1447 /* Test arm partial instruction caching. */
1448 executable_code code;
1449 struct sljit_compiler* compiler = sljit_create_compiler();
1450 sljit_sw buf[10];
1451
1452 if (verbose)
1453 printf("Run test19\n");
1454
1455 FAILED(!compiler, "cannot create compiler\n");
1456 buf[0] = 6;
1457 buf[1] = 4;
1458 buf[2] = 0;
1459 buf[3] = 0;
1460 buf[4] = 0;
1461 buf[5] = 0;
1462 buf[6] = 2;
1463 buf[7] = 0;
1464
1465 sljit_emit_enter(compiler, 1, 3, 1, 0);
1466 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw));
1467 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1468 SLJIT_ASSERT(compiler->cache_arg == 0);
1469 #endif
1470 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM0(), (sljit_sw)&buf[2], SLJIT_MEM0(), (sljit_sw)&buf[1], SLJIT_MEM0(), (sljit_sw)&buf[0]);
1471 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1472 SLJIT_ASSERT(compiler->cache_arg > 0);
1473 #endif
1474 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
1475 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, sizeof(sljit_sw));
1476 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_SCRATCH_REG1), (sljit_sw)&buf[0], SLJIT_MEM1(SLJIT_SCRATCH_REG2), (sljit_sw)&buf[0]);
1477 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1478 SLJIT_ASSERT(compiler->cache_arg > 0);
1479 #endif
1480 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 4, SLJIT_MEM0(), (sljit_sw)&buf[0], SLJIT_IMM, 2);
1481 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1482 SLJIT_ASSERT(compiler->cache_arg > 0);
1483 #endif
1484 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 5, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 2, SLJIT_MEM1(SLJIT_SCRATCH_REG1), (sljit_sw)&buf[0] + 4 * sizeof(sljit_sw));
1485 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1486 SLJIT_ASSERT(compiler->cache_arg > 0);
1487 #endif
1488 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 7, SLJIT_IMM, 10);
1489 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 7);
1490 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SCRATCH_REG2), (sljit_sw)&buf[5], SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM1(SLJIT_SCRATCH_REG2), (sljit_sw)&buf[5]);
1491 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1492 SLJIT_ASSERT(compiler->cache_arg > 0);
1493 #endif
1494
1495 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1496
1497 code.code = sljit_generate_code(compiler);
1498 CHECK(compiler);
1499 sljit_free_compiler(compiler);
1500
1501 code.func1((sljit_sw)&buf);
1502 FAILED(buf[0] != 10, "test19 case 1 failed\n");
1503 FAILED(buf[1] != 4, "test19 case 2 failed\n");
1504 FAILED(buf[2] != 14, "test19 case 3 failed\n");
1505 FAILED(buf[3] != 14, "test19 case 4 failed\n");
1506 FAILED(buf[4] != 8, "test19 case 5 failed\n");
1507 FAILED(buf[5] != 6, "test19 case 6 failed\n");
1508 FAILED(buf[6] != 12, "test19 case 7 failed\n");
1509 FAILED(buf[7] != 10, "test19 case 8 failed\n");
1510
1511 sljit_free_code(code.code);
1512 successful_tests++;
1513 }
1514
1515 static void test20(void)
1516 {
1517 /* Test stack. */
1518 executable_code code;
1519 struct sljit_compiler* compiler = sljit_create_compiler();
1520 struct sljit_jump* jump;
1521 struct sljit_label* label;
1522 sljit_sw buf[6];
1523 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1524 sljit_sw offset_value = SLJIT_W(0x1234567812345678);
1525 #else
1526 sljit_sw offset_value = SLJIT_W(0x12345678);
1527 #endif
1528
1529 if (verbose)
1530 printf("Run test20\n");
1531
1532 FAILED(!compiler, "cannot create compiler\n");
1533 buf[0] = 5;
1534 buf[1] = 12;
1535 buf[2] = 0;
1536 buf[3] = 0;
1537 buf[4] = 111;
1538 buf[5] = -12345;
1539
1540 sljit_emit_enter(compiler, 1, 5, 5, 4 * sizeof(sljit_sw));
1541
1542 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
1543 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw));
1544 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG1, 0, SLJIT_IMM, -1);
1545 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG2, 0, SLJIT_IMM, -1);
1546 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG1, 0, SLJIT_IMM, -1);
1547 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG2, 0, SLJIT_IMM, -1);
1548 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_uw), SLJIT_MEM1(SLJIT_LOCALS_REG), 0, SLJIT_MEM1(SLJIT_LOCALS_REG), sizeof(sljit_uw));
1549 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_uw), SLJIT_MEM1(SLJIT_LOCALS_REG), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_LOCALS_REG), 0);
1550 sljit_get_local_base(compiler, SLJIT_SCRATCH_REG1, 0, -offset_value);
1551 sljit_get_local_base(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, -0x1234);
1552 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
1553 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_uw), SLJIT_MEM1(SLJIT_SCRATCH_REG1), offset_value, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0x1234 + sizeof(sljit_sw));
1554
1555 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_uw));
1556 /* Dummy last instructions. */
1557 sljit_emit_const(compiler, SLJIT_SCRATCH_REG1, 0, -9);
1558 sljit_emit_label(compiler);
1559
1560 code.code = sljit_generate_code(compiler);
1561 CHECK(compiler);
1562 sljit_free_compiler(compiler);
1563
1564 FAILED(code.func1((sljit_sw)&buf) != -12345, "test20 case 1 failed\n")
1565
1566 FAILED(buf[2] != 60, "test20 case 2 failed\n");
1567 FAILED(buf[3] != 17, "test20 case 3 failed\n");
1568 FAILED(buf[4] != 7, "test20 case 4 failed\n");
1569
1570 sljit_free_code(code.code);
1571
1572 compiler = sljit_create_compiler();
1573 sljit_emit_enter(compiler, 0, 3, 0, SLJIT_MAX_LOCAL_SIZE);
1574
1575 sljit_get_local_base(compiler, SLJIT_SCRATCH_REG1, 0, SLJIT_MAX_LOCAL_SIZE - sizeof(sljit_sw));
1576 sljit_get_local_base(compiler, SLJIT_SCRATCH_REG2, 0, -(sljit_sw)sizeof(sljit_sw));
1577 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, -1);
1578 label = sljit_emit_label(compiler);
1579 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG3, 0);
1580 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0);
1581 jump = sljit_emit_jump(compiler, SLJIT_C_NOT_EQUAL);
1582 sljit_set_label(jump, label);
1583
1584 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1585
1586 code.code = sljit_generate_code(compiler);
1587 CHECK(compiler);
1588 sljit_free_compiler(compiler);
1589
1590 /* Just survive this code. */
1591 code.func0();
1592
1593 sljit_free_code(code.code);
1594 successful_tests++;
1595 }
1596
1597 static void test21(void)
1598 {
1599 /* Test fake enter. The parts of the jit code can be separated in the memory. */
1600 executable_code code1;
1601 executable_code code2;
1602 struct sljit_compiler* compiler = sljit_create_compiler();
1603 struct sljit_jump* jump;
1604 sljit_uw addr;
1605 sljit_sw buf[4];
1606
1607 if (verbose)
1608 printf("Run test21\n");
1609
1610 FAILED(!compiler, "cannot create compiler\n");
1611 buf[0] = 9;
1612 buf[1] = -6;
1613 buf[2] = 0;
1614 buf[3] = 0;
1615
1616 sljit_emit_enter(compiler, 1, 3, 2, 2 * sizeof(sljit_sw));
1617
1618 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), 0, SLJIT_IMM, 10);
1619 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_LOCALS_REG), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_LOCALS_REG), 0);
1620 jump = sljit_emit_jump(compiler, SLJIT_JUMP | SLJIT_REWRITABLE_JUMP);
1621 sljit_set_target(jump, 0);
1622
1623 code1.code = sljit_generate_code(compiler);
1624 CHECK(compiler);
1625 addr = sljit_get_jump_addr(jump);
1626 sljit_free_compiler(compiler);
1627
1628 compiler = sljit_create_compiler();
1629 FAILED(!compiler, "cannot create compiler\n");
1630
1631 /* Other part of the jit code. */
1632 sljit_set_context(compiler, 1, 3, 2, 2 * sizeof(sljit_sw));
1633
1634 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 2, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_LOCALS_REG), 0);
1635 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_LOCALS_REG), 0, SLJIT_MEM1(SLJIT_LOCALS_REG), 0);
1636 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), sizeof(sljit_sw));
1637
1638 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1639
1640 code2.code = sljit_generate_code(compiler);
1641 CHECK(compiler);
1642 sljit_free_compiler(compiler);
1643
1644 sljit_set_jump_addr(addr, SLJIT_FUNC_OFFSET(code2.code));
1645
1646 FAILED(code1.func1((sljit_sw)&buf) != 19, "test21 case 1 failed\n");
1647 FAILED(buf[2] != -16, "test21 case 2 failed\n");
1648 FAILED(buf[3] != 100, "test21 case 3 failed\n");
1649
1650 sljit_free_code(code1.code);
1651 sljit_free_code(code2.code);
1652 successful_tests++;
1653 }
1654
1655 static void test22(void)
1656 {
1657 /* Test simple byte and half-int data transfers. */
1658 executable_code code;
1659 struct sljit_compiler* compiler = sljit_create_compiler();
1660 sljit_sw buf[9];
1661 sljit_sh sbuf[7];
1662 sljit_sb bbuf[5];
1663
1664 if (verbose)
1665 printf("Run test22\n");
1666
1667 FAILED(!compiler, "cannot create compiler\n");
1668 buf[0] = 5;
1669 buf[1] = 0;
1670 buf[2] = 0;
1671 buf[3] = 0;
1672 buf[4] = 0;
1673 buf[5] = 0;
1674 buf[6] = 0;
1675 buf[7] = 0;
1676 buf[8] = 0;
1677
1678 sbuf[0] = 0;
1679 sbuf[1] = 0;
1680 sbuf[2] = -9;
1681 sbuf[3] = 0;
1682 sbuf[4] = 0;
1683 sbuf[5] = 0;
1684 sbuf[6] = 0;
1685
1686 bbuf[0] = 0;
1687 bbuf[1] = 0;
1688 bbuf[2] = -56;
1689 bbuf[3] = 0;
1690 bbuf[4] = 0;
1691
1692 sljit_emit_enter(compiler, 3, 3, 3, 0);
1693
1694 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
1695 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_SAVED_REG1, 0);
1696 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_IMM, -13);
1697 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), sizeof(sljit_sw));
1698 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG3, 0);
1699 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SCRATCH_REG1), sizeof(sljit_sw));
1700 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
1701 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM2(SLJIT_SCRATCH_REG2, SLJIT_SCRATCH_REG1), SLJIT_WORD_SHIFT, SLJIT_SCRATCH_REG2, 0);
1702 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
1703 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_SCRATCH_REG2, SLJIT_SCRATCH_REG1), 0, SLJIT_SCRATCH_REG2, 0);
1704 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 2);
1705 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM2(SLJIT_SCRATCH_REG2, SLJIT_SCRATCH_REG1), SLJIT_WORD_SHIFT, SLJIT_SCRATCH_REG2, 0);
1706
1707 sljit_emit_op1(compiler, SLJIT_MOV_SH, SLJIT_MEM1(SLJIT_SAVED_REG2), 0, SLJIT_IMM, -13);
1708 sljit_emit_op1(compiler, SLJIT_MOVU_UH, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_sh), SLJIT_IMM, 0x1234);
1709 sljit_emit_op1(compiler, SLJIT_MOVU_SH, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_sh));
1710 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
1711 sljit_emit_op1(compiler, SLJIT_MOV_UH, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_sh), SLJIT_MEM1(SLJIT_SAVED_REG2), -(sljit_sw)sizeof(sljit_sh));
1712 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xff0000 + 8000);
1713 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 2);
1714 sljit_emit_op1(compiler, SLJIT_MOV_SH, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SCRATCH_REG2), 1, SLJIT_SCRATCH_REG1, 0);
1715 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 3);
1716 sljit_emit_op1(compiler, SLJIT_MOVU_SH, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SCRATCH_REG2), 1, SLJIT_SCRATCH_REG1, 0);
1717 sljit_emit_op1(compiler, SLJIT_MOV_SH, SLJIT_MEM1(SLJIT_SAVED_REG2), 0, SLJIT_IMM, -9317);
1718 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 5 * sizeof(sljit_sh));
1719 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -5);
1720 sljit_emit_op1(compiler, SLJIT_MOV_UH, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM2(SLJIT_SCRATCH_REG2, SLJIT_SCRATCH_REG1), 1);
1721 sljit_emit_op1(compiler, SLJIT_MOV_UH, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_sh), SLJIT_SCRATCH_REG2, 0);
1722
1723 sljit_emit_op1(compiler, SLJIT_MOV_SB, SLJIT_MEM1(SLJIT_SAVED_REG3), 0, SLJIT_IMM, -45);
1724 sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_SAVED_REG3), sizeof(sljit_sb), SLJIT_IMM, 0x12);
1725 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 2 * sizeof(sljit_sb));
1726 sljit_emit_op1(compiler, SLJIT_MOVU_SB, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG3), sizeof(sljit_sb));
1727 sljit_emit_op1(compiler, SLJIT_MOV_SB, SLJIT_SAVED_REG2, 0, SLJIT_SCRATCH_REG2, 0);
1728 sljit_emit_op1(compiler, SLJIT_MOV_UB, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0);
1729 sljit_emit_op1(compiler, SLJIT_MOV_SB, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG2, 0);
1730 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_sw), SLJIT_SCRATCH_REG3, 0);
1731 sljit_emit_op1(compiler, SLJIT_MOV_UB, SLJIT_MEM1(SLJIT_SAVED_REG3), sizeof(sljit_sb), SLJIT_SAVED_REG2, 0);
1732 sljit_emit_op1(compiler, SLJIT_MOV_UB, SLJIT_MEM2(SLJIT_SAVED_REG3, SLJIT_SCRATCH_REG1), 0, SLJIT_SCRATCH_REG1, 0);
1733
1734 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1735
1736 code.code = sljit_generate_code(compiler);
1737 CHECK(compiler);
1738 sljit_free_compiler(compiler);
1739
1740 code.func3((sljit_sw)&buf, (sljit_sw)&sbuf, (sljit_sw)&bbuf);
1741 FAILED(buf[1] != -13, "test22 case 1 failed\n");
1742 FAILED(buf[2] != 5, "test22 case 2 failed\n");
1743 FAILED(buf[3] != -13, "test22 case 3 failed\n");
1744 FAILED(buf[4] != (sljit_sw)&buf[3], "test22 case 4 failed\n");
1745 FAILED(buf[5] != (sljit_sw)&buf[4], "test22 case 5 failed\n");
1746 FAILED(buf[6] != (sljit_sw)&buf[4], "test22 case 6 failed\n");
1747 FAILED(buf[7] != -9, "test22 case 7 failed\n");
1748 FAILED(buf[8] != -56, "test22 case 8 failed\n");
1749
1750 FAILED(sbuf[0] != -13, "test22 case 9 failed\n");
1751 FAILED(sbuf[1] != 0x1234, "test22 case 10 failed\n");
1752 FAILED(sbuf[3] != 0x1234, "test22 case 11 failed\n");
1753 FAILED(sbuf[4] != 8000, "test22 case 12 failed\n");
1754 FAILED(sbuf[5] != -9317, "test22 case 13 failed\n");
1755 FAILED(sbuf[6] != -9317, "test22 case 14 failed\n");
1756
1757 FAILED(bbuf[0] != -45, "test22 case 15 failed\n");
1758 FAILED(bbuf[1] != 0x12, "test22 case 16 failed\n");
1759 FAILED(bbuf[3] != -56, "test22 case 17 failed\n");
1760 FAILED(bbuf[4] != 2, "test22 case 18 failed\n");
1761
1762 sljit_free_code(code.code);
1763 successful_tests++;
1764 }
1765
1766 static void test23(void)
1767 {
1768 /* Test 32 bit / 64 bit signed / unsigned int transfer and conversion.
1769 This test has do real things on 64 bit systems, but works on 32 bit systems as well. */
1770 executable_code code;
1771 struct sljit_compiler* compiler = sljit_create_compiler();
1772 sljit_sw buf[9];
1773 sljit_si ibuf[5];
1774 union {
1775 sljit_si asint;
1776 sljit_ub asbytes[4];
1777 } u;
1778 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1779 sljit_sw garbage = SLJIT_W(0x1234567812345678);
1780 #else
1781 sljit_sw garbage = 0x12345678;
1782 #endif
1783
1784 if (verbose)
1785 printf("Run test23\n");
1786
1787 FAILED(!compiler, "cannot create compiler\n");
1788 buf[0] = 0;
1789 buf[1] = 0;
1790 buf[2] = 0;
1791 buf[3] = 0;
1792 buf[4] = 0;
1793 buf[5] = 0;
1794 buf[6] = 0;
1795 buf[7] = 0;
1796 buf[8] = 0;
1797
1798 ibuf[0] = 0;
1799 ibuf[1] = 0;
1800 ibuf[2] = -5791;
1801 ibuf[3] = 43579;
1802 ibuf[4] = 658923;
1803
1804 sljit_emit_enter(compiler, 2, 3, 3, 0);
1805 sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_MEM1(SLJIT_SAVED_REG2), 0, SLJIT_IMM, 34567);
1806 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
1807 sljit_emit_op1(compiler, SLJIT_MOVU_SI, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SCRATCH_REG1), 2, SLJIT_IMM, -7654);
1808 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, garbage);
1809 sljit_emit_op1(compiler, SLJIT_MOVU_SI, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_si));
1810 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
1811 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, garbage);
1812 sljit_emit_op1(compiler, SLJIT_MOVU_UI, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_si));
1813 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
1814 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, garbage);
1815 sljit_emit_op1(compiler, SLJIT_MOV_SI, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_si));
1816 sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
1817 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
1818 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x0f00f00);
1819 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 0x7777);
1820 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), 0x7777 + 2 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
1821 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 0x7777);
1822 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), -0x7777 + (sljit_sw)sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
1823 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 16 - sizeof(sljit_sw));
1824 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
1825 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 16);
1826 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM2(SLJIT_SCRATCH_REG1, SLJIT_SCRATCH_REG2), 1, SLJIT_SCRATCH_REG1, 0);
1827 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_SCRATCH_REG1), 0, SLJIT_IMM, 64, SLJIT_MEM1(SLJIT_SCRATCH_REG1), 0);
1828 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
1829 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG1), (sljit_sw)&buf[6], SLJIT_MEM0(), (sljit_sw)&buf[6]);
1830 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), 0, SLJIT_IMM, 0x123456);
1831 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_sw), SLJIT_SAVED_REG1, 0);
1832 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, sizeof(sljit_sw));
1833 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 100000 * sizeof(sljit_sw));
1834 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), 100001 * sizeof(sljit_sw), SLJIT_SAVED_REG1, 0);
1835 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, sizeof(sljit_sw));
1836 sljit_emit_op1(compiler, SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_si), SLJIT_IMM, 0x12345678);
1837
1838 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0x2bd700 | 243);
1839 sljit_emit_return(compiler, SLJIT_MOV_SB, SLJIT_SCRATCH_REG2, 0);
1840
1841 code.code = sljit_generate_code(compiler);
1842 CHECK(compiler);
1843 sljit_free_compiler(compiler);
1844
1845 FAILED(code.func2((sljit_sw)&buf, (sljit_sw)&ibuf) != -13, "test23 case 1 failed\n");
1846 FAILED(buf[0] != -5791, "test23 case 2 failed\n");
1847 FAILED(buf[1] != 43579, "test23 case 3 failed\n");
1848 FAILED(buf[2] != 658923, "test23 case 4 failed\n");
1849 FAILED(buf[3] != 0x0f00f00, "test23 case 5 failed\n");
1850 FAILED(buf[4] != 0x0f00f00, "test23 case 6 failed\n");
1851 FAILED(buf[5] != 80, "test23 case 7 failed\n");
1852 FAILED(buf[6] != 0x123456, "test23 case 8 failed\n");
1853 FAILED(buf[7] != (sljit_sw)&buf[5], "test23 case 9 failed\n");
1854 FAILED(buf[8] != (sljit_sw)&buf[8] - 100000 * sizeof(sljit_sw), "test23 case 10 failed\n");
1855
1856 FAILED(ibuf[0] != 34567, "test23 case 11 failed\n");
1857 FAILED(ibuf[1] != -7654, "test23 case 12 failed\n");
1858 u.asint = ibuf[4];
1859 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1860 FAILED(u.asbytes[0] != 0x78, "test23 case 13 failed\n");
1861 FAILED(u.asbytes[1] != 0x56, "test23 case 14 failed\n");
1862 FAILED(u.asbytes[2] != 0x34, "test23 case 15 failed\n");
1863 FAILED(u.asbytes[3] != 0x12, "test23 case 16 failed\n");
1864 #else
1865 FAILED(u.asbytes[0] != 0x12, "test23 case 13 failed\n");
1866 FAILED(u.asbytes[1] != 0x34, "test23 case 14 failed\n");
1867 FAILED(u.asbytes[2] != 0x56, "test23 case 15 failed\n");
1868 FAILED(u.asbytes[3] != 0x78, "test23 case 16 failed\n");
1869 #endif
1870
1871 sljit_free_code(code.code);
1872 successful_tests++;
1873 }
1874
1875 static void test24(void)
1876 {
1877 /* Some complicated addressing modes. */
1878 executable_code code;
1879 struct sljit_compiler* compiler = sljit_create_compiler();
1880 sljit_sw buf[9];
1881 sljit_sh sbuf[5];
1882 sljit_sb bbuf[7];
1883
1884 if (verbose)
1885 printf("Run test24\n");
1886
1887 FAILED(!compiler, "cannot create compiler\n");
1888
1889 buf[0] = 100567;
1890 buf[1] = 75799;
1891 buf[2] = 0;
1892 buf[3] = -8;
1893 buf[4] = -50;
1894 buf[5] = 0;
1895 buf[6] = 0;
1896 buf[7] = 0;
1897 buf[8] = 0;
1898
1899 sbuf[0] = 30000;
1900 sbuf[1] = 0;
1901 sbuf[2] = 0;
1902 sbuf[3] = -12345;
1903 sbuf[4] = 0;
1904
1905 bbuf[0] = -128;
1906 bbuf[1] = 0;
1907 bbuf[2] = 0;
1908 bbuf[3] = 99;
1909 bbuf[4] = 0;
1910 bbuf[5] = 0;
1911 bbuf[6] = 0;
1912
1913 sljit_emit_enter(compiler, 3, 3, 3, 0);
1914
1915 /* Nothing should be updated. */
1916 sljit_emit_op1(compiler, SLJIT_MOVU_SH, SLJIT_MEM0(), (sljit_sw)&sbuf[1], SLJIT_MEM0(), (sljit_sw)&sbuf[0]);
1917 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1918 SLJIT_ASSERT(compiler->cache_arg > 0);
1919 #endif
1920 sljit_emit_op1(compiler, SLJIT_MOVU_SB, SLJIT_MEM0(), (sljit_sw)&bbuf[1], SLJIT_MEM0(), (sljit_sw)&bbuf[0]);
1921 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1922 SLJIT_ASSERT(compiler->cache_arg > 0);
1923 #endif
1924 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 2);
1925 sljit_emit_op1(compiler, SLJIT_MOV_UH, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SCRATCH_REG1), 1, SLJIT_MEM0(), (sljit_sw)&sbuf[3]);
1926 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1927 SLJIT_ASSERT(compiler->cache_arg > 0);
1928 #endif
1929 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (sljit_sw)&buf[0]);
1930 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, sizeof(sljit_sw));
1931 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2);
1932 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM2(SLJIT_SCRATCH_REG1, SLJIT_SCRATCH_REG3), SLJIT_WORD_SHIFT, SLJIT_MEM0(), (sljit_sw)&buf[0], SLJIT_MEM2(SLJIT_SCRATCH_REG2, SLJIT_SCRATCH_REG1), 0);
1933 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1934 SLJIT_ASSERT(compiler->cache_arg > 0);
1935 #endif
1936 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, sizeof(sljit_sb));
1937 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, sizeof(sljit_sb));
1938 sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_SCRATCH_REG1), (sljit_sw)&bbuf[1], SLJIT_MEM1(SLJIT_SCRATCH_REG2), (sljit_sw)&bbuf[0]);
1939 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1940 SLJIT_ASSERT(compiler->cache_arg > 0);
1941 #endif
1942 sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_SCRATCH_REG1), 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(sljit_sb));
1943
1944 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, sizeof(sljit_sh));
1945 sljit_emit_op1(compiler, SLJIT_MOV_SH, SLJIT_MEM1(SLJIT_SCRATCH_REG2), (sljit_sw)&sbuf[3], SLJIT_SCRATCH_REG2, 0);
1946 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1947 SLJIT_ASSERT(compiler->cache_arg == 0);
1948 #endif
1949
1950 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 3);
1951 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG1), SLJIT_WORD_SHIFT);
1952 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1953 SLJIT_ASSERT(compiler->cache_arg > 0);
1954 #endif
1955 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 4);
1956 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_SAVED_REG1, 0);
1957 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_SCRATCH_REG2, SLJIT_SCRATCH_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG1), SLJIT_WORD_SHIFT);
1958 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1959 SLJIT_ASSERT(compiler->cache_arg > 0);
1960 #endif
1961 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG1, 0);
1962 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG2, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
1963 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 4);
1964 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM2(SLJIT_SCRATCH_REG2, SLJIT_SCRATCH_REG3), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_SCRATCH_REG1, SLJIT_SCRATCH_REG3), SLJIT_WORD_SHIFT);
1965 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1966 SLJIT_ASSERT(compiler->cache_arg > 0);
1967 #endif
1968 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
1969 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0);
1970
1971 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (sljit_sw)&buf - 0x7fff8000 + 6 * sizeof(sljit_sw));
1972 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 952467);
1973 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), 0x7fff8000, SLJIT_SCRATCH_REG2, 0);
1974 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), 0x7fff8000 + sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SCRATCH_REG1), 0x7fff8000);
1975
1976 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (sljit_sw)&buf + 0x7fff7fff + 6 * sizeof(sljit_sw));
1977 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SCRATCH_REG1), -0x7fff7fff + 2 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SCRATCH_REG1), -0x7fff7fff + sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SCRATCH_REG1), -0x7fff7fff);
1978 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (sljit_sw)&bbuf - 0x7fff7ffe + 3 * sizeof(sljit_sb));
1979 sljit_emit_op1(compiler, SLJIT_MOV_SB, SLJIT_MEM1(SLJIT_SCRATCH_REG1), 0x7fff7fff, SLJIT_MEM1(SLJIT_SCRATCH_REG1), 0x7fff7ffe);
1980 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (sljit_sw)&bbuf + 0x7fff7fff + 5 * sizeof(sljit_sb));
1981 sljit_emit_op1(compiler, SLJIT_MOV_SB, SLJIT_MEM1(SLJIT_SCRATCH_REG1), -0x7fff7fff, SLJIT_MEM1(SLJIT_SCRATCH_REG1), -0x7fff8000);
1982 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1983 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (sljit_sw)&bbuf - SLJIT_W(0x123456123456));
1984 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, (sljit_sw)&bbuf - SLJIT_W(0x123456123456));
1985 sljit_emit_op1(compiler, SLJIT_MOV_SB, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_W(0x123456123456) + 6 * sizeof(sljit_sb), SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_W(0x123456123456));
1986 #endif
1987
1988 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1989
1990 code.code = sljit_generate_code(compiler);
1991 CHECK(compiler);
1992 sljit_free_compiler(compiler);
1993
1994 code.func3((sljit_sw)&buf, (sljit_sw)&sbuf, (sljit_sw)&bbuf);
1995 FAILED(buf[2] != 176366, "test24 case 1 failed\n");
1996 FAILED(buf[3] != 64, "test24 case 2 failed\n");
1997 FAILED(buf[4] != -100, "test24 case 3 failed\n");
1998 FAILED(buf[5] != -100 + (sljit_sw)&buf[5] + (sljit_sw)&buf[4], "test24 case 4 failed\n");
1999 FAILED(buf[6] != 952467, "test24 case 5 failed\n");
2000 FAILED(buf[7] != 952467, "test24 case 6 failed\n");
2001 FAILED(buf[8] != 952467 * 2, "test24 case 7 failed\n");
2002
2003 FAILED(sbuf[1] != 30000, "test24 case 8 failed\n");
2004 FAILED(sbuf[2] != -12345, "test24 case 9 failed\n");
2005 FAILED(sbuf[4] != sizeof(sljit_sh), "test24 case 10 failed\n");
2006
2007 FAILED(bbuf[1] != -128, "test24 case 11 failed\n");
2008 FAILED(bbuf[2] != 99, "test24 case 12 failed\n");
2009 FAILED(bbuf[4] != 99, "test24 case 13 failed\n");
2010 FAILED(bbuf[5] != 99, "test24 case 14 failed\n");
2011 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2012 FAILED(bbuf[6] != -128, "test24 case 15 failed\n");
2013 #endif
2014
2015 sljit_free_code(code.code);
2016 successful_tests++;
2017 }
2018
2019 static void test25(void)
2020 {
2021 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2022 /* 64 bit loads. */
2023 executable_code code;
2024 struct sljit_compiler* compiler = sljit_create_compiler();
2025 sljit_sw buf[14];
2026
2027 if (verbose)
2028 printf("Run test25\n");
2029
2030 FAILED(!compiler, "cannot create compiler\n");
2031 buf[0] = 7;
2032 buf[1] = 0;
2033 buf[2] = 0;
2034 buf[3] = 0;
2035 buf[4] = 0;
2036 buf[5] = 0;
2037 buf[6] = 0;
2038 buf[7] = 0;
2039 buf[8] = 0;
2040 buf[9] = 0;
2041 buf[10] = 0;
2042 buf[11] = 0;
2043 buf[12] = 0;
2044 buf[13] = 0;
2045
2046 sljit_emit_enter(compiler, 1, 3, 1, 0);
2047
2048 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 0);
2049 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 1 * sizeof(sljit_sw), SLJIT_IMM, 0x7fff);
2050 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_sw), SLJIT_IMM, -0x8000);
2051 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_sw), SLJIT_IMM, 0x7fffffff);
2052 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(-0x80000000));
2053 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x1234567887654321));
2054 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0xff80000000));
2055 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x3ff0000000));
2056 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0xfffffff800100000));
2057 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 9 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0xfffffff80010f000));
2058 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 10 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00000008001));
2059 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 11 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00080010000));
2060 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 12 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00080018001));
2061 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 13 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00ffff00000));
2062
2063 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2064
2065 code.code = sljit_generate_code(compiler);
2066 CHECK(compiler);
2067 sljit_free_compiler(compiler);
2068
2069 code.func1((sljit_sw)&buf);
2070 FAILED(buf[0] != 0, "test25 case 1 failed\n");
2071 FAILED(buf[1] != 0x7fff, "test25 case 2 failed\n");
2072 FAILED(buf[2] != -0x8000, "test25 case 3 failed\n");
2073 FAILED(buf[3] != 0x7fffffff, "test25 case 4 failed\n");
2074 FAILED(buf[4] != SLJIT_W(-0x80000000), "test25 case 5 failed\n");
2075 FAILED(buf[5] != SLJIT_W(0x1234567887654321), "test25 case 6 failed\n");
2076 FAILED(buf[6] != SLJIT_W(0xff80000000), "test25 case 7 failed\n");
2077 FAILED(buf[7] != SLJIT_W(0x3ff0000000), "test25 case 8 failed\n");
2078 FAILED((sljit_uw)buf[8] != SLJIT_W(0xfffffff800100000), "test25 case 9 failed\n");
2079 FAILED((sljit_uw)buf[9] != SLJIT_W(0xfffffff80010f000), "test25 case 10 failed\n");
2080 FAILED(buf[10] != SLJIT_W(0x07fff00000008001), "test25 case 11 failed\n");
2081 FAILED(buf[11] != SLJIT_W(0x07fff00080010000), "test25 case 12 failed\n");
2082 FAILED(buf[12] != SLJIT_W(0x07fff00080018001), "test25 case 13 failed\n");
2083 FAILED(buf[13] != SLJIT_W(0x07fff00ffff00000), "test25 case 14 failed\n");
2084
2085 sljit_free_code(code.code);
2086 #endif
2087 successful_tests++;
2088 }
2089
2090 static void test26(void)
2091 {
2092 /* Aligned access without aligned offsets. */
2093 executable_code code;
2094 struct sljit_compiler* compiler = sljit_create_compiler();
2095 sljit_sw buf[4];
2096 sljit_si ibuf[4];
2097 sljit_d dbuf[4];
2098
2099 if (verbose)
2100 printf("Run test26\n");
2101
2102 FAILED(!compiler, "cannot create compiler\n");
2103
2104 buf[0] = -2789;
2105 buf[1] = 0;
2106 buf[2] = 4;
2107 buf[3] = -4;
2108
2109 ibuf[0] = -689;
2110 ibuf[1] = 0;
2111 ibuf[2] = -6;
2112 ibuf[3] = 3;
2113
2114 dbuf[0] = 5.75;
2115 dbuf[1] = 0.0;
2116 dbuf[2] = 0.0;
2117 dbuf[3] = -4.0;
2118
2119 sljit_emit_enter(compiler, 3, 3, 3, 0);
2120
2121 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 3);
2122 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);
2123 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), -3);
2124 sljit_emit_op1(compiler, SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_si) - 1, SLJIT_SCRATCH_REG1, 0);
2125 sljit_emit_op1(compiler, SLJIT_MOV_SI, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), -1);
2126 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) - 3, SLJIT_SCRATCH_REG1, 0);
2127
2128 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 100);
2129 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_SCRATCH_REG1), sizeof(sljit_sw) * 2 - 103, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 2 - 3, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 3 - 3);
2130 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 100);
2131 sljit_emit_op2(compiler, SLJIT_IMUL, SLJIT_MEM1(SLJIT_SCRATCH_REG1), sizeof(sljit_si) * 2 - 101, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_si) * 2 - 1, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_si) * 3 - 1);
2132
2133 if (sljit_is_fpu_available()) {
2134 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SAVED_REG3, 0, SLJIT_SAVED_REG3, 0, SLJIT_IMM, 3);
2135 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_MEM1(SLJIT_SAVED_REG3), sizeof(sljit_d) - 3, SLJIT_MEM1(SLJIT_SAVED_REG3), -3);
2136 sljit_emit_fop2(compiler, SLJIT_ADDD, SLJIT_MEM1(SLJIT_SAVED_REG3), sizeof(sljit_d) * 2 - 3, SLJIT_MEM1(SLJIT_SAVED_REG3), -3, SLJIT_MEM1(SLJIT_SAVED_REG3), sizeof(sljit_d) - 3);
2137 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG3, 0, SLJIT_IMM, 2);
2138 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, (sizeof(sljit_d) * 3 - 4) >> 1);
2139 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG3, 0, SLJIT_IMM, 1);
2140 sljit_emit_fop2(compiler, SLJIT_DIVD, SLJIT_MEM1(SLJIT_SCRATCH_REG1), sizeof(sljit_d) * 3 - 5, SLJIT_MEM1(SLJIT_SAVED_REG3), sizeof(sljit_d) * 2 - 3, SLJIT_MEM2(SLJIT_SCRATCH_REG3, SLJIT_SCRATCH_REG2), 1);
2141 }
2142
2143 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2144
2145 code.code = sljit_generate_code(compiler);
2146 CHECK(compiler);
2147 sljit_free_compiler(compiler);
2148
2149 code.func3((sljit_sw)&buf, (sljit_sw)&ibuf, (sljit_sw)&dbuf);
2150
2151 FAILED(buf[1] != -689, "test26 case 1 failed\n");
2152 FAILED(buf[2] != -16, "test26 case 2 failed\n");
2153 FAILED(ibuf[1] != -2789, "test26 case 3 failed\n");
2154 FAILED(ibuf[2] != -18, "test26 case 4 failed\n");
2155
2156 if (sljit_is_fpu_available()) {
2157 FAILED(dbuf[1] != 5.75, "test26 case 5 failed\n");
2158 FAILED(dbuf[2] != 11.5, "test26 case 6 failed\n");
2159 FAILED(dbuf[3] != -2.875, "test26 case 7 failed\n");
2160 }
2161
2162 sljit_free_code(code.code);
2163 successful_tests++;
2164 }
2165
2166 static void test27(void)
2167 {
2168 #define SET_NEXT_BYTE(type) \
2169 cond_set(compiler, SLJIT_SCRATCH_REG3, 0, type); \
2170 sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_SAVED_REG1), 1, SLJIT_SCRATCH_REG3, 0);
2171 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2172 #define RESULT(i) i
2173 #else
2174 #define RESULT(i) (3 - i)
2175 #endif
2176
2177 /* Playing with conditional flags. */
2178 executable_code code;
2179 struct sljit_compiler* compiler = sljit_create_compiler();
2180 sljit_sb buf[37];
2181 sljit_si i;
2182
2183 if (verbose)
2184 printf("Run test27\n");
2185
2186 for (i = 0; i < 37; ++i)
2187 buf[i] = 10;
2188
2189 FAILED(!compiler, "cannot create compiler\n");
2190
2191 /* 3 arguments passed, 3 arguments used. */
2192 sljit_emit_enter(compiler, 1, 3, 3, 0);
2193
2194 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 1);
2195
2196 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x1001);
2197 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 20);
2198 /* 0x100100000 on 64 bit machines, 0x100000 on 32 bit machines. */
2199 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0x800000);
2200 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
2201 sljit_emit_op0(compiler, SLJIT_NOP); /* Nop should keep the flags. */
2202 SET_NEXT_BYTE(SLJIT_C_GREATER);
2203 SET_NEXT_BYTE(SLJIT_C_LESS);
2204 sljit_emit_op1(compiler, SLJIT_MOV_SI | SLJIT_INT_OP, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
2205 sljit_emit_op1(compiler, SLJIT_MOV_SI | SLJIT_INT_OP, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0);
2206 sljit_emit_op2(compiler, SLJIT_ISUB | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
2207 sljit_emit_op0(compiler, SLJIT_NOP); /* Nop should keep the flags. */
2208 SET_NEXT_BYTE(SLJIT_C_GREATER);
2209 SET_NEXT_BYTE(SLJIT_C_LESS);
2210
2211 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x1000);
2212 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 20);
2213 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x10);
2214 /* 0x100000010 on 64 bit machines, 0x10 on 32 bit machines. */
2215 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x80);
2216 SET_NEXT_BYTE(SLJIT_C_GREATER);
2217 SET_NEXT_BYTE(SLJIT_C_LESS);
2218 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
2219 sljit_emit_op2(compiler, SLJIT_ISUB | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x80);
2220 SET_NEXT_BYTE(SLJIT_C_GREATER);
2221 SET_NEXT_BYTE(SLJIT_C_LESS);
2222
2223 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
2224 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
2225 /* 0xff..ff on all machines. */
2226 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_U, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
2227 SET_NEXT_BYTE(SLJIT_C_LESS_EQUAL);
2228 SET_NEXT_BYTE(SLJIT_C_GREATER_EQUAL);
2229 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_S, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, -1);
2230 SET_NEXT_BYTE(SLJIT_C_SIG_GREATER);
2231 SET_NEXT_BYTE(SLJIT_C_SIG_LESS);
2232 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0);
2233 SET_NEXT_BYTE(SLJIT_C_EQUAL);
2234 SET_NEXT_BYTE(SLJIT_C_NOT_EQUAL);
2235 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_O | SLJIT_SET_U, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, -2);
2236 SET_NEXT_BYTE(SLJIT_C_OVERFLOW);
2237 SET_NEXT_BYTE(SLJIT_C_NOT_OVERFLOW);
2238 SET_NEXT_BYTE(SLJIT_C_GREATER_EQUAL);
2239 SET_NEXT_BYTE(SLJIT_C_LESS_EQUAL);
2240
2241 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x80000000);
2242 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 16);
2243 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 16);
2244 /* 0x80..0 on 64 bit machines, 0 on 32 bit machines. */
2245 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0xffffffff);
2246 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
2247 SET_NEXT_BYTE(SLJIT_C_OVERFLOW);
2248 SET_NEXT_BYTE(SLJIT_C_NOT_OVERFLOW);
2249 sljit_emit_op1(compiler, SLJIT_MOV_SI, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
2250 sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0);
2251 sljit_emit_op2(compiler, SLJIT_ISUB | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
2252 SET_NEXT_BYTE(SLJIT_C_OVERFLOW);
2253 SET_NEXT_BYTE(SLJIT_C_NOT_OVERFLOW);
2254
2255 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
2256 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_C, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
2257 sljit_emit_op2(compiler, SLJIT_SUBC | SLJIT_SET_C, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
2258 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 6, SLJIT_SCRATCH_REG1, 0);
2259 sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_SAVED_REG1), 1, SLJIT_SCRATCH_REG1, 0);
2260
2261 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -1);
2262 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_C, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
2263 sljit_emit_op2(compiler, SLJIT_ADDC | SLJIT_SET_C, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
2264 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 9);
2265 sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_SAVED_REG1), 1, SLJIT_SCRATCH_REG1, 0);
2266
2267 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
2268 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (8 * sizeof(sljit_sw)) - 1);
2269 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
2270 SET_NEXT_BYTE(SLJIT_C_EQUAL);
2271 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
2272 SET_NEXT_BYTE(SLJIT_C_EQUAL);
2273
2274 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
2275 sljit_emit_op2(compiler, SLJIT_ASHR | SLJIT_SET_E, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
2276 SET_NEXT_BYTE(SLJIT_C_EQUAL);
2277 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
2278 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_E, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xffffc0);
2279 SET_NEXT_BYTE(SLJIT_C_NOT_EQUAL);
2280 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 0);
2281 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
2282 sljit_emit_op2(compiler, SLJIT_ASHR | SLJIT_SET_E, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_PREF_SHIFT_REG, 0);
2283 SET_NEXT_BYTE(SLJIT_C_EQUAL);
2284 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 0);
2285 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
2286 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_E, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_PREF_SHIFT_REG, 0);
2287 SET_NEXT_BYTE(SLJIT_C_NOT_EQUAL);
2288
2289 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
2290 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2291 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_C, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
2292 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1, SLJIT_SCRATCH_REG1, 0);
2293 sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_SAVED_REG1), 1, SLJIT_SCRATCH_REG3, 0);
2294 sljit_emit_op2(compiler, SLJIT_SUBC | SLJIT_SET_C, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
2295 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1, SLJIT_SCRATCH_REG1, 0);
2296 sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_SAVED_REG1), 1, SLJIT_SCRATCH_REG3, 0);
2297
2298 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -34);
2299 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_S | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x1234);
2300 SET_NEXT_BYTE(SLJIT_C_LESS);
2301 SET_NEXT_BYTE(SLJIT_C_SIG_LESS);
2302 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2303 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(0x12300000000) - 43);
2304 #else
2305 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -43);
2306 #endif
2307 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, -96);
2308 sljit_emit_op2(compiler, SLJIT_ISUB | SLJIT_SET_S | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
2309 SET_NEXT_BYTE(SLJIT_C_LESS);
2310 SET_NEXT_BYTE(SLJIT_C_SIG_GREATER);
2311
2312 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2313
2314 code.code = sljit_generate_code(compiler);
2315 CHECK(compiler);
2316 sljit_free_compiler(compiler);
2317
2318 code.func1((sljit_sw)&buf);
2319
2320 FAILED(buf[0] != RESULT(1), "test27 case 1 failed\n");
2321 FAILED(buf[1] != RESULT(2), "test27 case 2 failed\n");
2322 FAILED(buf[2] != 2, "test27 case 3 failed\n");
2323 FAILED(buf[3] != 1, "test27 case 4 failed\n");
2324 FAILED(buf[4] != RESULT(1), "test27 case 5 failed\n");
2325 FAILED(buf[5] != RESULT(2), "test27 case 6 failed\n");
2326 FAILED(buf[6] != 2, "test27 case 7 failed\n");
2327 FAILED(buf[7] != 1, "test27 case 8 failed\n");
2328
2329 FAILED(buf[8] != 2, "test27 case 9 failed\n");
2330 FAILED(buf[9] != 1, "test27 case 10 failed\n");
2331 FAILED(buf[10] != 2, "test27 case 11 failed\n");
2332 FAILED(buf[11] != 1, "test27 case 12 failed\n");
2333 FAILED(buf[12] != 1, "test27 case 13 failed\n");
2334 FAILED(buf[13] != 2, "test27 case 14 failed\n");
2335 FAILED(buf[14] != 2, "test27 case 15 failed\n");
2336 FAILED(buf[15] != 1, "test27 case 16 failed\n");
2337 FAILED(buf[16] != 1, "test27 case 17 failed\n");
2338 FAILED(buf[17] != 2, "test27 case 18 failed\n");
2339
2340 FAILED(buf[18] != RESULT(1), "test27 case 19 failed\n");
2341 FAILED(buf[19] != RESULT(2), "test27 case 20 failed\n");
2342 FAILED(buf[20] != 2, "test27 case 21 failed\n");
2343 FAILED(buf[21] != 1, "test27 case 22 failed\n");
2344
2345 FAILED(buf[22] != 5, "test27 case 23 failed\n");
2346 FAILED(buf[23] != 9, "test27 case 24 failed\n");
2347
2348 FAILED(buf[24] != 2, "test27 case 25 failed\n");
2349 FAILED(buf[25] != 1, "test27 case 26 failed\n");
2350
2351 FAILED(buf[26] != 1, "test27 case 27 failed\n");
2352 FAILED(buf[27] != 1, "test27 case 28 failed\n");
2353 FAILED(buf[28] != 1, "test27 case 29 failed\n");
2354 FAILED(buf[29] != 1, "test27 case 30 failed\n");
2355
2356 FAILED(buf[30] != 1, "test27 case 31 failed\n");
2357 FAILED(buf[31] != 0, "test27 case 32 failed\n");
2358
2359 FAILED(buf[32] != 2, "test27 case 33 failed\n");
2360 FAILED(buf[33] != 1, "test27 case 34 failed\n");
2361 FAILED(buf[34] != 2, "test27 case 35 failed\n");
2362 FAILED(buf[35] != 1, "test27 case 36 failed\n");
2363 FAILED(buf[36] != 10, "test27 case 37 failed\n");
2364
2365 sljit_free_code(code.code);
2366 successful_tests++;
2367 #undef SET_NEXT_BYTE
2368 #undef RESULT
2369 }
2370
2371 static void test28(void)
2372 {
2373 /* Test mov. */
2374 executable_code code;
2375 struct sljit_compiler* compiler = sljit_create_compiler();
2376 struct sljit_const* const1;
2377 struct sljit_label* label;
2378 sljit_uw label_addr;
2379 sljit_sw buf[5];
2380
2381 if (verbose)
2382 printf("Run test28\n");
2383
2384 FAILED(!compiler, "cannot create compiler\n");
2385
2386 buf[0] = -36;
2387 buf[1] = 8;
2388 buf[2] = 0;
2389 buf[3] = 10;
2390 buf[4] = 0;
2391
2392 FAILED(!compiler, "cannot create compiler\n");
2393 sljit_emit_enter(compiler, 1, 5, 5, 0);
2394 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG1, 0, SLJIT_IMM, -234);
2395 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw));
2396 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_SAVED_EREG1, 0, SLJIT_TEMPORARY_EREG1, 0, SLJIT_TEMPORARY_EREG2, 0);
2397 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_SAVED_EREG1, 0);
2398 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SAVED_EREG1, 0, SLJIT_IMM, 0);
2399 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_SAVED_EREG1, 0, SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
2400 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_sw), SLJIT_SAVED_EREG1, 0);
2401 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_sw));
2402 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SAVED_EREG2, 0, SLJIT_SAVED_EREG2, 0, SLJIT_TEMPORARY_EREG2, 0);
2403 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_sw), SLJIT_SAVED_EREG2, 0);
2404 const1 = sljit_emit_const(compiler, SLJIT_SAVED_EREG1, 0, 0);
2405 sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_SAVED_EREG1, 0);
2406 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SAVED_EREG1, 0, SLJIT_SAVED_EREG1, 0, SLJIT_IMM, 100);
2407 label = sljit_emit_label(compiler);
2408 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_sw), SLJIT_SAVED_EREG1, 0);
2409 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG2, 0);
2410
2411 code.code = sljit_generate_code(compiler);
2412 CHECK(compiler);
2413 label_addr = sljit_get_label_addr(label);
2414 sljit_set_const(sljit_get_const_addr(const1), label_addr);
2415 sljit_free_compiler(compiler);
2416
2417 FAILED(code.func1((sljit_sw)&buf) != 8, "test28 case 1 failed\n");
2418 FAILED(buf[1] != -1872, "test28 case 2 failed\n");
2419 FAILED(buf[2] != 1, "test28 case 3 failed\n");
2420 FAILED(buf[3] != 2, "test28 case 4 failed\n");
2421 FAILED(buf[4] != label_addr, "test28 case 5 failed\n");
2422
2423 sljit_free_code(code.code);
2424 successful_tests++;
2425 }
2426
2427 static void test29(void)
2428 {
2429 /* Test signed/unsigned bytes and halfs. */
2430 executable_code code;
2431 struct sljit_compiler* compiler = sljit_create_compiler();
2432 sljit_sw buf[25];
2433
2434 if (verbose)
2435 printf("Run test29\n");
2436
2437 buf[0] = 0;
2438 buf[1] = 0;
2439 buf[2] = 0;
2440 buf[3] = 0;
2441 buf[4] = 0;
2442 buf[5] = 0;
2443 buf[6] = 0;
2444 buf[7] = 0;
2445 buf[8] = 0;
2446 buf[9] = 0;
2447 buf[10] = 0;
2448 buf[11] = 0;
2449 buf[12] = 0;
2450 buf[13] = 0;
2451 buf[14] = 0;
2452 buf[15] = 0;
2453 buf[16] = 0;
2454 buf[17] = 0;
2455 buf[18] = 0;
2456 buf[19] = 0;
2457 buf[20] = 0;
2458 buf[21] = 0;
2459 buf[22] = 0;
2460 buf[23] = 0;
2461 buf[24] = 0;
2462
2463 FAILED(!compiler, "cannot create compiler\n");
2464 sljit_emit_enter(compiler, 1, 5, 5, 0);
2465
2466 sljit_emit_op1(compiler, SLJIT_MOV_SB, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -187);
2467 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
2468 sljit_emit_op1(compiler, SLJIT_MOVU_SB, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -605);
2469 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SCRATCH_REG1, 0);
2470 sljit_emit_op1(compiler, SLJIT_MOV_UB, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -56);
2471 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SCRATCH_REG1, 0);
2472 sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_TEMPORARY_EREG2, 0, SLJIT_IMM, 0xcde5);
2473 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_EREG2, 0);
2474
2475 sljit_emit_op1(compiler, SLJIT_MOV_SH, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -45896);
2476 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SCRATCH_REG1, 0);
2477 sljit_emit_op1(compiler, SLJIT_MOVU_SH, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -1472797);
2478 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SCRATCH_REG1, 0);
2479 sljit_emit_op1(compiler, SLJIT_MOV_UH, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -12890);
2480 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SCRATCH_REG1, 0);
2481 sljit_emit_op1(compiler, SLJIT_MOVU_UH, SLJIT_TEMPORARY_EREG2, 0, SLJIT_IMM, 0x9cb0a6);
2482 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_EREG2, 0);
2483
2484 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2485 sljit_emit_op1(compiler, SLJIT_MOV_SI, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(-3580429715));
2486 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SCRATCH_REG1, 0);
2487 sljit_emit_op1(compiler, SLJIT_MOVU_SI, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(-100722768662));
2488 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SCRATCH_REG1, 0);
2489 sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(-1457052677972));
2490 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SCRATCH_REG1, 0);
2491 sljit_emit_op1(compiler, SLJIT_MOVU_UI, SLJIT_TEMPORARY_EREG2, 0, SLJIT_IMM, SLJIT_W(0xcef97a70b5));
2492 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_EREG2, 0);
2493 #else
2494 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 4 * sizeof(sljit_uw));
2495 #endif
2496
2497 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, -187);
2498 sljit_emit_op1(compiler, SLJIT_MOV_SB, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
2499 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SCRATCH_REG1, 0);
2500 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_IMM, -605);
2501 sljit_emit_op1(compiler, SLJIT_MOVU_SB, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG3, 0);
2502 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SCRATCH_REG1, 0);
2503 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, -56);
2504 sljit_emit_op1(compiler, SLJIT_MOV_UB, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG3, 0);
2505 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SCRATCH_REG1, 0);
2506 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG1, 0, SLJIT_IMM, 0xcde5);
2507 sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_TEMPORARY_EREG2, 0, SLJIT_TEMPORARY_EREG1, 0);
2508 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_EREG2, 0);
2509
2510 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, -45896);
2511 sljit_emit_op1(compiler, SLJIT_MOV_SH, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
2512 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SCRATCH_REG1, 0);
2513 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_IMM, -1472797);
2514 sljit_emit_op1(compiler, SLJIT_MOVU_SH, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG3, 0);
2515 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SCRATCH_REG1, 0);
2516 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, -12890);
2517 sljit_emit_op1(compiler, SLJIT_MOV_UH, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG3, 0);
2518 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SCRATCH_REG1, 0);
2519 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG1, 0, SLJIT_IMM, 0x9cb0a6);
2520 sljit_emit_op1(compiler, SLJIT_MOVU_UH, SLJIT_TEMPORARY_EREG2, 0, SLJIT_TEMPORARY_EREG1, 0);
2521 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_EREG2, 0);
2522
2523 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2524 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, SLJIT_W(-3580429715));
2525 sljit_emit_op1(compiler, SLJIT_MOV_SI, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
2526 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SCRATCH_REG1, 0);
2527 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_IMM, SLJIT_W(-100722768662));
2528 sljit_emit_op1(compiler, SLJIT_MOVU_SI, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG3, 0);
2529 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SCRATCH_REG1, 0);
2530 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, SLJIT_W(-1457052677972));
2531 sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG3, 0);
2532 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SCRATCH_REG1, 0);
2533 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG1, 0, SLJIT_IMM, SLJIT_W(0xcef97a70b5));
2534 sljit_emit_op1(compiler, SLJIT_MOVU_UI, SLJIT_TEMPORARY_EREG2, 0, SLJIT_TEMPORARY_EREG1, 0);
2535 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_EREG2, 0);
2536 #else
2537 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 4 * sizeof(sljit_uw));
2538 #endif
2539
2540 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_IMM, 0x9faa5);
2541 sljit_emit_op1(compiler, SLJIT_MOV_SB, SLJIT_SAVED_REG3, 0, SLJIT_SAVED_REG3, 0);
2542 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SAVED_REG3, 0);
2543
2544 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2545
2546 code.code = sljit_generate_code(compiler);
2547 CHECK(compiler);
2548 sljit_free_compiler(compiler);
2549
2550 code.func1((sljit_sw)&buf);
2551 FAILED(buf[0] != 69, "test29 case 1 failed\n");
2552 FAILED(buf[1] != -93, "test29 case 2 failed\n");
2553 FAILED(buf[2] != 200, "test29 case 3 failed\n");
2554 FAILED(buf[3] != 0xe5, "test29 case 4 failed\n");
2555 FAILED(buf[4] != 19640, "test29 case 5 failed\n");
2556 FAILED(buf[5] != -31005, "test29 case 6 failed\n");
2557 FAILED(buf[6] != 52646, "test29 case 7 failed\n");
2558 FAILED(buf[7] != 0xb0a6, "test29 case 8 failed\n");
2559
2560 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2561 FAILED(buf[8] != SLJIT_W(714537581), "test29 case 9 failed\n");
2562 FAILED(buf[9] != SLJIT_W(-1938520854), "test29 case 10 failed\n");
2563 FAILED(buf[10] != SLJIT_W(3236202668), "test29 case 11 failed\n");
2564 FAILED(buf[11] != SLJIT_W(0xf97a70b5), "test29 case 12 failed\n");
2565 #endif
2566
2567 FAILED(buf[12] != 69, "test29 case 13 failed\n");
2568 FAILED(buf[13] != -93, "test29 case 14 failed\n");
2569 FAILED(buf[14] != 200, "test29 case 15 failed\n");
2570 FAILED(buf[15] != 0xe5, "test29 case 16 failed\n");
2571 FAILED(buf[16] != 19640, "test29 case 17 failed\n");
2572 FAILED(buf[17] != -31005, "test29 case 18 failed\n");
2573 FAILED(buf[18] != 52646, "test29 case 19 failed\n");
2574 FAILED(buf[19] != 0xb0a6, "test29 case 20 failed\n");
2575
2576 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2577 FAILED(buf[20] != SLJIT_W(714537581), "test29 case 21 failed\n");
2578 FAILED(buf[21] != SLJIT_W(-1938520854), "test29 case 22 failed\n");
2579 FAILED(buf[22] != SLJIT_W(3236202668), "test29 case 23 failed\n");
2580 FAILED(buf[23] != SLJIT_W(0xf97a70b5), "test29 case 24 failed\n");
2581 #endif
2582
2583 FAILED(buf[24] != -91, "test29 case 25 failed\n");
2584
2585 sljit_free_code(code.code);
2586 successful_tests++;
2587 }
2588
2589 static void test30(void)
2590 {
2591 /* Test unused results. */
2592 executable_code code;
2593 struct sljit_compiler* compiler = sljit_create_compiler();
2594 sljit_sw buf[1];
2595
2596 if (verbose)
2597 printf("Run test30\n");
2598
2599 FAILED(!compiler, "cannot create compiler\n");
2600 buf[0] = 0;
2601 sljit_emit_enter(compiler, 1, 5, 5, 0);
2602
2603 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
2604 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2605 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2606 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG1, 0, SLJIT_IMM, 1);
2607 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG2, 0, SLJIT_IMM, 1);
2608 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2609 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SAVED_REG2, 0, SLJIT_IMM, SLJIT_W(-0x123ffffffff));
2610 #else
2611 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);
2612 #endif
2613 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_IMM, 1);
2614 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG1, 0, SLJIT_IMM, 1);
2615 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG2, 0, SLJIT_IMM, 1);
2616
2617 /* Some calculations with unused results. */
2618 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG3, 0);
2619 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG2, 0);
2620 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
2621 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
2622 sljit_emit_op2(compiler, SLJIT_ISUB | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
2623 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_UNUSED, 0, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
2624 sljit_emit_op2(compiler, SLJIT_SHL | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SAVED_EREG1, 0, SLJIT_SCRATCH_REG3, 0);
2625 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 5);
2626 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 0xff);
2627 sljit_emit_op1(compiler, SLJIT_INOT | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SAVED_REG2, 0);
2628
2629 /* Testing that any change happens. */
2630 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
2631 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG3, 0);
2632 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_TEMPORARY_EREG1, 0);
2633 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_TEMPORARY_EREG2, 0);
2634 sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0);
2635 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG2, 0);
2636 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG3, 0);
2637 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_EREG1, 0);
2638 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_EREG2, 0);
2639
2640 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2641
2642 code.code = sljit_generate_code(compiler);
2643 CHECK(compiler);
2644 sljit_free_compiler(compiler);
2645
2646 code.func1((sljit_sw)&buf);
2647 FAILED(buf[0] != 9, "test30 case 1 failed\n");
2648
2649 sljit_free_code(code.code);
2650 successful_tests++;
2651 }
2652
2653 static void test31(void)
2654 {
2655 /* Integer mul and set flags. */
2656 executable_code code;
2657 struct sljit_compiler* compiler = sljit_create_compiler();
2658 sljit_sw buf[12];
2659 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2660 sljit_sw big_word = SLJIT_W(0x7fffffff00000000);
2661 sljit_sw big_word2 = SLJIT_W(0x7fffffff00000012);
2662 #else
2663 sljit_sw big_word = 0x7fffffff;
2664 sljit_sw big_word2 = 0x00000012;
2665 #endif
2666
2667 if (verbose)
2668 printf("Run test31\n");
2669
2670 buf[0] = 3;
2671 buf[1] = 3;
2672 buf[2] = 3;
2673 buf[3] = 3;
2674 buf[4] = 3;
2675 buf[5] = 3;
2676 buf[6] = 3;
2677 buf[7] = 3;
2678 buf[8] = 3;
2679 buf[9] = 3;
2680 buf[10] = 3;
2681 buf[11] = 3;
2682
2683 FAILED(!compiler, "cannot create compiler\n");
2684
2685 sljit_emit_enter(compiler, 1, 3, 5, 0);
2686 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
2687 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, -45);
2688 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_C_MUL_NOT_OVERFLOW);
2689 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_C_MUL_OVERFLOW);
2690
2691 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_IMM, big_word);
2692 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_O, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG3, 0, SLJIT_IMM, -2);
2693 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 33); /* Should not change flags. */
2694 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0); /* Should not change flags. */
2695 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_sw), SLJIT_C_MUL_OVERFLOW);
2696 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_sw), SLJIT_C_MUL_NOT_OVERFLOW);
2697
2698 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SAVED_EREG1, 0, SLJIT_IMM, 0x3f6b0);
2699 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SAVED_EREG2, 0, SLJIT_IMM, 0x2a783);
2700 sljit_emit_op2(compiler, SLJIT_IMUL | SLJIT_SET_O, SLJIT_SCRATCH_REG2, 0, SLJIT_SAVED_EREG1, 0, SLJIT_SAVED_EREG2, 0);
2701 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_sw), SLJIT_C_MUL_OVERFLOW);
2702 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0);
2703
2704 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, big_word2);
2705 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG2, 0);
2706 sljit_emit_op2(compiler, SLJIT_IMUL | SLJIT_SET_O, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 23);
2707 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_sw), SLJIT_C_MUL_OVERFLOW);
2708
2709 sljit_emit_op2(compiler, SLJIT_IMUL | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, -23);
2710 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_sw), SLJIT_C_MUL_NOT_OVERFLOW);
2711 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, -23);
2712 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_sw), SLJIT_C_MUL_NOT_OVERFLOW);
2713
2714 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 67);
2715 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_O, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, -23);
2716 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 9 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0);
2717
2718 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2719
2720 code.code = sljit_generate_code(compiler);
2721 CHECK(compiler);
2722 sljit_free_compiler(compiler);
2723
2724 code.func1((sljit_sw)&buf);
2725
2726 FAILED(buf[0] != 1, "test31 case 1 failed\n");
2727 FAILED(buf[1] != 2, "test31 case 2 failed\n");
2728 /* Qemu issues for 64 bit muls. */
2729 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2730 FAILED(buf[2] != 1, "test31 case 3 failed\n");
2731 FAILED(buf[3] != 2, "test31 case 4 failed\n");
2732 #endif
2733 FAILED(buf[4] != 1, "test31 case 5 failed\n");
2734 FAILED((buf[5] & 0xffffffff) != 0x85540c10, "test31 case 6 failed\n");
2735 FAILED(buf[6] != 2, "test31 case 7 failed\n");
2736 FAILED(buf[7] != 1, "test31 case 8 failed\n");
2737 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2738 FAILED(buf[8] != 1, "test31 case 9 failed\n");
2739 #endif
2740 FAILED(buf[9] != -1541, "test31 case 10 failed\n");
2741
2742 sljit_free_code(code.code);
2743 successful_tests++;
2744 }
2745
2746 static void test32(void)
2747 {
2748 /* Floating point set flags. */
2749 executable_code code;
2750 struct sljit_compiler* compiler = sljit_create_compiler();
2751
2752 sljit_sw buf[16];
2753 union {
2754 sljit_d value;
2755 struct {
2756 sljit_si value1;
2757 sljit_si value2;
2758 } u;
2759 } dbuf[4];
2760
2761 if (verbose)
2762 printf("Run test32\n");
2763
2764 buf[0] = 5;
2765 buf[1] = 5;
2766 buf[2] = 5;
2767 buf[3] = 5;
2768 buf[4] = 5;
2769 buf[5] = 5;
2770 buf[6] = 5;
2771 buf[7] = 5;
2772 buf[8] = 5;
2773 buf[9] = 5;
2774 buf[10] = 5;
2775 buf[11] = 5;
2776 buf[12] = 5;
2777 buf[13] = 5;
2778 buf[14] = 5;
2779 buf[15] = 5;
2780
2781 /* Two NaNs */
2782 dbuf[0].u.value1 = 0x7fffffff;
2783 dbuf[0].u.value2 = 0x7fffffff;
2784 dbuf[1].u.value1 = 0x7fffffff;
2785 dbuf[1].u.value2 = 0x7fffffff;
2786 dbuf[2].value = -13.0;
2787 dbuf[3].value = 27.0;
2788
2789 if (!sljit_is_fpu_available()) {
2790 printf("no fpu available, test32 skipped\n");
2791 successful_tests++;
2792 if (compiler)
2793 sljit_free_compiler(compiler);
2794 return;
2795 }
2796
2797 FAILED(!compiler, "cannot create compiler\n");
2798 SLJIT_ASSERT(sizeof(sljit_d) == 8 && sizeof(sljit_si) == 4 && sizeof(dbuf[0]) == 8);
2799
2800 sljit_emit_enter(compiler, 2, 1, 2, 0);
2801
2802 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 0);
2803 sljit_emit_fop1(compiler, SLJIT_CMPD | SLJIT_SET_E, SLJIT_MEM1(SLJIT_SAVED_REG2), 3 * sizeof(sljit_d), SLJIT_FLOAT_REG1, 0);
2804 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 2 * sizeof(sljit_d));
2805 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_C_FLOAT_UNORDERED);
2806 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_C_FLOAT_ORDERED);
2807
2808 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG3, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 3 * sizeof(sljit_d));
2809 sljit_emit_fop1(compiler, SLJIT_CMPD | SLJIT_SET_E | SLJIT_SET_S, SLJIT_FLOAT_REG2, 0, SLJIT_FLOAT_REG3, 0);
2810 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_sw), SLJIT_C_FLOAT_UNORDERED);
2811 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_sw), SLJIT_C_FLOAT_ORDERED);
2812 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_sw), SLJIT_C_FLOAT_LESS);
2813 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw), SLJIT_C_FLOAT_GREATER_EQUAL);
2814 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_sw), SLJIT_C_FLOAT_GREATER);
2815 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_sw), SLJIT_C_FLOAT_LESS_EQUAL);
2816 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_sw), SLJIT_C_FLOAT_EQUAL);
2817 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 9 * sizeof(sljit_sw), SLJIT_C_FLOAT_NOT_EQUAL);
2818
2819 sljit_emit_fop1(compiler, SLJIT_CMPD | SLJIT_SET_E, SLJIT_FLOAT_REG3, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 3 * sizeof(sljit_d));
2820 sljit_emit_fop2(compiler, SLJIT_ADDD, SLJIT_FLOAT_REG4, 0, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_d));
2821 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 10 * sizeof(sljit_sw), SLJIT_C_FLOAT_UNORDERED);
2822 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 11 * sizeof(sljit_sw), SLJIT_C_FLOAT_EQUAL);
2823
2824 sljit_emit_fop1(compiler, SLJIT_CMPD | SLJIT_SET_S, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_d), SLJIT_FLOAT_REG1, 0);
2825 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 12 * sizeof(sljit_sw), SLJIT_C_FLOAT_ORDERED);
2826
2827 sljit_emit_fop1(compiler, SLJIT_CMPD | SLJIT_SET_S, SLJIT_FLOAT_REG4, 0, SLJIT_FLOAT_REG3, 0);
2828 sljit_emit_op1(compiler, SLJIT_MOV_UB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 0);
2829 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 13 * sizeof(sljit_sw), SLJIT_C_FLOAT_UNORDERED);
2830
2831 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2832
2833 code.code = sljit_generate_code(compiler);
2834 CHECK(compiler);
2835 sljit_free_compiler(compiler);
2836
2837 code.func2((sljit_sw)&buf, (sljit_sw)&dbuf);
2838
2839 FAILED(buf[0] != 1, "test32 case 1 failed\n");
2840 FAILED(buf[1] != 2, "test32 case 2 failed\n");
2841 FAILED(buf[2] != 2, "test32 case 3 failed\n");
2842 FAILED(buf[3] != 1, "test32 case 4 failed\n");
2843 FAILED(buf[4] != 1, "test32 case 5 failed\n");
2844 FAILED(buf[5] != 2, "test32 case 6 failed\n");
2845 FAILED(buf[6] != 2, "test32 case 7 failed\n");
2846 FAILED(buf[7] != 1, "test32 case 8 failed\n");
2847 FAILED(buf[8] != 2, "test32 case 9 failed\n");
2848 FAILED(buf[9] != 1, "test32 case 10 failed\n");
2849 FAILED(buf[10] != 2, "test32 case 11 failed\n");
2850 FAILED(buf[11] != 1, "test32 case 12 failed\n");
2851 FAILED(buf[12] != 2, "test32 case 13 failed\n");
2852 FAILED(buf[13] != 1, "test32 case 14 failed\n");
2853
2854 sljit_free_code(code.code);
2855 successful_tests++;
2856 }
2857
2858 static void test33(void)
2859 {
2860 /* Test keep flags. */
2861 executable_code code;
2862 struct sljit_compiler* compiler = sljit_create_compiler();
2863 sljit_sw buf[7];
2864 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2865 sljit_sw big_word = SLJIT_W(0x8000000000000003);
2866 #else
2867 sljit_sw big_word = 0x80000003;
2868 #endif
2869
2870 if (verbose)
2871 printf("Run test33\n");
2872
2873 buf[0] = 3;
2874 buf[1] = 3;
2875 buf[2] = 3;
2876 buf[3] = 3;
2877 buf[4] = 3;
2878 buf[5] = 3;
2879 buf[6] = 3;
2880
2881 FAILED(!compiler, "cannot create compiler\n");
2882
2883 sljit_emit_enter(compiler, 1, 3, 3, 0);
2884 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, big_word);
2885 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_E | SLJIT_SET_C, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, big_word);
2886 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG2, 0);
2887 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 8);
2888 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_KEEP_FLAGS, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 8);
2889 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
2890 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
2891 sljit_emit_op2(compiler, SLJIT_ADDC | SLJIT_KEEP_FLAGS, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
2892 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 7);
2893
2894 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 8);
2895 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 8);
2896 sljit_emit_op2(compiler, SLJIT_SHL | SLJIT_KEEP_FLAGS, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw));
2897 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2898
2899 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw), SLJIT_IMM, 0x124);
2900 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 2);
2901 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
2902 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_KEEP_FLAGS, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
2903 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw), SLJIT_C_NOT_EQUAL);
2904
2905 /* PowerPC specific test. */
2906 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -1);
2907 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_C, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 2);
2908 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x80);
2909 sljit_emit_op2(compiler, SLJIT_ASHR | SLJIT_KEEP_FLAGS, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
2910 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
2911 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
2912
2913 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2914
2915 code.code = sljit_generate_code(compiler);
2916 CHECK(compiler);
2917 sljit_free_compiler(compiler);
2918
2919 code.func1((sljit_sw)&buf);
2920
2921 FAILED(buf[0] != 6, "test33 case 1 failed\n");
2922 FAILED(buf[1] != 1, "test33 case 2 failed\n");
2923 FAILED(buf[2] != 8, "test33 case 3 failed\n");
2924 FAILED(buf[3] != 16, "test33 case 4 failed\n");
2925 FAILED(buf[4] != 1, "test33 case 5 failed\n");
2926 FAILED(buf[5] != 0x125, "test33 case 6 failed\n");
2927 FAILED(buf[6] != 1, "test33 case 7 failed\n");
2928
2929 sljit_free_code(code.code);
2930 successful_tests++;
2931 }
2932
2933 static void test34(void)
2934 {
2935 /* Test fast calls. */
2936 executable_code codeA;
2937 executable_code codeB;
2938 executable_code codeC;
2939 executable_code codeD;
2940 executable_code codeE;
2941 executable_code codeF;
2942 struct sljit_compiler* compiler;
2943 struct sljit_jump *jump;
2944 struct sljit_label* label;
2945 sljit_uw addr;
2946 sljit_p buf[2];
2947
2948 if (verbose)
2949 printf("Run test34\n");
2950
2951 buf[0] = 0;
2952 buf[1] = 0;
2953
2954 /* A */
2955 compiler = sljit_create_compiler();
2956 FAILED(!compiler, "cannot create compiler\n");
2957 sljit_set_context(compiler, 1, 5, 5, 2 * sizeof(sljit_p));
2958
2959 sljit_emit_fast_enter(compiler, SLJIT_SCRATCH_REG2, 0);
2960 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 4);
2961 sljit_emit_fast_return(compiler, SLJIT_SCRATCH_REG2, 0);
2962
2963 codeA.code = sljit_generate_code(compiler);
2964 CHECK(compiler);
2965 sljit_free_compiler(compiler);
2966
2967 /* B */
2968 compiler = sljit_create_compiler();
2969 FAILED(!compiler, "cannot create compiler\n");
2970 sljit_set_context(compiler, 1, 5, 5, 2 * sizeof(sljit_p));
2971
2972 sljit_emit_fast_enter(compiler, SLJIT_TEMPORARY_EREG2, 0);
2973 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 6);
2974 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeA.code));
2975 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_SCRATCH_REG2, 0);
2976 sljit_emit_fast_return(compiler, SLJIT_TEMPORARY_EREG2, 0);
2977
2978 codeB.code = sljit_generate_code(compiler);
2979 CHECK(compiler);
2980 sljit_free_compiler(compiler);
2981
2982 /* C */
2983 compiler = sljit_create_compiler();
2984 FAILED(!compiler, "cannot create compiler\n");
2985 sljit_set_context(compiler, 1, 5, 5, 2 * sizeof(sljit_p));
2986
2987 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), sizeof(sljit_p));
2988 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 8);
2989 jump = sljit_emit_jump(compiler, SLJIT_REWRITABLE_JUMP | SLJIT_FAST_CALL);
2990 sljit_set_target(jump, SLJIT_FUNC_OFFSET(codeB.code));
2991 sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), sizeof(sljit_p));
2992
2993 codeC.code = sljit_generate_code(compiler);
2994 CHECK(compiler);
2995 sljit_free_compiler(compiler);
2996
2997 /* D */
2998 compiler = sljit_create_compiler();
2999 FAILED(!compiler, "cannot create compiler\n");
3000 sljit_set_context(compiler, 1, 5, 5, 2 * sizeof(sljit_p));
3001
3002 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), 0);
3003 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 10);
3004 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeC.code));
3005 sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), 0);
3006
3007 codeD.code = sljit_generate_code(compiler);
3008 CHECK(compiler);
3009 sljit_free_compiler(compiler);
3010
3011 /* E */
3012 compiler = sljit_create_compiler();
3013 FAILED(!compiler, "cannot create compiler\n");
3014 sljit_set_context(compiler, 1, 5, 5, 2 * sizeof(sljit_p));
3015
3016 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
3017 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 12);
3018 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_p), SLJIT_IMM, SLJIT_FUNC_OFFSET(codeD.code));
3019 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_p));
3020 sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
3021
3022 codeE.code = sljit_generate_code(compiler);
3023 CHECK(compiler);
3024 sljit_free_compiler(compiler);
3025
3026 /* F */
3027 compiler = sljit_create_compiler();
3028 FAILED(!compiler, "cannot create compiler\n");
3029
3030 sljit_emit_enter(compiler, 1, 5, 5, 2 * sizeof(sljit_p));
3031 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
3032 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeE.code));
3033 label = sljit_emit_label(compiler);
3034 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0);
3035
3036 codeF.code = sljit_generate_code(compiler);
3037 CHECK(compiler);
3038 addr = sljit_get_label_addr(label);
3039 sljit_free_compiler(compiler);
3040
3041 FAILED(codeF.func1((sljit_sw)&buf) != 40, "test34 case 1 failed\n");
3042 FAILED(buf[0] != addr - SLJIT_RETURN_ADDRESS_OFFSET, "test34 case 2 failed\n");
3043
3044 sljit_free_code(codeA.code);
3045 sljit_free_code(codeB.code);
3046 sljit_free_code(codeC.code);
3047 sljit_free_code(codeD.code);
3048 sljit_free_code(codeE.code);
3049 sljit_free_code(codeF.code);
3050 successful_tests++;
3051 }
3052
3053 static void test35(void)
3054 {
3055 /* More complicated tests for fast calls. */
3056 executable_code codeA;
3057 executable_code codeB;
3058 executable_code codeC;
3059 struct sljit_compiler* compiler;
3060 struct sljit_jump *jump;
3061 struct sljit_label* label;
3062 sljit_uw return_addr, jump_addr;
3063 sljit_p buf[1];
3064
3065 if (verbose)
3066 printf("Run test35\n");
3067
3068 buf[0] = 0;
3069
3070 /* A */
3071 compiler = sljit_create_compiler();
3072 FAILED(!compiler, "cannot create compiler\n");
3073 sljit_set_context(compiler, 0, 2, 2, 0);
3074
3075 sljit_emit_fast_enter(compiler, SLJIT_MEM0(), (sljit_sw)&buf[0]);
3076 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 5);
3077 jump = sljit_emit_jump(compiler, SLJIT_REWRITABLE_JUMP | SLJIT_FAST_CALL);
3078 sljit_set_target(jump, 0);
3079 label = sljit_emit_label(compiler);
3080 sljit_emit_fast_return(compiler, SLJIT_MEM0(), (sljit_sw)&buf[0]);
3081
3082 codeA.code = sljit_generate_code(compiler);
3083 CHECK(compiler);
3084 return_addr = sljit_get_label_addr(label) - SLJIT_RETURN_ADDRESS_OFFSET;
3085 jump_addr = sljit_get_jump_addr(jump);
3086 sljit_free_compiler(compiler);
3087
3088 /* B */
3089 compiler = sljit_create_compiler();
3090 FAILED(!compiler, "cannot create compiler\n");
3091 sljit_set_context(compiler, 0, 2, 2, 0);
3092
3093 sljit_emit_fast_enter(compiler, SLJIT_UNUSED, 0);
3094 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 7);
3095 sljit_emit_fast_return(compiler, SLJIT_IMM, return_addr);
3096
3097 codeB.code = sljit_generate_code(compiler);
3098 CHECK(compiler);
3099 sljit_free_compiler(compiler);
3100 sljit_set_jump_addr(jump_addr, SLJIT_FUNC_OFFSET(codeB.code));
3101
3102 /* C */
3103 compiler = sljit_create_compiler();
3104 FAILED(!compiler, "cannot create compiler\n");
3105
3106 sljit_emit_enter(compiler, 0, 2, 2, 0);
3107 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
3108 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeA.code));
3109 label = sljit_emit_label(compiler);
3110 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0);
3111
3112 codeC.code = sljit_generate_code(compiler);
3113 CHECK(compiler);
3114 return_addr = sljit_get_label_addr(label);
3115 sljit_free_compiler(compiler);
3116
3117 FAILED(codeC.func0() != 12, "test35 case 1 failed\n");
3118 FAILED(buf[0] != return_addr - SLJIT_RETURN_ADDRESS_OFFSET, "test35 case 2 failed\n");
3119
3120 sljit_free_code(codeA.code);
3121 sljit_free_code(codeB.code);
3122 sljit_free_code(codeC.code);
3123 successful_tests++;
3124 }
3125
3126 static sljit_si cmp_test(struct sljit_compiler *compiler, sljit_si type, sljit_si src1, sljit_sw src1w, sljit_si src2, sljit_sw src2w)
3127 {
3128 /* 2 = true, 1 = false */
3129 struct sljit_jump* jump;
3130 struct sljit_label* label;
3131
3132 if (sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_SAVED_REG1), 1, SLJIT_IMM, 2))
3133 return compiler->error;
3134 jump = sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w);
3135 if (!jump)
3136 return compiler->error;
3137 if (sljit_emit_op1(compiler, SLJIT_MOV_UB, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 1))
3138 return compiler->error;
3139 label = sljit_emit_label(compiler);
3140 if (!label)
3141 return compiler->error;
3142 sljit_set_label(jump, label);
3143 return SLJIT_SUCCESS;
3144 }
3145
3146 #define TEST_CASES (7 + 10 + 12 + 11 + 4)
3147 static void test36(void)
3148 {
3149 /* Compare instruction. */
3150 executable_code code;
3151 struct sljit_compiler* compiler = sljit_create_compiler();
3152
3153 sljit_sb buf[TEST_CASES];
3154 sljit_sb compare_buf[TEST_CASES] = {
3155 1, 1, 2, 2, 1, 2, 2,
3156 1, 1, 2, 2, 2, 1, 2, 2, 1, 1,
3157 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2,
3158 2, 1, 2, 1, 1, 1, 2, 1, 2, 1, 2,
3159 2, 1, 1, 2
3160 };
3161 sljit_sw data[4];
3162 sljit_si i;
3163
3164 if (verbose)
3165 printf("Run test36\n");
3166
3167 FAILED(!compiler, "cannot create compiler\n");
3168 for (i = 0; i < TEST_CASES; ++i)
3169 buf[i] = 100;
3170 data[0] = 32;
3171 data[1] = -9;
3172 data[2] = 43;
3173 data[3] = -13;
3174
3175 sljit_emit_enter(compiler, 2, 3, 2, 0);
3176 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 1);
3177
3178 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 13);
3179 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 15);
3180 cmp_test(compiler, SLJIT_C_EQUAL, SLJIT_IMM, 9, SLJIT_SCRATCH_REG1, 0);
3181 cmp_test(compiler, SLJIT_C_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
3182 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 3);
3183 cmp_test(compiler, SLJIT_C_EQUAL, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SCRATCH_REG1), SLJIT_WORD_SHIFT, SLJIT_IMM, -13);
3184 cmp_test(compiler, SLJIT_C_NOT_EQUAL, SLJIT_IMM, 0, SLJIT_SCRATCH_REG1, 0);
3185 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
3186 cmp_test(compiler, SLJIT_C_NOT_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 0, SLJIT_SCRATCH_REG1, 0);
3187 cmp_test(compiler, SLJIT_C_EQUAL, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SCRATCH_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SCRATCH_REG1), SLJIT_WORD_SHIFT);
3188 cmp_test(compiler, SLJIT_C_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
3189
3190 cmp_test(compiler, SLJIT_C_SIG_LESS, SLJIT_MEM1(SLJIT_SAVED_REG2), 0, SLJIT_IMM, 0);
3191 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -8);
3192 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
3193 cmp_test(compiler, SLJIT_C_SIG_GREATER, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
3194 cmp_test(compiler, SLJIT_C_SIG_LESS_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
3195 cmp_test(compiler, SLJIT_C_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
3196 cmp_test(compiler, SLJIT_C_SIG_GREATER_EQUAL, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
3197 cmp_test(compiler, SLJIT_C_SIG_GREATER, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 2 * sizeof(sljit_sw));
3198 cmp_test(compiler, SLJIT_C_SIG_LESS_EQUAL, SLJIT_IMM, 0, SLJIT_SCRATCH_REG2, 0);
3199 cmp_test(compiler, SLJIT_C_SIG_LESS, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 2 * sizeof(sljit_sw));
3200 cmp_test(compiler, SLJIT_C_SIG_LESS, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 3 * sizeof(sljit_sw));
3201 cmp_test(compiler, SLJIT_C_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 3 * sizeof(sljit_sw));
3202
3203 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 8);
3204 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
3205 cmp_test(compiler, SLJIT_C_LESS, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_sw));
3206 cmp_test(compiler, SLJIT_C_GREATER_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 8);
3207 cmp_test(compiler, SLJIT_C_LESS, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -10);
3208 cmp_test(compiler, SLJIT_C_LESS, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 8);
3209 cmp_test(compiler, SLJIT_C_GREATER_EQUAL, SLJIT_IMM, 8, SLJIT_SCRATCH_REG2, 0);
3210 cmp_test(compiler, SLJIT_C_GREATER_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 8, SLJIT_SCRATCH_REG2, 0);
3211 cmp_test(compiler, SLJIT_C_GREATER, SLJIT_IMM, 8, SLJIT_SCRATCH_REG2, 0);
3212 cmp_test(compiler, SLJIT_C_LESS_EQUAL, SLJIT_IMM, 7, SLJIT_SCRATCH_REG1, 0);
3213 cmp_test(compiler, SLJIT_C_GREATER, SLJIT_IMM, 1, SLJIT_MEM1(SLJIT_SAVED_REG2), 3 * sizeof(sljit_sw));
3214 cmp_test(compiler, SLJIT_C_LESS_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
3215 cmp_test(compiler, SLJIT_C_GREATER, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
3216 cmp_test(compiler, SLJIT_C_GREATER | SLJIT_REWRITABLE_JUMP, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
3217
3218 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -3);
3219 cmp_test(compiler, SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
3220 cmp_test(compiler, SLJIT_C_SIG_GREATER_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
3221 cmp_test(compiler, SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -1);
3222 cmp_test(compiler, SLJIT_C_SIG_GREATER_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
3223 cmp_test(compiler, SLJIT_C_SIG_LESS, SLJIT_MEM1(SLJIT_SAVED_REG2), 0, SLJIT_IMM, -1);
3224 cmp_test(compiler, SLJIT_C_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_MEM1(SLJIT_SAVED_REG2), 0, SLJIT_IMM, -1);
3225 cmp_test(compiler, SLJIT_C_SIG_LESS_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
3226 cmp_test(compiler, SLJIT_C_SIG_GREATER, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
3227 cmp_test(compiler, SLJIT_C_SIG_LESS_EQUAL, SLJIT_IMM, -4, SLJIT_SCRATCH_REG1, 0);
3228 cmp_test(compiler, SLJIT_C_SIG_GREATER, SLJIT_IMM, -1, SLJIT_SCRATCH_REG2, 0);
3229 cmp_test(compiler, SLJIT_C_SIG_GREATER | SLJIT_REWRITABLE_JUMP, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, -1);
3230
3231 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3232 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(0xf00000004));
3233 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0);
3234 cmp_test(compiler, SLJIT_C_LESS | SLJIT_INT_OP, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 5);
3235 cmp_test(compiler, SLJIT_C_LESS, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 5);
3236 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(0xff0000004));
3237 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0);
3238 cmp_test(compiler, SLJIT_C_SIG_GREATER | SLJIT_INT_OP, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 5);
3239 cmp_test(compiler, SLJIT_C_SIG_GREATER, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 5);
3240 #else
3241 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 4);
3242 cmp_test(compiler, SLJIT_C_LESS | SLJIT_INT_OP, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 5);
3243 cmp_test(compiler, SLJIT_C_GREATER | SLJIT_INT_OP, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 5);
3244 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xf0000004);
3245 cmp_test(compiler, SLJIT_C_SIG_GREATER | SLJIT_INT_OP, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 5);
3246 cmp_test(compiler, SLJIT_C_SIG_LESS | SLJIT_INT_OP, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 5);
3247 #endif
3248
3249 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3250
3251 code.code = sljit_generate_code(compiler);
3252 CHECK(compiler);
3253 sljit_free_compiler(compiler);
3254
3255 code.func2((sljit_sw)&buf, (sljit_sw)&data);
3256
3257 for (i = 0; i < TEST_CASES; ++i)
3258 if (SLJIT_UNLIKELY(buf[i] != compare_buf[i])) {
3259 printf("test36 case %d failed\n", i + 1);
3260 return;
3261 }
3262
3263 sljit_free_code(code.code);
3264 successful_tests++;
3265 }
3266 #undef TEST_CASES
3267
3268 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3269 #define BITN(n) (SLJIT_W(1) << (63 - (n)))
3270 #define RESN(n) (n)
3271 #else
3272 #define BITN(n) (1 << (31 - ((n) & 0x1f)))
3273 #define RESN(n) ((n) & 0x1f)
3274 #endif
3275
3276 static void test37(void)
3277 {
3278 /* Test count leading zeroes. */
3279 executable_code code;
3280 struct sljit_compiler* compiler = sljit_create_compiler();
3281 sljit_sw buf[15];
3282 sljit_si ibuf[2];
3283 sljit_si i;
3284
3285 if (verbose)
3286 printf("Run test37\n");
3287
3288 FAILED(!compiler, "cannot create compiler\n");
3289
3290 for (i = 0; i < 15; i++)
3291 buf[i] = -1;
3292 buf[3] = 0;
3293 buf[7] = BITN(13);
3294 ibuf[0] = -1;
3295 ibuf[1] = -1;
3296 sljit_emit_enter(compiler, 2, 1, 2, 0);
3297 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, BITN(27));
3298 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
3299 sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_SET_E, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, BITN(47));
3300 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3301 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_C_ZERO);
3302 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_sw));
3303 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -1);
3304 sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_SET_E, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
3305 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_C_ZERO);
3306 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3307 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
3308 sljit_emit_op1(compiler, SLJIT_ICLZ, SLJIT_MEM1(SLJIT_SAVED_REG2), 0, SLJIT_SCRATCH_REG1, 0);
3309 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -1);
3310 sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0);
3311 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_C_ZERO);
3312 sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_KEEP_FLAGS, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_sw));
3313 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3314 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
3315 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, BITN(58));
3316 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_SAVED_REG1), 9 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3317 sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 10 * sizeof(sljit_sw));
3318 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 10 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
3319 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0);
3320 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_SAVED_REG1), 11 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3321 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3322 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(0xff08a00000));
3323 #else
3324 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x08a00000);
3325 #endif
3326 sljit_emit_op1(compiler, SLJIT_ICLZ, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_si), SLJIT_SCRATCH_REG1, 0);
3327 sljit_emit_op1(compiler, SLJIT_ICLZ, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
3328 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 12 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3329 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3330 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(0xffc8a00000));
3331 #else
3332 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xc8a00000);
3333 #endif
3334 sljit_emit_op1(compiler, SLJIT_ICLZ | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0);
3335 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 13 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_C_ZERO);
3336 sljit_emit_op1(compiler, SLJIT_ICLZ | SLJIT_SET_E, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
3337 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 14 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3338
3339 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3340
3341 code.code = sljit_generate_code(compiler);
3342 CHECK(compiler);
3343 sljit_free_compiler(compiler);
3344
3345 code.func2((sljit_sw)&buf, (sljit_sw)&ibuf);
3346 FAILED(buf[0] != RESN(27), "test37 case 1 failed\n");
3347 FAILED(buf[1] != RESN(47), "test37 case 2 failed\n");
3348 FAILED(buf[2] != 0, "test37 case 3 failed\n");
3349 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3350 FAILED(buf[3] != 64, "test37 case 4 failed\n");
3351 #else
3352 FAILED(buf[3] != 32, "test37 case 4 failed\n");
3353 #endif
3354 FAILED(buf[4] != 1, "test37 case 5 failed\n");
3355 FAILED(buf[5] != 0, "test37 case 6 failed\n");
3356 FAILED(ibuf[0] != 32, "test37 case 7 failed\n");
3357 FAILED(buf[6] != 1, "test37 case 8 failed\n");
3358 FAILED(buf[7] != RESN(13), "test37 case 9 failed\n");
3359 #if !(defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3360 FAILED(buf[8] != 0, "test37 case 10 failed\n");
3361 #endif
3362 FAILED(buf[9] != RESN(58), "test37 case 11 failed\n");
3363 FAILED(buf[10] != 0, "test37 case 12 failed\n");
3364 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3365 FAILED(buf[11] != 64, "test37 case 13 failed\n");
3366 #else
3367 FAILED(buf[11] != 32, "test37 case 13 failed\n");
3368 #endif
3369 FAILED(ibuf[1] != 4, "test37 case 14 failed\n");
3370 FAILED((buf[12] & 0xffffffff) != 4, "test37 case 15 failed\n");
3371 FAILED(buf[13] != 1, "test37 case 16 failed\n");
3372 FAILED((buf[14] & 0xffffffff) != 0, "test37 case 17 failed\n");
3373
3374 sljit_free_code(code.code);
3375 successful_tests++;
3376 }
3377 #undef BITN
3378 #undef RESN
3379
3380 static void test38(void)
3381 {
3382 #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)
3383 /* Test stack utility. */
3384 executable_code code;
3385 struct sljit_compiler* compiler = sljit_create_compiler();
3386 struct sljit_jump* alloc_fail;
3387 struct sljit_jump* alloc2_fail;
3388 struct sljit_jump* alloc3_fail;
3389 struct sljit_jump* jump;
3390 struct sljit_label* label;
3391
3392 if (verbose)
3393 printf("Run test38\n");
3394
3395 FAILED(!compiler, "cannot create compiler\n");
3396
3397 sljit_emit_enter(compiler, 0, 2, 1, 0);
3398
3399 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 8192);
3400 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 65536);
3401 sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_allocate_stack));
3402 alloc_fail = sljit_emit_cmp(compiler, SLJIT_C_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3403 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_RETURN_REG, 0);
3404
3405 /* Write 8k data. */
3406 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(struct sljit_stack, base), SLJIT_IMM, sizeof(sljit_sw));
3407 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 8192);
3408 label = sljit_emit_label(compiler);
3409 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG1), sizeof(sljit_sw), SLJIT_IMM, -1);
3410 jump = sljit_emit_cmp(compiler, SLJIT_C_LESS, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
3411 sljit_set_label(jump, label);
3412
3413 /* Grow stack. */
3414 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG1, 0);
3415 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(struct sljit_stack, base), SLJIT_IMM, 65536);
3416 sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_stack_resize));
3417 alloc2_fail = sljit_emit_cmp(compiler, SLJIT_C_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3418
3419 /* Write 64k data. */
3420 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(struct sljit_stack, base), SLJIT_IMM, sizeof(sljit_sw));
3421 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 65536);
3422 label = sljit_emit_label(compiler);
3423 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG1), sizeof(sljit_sw), SLJIT_IMM, -1);
3424 jump = sljit_emit_cmp(compiler, SLJIT_C_LESS, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
3425 sljit_set_label(jump, label);
3426
3427 /* Shrink stack. */
3428 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG1, 0);
3429 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(struct sljit_stack, base), SLJIT_IMM, 32768);
3430 sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_stack_resize));
3431 alloc3_fail = sljit_emit_cmp(compiler, SLJIT_C_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3432
3433 /* Write 32k data. */
3434 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(struct sljit_stack, base), SLJIT_IMM, sizeof(sljit_sw));
3435 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(struct sljit_stack, limit), SLJIT_IMM, sizeof(sljit_sw));
3436 label = sljit_emit_label(compiler);
3437 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG1), sizeof(sljit_sw), SLJIT_IMM, -1);
3438 jump = sljit_emit_cmp(compiler, SLJIT_C_LESS, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
3439 sljit_set_label(jump, label);
3440
3441 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG1, 0);
3442 sljit_emit_ijump(compiler, SLJIT_CALL1, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_free_stack));
3443
3444 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
3445 label = sljit_emit_label(compiler);
3446 sljit_set_label(alloc_fail, label);
3447 sljit_set_label(alloc2_fail, label);
3448 sljit_set_label(alloc3_fail, label);
3449 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3450
3451 code.code = sljit_generate_code(compiler);
3452 CHECK(compiler);
3453 sljit_free_compiler(compiler);
3454
3455 /* Just survive this. */
3456 FAILED(code.func0() != 1, "test38 case 1 failed\n");
3457
3458 sljit_free_code(code.code);
3459 #endif
3460 successful_tests++;
3461 }
3462
3463 static void test39(void)
3464 {
3465 /* Test error handling. */
3466 executable_code code;
3467 struct sljit_compiler* compiler = sljit_create_compiler();
3468 struct sljit_jump* jump;
3469
3470 if (verbose)
3471 printf("Run test39\n");
3472
3473 FAILED(!compiler, "cannot create compiler\n");
3474
3475 /* Such assignment should never happen in a regular program. */
3476 compiler->error = -3967;
3477
3478 SLJIT_ASSERT(sljit_emit_enter(compiler, 2, 5, 5, 32) == -3967);
3479 SLJIT_ASSERT(sljit_emit_return(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0) == -3967);
3480 SLJIT_ASSERT(sljit_emit_op0(compiler, SLJIT_NOP) == -3967);
3481 SLJIT_ASSERT(sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM2(SLJIT_SCRATCH_REG1, SLJIT_SCRATCH_REG2), 1) == -3967);
3482 SLJIT_ASSERT(sljit_emit_op2(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), 64, SLJIT_MEM1(SLJIT_SAVED_REG1), -64) == -3967);
3483 SLJIT_ASSERT(sljit_emit_fop1(compiler, SLJIT_ABSD, SLJIT_FLOAT_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0) == -3967);
3484 SLJIT_ASSERT(sljit_emit_fop2(compiler, SLJIT_DIVD, SLJIT_FLOAT_REG3, 0, SLJIT_MEM2(SLJIT_SCRATCH_REG1, SLJIT_SAVED_REG1), 0, SLJIT_FLOAT_REG3, 0) == -3967);
3485 SLJIT_ASSERT(!sljit_emit_label(compiler));
3486 jump = sljit_emit_jump(compiler, SLJIT_CALL3);
3487 SLJIT_ASSERT(!jump);
3488 sljit_set_label(jump, (struct sljit_label*)0x123450);
3489 sljit_set_target(jump, 0x123450);
3490 jump = sljit_emit_cmp(compiler, SLJIT_C_SIG_LESS_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
3491 SLJIT_ASSERT(!jump);
3492 SLJIT_ASSERT(sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM1(SLJIT_SCRATCH_REG1), 8) == -3967);
3493 SLJIT_ASSERT(sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_UNUSED, 0, SLJIT_C_MUL_OVERFLOW) == -3967);
3494 SLJIT_ASSERT(!sljit_emit_const(compiler, SLJIT_SCRATCH_REG1, 0, 99));
3495
3496 SLJIT_ASSERT(!compiler->labels && !compiler->jumps && !compiler->consts);
3497 SLJIT_ASSERT(!compiler->last_label && !compiler->last_jump && !compiler->last_const);
3498 SLJIT_ASSERT(!compiler->buf->next && !compiler->buf->used_size);
3499 SLJIT_ASSERT(!compiler->abuf->next && !compiler->abuf->used_size);
3500
3501 code.code = sljit_generate_code(compiler);
3502 SLJIT_ASSERT(!code.code && sljit_get_compiler_error(compiler) == -3967);
3503 sljit_free_compiler(compiler);
3504 successful_tests++;
3505 }
3506
3507 static void test40(void)
3508 {
3509 /* Test emit_op_flags. */
3510 executable_code code;
3511 struct sljit_compiler* compiler = sljit_create_compiler();
3512 sljit_sw buf[10];
3513
3514 if (verbose)
3515 printf("Run test40\n");
3516
3517 FAILED(!compiler, "cannot create compiler\n");
3518 buf[0] = -100;
3519 buf[1] = -100;
3520 buf[2] = -100;
3521 buf[3] = -8;
3522 buf[4] = -100;
3523 buf[5] = -100;
3524 buf[6] = 0;
3525 buf[7] = 0;
3526 buf[8] = -100;
3527 buf[9] = -100;
3528
3529 sljit_emit_enter(compiler, 1, 3, 4, sizeof(sljit_sw));
3530
3531 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -5);
3532 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_IMM, -6, SLJIT_SCRATCH_REG1, 0);
3533 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0x123456);
3534 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_C_SIG_LESS);
3535 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG2, 0);
3536
3537 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -13);
3538 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_IMM, -13, SLJIT_SCRATCH_REG1, 0);
3539 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), 0, SLJIT_IMM, 0);
3540 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_KEEP_FLAGS, SLJIT_MEM1(SLJIT_LOCALS_REG), 0, SLJIT_MEM1(SLJIT_LOCALS_REG), 0, SLJIT_C_EQUAL);
3541 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3542 sljit_emit_op2(compiler, SLJIT_OR | SLJIT_KEEP_FLAGS, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_LOCALS_REG), 0);
3543 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
3544 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_C_EQUAL);
3545 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 2, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3546
3547 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -13);
3548 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 3);
3549 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_S, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
3550 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG2), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG2), SLJIT_WORD_SHIFT, SLJIT_C_SIG_LESS);
3551
3552 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -8);
3553 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 33);
3554 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG2, 0);
3555 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 0);
3556 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
3557 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_KEEP_FLAGS, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_C_EQUAL);
3558 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG1, 0, SLJIT_IMM, 0x88);
3559 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_KEEP_FLAGS, SLJIT_SAVED_EREG1, 0, SLJIT_SAVED_EREG1, 0, SLJIT_C_NOT_EQUAL);
3560 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 4, SLJIT_SAVED_REG2, 0);
3561 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 5, SLJIT_SAVED_EREG1, 0);
3562
3563 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x84);
3564 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_IMM, 0x180, SLJIT_SCRATCH_REG1, 0);
3565 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_E, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 6, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 6, SLJIT_C_EQUAL);
3566 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 7, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 7, SLJIT_C_EQUAL);
3567
3568 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
3569 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
3570 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_E, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_C_NOT_EQUAL);
3571 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 8, SLJIT_UNUSED, 0, SLJIT_C_NOT_EQUAL);
3572
3573 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x123456);
3574 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
3575 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_C_GREATER);
3576 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw) * 9, SLJIT_SCRATCH_REG1, 0);
3577
3578 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), 0, SLJIT_IMM, 0xbaddead);
3579 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), 0);
3580
3581 code.code = sljit_generate_code(compiler);
3582 CHECK(compiler);
3583 sljit_free_compiler(compiler);
3584
3585 FAILED(code.func1((sljit_sw)&buf) != 0xbaddead, "test40 case 1 failed\n");
3586 FAILED(buf[0] != 0x123457, "test40 case 2 failed\n");
3587 FAILED(buf[1] != 1, "test40 case 3 failed\n");
3588 FAILED(buf[2] != 0, "test40 case 4 failed\n");
3589 FAILED(buf[3] != -7, "test40 case 5 failed\n");
3590 FAILED(buf[4] != 0, "test40 case 6 failed\n");
3591 FAILED(buf[5] != 0x89, "test40 case 7 failed\n");
3592 FAILED(buf[6] != 0, "test40 case 8 failed\n");
3593 FAILED(buf[7] != 1, "test40 case 9 failed\n");
3594 FAILED(buf[8] != 1, "test40 case 10 failed\n");
3595 FAILED(buf[9] != 0x123457, "test40 case 11 failed\n");
3596
3597 sljit_free_code(code.code);
3598 successful_tests++;
3599 }
3600
3601 static void test41(void)
3602 {
3603 /* Test inline assembly. */
3604 executable_code code;
3605 struct sljit_compiler* compiler = sljit_create_compiler();
3606 sljit_si i;
3607 sljit_d buf[3];
3608 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3609 sljit_ub inst[16];
3610 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3611 sljit_ub inst[16];
3612 sljit_si reg;
3613 #else
3614 sljit_ui inst;
3615 #endif
3616
3617 if (verbose)
3618 printf("Run test41\n");
3619
3620 for (i = 1; i <= SLJIT_NO_REGISTERS; i++) {
3621 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3622 if (i == SLJIT_TEMPORARY_EREG1 || i == SLJIT_TEMPORARY_EREG2
3623 || i == SLJIT_SAVED_EREG1 || i == SLJIT_SAVED_EREG2) {
3624 SLJIT_ASSERT(sljit_get_register_index(i) == -1);
3625 continue;
3626 }
3627 #endif
3628 SLJIT_ASSERT(sljit_get_register_index(i) >= 0 && sljit_get_register_index(i) < 32);
3629 }
3630
3631 FAILED(!compiler, "cannot create compiler\n");
3632 sljit_emit_enter(compiler, 2, 3, 3, 0);
3633
3634 /* Returns with the sum of SLJIT_SAVED_REG1 and SLJIT_SAVED_REG2. */
3635 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3636 /* lea SLJIT_RETURN_REG, [SLJIT_SAVED_REG1, SLJIT_SAVED_REG2] */
3637 inst[0] = 0x48;
3638 inst[1] = 0x8d;
3639 inst[2] = 0x04 | ((sljit_get_register_index(SLJIT_RETURN_REG) & 0x7) << 3);
3640 inst[3] = (sljit_get_register_index(SLJIT_SAVED_REG1) & 0x7)
3641 | ((sljit_get_register_index(SLJIT_SAVED_REG2) & 0x7) << 3);
3642 sljit_emit_op_custom(compiler, inst, 4);
3643 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3644 /* lea SLJIT_RETURN_REG, [SLJIT_SAVED_REG1, SLJIT_SAVED_REG2] */
3645 inst[0] = 0x48; /* REX_W */
3646 inst[1] = 0x8d;
3647 inst[2] = 0x04;
3648 reg = sljit_get_register_index(SLJIT_RETURN_REG);
3649 inst[2] |= ((reg & 0x7) << 3);
3650 if (reg > 7)
3651 inst[0] |= 0x04; /* REX_R */
3652 reg = sljit_get_register_index(SLJIT_SAVED_REG1);
3653 inst[3] = reg & 0x7;
3654 if (reg > 7)
3655 inst[0] |= 0x01; /* REX_B */
3656 reg = sljit_get_register_index(SLJIT_SAVED_REG2);
3657 inst[3] |= (reg & 0x7) << 3;
3658 if (reg > 7)
3659 inst[0] |= 0x02; /* REX_X */
3660 sljit_emit_op_custom(compiler, inst, 4);
3661 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
3662 /* add rd, rn, rm */
3663 inst = 0xe0800000 | (sljit_get_register_index(SLJIT_RETURN_REG) << 12)
3664 | (sljit_get_register_index(SLJIT_SAVED_REG1) << 16)
3665 | sljit_get_register_index(SLJIT_SAVED_REG2);
3666 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_ui));
3667 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
3668 /* add rd, rn, rm */
3669 inst = 0xeb000000 | (sljit_get_register_index(SLJIT_RETURN_REG) << 8)
3670 | (sljit_get_register_index(SLJIT_SAVED_REG1) << 16)
3671 | sljit_get_register_index(SLJIT_SAVED_REG2);
3672 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_ui));
3673 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3674 /* add rd, rn, rm */
3675 inst = 0x8b000000 | sljit_get_register_index(SLJIT_RETURN_REG)
3676 | (sljit_get_register_index(SLJIT_SAVED_REG1) << 5)
3677 | (sljit_get_register_index(SLJIT_SAVED_REG2) << 16);
3678 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_ui));
3679 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
3680 /* add rD, rA, rB */
3681 inst = (31 << 26) | (266 << 1) | (sljit_get_register_index(SLJIT_RETURN_REG) << 21)
3682 | (sljit_get_register_index(SLJIT_SAVED_REG1) << 16)
3683 | (sljit_get_register_index(SLJIT_SAVED_REG2) << 11);
3684 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_ui));
3685 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
3686 /* addu rd, rs, rt */
3687 inst = 33 | (sljit_get_register_index(SLJIT_RETURN_REG) << 11)
3688 | (sljit_get_register_index(SLJIT_SAVED_REG1) << 21)
3689 | (sljit_get_register_index(SLJIT_SAVED_REG2) << 16);
3690 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_ui));
3691 #elif (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
3692 /* daddu rd, rs, rt */
3693 inst = 45 | (sljit_get_register_index(SLJIT_RETURN_REG) << 11)
3694 | (sljit_get_register_index(SLJIT_SAVED_REG1) << 21)
3695 | (sljit_get_register_index(SLJIT_SAVED_REG2) << 16);
3696 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_ui));
3697 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3698 /* add rd, rs1, rs2 */
3699 inst = (0x2 << 30) | (sljit_get_register_index(SLJIT_RETURN_REG) << 25)
3700 | (sljit_get_register_index(SLJIT_SAVED_REG1) << 14)
3701 | sljit_get_register_index(SLJIT_SAVED_REG2);
3702 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_ui));
3703 #else
3704 inst = 0;
3705 sljit_emit_op_custom(compiler, &inst, 0);
3706 #endif
3707
3708 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
3709
3710 code.code = sljit_generate_code(compiler);
3711 CHECK(compiler);
3712 sljit_free_compiler(compiler);
3713
3714 FAILED(code.func2(32, -11) != 21, "test41 case 1 failed\n");
3715 FAILED(code.func2(1000, 234) != 1234, "test41 case 2 failed\n");
3716 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3717 FAILED(code.func2(SLJIT_W(0x20f0a04090c06070), SLJIT_W(0x020f0a04090c0607)) != SLJIT_W(0x22ffaa4499cc6677), "test41 case 3 failed\n");
3718 #endif
3719
3720 sljit_free_code(code.code);
3721
3722 if (sljit_is_fpu_available()) {
3723 buf[0] = 13.5;
3724 buf[1] = -2.25;
3725 buf[2] = 0.0;
3726
3727 compiler = sljit_create_compiler();
3728 sljit_emit_enter(compiler, 1, 0, 1, 0);
3729 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
3730 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_d));
3731 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3732 /* addsd x, xm */
3733 inst[0] = 0xf2;
3734 inst[1] = 0x0f;
3735 inst[2] = 0x58;
3736 inst[3] = 0xc0 | (sljit_get_float_register_index(SLJIT_FLOAT_REG1) << 3)
3737 | sljit_get_float_register_index(SLJIT_FLOAT_REG2);
3738 sljit_emit_op_custom(compiler, inst, 4);
3739 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3740 /* addsd x, xm */
3741 if (sljit_get_float_register_index(SLJIT_FLOAT_REG1) > 7 || sljit_get_float_register_index(SLJIT_FLOAT_REG2) > 7) {
3742 inst[0] = 0;
3743 if (sljit_get_float_register_index(SLJIT_FLOAT_REG1) > 7)
3744 inst[0] |= 0x04; /* REX_R */
3745 if (sljit_get_float_register_index(SLJIT_FLOAT_REG2) > 7)
3746 inst[0] |= 0x01; /* REX_B */
3747 inst[1] = 0xf2;
3748 inst[2] = 0x0f;
3749 inst[3] = 0x58;
3750 inst[4] = 0xc0 | ((sljit_get_float_register_index(SLJIT_FLOAT_REG1) & 0x7) << 3)
3751 | (sljit_get_float_register_index(SLJIT_FLOAT_REG2) & 0x7);
3752 sljit_emit_op_custom(compiler, inst, 5);
3753 }
3754 else {
3755 inst[0] = 0xf2;
3756 inst[1] = 0x0f;
3757 inst[2] = 0x58;
3758 inst[3] = 0xc0 | (sljit_get_float_register_index(SLJIT_FLOAT_REG1) << 3)
3759 | sljit_get_float_register_index(SLJIT_FLOAT_REG2);
3760 sljit_emit_op_custom(compiler, inst, 4);
3761 }
3762 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
3763 /* vadd.f64 dd, dn, dm */
3764 inst = 0xee300b00 | (sljit_get_float_register_index(SLJIT_FLOAT_REG1) << 12)
3765 | (sljit_get_float_register_index(SLJIT_FLOAT_REG1) << 16)
3766 | sljit_get_float_register_index(SLJIT_FLOAT_REG2);
3767 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_ui));
3768 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3769 /* fadd rd, rn, rm */
3770 inst = 0x1e602800 | sljit_get_float_register_index(SLJIT_FLOAT_REG1)
3771 | (sljit_get_float_register_index(SLJIT_FLOAT_REG1) << 5)
3772 | (sljit_get_float_register_index(SLJIT_FLOAT_REG2) << 16);
3773 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_ui));
3774 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
3775 /* fadd frD, frA, frB */
3776 inst = (63 << 26) | (21 << 1) | (sljit_get_float_register_index(SLJIT_FLOAT_REG1) << 21)
3777 | (sljit_get_float_register_index(SLJIT_FLOAT_REG1) << 16)
3778 | (sljit_get_float_register_index(SLJIT_FLOAT_REG2) << 11);
3779 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_ui));
3780 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) || (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
3781 /* add.d fd, fs, ft */
3782 inst = (17 << 26) | (17 << 21) | (sljit_get_float_register_index(SLJIT_FLOAT_REG1) << 6)
3783 | (sljit_get_float_register_index(SLJIT_FLOAT_REG1) << 11)
3784 | (sljit_get_float_register_index(SLJIT_FLOAT_REG2) << 16);
3785 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_ui));
3786 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3787 /* faddd rd, rs1, rs2 */
3788 inst = (0x2 << 30) | (0x34 << 19) | (0x42 << 5)
3789 | (sljit_get_float_register_index(SLJIT_FLOAT_REG1) << 25)
3790 | (sljit_get_float_register_index(SLJIT_FLOAT_REG1) << 14)
3791 | sljit_get_float_register_index(SLJIT_FLOAT_REG2);
3792 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_ui));
3793 #endif
3794 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_d), SLJIT_FLOAT_REG1, 0);
3795 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3796
3797 code.code = sljit_generate_code(compiler);
3798 CHECK(compiler);
3799 sljit_free_compiler(compiler);
3800
3801 code.func1((sljit_sw)&buf);
3802 FAILED(buf[2] != 11.25, "test41 case 3 failed\n");
3803
3804 sljit_free_code(code.code);
3805 }
3806
3807 successful_tests++;
3808 }
3809
3810 static void test42(void)
3811 {
3812 /* Test long multiply and division. */
3813 executable_code code;
3814 struct sljit_compiler* compiler = sljit_create_compiler();
3815 sljit_si i;
3816 sljit_sw buf[7 + 8 + 4];
3817
3818 if (verbose)
3819 printf("Run test42\n");
3820
3821 FAILED(!compiler, "cannot create compiler\n");
3822 for (i = 0; i < 7 + 8; i++)
3823 buf[i] = -1;
3824
3825 sljit_emit_enter(compiler, 1, 5, 5, 0);
3826
3827 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, -0x1fb308a);
3828 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG1, 0, SLJIT_IMM, 0xf50c873);
3829 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG2, 0, SLJIT_IMM, 0x8a0475b);
3830 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 0x9dc849b);
3831 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_IMM, -0x7c69a35);
3832 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG1, 0, SLJIT_IMM, 0x5a4d0c4);
3833 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG2, 0, SLJIT_IMM, 0x9a3b06d);
3834
3835 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3836 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3837 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3838 sljit_emit_op0(compiler, SLJIT_UMUL);
3839 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3840 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0);
3841
3842 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3843 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3844 sljit_emit_op0(compiler, SLJIT_SMUL);
3845 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 9 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3846 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 10 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0);
3847
3848 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3849 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3850 sljit_emit_op0(compiler, SLJIT_UDIV);
3851 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 11 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3852 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 12 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0);
3853
3854 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3855 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3856 sljit_emit_op0(compiler, SLJIT_SDIV);
3857 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 13 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3858 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 14 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0);
3859
3860 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(0x5cf783d3cf0a74b0));
3861 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, SLJIT_W(0x3d5df42d03a28fc7));
3862 sljit_emit_op0(compiler, SLJIT_IUDIV);
3863 sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
3864 sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0);
3865 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 15 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3866 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 16 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0);
3867
3868 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, SLJIT_W(0x371df5197ba26a28));
3869 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, SLJIT_W(0x46c78a5cfd6a420c));
3870 sljit_emit_op0(compiler, SLJIT_ISDIV);
3871 sljit_emit_op1(compiler, SLJIT_MOV_SI, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0);
3872 sljit_emit_op1(compiler, SLJIT_MOV_SI, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0);
3873 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 17 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3874 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 18 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0);
3875
3876 #else
3877 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -0x58cd67f5);
3878 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0x3cb088df);
3879 sljit_emit_op0(compiler, SLJIT_UMUL);
3880 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3881 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0);
3882
3883 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -0x58cd67f5);
3884 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0x3cb088df);
3885 sljit_emit_op0(compiler, SLJIT_SMUL);
3886 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 9 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3887 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 10 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0);
3888
3889 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -0x58cd67f5);
3890 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0x3cb088df);
3891 sljit_emit_op0(compiler, SLJIT_UDIV);
3892 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 11 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3893 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 12 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0);
3894
3895 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, -0x58cd67f5);
3896 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0x3cb088df);
3897 sljit_emit_op0(compiler, SLJIT_SDIV);
3898 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 13 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3899 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 14 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0);
3900
3901 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xcf0a74b0);
3902 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0x03a28fc7);
3903 sljit_emit_op0(compiler, SLJIT_IUDIV);
3904 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 15 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3905 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 16 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0);
3906
3907 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x7ba26a28);
3908 sljit_emit_op1(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, (sljit_sw)0xfd6a420c);
3909 sljit_emit_op0(compiler, SLJIT_ISDIV);
3910 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 17 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
3911 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 18 * sizeof(sljit_sw), SLJIT_SCRATCH_REG2, 0);
3912 #endif
3913
3914 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG3, 0);
3915 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_TEMPORARY_EREG1, 0);
3916 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_sw), SLJIT_TEMPORARY_EREG2, 0);
3917 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_sw), SLJIT_SAVED_REG2, 0);
3918 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_sw), SLJIT_SAVED_REG3, 0);
3919 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_sw), SLJIT_SAVED_EREG1, 0);
3920 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_sw), SLJIT_SAVED_EREG2, 0);
3921
3922 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3923
3924 code.code = sljit_generate_code(compiler);
3925 CHECK(compiler);
3926 sljit_free_compiler(compiler);
3927
3928 code.func1((sljit_sw)&buf);
3929
3930 FAILED(buf[0] != -0x1fb308a, "test42 case 1 failed\n");
3931 FAILED(buf[1] != 0xf50c873, "test42 case 2 failed\n");
3932 FAILED(buf[2] != 0x8a0475b, "test42 case 3 failed\n");
3933 FAILED(buf[3] != 0x9dc849b, "test42 case 4 failed\n");
3934 FAILED(buf[4] != -0x7c69a35, "test42 case 5 failed\n");
3935 FAILED(buf[5] != 0x5a4d0c4, "test42 case 6 failed\n");
3936 FAILED(buf[6] != 0x9a3b06d, "test42 case 7 failed\n");
3937
3938 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3939 FAILED(buf[7] != SLJIT_W(-4388959407985636971), "test42 case 8 failed\n");
3940 FAILED(buf[8] != SLJIT_W(2901680654366567099), "test42 case 9 failed\n");
3941 FAILED(buf[9] != SLJIT_W(-4388959407985636971), "test42 case 10 failed\n");
3942 FAILED(buf[10] != SLJIT_W(-1677173957268872740), "test42 case 11 failed\n");
3943 FAILED(buf[11] != SLJIT_W(2), "test42 case 12 failed\n");
3944 FAILED(buf[12] != SLJIT_W(2532236178951865933), "test42 case 13 failed\n");
3945 FAILED(buf[13] != SLJIT_W(-1), "test42 case 14 failed\n");
3946 FAILED(buf[14] != SLJIT_W(-2177944059851366166), "test42 case 15 failed\n");
3947 #else
3948 FAILED(buf[7] != -1587000939, "test42 case 8 failed\n");
3949 FAILED(buf[8] != 665003983, "test42 case 9 failed\n");
3950 FAILED(buf[9] != -1587000939, "test42 case 10 failed\n");
3951 FAILED(buf[10] != -353198352, "test42 case 11 failed\n");
3952 FAILED(buf[11] != 2, "test42 case 12 failed\n");
3953 FAILED(buf[12] != 768706125, "test42 case 13 failed\n");
3954 FAILED(buf[13] != -1, "test42 case 14 failed\n");
3955 FAILED(buf[14] != -471654166, "test42 case 15 failed\n");
3956 #endif
3957
3958 FAILED(buf[15] != SLJIT_W(56), "test42 case 16 failed\n");
3959 FAILED(buf[16] != SLJIT_W(58392872), "test42 case 17 failed\n");
3960 FAILED(buf[17] != SLJIT_W(-47), "test42 case 18 failed\n");
3961 FAILED(buf[18] != SLJIT_W(35949148), "test42 case 19 failed\n");
3962
3963 sljit_free_code(code.code);
3964 successful_tests++;
3965 }
3966
3967 static void test43(void)
3968 {
3969 /* Test floating point compare. */
3970 executable_code code;
3971 struct sljit_compiler* compiler = sljit_create_compiler();
3972 struct sljit_jump* jump;
3973
3974 union {
3975 sljit_d value;
3976 struct {
3977 sljit_ui value1;
3978 sljit_ui value2;
3979 } u;
3980 } dbuf[4];
3981
3982 if (verbose)
3983 printf("Run test43\n");
3984
3985 if (!sljit_is_fpu_available()) {
3986 printf("no fpu available, test43 skipped\n");
3987 successful_tests++;
3988 if (compiler)
3989 sljit_free_compiler(compiler);
3990 return;
3991 }
3992
3993 FAILED(!compiler, "cannot create compiler\n");
3994
3995 dbuf[0].value = 12.125;
3996 /* a NaN */
3997 dbuf[1].u.value1 = 0x7fffffff;
3998 dbuf[1].u.value2 = 0x7fffffff;
3999 dbuf[2].value = -13.5;
4000 dbuf[3].value = 12.125;
4001
4002 sljit_emit_enter(compiler, 1, 1, 1, 0);
4003 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 2);
4004 /* dbuf[0] < dbuf[2] -> -2 */
4005 jump = sljit_emit_fcmp(compiler, SLJIT_C_FLOAT_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG1), SLJIT_DOUBLE_SHIFT);
4006 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, -2);
4007
4008 sljit_set_label(jump, sljit_emit_label(compiler));
4009 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
4010 /* dbuf[0] and dbuf[1] is not NaN -> 5 */
4011 jump = sljit_emit_fcmp(compiler, SLJIT_C_FLOAT_UNORDERED, SLJIT_MEM0(), (sljit_sw)&dbuf[1], SLJIT_FLOAT_REG2, 0);
4012 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 5);
4013
4014 sljit_set_label(jump, sljit_emit_label(compiler));
4015 sljit_emit_fop1(compiler, SLJIT_MOVD, SLJIT_FLOAT_REG3, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_d));
4016 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 11);
4017 /* dbuf[0] == dbuf[3] -> 11 */
4018 jump = sljit_emit_fcmp(compiler, SLJIT_C_FLOAT_EQUAL, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_FLOAT_REG3, 0);
4019
4020 /* else -> -17 */
4021 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, -17);
4022 sljit_set_label(jump, sljit_emit_label(compiler));
4023 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4024
4025 code.code = sljit_generate_code(compiler);
4026 CHECK(compiler);
4027 sljit_free_compiler(compiler);
4028
4029 FAILED(code.func1((sljit_sw)&dbuf) != 11, "test43 case 1 failed\n");
4030 dbuf[3].value = 12;
4031 FAILED(code.func1((sljit_sw)&dbuf) != -17, "test43 case 2 failed\n");
4032 dbuf[1].value = 0;
4033 FAILED(code.func1((sljit_sw)&dbuf) != 5, "test43 case 3 failed\n");
4034 dbuf[2].value = 20;
4035 FAILED(code.func1((sljit_sw)&dbuf) != -2, "test43 case 4 failed\n");
4036
4037 sljit_free_code(code.code);
4038 successful_tests++;
4039 }
4040
4041 static void test44(void)
4042 {
4043 /* Test mov. */
4044 executable_code code;
4045 struct sljit_compiler* compiler = sljit_create_compiler();
4046 void *buf[5];
4047
4048 if (verbose)
4049 printf("Run test44\n");
4050
4051 FAILED(!compiler, "cannot create compiler\n");
4052
4053 buf[0] = buf + 2;
4054 buf[1] = NULL;
4055 buf[2] = NULL;
4056 buf[3] = NULL;
4057 buf[4] = NULL;
4058 sljit_emit_enter(compiler, 1, 3, 2, 0);
4059
4060 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
4061 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_p), SLJIT_SCRATCH_REG1, 0);
4062 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, sizeof(sljit_p));
4063 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 2);
4064 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG2), SLJIT_POINTER_SHIFT, SLJIT_SCRATCH_REG1, 0);
4065 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, sizeof(sljit_p));
4066 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 3);
4067 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0);
4068 sljit_emit_op1(compiler, SLJIT_MOVU_P, SLJIT_MEM2(SLJIT_SCRATCH_REG3, SLJIT_SCRATCH_REG2), SLJIT_POINTER_SHIFT, SLJIT_SCRATCH_REG1, 0);
4069 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 2 * sizeof(sljit_p));
4070 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(sljit_p), SLJIT_SCRATCH_REG1, 0);
4071
4072 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0);
4073
4074 code.code = sljit_generate_code(compiler);
4075 CHECK(compiler);
4076 sljit_free_compiler(compiler);
4077
4078 FAILED(code.func1((sljit_sw)&buf) != (sljit_sw)(buf + 2), "test44 case 1 failed\n");
4079 FAILED(buf[1] != buf + 2, "test44 case 2 failed\n");
4080 FAILED(buf[2] != buf + 3, "test44 case 3 failed\n");
4081 FAILED(buf[3] != buf + 4, "test44 case 4 failed\n");
4082 FAILED(buf[4] != buf + 2, "test44 case 5 failed\n");
4083
4084 sljit_free_code(code.code);
4085 successful_tests++;
4086 }
4087
4088 static void test45(void)
4089 {
4090 /* Test single precision floating point. */
4091
4092 executable_code code;
4093 struct sljit_compiler* compiler = sljit_create_compiler();
4094 sljit_s buf[12];
4095 sljit_sw buf2[6];
4096 struct sljit_jump* jump;
4097
4098 if (verbose)
4099 printf("Run test45\n");
4100
4101 if (!sljit_is_fpu_available()) {
4102 printf("no fpu available, test45 skipped\n");
4103 successful_tests++;
4104 if (compiler)
4105 sljit_free_compiler(compiler);
4106 return;
4107 }
4108
4109 FAILED(!compiler, "cannot create compiler\n");
4110
4111 buf[0] = 5.5;
4112 buf[1] = -7.25;
4113 buf[2] = 0;
4114 buf[3] = 0;
4115 buf[4] = 0;
4116 buf[5] = 0;
4117 buf[6] = 0;
4118 buf[7] = 8.75;
4119 buf[8] = 0;
4120 buf[9] = 16.5;
4121 buf[10] = 0;
4122 buf[11] = 0;
4123
4124 buf2[0] = -1;
4125 buf2[1] = -1;
4126 buf2[2] = -1;
4127 buf2[3] = -1;
4128 buf2[4] = -1;
4129 buf2[5] = -1;
4130
4131 sljit_emit_enter(compiler, 2, 3, 2, 0);
4132
4133 sljit_emit_fop1(compiler, SLJIT_MOVS, SLJIT_FLOAT_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
4134 sljit_emit_fop1(compiler, SLJIT_MOVS, SLJIT_FLOAT_REG6, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_s));
4135 sljit_emit_fop1(compiler, SLJIT_NEGS, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_s), SLJIT_FLOAT_REG1, 0);
4136 sljit_emit_fop1(compiler, SLJIT_ABSS, SLJIT_FLOAT_REG2, 0, SLJIT_FLOAT_REG6, 0);
4137 sljit_emit_fop1(compiler, SLJIT_MOVS, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_s), SLJIT_FLOAT_REG2, 0);
4138 sljit_emit_fop1(compiler, SLJIT_ABSS, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_s), SLJIT_FLOAT_REG6, 0);
4139 sljit_emit_fop1(compiler, SLJIT_NEGS, SLJIT_FLOAT_REG5, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
4140 sljit_emit_fop1(compiler, SLJIT_MOVS, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_s), SLJIT_FLOAT_REG5, 0);
4141
4142 sljit_emit_fop2(compiler, SLJIT_ADDS, SLJIT_FLOAT_REG1, 0, SLJIT_FLOAT_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_s));
4143 sljit_emit_fop1(compiler, SLJIT_MOVS, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_s), SLJIT_FLOAT_REG1, 0);
4144 sljit_emit_fop2(compiler, SLJIT_SUBS, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_s), SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_s), SLJIT_FLOAT_REG6, 0);
4145 sljit_emit_fop1(compiler, SLJIT_MOVS, SLJIT_FLOAT_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
4146 sljit_emit_fop2(compiler, SLJIT_MULS, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_s), SLJIT_FLOAT_REG1, 0, SLJIT_FLOAT_REG1, 0);
4147 sljit_emit_fop2(compiler, SLJIT_DIVS, SLJIT_FLOAT_REG3, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 9 * sizeof(sljit_s), SLJIT_FLOAT_REG1, 0);
4148 sljit_emit_fop1(compiler, SLJIT_ABSS, SLJIT_MEM1(SLJIT_SAVED_REG1), 9 * sizeof(sljit_s), SLJIT_FLOAT_REG3, 0);
4149 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 0x3d0ac);
4150 sljit_emit_fop1(compiler, SLJIT_NEGS, SLJIT_MEM1(SLJIT_SAVED_REG1), 10 * sizeof(sljit_s), SLJIT_MEM1(SLJIT_SCRATCH_REG1), 0x3d0ac);
4151 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SCRATCH_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 0x3d0ac + sizeof(sljit_s));
4152 sljit_emit_fop1(compiler, SLJIT_ABSS, SLJIT_MEM1(SLJIT_SAVED_REG1), 11 * sizeof(sljit_s), SLJIT_MEM1(SLJIT_SCRATCH_REG1), -0x3d0ac);
4153
4154 sljit_emit_fop1(compiler, SLJIT_MOVS, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
4155 sljit_emit_fop1(compiler, SLJIT_MOVS, SLJIT_FLOAT_REG3, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_s));
4156 sljit_emit_fop1(compiler, SLJIT_CMPS | SLJIT_SET_E | SLJIT_SET_S, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
4157 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG2), 0, SLJIT_C_FLOAT_EQUAL);
4158 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_sw), SLJIT_C_FLOAT_LESS);
4159 sljit_emit_fop1(compiler, SLJIT_CMPS | SLJIT_SET_E, SLJIT_FLOAT_REG2, 0, SLJIT_FLOAT_REG3, 0);
4160 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG2), 2 * sizeof(sljit_sw), SLJIT_C_FLOAT_EQUAL);
4161 sljit_emit_fop1(compiler, SLJIT_CMPS | SLJIT_SET_S, SLJIT_FLOAT_REG2, 0, SLJIT_FLOAT_REG3, 0);
4162 cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG2), 3 * sizeof(sljit_sw), SLJIT_C_FLOAT_GREATER_EQUAL);
4163
4164 jump = sljit_emit_fcmp(compiler, SLJIT_C_FLOAT_LESS_EQUAL | SLJIT_SINGLE_OP, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_s));
4165 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 4 * sizeof(sljit_sw), SLJIT_IMM, 7);
4166 sljit_set_label(jump, sljit_emit_label(compiler));
4167
4168 jump = sljit_emit_fcmp(compiler, SLJIT_C_FLOAT_GREATER | SLJIT_SINGLE_OP, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_FLOAT_REG3, 0);
4169 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 5 * sizeof(sljit_sw), SLJIT_IMM, 6);
4170 sljit_set_label(jump, sljit_emit_label(compiler));
4171
4172 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0);
4173
4174 code.code = sljit_generate_code(compiler);
4175 CHECK(compiler);
4176 sljit_free_compiler(compiler);
4177
4178 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
4179 FAILED(buf[2] != -5.5, "test45 case 1 failed\n");
4180 FAILED(buf[3] != 7.25, "test45 case 2 failed\n");
4181 FAILED(buf[4] != 7.25, "test45 case 3 failed\n");
4182 FAILED(buf[5] != -5.5, "test45 case 4 failed\n");
4183 FAILED(buf[6] != -1.75, "test45 case 5 failed\n");
4184 FAILED(buf[7] != 16.0, "test45 case 6 failed\n");
4185 FAILED(buf[8] != 30.25, "test45 case 7 failed\n");
4186 FAILED(buf[9] != 3, "test45 case 8 failed\n");
4187 FAILED(buf[10] != -5.5, "test45 case 9 failed\n");
4188 FAILED(buf[11] != 7.25, "test45 case 10 failed\n");
4189 FAILED(buf2[0] != 1, "test45 case 11 failed\n");
4190 FAILED(buf2[1] != 2, "test45 case 12 failed\n");
4191 FAILED(buf2[2] != 2, "test45 case 13 failed\n");
4192 FAILED(buf2[3] != 1, "test45 case 14 failed\n");
4193 FAILED(buf2[4] != 7, "test45 case 15 failed\n");
4194 FAILED(buf2[5] != -1, "test45 case 16 failed\n");
4195
4196 sljit_free_code(code.code);
4197 successful_tests++;
4198 }
4199
4200 static void test46(void)
4201 {
4202 /* Test sljit_emit_op_flags with 32 bit operations. */
4203
4204 executable_code code;
4205 struct sljit_compiler* compiler = sljit_create_compiler();
4206 sljit_si buf[24];
4207 sljit_sw buf2[6];
4208 sljit_si i;
4209
4210 if (verbose)
4211 printf("Run test46\n");
4212
4213 for (i = 0; i < 24; ++i)
4214 buf[i] = -17;
4215 buf[16] = 0;
4216 for (i = 0; i < 6; ++i)
4217 buf2[i] = -13;
4218 buf2[4] = -124;
4219
4220 sljit_emit_enter(compiler, 2, 3, 3, 0);
4221
4222 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, -7);
4223 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 13);
4224 sljit_emit_op_flags(compiler, SLJIT_MOV_SI, SLJIT_MEM0(), (sljit_sw)&buf, SLJIT_UNUSED, 0, SLJIT_C_LESS);
4225 sljit_emit_op_flags(compiler, SLJIT_IAND, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_si), SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_si), SLJIT_C_GREATER);
4226
4227 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, -7);
4228 sljit_emit_op_flags(compiler, SLJIT_IAND | SLJIT_KEEP_FLAGS, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_si), SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_si), SLJIT_C_EQUAL);
4229 sljit_emit_op_flags(compiler, SLJIT_IAND | SLJIT_KEEP_FLAGS, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_si), SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_si), SLJIT_C_EQUAL);
4230 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x1235);
4231 sljit_emit_op_flags(compiler, SLJIT_IAND | SLJIT_SET_E, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_C_EQUAL);
4232 sljit_emit_op_flags(compiler, SLJIT_IAND, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_si), SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_si), SLJIT_C_EQUAL);
4233 sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_MEM1(SLJIT_SAVED_REG1), 10 * sizeof(sljit_si), SLJIT_SCRATCH_REG1, 0);
4234
4235 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, -7);
4236 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 12);
4237 sljit_emit_op_flags(compiler, SLJIT_MOV_UI, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG1), 2, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4238 sljit_emit_op_flags(compiler, SLJIT_IMOV, SLJIT_SCRATCH_REG1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4239 sljit_emit_op1(compiler, SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SAVED_REG1), 14 * sizeof(sljit_si), SLJIT_SCRATCH_REG1, 0);
4240 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 16);
4241 sljit_emit_op_flags(compiler, SLJIT_IAND | SLJIT_SET_E, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG1), 2, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_SCRATCH_REG1), 2, SLJIT_C_EQUAL);
4242 sljit_emit_op_flags(compiler, SLJIT_MOV_UI, SLJIT_MEM1(SLJIT_SAVED_REG1), 18 * sizeof(sljit_si), SLJIT_UNUSED, 0, SLJIT_C_NOT_EQUAL);
4243
4244 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, -7);
4245 sljit_emit_op_flags(compiler, SLJIT_IXOR | SLJIT_KEEP_FLAGS, SLJIT_MEM1(SLJIT_SAVED_REG1), 20 * sizeof(sljit_si), SLJIT_MEM1(SLJIT_SAVED_REG1), 20 * sizeof(sljit_si), SLJIT_C_EQUAL);
4246 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 39);
4247 sljit_emit_op_flags(compiler, SLJIT_IXOR, SLJIT_SCRATCH_REG1, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_C_EQUAL);
4248 sljit_emit_op1(compiler, SLJIT_MOV_SI | SLJIT_INT_OP, SLJIT_MEM1(SLJIT_SAVED_REG1), 22 * sizeof(sljit_si), SLJIT_SCRATCH_REG1, 0);
4249
4250 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, -7);
4251 sljit_emit_op_flags(compiler, SLJIT_AND, SLJIT_MEM0(), (sljit_sw)&buf2, SLJIT_MEM0(), (sljit_sw)&buf2, SLJIT_C_GREATER);
4252 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E | SLJIT_SET_S | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 5);
4253 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 1);
4254 sljit_emit_op_flags(compiler, SLJIT_AND | SLJIT_KEEP_FLAGS, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SCRATCH_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SCRATCH_REG1), SLJIT_WORD_SHIFT, SLJIT_C_SIG_LESS);
4255 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 2);
4256 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SCRATCH_REG1), SLJIT_WORD_SHIFT, SLJIT_UNUSED, 0, SLJIT_C_LESS);
4257 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_UNUSED, 0, SLJIT_C_NOT_EQUAL);
4258 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 3 * sizeof(sljit_sw), SLJIT_SAVED_REG3, 0);
4259 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_SAVED_REG2), 4 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SAVED_REG2), 4 * sizeof(sljit_sw), SLJIT_C_GREATER);
4260 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 0);
4261 sljit_emit_op_flags(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_SAVED_REG2), 5 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SAVED_REG2), 5 * sizeof(sljit_sw), SLJIT_C_GREATER);
4262
4263 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
4264
4265 code.code = sljit_generate_code(compiler);
4266 CHECK(compiler);
4267 sljit_free_compiler(compiler);
4268
4269 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
4270 FAILED(buf[0] != 0, "test46 case 1 failed\n");
4271 FAILED(buf[1] != -17, "test46 case 2 failed\n");
4272 FAILED(buf[2] != 1, "test46 case 3 failed\n");
4273 FAILED(buf[3] != -17, "test46 case 4 failed\n");
4274 FAILED(buf[4] != 1, "test46 case 5 failed\n");
4275 FAILED(buf[5] != -17, "test46 case 6 failed\n");
4276 FAILED(buf[6] != 1, "test46 case 7 failed\n");
4277 FAILED(buf[7] != -17, "test46 case 8 failed\n");
4278 FAILED(buf[8] != 0, "test46 case 9 failed\n");
4279 FAILED(buf[9] != -17, "test46 case 10 failed\n");
4280 FAILED(buf[10] != 1, "test46 case 11 failed\n");
4281 FAILED(buf[11] != -17, "test46 case 12 failed\n");
4282 FAILED(buf[12] != 1, "test46 case 13 failed\n");
4283 FAILED(buf[13] != -17, "test46 case 14 failed\n");
4284 FAILED(buf[14] != 1, "test46 case 15 failed\n");
4285 FAILED(buf[15] != -17, "test46 case 16 failed\n");
4286 FAILED(buf[16] != 0, "test46 case 17 failed\n");
4287 FAILED(buf[17] != -17, "test46 case 18 failed\n");
4288 FAILED(buf[18] != 0, "test46 case 19 failed\n");
4289 FAILED(buf[19] != -17, "test46 case 20 failed\n");
4290 FAILED(buf[20] != -18, "test46 case 21 failed\n");
4291 FAILED(buf[21] != -17, "test46 case 22 failed\n");
4292 FAILED(buf[22] != 38, "test46 case 23 failed\n");
4293 FAILED(buf[23] != -17, "test46 case 24 failed\n");
4294
4295 FAILED(buf2[0] != 0, "test46 case 25 failed\n");
4296 FAILED(buf2[1] != 1, "test46 case 26 failed\n");
4297 FAILED(buf2[2] != 0, "test46 case 27 failed\n");
4298 FAILED(buf2[3] != 1, "test46 case 28 failed\n");
4299 FAILED(buf2[4] != -123, "test46 case 29 failed\n");
4300 FAILED(buf2[5] != -14, "test46 case 30 failed\n");
4301
4302 sljit_free_code(code.code);
4303 successful_tests++;
4304 }
4305
4306 static void test47(void)
4307 {
4308 /* Test jump optimizations. */
4309 executable_code code;
4310 struct sljit_compiler* compiler = sljit_create_compiler();
4311 sljit_sw buf[3];
4312
4313 if (verbose)
4314 printf("Run test47\n");
4315
4316 FAILED(!compiler, "cannot create compiler\n");
4317 buf[0] = 0;
4318 buf[1] = 0;
4319 buf[2] = 0;
4320
4321 sljit_emit_enter(compiler, 1, 3, 1, 0);
4322 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x3a5c6f);
4323 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 3);
4324 sljit_set_target(sljit_emit_jump(compiler, SLJIT_C_LESS), 0x11223344);
4325 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
4326 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0xd37c10);
4327 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4328 sljit_set_target(sljit_emit_jump(compiler, SLJIT_C_LESS), SLJIT_W(0x112233445566));
4329 #endif
4330 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
4331 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0x59b48e);
4332 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4333 sljit_set_target(sljit_emit_jump(compiler, SLJIT_C_LESS), SLJIT_W(0x1122334455667788));
4334 #endif
4335 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
4336 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4337
4338 code.code = sljit_generate_code(compiler);
4339 CHECK(compiler);
4340 sljit_free_compiler(compiler);
4341
4342 code.func1((sljit_sw)&buf);
4343 FAILED(buf[0] != 0x3a5c6f, "test47 case 1 failed\n");
4344 FAILED(buf[1] != 0xd37c10, "test47 case 2 failed\n");
4345 FAILED(buf[2] != 0x59b48e, "test47 case 3 failed\n");
4346
4347 sljit_free_code(code.code);
4348 successful_tests++;
4349 }
4350
4351 void sljit_test(int argc, char* argv[]);
4352 void sljit_test(int argc, char* argv[])
4353 {
4354 sljit_si has_arg = (argc >= 2 && argv[1][0] == '-' && argv[1][2] == '\0');
4355 verbose = has_arg && argv[1][1] == 'v';
4356 silent = has_arg && argv[1][1] == 's';
4357
4358 if (!verbose && !silent)
4359 printf("Pass -v to enable verbose, -s to disable this hint.\n\n");
4360
4361 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
4362 test_exec_allocator();
4363 #endif
4364 test1();
4365 test2();
4366 test3();
4367 test4();
4368 test5();
4369 test6();
4370 test7();
4371 test8();
4372 test9();
4373 test10();
4374 test11();
4375 test12();
4376 test13();
4377 test14();
4378 test15();
4379 test16();
4380 test17();
4381 test18();
4382 test19();
4383 test20();
4384 test21();
4385 test22();
4386 test23();
4387 test24();
4388 test25();
4389 test26();
4390 test27();
4391 test28();
4392 test29();
4393 test30();
4394 test31();
4395 test32();
4396 test33();
4397 test34();
4398 test35();
4399 test36();
4400 test37();
4401 test38();
4402 test39();
4403 test40();
4404 test41();
4405 test42();
4406 test43();
4407 test44();
4408 test45();
4409 test46();
4410 test47();
4411
4412 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
4413 sljit_free_unused_memory_exec();
4414 #endif
4415
4416 printf("SLJIT tests: On " COLOR_ARCH "%s" COLOR_DEFAULT "%s: ", sljit_get_platform_name(), sljit_is_fpu_available() ? " (+fpu)" : "");
4417 if (successful_tests == 47)
4418 printf("All tests are " COLOR_GREEN "PASSED" COLOR_DEFAULT "!\n");
4419 else
4420 printf("Successful test ratio: " COLOR_RED "%d%%" COLOR_DEFAULT ".\n", successful_tests * 100 / 47);
4421 }
4422