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