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