sljitTest.c revision 1.1.1.5 1 /*
2 * Stack-less Just-In-Time compiler
3 *
4 * Copyright Zoltan Herczeg (hzmester (at) freemail.hu). All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification, are
7 * permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice, this list of
10 * conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 * of conditions and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 /* Must be the first one. Must not depend on any other include. */
28 #include "sljitLir.h"
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 #if defined _WIN32 || defined _WIN64
35 #define COLOR_RED
36 #define COLOR_GREEN
37 #define COLOR_ARCH
38 #define COLOR_DEFAULT
39 #else
40 #define COLOR_RED "\33[31m"
41 #define COLOR_GREEN "\33[32m"
42 #define COLOR_ARCH "\33[33m"
43 #define COLOR_DEFAULT "\33[0m"
44 #endif
45
46 union executable_code {
47 void* code;
48 sljit_sw (SLJIT_CALL *func0)(void);
49 sljit_sw (SLJIT_CALL *func1)(sljit_sw a);
50 sljit_sw (SLJIT_CALL *func2)(sljit_sw a, sljit_sw b);
51 sljit_sw (SLJIT_CALL *func3)(sljit_sw a, sljit_sw b, sljit_sw c);
52 };
53 typedef union executable_code executable_code;
54
55 static sljit_s32 successful_tests = 0;
56 static sljit_s32 verbose = 0;
57 static sljit_s32 silent = 0;
58
59 #define FAILED(cond, text) \
60 if (SLJIT_UNLIKELY(cond)) { \
61 printf(text); \
62 return; \
63 }
64
65 #define CHECK(compiler) \
66 if (sljit_get_compiler_error(compiler) != SLJIT_ERR_COMPILED) { \
67 printf("Compiler error: %d\n", sljit_get_compiler_error(compiler)); \
68 sljit_free_compiler(compiler); \
69 return; \
70 }
71
72 static void cond_set(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_s32 type)
73 {
74 /* Testing both sljit_emit_op_flags and sljit_emit_jump. */
75 struct sljit_jump* jump;
76 struct sljit_label* label;
77
78 sljit_emit_op_flags(compiler, SLJIT_MOV, dst, dstw, SLJIT_UNUSED, 0, type);
79 jump = sljit_emit_jump(compiler, type);
80 sljit_emit_op2(compiler, SLJIT_ADD, dst, dstw, dst, dstw, SLJIT_IMM, 2);
81 label = sljit_emit_label(compiler);
82 sljit_set_label(jump, label);
83 }
84
85 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
86
87 #define MALLOC_EXEC(result, size) \
88 result = SLJIT_MALLOC_EXEC(size); \
89 if (!result) { \
90 printf("Cannot allocate executable memory\n"); \
91 return; \
92 } \
93 memset(result, 255, size);
94
95 #define FREE_EXEC(ptr) \
96 SLJIT_FREE_EXEC(((sljit_u8*)(ptr)) + SLJIT_EXEC_OFFSET(ptr));
97
98 static void test_exec_allocator(void)
99 {
100 /* This is not an sljit test. */
101 void *ptr1;
102 void *ptr2;
103 void *ptr3;
104
105 if (verbose)
106 printf("Run executable allocator test\n");
107
108 MALLOC_EXEC(ptr1, 32);
109 MALLOC_EXEC(ptr2, 512);
110 MALLOC_EXEC(ptr3, 512);
111 FREE_EXEC(ptr2);
112 FREE_EXEC(ptr3);
113 FREE_EXEC(ptr1);
114 MALLOC_EXEC(ptr1, 262104);
115 MALLOC_EXEC(ptr2, 32000);
116 FREE_EXEC(ptr1);
117 MALLOC_EXEC(ptr1, 262104);
118 FREE_EXEC(ptr1);
119 FREE_EXEC(ptr2);
120 MALLOC_EXEC(ptr1, 512);
121 MALLOC_EXEC(ptr2, 512);
122 MALLOC_EXEC(ptr3, 512);
123 FREE_EXEC(ptr2);
124 MALLOC_EXEC(ptr2, 512);
125 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
126 sljit_free_unused_memory_exec();
127 #endif
128 FREE_EXEC(ptr3);
129 FREE_EXEC(ptr1);
130 FREE_EXEC(ptr2);
131 #if (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK)
132 /* Just call the global locks. */
133 sljit_grab_lock();
134 sljit_release_lock();
135 #endif
136
137 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
138 sljit_free_unused_memory_exec();
139 #endif
140 }
141
142 #undef MALLOC_EXEC
143
144 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
145
146 static void test1(void)
147 {
148 /* Enter and return from an sljit function. */
149 executable_code code;
150 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
151
152 if (verbose)
153 printf("Run test1\n");
154
155 FAILED(!compiler, "cannot create compiler\n");
156
157 /* 3 arguments passed, 3 arguments used. */
158 sljit_emit_enter(compiler, 0, 3, 3, 3, 0, 0, 0);
159 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_S1, 0);
160
161 SLJIT_ASSERT(sljit_get_generated_code_size(compiler) == 0);
162 code.code = sljit_generate_code(compiler);
163 CHECK(compiler);
164 SLJIT_ASSERT(compiler->error == SLJIT_ERR_COMPILED);
165 SLJIT_ASSERT(sljit_get_generated_code_size(compiler) > 0);
166 sljit_free_compiler(compiler);
167
168 FAILED(code.func3(3, -21, 86) != -21, "test1 case 1 failed\n");
169 FAILED(code.func3(4789, 47890, 997) != 47890, "test1 case 2 failed\n");
170
171 sljit_free_code(code.code);
172 successful_tests++;
173 }
174
175 static void test2(void)
176 {
177 /* Test mov. */
178 executable_code code;
179 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
180 sljit_sw buf[8];
181 static sljit_sw data[2] = { 0, -9876 };
182
183 if (verbose)
184 printf("Run test2\n");
185
186 FAILED(!compiler, "cannot create compiler\n");
187
188 buf[0] = 5678;
189 buf[1] = 0;
190 buf[2] = 0;
191 buf[3] = 0;
192 buf[4] = 0;
193 buf[5] = 0;
194 buf[6] = 0;
195 buf[7] = 0;
196 sljit_emit_enter(compiler, 0, 1, 3, 2, 0, 0, 0);
197 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_UNUSED, 0, SLJIT_MEM0(), (sljit_sw)&buf);
198 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 9999);
199 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_S0, 0);
200 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw), SLJIT_R0, 0);
201 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
202 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM2(SLJIT_S1, SLJIT_R1), 0);
203 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, 2);
204 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_S1, SLJIT_S0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S1, SLJIT_R1), 0);
205 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, 3);
206 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_S1, SLJIT_S0), SLJIT_WORD_SHIFT, SLJIT_MEM0(), (sljit_sw)&buf);
207 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
208 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&data);
209 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
210 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf - 0x12345678);
211 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), 0x12345678);
212 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_R0, 0);
213 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3456);
214 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf - 0xff890 + 6 * sizeof(sljit_sw));
215 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0xff890, SLJIT_R0, 0);
216 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf + 0xff890 + 7 * sizeof(sljit_sw));
217 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), -0xff890, SLJIT_R0, 0);
218 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R2, 0);
219
220 code.code = sljit_generate_code(compiler);
221 CHECK(compiler);
222 sljit_free_compiler(compiler);
223
224 FAILED(code.func1((sljit_sw)&buf) != 9999, "test2 case 1 failed\n");
225 FAILED(buf[1] != 9999, "test2 case 2 failed\n");
226 FAILED(buf[2] != 9999, "test2 case 3 failed\n");
227 FAILED(buf[3] != 5678, "test2 case 4 failed\n");
228 FAILED(buf[4] != -9876, "test2 case 5 failed\n");
229 FAILED(buf[5] != 5678, "test2 case 6 failed\n");
230 FAILED(buf[6] != 3456, "test2 case 6 failed\n");
231 FAILED(buf[7] != 3456, "test2 case 6 failed\n");
232
233 sljit_free_code(code.code);
234 successful_tests++;
235 }
236
237 static void test3(void)
238 {
239 /* Test not. */
240 executable_code code;
241 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
242 sljit_sw buf[5];
243
244 if (verbose)
245 printf("Run test3\n");
246
247 FAILED(!compiler, "cannot create compiler\n");
248 buf[0] = 1234;
249 buf[1] = 0;
250 buf[2] = 9876;
251 buf[3] = 0;
252 buf[4] = 0x12345678;
253
254 sljit_emit_enter(compiler, 0, 1, 3, 1, 0, 0, 0);
255 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_UNUSED, 0, SLJIT_MEM0(), (sljit_sw)&buf);
256 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 0);
257 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM0(), (sljit_sw)&buf[1], SLJIT_MEM0(), (sljit_sw)&buf[1]);
258 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_S0), 0);
259 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2);
260 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf[4] - 0xff0000 - 0x20);
261 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, (sljit_sw)&buf[4] - 0xff0000);
262 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM1(SLJIT_R1), 0xff0000 + 0x20, SLJIT_MEM1(SLJIT_R2), 0xff0000);
263 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
264
265 code.code = sljit_generate_code(compiler);
266 CHECK(compiler);
267 sljit_free_compiler(compiler);
268
269 FAILED(code.func1((sljit_sw)&buf) != ~1234, "test3 case 1 failed\n");
270 FAILED(buf[1] != ~1234, "test3 case 2 failed\n");
271 FAILED(buf[3] != ~9876, "test3 case 3 failed\n");
272 FAILED(buf[4] != ~0x12345678, "test3 case 4 failed\n");
273
274 sljit_free_code(code.code);
275 successful_tests++;
276 }
277
278 static void test4(void)
279 {
280 /* Test neg. */
281 executable_code code;
282 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
283 sljit_sw buf[4];
284
285 if (verbose)
286 printf("Run test4\n");
287
288 FAILED(!compiler, "cannot create compiler\n");
289 buf[0] = 0;
290 buf[1] = 1234;
291 buf[2] = 0;
292 buf[3] = 0;
293
294 sljit_emit_enter(compiler, 0, 2, 3, 2, 0, 0, 0);
295 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0);
296 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_S1, 0);
297 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM0(), (sljit_sw)&buf[0], SLJIT_MEM0(), (sljit_sw)&buf[1]);
298 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_RETURN_REG, 0, SLJIT_S1, 0);
299 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_IMM, 299);
300 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
301
302 code.code = sljit_generate_code(compiler);
303 CHECK(compiler);
304 sljit_free_compiler(compiler);
305
306 FAILED(code.func2((sljit_sw)&buf, 4567) != -4567, "test4 case 1 failed\n");
307 FAILED(buf[0] != -1234, "test4 case 2 failed\n");
308 FAILED(buf[2] != -4567, "test4 case 3 failed\n");
309 FAILED(buf[3] != -299, "test4 case 4 failed\n");
310
311 sljit_free_code(code.code);
312 successful_tests++;
313 }
314
315 static void test5(void)
316 {
317 /* Test add. */
318 executable_code code;
319 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
320 sljit_sw buf[9];
321
322 if (verbose)
323 printf("Run test5\n");
324
325 FAILED(!compiler, "cannot create compiler\n");
326 buf[0] = 100;
327 buf[1] = 200;
328 buf[2] = 300;
329 buf[3] = 0;
330 buf[4] = 0;
331 buf[5] = 0;
332 buf[6] = 0;
333 buf[7] = 0;
334 buf[8] = 313;
335
336 sljit_emit_enter(compiler, 0, 1, 3, 2, 0, 0, 0);
337 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_UNUSED, 0, SLJIT_IMM, 16, SLJIT_IMM, 16);
338 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_UNUSED, 0, SLJIT_IMM, 255, SLJIT_IMM, 255);
339 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_UNUSED, 0, SLJIT_S0, 0, SLJIT_S0, 0);
340 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
341 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 50);
342 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 1, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 1, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 0);
343 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw) + 2);
344 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 50);
345 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 0);
346 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
347 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_IMM, 4, SLJIT_R0, 0);
348 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_IMM, 50, SLJIT_R1, 0);
349 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_IMM, 50, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw));
350 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R1, 0);
351 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw));
352 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw));
353 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R1, 0);
354 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x1e7d39f2);
355 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_R1, 0, SLJIT_IMM, 0x23de7c06);
356 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, 0x3d72e452, SLJIT_R1, 0);
357 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_IMM, -43, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw));
358 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_IMM, 1000, SLJIT_R0, 0);
359 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1430);
360 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_IMM, -99, SLJIT_R0, 0);
361
362 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
363
364 code.code = sljit_generate_code(compiler);
365 CHECK(compiler);
366 sljit_free_compiler(compiler);
367
368 FAILED(code.func1((sljit_sw)&buf) != 2437 + 2 * sizeof(sljit_sw), "test5 case 1 failed\n");
369 FAILED(buf[0] != 202 + 2 * sizeof(sljit_sw), "test5 case 2 failed\n");
370 FAILED(buf[2] != 500, "test5 case 3 failed\n");
371 FAILED(buf[3] != 400, "test5 case 4 failed\n");
372 FAILED(buf[4] != 200, "test5 case 5 failed\n");
373 FAILED(buf[5] != 250, "test5 case 6 failed\n");
374 FAILED(buf[6] != 0x425bb5f8, "test5 case 7 failed\n");
375 FAILED(buf[7] != 0x5bf01e44, "test5 case 8 failed\n");
376 FAILED(buf[8] != 270, "test5 case 9 failed\n");
377
378 sljit_free_code(code.code);
379 successful_tests++;
380 }
381
382 static void test6(void)
383 {
384 /* Test addc, sub, subc. */
385 executable_code code;
386 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
387 sljit_sw buf[10];
388
389 if (verbose)
390 printf("Run test6\n");
391
392 FAILED(!compiler, "cannot create compiler\n");
393 buf[0] = 0;
394 buf[1] = 0;
395 buf[2] = 0;
396 buf[3] = 0;
397 buf[4] = 0;
398 buf[5] = 0;
399 buf[6] = 0;
400 buf[7] = 0;
401 buf[8] = 0;
402 buf[9] = 0;
403
404 sljit_emit_enter(compiler, 0, 1, 3, 1, 0, 0, 0);
405 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
406 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -1);
407 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0, SLJIT_IMM, 0);
408 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R0, 0);
409 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 4);
410 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 100);
411 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, SLJIT_IMM, 50);
412 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 6000);
413 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_IMM, 10);
414 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_IMM, 5);
415 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 100);
416 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2);
417 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R0, 0);
418 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5000);
419 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R0, 0);
420 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_R1, 0);
421 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_R1, 0);
422 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5000);
423 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_IMM, 6000, SLJIT_R0, 0);
424 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_R0, 0);
425 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 100);
426 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 32768);
427 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_R1, 0);
428 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -32767);
429 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_R1, 0);
430 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x52cd3bf4);
431 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_R0, 0, SLJIT_IMM, 0x3da297c6);
432 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 10);
433 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 5);
434 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 2);
435 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, -2220);
436 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
437
438 code.code = sljit_generate_code(compiler);
439 CHECK(compiler);
440 sljit_free_compiler(compiler);
441
442 FAILED(code.func1((sljit_sw)&buf) != 2223, "test6 case 1 failed\n");
443 FAILED(buf[0] != 1, "test6 case 2 failed\n");
444 FAILED(buf[1] != 5, "test6 case 3 failed\n");
445 FAILED(buf[2] != 50, "test6 case 4 failed\n");
446 FAILED(buf[3] != 4, "test6 case 5 failed\n");
447 FAILED(buf[4] != 50, "test6 case 6 failed\n");
448 FAILED(buf[5] != 50, "test6 case 7 failed\n");
449 FAILED(buf[6] != 1000, "test6 case 8 failed\n");
450 FAILED(buf[7] != 100 - 32768, "test6 case 9 failed\n");
451 FAILED(buf[8] != 100 + 32767, "test6 case 10 failed\n");
452 FAILED(buf[9] != 0x152aa42e, "test6 case 11 failed\n");
453
454 sljit_free_code(code.code);
455 successful_tests++;
456 }
457
458 static void test7(void)
459 {
460 /* Test logical operators. */
461 executable_code code;
462 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
463 sljit_sw buf[8];
464
465 if (verbose)
466 printf("Run test7\n");
467
468 FAILED(!compiler, "cannot create compiler\n");
469 buf[0] = 0xff80;
470 buf[1] = 0x0f808080;
471 buf[2] = 0;
472 buf[3] = 0xaaaaaa;
473 buf[4] = 0;
474 buf[5] = 0x4040;
475 buf[6] = 0;
476 buf[7] = 0xc43a7f95;
477
478 sljit_emit_enter(compiler, 0, 1, 3, 1, 0, 0, 0);
479 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xf0C000);
480 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, SLJIT_IMM, 0x308f);
481 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
482 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_IMM, 0xf0f0f0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3);
483 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xC0F0);
484 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5);
485 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xff0000);
486 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R0, 0);
487 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0xC0F0);
488 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5);
489 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_R2, 0, SLJIT_IMM, 0xff0000);
490 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 0xFFFFFF, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
491 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_IMM, 0xa56c82c0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6);
492 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7);
493 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_IMM, 0xff00ff00, SLJIT_R0, 0);
494 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xff00ff00);
495 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 0x0f);
496 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0x888888, SLJIT_R1, 0);
497 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
498
499 code.code = sljit_generate_code(compiler);
500 CHECK(compiler);
501 sljit_free_compiler(compiler);
502
503 FAILED(code.func1((sljit_sw)&buf) != 0x8808, "test7 case 1 failed\n");
504 FAILED(buf[0] != 0x0F807F00, "test7 case 2 failed\n");
505 FAILED(buf[1] != 0x0F7F7F7F, "test7 case 3 failed\n");
506 FAILED(buf[2] != 0x00F0F08F, "test7 case 4 failed\n");
507 FAILED(buf[3] != 0x00A0A0A0, "test7 case 5 failed\n");
508 FAILED(buf[4] != 0x00FF80B0, "test7 case 6 failed\n");
509 FAILED(buf[5] != 0x00FF4040, "test7 case 7 failed\n");
510 FAILED(buf[6] != 0xa56c82c0, "test7 case 8 failed\n");
511 FAILED(buf[7] != 0x3b3a8095, "test7 case 9 failed\n");
512
513 sljit_free_code(code.code);
514 successful_tests++;
515 }
516
517 static void test8(void)
518 {
519 /* Test flags (neg, cmp, test). */
520 executable_code code;
521 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
522 sljit_sw buf[13];
523
524 if (verbose)
525 printf("Run test8\n");
526
527 FAILED(!compiler, "cannot create compiler\n");
528 buf[0] = 100;
529 buf[1] = 3;
530 buf[2] = 3;
531 buf[3] = 3;
532 buf[4] = 3;
533 buf[5] = 3;
534 buf[6] = 3;
535 buf[7] = 3;
536 buf[8] = 3;
537 buf[9] = 3;
538 buf[10] = 3;
539 buf[11] = 3;
540 buf[12] = 3;
541
542 sljit_emit_enter(compiler, 0, 1, 3, 2, 0, 0, 0);
543 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 20);
544 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 10);
545 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_IMM, 6, SLJIT_IMM, 5);
546 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_NOT_EQUAL);
547 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_UNUSED, 0, SLJIT_EQUAL);
548 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 3000);
549 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_UNUSED, 0, SLJIT_GREATER);
550 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 3000);
551 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_S1, 0);
552 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_UNUSED, 0, SLJIT_LESS);
553 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R2, 0);
554 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, -15);
555 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_UNUSED, 0, SLJIT_SIG_GREATER);
556 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_R2, 0);
557 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
558 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
559 sljit_emit_op1(compiler, SLJIT_NEG | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_IMM, (sljit_sw)1 << ((sizeof(sljit_sw) << 3) - 1));
560 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_UNUSED, 0, SLJIT_OVERFLOW);
561 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
562 sljit_emit_op1(compiler, SLJIT_NOT | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R0, 0);
563 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_UNUSED, 0, SLJIT_ZERO);
564 sljit_emit_op1(compiler, SLJIT_NOT | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R1, 0);
565 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_UNUSED, 0, SLJIT_ZERO);
566 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_IMM, 0xffff, SLJIT_R0, 0);
567 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffff);
568 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_UNUSED, 0, SLJIT_NOT_ZERO);
569 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_IMM, 0xffff, SLJIT_R1, 0);
570 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_IMM, 0xffff);
571 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R1, 0);
572 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), 0);
573 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0);
574 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0x1);
575 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 10, SLJIT_UNUSED, 0, SLJIT_NOT_ZERO);
576 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(1) << ((sizeof(sljit_sw) << 3) - 1));
577 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
578 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_R0, 0);
579 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 11, SLJIT_UNUSED, 0, SLJIT_OVERFLOW);
580 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_R0, 0);
581 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 12, SLJIT_UNUSED, 0, SLJIT_OVERFLOW);
582 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
583
584 code.code = sljit_generate_code(compiler);
585 CHECK(compiler);
586 sljit_free_compiler(compiler);
587
588 code.func1((sljit_sw)&buf);
589 FAILED(buf[1] != 1, "test8 case 1 failed\n");
590 FAILED(buf[2] != 0, "test8 case 2 failed\n");
591 FAILED(buf[3] != 0, "test8 case 3 failed\n");
592 FAILED(buf[4] != 1, "test8 case 4 failed\n");
593 FAILED(buf[5] != 1, "test8 case 5 failed\n");
594 FAILED(buf[6] != 1, "test8 case 6 failed\n");
595 FAILED(buf[7] != 1, "test8 case 7 failed\n");
596 FAILED(buf[8] != 0, "test8 case 8 failed\n");
597 FAILED(buf[9] != 1, "test8 case 9 failed\n");
598 FAILED(buf[10] != 0, "test8 case 10 failed\n");
599 FAILED(buf[11] != 1, "test8 case 11 failed\n");
600 FAILED(buf[12] != 0, "test8 case 12 failed\n");
601
602 sljit_free_code(code.code);
603 successful_tests++;
604 }
605
606 static void test9(void)
607 {
608 /* Test shift. */
609 executable_code code;
610 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
611 sljit_sw buf[13];
612
613 if (verbose)
614 printf("Run test9\n");
615
616 FAILED(!compiler, "cannot create compiler\n");
617 buf[0] = 0;
618 buf[1] = 0;
619 buf[2] = 0;
620 buf[3] = 0;
621 buf[4] = 1 << 10;
622 buf[5] = 0;
623 buf[6] = 0;
624 buf[7] = 0;
625 buf[8] = 0;
626 buf[9] = 3;
627 buf[10] = 0;
628 buf[11] = 0;
629 buf[12] = 0;
630
631 sljit_emit_enter(compiler, 0, 1, 3, 2, 0, 0, 0);
632 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xf);
633 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 3);
634 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
635 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
636 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 2);
637 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
638 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R1, 0, SLJIT_IMM, 1);
639 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -64);
640 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 2);
641 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, SLJIT_PREF_SHIFT_REG, 0);
642
643 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 0xff);
644 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
645 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_PREF_SHIFT_REG, 0, SLJIT_PREF_SHIFT_REG, 0, SLJIT_R0, 0);
646 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_PREF_SHIFT_REG, 0);
647 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 0xff);
648 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
649 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R0, 0);
650 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_PREF_SHIFT_REG, 0, SLJIT_R0, 0);
651
652 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, 0xf);
653 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
654 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_R0, 0);
655 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_S1, 0);
656 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_R0, 0);
657 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_R0, 0);
658 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0xf00);
659 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
660 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R1, 0, SLJIT_R2, 0, SLJIT_R0, 0);
661 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_R1, 0);
662
663 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)buf);
664 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 9);
665 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), SLJIT_WORD_SHIFT);
666
667 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 4);
668 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 2, SLJIT_PREF_SHIFT_REG, 0);
669 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 10, SLJIT_PREF_SHIFT_REG, 0);
670
671 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xa9);
672 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 0);
673 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x7d00);
674 sljit_emit_op2(compiler, SLJIT_LSHR32, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 32);
675 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
676 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
677 #endif
678 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R0, 0);
679 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xe30000);
680 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
681 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffc0);
682 #else
683 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffe0);
684 #endif
685 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R0, 0);
686 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x25000000);
687 sljit_emit_op2(compiler, SLJIT_SHL32, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xfffe1);
688 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
689 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
690 #endif
691 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 11, SLJIT_R1, 0, SLJIT_R0, 0);
692
693 SLJIT_ASSERT(SLJIT_R2 == SLJIT_PREF_SHIFT_REG);
694 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 0);
695 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x5c);
696 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_PREF_SHIFT_REG, 0);
697 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0xf600);
698 sljit_emit_op2(compiler, SLJIT_LSHR32, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_PREF_SHIFT_REG, 0);
699 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
700 /* Alternative form of uint32 type cast. */
701 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffffffff);
702 #endif
703 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R0, 0);
704 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x630000);
705 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_PREF_SHIFT_REG, 0);
706 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 12, SLJIT_R1, 0, SLJIT_R0, 0);
707
708 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
709
710 code.code = sljit_generate_code(compiler);
711 CHECK(compiler);
712 sljit_free_compiler(compiler);
713
714 code.func1((sljit_sw)&buf);
715 FAILED(buf[0] != 0x3c, "test9 case 1 failed\n");
716 FAILED(buf[1] != 0xf0, "test9 case 2 failed\n");
717 FAILED(buf[2] != -16, "test9 case 3 failed\n");
718 FAILED(buf[3] != 0xff0, "test9 case 4 failed\n");
719 FAILED(buf[4] != 4, "test9 case 5 failed\n");
720 FAILED(buf[5] != 0xff00, "test9 case 6 failed\n");
721 FAILED(buf[6] != 0x3c, "test9 case 7 failed\n");
722 FAILED(buf[7] != 0xf0, "test9 case 8 failed\n");
723 FAILED(buf[8] != 0xf0, "test9 case 9 failed\n");
724 FAILED(buf[9] != 0x18, "test9 case 10 failed\n");
725 FAILED(buf[10] != 32, "test9 case 11 failed\n");
726 FAILED(buf[11] != 0x4ae37da9, "test9 case 12 failed\n");
727 FAILED(buf[12] != 0x63f65c, "test9 case 13 failed\n");
728
729 sljit_free_code(code.code);
730 successful_tests++;
731 }
732
733 static void test10(void)
734 {
735 /* Test multiplications. */
736 executable_code code;
737 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
738 sljit_sw buf[7];
739
740 if (verbose)
741 printf("Run test10\n");
742
743 FAILED(!compiler, "cannot create compiler\n");
744 buf[0] = 3;
745 buf[1] = 0;
746 buf[2] = 0;
747 buf[3] = 6;
748 buf[4] = -10;
749 buf[5] = 0;
750 buf[6] = 0;
751
752 sljit_emit_enter(compiler, 0, 1, 3, 1, 0, 0, 0);
753 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5);
754 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
755 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
756 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 7);
757 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_R2, 0, SLJIT_IMM, 8);
758 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
759 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_IMM, -3, SLJIT_IMM, -4);
760 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0);
761 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -2);
762 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_R0, 0);
763 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw) / 2);
764 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf[3]);
765 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 1, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 1, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 1);
766 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 9);
767 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R0, 0);
768 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_R0, 0);
769 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
770 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3);
771 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x123456789));
772 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_R0, 0);
773 #endif
774 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 11, SLJIT_IMM, 10);
775 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
776
777 code.code = sljit_generate_code(compiler);
778 CHECK(compiler);
779 sljit_free_compiler(compiler);
780
781 FAILED(code.func1((sljit_sw)&buf) != 110, "test10 case 1 failed\n");
782 FAILED(buf[0] != 15, "test10 case 2 failed\n");
783 FAILED(buf[1] != 56, "test10 case 3 failed\n");
784 FAILED(buf[2] != 12, "test10 case 4 failed\n");
785 FAILED(buf[3] != -12, "test10 case 5 failed\n");
786 FAILED(buf[4] != 100, "test10 case 6 failed\n");
787 FAILED(buf[5] != 81, "test10 case 7 failed\n");
788 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
789 FAILED(buf[6] != SLJIT_W(0x123456789) * 3, "test10 case 8 failed\n");
790 #endif
791
792 sljit_free_code(code.code);
793 successful_tests++;
794 }
795
796 static void test11(void)
797 {
798 /* Test rewritable constants. */
799 executable_code code;
800 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
801 struct sljit_const* const1;
802 struct sljit_const* const2;
803 struct sljit_const* const3;
804 struct sljit_const* const4;
805 void* value;
806 sljit_sw executable_offset;
807 sljit_uw const1_addr;
808 sljit_uw const2_addr;
809 sljit_uw const3_addr;
810 sljit_uw const4_addr;
811 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
812 sljit_sw word_value1 = SLJIT_W(0xaaaaaaaaaaaaaaaa);
813 sljit_sw word_value2 = SLJIT_W(0xfee1deadfbadf00d);
814 #else
815 sljit_sw word_value1 = 0xaaaaaaaal;
816 sljit_sw word_value2 = 0xfbadf00dl;
817 #endif
818 sljit_sw buf[3];
819
820 if (verbose)
821 printf("Run test11\n");
822
823 FAILED(!compiler, "cannot create compiler\n");
824 buf[0] = 0;
825 buf[1] = 0;
826 buf[2] = 0;
827
828 sljit_emit_enter(compiler, 0, 1, 3, 1, 0, 0, 0);
829
830 SLJIT_ASSERT(!sljit_alloc_memory(compiler, 0));
831 SLJIT_ASSERT(!sljit_alloc_memory(compiler, 16 * sizeof(sljit_sw) + 1));
832
833 const1 = sljit_emit_const(compiler, SLJIT_MEM0(), (sljit_sw)&buf[0], -0x81b9);
834
835 value = sljit_alloc_memory(compiler, 16 * sizeof(sljit_sw));
836 if (value != NULL)
837 {
838 SLJIT_ASSERT(!((sljit_sw)value & (sizeof(sljit_sw) - 1)));
839 memset(value, 255, 16 * sizeof(sljit_sw));
840 }
841
842 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
843 const2 = sljit_emit_const(compiler, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT - 1, -65535);
844 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[0] + 2 * sizeof(sljit_sw) - 2);
845 const3 = sljit_emit_const(compiler, SLJIT_MEM1(SLJIT_R0), 0, word_value1);
846
847 value = sljit_alloc_memory(compiler, 17);
848 if (value != NULL)
849 {
850 SLJIT_ASSERT(!((sljit_sw)value & (sizeof(sljit_sw) - 1)));
851 memset(value, 255, 16);
852 }
853
854 const4 = sljit_emit_const(compiler, SLJIT_RETURN_REG, 0, 0xf7afcdb7);
855
856 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
857
858 code.code = sljit_generate_code(compiler);
859 CHECK(compiler);
860 executable_offset = sljit_get_executable_offset(compiler);
861 const1_addr = sljit_get_const_addr(const1);
862 const2_addr = sljit_get_const_addr(const2);
863 const3_addr = sljit_get_const_addr(const3);
864 const4_addr = sljit_get_const_addr(const4);
865 sljit_free_compiler(compiler);
866
867 FAILED(code.func1((sljit_sw)&buf) != 0xf7afcdb7, "test11 case 1 failed\n");
868 FAILED(buf[0] != -0x81b9, "test11 case 2 failed\n");
869 FAILED(buf[1] != -65535, "test11 case 3 failed\n");
870 FAILED(buf[2] != word_value1, "test11 case 4 failed\n");
871
872 sljit_set_const(const1_addr, -1, executable_offset);
873 sljit_set_const(const2_addr, word_value2, executable_offset);
874 sljit_set_const(const3_addr, 0xbab0fea1, executable_offset);
875 sljit_set_const(const4_addr, -60089, executable_offset);
876
877 FAILED(code.func1((sljit_sw)&buf) != -60089, "test11 case 5 failed\n");
878 FAILED(buf[0] != -1, "test11 case 6 failed\n");
879 FAILED(buf[1] != word_value2, "test11 case 7 failed\n");
880 FAILED(buf[2] != 0xbab0fea1, "test11 case 8 failed\n");
881
882 sljit_free_code(code.code);
883 successful_tests++;
884 }
885
886 static void test12(void)
887 {
888 /* Test rewriteable jumps. */
889 executable_code code;
890 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
891 struct sljit_label *label1;
892 struct sljit_label *label2;
893 struct sljit_label *label3;
894 struct sljit_jump *jump1;
895 struct sljit_jump *jump2;
896 struct sljit_jump *jump3;
897 sljit_sw executable_offset;
898 void* value;
899 sljit_uw jump1_addr;
900 sljit_uw label1_addr;
901 sljit_uw label2_addr;
902 sljit_sw buf[1];
903
904 if (verbose)
905 printf("Run test12\n");
906
907 FAILED(!compiler, "cannot create compiler\n");
908 buf[0] = 0;
909
910 sljit_emit_enter(compiler, 0, 2, 3, 2, 0, 0, 0);
911 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_UNUSED, 0, SLJIT_S1, 0, SLJIT_IMM, 10);
912 jump1 = sljit_emit_jump(compiler, SLJIT_REWRITABLE_JUMP | SLJIT_SIG_GREATER);
913 /* Default handler. */
914 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 5);
915 jump2 = sljit_emit_jump(compiler, SLJIT_JUMP);
916
917 value = sljit_alloc_memory(compiler, 15);
918 if (value != NULL)
919 {
920 SLJIT_ASSERT(!((sljit_sw)value & (sizeof(sljit_sw) - 1)));
921 memset(value, 255, 15);
922 }
923
924 /* Handler 1. */
925 label1 = sljit_emit_label(compiler);
926 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 6);
927 jump3 = sljit_emit_jump(compiler, SLJIT_JUMP);
928 /* Handler 2. */
929 label2 = sljit_emit_label(compiler);
930 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 7);
931 /* Exit. */
932 label3 = sljit_emit_label(compiler);
933 sljit_set_label(jump2, label3);
934 sljit_set_label(jump3, label3);
935 /* By default, set to handler 1. */
936 sljit_set_label(jump1, label1);
937 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
938
939 value = sljit_alloc_memory(compiler, 8);
940 if (value != NULL)
941 {
942 SLJIT_ASSERT(!((sljit_sw)value & (sizeof(sljit_sw) - 1)));
943 memset(value, 255, 8);
944 }
945
946 code.code = sljit_generate_code(compiler);
947 CHECK(compiler);
948 executable_offset = sljit_get_executable_offset(compiler);
949 jump1_addr = sljit_get_jump_addr(jump1);
950 label1_addr = sljit_get_label_addr(label1);
951 label2_addr = sljit_get_label_addr(label2);
952 sljit_free_compiler(compiler);
953
954 code.func2((sljit_sw)&buf, 4);
955 FAILED(buf[0] != 5, "test12 case 1 failed\n");
956
957 code.func2((sljit_sw)&buf, 11);
958 FAILED(buf[0] != 6, "test12 case 2 failed\n");
959
960 sljit_set_jump_addr(jump1_addr, label2_addr, executable_offset);
961 code.func2((sljit_sw)&buf, 12);
962 FAILED(buf[0] != 7, "test12 case 3 failed\n");
963
964 sljit_set_jump_addr(jump1_addr, label1_addr, executable_offset);
965 code.func2((sljit_sw)&buf, 13);
966 FAILED(buf[0] != 6, "test12 case 4 failed\n");
967
968 sljit_free_code(code.code);
969 successful_tests++;
970 }
971
972 static void test13(void)
973 {
974 /* Test fpu monadic functions. */
975 executable_code code;
976 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
977 sljit_f64 buf[7];
978 sljit_sw buf2[6];
979
980 if (verbose)
981 printf("Run test13\n");
982
983 if (!sljit_is_fpu_available()) {
984 if (verbose)
985 printf("no fpu available, test13 skipped\n");
986 successful_tests++;
987 if (compiler)
988 sljit_free_compiler(compiler);
989 return;
990 }
991
992 FAILED(!compiler, "cannot create compiler\n");
993 buf[0] = 7.75;
994 buf[1] = -4.5;
995 buf[2] = 0.0;
996 buf[3] = 0.0;
997 buf[4] = 0.0;
998 buf[5] = 0.0;
999 buf[6] = 0.0;
1000
1001 buf2[0] = 10;
1002 buf2[1] = 10;
1003 buf2[2] = 10;
1004 buf2[3] = 10;
1005 buf2[4] = 10;
1006 buf2[5] = 10;
1007
1008 sljit_emit_enter(compiler, 0, 2, 3, 2, 6, 0, 0);
1009 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM0(), (sljit_sw)&buf[2], SLJIT_MEM0(), (sljit_sw)&buf[1]);
1010 sljit_emit_fop1(compiler, SLJIT_ABS_F64, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1011 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM0(), (sljit_sw)&buf[0]);
1012 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2 * sizeof(sljit_f64));
1013 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 0);
1014 sljit_emit_fop1(compiler, SLJIT_NEG_F64, SLJIT_FR2, 0, SLJIT_FR0, 0);
1015 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR3, 0, SLJIT_FR2, 0);
1016 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM0(), (sljit_sw)&buf[4], SLJIT_FR3, 0);
1017 sljit_emit_fop1(compiler, SLJIT_ABS_F64, SLJIT_FR4, 0, SLJIT_FR1, 0);
1018 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f64), SLJIT_FR4, 0);
1019 sljit_emit_fop1(compiler, SLJIT_NEG_F64, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64), SLJIT_FR4, 0);
1020
1021 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), 0);
1022 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_F, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1023 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_UNUSED, 0, SLJIT_GREATER_F64);
1024 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_F, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64), SLJIT_FR5, 0);
1025 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_GREATER_F64);
1026 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_FR5, 0);
1027 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR1, 0);
1028 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_EQUAL_F64);
1029 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_FR1, 0);
1030 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_LESS_F64);
1031 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1032 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_EQUAL_F64);
1033 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_NOT_EQUAL_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1034 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_NOT_EQUAL_F64);
1035
1036 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1037
1038 code.code = sljit_generate_code(compiler);
1039 CHECK(compiler);
1040 sljit_free_compiler(compiler);
1041
1042 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
1043 FAILED(buf[2] != -4.5, "test13 case 1 failed\n");
1044 FAILED(buf[3] != 4.5, "test13 case 2 failed\n");
1045 FAILED(buf[4] != -7.75, "test13 case 3 failed\n");
1046 FAILED(buf[5] != 4.5, "test13 case 4 failed\n");
1047 FAILED(buf[6] != -4.5, "test13 case 5 failed\n");
1048
1049 FAILED(buf2[0] != 1, "test13 case 6 failed\n");
1050 FAILED(buf2[1] != 0, "test13 case 7 failed\n");
1051 FAILED(buf2[2] != 1, "test13 case 8 failed\n");
1052 FAILED(buf2[3] != 0, "test13 case 9 failed\n");
1053 FAILED(buf2[4] != 0, "test13 case 10 failed\n");
1054 FAILED(buf2[5] != 1, "test13 case 11 failed\n");
1055
1056 sljit_free_code(code.code);
1057 successful_tests++;
1058 }
1059
1060 static void test14(void)
1061 {
1062 /* Test fpu diadic functions. */
1063 executable_code code;
1064 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1065 sljit_f64 buf[15];
1066
1067 if (verbose)
1068 printf("Run test14\n");
1069
1070 if (!sljit_is_fpu_available()) {
1071 if (verbose)
1072 printf("no fpu available, test14 skipped\n");
1073 successful_tests++;
1074 if (compiler)
1075 sljit_free_compiler(compiler);
1076 return;
1077 }
1078 buf[0] = 7.25;
1079 buf[1] = 3.5;
1080 buf[2] = 1.75;
1081 buf[3] = 0.0;
1082 buf[4] = 0.0;
1083 buf[5] = 0.0;
1084 buf[6] = 0.0;
1085 buf[7] = 0.0;
1086 buf[8] = 0.0;
1087 buf[9] = 0.0;
1088 buf[10] = 0.0;
1089 buf[11] = 0.0;
1090 buf[12] = 8.0;
1091 buf[13] = 4.0;
1092 buf[14] = 0.0;
1093
1094 FAILED(!compiler, "cannot create compiler\n");
1095 sljit_emit_enter(compiler, 0, 1, 3, 1, 6, 0, 0);
1096
1097 /* ADD */
1098 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_f64));
1099 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1100 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2);
1101 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 3, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 0, SLJIT_MEM1(SLJIT_S0), 0);
1102 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_FR1, 0);
1103 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR1, 0, SLJIT_FR0, 0, SLJIT_FR1, 0);
1104 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 4, SLJIT_FR0, 0);
1105 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 5, SLJIT_FR1, 0);
1106
1107 /* SUB */
1108 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 0);
1109 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR3, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2);
1110 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 2);
1111 sljit_emit_fop2(compiler, SLJIT_SUB_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 6, SLJIT_FR3, 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R1), SLJIT_F64_SHIFT);
1112 sljit_emit_fop2(compiler, SLJIT_SUB_F64, SLJIT_FR2, 0, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2);
1113 sljit_emit_fop2(compiler, SLJIT_SUB_F64, SLJIT_FR3, 0, SLJIT_FR2, 0, SLJIT_FR3, 0);
1114 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 7, SLJIT_FR2, 0);
1115 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 8, SLJIT_FR3, 0);
1116
1117 /* MUL */
1118 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
1119 sljit_emit_fop2(compiler, SLJIT_MUL_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 9, SLJIT_MEM2(SLJIT_S0, SLJIT_R1), SLJIT_F64_SHIFT, SLJIT_FR1, 0);
1120 sljit_emit_fop2(compiler, SLJIT_MUL_F64, SLJIT_FR1, 0, SLJIT_FR1, 0, SLJIT_FR2, 0);
1121 sljit_emit_fop2(compiler, SLJIT_MUL_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2, SLJIT_FR2, 0);
1122 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 10, SLJIT_FR1, 0);
1123 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 11, SLJIT_FR5, 0);
1124
1125 /* DIV */
1126 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 12);
1127 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 13);
1128 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR4, 0, SLJIT_FR5, 0);
1129 sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 12, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 12, SLJIT_FR1, 0);
1130 sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_FR5, 0, SLJIT_FR5, 0, SLJIT_FR1, 0);
1131 sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_FR4, 0, SLJIT_FR1, 0, SLJIT_FR4, 0);
1132 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 13, SLJIT_FR5, 0);
1133 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 14, SLJIT_FR4, 0);
1134
1135 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1136
1137 code.code = sljit_generate_code(compiler);
1138 CHECK(compiler);
1139 sljit_free_compiler(compiler);
1140
1141 code.func1((sljit_sw)&buf);
1142 FAILED(buf[3] != 10.75, "test14 case 1 failed\n");
1143 FAILED(buf[4] != 5.25, "test14 case 2 failed\n");
1144 FAILED(buf[5] != 7.0, "test14 case 3 failed\n");
1145 FAILED(buf[6] != 0.0, "test14 case 4 failed\n");
1146 FAILED(buf[7] != 5.5, "test14 case 5 failed\n");
1147 FAILED(buf[8] != 3.75, "test14 case 6 failed\n");
1148 FAILED(buf[9] != 24.5, "test14 case 7 failed\n");
1149 FAILED(buf[10] != 38.5, "test14 case 8 failed\n");
1150 FAILED(buf[11] != 9.625, "test14 case 9 failed\n");
1151 FAILED(buf[12] != 2.0, "test14 case 10 failed\n");
1152 FAILED(buf[13] != 2.0, "test14 case 11 failed\n");
1153 FAILED(buf[14] != 0.5, "test14 case 12 failed\n");
1154
1155 sljit_free_code(code.code);
1156 successful_tests++;
1157 }
1158
1159 static sljit_sw SLJIT_CALL func(sljit_sw a, sljit_sw b, sljit_sw c)
1160 {
1161 return a + b + c + 5;
1162 }
1163
1164 static void test15(void)
1165 {
1166 /* Test function call. */
1167 executable_code code;
1168 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1169 struct sljit_jump* jump = NULL;
1170 sljit_sw buf[7];
1171
1172 if (verbose)
1173 printf("Run test15\n");
1174
1175 FAILED(!compiler, "cannot create compiler\n");
1176 buf[0] = 0;
1177 buf[1] = 0;
1178 buf[2] = 0;
1179 buf[3] = 0;
1180 buf[4] = 0;
1181 buf[5] = 0;
1182 buf[6] = SLJIT_FUNC_OFFSET(func);
1183
1184 sljit_emit_enter(compiler, 0, 1, 4, 1, 0, 0, 0);
1185
1186 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5);
1187 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 7);
1188 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -3);
1189 sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1190 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_RETURN_REG, 0);
1191
1192 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -5);
1193 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -10);
1194 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2);
1195 jump = sljit_emit_jump(compiler, SLJIT_CALL3 | SLJIT_REWRITABLE_JUMP);
1196 sljit_set_target(jump, (sljit_sw)-1);
1197 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1198
1199 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1200 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 40);
1201 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -3);
1202 sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_R0, 0);
1203 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1204
1205 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -60);
1206 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1207 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -30);
1208 sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_R1, 0);
1209 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1210
1211 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 10);
1212 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 16);
1213 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1214 sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_R2, 0);
1215 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1216
1217 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 100);
1218 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 110);
1219 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 120);
1220 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1221 sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_R3, 0);
1222 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1223
1224 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -10);
1225 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -16);
1226 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 6);
1227 sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw));
1228 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1229
1230 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1231
1232 code.code = sljit_generate_code(compiler);
1233 CHECK(compiler);
1234 sljit_set_jump_addr(sljit_get_jump_addr(jump), SLJIT_FUNC_OFFSET(func), sljit_get_executable_offset(compiler));
1235 sljit_free_compiler(compiler);
1236
1237 FAILED(code.func1((sljit_sw)&buf) != -15, "test15 case 1 failed\n");
1238 FAILED(buf[0] != 14, "test15 case 2 failed\n");
1239 FAILED(buf[1] != -8, "test15 case 3 failed\n");
1240 FAILED(buf[2] != SLJIT_FUNC_OFFSET(func) + 42, "test15 case 4 failed\n");
1241 FAILED(buf[3] != SLJIT_FUNC_OFFSET(func) - 85, "test15 case 5 failed\n");
1242 FAILED(buf[4] != SLJIT_FUNC_OFFSET(func) + 31, "test15 case 6 failed\n");
1243 FAILED(buf[5] != 335, "test15 case 7 failed\n");
1244 FAILED(buf[6] != -15, "test15 case 8 failed\n");
1245
1246 sljit_free_code(code.code);
1247 successful_tests++;
1248 }
1249
1250 static void test16(void)
1251 {
1252 /* Ackermann benchmark. */
1253 executable_code code;
1254 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1255 struct sljit_label *entry;
1256 struct sljit_label *label;
1257 struct sljit_jump *jump;
1258 struct sljit_jump *jump1;
1259 struct sljit_jump *jump2;
1260
1261 if (verbose)
1262 printf("Run test16\n");
1263
1264 FAILED(!compiler, "cannot create compiler\n");
1265
1266 entry = sljit_emit_label(compiler);
1267 sljit_emit_enter(compiler, 0, 2, 3, 2, 0, 0, 0);
1268 /* If x == 0. */
1269 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_S0, 0, SLJIT_IMM, 0);
1270 jump1 = sljit_emit_jump(compiler, SLJIT_EQUAL);
1271 /* If y == 0. */
1272 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_S1, 0, SLJIT_IMM, 0);
1273 jump2 = sljit_emit_jump(compiler, SLJIT_EQUAL);
1274
1275 /* Ack(x,y-1). */
1276 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
1277 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_S1, 0, SLJIT_IMM, 1);
1278 jump = sljit_emit_jump(compiler, SLJIT_CALL2);
1279 sljit_set_label(jump, entry);
1280
1281 /* Returns with Ack(x-1, Ack(x,y-1)). */
1282 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_RETURN_REG, 0);
1283 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
1284 jump = sljit_emit_jump(compiler, SLJIT_CALL2);
1285 sljit_set_label(jump, entry);
1286 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1287
1288 /* Returns with y+1. */
1289 label = sljit_emit_label(compiler);
1290 sljit_set_label(jump1, label);
1291 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1, SLJIT_S1, 0);
1292 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1293
1294 /* Returns with Ack(x-1,1) */
1295 label = sljit_emit_label(compiler);
1296 sljit_set_label(jump2, label);
1297 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
1298 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
1299 jump = sljit_emit_jump(compiler, SLJIT_CALL2);
1300 sljit_set_label(jump, entry);
1301 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1302
1303 code.code = sljit_generate_code(compiler);
1304 CHECK(compiler);
1305 sljit_free_compiler(compiler);
1306
1307 FAILED(code.func2(3, 3) != 61, "test16 case 1 failed\n");
1308 /* For benchmarking. */
1309 /* FAILED(code.func2(3, 11) != 16381, "test16 case 1 failed\n"); */
1310
1311 sljit_free_code(code.code);
1312 successful_tests++;
1313 }
1314
1315 static void test17(void)
1316 {
1317 /* Test arm constant pool. */
1318 executable_code code;
1319 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1320 sljit_s32 i;
1321 sljit_sw buf[5];
1322
1323 if (verbose)
1324 printf("Run test17\n");
1325
1326 FAILED(!compiler, "cannot create compiler\n");
1327 buf[0] = 0;
1328 buf[1] = 0;
1329 buf[2] = 0;
1330 buf[3] = 0;
1331 buf[4] = 0;
1332
1333 sljit_emit_enter(compiler, 0, 1, 3, 1, 0, 0, 0);
1334 for (i = 0; i <= 0xfff; i++) {
1335 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x81818000 | i);
1336 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x81818000 | i);
1337 if ((i & 0x3ff) == 0)
1338 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), (i >> 10) * sizeof(sljit_sw), SLJIT_R0, 0);
1339 }
1340 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
1341 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1342
1343 code.code = sljit_generate_code(compiler);
1344 CHECK(compiler);
1345 sljit_free_compiler(compiler);
1346
1347 code.func1((sljit_sw)&buf);
1348 FAILED((sljit_uw)buf[0] != 0x81818000, "test17 case 1 failed\n");
1349 FAILED((sljit_uw)buf[1] != 0x81818400, "test17 case 2 failed\n");
1350 FAILED((sljit_uw)buf[2] != 0x81818800, "test17 case 3 failed\n");
1351 FAILED((sljit_uw)buf[3] != 0x81818c00, "test17 case 4 failed\n");
1352 FAILED((sljit_uw)buf[4] != 0x81818fff, "test17 case 5 failed\n");
1353
1354 sljit_free_code(code.code);
1355 successful_tests++;
1356 }
1357
1358 static void test18(void)
1359 {
1360 /* Test 64 bit. */
1361 executable_code code;
1362 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1363 sljit_sw buf[11];
1364
1365 if (verbose)
1366 printf("Run test18\n");
1367
1368 FAILED(!compiler, "cannot create compiler\n");
1369 buf[0] = 0;
1370 buf[1] = 0;
1371 buf[2] = 0;
1372 buf[3] = 0;
1373 buf[4] = 0;
1374 buf[5] = 100;
1375 buf[6] = 100;
1376 buf[7] = 100;
1377 buf[8] = 100;
1378 buf[9] = 0;
1379 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1380 buf[10] = SLJIT_W(1) << 32;
1381 #else
1382 buf[10] = 1;
1383 #endif
1384
1385 sljit_emit_enter(compiler, 0, 1, 3, 2, 0, 0, 0);
1386
1387 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1388 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, SLJIT_W(0x1122334455667788));
1389 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x1122334455667788));
1390
1391 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(1000000000000));
1392 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(1000000000000));
1393 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_IMM, SLJIT_W(5000000000000), SLJIT_R0, 0);
1394
1395 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1396 sljit_emit_op2(compiler, SLJIT_ADD32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1397
1398 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1399 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1400 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_UNUSED, 0, SLJIT_ZERO);
1401 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_S1, 0);
1402 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
1403 sljit_emit_op2(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1404 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_UNUSED, 0, SLJIT_ZERO32);
1405
1406 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1407 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x2208080808));
1408 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_UNUSED, 0, SLJIT_LESS);
1409 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
1410 sljit_emit_op2(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1104040404));
1411 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_UNUSED, 0, SLJIT_NOT_ZERO32);
1412
1413 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 4);
1414 sljit_emit_op2(compiler, SLJIT_SHL32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_IMM, SLJIT_W(0xffff0000), SLJIT_R0, 0);
1415
1416 sljit_emit_op2(compiler, SLJIT_MUL32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 10, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 10, SLJIT_IMM, -1);
1417 #else
1418 /* 32 bit operations. */
1419
1420 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0x11223344);
1421 sljit_emit_op2(compiler, SLJIT_ADD32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 0x44332211);
1422
1423 #endif
1424
1425 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1426
1427 code.code = sljit_generate_code(compiler);
1428 CHECK(compiler);
1429 sljit_free_compiler(compiler);
1430
1431 code.func1((sljit_sw)&buf);
1432 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1433 FAILED(buf[0] != SLJIT_W(0x1122334455667788), "test18 case 1 failed\n");
1434 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1435 FAILED(buf[1] != 0x55667788, "test18 case 2 failed\n");
1436 #else
1437 FAILED(buf[1] != SLJIT_W(0x5566778800000000), "test18 case 2 failed\n");
1438 #endif
1439 FAILED(buf[2] != SLJIT_W(2000000000000), "test18 case 3 failed\n");
1440 FAILED(buf[3] != SLJIT_W(4000000000000), "test18 case 4 failed\n");
1441 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1442 FAILED(buf[4] != 0x28282828, "test18 case 5 failed\n");
1443 #else
1444 FAILED(buf[4] != SLJIT_W(0x2828282800000000), "test18 case 5 failed\n");
1445 #endif
1446 FAILED(buf[5] != 0, "test18 case 6 failed\n");
1447 FAILED(buf[6] != 1, "test18 case 7 failed\n");
1448 FAILED(buf[7] != 1, "test18 case 8 failed\n");
1449 FAILED(buf[8] != 0, "test18 case 9 failed\n");
1450 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1451 FAILED(buf[9] != 0xfff00000, "test18 case 10 failed\n");
1452 FAILED(buf[10] != 0xffffffff, "test18 case 11 failed\n");
1453 #else
1454 FAILED(buf[9] != SLJIT_W(0xfff0000000000000), "test18 case 10 failed\n");
1455 FAILED(buf[10] != SLJIT_W(0xffffffff00000000), "test18 case 11 failed\n");
1456 #endif
1457 #else
1458 FAILED(buf[0] != 0x11223344, "test18 case 1 failed\n");
1459 FAILED(buf[1] != 0x44332211, "test18 case 2 failed\n");
1460 #endif
1461
1462 sljit_free_code(code.code);
1463 successful_tests++;
1464 }
1465
1466 static void test19(void)
1467 {
1468 /* Test arm partial instruction caching. */
1469 executable_code code;
1470 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1471 sljit_sw buf[10];
1472
1473 if (verbose)
1474 printf("Run test19\n");
1475
1476 FAILED(!compiler, "cannot create compiler\n");
1477 buf[0] = 6;
1478 buf[1] = 4;
1479 buf[2] = 0;
1480 buf[3] = 0;
1481 buf[4] = 0;
1482 buf[5] = 0;
1483 buf[6] = 2;
1484 buf[7] = 0;
1485
1486 sljit_emit_enter(compiler, 0, 1, 3, 1, 0, 0, 0);
1487 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
1488 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM0(), (sljit_sw)&buf[2], SLJIT_MEM0(), (sljit_sw)&buf[1], SLJIT_MEM0(), (sljit_sw)&buf[0]);
1489 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
1490 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1491 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&buf[0], SLJIT_MEM1(SLJIT_R1), (sljit_sw)&buf[0]);
1492 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_MEM0(), (sljit_sw)&buf[0], SLJIT_IMM, 2);
1493 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&buf[0] + 4 * sizeof(sljit_sw));
1494 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_IMM, 10);
1495 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 7);
1496 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_R1), (sljit_sw)&buf[5], SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_MEM1(SLJIT_R1), (sljit_sw)&buf[5]);
1497
1498 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1499
1500 code.code = sljit_generate_code(compiler);
1501 CHECK(compiler);
1502 sljit_free_compiler(compiler);
1503
1504 code.func1((sljit_sw)&buf);
1505 FAILED(buf[0] != 10, "test19 case 1 failed\n");
1506 FAILED(buf[1] != 4, "test19 case 2 failed\n");
1507 FAILED(buf[2] != 14, "test19 case 3 failed\n");
1508 FAILED(buf[3] != 14, "test19 case 4 failed\n");
1509 FAILED(buf[4] != 8, "test19 case 5 failed\n");
1510 FAILED(buf[5] != 6, "test19 case 6 failed\n");
1511 FAILED(buf[6] != 12, "test19 case 7 failed\n");
1512 FAILED(buf[7] != 10, "test19 case 8 failed\n");
1513
1514 sljit_free_code(code.code);
1515 successful_tests++;
1516 }
1517
1518 static void test20(void)
1519 {
1520 /* Test stack. */
1521 executable_code code;
1522 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1523 struct sljit_jump* jump;
1524 struct sljit_label* label;
1525 sljit_sw buf[6];
1526 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1527 sljit_sw offset_value = SLJIT_W(0x1234567812345678);
1528 #else
1529 sljit_sw offset_value = SLJIT_W(0x12345678);
1530 #endif
1531
1532 if (verbose)
1533 printf("Run test20\n");
1534
1535 FAILED(!compiler, "cannot create compiler\n");
1536 buf[0] = 5;
1537 buf[1] = 12;
1538 buf[2] = 0;
1539 buf[3] = 0;
1540 buf[4] = 111;
1541 buf[5] = -12345;
1542
1543 sljit_emit_enter(compiler, 0, 1, 5, 5, 0, 0, 4 * sizeof(sljit_sw));
1544 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_S0), 0);
1545 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw));
1546 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -1);
1547 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, -1);
1548 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, -1);
1549 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_IMM, -1);
1550 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_uw), SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
1551 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_uw), SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_SP), 0);
1552 sljit_get_local_base(compiler, SLJIT_R0, 0, -offset_value);
1553 sljit_get_local_base(compiler, SLJIT_MEM1(SLJIT_S0), 0, -0x1234);
1554 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), 0);
1555 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_uw), SLJIT_MEM1(SLJIT_R0), offset_value, SLJIT_MEM1(SLJIT_R1), 0x1234 + sizeof(sljit_sw));
1556 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_uw));
1557 /* Dummy last instructions. */
1558 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, 23);
1559 sljit_emit_label(compiler);
1560
1561 code.code = sljit_generate_code(compiler);
1562 CHECK(compiler);
1563 sljit_free_compiler(compiler);
1564
1565 FAILED(code.func1((sljit_sw)&buf) != -12345, "test20 case 1 failed\n")
1566
1567 FAILED(buf[2] != 60, "test20 case 2 failed\n");
1568 FAILED(buf[3] != 17, "test20 case 3 failed\n");
1569 FAILED(buf[4] != 7, "test20 case 4 failed\n");
1570
1571 sljit_free_code(code.code);
1572
1573 compiler = sljit_create_compiler(NULL);
1574 sljit_emit_enter(compiler, 0, 0, 3, 0, 0, 0, SLJIT_MAX_LOCAL_SIZE);
1575
1576 sljit_get_local_base(compiler, SLJIT_R0, 0, SLJIT_MAX_LOCAL_SIZE - sizeof(sljit_sw));
1577 sljit_get_local_base(compiler, SLJIT_R1, 0, -(sljit_sw)sizeof(sljit_sw));
1578 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -1);
1579 label = sljit_emit_label(compiler);
1580 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_sw), SLJIT_R2, 0);
1581 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_R0, 0);
1582 jump = sljit_emit_jump(compiler, SLJIT_NOT_EQUAL);
1583 sljit_set_label(jump, label);
1584
1585 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 0x5387);
1586
1587 code.code = sljit_generate_code(compiler);
1588 CHECK(compiler);
1589 sljit_free_compiler(compiler);
1590
1591 FAILED(code.func0() != 0x5387, "test20 case 5 failed\n");
1592
1593 sljit_free_code(code.code);
1594
1595 compiler = sljit_create_compiler(NULL);
1596 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, 0, 3, 0, 0, 0, SLJIT_MAX_LOCAL_SIZE);
1597
1598 sljit_get_local_base(compiler, SLJIT_R0, 0, SLJIT_MAX_LOCAL_SIZE - sizeof(sljit_sw));
1599 sljit_get_local_base(compiler, SLJIT_R1, 0, -(sljit_sw)sizeof(sljit_sw));
1600 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -1);
1601 label = sljit_emit_label(compiler);
1602 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_sw), SLJIT_R2, 0);
1603 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_R0, 0);
1604 jump = sljit_emit_jump(compiler, SLJIT_NOT_EQUAL);
1605 sljit_set_label(jump, label);
1606
1607 sljit_get_local_base(compiler, SLJIT_R0, 0, 0);
1608 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
1609
1610 code.code = sljit_generate_code(compiler);
1611 CHECK(compiler);
1612 sljit_free_compiler(compiler);
1613
1614 FAILED(code.func0() % sizeof(sljit_f64) != 0, "test20 case 6 failed\n");
1615
1616 sljit_free_code(code.code);
1617 successful_tests++;
1618 }
1619
1620 static void test21(void)
1621 {
1622 /* Test set context. The parts of the jit code can be separated in the memory. */
1623 executable_code code1;
1624 executable_code code2;
1625 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1626 struct sljit_jump* jump = NULL;
1627 sljit_uw addr;
1628 sljit_sw executable_offset;
1629 sljit_sw buf[4];
1630
1631 if (verbose)
1632 printf("Run test21\n");
1633
1634 FAILED(!compiler, "cannot create compiler\n");
1635 buf[0] = 9;
1636 buf[1] = -6;
1637 buf[2] = 0;
1638 buf[3] = 0;
1639
1640 sljit_emit_enter(compiler, 0, 1, 3, 2, 0, 0, 2 * sizeof(sljit_sw));
1641
1642 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 10);
1643 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_SP), 0);
1644
1645 jump = sljit_emit_jump(compiler, SLJIT_JUMP | SLJIT_REWRITABLE_JUMP);
1646 sljit_set_target(jump, 0);
1647
1648 code1.code = sljit_generate_code(compiler);
1649 CHECK(compiler);
1650
1651 executable_offset = sljit_get_executable_offset(compiler);
1652 addr = sljit_get_jump_addr(jump);
1653
1654 sljit_free_compiler(compiler);
1655
1656 compiler = sljit_create_compiler(NULL);
1657 FAILED(!compiler, "cannot create compiler\n");
1658
1659 /* Other part of the jit code. */
1660 sljit_set_context(compiler, 0, 1, 3, 2, 0, 0, 2 * sizeof(sljit_sw));
1661
1662 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SP), 0);
1663 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_SP), 0);
1664 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_sw));
1665
1666 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1667
1668 code2.code = sljit_generate_code(compiler);
1669 CHECK(compiler);
1670 sljit_free_compiler(compiler);
1671
1672 sljit_set_jump_addr(addr, SLJIT_FUNC_OFFSET(code2.code), executable_offset);
1673
1674 FAILED(code1.func1((sljit_sw)&buf) != 19, "test21 case 1 failed\n");
1675 FAILED(buf[2] != -16, "test21 case 2 failed\n");
1676 FAILED(buf[3] != 100, "test21 case 3 failed\n");
1677
1678 sljit_free_code(code1.code);
1679 sljit_free_code(code2.code);
1680 successful_tests++;
1681 }
1682
1683 static void test22(void)
1684 {
1685 /* Test simple byte and half-int data transfers. */
1686 executable_code code;
1687 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1688 sljit_sw buf[9];
1689 sljit_s16 sbuf[7];
1690 sljit_s8 bbuf[5];
1691
1692 if (verbose)
1693 printf("Run test22\n");
1694
1695 FAILED(!compiler, "cannot create compiler\n");
1696 buf[0] = 5;
1697 buf[1] = 0;
1698 buf[2] = 0;
1699 buf[3] = 0;
1700 buf[4] = 0;
1701 buf[5] = 0;
1702 buf[6] = 0;
1703 buf[7] = 0;
1704 buf[8] = 0;
1705
1706 sbuf[0] = 0;
1707 sbuf[1] = 0;
1708 sbuf[2] = -9;
1709 sbuf[3] = 0;
1710 sbuf[4] = 0;
1711 sbuf[5] = 0;
1712 sbuf[6] = 0;
1713
1714 bbuf[0] = 0;
1715 bbuf[1] = 0;
1716 bbuf[2] = -56;
1717 bbuf[3] = 0;
1718 bbuf[4] = 0;
1719
1720 sljit_emit_enter(compiler, 0, 3, 3, 3, 0, 0, 0);
1721
1722 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, sizeof(sljit_sw));
1723 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_S0, 0);
1724 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_sw), SLJIT_IMM, -13);
1725 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_sw));
1726 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_sw), SLJIT_R2, 0);
1727 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_R0), sizeof(sljit_sw));
1728 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1 << SLJIT_WORD_SHIFT);
1729 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_R1, 0);
1730 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0, SLJIT_R2, 0);
1731 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
1732 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0, SLJIT_R1, 0);
1733 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2 << SLJIT_WORD_SHIFT);
1734 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_R1, 0);
1735 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0, SLJIT_R2, 0);
1736
1737 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, -13);
1738 sljit_emit_op1(compiler, SLJIT_MOVU_U16, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s16), SLJIT_IMM, 0x1234);
1739 sljit_emit_op1(compiler, SLJIT_MOVU_S16, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s16));
1740 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R0, 0);
1741 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s16), SLJIT_MEM1(SLJIT_S1), -(sljit_sw)sizeof(sljit_s16));
1742 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xff0000 + 8000);
1743 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 2);
1744 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM2(SLJIT_S1, SLJIT_R1), 1, SLJIT_R0, 0);
1745 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 6);
1746 sljit_emit_op1(compiler, SLJIT_MOVU_S16, SLJIT_MEM2(SLJIT_S1, SLJIT_R1), 0, SLJIT_R0, 0);
1747 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, -9317);
1748 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S1, 0, SLJIT_IMM, 5 * sizeof(sljit_s16));
1749 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -10);
1750 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R1, 0, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0);
1751 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s16), SLJIT_R1, 0);
1752
1753 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM1(SLJIT_S2), 0, SLJIT_IMM, -45);
1754 sljit_emit_op1(compiler, SLJIT_MOVU_U8, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_s8), SLJIT_IMM, 0x12);
1755 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2 * sizeof(sljit_s8));
1756 sljit_emit_op1(compiler, SLJIT_MOVU_S8, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_s8));
1757 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_S1, 0, SLJIT_R1, 0);
1758 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_S1, 0, SLJIT_S1, 0);
1759 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R2, 0, SLJIT_S1, 0);
1760 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R2, 0);
1761 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_s8), SLJIT_S1, 0);
1762 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM2(SLJIT_S2, SLJIT_R0), 0, SLJIT_R0, 0);
1763
1764 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1765
1766 code.code = sljit_generate_code(compiler);
1767 CHECK(compiler);
1768 sljit_free_compiler(compiler);
1769
1770 code.func3((sljit_sw)&buf, (sljit_sw)&sbuf, (sljit_sw)&bbuf);
1771 FAILED(buf[1] != -13, "test22 case 1 failed\n");
1772 FAILED(buf[2] != 5, "test22 case 2 failed\n");
1773 FAILED(buf[3] != -13, "test22 case 3 failed\n");
1774 FAILED(buf[4] != (sljit_sw)&buf[3], "test22 case 4 failed\n");
1775 FAILED(buf[5] != (sljit_sw)&buf[4], "test22 case 5 failed\n");
1776 FAILED(buf[6] != (sljit_sw)&buf[4], "test22 case 6 failed\n");
1777 FAILED(buf[7] != -9, "test22 case 7 failed\n");
1778 FAILED(buf[8] != -56, "test22 case 8 failed\n");
1779
1780 FAILED(sbuf[0] != -13, "test22 case 9 failed\n");
1781 FAILED(sbuf[1] != 0x1234, "test22 case 10 failed\n");
1782 FAILED(sbuf[3] != 0x1234, "test22 case 11 failed\n");
1783 FAILED(sbuf[4] != 8000, "test22 case 12 failed\n");
1784 FAILED(sbuf[5] != -9317, "test22 case 13 failed\n");
1785 FAILED(sbuf[6] != -9317, "test22 case 14 failed\n");
1786
1787 FAILED(bbuf[0] != -45, "test22 case 15 failed\n");
1788 FAILED(bbuf[1] != 0x12, "test22 case 16 failed\n");
1789 FAILED(bbuf[3] != -56, "test22 case 17 failed\n");
1790 FAILED(bbuf[4] != 2, "test22 case 18 failed\n");
1791
1792 sljit_free_code(code.code);
1793 successful_tests++;
1794 }
1795
1796 static void test23(void)
1797 {
1798 /* Test 32 bit / 64 bit signed / unsigned int transfer and conversion.
1799 This test has do real things on 64 bit systems, but works on 32 bit systems as well. */
1800 executable_code code;
1801 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1802 sljit_sw buf[9];
1803 sljit_s32 ibuf[5];
1804 union {
1805 sljit_s32 asint;
1806 sljit_u8 asbytes[4];
1807 } u;
1808 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1809 sljit_sw garbage = SLJIT_W(0x1234567812345678);
1810 #else
1811 sljit_sw garbage = 0x12345678;
1812 #endif
1813
1814 if (verbose)
1815 printf("Run test23\n");
1816
1817 FAILED(!compiler, "cannot create compiler\n");
1818 buf[0] = 0;
1819 buf[1] = 0;
1820 buf[2] = 0;
1821 buf[3] = 0;
1822 buf[4] = 0;
1823 buf[5] = 0;
1824 buf[6] = 0;
1825 buf[7] = 0;
1826 buf[8] = 0;
1827
1828 ibuf[0] = 0;
1829 ibuf[1] = 0;
1830 ibuf[2] = -5791;
1831 ibuf[3] = 43579;
1832 ibuf[4] = 658923;
1833
1834 sljit_emit_enter(compiler, 0, 2, 3, 3, 0, 0, 0);
1835 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, 34567);
1836 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
1837 sljit_emit_op1(compiler, SLJIT_MOVU_S32, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), 0, SLJIT_IMM, -7654);
1838 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, garbage);
1839 sljit_emit_op1(compiler, SLJIT_MOVU_S32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32));
1840 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
1841 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, garbage);
1842 sljit_emit_op1(compiler, SLJIT_MOVU_U32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32));
1843 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
1844 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, garbage);
1845 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32));
1846 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
1847 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
1848 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x0f00f00);
1849 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 0x7777);
1850 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), 0x7777 + 2 * sizeof(sljit_sw), SLJIT_R0, 0);
1851 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 0x7777);
1852 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), -0x7777 + (sljit_sw)sizeof(sljit_sw), SLJIT_R0, 0);
1853 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, sizeof(sljit_sw));
1854 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1);
1855 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM2(SLJIT_R1, SLJIT_R1), 0, SLJIT_IMM, 16);
1856 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_R1), 0, SLJIT_IMM, 64, SLJIT_MEM1(SLJIT_R1), 0);
1857 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
1858 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&buf[6], SLJIT_MEM0(), (sljit_sw)&buf[6]);
1859 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_IMM, 0x123456);
1860 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_S0, 0);
1861 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R1, 0);
1862 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, sizeof(sljit_sw));
1863 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 100000 * sizeof(sljit_sw));
1864 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), 100001 * sizeof(sljit_sw), SLJIT_IMM, 123456);
1865 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 123);
1866 sljit_emit_op1(compiler, SLJIT_MOVU_S32, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32), SLJIT_IMM, 0x12345678);
1867
1868 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x2bd700 | 243);
1869 sljit_emit_return(compiler, SLJIT_MOV_S8, SLJIT_R1, 0);
1870
1871 code.code = sljit_generate_code(compiler);
1872 CHECK(compiler);
1873 sljit_free_compiler(compiler);
1874
1875 FAILED(code.func2((sljit_sw)&buf, (sljit_sw)&ibuf) != -13, "test23 case 1 failed\n");
1876 FAILED(buf[0] != -5791, "test23 case 2 failed\n");
1877 FAILED(buf[1] != 43579, "test23 case 3 failed\n");
1878 FAILED(buf[2] != 658923, "test23 case 4 failed\n");
1879 FAILED(buf[3] != 0x0f00f00, "test23 case 5 failed\n");
1880 FAILED(buf[4] != 0x0f00f00, "test23 case 6 failed\n");
1881 FAILED(buf[5] != 80, "test23 case 7 failed\n");
1882 FAILED(buf[6] != 0x123456, "test23 case 8 failed\n");
1883 FAILED(buf[7] != (sljit_sw)&buf[5], "test23 case 9 failed\n");
1884 FAILED(buf[8] != 123456 + 123, "test23 case 10 failed\n");
1885
1886 FAILED(ibuf[0] != 34567, "test23 case 11 failed\n");
1887 FAILED(ibuf[1] != -7654, "test23 case 12 failed\n");
1888 u.asint = ibuf[4];
1889 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1890 FAILED(u.asbytes[0] != 0x78, "test23 case 13 failed\n");
1891 FAILED(u.asbytes[1] != 0x56, "test23 case 14 failed\n");
1892 FAILED(u.asbytes[2] != 0x34, "test23 case 15 failed\n");
1893 FAILED(u.asbytes[3] != 0x12, "test23 case 16 failed\n");
1894 #else
1895 FAILED(u.asbytes[0] != 0x12, "test23 case 13 failed\n");
1896 FAILED(u.asbytes[1] != 0x34, "test23 case 14 failed\n");
1897 FAILED(u.asbytes[2] != 0x56, "test23 case 15 failed\n");
1898 FAILED(u.asbytes[3] != 0x78, "test23 case 16 failed\n");
1899 #endif
1900
1901 sljit_free_code(code.code);
1902 successful_tests++;
1903 }
1904
1905 static void test24(void)
1906 {
1907 /* Some complicated addressing modes. */
1908 executable_code code;
1909 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1910 sljit_sw buf[9];
1911 sljit_s16 sbuf[5];
1912 sljit_s8 bbuf[7];
1913
1914 if (verbose)
1915 printf("Run test24\n");
1916
1917 FAILED(!compiler, "cannot create compiler\n");
1918
1919 buf[0] = 100567;
1920 buf[1] = 75799;
1921 buf[2] = 0;
1922 buf[3] = -8;
1923 buf[4] = -50;
1924 buf[5] = 0;
1925 buf[6] = 0;
1926 buf[7] = 0;
1927 buf[8] = 0;
1928
1929 sbuf[0] = 30000;
1930 sbuf[1] = 0;
1931 sbuf[2] = 0;
1932 sbuf[3] = -12345;
1933 sbuf[4] = 0;
1934
1935 bbuf[0] = -128;
1936 bbuf[1] = 0;
1937 bbuf[2] = 0;
1938 bbuf[3] = 99;
1939 bbuf[4] = 0;
1940 bbuf[5] = 0;
1941 bbuf[6] = 0;
1942
1943 sljit_emit_enter(compiler, 0, 3, 3, 3, 0, 0, 0);
1944
1945 /* Nothing should be updated. */
1946 sljit_emit_op1(compiler, SLJIT_MOVU_S16, SLJIT_MEM0(), (sljit_sw)&sbuf[1], SLJIT_MEM0(), (sljit_sw)&sbuf[0]);
1947 sljit_emit_op1(compiler, SLJIT_MOVU_S8, SLJIT_MEM0(), (sljit_sw)&bbuf[1], SLJIT_MEM0(), (sljit_sw)&bbuf[0]);
1948 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
1949 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), 1, SLJIT_MEM0(), (sljit_sw)&sbuf[3]);
1950 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[0]);
1951 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1952 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2);
1953 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM2(SLJIT_R0, SLJIT_R2), SLJIT_WORD_SHIFT, SLJIT_MEM0(), (sljit_sw)&buf[0], SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0);
1954 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_s8));
1955 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_s8));
1956 sljit_emit_op1(compiler, SLJIT_MOVU_U8, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&bbuf[1], SLJIT_MEM1(SLJIT_R1), (sljit_sw)&bbuf[0]);
1957 sljit_emit_op1(compiler, SLJIT_MOVU_U8, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_MEM1(SLJIT_R1), 2 * sizeof(sljit_s8));
1958
1959 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_s16));
1960 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R1), (sljit_sw)&sbuf[3], SLJIT_R1, 0);
1961
1962 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3);
1963 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT);
1964 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
1965 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_S0, 0);
1966 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT);
1967 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
1968 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, sizeof(sljit_sw));
1969 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 4 << SLJIT_WORD_SHIFT);
1970 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0, SLJIT_MEM2(SLJIT_R0, SLJIT_R2), 0);
1971 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R0, 0);
1972 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R1, 0);
1973
1974 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf - 0x7fff8000 + 6 * sizeof(sljit_sw));
1975 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 952467);
1976 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0x7fff8000, SLJIT_R1, 0);
1977 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0x7fff8000 + sizeof(sljit_sw), SLJIT_MEM1(SLJIT_R0), 0x7fff8000);
1978
1979 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf + 0x7fff7fff + 6 * sizeof(sljit_sw));
1980 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_R0), -0x7fff7fff + 2 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_R0), -0x7fff7fff + sizeof(sljit_sw), SLJIT_MEM1(SLJIT_R0), -0x7fff7fff);
1981 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&bbuf - 0x7fff7ffe + 3 * sizeof(sljit_s8));
1982 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM1(SLJIT_R0), 0x7fff7fff, SLJIT_MEM1(SLJIT_R0), 0x7fff7ffe);
1983 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&bbuf + 0x7fff7fff + 5 * sizeof(sljit_s8));
1984 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM1(SLJIT_R0), -0x7fff7fff, SLJIT_MEM1(SLJIT_R0), -0x7fff8000);
1985 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1986 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&bbuf - SLJIT_W(0x123456123456));
1987 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&bbuf - SLJIT_W(0x123456123456));
1988 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM1(SLJIT_R0), SLJIT_W(0x123456123456) + 6 * sizeof(sljit_s8), SLJIT_MEM1(SLJIT_R1), SLJIT_W(0x123456123456));
1989 #endif
1990
1991 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1992
1993 code.code = sljit_generate_code(compiler);
1994 CHECK(compiler);
1995 sljit_free_compiler(compiler);
1996
1997 code.func3((sljit_sw)&buf, (sljit_sw)&sbuf, (sljit_sw)&bbuf);
1998 FAILED(buf[2] != 176366, "test24 case 1 failed\n");
1999 FAILED(buf[3] != 64, "test24 case 2 failed\n");
2000 FAILED(buf[4] != -100, "test24 case 3 failed\n");
2001 FAILED(buf[5] != -100 + (sljit_sw)&buf[5] + (sljit_sw)&buf[4], "test24 case 4 failed\n");
2002 FAILED(buf[6] != 952467, "test24 case 5 failed\n");
2003 FAILED(buf[7] != 952467, "test24 case 6 failed\n");
2004 FAILED(buf[8] != 952467 * 2, "test24 case 7 failed\n");
2005
2006 FAILED(sbuf[1] != 30000, "test24 case 8 failed\n");
2007 FAILED(sbuf[2] != -12345, "test24 case 9 failed\n");
2008 FAILED(sbuf[4] != sizeof(sljit_s16), "test24 case 10 failed\n");
2009
2010 FAILED(bbuf[1] != -128, "test24 case 11 failed\n");
2011 FAILED(bbuf[2] != 99, "test24 case 12 failed\n");
2012 FAILED(bbuf[4] != 99, "test24 case 13 failed\n");
2013 FAILED(bbuf[5] != 99, "test24 case 14 failed\n");
2014 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2015 FAILED(bbuf[6] != -128, "test24 case 15 failed\n");
2016 #endif
2017
2018 sljit_free_code(code.code);
2019 successful_tests++;
2020 }
2021
2022 static void test25(void)
2023 {
2024 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2025 /* 64 bit loads. */
2026 executable_code code;
2027 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2028 sljit_sw buf[14];
2029
2030 if (verbose)
2031 printf("Run test25\n");
2032
2033 FAILED(!compiler, "cannot create compiler\n");
2034 buf[0] = 7;
2035 buf[1] = 0;
2036 buf[2] = 0;
2037 buf[3] = 0;
2038 buf[4] = 0;
2039 buf[5] = 0;
2040 buf[6] = 0;
2041 buf[7] = 0;
2042 buf[8] = 0;
2043 buf[9] = 0;
2044 buf[10] = 0;
2045 buf[11] = 0;
2046 buf[12] = 0;
2047 buf[13] = 0;
2048
2049 sljit_emit_enter(compiler, 0, 1, 3, 1, 0, 0, 0);
2050
2051 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0);
2052 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 1 * sizeof(sljit_sw), SLJIT_IMM, 0x7fff);
2053 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_IMM, -0x8000);
2054 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_IMM, 0x7fffffff);
2055 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(-0x80000000));
2056 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x1234567887654321));
2057 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0xff80000000));
2058 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x3ff0000000));
2059 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0xfffffff800100000));
2060 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0xfffffff80010f000));
2061 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00000008001));
2062 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00080010000));
2063 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00080018001));
2064 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00ffff00000));
2065
2066 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2067
2068 code.code = sljit_generate_code(compiler);
2069 CHECK(compiler);
2070 sljit_free_compiler(compiler);
2071
2072 code.func1((sljit_sw)&buf);
2073 FAILED(buf[0] != 0, "test25 case 1 failed\n");
2074 FAILED(buf[1] != 0x7fff, "test25 case 2 failed\n");
2075 FAILED(buf[2] != -0x8000, "test25 case 3 failed\n");
2076 FAILED(buf[3] != 0x7fffffff, "test25 case 4 failed\n");
2077 FAILED(buf[4] != SLJIT_W(-0x80000000), "test25 case 5 failed\n");
2078 FAILED(buf[5] != SLJIT_W(0x1234567887654321), "test25 case 6 failed\n");
2079 FAILED(buf[6] != SLJIT_W(0xff80000000), "test25 case 7 failed\n");
2080 FAILED(buf[7] != SLJIT_W(0x3ff0000000), "test25 case 8 failed\n");
2081 FAILED((sljit_uw)buf[8] != SLJIT_W(0xfffffff800100000), "test25 case 9 failed\n");
2082 FAILED((sljit_uw)buf[9] != SLJIT_W(0xfffffff80010f000), "test25 case 10 failed\n");
2083 FAILED(buf[10] != SLJIT_W(0x07fff00000008001), "test25 case 11 failed\n");
2084 FAILED(buf[11] != SLJIT_W(0x07fff00080010000), "test25 case 12 failed\n");
2085 FAILED(buf[12] != SLJIT_W(0x07fff00080018001), "test25 case 13 failed\n");
2086 FAILED(buf[13] != SLJIT_W(0x07fff00ffff00000), "test25 case 14 failed\n");
2087
2088 sljit_free_code(code.code);
2089 #endif
2090 successful_tests++;
2091 }
2092
2093 static void test26(void)
2094 {
2095 /* Aligned access without aligned offsets. */
2096 executable_code code;
2097 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2098 sljit_sw buf[4];
2099 sljit_s32 ibuf[4];
2100 sljit_f64 dbuf[4];
2101
2102 if (verbose)
2103 printf("Run test26\n");
2104
2105 FAILED(!compiler, "cannot create compiler\n");
2106
2107 buf[0] = -2789;
2108 buf[1] = 0;
2109 buf[2] = 4;
2110 buf[3] = -4;
2111
2112 ibuf[0] = -689;
2113 ibuf[1] = 0;
2114 ibuf[2] = -6;
2115 ibuf[3] = 3;
2116
2117 dbuf[0] = 5.75;
2118 dbuf[1] = 0.0;
2119 dbuf[2] = 0.0;
2120 dbuf[3] = -4.0;
2121
2122 sljit_emit_enter(compiler, 0, 3, 3, 3, 0, 0, 0);
2123
2124 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 3);
2125 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, 1);
2126 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), -3);
2127 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32) - 1, SLJIT_R0, 0);
2128 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), -1);
2129 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) - 3, SLJIT_R0, 0);
2130
2131 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 100);
2132 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_sw) * 2 - 103, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2 - 3, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3 - 3);
2133 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, 100);
2134 sljit_emit_op2(compiler, SLJIT_MUL32, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_s32) * 2 - 101, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32) * 2 - 1, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32) * 3 - 1);
2135
2136 if (sljit_is_fpu_available()) {
2137 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S2, 0, SLJIT_S2, 0, SLJIT_IMM, 3);
2138 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f64) - 3, SLJIT_MEM1(SLJIT_S2), -3);
2139 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f64) * 2 - 3, SLJIT_MEM1(SLJIT_S2), -3, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f64) - 3);
2140 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S2, 0, SLJIT_IMM, 2);
2141 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sizeof(sljit_f64) * 3 - 4) >> 1);
2142 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, 1);
2143 sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_f64) * 3 - 5, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f64) * 2 - 3, SLJIT_MEM2(SLJIT_R2, SLJIT_R1), 1);
2144 }
2145
2146 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2147
2148 code.code = sljit_generate_code(compiler);
2149 CHECK(compiler);
2150 sljit_free_compiler(compiler);
2151
2152 code.func3((sljit_sw)&buf, (sljit_sw)&ibuf, (sljit_sw)&dbuf);
2153
2154 FAILED(buf[1] != -689, "test26 case 1 failed\n");
2155 FAILED(buf[2] != -16, "test26 case 2 failed\n");
2156 FAILED(ibuf[1] != -2789, "test26 case 3 failed\n");
2157 FAILED(ibuf[2] != -18, "test26 case 4 failed\n");
2158
2159 if (sljit_is_fpu_available()) {
2160 FAILED(dbuf[1] != 5.75, "test26 case 5 failed\n");
2161 FAILED(dbuf[2] != 11.5, "test26 case 6 failed\n");
2162 FAILED(dbuf[3] != -2.875, "test26 case 7 failed\n");
2163 }
2164
2165 sljit_free_code(code.code);
2166 successful_tests++;
2167 }
2168
2169 static void test27(void)
2170 {
2171 #define SET_NEXT_BYTE(type) \
2172 cond_set(compiler, SLJIT_R2, 0, type); \
2173 sljit_emit_op1(compiler, SLJIT_MOVU_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R2, 0);
2174 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2175 #define RESULT(i) i
2176 #else
2177 #define RESULT(i) (3 - i)
2178 #endif
2179
2180 /* Playing with conditional flags. */
2181 executable_code code;
2182 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2183 sljit_u8 buf[37];
2184 sljit_s32 i;
2185
2186 if (verbose)
2187 printf("Run test27\n");
2188
2189 for (i = 0; i < 37; ++i)
2190 buf[i] = 10;
2191
2192 FAILED(!compiler, "cannot create compiler\n");
2193
2194 /* 3 arguments passed, 3 arguments used. */
2195 sljit_emit_enter(compiler, 0, 1, 3, 3, 0, 0, 0);
2196
2197 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2198
2199 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x1001);
2200 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 20);
2201 /* 0x100100000 on 64 bit machines, 0x100000 on 32 bit machines. */
2202 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x800000);
2203 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2204 sljit_emit_op0(compiler, SLJIT_NOP); /* Nop should keep the flags. */
2205 SET_NEXT_BYTE(SLJIT_GREATER);
2206 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2207 SET_NEXT_BYTE(SLJIT_LESS);
2208 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
2209 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R1, 0);
2210 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2211 sljit_emit_op0(compiler, SLJIT_NOP); /* Nop should keep the flags. */
2212 SET_NEXT_BYTE(SLJIT_GREATER32);
2213 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2214 SET_NEXT_BYTE(SLJIT_LESS32);
2215
2216 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x1000);
2217 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 20);
2218 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0x10);
2219 /* 0x100000010 on 64 bit machines, 0x10 on 32 bit machines. */
2220 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2221 SET_NEXT_BYTE(SLJIT_GREATER);
2222 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2223 SET_NEXT_BYTE(SLJIT_LESS);
2224 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
2225 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2226 SET_NEXT_BYTE(SLJIT_GREATER32);
2227 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2228 SET_NEXT_BYTE(SLJIT_LESS32);
2229
2230 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2231 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2232 /* 0xff..ff on all machines. */
2233 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2234 SET_NEXT_BYTE(SLJIT_LESS_EQUAL);
2235 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2236 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL);
2237 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R2, 0, SLJIT_R1, 0, SLJIT_IMM, -1);
2238 SET_NEXT_BYTE(SLJIT_SIG_GREATER);
2239 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, -1);
2240 SET_NEXT_BYTE(SLJIT_SIG_LESS);
2241 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_R1, 0, SLJIT_R0, 0);
2242 SET_NEXT_BYTE(SLJIT_EQUAL);
2243 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_R0, 0);
2244 SET_NEXT_BYTE(SLJIT_NOT_EQUAL);
2245 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2246 SET_NEXT_BYTE(SLJIT_OVERFLOW);
2247 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_NOT_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2248 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW);
2249 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2250 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL);
2251 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2252 SET_NEXT_BYTE(SLJIT_LESS_EQUAL);
2253
2254 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x80000000);
2255 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 16);
2256 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 16);
2257 /* 0x80..0 on 64 bit machines, 0 on 32 bit machines. */
2258 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0xffffffff);
2259 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2260 SET_NEXT_BYTE(SLJIT_OVERFLOW);
2261 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_NOT_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2262 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW);
2263 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
2264 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
2265 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2266 SET_NEXT_BYTE(SLJIT_OVERFLOW32);
2267 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_NOT_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2268 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW32);
2269
2270 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2271 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2272 sljit_emit_op2(compiler, SLJIT_SUBC | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0);
2273 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_R0, 0, SLJIT_IMM, 6, SLJIT_R0, 0);
2274 sljit_emit_op1(compiler, SLJIT_MOVU_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R0, 0);
2275
2276 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
2277 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2278 sljit_emit_op2(compiler, SLJIT_ADDC | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2279 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 9);
2280 sljit_emit_op1(compiler, SLJIT_MOVU_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R0, 0);
2281
2282 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2283 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, (8 * sizeof(sljit_sw)) - 1);
2284 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0);
2285 SET_NEXT_BYTE(SLJIT_EQUAL);
2286 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R0, 0);
2287 SET_NEXT_BYTE(SLJIT_EQUAL);
2288
2289 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2290 sljit_emit_op2(compiler, SLJIT_ASHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0);
2291 SET_NEXT_BYTE(SLJIT_EQUAL);
2292 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2293 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffffc0);
2294 SET_NEXT_BYTE(SLJIT_NOT_EQUAL);
2295 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 0);
2296 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2297 sljit_emit_op2(compiler, SLJIT_ASHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_PREF_SHIFT_REG, 0);
2298 SET_NEXT_BYTE(SLJIT_EQUAL);
2299 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 0);
2300 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2301 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_PREF_SHIFT_REG, 0);
2302 SET_NEXT_BYTE(SLJIT_NOT_EQUAL);
2303
2304 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2305 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
2306 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R0, 0);
2307 sljit_emit_op2(compiler, SLJIT_SUBC | SLJIT_SET_CARRY, SLJIT_R2, 0, SLJIT_IMM, 1, SLJIT_R0, 0);
2308 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R2, 0);
2309 sljit_emit_op2(compiler, SLJIT_SUBC | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2310 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_R2, 0, SLJIT_IMM, 1, SLJIT_R0, 0);
2311 sljit_emit_op1(compiler, SLJIT_MOVU_U8, SLJIT_MEM1(SLJIT_S0), 2, SLJIT_R2, 0);
2312
2313 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -34);
2314 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x1234);
2315 SET_NEXT_BYTE(SLJIT_LESS);
2316 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x1234);
2317 SET_NEXT_BYTE(SLJIT_SIG_LESS);
2318 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2319 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x12300000000) - 43);
2320 #else
2321 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, -43);
2322 #endif
2323 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -96);
2324 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2325 SET_NEXT_BYTE(SLJIT_LESS32);
2326 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_SIG_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2327 SET_NEXT_BYTE(SLJIT_SIG_GREATER32);
2328
2329 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2330
2331 code.code = sljit_generate_code(compiler);
2332 CHECK(compiler);
2333 sljit_free_compiler(compiler);
2334
2335 code.func1((sljit_sw)&buf);
2336
2337 FAILED(buf[0] != RESULT(1), "test27 case 1 failed\n");
2338 FAILED(buf[1] != RESULT(2), "test27 case 2 failed\n");
2339 FAILED(buf[2] != 2, "test27 case 3 failed\n");
2340 FAILED(buf[3] != 1, "test27 case 4 failed\n");
2341 FAILED(buf[4] != RESULT(1), "test27 case 5 failed\n");
2342 FAILED(buf[5] != RESULT(2), "test27 case 6 failed\n");
2343 FAILED(buf[6] != 2, "test27 case 7 failed\n");
2344 FAILED(buf[7] != 1, "test27 case 8 failed\n");
2345
2346 FAILED(buf[8] != 2, "test27 case 9 failed\n");
2347 FAILED(buf[9] != 1, "test27 case 10 failed\n");
2348 FAILED(buf[10] != 2, "test27 case 11 failed\n");
2349 FAILED(buf[11] != 1, "test27 case 12 failed\n");
2350 FAILED(buf[12] != 1, "test27 case 13 failed\n");
2351 FAILED(buf[13] != 2, "test27 case 14 failed\n");
2352 FAILED(buf[14] != 2, "test27 case 15 failed\n");
2353 FAILED(buf[15] != 1, "test27 case 16 failed\n");
2354 FAILED(buf[16] != 1, "test27 case 17 failed\n");
2355 FAILED(buf[17] != 2, "test27 case 18 failed\n");
2356
2357 FAILED(buf[18] != RESULT(1), "test27 case 19 failed\n");
2358 FAILED(buf[19] != RESULT(2), "test27 case 20 failed\n");
2359 FAILED(buf[20] != 2, "test27 case 21 failed\n");
2360 FAILED(buf[21] != 1, "test27 case 22 failed\n");
2361
2362 FAILED(buf[22] != 5, "test27 case 23 failed\n");
2363 FAILED(buf[23] != 9, "test27 case 24 failed\n");
2364
2365 FAILED(buf[24] != 2, "test27 case 25 failed\n");
2366 FAILED(buf[25] != 1, "test27 case 26 failed\n");
2367
2368 FAILED(buf[26] != 1, "test27 case 27 failed\n");
2369 FAILED(buf[27] != 1, "test27 case 28 failed\n");
2370 FAILED(buf[28] != 1, "test27 case 29 failed\n");
2371 FAILED(buf[29] != 1, "test27 case 30 failed\n");
2372
2373 FAILED(buf[30] != 1, "test27 case 31 failed\n");
2374 FAILED(buf[31] != 0, "test27 case 32 failed\n");
2375
2376 FAILED(buf[32] != 2, "test27 case 33 failed\n");
2377 FAILED(buf[33] != 1, "test27 case 34 failed\n");
2378 FAILED(buf[34] != 2, "test27 case 35 failed\n");
2379 FAILED(buf[35] != 1, "test27 case 36 failed\n");
2380 FAILED(buf[36] != 10, "test27 case 37 failed\n");
2381
2382 sljit_free_code(code.code);
2383 successful_tests++;
2384 #undef SET_NEXT_BYTE
2385 #undef RESULT
2386 }
2387
2388 static void test28(void)
2389 {
2390 /* Test mov. */
2391 executable_code code;
2392 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2393 struct sljit_const* const1 = NULL;
2394 struct sljit_label* label = NULL;
2395 sljit_uw label_addr = 0;
2396 sljit_sw buf[5];
2397
2398 if (verbose)
2399 printf("Run test28\n");
2400
2401 FAILED(!compiler, "cannot create compiler\n");
2402
2403 buf[0] = -36;
2404 buf[1] = 8;
2405 buf[2] = 0;
2406 buf[3] = 10;
2407 buf[4] = 0;
2408
2409 FAILED(!compiler, "cannot create compiler\n");
2410 sljit_emit_enter(compiler, 0, 1, 5, 5, 0, 0, 0);
2411 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -234);
2412 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
2413 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_S3, 0, SLJIT_R3, 0, SLJIT_R4, 0);
2414 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_S3, 0);
2415 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_S3, 0, SLJIT_IMM, 0);
2416 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_UNUSED, 0, SLJIT_NOT_ZERO);
2417 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_S3, 0);
2418 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw));
2419 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S4, 0, SLJIT_S4, 0, SLJIT_R4, 0);
2420 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_S4, 0);
2421
2422 const1 = sljit_emit_const(compiler, SLJIT_S3, 0, 0);
2423 sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_S3, 0);
2424 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S3, 0, SLJIT_S3, 0, SLJIT_IMM, 100);
2425 label = sljit_emit_label(compiler);
2426 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_S3, 0);
2427
2428 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R4, 0);
2429
2430 code.code = sljit_generate_code(compiler);
2431 CHECK(compiler);
2432
2433 label_addr = sljit_get_label_addr(label);
2434 sljit_set_const(sljit_get_const_addr(const1), label_addr, sljit_get_executable_offset(compiler));
2435
2436 sljit_free_compiler(compiler);
2437
2438 FAILED(code.func1((sljit_sw)&buf) != 8, "test28 case 1 failed\n");
2439 FAILED(buf[1] != -1872, "test28 case 2 failed\n");
2440 FAILED(buf[2] != 1, "test28 case 3 failed\n");
2441 FAILED(buf[3] != 2, "test28 case 4 failed\n");
2442 FAILED(buf[4] != label_addr, "test28 case 5 failed\n");
2443
2444 sljit_free_code(code.code);
2445 successful_tests++;
2446 }
2447
2448 static void test29(void)
2449 {
2450 /* Test signed/unsigned bytes and halfs. */
2451 executable_code code;
2452 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2453 sljit_sw buf[25];
2454
2455 if (verbose)
2456 printf("Run test29\n");
2457
2458 buf[0] = 0;
2459 buf[1] = 0;
2460 buf[2] = 0;
2461 buf[3] = 0;
2462 buf[4] = 0;
2463 buf[5] = 0;
2464 buf[6] = 0;
2465 buf[7] = 0;
2466 buf[8] = 0;
2467 buf[9] = 0;
2468 buf[10] = 0;
2469 buf[11] = 0;
2470 buf[12] = 0;
2471 buf[13] = 0;
2472 buf[14] = 0;
2473 buf[15] = 0;
2474 buf[16] = 0;
2475 buf[17] = 0;
2476 buf[18] = 0;
2477 buf[19] = 0;
2478 buf[20] = 0;
2479 buf[21] = 0;
2480 buf[22] = 0;
2481 buf[23] = 0;
2482 buf[24] = 0;
2483
2484 FAILED(!compiler, "cannot create compiler\n");
2485 sljit_emit_enter(compiler, 0, 1, 5, 5, 0, 0, 0);
2486
2487 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_IMM, -187);
2488 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
2489 sljit_emit_op1(compiler, SLJIT_MOVU_S8, SLJIT_R0, 0, SLJIT_IMM, -605);
2490 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2491 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R0, 0, SLJIT_IMM, -56);
2492 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2493 sljit_emit_op1(compiler, SLJIT_MOVU_U8, SLJIT_R4, 0, SLJIT_IMM, 0xcde5);
2494 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R4, 0);
2495
2496 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_IMM, -45896);
2497 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2498 sljit_emit_op1(compiler, SLJIT_MOVU_S16, SLJIT_R0, 0, SLJIT_IMM, -1472797);
2499 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2500 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R0, 0, SLJIT_IMM, -12890);
2501 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2502 sljit_emit_op1(compiler, SLJIT_MOVU_U16, SLJIT_R4, 0, SLJIT_IMM, 0x9cb0a6);
2503 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R4, 0);
2504
2505 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2506 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-3580429715));
2507 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2508 sljit_emit_op1(compiler, SLJIT_MOVU_S32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-100722768662));
2509 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2510 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-1457052677972));
2511 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2512 sljit_emit_op1(compiler, SLJIT_MOVU_U32, SLJIT_R4, 0, SLJIT_IMM, SLJIT_W(0xcef97a70b5));
2513 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R4, 0);
2514 #else
2515 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 4 * sizeof(sljit_uw));
2516 #endif
2517
2518 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -187);
2519 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_R1, 0);
2520 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2521 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -605);
2522 sljit_emit_op1(compiler, SLJIT_MOVU_S8, SLJIT_R0, 0, SLJIT_S2, 0);
2523 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2524 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -56);
2525 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R0, 0, SLJIT_R2, 0);
2526 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2527 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0xcde5);
2528 sljit_emit_op1(compiler, SLJIT_MOVU_U8, SLJIT_R4, 0, SLJIT_R3, 0);
2529 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R4, 0);
2530
2531 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -45896);
2532 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_R1, 0);
2533 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2534 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -1472797);
2535 sljit_emit_op1(compiler, SLJIT_MOVU_S16, SLJIT_R0, 0, SLJIT_S2, 0);
2536 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2537 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -12890);
2538 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R0, 0, SLJIT_R2, 0);
2539 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2540 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0x9cb0a6);
2541 sljit_emit_op1(compiler, SLJIT_MOVU_U16, SLJIT_R4, 0, SLJIT_R3, 0);
2542 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R4, 0);
2543
2544 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2545 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(-3580429715));
2546 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R1, 0);
2547 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2548 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, SLJIT_W(-100722768662));
2549 sljit_emit_op1(compiler, SLJIT_MOVU_S32, SLJIT_R0, 0, SLJIT_S2, 0);
2550 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2551 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, SLJIT_W(-1457052677972));
2552 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R2, 0);
2553 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2554 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_W(0xcef97a70b5));
2555 sljit_emit_op1(compiler, SLJIT_MOVU_U32, SLJIT_R4, 0, SLJIT_R3, 0);
2556 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R4, 0);
2557 #else
2558 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 4 * sizeof(sljit_uw));
2559 #endif
2560
2561 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, 0x9faa5);
2562 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_S2, 0, SLJIT_S2, 0);
2563 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_S2, 0);
2564
2565 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2566
2567 code.code = sljit_generate_code(compiler);
2568 CHECK(compiler);
2569 sljit_free_compiler(compiler);
2570
2571 code.func1((sljit_sw)&buf);
2572 FAILED(buf[0] != 69, "test29 case 1 failed\n");
2573 FAILED(buf[1] != -93, "test29 case 2 failed\n");
2574 FAILED(buf[2] != 200, "test29 case 3 failed\n");
2575 FAILED(buf[3] != 0xe5, "test29 case 4 failed\n");
2576 FAILED(buf[4] != 19640, "test29 case 5 failed\n");
2577 FAILED(buf[5] != -31005, "test29 case 6 failed\n");
2578 FAILED(buf[6] != 52646, "test29 case 7 failed\n");
2579 FAILED(buf[7] != 0xb0a6, "test29 case 8 failed\n");
2580
2581 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2582 FAILED(buf[8] != SLJIT_W(714537581), "test29 case 9 failed\n");
2583 FAILED(buf[9] != SLJIT_W(-1938520854), "test29 case 10 failed\n");
2584 FAILED(buf[10] != SLJIT_W(3236202668), "test29 case 11 failed\n");
2585 FAILED(buf[11] != SLJIT_W(0xf97a70b5), "test29 case 12 failed\n");
2586 #endif
2587
2588 FAILED(buf[12] != 69, "test29 case 13 failed\n");
2589 FAILED(buf[13] != -93, "test29 case 14 failed\n");
2590 FAILED(buf[14] != 200, "test29 case 15 failed\n");
2591 FAILED(buf[15] != 0xe5, "test29 case 16 failed\n");
2592 FAILED(buf[16] != 19640, "test29 case 17 failed\n");
2593 FAILED(buf[17] != -31005, "test29 case 18 failed\n");
2594 FAILED(buf[18] != 52646, "test29 case 19 failed\n");
2595 FAILED(buf[19] != 0xb0a6, "test29 case 20 failed\n");
2596
2597 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2598 FAILED(buf[20] != SLJIT_W(714537581), "test29 case 21 failed\n");
2599 FAILED(buf[21] != SLJIT_W(-1938520854), "test29 case 22 failed\n");
2600 FAILED(buf[22] != SLJIT_W(3236202668), "test29 case 23 failed\n");
2601 FAILED(buf[23] != SLJIT_W(0xf97a70b5), "test29 case 24 failed\n");
2602 #endif
2603
2604 FAILED(buf[24] != -91, "test29 case 25 failed\n");
2605
2606 sljit_free_code(code.code);
2607 successful_tests++;
2608 }
2609
2610 static void test30(void)
2611 {
2612 /* Test unused results. */
2613 executable_code code;
2614 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2615 sljit_sw buf[1];
2616
2617 if (verbose)
2618 printf("Run test30\n");
2619
2620 FAILED(!compiler, "cannot create compiler\n");
2621 buf[0] = 0;
2622 sljit_emit_enter(compiler, 0, 1, 5, 5, 0, 0, 0);
2623
2624 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2625 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
2626 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 1);
2627 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 1);
2628 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, 1);
2629 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2630 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S1, 0, SLJIT_IMM, SLJIT_W(-0x123ffffffff));
2631 #else
2632 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S1, 0, SLJIT_IMM, 1);
2633 #endif
2634 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, 1);
2635 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, 1);
2636 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_IMM, 1);
2637
2638 /* Some calculations with unused results. */
2639 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_UNUSED, 0, SLJIT_R2, 0);
2640 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_UNUSED, 0, SLJIT_R1, 0);
2641 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0);
2642 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0);
2643 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_GREATER_EQUAL, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0);
2644 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_UNUSED, 0, SLJIT_S0, 0, SLJIT_MEM1(SLJIT_S0), 0);
2645 sljit_emit_op2(compiler, SLJIT_SHL | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_S3, 0, SLJIT_R2, 0);
2646 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 5);
2647 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0xff);
2648 sljit_emit_op1(compiler, SLJIT_NOT32 | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_S1, 0);
2649
2650 /* Testing that any change happens. */
2651 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2652 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R2, 0);
2653 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R3, 0);
2654 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R4, 0);
2655 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_S1, 0, SLJIT_S1, 0);
2656 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S1, 0);
2657 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S2, 0);
2658 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S3, 0);
2659 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0, SLJIT_S4, 0);
2660
2661 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2662
2663 code.code = sljit_generate_code(compiler);
2664 CHECK(compiler);
2665 sljit_free_compiler(compiler);
2666
2667 code.func1((sljit_sw)&buf);
2668 FAILED(buf[0] != 9, "test30 case 1 failed\n");
2669
2670 sljit_free_code(code.code);
2671 successful_tests++;
2672 }
2673
2674 static void test31(void)
2675 {
2676 /* Integer mul and set flags. */
2677 executable_code code;
2678 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2679 sljit_sw buf[12];
2680 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2681 sljit_sw big_word = SLJIT_W(0x7fffffff00000000);
2682 sljit_sw big_word2 = SLJIT_W(0x7fffffff00000012);
2683 #else
2684 sljit_sw big_word = 0x7fffffff;
2685 sljit_sw big_word2 = 0x00000012;
2686 #endif
2687
2688 if (verbose)
2689 printf("Run test31\n");
2690
2691 buf[0] = 3;
2692 buf[1] = 3;
2693 buf[2] = 3;
2694 buf[3] = 3;
2695 buf[4] = 3;
2696 buf[5] = 3;
2697 buf[6] = 3;
2698 buf[7] = 3;
2699 buf[8] = 3;
2700 buf[9] = 3;
2701 buf[10] = 3;
2702 buf[11] = 3;
2703
2704 FAILED(!compiler, "cannot create compiler\n");
2705
2706 sljit_emit_enter(compiler, 0, 1, 3, 5, 0, 0, 0);
2707 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
2708 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_NOT_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_IMM, -45);
2709 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MUL_NOT_OVERFLOW);
2710 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_IMM, -45);
2711 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MUL_OVERFLOW);
2712
2713 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, big_word);
2714 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, -2);
2715 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 33); /* Should not change flags. */
2716 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0); /* Should not change flags. */
2717 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_MUL_OVERFLOW);
2718 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_NOT_OVERFLOW, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, -2);
2719 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_MUL_NOT_OVERFLOW);
2720
2721 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S3, 0, SLJIT_IMM, 0x3f6b0);
2722 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S4, 0, SLJIT_IMM, 0x2a783);
2723 sljit_emit_op2(compiler, SLJIT_MUL32 | SLJIT_SET_MUL_OVERFLOW, SLJIT_R1, 0, SLJIT_S3, 0, SLJIT_S4, 0);
2724 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_MUL_OVERFLOW32);
2725 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R1, 0);
2726
2727 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, big_word2);
2728 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R2, 0, SLJIT_R1, 0);
2729 sljit_emit_op2(compiler, SLJIT_MUL32 | SLJIT_SET_MUL_OVERFLOW, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 23);
2730 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_MUL_OVERFLOW32);
2731
2732 sljit_emit_op2(compiler, SLJIT_MUL32 | SLJIT_SET_MUL_NOT_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -23);
2733 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_MUL_NOT_OVERFLOW32);
2734 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_NOT_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -23);
2735 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_MUL_NOT_OVERFLOW);
2736
2737 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 67);
2738 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, -23);
2739 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R1, 0);
2740
2741 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2742
2743 code.code = sljit_generate_code(compiler);
2744 CHECK(compiler);
2745 sljit_free_compiler(compiler);
2746
2747 code.func1((sljit_sw)&buf);
2748
2749 FAILED(buf[0] != 1, "test31 case 1 failed\n");
2750 FAILED(buf[1] != 2, "test31 case 2 failed\n");
2751 /* Qemu issues for 64 bit muls. */
2752 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2753 FAILED(buf[2] != 1, "test31 case 3 failed\n");
2754 FAILED(buf[3] != 2, "test31 case 4 failed\n");
2755 #endif
2756 FAILED(buf[4] != 1, "test31 case 5 failed\n");
2757 FAILED((buf[5] & 0xffffffff) != 0x85540c10, "test31 case 6 failed\n");
2758 FAILED(buf[6] != 2, "test31 case 7 failed\n");
2759 FAILED(buf[7] != 1, "test31 case 8 failed\n");
2760 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2761 FAILED(buf[8] != 1, "test31 case 9 failed\n");
2762 #endif
2763 FAILED(buf[9] != -1541, "test31 case 10 failed\n");
2764
2765 sljit_free_code(code.code);
2766 successful_tests++;
2767 }
2768
2769 static void test32(void)
2770 {
2771 /* Floating point set flags. */
2772 executable_code code;
2773 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2774
2775 sljit_sw buf[16];
2776 union {
2777 sljit_f64 value;
2778 struct {
2779 sljit_s32 value1;
2780 sljit_s32 value2;
2781 } u;
2782 } dbuf[4];
2783
2784 if (verbose)
2785 printf("Run test32\n");
2786
2787 buf[0] = 5;
2788 buf[1] = 5;
2789 buf[2] = 5;
2790 buf[3] = 5;
2791 buf[4] = 5;
2792 buf[5] = 5;
2793 buf[6] = 5;
2794 buf[7] = 5;
2795 buf[8] = 5;
2796 buf[9] = 5;
2797 buf[10] = 5;
2798 buf[11] = 5;
2799 buf[12] = 5;
2800 buf[13] = 5;
2801 buf[14] = 5;
2802 buf[15] = 5;
2803
2804 /* Two NaNs */
2805 dbuf[0].u.value1 = 0x7fffffff;
2806 dbuf[0].u.value2 = 0x7fffffff;
2807 dbuf[1].u.value1 = 0x7fffffff;
2808 dbuf[1].u.value2 = 0x7fffffff;
2809 dbuf[2].value = -13.0;
2810 dbuf[3].value = 27.0;
2811
2812 if (!sljit_is_fpu_available()) {
2813 if (verbose)
2814 printf("no fpu available, test32 skipped\n");
2815 successful_tests++;
2816 if (compiler)
2817 sljit_free_compiler(compiler);
2818 return;
2819 }
2820
2821 FAILED(!compiler, "cannot create compiler\n");
2822 SLJIT_ASSERT(sizeof(sljit_f64) == 8 && sizeof(sljit_s32) == 4 && sizeof(dbuf[0]) == 8);
2823
2824 sljit_emit_enter(compiler, 0, 2, 1, 2, 4, 0, 0);
2825
2826 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
2827 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
2828 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f64));
2829 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_UNORDERED_F64);
2830 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_ORDERED_F, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
2831 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_ORDERED_F64);
2832
2833 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64));
2834 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2835 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_UNORDERED_F64);
2836 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_ORDERED_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2837 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_ORDERED_F64);
2838 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2839 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_LESS_F64);
2840 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2841 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_GREATER_EQUAL_F64);
2842 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2843 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_GREATER_F64);
2844 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_LESS_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2845 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_LESS_EQUAL_F64);
2846 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2847 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
2848 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_NOT_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2849 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_NOT_EQUAL_F64);
2850
2851 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64));
2852 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR3, 0, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64));
2853 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_UNORDERED_F64);
2854 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64));
2855 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
2856
2857 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_ORDERED_F, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64), SLJIT_FR0, 0);
2858 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_ORDERED_F64);
2859
2860 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_FR3, 0, SLJIT_FR2, 0);
2861 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 0);
2862 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_UNORDERED_F64);
2863
2864 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2865
2866 code.code = sljit_generate_code(compiler);
2867 CHECK(compiler);
2868 sljit_free_compiler(compiler);
2869
2870 code.func2((sljit_sw)&buf, (sljit_sw)&dbuf);
2871
2872 FAILED(buf[0] != 1, "test32 case 1 failed\n");
2873 FAILED(buf[1] != 2, "test32 case 2 failed\n");
2874 FAILED(buf[2] != 2, "test32 case 3 failed\n");
2875 FAILED(buf[3] != 1, "test32 case 4 failed\n");
2876 FAILED(buf[4] != 1, "test32 case 5 failed\n");
2877 FAILED(buf[5] != 2, "test32 case 6 failed\n");
2878 FAILED(buf[6] != 2, "test32 case 7 failed\n");
2879 FAILED(buf[7] != 1, "test32 case 8 failed\n");
2880 FAILED(buf[8] != 2, "test32 case 9 failed\n");
2881 FAILED(buf[9] != 1, "test32 case 10 failed\n");
2882 FAILED(buf[10] != 2, "test32 case 11 failed\n");
2883 FAILED(buf[11] != 1, "test32 case 12 failed\n");
2884 FAILED(buf[12] != 2, "test32 case 13 failed\n");
2885 FAILED(buf[13] != 1, "test32 case 14 failed\n");
2886
2887 sljit_free_code(code.code);
2888 successful_tests++;
2889 }
2890
2891 static void test33(void)
2892 {
2893 /* Test setting multiple flags. */
2894 executable_code code;
2895 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2896 struct sljit_jump* jump;
2897 sljit_sw buf[10];
2898
2899 if (verbose)
2900 printf("Run test33\n");
2901
2902 buf[0] = 3;
2903 buf[1] = 3;
2904 buf[2] = 3;
2905 buf[3] = 3;
2906 buf[4] = 3;
2907 buf[5] = 3;
2908 buf[6] = 3;
2909 buf[7] = 3;
2910 buf[8] = 3;
2911 buf[9] = 3;
2912
2913 FAILED(!compiler, "cannot create compiler\n");
2914
2915 sljit_emit_enter(compiler, 0, 1, 3, 3, 0, 0, 0);
2916
2917 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 20);
2918 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 10);
2919 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2920 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_UNUSED, 0, SLJIT_ZERO);
2921 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -10);
2922 jump = sljit_emit_jump(compiler, SLJIT_LESS);
2923 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 11);
2924 sljit_set_label(jump, sljit_emit_label(compiler));
2925
2926 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_SIG_GREATER, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2927 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_SIG_GREATER);
2928 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_IMM, 45);
2929 jump = sljit_emit_jump(compiler, SLJIT_NOT_EQUAL);
2930 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_IMM, 55);
2931 sljit_set_label(jump, sljit_emit_label(compiler));
2932
2933 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2934 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x8000000000000000));
2935 #else
2936 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x80000000));
2937 #endif
2938 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
2939 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_NOT_OVERFLOW, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2940 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_IMM, 33);
2941 jump = sljit_emit_jump(compiler, SLJIT_NOT_OVERFLOW);
2942 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_ZERO);
2943 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_IMM, 13);
2944 sljit_set_label(jump, sljit_emit_label(compiler));
2945
2946 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x80000000));
2947 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R0, 0);
2948 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2949 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 0);
2950 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_NOT_ZERO);
2951 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, 78);
2952 jump = sljit_emit_jump(compiler, SLJIT_OVERFLOW32);
2953 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, 48);
2954 sljit_set_label(jump, sljit_emit_label(compiler));
2955
2956 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2957 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x8000000000000000));
2958 #else
2959 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x80000000));
2960 #endif
2961 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_R0, 0);
2962 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_Z | SLJIT_SET_NOT_OVERFLOW, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2963 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_IMM, 30);
2964 jump = sljit_emit_jump(compiler, SLJIT_NOT_OVERFLOW);
2965 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_IMM, 50);
2966 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_ZERO);
2967 sljit_set_label(jump, sljit_emit_label(compiler));
2968
2969 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2970
2971 code.code = sljit_generate_code(compiler);
2972 CHECK(compiler);
2973 sljit_free_compiler(compiler);
2974
2975 code.func1((sljit_sw)&buf);
2976
2977 FAILED(buf[0] != 0, "test33 case 1 failed\n");
2978 FAILED(buf[1] != 11, "test33 case 2 failed\n");
2979 FAILED(buf[2] != 1, "test33 case 3 failed\n");
2980 FAILED(buf[3] != 45, "test33 case 4 failed\n");
2981 FAILED(buf[4] != 13, "test33 case 5 failed\n");
2982 FAILED(buf[5] != 0, "test33 case 6 failed\n");
2983 FAILED(buf[6] != 0, "test33 case 7 failed\n");
2984 FAILED(buf[7] != 48, "test33 case 8 failed\n");
2985 FAILED(buf[8] != 50, "test33 case 9 failed\n");
2986 FAILED(buf[9] != 1, "test33 case 10 failed\n");
2987
2988 sljit_free_code(code.code);
2989 successful_tests++;
2990 }
2991
2992 static void test34(void)
2993 {
2994 /* Test fast calls. */
2995 executable_code codeA;
2996 executable_code codeB;
2997 executable_code codeC;
2998 executable_code codeD;
2999 executable_code codeE;
3000 executable_code codeF;
3001 struct sljit_compiler* compiler;
3002 struct sljit_jump *jump;
3003 struct sljit_label* label;
3004 sljit_uw addr;
3005 sljit_p buf[2];
3006
3007 if (verbose)
3008 printf("Run test34\n");
3009
3010 buf[0] = 0;
3011 buf[1] = 0;
3012
3013 /* A */
3014 compiler = sljit_create_compiler(NULL);
3015 FAILED(!compiler, "cannot create compiler\n");
3016 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3017
3018 sljit_emit_fast_enter(compiler, SLJIT_R1, 0);
3019 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 4);
3020 sljit_emit_fast_return(compiler, SLJIT_R1, 0);
3021
3022 codeA.code = sljit_generate_code(compiler);
3023 CHECK(compiler);
3024 sljit_free_compiler(compiler);
3025
3026 /* B */
3027 compiler = sljit_create_compiler(NULL);
3028 FAILED(!compiler, "cannot create compiler\n");
3029 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3030
3031 sljit_emit_fast_enter(compiler, SLJIT_R4, 0);
3032 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 6);
3033 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeA.code));
3034 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_R1, 0);
3035 sljit_emit_fast_return(compiler, SLJIT_R4, 0);
3036
3037 codeB.code = sljit_generate_code(compiler);
3038 CHECK(compiler);
3039 sljit_free_compiler(compiler);
3040
3041 /* C */
3042 compiler = sljit_create_compiler(NULL);
3043 FAILED(!compiler, "cannot create compiler\n");
3044 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3045
3046 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_p));
3047 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
3048 jump = sljit_emit_jump(compiler, SLJIT_FAST_CALL | SLJIT_REWRITABLE_JUMP);
3049 sljit_set_target(jump, SLJIT_FUNC_OFFSET(codeB.code));
3050 sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_p));
3051
3052 codeC.code = sljit_generate_code(compiler);
3053 CHECK(compiler);
3054 sljit_free_compiler(compiler);
3055
3056 /* D */
3057 compiler = sljit_create_compiler(NULL);
3058 FAILED(!compiler, "cannot create compiler\n");
3059 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3060
3061 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SP), 0);
3062 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 10);
3063 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeC.code));
3064 sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_SP), 0);
3065
3066 codeD.code = sljit_generate_code(compiler);
3067 CHECK(compiler);
3068 sljit_free_compiler(compiler);
3069
3070 /* E */
3071 compiler = sljit_create_compiler(NULL);
3072 FAILED(!compiler, "cannot create compiler\n");
3073 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3074
3075 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_S0), 0);
3076 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 12);
3077 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_p), SLJIT_IMM, SLJIT_FUNC_OFFSET(codeD.code));
3078 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_p));
3079 sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_S0), 0);
3080
3081 codeE.code = sljit_generate_code(compiler);
3082 CHECK(compiler);
3083 sljit_free_compiler(compiler);
3084
3085 /* F */
3086 compiler = sljit_create_compiler(NULL);
3087 FAILED(!compiler, "cannot create compiler\n");
3088
3089 sljit_emit_enter(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3090 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3091 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeE.code));
3092 label = sljit_emit_label(compiler);
3093 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
3094
3095 codeF.code = sljit_generate_code(compiler);
3096 CHECK(compiler);
3097 addr = sljit_get_label_addr(label);
3098 sljit_free_compiler(compiler);
3099
3100 FAILED(codeF.func1((sljit_sw)&buf) != 40, "test34 case 1 failed\n");
3101 FAILED(buf[0] != addr - SLJIT_RETURN_ADDRESS_OFFSET, "test34 case 2 failed\n");
3102
3103 sljit_free_code(codeA.code);
3104 sljit_free_code(codeB.code);
3105 sljit_free_code(codeC.code);
3106 sljit_free_code(codeD.code);
3107 sljit_free_code(codeE.code);
3108 sljit_free_code(codeF.code);
3109 successful_tests++;
3110 }
3111
3112 static void test35(void)
3113 {
3114 /* More complicated tests for fast calls. */
3115 executable_code codeA;
3116 executable_code codeB;
3117 executable_code codeC;
3118 struct sljit_compiler* compiler;
3119 struct sljit_jump *jump = NULL;
3120 struct sljit_label* label;
3121 sljit_sw executable_offset;
3122 sljit_uw return_addr;
3123 sljit_uw jump_addr = 0;
3124 sljit_p buf[1];
3125
3126 if (verbose)
3127 printf("Run test35\n");
3128
3129 buf[0] = 0;
3130
3131 /* A */
3132 compiler = sljit_create_compiler(NULL);
3133 FAILED(!compiler, "cannot create compiler\n");
3134 sljit_set_context(compiler, 0, 0, 2, 2, 0, 0, 0);
3135
3136 sljit_emit_fast_enter(compiler, SLJIT_MEM0(), (sljit_sw)&buf[0]);
3137 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 5);
3138
3139 jump = sljit_emit_jump(compiler, SLJIT_FAST_CALL | SLJIT_REWRITABLE_JUMP);
3140 sljit_set_target(jump, 0);
3141
3142 label = sljit_emit_label(compiler);
3143 sljit_emit_fast_return(compiler, SLJIT_MEM0(), (sljit_sw)&buf[0]);
3144
3145 codeA.code = sljit_generate_code(compiler);
3146 CHECK(compiler);
3147 return_addr = sljit_get_label_addr(label) - SLJIT_RETURN_ADDRESS_OFFSET;
3148 executable_offset = sljit_get_executable_offset(compiler);
3149 jump_addr = sljit_get_jump_addr(jump);
3150 sljit_free_compiler(compiler);
3151
3152 /* B */
3153 compiler = sljit_create_compiler(NULL);
3154 FAILED(!compiler, "cannot create compiler\n");
3155 sljit_set_context(compiler, 0, 0, 2, 2, 0, 0, 0);
3156
3157 sljit_emit_fast_enter(compiler, SLJIT_UNUSED, 0);
3158 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 7);
3159 sljit_emit_fast_return(compiler, SLJIT_IMM, return_addr);
3160
3161 codeB.code = sljit_generate_code(compiler);
3162 CHECK(compiler);
3163 sljit_free_compiler(compiler);
3164
3165 sljit_set_jump_addr(jump_addr, SLJIT_FUNC_OFFSET(codeB.code), executable_offset);
3166
3167 /* C */
3168 compiler = sljit_create_compiler(NULL);
3169 FAILED(!compiler, "cannot create compiler\n");
3170
3171 sljit_emit_enter(compiler, 0, 0, 2, 2, 0, 0, 0);
3172 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3173 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeA.code));
3174 label = sljit_emit_label(compiler);
3175 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
3176
3177 codeC.code = sljit_generate_code(compiler);
3178 CHECK(compiler);
3179 return_addr = sljit_get_label_addr(label);
3180 sljit_free_compiler(compiler);
3181
3182 FAILED(codeC.func0() != 12, "test35 case 1 failed\n");
3183 FAILED(buf[0] != return_addr - SLJIT_RETURN_ADDRESS_OFFSET, "test35 case 2 failed\n");
3184
3185 sljit_free_code(codeA.code);
3186 sljit_free_code(codeB.code);
3187 sljit_free_code(codeC.code);
3188 successful_tests++;
3189 }
3190
3191 static sljit_s32 cmp_test(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src1, sljit_sw src1w, sljit_s32 src2, sljit_sw src2w)
3192 {
3193 /* 2 = true, 1 = false */
3194 struct sljit_jump* jump;
3195 struct sljit_label* label;
3196
3197 if (sljit_emit_op1(compiler, SLJIT_MOVU_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_IMM, 2))
3198 return compiler->error;
3199 jump = sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w);
3200 if (!jump)
3201 return compiler->error;
3202 if (sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 1))
3203 return compiler->error;
3204 label = sljit_emit_label(compiler);
3205 if (!label)
3206 return compiler->error;
3207 sljit_set_label(jump, label);
3208 return SLJIT_SUCCESS;
3209 }
3210
3211 #define TEST_CASES (7 + 10 + 12 + 11 + 4)
3212 static void test36(void)
3213 {
3214 /* Compare instruction. */
3215 executable_code code;
3216 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3217
3218 sljit_s8 buf[TEST_CASES];
3219 sljit_s8 compare_buf[TEST_CASES] = {
3220 1, 1, 2, 2, 1, 2, 2,
3221 1, 1, 2, 2, 2, 1, 2, 2, 1, 1,
3222 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2,
3223 2, 1, 2, 1, 1, 1, 2, 1, 2, 1, 2,
3224 2, 1, 1, 2
3225 };
3226 sljit_sw data[4];
3227 sljit_s32 i;
3228
3229 if (verbose)
3230 printf("Run test36\n");
3231
3232 FAILED(!compiler, "cannot create compiler\n");
3233 for (i = 0; i < TEST_CASES; ++i)
3234 buf[i] = 100;
3235 data[0] = 32;
3236 data[1] = -9;
3237 data[2] = 43;
3238 data[3] = -13;
3239
3240 sljit_emit_enter(compiler, 0, 2, 3, 2, 0, 0, 0);
3241 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
3242
3243 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 13);
3244 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 15);
3245 cmp_test(compiler, SLJIT_EQUAL, SLJIT_IMM, 9, SLJIT_R0, 0);
3246 cmp_test(compiler, SLJIT_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3247 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3);
3248 cmp_test(compiler, SLJIT_EQUAL, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_IMM, -13);
3249 cmp_test(compiler, SLJIT_NOT_EQUAL, SLJIT_IMM, 0, SLJIT_R0, 0);
3250 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3251 cmp_test(compiler, SLJIT_NOT_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 0, SLJIT_R0, 0);
3252 cmp_test(compiler, SLJIT_EQUAL, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT);
3253 cmp_test(compiler, SLJIT_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_R0, 0, SLJIT_IMM, 0);
3254
3255 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, 0);
3256 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -8);
3257 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3258 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_R0, 0, SLJIT_IMM, 0);
3259 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 0);
3260 cmp_test(compiler, SLJIT_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_R0, 0, SLJIT_IMM, 0);
3261 cmp_test(compiler, SLJIT_SIG_GREATER_EQUAL, SLJIT_R1, 0, SLJIT_IMM, 0);
3262 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw));
3263 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_IMM, 0, SLJIT_R1, 0);
3264 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw));
3265 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw));
3266 cmp_test(compiler, SLJIT_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw));
3267
3268 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
3269 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3270 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw));
3271 cmp_test(compiler, SLJIT_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 8);
3272 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_IMM, -10);
3273 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_IMM, 8);
3274 cmp_test(compiler, SLJIT_GREATER_EQUAL, SLJIT_IMM, 8, SLJIT_R1, 0);
3275 cmp_test(compiler, SLJIT_GREATER_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 8, SLJIT_R1, 0);
3276 cmp_test(compiler, SLJIT_GREATER, SLJIT_IMM, 8, SLJIT_R1, 0);
3277 cmp_test(compiler, SLJIT_LESS_EQUAL, SLJIT_IMM, 7, SLJIT_R0, 0);
3278 cmp_test(compiler, SLJIT_GREATER, SLJIT_IMM, 1, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw));
3279 cmp_test(compiler, SLJIT_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3280 cmp_test(compiler, SLJIT_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
3281 cmp_test(compiler, SLJIT_GREATER | SLJIT_REWRITABLE_JUMP, SLJIT_R0, 0, SLJIT_R1, 0);
3282
3283 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -3);
3284 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3285 cmp_test(compiler, SLJIT_SIG_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3286 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_R0, 0, SLJIT_IMM, -1);
3287 cmp_test(compiler, SLJIT_SIG_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 1);
3288 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, -1);
3289 cmp_test(compiler, SLJIT_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, -1);
3290 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3291 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
3292 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_IMM, -4, SLJIT_R0, 0);
3293 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_IMM, -1, SLJIT_R1, 0);
3294 cmp_test(compiler, SLJIT_SIG_GREATER | SLJIT_REWRITABLE_JUMP, SLJIT_R1, 0, SLJIT_IMM, -1);
3295
3296 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3297 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xf00000004));
3298 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R0, 0);
3299 cmp_test(compiler, SLJIT_LESS32, SLJIT_R1, 0, SLJIT_IMM, 5);
3300 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_IMM, 5);
3301 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xff0000004));
3302 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R0, 0);
3303 cmp_test(compiler, SLJIT_SIG_GREATER32, SLJIT_R1, 0, SLJIT_IMM, 5);
3304 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_R0, 0, SLJIT_IMM, 5);
3305 #else
3306 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 4);
3307 cmp_test(compiler, SLJIT_LESS32, SLJIT_R0, 0, SLJIT_IMM, 5);
3308 cmp_test(compiler, SLJIT_GREATER32, SLJIT_R0, 0, SLJIT_IMM, 5);
3309 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0xf0000004);
3310 cmp_test(compiler, SLJIT_SIG_GREATER32, SLJIT_R0, 0, SLJIT_IMM, 5);
3311 cmp_test(compiler, SLJIT_SIG_LESS32, SLJIT_R0, 0, SLJIT_IMM, 5);
3312 #endif
3313
3314 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3315
3316 code.code = sljit_generate_code(compiler);
3317 CHECK(compiler);
3318 sljit_free_compiler(compiler);
3319
3320 code.func2((sljit_sw)&buf, (sljit_sw)&data);
3321
3322 for (i = 0; i < TEST_CASES; ++i)
3323 if (SLJIT_UNLIKELY(buf[i] != compare_buf[i])) {
3324 printf("test36 case %d failed\n", i + 1);
3325 return;
3326 }
3327
3328 sljit_free_code(code.code);
3329 successful_tests++;
3330 }
3331 #undef TEST_CASES
3332
3333 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3334 #define BITN(n) (SLJIT_W(1) << (63 - (n)))
3335 #define RESN(n) (n)
3336 #else
3337 #define BITN(n) (1 << (31 - ((n) & 0x1f)))
3338 #define RESN(n) ((n) & 0x1f)
3339 #endif
3340
3341 static void test37(void)
3342 {
3343 /* Test count leading zeroes. */
3344 executable_code code;
3345 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3346 sljit_sw buf[15];
3347 sljit_s32 ibuf[2];
3348 sljit_s32 i;
3349
3350 if (verbose)
3351 printf("Run test37\n");
3352
3353 FAILED(!compiler, "cannot create compiler\n");
3354
3355 for (i = 0; i < 15; i++)
3356 buf[i] = -1;
3357 buf[3] = 0;
3358 buf[7] = BITN(13);
3359 ibuf[0] = -1;
3360 ibuf[1] = -1;
3361 sljit_emit_enter(compiler, 0, 2, 1, 2, 0, 0, 0);
3362 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, BITN(27));
3363 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
3364 sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, BITN(47));
3365 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
3366 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_ZERO);
3367 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw));
3368 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
3369 sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0);
3370 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_ZERO);
3371 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R0, 0);
3372 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0);
3373 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_R0, 0);
3374 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
3375 sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0);
3376 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_ZERO);
3377 sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw));
3378 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R0, 0);
3379 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_NOT_ZERO);
3380 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, BITN(58));
3381 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R0, 0);
3382 sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw));
3383 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_NOT_ZERO);
3384 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3385 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
3386 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3387 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xff08a00000));
3388 #else
3389 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x08a00000);
3390 #endif
3391 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32), SLJIT_R0, 0);
3392 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_R0, 0, SLJIT_R0, 0);
3393 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R0, 0);
3394 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3395 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xffc8a00000));
3396 #else
3397 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0xc8a00000);
3398 #endif
3399 sljit_emit_op1(compiler, SLJIT_CLZ32 | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0);
3400 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_ZERO32);
3401 sljit_emit_op1(compiler, SLJIT_CLZ32 | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0);
3402 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R0, 0);
3403
3404 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3405
3406 code.code = sljit_generate_code(compiler);
3407 CHECK(compiler);
3408 sljit_free_compiler(compiler);
3409
3410 code.func2((sljit_sw)&buf, (sljit_sw)&ibuf);
3411 FAILED(buf[0] != RESN(27), "test37 case 1 failed\n");
3412 FAILED(buf[1] != RESN(47), "test37 case 2 failed\n");
3413 FAILED(buf[2] != 0, "test37 case 3 failed\n");
3414 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3415 FAILED(buf[3] != 64, "test37 case 4 failed\n");
3416 #else
3417 FAILED(buf[3] != 32, "test37 case 4 failed\n");
3418 #endif
3419 FAILED(buf[4] != 1, "test37 case 5 failed\n");
3420 FAILED(buf[5] != 0, "test37 case 6 failed\n");
3421 FAILED(ibuf[0] != 32, "test37 case 7 failed\n");
3422 FAILED(buf[6] != 1, "test37 case 8 failed\n");
3423 FAILED(buf[7] != RESN(13), "test37 case 9 failed\n");
3424 #if !(defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3425 FAILED(buf[8] != 1, "test37 case 10 failed\n");
3426 #endif
3427 FAILED(buf[9] != RESN(58), "test37 case 11 failed\n");
3428 FAILED(buf[10] != 0, "test37 case 12 failed\n");
3429 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3430 FAILED(buf[11] != 64, "test37 case 13 failed\n");
3431 #else
3432 FAILED(buf[11] != 32, "test37 case 13 failed\n");
3433 #endif
3434 FAILED(ibuf[1] != 4, "test37 case 14 failed\n");
3435 FAILED((buf[12] & 0xffffffff) != 4, "test37 case 15 failed\n");
3436 FAILED(buf[13] != 1, "test37 case 16 failed\n");
3437 FAILED((buf[14] & 0xffffffff) != 0, "test37 case 17 failed\n");
3438
3439 sljit_free_code(code.code);
3440 successful_tests++;
3441 }
3442 #undef BITN
3443 #undef RESN
3444
3445 static void test38(void)
3446 {
3447 #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)
3448 /* Test stack utility. */
3449 executable_code code;
3450 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3451 struct sljit_jump* alloc1_fail;
3452 struct sljit_jump* alloc2_fail;
3453 struct sljit_jump* alloc3_fail;
3454 struct sljit_jump* sanity1_fail;
3455 struct sljit_jump* sanity2_fail;
3456 struct sljit_jump* jump;
3457 struct sljit_label* label;
3458
3459 if (verbose)
3460 printf("Run test38\n");
3461
3462 FAILED(!compiler, "cannot create compiler\n");
3463
3464 sljit_emit_enter(compiler, 0, 0, 3, 1, 0, 0, 0);
3465
3466 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8192);
3467 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 65536);
3468 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0);
3469 sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_allocate_stack));
3470 alloc1_fail = sljit_emit_cmp(compiler, SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3471 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_RETURN_REG, 0);
3472
3473 /* Write 8k data. */
3474 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, limit), SLJIT_IMM, sizeof(sljit_sw));
3475 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 8192);
3476 label = sljit_emit_label(compiler);
3477 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_sw), SLJIT_IMM, -1);
3478 jump = sljit_emit_cmp(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3479 sljit_set_label(jump, label);
3480
3481 /* Grow stack. */
3482 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
3483 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, base), SLJIT_IMM, 65536);
3484 sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_stack_resize));
3485 alloc2_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3486
3487 /* Write 64k data. */
3488 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, limit), SLJIT_IMM, sizeof(sljit_sw));
3489 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 65536);
3490 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, max_limit), SLJIT_IMM, sizeof(sljit_sw));
3491 sanity1_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, 0, SLJIT_R2, 0);
3492 label = sljit_emit_label(compiler);
3493 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_sw), SLJIT_IMM, -1);
3494 jump = sljit_emit_cmp(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3495 sljit_set_label(jump, label);
3496
3497 /* Shrink stack. */
3498 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
3499 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, base), SLJIT_IMM, 32768);
3500 sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_stack_resize));
3501 alloc3_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3502
3503 /* Write 32k data. */
3504 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, limit), SLJIT_IMM, sizeof(sljit_sw));
3505 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, base), SLJIT_IMM, sizeof(sljit_sw));
3506 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, base), SLJIT_IMM, 32768 + sizeof(sljit_sw));
3507 sanity2_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, 0, SLJIT_R2, 0);
3508 label = sljit_emit_label(compiler);
3509 sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_sw), SLJIT_IMM, -1);
3510 jump = sljit_emit_cmp(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3511 sljit_set_label(jump, label);
3512
3513 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
3514 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3515 sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_free_stack));
3516
3517 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 4567);
3518
3519 label = sljit_emit_label(compiler);
3520 sljit_set_label(alloc1_fail, label);
3521 sljit_set_label(alloc2_fail, label);
3522 sljit_set_label(alloc3_fail, label);
3523 sljit_set_label(sanity1_fail, label);
3524 sljit_set_label(sanity2_fail, label);
3525 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 0);
3526
3527 code.code = sljit_generate_code(compiler);
3528 CHECK(compiler);
3529 sljit_free_compiler(compiler);
3530
3531 /* Just survive this. */
3532 FAILED(code.func0() != 4567, "test38 case 1 failed\n");
3533
3534 sljit_free_code(code.code);
3535 #endif
3536 successful_tests++;
3537 }
3538
3539 static void test39(void)
3540 {
3541 /* Test error handling. */
3542 executable_code code;
3543 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3544 struct sljit_jump* jump;
3545
3546 if (verbose)
3547 printf("Run test39\n");
3548
3549 FAILED(!compiler, "cannot create compiler\n");
3550
3551 /* Such assignment should never happen in a regular program. */
3552 compiler->error = -3967;
3553
3554 SLJIT_ASSERT(sljit_emit_enter(compiler, 0, 2, 5, 5, 6, 0, 32) == -3967);
3555 SLJIT_ASSERT(sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R1, 0) == -3967);
3556 SLJIT_ASSERT(sljit_emit_op0(compiler, SLJIT_NOP) == -3967);
3557 SLJIT_ASSERT(sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1) == -3967);
3558 SLJIT_ASSERT(sljit_emit_op2(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), 64, SLJIT_MEM1(SLJIT_S0), -64) == -3967);
3559 SLJIT_ASSERT(sljit_emit_fop1(compiler, SLJIT_ABS_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_R1), 0) == -3967);
3560 SLJIT_ASSERT(sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_FR2, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_S0), 0, SLJIT_FR2, 0) == -3967);
3561 SLJIT_ASSERT(!sljit_emit_label(compiler));
3562 jump = sljit_emit_jump(compiler, SLJIT_CALL3);
3563 SLJIT_ASSERT(!jump);
3564 sljit_set_label(jump, (struct sljit_label*)0x123450);
3565 sljit_set_target(jump, 0x123450);
3566 jump = sljit_emit_cmp(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3567 SLJIT_ASSERT(!jump);
3568 SLJIT_ASSERT(sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM1(SLJIT_R0), 8) == -3967);
3569 SLJIT_ASSERT(sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_UNUSED, 0, SLJIT_MUL_OVERFLOW) == -3967);
3570 SLJIT_ASSERT(!sljit_emit_const(compiler, SLJIT_R0, 0, 99));
3571
3572 SLJIT_ASSERT(!compiler->labels && !compiler->jumps && !compiler->consts);
3573 SLJIT_ASSERT(!compiler->last_label && !compiler->last_jump && !compiler->last_const);
3574 SLJIT_ASSERT(!compiler->buf->next && !compiler->buf->used_size);
3575 SLJIT_ASSERT(!compiler->abuf->next && !compiler->abuf->used_size);
3576
3577 sljit_set_compiler_memory_error(compiler);
3578 FAILED(sljit_get_compiler_error(compiler) != -3967, "test39 case 1 failed\n");
3579
3580 code.code = sljit_generate_code(compiler);
3581 FAILED(sljit_get_compiler_error(compiler) != -3967, "test39 case 2 failed\n");
3582 FAILED(!!code.code, "test39 case 3 failed\n");
3583 sljit_free_compiler(compiler);
3584
3585 compiler = sljit_create_compiler(NULL);
3586 FAILED(!compiler, "cannot create compiler\n");
3587
3588 FAILED(sljit_get_compiler_error(compiler) != SLJIT_SUCCESS, "test39 case 4 failed\n");
3589 sljit_set_compiler_memory_error(compiler);
3590 FAILED(sljit_get_compiler_error(compiler) != SLJIT_ERR_ALLOC_FAILED, "test39 case 5 failed\n");
3591 sljit_free_compiler(compiler);
3592
3593 successful_tests++;
3594 }
3595
3596 static void test40(void)
3597 {
3598 /* Test emit_op_flags. */
3599 executable_code code;
3600 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3601 sljit_sw buf[10];
3602
3603 if (verbose)
3604 printf("Run test40\n");
3605
3606 FAILED(!compiler, "cannot create compiler\n");
3607 buf[0] = -100;
3608 buf[1] = -100;
3609 buf[2] = -100;
3610 buf[3] = -8;
3611 buf[4] = -100;
3612 buf[5] = -100;
3613 buf[6] = 0;
3614 buf[7] = 0;
3615 buf[8] = -100;
3616 buf[9] = -100;
3617
3618 sljit_emit_enter(compiler, 0, 1, 3, 4, 0, 0, sizeof(sljit_sw));
3619
3620 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -5);
3621 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, SLJIT_IMM, -6, SLJIT_R0, 0);
3622 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x123456);
3623 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_SIG_LESS);
3624 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R1, 0);
3625
3626 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -13);
3627 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_IMM, -13, SLJIT_R0, 0);
3628 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 0);
3629 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_EQUAL);
3630 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_UNUSED, 0, SLJIT_NOT_EQUAL);
3631 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SP), 0);
3632 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_IMM, -13, SLJIT_R0, 0);
3633 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3634 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_EQUAL);
3635 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_UNUSED, 0, SLJIT_EQUAL);
3636
3637 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -13);
3638 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3);
3639 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R1, 0);
3640 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM2(SLJIT_S0, SLJIT_R1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S0, SLJIT_R1), SLJIT_WORD_SHIFT, SLJIT_SIG_LESS);
3641
3642 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -8);
3643 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 33);
3644 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
3645 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, 0);
3646 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_UNUSED, 0, SLJIT_GREATER);
3647 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_EQUAL);
3648 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
3649 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, 0x88);
3650 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_S3, 0, SLJIT_S3, 0, SLJIT_NOT_EQUAL);
3651 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_S1, 0);
3652 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_S3, 0);
3653
3654 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x84);
3655 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_IMM, 0x180, SLJIT_R0, 0);
3656 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_EQUAL);
3657 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_EQUAL);
3658
3659 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
3660 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
3661 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_NOT_EQUAL);
3662 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_UNUSED, 0, SLJIT_NOT_EQUAL);
3663
3664 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x123456);
3665 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
3666 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_GREATER);
3667 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_R0, 0);
3668
3669 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 0xbaddead);
3670 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0);
3671
3672 code.code = sljit_generate_code(compiler);
3673 CHECK(compiler);
3674 sljit_free_compiler(compiler);
3675
3676 FAILED(code.func1((sljit_sw)&buf) != 0xbaddead, "test40 case 1 failed\n");
3677 FAILED(buf[0] != 0x123457, "test40 case 2 failed\n");
3678 FAILED(buf[1] != 1, "test40 case 3 failed\n");
3679 FAILED(buf[2] != 0, "test40 case 4 failed\n");
3680 FAILED(buf[3] != -7, "test40 case 5 failed\n");
3681 FAILED(buf[4] != 0, "test40 case 6 failed\n");
3682 FAILED(buf[5] != 0x89, "test40 case 7 failed\n");
3683 FAILED(buf[6] != 0, "test40 case 8 failed\n");
3684 FAILED(buf[7] != 1, "test40 case 9 failed\n");
3685 FAILED(buf[8] != 1, "test40 case 10 failed\n");
3686 FAILED(buf[9] != 0x123457, "test40 case 11 failed\n");
3687
3688 sljit_free_code(code.code);
3689 successful_tests++;
3690 }
3691
3692 static void test41(void)
3693 {
3694 /* Test inline assembly. */
3695 executable_code code;
3696 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3697 sljit_s32 i;
3698 sljit_f64 buf[3];
3699 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3700 sljit_u8 inst[16];
3701 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3702 sljit_u8 inst[16];
3703 sljit_s32 reg;
3704 #else
3705 sljit_u32 inst;
3706 #endif
3707
3708 if (verbose)
3709 printf("Run test41\n");
3710
3711 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
3712 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3713 if (SLJIT_R(i) >= SLJIT_R3 && SLJIT_R(i) <= SLJIT_R8) {
3714 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i)) == -1);
3715 continue;
3716 }
3717 #endif
3718 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i)) >= 0 && sljit_get_register_index(SLJIT_R(i)) < 64);
3719 }
3720
3721 FAILED(!compiler, "cannot create compiler\n");
3722 sljit_emit_enter(compiler, 0, 2, 3, 3, 0, 0, 0);
3723
3724 /* Returns with the sum of SLJIT_S0 and SLJIT_S1. */
3725 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3726 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3727 inst[0] = 0x48;
3728 inst[1] = 0x8d;
3729 inst[2] = 0x04 | ((sljit_get_register_index(SLJIT_RETURN_REG) & 0x7) << 3);
3730 inst[3] = (sljit_get_register_index(SLJIT_S0) & 0x7)
3731 | ((sljit_get_register_index(SLJIT_S1) & 0x7) << 3);
3732 sljit_emit_op_custom(compiler, inst, 4);
3733 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3734 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3735 inst[0] = 0x48; /* REX_W */
3736 inst[1] = 0x8d;
3737 inst[2] = 0x04;
3738 reg = sljit_get_register_index(SLJIT_RETURN_REG);
3739 inst[2] |= ((reg & 0x7) << 3);
3740 if (reg > 7)
3741 inst[0] |= 0x04; /* REX_R */
3742 reg = sljit_get_register_index(SLJIT_S0);
3743 inst[3] = reg & 0x7;
3744 if (reg > 7)
3745 inst[0] |= 0x01; /* REX_B */
3746 reg = sljit_get_register_index(SLJIT_S1);
3747 inst[3] |= (reg & 0x7) << 3;
3748 if (reg > 7)
3749 inst[0] |= 0x02; /* REX_X */
3750 sljit_emit_op_custom(compiler, inst, 4);
3751 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
3752 /* add rd, rn, rm */
3753 inst = 0xe0800000 | (sljit_get_register_index(SLJIT_RETURN_REG) << 12)
3754 | (sljit_get_register_index(SLJIT_S0) << 16)
3755 | sljit_get_register_index(SLJIT_S1);
3756 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3757 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
3758 /* add rd, rn, rm */
3759 inst = 0xeb000000 | (sljit_get_register_index(SLJIT_RETURN_REG) << 8)
3760 | (sljit_get_register_index(SLJIT_S0) << 16)
3761 | sljit_get_register_index(SLJIT_S1);
3762 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3763 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3764 /* add rd, rn, rm */
3765 inst = 0x8b000000 | sljit_get_register_index(SLJIT_RETURN_REG)
3766 | (sljit_get_register_index(SLJIT_S0) << 5)
3767 | (sljit_get_register_index(SLJIT_S1) << 16);
3768 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3769 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3770 /* add rD, rA, rB */
3771 inst = (31 << 26) | (266 << 1) | (sljit_get_register_index(SLJIT_RETURN_REG) << 21)
3772 | (sljit_get_register_index(SLJIT_S0) << 16)
3773 | (sljit_get_register_index(SLJIT_S1) << 11);
3774 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3775 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
3776 /* addu rd, rs, rt */
3777 inst = 33 | (sljit_get_register_index(SLJIT_RETURN_REG) << 11)
3778 | (sljit_get_register_index(SLJIT_S0) << 21)
3779 | (sljit_get_register_index(SLJIT_S1) << 16);
3780 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3781 #elif (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
3782 /* daddu rd, rs, rt */
3783 inst = 45 | (sljit_get_register_index(SLJIT_RETURN_REG) << 11)
3784 | (sljit_get_register_index(SLJIT_S0) << 21)
3785 | (sljit_get_register_index(SLJIT_S1) << 16);
3786 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3787 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3788 /* add rd, rs1, rs2 */
3789 inst = (0x2 << 30) | (sljit_get_register_index(SLJIT_RETURN_REG) << 25)
3790 | (sljit_get_register_index(SLJIT_S0) << 14)
3791 | sljit_get_register_index(SLJIT_S1);
3792 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3793 #else
3794 inst = 0;
3795 sljit_emit_op_custom(compiler, &inst, 0);
3796 #endif
3797
3798 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
3799
3800 code.code = sljit_generate_code(compiler);
3801 CHECK(compiler);
3802 sljit_free_compiler(compiler);
3803
3804 FAILED(code.func2(32, -11) != 21, "test41 case 1 failed\n");
3805 FAILED(code.func2(1000, 234) != 1234, "test41 case 2 failed\n");
3806 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3807 FAILED(code.func2(SLJIT_W(0x20f0a04090c06070), SLJIT_W(0x020f0a04090c0607)) != SLJIT_W(0x22ffaa4499cc6677), "test41 case 3 failed\n");
3808 #endif
3809
3810 sljit_free_code(code.code);
3811
3812 if (sljit_is_fpu_available()) {
3813 buf[0] = 13.5;
3814 buf[1] = -2.25;
3815 buf[2] = 0.0;
3816
3817 compiler = sljit_create_compiler(NULL);
3818 sljit_emit_enter(compiler, 0, 1, 0, 1, 2, 0, 0);
3819 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
3820 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
3821 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3822 /* addsd x, xm */
3823 inst[0] = 0xf2;
3824 inst[1] = 0x0f;
3825 inst[2] = 0x58;
3826 inst[3] = 0xc0 | (sljit_get_float_register_index(SLJIT_FR0) << 3)
3827 | sljit_get_float_register_index(SLJIT_FR1);
3828 sljit_emit_op_custom(compiler, inst, 4);
3829 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3830 /* addsd x, xm */
3831 if (sljit_get_float_register_index(SLJIT_FR0) > 7 || sljit_get_float_register_index(SLJIT_FR1) > 7) {
3832 inst[0] = 0;
3833 if (sljit_get_float_register_index(SLJIT_FR0) > 7)
3834 inst[0] |= 0x04; /* REX_R */
3835 if (sljit_get_float_register_index(SLJIT_FR1) > 7)
3836 inst[0] |= 0x01; /* REX_B */
3837 inst[1] = 0xf2;
3838 inst[2] = 0x0f;
3839 inst[3] = 0x58;
3840 inst[4] = 0xc0 | ((sljit_get_float_register_index(SLJIT_FR0) & 0x7) << 3)
3841 | (sljit_get_float_register_index(SLJIT_FR1) & 0x7);
3842 sljit_emit_op_custom(compiler, inst, 5);
3843 }
3844 else {
3845 inst[0] = 0xf2;
3846 inst[1] = 0x0f;
3847 inst[2] = 0x58;
3848 inst[3] = 0xc0 | (sljit_get_float_register_index(SLJIT_FR0) << 3)
3849 | sljit_get_float_register_index(SLJIT_FR1);
3850 sljit_emit_op_custom(compiler, inst, 4);
3851 }
3852 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
3853 /* vadd.f64 dd, dn, dm */
3854 inst = 0xee300b00 | ((sljit_get_float_register_index(SLJIT_FR0) >> 1) << 12)
3855 | ((sljit_get_float_register_index(SLJIT_FR0) >> 1) << 16)
3856 | (sljit_get_float_register_index(SLJIT_FR1) >> 1);
3857 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3858 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3859 /* fadd rd, rn, rm */
3860 inst = 0x1e602800 | sljit_get_float_register_index(SLJIT_FR0)
3861 | (sljit_get_float_register_index(SLJIT_FR0) << 5)
3862 | (sljit_get_float_register_index(SLJIT_FR1) << 16);
3863 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3864 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3865 /* fadd frD, frA, frB */
3866 inst = (63 << 26) | (21 << 1) | (sljit_get_float_register_index(SLJIT_FR0) << 21)
3867 | (sljit_get_float_register_index(SLJIT_FR0) << 16)
3868 | (sljit_get_float_register_index(SLJIT_FR1) << 11);
3869 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3870 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
3871 /* add.d fd, fs, ft */
3872 inst = (17 << 26) | (17 << 21) | (sljit_get_float_register_index(SLJIT_FR0) << 6)
3873 | (sljit_get_float_register_index(SLJIT_FR0) << 11)
3874 | (sljit_get_float_register_index(SLJIT_FR1) << 16);
3875 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3876 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3877 /* faddd rd, rs1, rs2 */
3878 inst = (0x2 << 30) | (0x34 << 19) | (0x42 << 5)
3879 | (sljit_get_float_register_index(SLJIT_FR0) << 25)
3880 | (sljit_get_float_register_index(SLJIT_FR0) << 14)
3881 | sljit_get_float_register_index(SLJIT_FR1);
3882 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3883 #endif
3884 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_FR0, 0);
3885 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3886
3887 code.code = sljit_generate_code(compiler);
3888 CHECK(compiler);
3889 sljit_free_compiler(compiler);
3890
3891 code.func1((sljit_sw)&buf);
3892 FAILED(buf[2] != 11.25, "test41 case 3 failed\n");
3893
3894 sljit_free_code(code.code);
3895 }
3896
3897 successful_tests++;
3898 }
3899
3900 static void test42(void)
3901 {
3902 /* Test long multiply and division. */
3903 executable_code code;
3904 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3905 sljit_s32 i;
3906 sljit_sw buf[7 + 4 + 8 + 8];
3907
3908 if (verbose)
3909 printf("Run test42\n");
3910
3911 FAILED(!compiler, "cannot create compiler\n");
3912 for (i = 0; i < 7 + 4 + 8 + 8; i++)
3913 buf[i] = -1;
3914
3915 sljit_emit_enter(compiler, 0, 1, 5, 5, 0, 0, 0);
3916
3917 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -0x1fb308a);
3918 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0xf50c873);
3919 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, 0x8a0475b);
3920 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, 0x9dc849b);
3921 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -0x7c69a35);
3922 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, 0x5a4d0c4);
3923 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_IMM, 0x9a3b06d);
3924
3925 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3926 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3927 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3928 sljit_emit_op0(compiler, SLJIT_LMUL_UW);
3929 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R0, 0);
3930 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R1, 0);
3931
3932 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3933 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3934 sljit_emit_op0(compiler, SLJIT_LMUL_SW);
3935 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R0, 0);
3936 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R1, 0);
3937
3938 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3939 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3940 sljit_emit_op0(compiler, SLJIT_DIVMOD_UW);
3941 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
3942 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R1, 0);
3943
3944 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3945 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3946 sljit_emit_op0(compiler, SLJIT_DIVMOD_SW);
3947 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R0, 0);
3948 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R1, 0);
3949
3950 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x5cf783d3cf0a74b0));
3951 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3d5df42d03a28fc7));
3952 sljit_emit_op0(compiler, SLJIT_DIVMOD_U32);
3953 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
3954 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
3955 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R0, 0);
3956 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R1, 0);
3957
3958 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x371df5197ba26a28));
3959 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x46c78a5cfd6a420c));
3960 sljit_emit_op0(compiler, SLJIT_DIVMOD_S32);
3961 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
3962 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R1, 0, SLJIT_R1, 0);
3963 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R0, 0);
3964 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_sw), SLJIT_R1, 0);
3965
3966 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xc456f048c28a611b));
3967 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3d4af2c543));
3968 sljit_emit_op0(compiler, SLJIT_DIV_UW);
3969 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 19 * sizeof(sljit_sw), SLJIT_R0, 0);
3970 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_sw), SLJIT_R1, 0);
3971
3972 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x720fa4b74c329b14));
3973 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0xa64ae42b7d6));
3974 sljit_emit_op0(compiler, SLJIT_DIV_SW);
3975 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 21 * sizeof(sljit_sw), SLJIT_R0, 0);
3976 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_sw), SLJIT_R1, 0);
3977
3978 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x4af51c027b34));
3979 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x9ba4ff2906b14));
3980 sljit_emit_op0(compiler, SLJIT_DIV_U32);
3981 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
3982 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
3983 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 23 * sizeof(sljit_sw), SLJIT_R0, 0);
3984 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 24 * sizeof(sljit_sw), SLJIT_R1, 0);
3985
3986 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xc40b58a3f20d));
3987 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(-0xa63c923));
3988 sljit_emit_op0(compiler, SLJIT_DIV_S32);
3989 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
3990 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R1, 0, SLJIT_R1, 0);
3991 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 25 * sizeof(sljit_sw), SLJIT_R0, 0);
3992 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 26 * sizeof(sljit_sw), SLJIT_R1, 0);
3993
3994 #else
3995 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
3996 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
3997 sljit_emit_op0(compiler, SLJIT_LMUL_UW);
3998 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R0, 0);
3999 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R1, 0);
4000
4001 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
4002 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
4003 sljit_emit_op0(compiler, SLJIT_LMUL_SW);
4004 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R0, 0);
4005 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R1, 0);
4006
4007 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
4008 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
4009 sljit_emit_op0(compiler, SLJIT_DIVMOD_UW);
4010 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
4011 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R1, 0);
4012
4013 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
4014 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
4015 sljit_emit_op0(compiler, SLJIT_DIVMOD_SW);
4016 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R0, 0);
4017 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R1, 0);
4018
4019 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0xcf0a74b0);
4020 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 0x03a28fc7);
4021 sljit_emit_op0(compiler, SLJIT_DIVMOD_U32);
4022 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R0, 0);
4023 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R1, 0);
4024
4025 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x7ba26a28);
4026 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)0xfd6a420c);
4027 sljit_emit_op0(compiler, SLJIT_DIVMOD_S32);
4028 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R0, 0);
4029 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_sw), SLJIT_R1, 0);
4030
4031 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x9d4b7036));
4032 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0xb86d0));
4033 sljit_emit_op0(compiler, SLJIT_DIV_UW);
4034 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 19 * sizeof(sljit_sw), SLJIT_R0, 0);
4035 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_sw), SLJIT_R1, 0);
4036
4037 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x58b0692c));
4038 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0xd357));
4039 sljit_emit_op0(compiler, SLJIT_DIV_SW);
4040 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 21 * sizeof(sljit_sw), SLJIT_R0, 0);
4041 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_sw), SLJIT_R1, 0);
4042
4043 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1c027b34));
4044 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0xf2906b14));
4045 sljit_emit_op0(compiler, SLJIT_DIV_U32);
4046 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
4047 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
4048 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 23 * sizeof(sljit_sw), SLJIT_R0, 0);
4049 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 24 * sizeof(sljit_sw), SLJIT_R1, 0);
4050
4051 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x58a3f20d));
4052 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(-0xa63c923));
4053 sljit_emit_op0(compiler, SLJIT_DIV_S32);
4054 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
4055 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R1, 0, SLJIT_R1, 0);
4056 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 25 * sizeof(sljit_sw), SLJIT_R0, 0);
4057 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 26 * sizeof(sljit_sw), SLJIT_R1, 0);
4058 #endif
4059
4060 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R2, 0);
4061 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R3, 0);
4062 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R4, 0);
4063 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_S1, 0);
4064 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_S2, 0);
4065 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_S3, 0);
4066 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_S4, 0);
4067
4068 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
4069
4070 code.code = sljit_generate_code(compiler);
4071 CHECK(compiler);
4072 sljit_free_compiler(compiler);
4073
4074 code.func1((sljit_sw)&buf);
4075
4076 FAILED(buf[0] != -0x1fb308a, "test42 case 1 failed\n");
4077 FAILED(buf[1] != 0xf50c873, "test42 case 2 failed\n");
4078 FAILED(buf[2] != 0x8a0475b, "test42 case 3 failed\n");
4079 FAILED(buf[3] != 0x9dc849b, "test42 case 4 failed\n");
4080 FAILED(buf[4] != -0x7c69a35, "test42 case 5 failed\n");
4081 FAILED(buf[5] != 0x5a4d0c4, "test42 case 6 failed\n");
4082 FAILED(buf[6] != 0x9a3b06d, "test42 case 7 failed\n");
4083
4084 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4085 FAILED(buf[7] != SLJIT_W(-4388959407985636971), "test42 case 8 failed\n");
4086 FAILED(buf[8] != SLJIT_W(2901680654366567099), "test42 case 9 failed\n");
4087 FAILED(buf[9] != SLJIT_W(-4388959407985636971), "test42 case 10 failed\n");
4088 FAILED(buf[10] != SLJIT_W(-1677173957268872740), "test42 case 11 failed\n");
4089 FAILED(buf[11] != SLJIT_W(2), "test42 case 12 failed\n");
4090 FAILED(buf[12] != SLJIT_W(2532236178951865933), "test42 case 13 failed\n");
4091 FAILED(buf[13] != SLJIT_W(-1), "test42 case 14 failed\n");
4092 FAILED(buf[14] != SLJIT_W(-2177944059851366166), "test42 case 15 failed\n");
4093 #else
4094 FAILED(buf[7] != -1587000939, "test42 case 8 failed\n");
4095 FAILED(buf[8] != 665003983, "test42 case 9 failed\n");
4096 FAILED(buf[9] != -1587000939, "test42 case 10 failed\n");
4097 FAILED(buf[10] != -353198352, "test42 case 11 failed\n");
4098 FAILED(buf[11] != 2, "test42 case 12 failed\n");
4099 FAILED(buf[12] != 768706125, "test42 case 13 failed\n");
4100 FAILED(buf[13] != -1, "test42 case 14 failed\n");
4101 FAILED(buf[14] != -471654166, "test42 case 15 failed\n");
4102 #endif
4103
4104 FAILED(buf[15] != SLJIT_W(56), "test42 case 16 failed\n");
4105 FAILED(buf[16] != SLJIT_W(58392872), "test42 case 17 failed\n");
4106 FAILED(buf[17] != SLJIT_W(-47), "test42 case 18 failed\n");
4107 FAILED(buf[18] != SLJIT_W(35949148), "test42 case 19 failed\n");
4108
4109 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4110 FAILED(buf[19] != SLJIT_W(0x3340bfc), "test42 case 20 failed\n");
4111 FAILED(buf[20] != SLJIT_W(0x3d4af2c543), "test42 case 21 failed\n");
4112 FAILED(buf[21] != SLJIT_W(-0xaf978), "test42 case 22 failed\n");
4113 FAILED(buf[22] != SLJIT_W(0xa64ae42b7d6), "test42 case 23 failed\n");
4114 #else
4115 FAILED(buf[19] != SLJIT_W(0xda5), "test42 case 20 failed\n");
4116 FAILED(buf[20] != SLJIT_W(0xb86d0), "test42 case 21 failed\n");
4117 FAILED(buf[21] != SLJIT_W(-0x6b6e), "test42 case 22 failed\n");
4118 FAILED(buf[22] != SLJIT_W(0xd357), "test42 case 23 failed\n");
4119 #endif
4120
4121 FAILED(buf[23] != SLJIT_W(0x0), "test42 case 24 failed\n");
4122 FAILED(buf[24] != SLJIT_W(0xf2906b14), "test42 case 25 failed\n");
4123 FAILED(buf[25] != SLJIT_W(-0x8), "test42 case 26 failed\n");
4124 FAILED(buf[26] != SLJIT_W(-0xa63c923), "test42 case 27 failed\n");
4125
4126 sljit_free_code(code.code);
4127 successful_tests++;
4128 }
4129
4130 static void test43(void)
4131 {
4132 /* Test floating point compare. */
4133 executable_code code;
4134 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4135 struct sljit_jump* jump;
4136
4137 union {
4138 sljit_f64 value;
4139 struct {
4140 sljit_u32 value1;
4141 sljit_u32 value2;
4142 } u;
4143 } dbuf[4];
4144
4145 if (verbose)
4146 printf("Run test43\n");
4147
4148 if (!sljit_is_fpu_available()) {
4149 if (verbose)
4150 printf("no fpu available, test43 skipped\n");
4151 successful_tests++;
4152 if (compiler)
4153 sljit_free_compiler(compiler);
4154 return;
4155 }
4156
4157 FAILED(!compiler, "cannot create compiler\n");
4158
4159 dbuf[0].value = 12.125;
4160 /* a NaN */
4161 dbuf[1].u.value1 = 0x7fffffff;
4162 dbuf[1].u.value2 = 0x7fffffff;
4163 dbuf[2].value = -13.5;
4164 dbuf[3].value = 12.125;
4165
4166 sljit_emit_enter(compiler, 0, 1, 1, 1, 3, 0, 0);
4167 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
4168 /* dbuf[0] < dbuf[2] -> -2 */
4169 jump = sljit_emit_fcmp(compiler, SLJIT_GREATER_EQUAL_F64, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_F64_SHIFT);
4170 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, -2);
4171
4172 sljit_set_label(jump, sljit_emit_label(compiler));
4173 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4174 /* dbuf[0] and dbuf[1] is not NaN -> 5 */
4175 jump = sljit_emit_fcmp(compiler, SLJIT_UNORDERED_F64, SLJIT_MEM0(), (sljit_sw)&dbuf[1], SLJIT_FR1, 0);
4176 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 5);
4177
4178 sljit_set_label(jump, sljit_emit_label(compiler));
4179 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64));
4180 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 11);
4181 /* dbuf[0] == dbuf[3] -> 11 */
4182 jump = sljit_emit_fcmp(compiler, SLJIT_EQUAL_F64, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_FR2, 0);
4183
4184 /* else -> -17 */
4185 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, -17);
4186 sljit_set_label(jump, sljit_emit_label(compiler));
4187 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4188
4189 code.code = sljit_generate_code(compiler);
4190 CHECK(compiler);
4191 sljit_free_compiler(compiler);
4192
4193 FAILED(code.func1((sljit_sw)&dbuf) != 11, "test43 case 1 failed\n");
4194 dbuf[3].value = 12;
4195 FAILED(code.func1((sljit_sw)&dbuf) != -17, "test43 case 2 failed\n");
4196 dbuf[1].value = 0;
4197 FAILED(code.func1((sljit_sw)&dbuf) != 5, "test43 case 3 failed\n");
4198 dbuf[2].value = 20;
4199 FAILED(code.func1((sljit_sw)&dbuf) != -2, "test43 case 4 failed\n");
4200
4201 sljit_free_code(code.code);
4202 successful_tests++;
4203 }
4204
4205 static void test44(void)
4206 {
4207 /* Test mov. */
4208 executable_code code;
4209 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4210 void *buf[5];
4211
4212 if (verbose)
4213 printf("Run test44\n");
4214
4215 FAILED(!compiler, "cannot create compiler\n");
4216
4217 buf[0] = buf + 2;
4218 buf[1] = NULL;
4219 buf[2] = NULL;
4220 buf[3] = NULL;
4221 buf[4] = NULL;
4222 sljit_emit_enter(compiler, 0, 1, 3, 2, 0, 0, 0);
4223
4224 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 0);
4225 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_p), SLJIT_R0, 0);
4226 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_p));
4227 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 2);
4228 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM2(SLJIT_S0, SLJIT_R1), SLJIT_POINTER_SHIFT, SLJIT_R0, 0);
4229 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_p));
4230 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3 << SLJIT_POINTER_SHIFT);
4231 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_S0, 0);
4232 sljit_emit_op1(compiler, SLJIT_MOVU_P, SLJIT_MEM2(SLJIT_R2, SLJIT_R1), 0, SLJIT_R0, 0);
4233 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 2 * sizeof(sljit_p));
4234 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM1(SLJIT_R2), sizeof(sljit_p), SLJIT_R0, 0);
4235
4236 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
4237
4238 code.code = sljit_generate_code(compiler);
4239 CHECK(compiler);
4240 sljit_free_compiler(compiler);
4241
4242 FAILED(code.func1((sljit_sw)&buf) != (sljit_sw)(buf + 2), "test44 case 1 failed\n");
4243 FAILED(buf[1] != buf + 2, "test44 case 2 failed\n");
4244 FAILED(buf[2] != buf + 3, "test44 case 3 failed\n");
4245 FAILED(buf[3] != buf + 4, "test44 case 4 failed\n");
4246 FAILED(buf[4] != buf + 2, "test44 case 5 failed\n");
4247
4248 sljit_free_code(code.code);
4249 successful_tests++;
4250 }
4251
4252 static void test45(void)
4253 {
4254 /* Test single precision floating point. */
4255
4256 executable_code code;
4257 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4258 sljit_f32 buf[12];
4259 sljit_sw buf2[6];
4260 struct sljit_jump* jump;
4261
4262 if (verbose)
4263 printf("Run test45\n");
4264
4265 if (!sljit_is_fpu_available()) {
4266 if (verbose)
4267 printf("no fpu available, test45 skipped\n");
4268 successful_tests++;
4269 if (compiler)
4270 sljit_free_compiler(compiler);
4271 return;
4272 }
4273
4274 FAILED(!compiler, "cannot create compiler\n");
4275
4276 buf[0] = 5.5;
4277 buf[1] = -7.25;
4278 buf[2] = 0;
4279 buf[3] = 0;
4280 buf[4] = 0;
4281 buf[5] = 0;
4282 buf[6] = 0;
4283 buf[7] = 8.75;
4284 buf[8] = 0;
4285 buf[9] = 16.5;
4286 buf[10] = 0;
4287 buf[11] = 0;
4288
4289 buf2[0] = -1;
4290 buf2[1] = -1;
4291 buf2[2] = -1;
4292 buf2[3] = -1;
4293 buf2[4] = -1;
4294 buf2[5] = -1;
4295
4296 sljit_emit_enter(compiler, 0, 2, 3, 2, 6, 0, 0);
4297
4298 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
4299 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4300 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f32), SLJIT_FR0, 0);
4301 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_FR1, 0, SLJIT_FR5, 0);
4302 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f32), SLJIT_FR1, 0);
4303 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f32), SLJIT_FR5, 0);
4304 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_FR4, 0, SLJIT_MEM1(SLJIT_S0), 0);
4305 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f32), SLJIT_FR4, 0);
4306
4307 sljit_emit_fop2(compiler, SLJIT_ADD_F32, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4308 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f32), SLJIT_FR0, 0);
4309 sljit_emit_fop2(compiler, SLJIT_SUB_F32, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_f32), SLJIT_FR5, 0);
4310 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
4311 sljit_emit_fop2(compiler, SLJIT_MUL_F32, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_f32), SLJIT_FR0, 0, SLJIT_FR0, 0);
4312 sljit_emit_fop2(compiler, SLJIT_DIV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f32), SLJIT_FR0, 0);
4313 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f32), SLJIT_FR2, 0);
4314 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 0x3d0ac);
4315 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_R0), 0x3d0ac);
4316 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 0x3d0ac + sizeof(sljit_f32));
4317 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_R0), -0x3d0ac);
4318
4319 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4320 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4321 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4322 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_EQUAL_F32);
4323 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4324 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw), SLJIT_LESS_F32);
4325 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
4326 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw), SLJIT_EQUAL_F32);
4327 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_GREATER_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
4328 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw), SLJIT_GREATER_EQUAL_F32);
4329
4330 jump = sljit_emit_fcmp(compiler, SLJIT_LESS_EQUAL_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4331 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_IMM, 7);
4332 sljit_set_label(jump, sljit_emit_label(compiler));
4333
4334 jump = sljit_emit_fcmp(compiler, SLJIT_GREATER_F32, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_FR2, 0);
4335 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_IMM, 6);
4336 sljit_set_label(jump, sljit_emit_label(compiler));
4337
4338 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
4339
4340 code.code = sljit_generate_code(compiler);
4341 CHECK(compiler);
4342 sljit_free_compiler(compiler);
4343
4344 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
4345 FAILED(buf[2] != -5.5, "test45 case 1 failed\n");
4346 FAILED(buf[3] != 7.25, "test45 case 2 failed\n");
4347 FAILED(buf[4] != 7.25, "test45 case 3 failed\n");
4348 FAILED(buf[5] != -5.5, "test45 case 4 failed\n");
4349 FAILED(buf[6] != -1.75, "test45 case 5 failed\n");
4350 FAILED(buf[7] != 16.0, "test45 case 6 failed\n");
4351 FAILED(buf[8] != 30.25, "test45 case 7 failed\n");
4352 FAILED(buf[9] != 3, "test45 case 8 failed\n");
4353 FAILED(buf[10] != -5.5, "test45 case 9 failed\n");
4354 FAILED(buf[11] != 7.25, "test45 case 10 failed\n");
4355 FAILED(buf2[0] != 1, "test45 case 11 failed\n");
4356 FAILED(buf2[1] != 2, "test45 case 12 failed\n");
4357 FAILED(buf2[2] != 2, "test45 case 13 failed\n");
4358 FAILED(buf2[3] != 1, "test45 case 14 failed\n");
4359 FAILED(buf2[4] != 7, "test45 case 15 failed\n");
4360 FAILED(buf2[5] != -1, "test45 case 16 failed\n");
4361
4362 sljit_free_code(code.code);
4363 successful_tests++;
4364 }
4365
4366 static void test46(void)
4367 {
4368 /* Test sljit_emit_op_flags with 32 bit operations. */
4369
4370 executable_code code;
4371 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4372 sljit_s32 buf[24];
4373 sljit_sw buf2[6];
4374 sljit_s32 i;
4375
4376 if (verbose)
4377 printf("Run test46\n");
4378
4379 for (i = 0; i < 24; ++i)
4380 buf[i] = -17;
4381 buf[16] = 0;
4382 for (i = 0; i < 6; ++i)
4383 buf2[i] = -13;
4384 buf2[4] = -124;
4385
4386 sljit_emit_enter(compiler, 0, 2, 3, 3, 0, 0, 0);
4387
4388 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -7);
4389 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, 13);
4390 sljit_emit_op_flags(compiler, SLJIT_MOV_S32, SLJIT_MEM0(), (sljit_sw)&buf, SLJIT_UNUSED, 0, SLJIT_LESS);
4391 sljit_emit_op_flags(compiler, SLJIT_AND32, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_s32), SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_s32), SLJIT_NOT_ZERO);
4392
4393 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -7);
4394 sljit_emit_op_flags(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_s32), SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_s32), SLJIT_EQUAL);
4395 sljit_emit_op_flags(compiler, SLJIT_AND32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_s32), SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_s32), SLJIT_NOT_EQUAL);
4396 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x1235);
4397 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x1235);
4398 sljit_emit_op_flags(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_ZERO);
4399 sljit_emit_op_flags(compiler, SLJIT_AND32, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_s32), SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_s32), SLJIT_ZERO32);
4400 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_s32), SLJIT_R0, 0);
4401
4402 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -7);
4403 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 12);
4404 sljit_emit_op_flags(compiler, SLJIT_MOV_U32, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 2, SLJIT_UNUSED, 0, SLJIT_EQUAL);
4405 sljit_emit_op_flags(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_UNUSED, 0, SLJIT_EQUAL);
4406 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_s32), SLJIT_R0, 0);
4407 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
4408 sljit_emit_op_flags(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 2, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 2, SLJIT_EQUAL);
4409 sljit_emit_op_flags(compiler, SLJIT_MOV_U32, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_s32), SLJIT_UNUSED, 0, SLJIT_NOT_EQUAL32);
4410
4411 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -7);
4412 sljit_emit_op_flags(compiler, SLJIT_XOR32 | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_s32), SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_s32), SLJIT_ZERO);
4413 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 39);
4414 sljit_emit_op_flags(compiler, SLJIT_XOR32, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_NOT_ZERO);
4415 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_s32), SLJIT_R0, 0);
4416
4417 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -7);
4418 sljit_emit_op_flags(compiler, SLJIT_AND, SLJIT_MEM0(), (sljit_sw)&buf2, SLJIT_MEM0(), (sljit_sw)&buf2, SLJIT_GREATER);
4419 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, 5);
4420 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
4421 sljit_emit_op_flags(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_SIG_LESS);
4422 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
4423 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, 5);
4424 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_UNUSED, 0, SLJIT_LESS);
4425 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_UNUSED, 0, SLJIT_NOT_EQUAL);
4426 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, 5);
4427 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw), SLJIT_S2, 0);
4428 sljit_emit_op_flags(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_SIG_LESS);
4429 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_ZERO);
4430 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, 0);
4431 sljit_emit_op_flags(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_GREATER);
4432
4433 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
4434
4435 code.code = sljit_generate_code(compiler);
4436 CHECK(compiler);
4437 sljit_free_compiler(compiler);
4438
4439 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
4440 FAILED(buf[0] != 0, "test46 case 1 failed\n");
4441 FAILED(buf[1] != -17, "test46 case 2 failed\n");
4442 FAILED(buf[2] != 1, "test46 case 3 failed\n");
4443 FAILED(buf[3] != -17, "test46 case 4 failed\n");
4444 FAILED(buf[4] != 1, "test46 case 5 failed\n");
4445 FAILED(buf[5] != -17, "test46 case 6 failed\n");
4446 FAILED(buf[6] != 1, "test46 case 7 failed\n");
4447 FAILED(buf[7] != -17, "test46 case 8 failed\n");
4448 FAILED(buf[8] != 0, "test46 case 9 failed\n");
4449 FAILED(buf[9] != -17, "test46 case 10 failed\n");
4450 FAILED(buf[10] != 1, "test46 case 11 failed\n");
4451 FAILED(buf[11] != -17, "test46 case 12 failed\n");
4452 FAILED(buf[12] != 1, "test46 case 13 failed\n");
4453 FAILED(buf[13] != -17, "test46 case 14 failed\n");
4454 FAILED(buf[14] != 1, "test46 case 15 failed\n");
4455 FAILED(buf[15] != -17, "test46 case 16 failed\n");
4456 FAILED(buf[16] != 0, "test46 case 17 failed\n");
4457 FAILED(buf[17] != -17, "test46 case 18 failed\n");
4458 FAILED(buf[18] != 0, "test46 case 19 failed\n");
4459 FAILED(buf[19] != -17, "test46 case 20 failed\n");
4460 FAILED(buf[20] != -18, "test46 case 21 failed\n");
4461 FAILED(buf[21] != -17, "test46 case 22 failed\n");
4462 FAILED(buf[22] != 38, "test46 case 23 failed\n");
4463 FAILED(buf[23] != -17, "test46 case 24 failed\n");
4464
4465 FAILED(buf2[0] != 0, "test46 case 25 failed\n");
4466 FAILED(buf2[1] != 1, "test46 case 26 failed\n");
4467 FAILED(buf2[2] != 0, "test46 case 27 failed\n");
4468 FAILED(buf2[3] != 1, "test46 case 28 failed\n");
4469 FAILED(buf2[4] != -123, "test46 case 29 failed\n");
4470 FAILED(buf2[5] != -14, "test46 case 30 failed\n");
4471
4472 sljit_free_code(code.code);
4473 successful_tests++;
4474 }
4475
4476 static void test47(void)
4477 {
4478 /* Test jump optimizations. */
4479 executable_code code;
4480 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4481 sljit_sw buf[3];
4482
4483 if (verbose)
4484 printf("Run test47\n");
4485
4486 FAILED(!compiler, "cannot create compiler\n");
4487 buf[0] = 0;
4488 buf[1] = 0;
4489 buf[2] = 0;
4490
4491 sljit_emit_enter(compiler, 0, 1, 3, 1, 0, 0, 0);
4492 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x3a5c6f);
4493 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 3);
4494 sljit_set_target(sljit_emit_jump(compiler, SLJIT_LESS), 0x11223344);
4495 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
4496 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xd37c10);
4497 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4498 sljit_set_target(sljit_emit_jump(compiler, SLJIT_LESS), SLJIT_W(0x112233445566));
4499 #endif
4500 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
4501 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x59b48e);
4502 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4503 sljit_set_target(sljit_emit_jump(compiler, SLJIT_LESS), SLJIT_W(0x1122334455667788));
4504 #endif
4505 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
4506 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4507
4508 code.code = sljit_generate_code(compiler);
4509 CHECK(compiler);
4510 sljit_free_compiler(compiler);
4511
4512 code.func1((sljit_sw)&buf);
4513 FAILED(buf[0] != 0x3a5c6f, "test47 case 1 failed\n");
4514 FAILED(buf[1] != 0xd37c10, "test47 case 2 failed\n");
4515 FAILED(buf[2] != 0x59b48e, "test47 case 3 failed\n");
4516
4517 sljit_free_code(code.code);
4518 successful_tests++;
4519 }
4520
4521 static void test48(void)
4522 {
4523 /* Test floating point conversions. */
4524 executable_code code;
4525 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4526 int i;
4527 sljit_f64 dbuf[9];
4528 sljit_f32 sbuf[9];
4529 sljit_sw wbuf[9];
4530 sljit_s32 ibuf[9];
4531
4532 if (verbose)
4533 printf("Run test48\n");
4534
4535 if (!sljit_is_fpu_available()) {
4536 if (verbose)
4537 printf("no fpu available, test48 skipped\n");
4538 successful_tests++;
4539 if (compiler)
4540 sljit_free_compiler(compiler);
4541 return;
4542 }
4543
4544 FAILED(!compiler, "cannot create compiler\n");
4545 for (i = 0; i < 9; i++) {
4546 dbuf[i] = 0.0;
4547 sbuf[i] = 0.0;
4548 wbuf[i] = 0;
4549 ibuf[i] = 0;
4550 }
4551
4552 dbuf[0] = 123.5;
4553 dbuf[1] = -367;
4554 dbuf[2] = 917.75;
4555
4556 sbuf[0] = 476.25;
4557 sbuf[1] = -1689.75;
4558
4559 wbuf[0] = 2345;
4560
4561 ibuf[0] = 312;
4562 ibuf[1] = -9324;
4563
4564 sljit_emit_enter(compiler, 0, 0, 3, 3, 6, 0, 0);
4565 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
4566 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, (sljit_sw)&sbuf);
4567 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, (sljit_sw)&wbuf);
4568 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, (sljit_sw)&ibuf);
4569
4570 /* sbuf[2] */
4571 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_F64, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S0), 0);
4572 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), 0);
4573 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3);
4574 /* sbuf[3] */
4575 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_F64, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_F32_SHIFT, SLJIT_FR5, 0);
4576 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_F32, SLJIT_FR4, 0, SLJIT_MEM1(SLJIT_S1), 0);
4577 /* dbuf[3] */
4578 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64), SLJIT_FR4, 0);
4579 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR3, 0, SLJIT_MEM1(SLJIT_S1), 0);
4580 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_F32, SLJIT_FR2, 0, SLJIT_FR3, 0);
4581 /* dbuf[4] */
4582 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f64), SLJIT_FR2, 0);
4583 /* sbuf[4] */
4584 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_f32), SLJIT_FR3, 0);
4585
4586 /* wbuf[1] */
4587 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
4588 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
4589 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_UNUSED, 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_F64_SHIFT);
4590 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_R0, 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_F64_SHIFT);
4591 /* wbuf[2] */
4592 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
4593 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S1), 0);
4594 /* wbuf[3] */
4595 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F32, SLJIT_MEM1(SLJIT_S2), 3 * sizeof(sljit_sw), SLJIT_FR5, 0);
4596 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_FR0, 0, SLJIT_FR5, 0);
4597 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 4);
4598 /* wbuf[4] */
4599 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F32, SLJIT_MEM2(SLJIT_S2, SLJIT_R1), SLJIT_WORD_SHIFT, SLJIT_FR0, 0);
4600 sljit_emit_fop1(compiler, SLJIT_NEG_F64, SLJIT_FR4, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64));
4601 /* ibuf[2] */
4602 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F64, SLJIT_MEM1(SLJIT_R2), 2 * sizeof(sljit_s32), SLJIT_FR4, 0);
4603 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
4604 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F32, SLJIT_R0, 0, SLJIT_FR1, 0);
4605 /* ibuf[3] */
4606 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_R2), 3 * sizeof(sljit_s32), SLJIT_R0, 0);
4607
4608 /* dbuf[5] */
4609 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S2), 0);
4610 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_FR2, 0, SLJIT_IMM, -6213);
4611 /* dbuf[6] */
4612 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64), SLJIT_FR2, 0);
4613 /* dbuf[7] */
4614 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_f64), SLJIT_MEM0(), (sljit_sw)&ibuf[0]);
4615 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R2), sizeof(sljit_s32));
4616 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_FR1, 0, SLJIT_R0, 0);
4617 /* dbuf[8] */
4618 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_f64), SLJIT_FR1, 0);
4619 /* sbuf[5] */
4620 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_f32), SLJIT_IMM, -123);
4621 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 7190);
4622 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_FR3, 0, SLJIT_R0, 0);
4623 /* sbuf[6] */
4624 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 6 * sizeof(sljit_f32), SLJIT_FR3, 0);
4625 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 123);
4626 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_R2, 0, SLJIT_IMM, 123 * sizeof(sljit_s32));
4627 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_S32, SLJIT_FR1, 0, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 2);
4628 /* sbuf[7] */
4629 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 7 * sizeof(sljit_f32), SLJIT_FR1, 0);
4630 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
4631 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 3812);
4632 /* sbuf[8] */
4633 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_S32, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_F32_SHIFT, SLJIT_R1, 0);
4634
4635 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4636
4637 code.code = sljit_generate_code(compiler);
4638 CHECK(compiler);
4639 sljit_free_compiler(compiler);
4640
4641 code.func0();
4642 FAILED(dbuf[3] != 476.25, "test48 case 1 failed\n");
4643 FAILED(dbuf[4] != 476.25, "test48 case 2 failed\n");
4644 FAILED(dbuf[5] != 2345.0, "test48 case 3 failed\n");
4645 FAILED(dbuf[6] != -6213.0, "test48 case 4 failed\n");
4646 FAILED(dbuf[7] != 312.0, "test48 case 5 failed\n");
4647 FAILED(dbuf[8] != -9324.0, "test48 case 6 failed\n");
4648
4649 FAILED(sbuf[2] != 123.5, "test48 case 7 failed\n");
4650 FAILED(sbuf[3] != 123.5, "test48 case 8 failed\n");
4651 FAILED(sbuf[4] != 476.25, "test48 case 9 failed\n");
4652 FAILED(sbuf[5] != -123, "test48 case 10 failed\n");
4653 FAILED(sbuf[6] != 7190, "test48 case 11 failed\n");
4654 FAILED(sbuf[7] != 312, "test48 case 12 failed\n");
4655 FAILED(sbuf[8] != 3812, "test48 case 13 failed\n");
4656
4657 FAILED(wbuf[1] != -367, "test48 case 14 failed\n");
4658 FAILED(wbuf[2] != 917, "test48 case 15 failed\n");
4659 FAILED(wbuf[3] != 476, "test48 case 16 failed\n");
4660 FAILED(wbuf[4] != -476, "test48 case 17 failed\n");
4661
4662 FAILED(ibuf[2] != -917, "test48 case 18 failed\n");
4663 FAILED(ibuf[3] != -1689, "test48 case 19 failed\n");
4664
4665 sljit_free_code(code.code);
4666 successful_tests++;
4667 }
4668
4669 static void test49(void)
4670 {
4671 /* Test floating point conversions. */
4672 executable_code code;
4673 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4674 int i;
4675 sljit_f64 dbuf[10];
4676 sljit_f32 sbuf[9];
4677 sljit_sw wbuf[9];
4678 sljit_s32 ibuf[9];
4679 sljit_s32* dbuf_ptr = (sljit_s32*)dbuf;
4680 sljit_s32* sbuf_ptr = (sljit_s32*)sbuf;
4681
4682 if (verbose)
4683 printf("Run test49\n");
4684
4685 if (!sljit_is_fpu_available()) {
4686 if (verbose)
4687 printf("no fpu available, test49 skipped\n");
4688 successful_tests++;
4689 if (compiler)
4690 sljit_free_compiler(compiler);
4691 return;
4692 }
4693
4694 FAILED(!compiler, "cannot create compiler\n");
4695
4696 for (i = 0; i < 9; i++) {
4697 dbuf_ptr[i << 1] = -1;
4698 dbuf_ptr[(i << 1) + 1] = -1;
4699 sbuf_ptr[i] = -1;
4700 wbuf[i] = -1;
4701 ibuf[i] = -1;
4702 }
4703
4704 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4705 dbuf[9] = (sljit_f64)SLJIT_W(0x1122334455);
4706 #endif
4707 dbuf[0] = 673.75;
4708 sbuf[0] = -879.75;
4709 wbuf[0] = 345;
4710 ibuf[0] = -249;
4711
4712 sljit_emit_enter(compiler, 0, 0, 3, 3, 3, 0, 0);
4713 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
4714 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, (sljit_sw)&sbuf);
4715 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, (sljit_sw)&wbuf);
4716 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, (sljit_sw)&ibuf);
4717
4718 /* dbuf[2] */
4719 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_F32, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S1), 0);
4720 /* sbuf[2] */
4721 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_F64, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S0), 0);
4722 /* wbuf[2] */
4723 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 0);
4724 /* wbuf[4] */
4725 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F32, SLJIT_MEM1(SLJIT_S2), 4 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S1), 0);
4726 /* ibuf[2] */
4727 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F64, SLJIT_MEM1(SLJIT_R2), 2 * sizeof(sljit_s32), SLJIT_MEM1(SLJIT_S0), 0);
4728 /* ibuf[4] */
4729 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F32, SLJIT_MEM1(SLJIT_R2), 4 * sizeof(sljit_s32), SLJIT_MEM1(SLJIT_S1), 0);
4730 /* dbuf[4] */
4731 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S2), 0);
4732 /* sbuf[4] */
4733 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S2), 0);
4734 /* dbuf[6] */
4735 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_R2), 0);
4736 /* sbuf[6] */
4737 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_S32, SLJIT_MEM1(SLJIT_S1), 6 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_R2), 0);
4738
4739 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4740 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f64));
4741 /* wbuf[8] */
4742 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), 8 * sizeof(sljit_sw), SLJIT_R0, 0);
4743 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f64));
4744 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F64, SLJIT_R0, 0, SLJIT_FR2, 0);
4745 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
4746 sljit_emit_op2(compiler, SLJIT_AND32, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffff);
4747 /* ibuf[8] */
4748 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_R2), 8 * sizeof(sljit_s32), SLJIT_R0, 0);
4749 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x4455667788));
4750 /* dbuf[8] */
4751 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_f64), SLJIT_R0, 0);
4752 /* dbuf[9] */
4753 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f64), SLJIT_IMM, SLJIT_W(0x7766554433));
4754 #endif
4755
4756 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4757
4758 code.code = sljit_generate_code(compiler);
4759 CHECK(compiler);
4760 sljit_free_compiler(compiler);
4761
4762 code.func0();
4763
4764 FAILED(dbuf_ptr[(1 * 2) + 0] != -1, "test49 case 1 failed\n");
4765 FAILED(dbuf_ptr[(1 * 2) + 1] != -1, "test49 case 2 failed\n");
4766 FAILED(dbuf[2] != -879.75, "test49 case 3 failed\n");
4767 FAILED(dbuf_ptr[(3 * 2) + 0] != -1, "test49 case 4 failed\n");
4768 FAILED(dbuf_ptr[(3 * 2) + 1] != -1, "test49 case 5 failed\n");
4769 FAILED(dbuf[4] != 345, "test49 case 6 failed\n");
4770 FAILED(dbuf_ptr[(5 * 2) + 0] != -1, "test49 case 7 failed\n");
4771 FAILED(dbuf_ptr[(5 * 2) + 1] != -1, "test49 case 8 failed\n");
4772 FAILED(dbuf[6] != -249, "test49 case 9 failed\n");
4773 FAILED(dbuf_ptr[(7 * 2) + 0] != -1, "test49 case 10 failed\n");
4774 FAILED(dbuf_ptr[(7 * 2) + 1] != -1, "test49 case 11 failed\n");
4775
4776 FAILED(sbuf_ptr[1] != -1, "test49 case 12 failed\n");
4777 FAILED(sbuf[2] != 673.75, "test49 case 13 failed\n");
4778 FAILED(sbuf_ptr[3] != -1, "test49 case 14 failed\n");
4779 FAILED(sbuf[4] != 345, "test49 case 15 failed\n");
4780 FAILED(sbuf_ptr[5] != -1, "test49 case 16 failed\n");
4781 FAILED(sbuf[6] != -249, "test49 case 17 failed\n");
4782 FAILED(sbuf_ptr[7] != -1, "test49 case 18 failed\n");
4783
4784 FAILED(wbuf[1] != -1, "test49 case 19 failed\n");
4785 FAILED(wbuf[2] != 673, "test49 case 20 failed\n");
4786 FAILED(wbuf[3] != -1, "test49 case 21 failed\n");
4787 FAILED(wbuf[4] != -879, "test49 case 22 failed\n");
4788 FAILED(wbuf[5] != -1, "test49 case 23 failed\n");
4789
4790 FAILED(ibuf[1] != -1, "test49 case 24 failed\n");
4791 FAILED(ibuf[2] != 673, "test49 case 25 failed\n");
4792 FAILED(ibuf[3] != -1, "test49 case 26 failed\n");
4793 FAILED(ibuf[4] != -879, "test49 case 27 failed\n");
4794 FAILED(ibuf[5] != -1, "test49 case 28 failed\n");
4795
4796 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4797 FAILED(dbuf[8] != (sljit_f64)SLJIT_W(0x4455667788), "test49 case 29 failed\n");
4798 FAILED(dbuf[9] != (sljit_f64)SLJIT_W(0x66554433), "test49 case 30 failed\n");
4799 FAILED(wbuf[8] != SLJIT_W(0x1122334455), "test48 case 31 failed\n");
4800 FAILED(ibuf[8] == 0x4455, "test48 case 32 failed\n");
4801 #endif
4802
4803 sljit_free_code(code.code);
4804 successful_tests++;
4805 }
4806
4807 static void test50(void)
4808 {
4809 /* Test stack and floating point operations. */
4810 executable_code code;
4811 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4812 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4813 sljit_uw size1, size2, size3;
4814 int result;
4815 #endif
4816 sljit_f32 sbuf[7];
4817
4818 if (verbose)
4819 printf("Run test50\n");
4820
4821 if (!sljit_is_fpu_available()) {
4822 if (verbose)
4823 printf("no fpu available, test50 skipped\n");
4824 successful_tests++;
4825 if (compiler)
4826 sljit_free_compiler(compiler);
4827 return;
4828 }
4829
4830 FAILED(!compiler, "cannot create compiler\n");
4831
4832 sbuf[0] = 245.5;
4833 sbuf[1] = -100.25;
4834 sbuf[2] = 713.75;
4835
4836 sljit_emit_enter(compiler, 0, 1, 3, 3, 6, 0, 8 * sizeof(sljit_f32));
4837
4838 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_S0), 0);
4839 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 0);
4840 /* sbuf[3] */
4841 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), sizeof(sljit_f32));
4842 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4843 sljit_emit_fop2(compiler, SLJIT_ADD_F32, SLJIT_MEM1(SLJIT_SP), 2 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_f32));
4844 /* sbuf[4] */
4845 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 2 * sizeof(sljit_f32));
4846 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 2 * sizeof(sljit_f32), SLJIT_IMM, 5934);
4847 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_MEM1(SLJIT_SP), 3 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 2 * sizeof(sljit_f32));
4848 /* sbuf[5] */
4849 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 3 * sizeof(sljit_f32));
4850
4851 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4852 size1 = compiler->size;
4853 #endif
4854 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f32));
4855 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4856 size2 = compiler->size;
4857 #endif
4858 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR5, 0, SLJIT_FR2, 0);
4859 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4860 size3 = compiler->size;
4861 #endif
4862 /* sbuf[6] */
4863 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f32), SLJIT_FR5, 0);
4864 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4865 result = (compiler->size - size3) == (size3 - size2) && (size3 - size2) == (size2 - size1);
4866 #endif
4867
4868 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4869
4870 code.code = sljit_generate_code(compiler);
4871 CHECK(compiler);
4872 sljit_free_compiler(compiler);
4873
4874 code.func1((sljit_sw)&sbuf);
4875
4876 FAILED(sbuf[3] != 245.5, "test50 case 1 failed\n");
4877 FAILED(sbuf[4] != 145.25, "test50 case 2 failed\n");
4878 FAILED(sbuf[5] != 5934, "test50 case 3 failed\n");
4879 FAILED(sbuf[6] != 713.75, "test50 case 4 failed\n");
4880 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4881 FAILED(!result, "test50 case 5 failed\n");
4882 #endif
4883
4884 sljit_free_code(code.code);
4885 successful_tests++;
4886 }
4887
4888 static void test51(void)
4889 {
4890 /* Test all registers provided by the CPU. */
4891 executable_code code;
4892 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4893 struct sljit_jump* jump;
4894 sljit_sw buf[2];
4895 sljit_s32 i;
4896
4897 FAILED(!compiler, "cannot create compiler\n");
4898
4899 buf[0] = 39;
4900
4901 sljit_emit_enter(compiler, 0, 0, SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0, 0);
4902
4903 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4904 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 32);
4905
4906 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)buf);
4907 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
4908
4909 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
4910 if (sljit_get_register_index(SLJIT_R(i)) >= 0) {
4911 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_R0, 0);
4912 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R(i)), 0);
4913 } else
4914 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, buf[0]);
4915 }
4916
4917 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 32);
4918 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
4919 if (sljit_get_register_index(SLJIT_R(i)) >= 0) {
4920 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_R0, 0);
4921 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R(i)), 32);
4922 } else
4923 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, buf[0]);
4924 }
4925
4926 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
4927 if (sljit_get_register_index(SLJIT_R(i)) >= 0) {
4928 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 32);
4929 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM2(SLJIT_R(i), SLJIT_R0), 0);
4930 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_R(i)), 0);
4931 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 8);
4932 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_R(i)), 2);
4933 } else
4934 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 3 * buf[0]);
4935 }
4936
4937 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 32 + sizeof(sljit_sw), SLJIT_R1, 0);
4938
4939 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
4940
4941 code.code = sljit_generate_code(compiler);
4942 CHECK(compiler);
4943 sljit_free_compiler(compiler);
4944
4945 code.func0();
4946
4947 FAILED(buf[1] != (39 * 5 * (SLJIT_NUMBER_OF_REGISTERS - 2)), "test51 case 1 failed\n");
4948
4949 sljit_free_code(code.code);
4950
4951 /* Next test. */
4952
4953 compiler = sljit_create_compiler(NULL);
4954
4955 FAILED(!compiler, "cannot create compiler\n");
4956
4957 sljit_emit_enter(compiler, 0, 0, SLJIT_NUMBER_OF_SCRATCH_REGISTERS, SLJIT_NUMBER_OF_SAVED_REGISTERS, 0, 0, 0);
4958
4959 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4960 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 17);
4961
4962 jump = sljit_emit_jump(compiler, SLJIT_CALL0);
4963 /* SLJIT_R0 contains the first value. */
4964 for (i = 1; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4965 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
4966
4967 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
4968
4969 sljit_set_label(jump, sljit_emit_label(compiler));
4970 sljit_emit_enter(compiler, 0, 0, SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0, 0);
4971 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4972 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 35);
4973 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
4974
4975 code.code = sljit_generate_code(compiler);
4976 CHECK(compiler);
4977 sljit_free_compiler(compiler);
4978
4979 FAILED(code.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS * 35 + SLJIT_NUMBER_OF_SAVED_REGISTERS * 17), "test51 case 2 failed\n");
4980
4981 sljit_free_code(code.code);
4982
4983 /* Next test. */
4984
4985 compiler = sljit_create_compiler(NULL);
4986
4987 FAILED(!compiler, "cannot create compiler\n");
4988
4989 sljit_emit_enter(compiler, 0, 0, SLJIT_NUMBER_OF_SCRATCH_REGISTERS, SLJIT_NUMBER_OF_SAVED_REGISTERS, 0, 0, 0);
4990
4991 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4992 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 68);
4993
4994 jump = sljit_emit_jump(compiler, SLJIT_CALL0);
4995 /* SLJIT_R0 contains the first value. */
4996 for (i = 1; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4997 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
4998
4999 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
5000
5001 sljit_set_label(jump, sljit_emit_label(compiler));
5002 sljit_emit_enter(compiler, 0, 0, 0, SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0);
5003 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5004 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S(i), 0, SLJIT_IMM, 43);
5005 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5006
5007 code.code = sljit_generate_code(compiler);
5008 CHECK(compiler);
5009 sljit_free_compiler(compiler);
5010
5011 FAILED(code.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS * 43 + SLJIT_NUMBER_OF_SAVED_REGISTERS * 68), "test51 case 3 failed\n");
5012
5013 sljit_free_code(code.code);
5014 successful_tests++;
5015 }
5016
5017 static void test52(void)
5018 {
5019 /* Test all registers provided by the CPU. */
5020 executable_code code;
5021 struct sljit_compiler* compiler;
5022 struct sljit_jump* jump;
5023 sljit_f64 buf[3];
5024 sljit_s32 i;
5025
5026 if (!sljit_is_fpu_available()) {
5027 if (verbose)
5028 printf("no fpu available, test52 skipped\n");
5029 successful_tests++;
5030 return;
5031 }
5032
5033 /* Next test. */
5034
5035 compiler = sljit_create_compiler(NULL);
5036 FAILED(!compiler, "cannot create compiler\n");
5037 buf[0] = 6.25;
5038 buf[1] = 17.75;
5039
5040 sljit_emit_enter(compiler, 0, 1, 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS, 0);
5041
5042 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5043 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_MEM1(SLJIT_S0), 0);
5044
5045 jump = sljit_emit_jump(compiler, SLJIT_CALL0);
5046 /* SLJIT_FR0 contains the first value. */
5047 for (i = 1; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5048 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_FR(i), 0);
5049 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_FR0, 0);
5050
5051 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5052
5053 sljit_set_label(jump, sljit_emit_label(compiler));
5054 sljit_emit_enter(compiler, 0, 0, 1, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS, 0, 0);
5055 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[1]);
5056 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5057 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_MEM1(SLJIT_R0), 0);
5058 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5059
5060 code.code = sljit_generate_code(compiler);
5061 CHECK(compiler);
5062 sljit_free_compiler(compiler);
5063
5064 code.func1((sljit_sw)&buf);
5065 FAILED(buf[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS * 17.75 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS * 6.25), "test52 case 1 failed\n");
5066
5067 sljit_free_code(code.code);
5068
5069 /* Next test. */
5070
5071 compiler = sljit_create_compiler(NULL);
5072 FAILED(!compiler, "cannot create compiler\n");
5073 buf[0] = -32.5;
5074 buf[1] = -11.25;
5075
5076 sljit_emit_enter(compiler, 0, 1, 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS, 0);
5077
5078 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5079 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_MEM1(SLJIT_S0), 0);
5080
5081 jump = sljit_emit_jump(compiler, SLJIT_CALL0);
5082 /* SLJIT_FR0 contains the first value. */
5083 for (i = 1; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5084 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_FR(i), 0);
5085 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_FR0, 0);
5086
5087 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5088
5089 sljit_set_label(jump, sljit_emit_label(compiler));
5090 sljit_emit_enter(compiler, 0, 0, 1, 0, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS, 0);
5091 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[1]);
5092 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5093 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FS(i), 0, SLJIT_MEM1(SLJIT_R0), 0);
5094 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5095
5096 code.code = sljit_generate_code(compiler);
5097 CHECK(compiler);
5098 sljit_free_compiler(compiler);
5099
5100 code.func1((sljit_sw)&buf);
5101 FAILED(buf[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS * -11.25 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS * -32.5), "test52 case 2 failed\n");
5102
5103 sljit_free_code(code.code);
5104 successful_tests++;
5105 }
5106
5107 static void test53(void)
5108 {
5109 /* Check SLJIT_DOUBLE_ALIGNMENT. */
5110 executable_code code;
5111 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5112 sljit_sw buf[1];
5113
5114 if (verbose)
5115 printf("Run test53\n");
5116
5117 FAILED(!compiler, "cannot create compiler\n");
5118 buf[0] = -1;
5119
5120 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, 1, 1, 1, 0, 0, 2 * sizeof(sljit_sw));
5121
5122 sljit_get_local_base(compiler, SLJIT_R0, 0, 0);
5123 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5124
5125 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5126
5127 code.code = sljit_generate_code(compiler);
5128 CHECK(compiler);
5129 sljit_free_compiler(compiler);
5130
5131 code.func1((sljit_sw)&buf);
5132
5133 FAILED((buf[0] & (sizeof(sljit_f64) - 1)) != 0, "test53 case 1 failed\n");
5134
5135 sljit_free_code(code.code);
5136
5137 /* Next test. */
5138
5139 compiler = sljit_create_compiler(NULL);
5140 FAILED(!compiler, "cannot create compiler\n");
5141 buf[0] = -1;
5142
5143 /* One more saved register to break the alignment on x86-32. */
5144 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, 1, 1, 2, 0, 0, 2 * sizeof(sljit_sw));
5145
5146 sljit_get_local_base(compiler, SLJIT_R0, 0, 0);
5147 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5148
5149 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5150
5151 code.code = sljit_generate_code(compiler);
5152 CHECK(compiler);
5153 sljit_free_compiler(compiler);
5154
5155 code.func1((sljit_sw)&buf);
5156
5157 FAILED((buf[0] & (sizeof(sljit_f64) - 1)) != 0, "test53 case 2 failed\n");
5158
5159 sljit_free_code(code.code);
5160 successful_tests++;
5161 }
5162
5163 static void test54(void)
5164 {
5165 /* Check x86 cmov. */
5166 executable_code code;
5167 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5168 sljit_sw buf[6];
5169 sljit_s32 ibuf[6];
5170
5171 if (verbose)
5172 printf("Run test54\n");
5173
5174 FAILED(!compiler, "cannot create compiler\n");
5175
5176 buf[0] = 98;
5177 buf[1] = 0;
5178 buf[2] = 0;
5179 buf[3] = 0;
5180 buf[4] = 0;
5181 buf[5] = 0;
5182 ibuf[0] = 0;
5183 ibuf[1] = 0;
5184 ibuf[2] = 0;
5185 ibuf[3] = 0;
5186 ibuf[4] = 67;
5187 ibuf[5] = 38;
5188
5189 sljit_emit_enter(compiler, 0, 2, 2, 2, 0, 0, 0);
5190
5191 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
5192 if (sljit_x86_is_cmov_available()) {
5193 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 17);
5194 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 34);
5195 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, -10);
5196 sljit_x86_emit_cmov(compiler, SLJIT_SIG_LESS, SLJIT_R0, SLJIT_R1, 0);
5197 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
5198 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, -10);
5199 sljit_x86_emit_cmov(compiler, SLJIT_SIG_GREATER, SLJIT_R0, SLJIT_R1, 0);
5200 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
5201
5202 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 24);
5203 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 24);
5204 sljit_x86_emit_cmov(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, SLJIT_MEM1(SLJIT_S0), 0);
5205 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R0, 0);
5206 sljit_x86_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R0, SLJIT_MEM1(SLJIT_S0), 0);
5207 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
5208 sljit_x86_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R0, SLJIT_IMM, -135);
5209 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R0, 0);
5210
5211 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 177);
5212 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 177);
5213 sljit_x86_emit_cmov(compiler, SLJIT_LESS32, SLJIT_R0 | SLJIT_I32_OP, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_s32));
5214 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_s32), SLJIT_R0, 0);
5215
5216 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 177);
5217 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 177);
5218 sljit_x86_emit_cmov(compiler, SLJIT_GREATER32, SLJIT_R0 | SLJIT_I32_OP, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_s32));
5219 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_s32), SLJIT_R0, 0);
5220
5221 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 177);
5222 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_LESS_EQUAL, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 177);
5223 sljit_x86_emit_cmov(compiler, SLJIT_LESS_EQUAL32, SLJIT_R0 | SLJIT_I32_OP, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_s32));
5224 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32), SLJIT_R0, 0);
5225
5226 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 5 * sizeof(sljit_s32));
5227 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_GREATER_EQUAL, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
5228 sljit_x86_emit_cmov(compiler, SLJIT_GREATER_EQUAL32, SLJIT_R0 | SLJIT_I32_OP, SLJIT_MEM2(SLJIT_S1, SLJIT_R1), 0);
5229 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_R0, 0);
5230 }
5231 #endif
5232
5233 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5234
5235 code.code = sljit_generate_code(compiler);
5236 CHECK(compiler);
5237 sljit_free_compiler(compiler);
5238
5239 code.func2((sljit_sw)&buf, (sljit_sw)&ibuf);
5240
5241 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
5242 if (sljit_x86_is_cmov_available()) {
5243 FAILED(buf[1] != 17, "test54 case 1 failed\n");
5244 FAILED(buf[2] != 34, "test54 case 2 failed\n");
5245 FAILED(buf[3] != 24, "test54 case 3 failed\n");
5246 FAILED(buf[4] != 98, "test54 case 4 failed\n");
5247 FAILED(buf[5] != -135, "test54 case 5 failed\n");
5248 FAILED(ibuf[0] != 38, "test54 case 6 failed\n");
5249 FAILED(ibuf[1] != 67, "test54 case 7 failed\n");
5250 FAILED(ibuf[2] != 177, "test54 case 8 failed\n");
5251 FAILED(ibuf[3] != 177, "test54 case 9 failed\n");
5252 }
5253 #endif
5254
5255 sljit_free_code(code.code);
5256 successful_tests++;
5257 }
5258
5259 static void test55(void)
5260 {
5261 /* Check value preservation. */
5262 executable_code code;
5263 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5264 sljit_sw buf[2];
5265 sljit_s32 i;
5266
5267 if (verbose)
5268 printf("Run test55\n");
5269
5270 FAILED(!compiler, "cannot create compiler\n");
5271 buf[0] = 0;
5272 buf[1] = 0;
5273
5274 sljit_emit_enter(compiler, 0, 0, SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0, sizeof (sljit_sw));
5275
5276 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 217);
5277
5278 /* Check 1 */
5279 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5280 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 118);
5281
5282 sljit_emit_op0(compiler, SLJIT_DIVMOD_SW);
5283
5284 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
5285
5286 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5287 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
5288 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_SP), 0);
5289
5290 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)(buf + 0), SLJIT_R0, 0);
5291
5292 /* Check 2 */
5293 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5294 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 146);
5295
5296 sljit_emit_op0(compiler, SLJIT_DIV_SW);
5297
5298 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
5299
5300 for (i = 1; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5301 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
5302 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_SP), 0);
5303
5304 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)(buf + 1), SLJIT_R0, 0);
5305
5306 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5307
5308 code.code = sljit_generate_code(compiler);
5309 CHECK(compiler);
5310 sljit_free_compiler(compiler);
5311
5312 code.func0();
5313
5314 FAILED(buf[0] != (SLJIT_NUMBER_OF_REGISTERS - 2) * 118 + 217, "test55 case 1 failed\n");
5315 FAILED(buf[1] != (SLJIT_NUMBER_OF_REGISTERS - 1) * 146 + 217, "test55 case 2 failed\n");
5316
5317 sljit_free_code(code.code);
5318 successful_tests++;
5319 }
5320
5321 void sljit_test(int argc, char* argv[])
5322 {
5323 sljit_s32 has_arg = (argc >= 2 && argv[1][0] == '-' && argv[1][2] == '\0');
5324 verbose = has_arg && argv[1][1] == 'v';
5325 silent = has_arg && argv[1][1] == 's';
5326
5327 if (!verbose && !silent)
5328 printf("Pass -v to enable verbose, -s to disable this hint.\n\n");
5329
5330 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
5331 test_exec_allocator();
5332 #endif
5333 test1();
5334 test2();
5335 test3();
5336 test4();
5337 test5();
5338 test6();
5339 test7();
5340 test8();
5341 test9();
5342 test10();
5343 test11();
5344 test12();
5345 test13();
5346 test14();
5347 test15();
5348 test16();
5349 test17();
5350 test18();
5351 test19();
5352 test20();
5353 test21();
5354 test22();
5355 test23();
5356 test24();
5357 test25();
5358 test26();
5359 test27();
5360 test28();
5361 test29();
5362 test30();
5363 test31();
5364 test32();
5365 test33();
5366 test34();
5367 test35();
5368 test36();
5369 test37();
5370 test38();
5371 test39();
5372 test40();
5373 test41();
5374 test42();
5375 test43();
5376 test44();
5377 test45();
5378 test46();
5379 test47();
5380 test48();
5381 test49();
5382 test50();
5383 test51();
5384 test52();
5385 test53();
5386 test54();
5387 test55();
5388
5389 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
5390 sljit_free_unused_memory_exec();
5391 #endif
5392
5393 # define TEST_COUNT 55
5394
5395 printf("SLJIT tests: ");
5396 if (successful_tests == TEST_COUNT)
5397 printf("all tests are " COLOR_GREEN "PASSED" COLOR_DEFAULT " ");
5398 else
5399 printf(COLOR_RED "%d" COLOR_DEFAULT " (" COLOR_RED "%d%%" COLOR_DEFAULT ") tests are " COLOR_RED "FAILED" COLOR_DEFAULT " ", TEST_COUNT - successful_tests, (TEST_COUNT - successful_tests) * 100 / 47);
5400 printf("on " COLOR_ARCH "%s" COLOR_DEFAULT "%s\n", sljit_get_platform_name(), sljit_is_fpu_available() ? " (with fpu)" : " (without fpu)");
5401
5402 # undef TEST_COUNT
5403 }
5404