2 * Stack-less Just-In-Time compiler
4 * Copyright Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
6 * Redistribution and use in source and binary forms, with or without modification, are
7 * permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright notice, this list of
10 * conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 * of conditions and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 /* Must be the first one. Must not depend on any other include. */
34 #if defined _WIN32 || defined _WIN64
40 #define COLOR_RED "\33[31m"
41 #define COLOR_GREEN "\33[32m"
42 #define COLOR_ARCH "\33[33m"
43 #define COLOR_DEFAULT "\33[0m"
46 union executable_code
{
48 sljit_sw (SLJIT_CALL
*func0
)(void);
49 sljit_sw (SLJIT_CALL
*func1
)(sljit_sw a
);
50 sljit_sw (SLJIT_CALL
*func2
)(sljit_sw a
, sljit_sw b
);
51 sljit_sw (SLJIT_CALL
*func3
)(sljit_sw a
, sljit_sw b
, sljit_sw c
);
53 typedef union executable_code executable_code
;
55 static sljit_s32 successful_tests
= 0;
56 static sljit_s32 verbose
= 0;
57 static sljit_s32 silent
= 0;
59 #define FAILED(cond, text) \
60 if (SLJIT_UNLIKELY(cond)) { \
65 #define CHECK(compiler) \
66 if (sljit_get_compiler_error(compiler) != SLJIT_ERR_COMPILED) { \
67 printf("Compiler error: %d\n", sljit_get_compiler_error(compiler)); \
68 sljit_free_compiler(compiler); \
72 static void cond_set(struct sljit_compiler
*compiler
, sljit_s32 dst
, sljit_sw dstw
, sljit_s32 type
)
74 /* Testing both sljit_emit_op_flags and sljit_emit_jump. */
75 struct sljit_jump
* jump
;
76 struct sljit_label
* label
;
78 sljit_emit_op_flags(compiler
, SLJIT_MOV
, dst
, dstw
, SLJIT_UNUSED
, 0, type
);
79 jump
= sljit_emit_jump(compiler
, type
);
80 sljit_emit_op2(compiler
, SLJIT_ADD
, dst
, dstw
, dst
, dstw
, SLJIT_IMM
, 2);
81 label
= sljit_emit_label(compiler
);
82 sljit_set_label(jump
, label
);
85 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
87 #define MALLOC_EXEC(result, size) \
88 result = SLJIT_MALLOC_EXEC(size); \
90 printf("Cannot allocate executable memory\n"); \
93 memset(result, 255, size);
95 #define FREE_EXEC(ptr) \
96 SLJIT_FREE_EXEC(((sljit_u8*)(ptr)) + SLJIT_EXEC_OFFSET(ptr));
98 static void test_exec_allocator(void)
100 /* This is not an sljit test. */
106 printf("Run executable allocator test\n");
108 MALLOC_EXEC(ptr1
, 32);
109 MALLOC_EXEC(ptr2
, 512);
110 MALLOC_EXEC(ptr3
, 512);
114 MALLOC_EXEC(ptr1
, 262104);
115 MALLOC_EXEC(ptr2
, 32000);
117 MALLOC_EXEC(ptr1
, 262104);
120 MALLOC_EXEC(ptr1
, 512);
121 MALLOC_EXEC(ptr2
, 512);
122 MALLOC_EXEC(ptr3
, 512);
124 MALLOC_EXEC(ptr2
, 512);
125 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
126 sljit_free_unused_memory_exec();
131 #if (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK)
132 /* Just call the global locks. */
134 sljit_release_lock();
137 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
138 sljit_free_unused_memory_exec();
144 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
146 static void test1(void)
148 /* Enter and return from an sljit function. */
149 executable_code code
;
150 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
153 printf("Run test1\n");
155 FAILED(!compiler
, "cannot create compiler\n");
157 /* 3 arguments passed, 3 arguments used. */
158 sljit_emit_enter(compiler
, 0, 3, 3, 3, 0, 0, 0);
159 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_S1
, 0);
161 SLJIT_ASSERT(sljit_get_generated_code_size(compiler
) == 0);
162 code
.code
= sljit_generate_code(compiler
);
164 SLJIT_ASSERT(compiler
->error
== SLJIT_ERR_COMPILED
);
165 SLJIT_ASSERT(sljit_get_generated_code_size(compiler
) > 0);
166 sljit_free_compiler(compiler
);
168 FAILED(code
.func3(3, -21, 86) != -21, "test1 case 1 failed\n");
169 FAILED(code
.func3(4789, 47890, 997) != 47890, "test1 case 2 failed\n");
171 sljit_free_code(code
.code
);
175 static void test2(void)
178 executable_code code
;
179 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
181 static sljit_sw data
[2] = { 0, -9876 };
184 printf("Run test2\n");
186 FAILED(!compiler
, "cannot create compiler\n");
196 sljit_emit_enter(compiler
, 0, 1, 3, 2, 0, 0, 0);
197 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_UNUSED
, 0, SLJIT_MEM0(), (sljit_sw
)&buf
);
198 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 9999);
199 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_S0
, 0);
200 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
), SLJIT_R0
, 0);
201 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
202 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_MEM2(SLJIT_S1
, SLJIT_R1
), 0);
203 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 2);
204 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_S1
, SLJIT_S0
), SLJIT_WORD_SHIFT
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R1
), 0);
205 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 3);
206 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_S1
, SLJIT_S0
), SLJIT_WORD_SHIFT
, SLJIT_MEM0(), (sljit_sw
)&buf
);
207 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
208 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&data
);
209 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
210 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
- 0x12345678);
211 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R0
), 0x12345678);
212 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_R0
, 0);
213 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3456);
214 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
- 0xff890 + 6 * sizeof(sljit_sw
));
215 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0xff890, SLJIT_R0
, 0);
216 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
+ 0xff890 + 7 * sizeof(sljit_sw
));
217 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), -0xff890, SLJIT_R0
, 0);
218 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R2
, 0);
220 code
.code
= sljit_generate_code(compiler
);
222 sljit_free_compiler(compiler
);
224 FAILED(code
.func1((sljit_sw
)&buf
) != 9999, "test2 case 1 failed\n");
225 FAILED(buf
[1] != 9999, "test2 case 2 failed\n");
226 FAILED(buf
[2] != 9999, "test2 case 3 failed\n");
227 FAILED(buf
[3] != 5678, "test2 case 4 failed\n");
228 FAILED(buf
[4] != -9876, "test2 case 5 failed\n");
229 FAILED(buf
[5] != 5678, "test2 case 6 failed\n");
230 FAILED(buf
[6] != 3456, "test2 case 6 failed\n");
231 FAILED(buf
[7] != 3456, "test2 case 6 failed\n");
233 sljit_free_code(code
.code
);
237 static void test3(void)
240 executable_code code
;
241 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
245 printf("Run test3\n");
247 FAILED(!compiler
, "cannot create compiler\n");
254 sljit_emit_enter(compiler
, 0, 1, 3, 1, 0, 0, 0);
255 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_UNUSED
, 0, SLJIT_MEM0(), (sljit_sw
)&buf
);
256 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 0);
257 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_MEM0(), (sljit_sw
)&buf
[1], SLJIT_MEM0(), (sljit_sw
)&buf
[1]);
258 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_RETURN_REG
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
259 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2);
260 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[4] - 0xff0000 - 0x20);
261 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[4] - 0xff0000);
262 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_MEM1(SLJIT_R1
), 0xff0000 + 0x20, SLJIT_MEM1(SLJIT_R2
), 0xff0000);
263 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
265 code
.code
= sljit_generate_code(compiler
);
267 sljit_free_compiler(compiler
);
269 FAILED(code
.func1((sljit_sw
)&buf
) != ~1234, "test3 case 1 failed\n");
270 FAILED(buf
[1] != ~1234, "test3 case 2 failed\n");
271 FAILED(buf
[3] != ~9876, "test3 case 3 failed\n");
272 FAILED(buf
[4] != ~0x12345678, "test3 case 4 failed\n");
274 sljit_free_code(code
.code
);
278 static void test4(void)
281 executable_code code
;
282 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
286 printf("Run test4\n");
288 FAILED(!compiler
, "cannot create compiler\n");
294 sljit_emit_enter(compiler
, 0, 2, 3, 2, 0, 0, 0);
295 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
296 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_S1
, 0);
297 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_MEM0(), (sljit_sw
)&buf
[0], SLJIT_MEM0(), (sljit_sw
)&buf
[1]);
298 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_RETURN_REG
, 0, SLJIT_S1
, 0);
299 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_IMM
, 299);
300 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
302 code
.code
= sljit_generate_code(compiler
);
304 sljit_free_compiler(compiler
);
306 FAILED(code
.func2((sljit_sw
)&buf
, 4567) != -4567, "test4 case 1 failed\n");
307 FAILED(buf
[0] != -1234, "test4 case 2 failed\n");
308 FAILED(buf
[2] != -4567, "test4 case 3 failed\n");
309 FAILED(buf
[3] != -299, "test4 case 4 failed\n");
311 sljit_free_code(code
.code
);
315 static void test5(void)
318 executable_code code
;
319 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
323 printf("Run test5\n");
325 FAILED(!compiler
, "cannot create compiler\n");
336 sljit_emit_enter(compiler
, 0, 1, 3, 2, 0, 0, 0);
337 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_UNUSED
, 0, SLJIT_IMM
, 16, SLJIT_IMM
, 16);
338 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_UNUSED
, 0, SLJIT_IMM
, 255, SLJIT_IMM
, 255);
339 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_UNUSED
, 0, SLJIT_S0
, 0, SLJIT_S0
, 0);
340 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
341 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 50);
342 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 1, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 1, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 0);
343 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
) + 2);
344 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 50);
345 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
346 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
347 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_IMM
, 4, SLJIT_R0
, 0);
348 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_IMM
, 50, SLJIT_R1
, 0);
349 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_IMM
, 50, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
));
350 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R1
, 0);
351 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
));
352 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
));
353 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R1
, 0);
354 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x1e7d39f2);
355 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R1
, 0, SLJIT_IMM
, 0x23de7c06);
356 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, 0x3d72e452, SLJIT_R1
, 0);
357 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_IMM
, -43, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
));
358 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_IMM
, 1000, SLJIT_R0
, 0);
359 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1430);
360 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_IMM
, -99, SLJIT_R0
, 0);
362 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
364 code
.code
= sljit_generate_code(compiler
);
366 sljit_free_compiler(compiler
);
368 FAILED(code
.func1((sljit_sw
)&buf
) != 2437 + 2 * sizeof(sljit_sw
), "test5 case 1 failed\n");
369 FAILED(buf
[0] != 202 + 2 * sizeof(sljit_sw
), "test5 case 2 failed\n");
370 FAILED(buf
[2] != 500, "test5 case 3 failed\n");
371 FAILED(buf
[3] != 400, "test5 case 4 failed\n");
372 FAILED(buf
[4] != 200, "test5 case 5 failed\n");
373 FAILED(buf
[5] != 250, "test5 case 6 failed\n");
374 FAILED(buf
[6] != 0x425bb5f8, "test5 case 7 failed\n");
375 FAILED(buf
[7] != 0x5bf01e44, "test5 case 8 failed\n");
376 FAILED(buf
[8] != 270, "test5 case 9 failed\n");
378 sljit_free_code(code
.code
);
382 static void test6(void)
384 /* Test addc, sub, subc. */
385 executable_code code
;
386 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
390 printf("Run test6\n");
392 FAILED(!compiler
, "cannot create compiler\n");
404 sljit_emit_enter(compiler
, 0, 1, 3, 1, 0, 0, 0);
405 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
406 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -1);
407 sljit_emit_op2(compiler
, SLJIT_ADDC
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0, SLJIT_IMM
, 0);
408 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R0
, 0);
409 sljit_emit_op2(compiler
, SLJIT_ADDC
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 4);
410 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 100);
411 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, SLJIT_IMM
, 50);
412 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 6000);
413 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_IMM
, 10);
414 sljit_emit_op2(compiler
, SLJIT_SUBC
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_IMM
, 5);
415 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 100);
416 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2);
417 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R0
, 0);
418 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5000);
419 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R0
, 0);
420 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
421 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R1
, 0);
422 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5000);
423 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_IMM
, 6000, SLJIT_R0
, 0);
424 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_R0
, 0);
425 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 100);
426 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 32768);
427 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_R1
, 0);
428 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -32767);
429 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_R1
, 0);
430 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x52cd3bf4);
431 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_R0
, 0, SLJIT_IMM
, 0x3da297c6);
432 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 10);
433 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_RETURN_REG
, 0, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 5);
434 sljit_emit_op2(compiler
, SLJIT_SUBC
, SLJIT_RETURN_REG
, 0, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 2);
435 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_RETURN_REG
, 0, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, -2220);
436 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
438 code
.code
= sljit_generate_code(compiler
);
440 sljit_free_compiler(compiler
);
442 FAILED(code
.func1((sljit_sw
)&buf
) != 2223, "test6 case 1 failed\n");
443 FAILED(buf
[0] != 1, "test6 case 2 failed\n");
444 FAILED(buf
[1] != 5, "test6 case 3 failed\n");
445 FAILED(buf
[2] != 50, "test6 case 4 failed\n");
446 FAILED(buf
[3] != 4, "test6 case 5 failed\n");
447 FAILED(buf
[4] != 50, "test6 case 6 failed\n");
448 FAILED(buf
[5] != 50, "test6 case 7 failed\n");
449 FAILED(buf
[6] != 1000, "test6 case 8 failed\n");
450 FAILED(buf
[7] != 100 - 32768, "test6 case 9 failed\n");
451 FAILED(buf
[8] != 100 + 32767, "test6 case 10 failed\n");
452 FAILED(buf
[9] != 0x152aa42e, "test6 case 11 failed\n");
454 sljit_free_code(code
.code
);
458 static void test7(void)
460 /* Test logical operators. */
461 executable_code code
;
462 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
466 printf("Run test7\n");
468 FAILED(!compiler
, "cannot create compiler\n");
478 sljit_emit_enter(compiler
, 0, 1, 3, 1, 0, 0, 0);
479 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xf0C000);
480 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, SLJIT_IMM
, 0x308f);
481 sljit_emit_op2(compiler
, SLJIT_XOR
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
482 sljit_emit_op2(compiler
, SLJIT_AND
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_IMM
, 0xf0f0f0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3);
483 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xC0F0);
484 sljit_emit_op2(compiler
, SLJIT_XOR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5);
485 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xff0000);
486 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R0
, 0);
487 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0xC0F0);
488 sljit_emit_op2(compiler
, SLJIT_AND
, SLJIT_R2
, 0, SLJIT_R2
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5);
489 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R2
, 0, SLJIT_IMM
, 0xff0000);
490 sljit_emit_op2(compiler
, SLJIT_XOR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 0xFFFFFF, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
491 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_IMM
, 0xa56c82c0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6);
492 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7);
493 sljit_emit_op2(compiler
, SLJIT_XOR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_IMM
, 0xff00ff00, SLJIT_R0
, 0);
494 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xff00ff00);
495 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x0f);
496 sljit_emit_op2(compiler
, SLJIT_AND
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0x888888, SLJIT_R1
, 0);
497 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
499 code
.code
= sljit_generate_code(compiler
);
501 sljit_free_compiler(compiler
);
503 FAILED(code
.func1((sljit_sw
)&buf
) != 0x8808, "test7 case 1 failed\n");
504 FAILED(buf
[0] != 0x0F807F00, "test7 case 2 failed\n");
505 FAILED(buf
[1] != 0x0F7F7F7F, "test7 case 3 failed\n");
506 FAILED(buf
[2] != 0x00F0F08F, "test7 case 4 failed\n");
507 FAILED(buf
[3] != 0x00A0A0A0, "test7 case 5 failed\n");
508 FAILED(buf
[4] != 0x00FF80B0, "test7 case 6 failed\n");
509 FAILED(buf
[5] != 0x00FF4040, "test7 case 7 failed\n");
510 FAILED(buf
[6] != 0xa56c82c0, "test7 case 8 failed\n");
511 FAILED(buf
[7] != 0x3b3a8095, "test7 case 9 failed\n");
513 sljit_free_code(code
.code
);
517 static void test8(void)
519 /* Test flags (neg, cmp, test). */
520 executable_code code
;
521 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
525 printf("Run test8\n");
527 FAILED(!compiler
, "cannot create compiler\n");
542 sljit_emit_enter(compiler
, 0, 1, 3, 2, 0, 0, 0);
543 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 20);
544 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 10);
545 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_IMM
, 6, SLJIT_IMM
, 5);
546 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_UNUSED
, 0, SLJIT_NOT_EQUAL
);
547 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_UNUSED
, 0, SLJIT_EQUAL
);
548 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 3000);
549 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_UNUSED
, 0, SLJIT_GREATER
);
550 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 3000);
551 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_S1
, 0);
552 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_UNUSED
, 0, SLJIT_LESS
);
553 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R2
, 0);
554 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -15);
555 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_UNUSED
, 0, SLJIT_SIG_GREATER
);
556 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R2
, 0);
557 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
558 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
559 sljit_emit_op1(compiler
, SLJIT_NEG
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_IMM
, (sljit_sw
)1 << ((sizeof(sljit_sw
) << 3) - 1));
560 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_UNUSED
, 0, SLJIT_OVERFLOW
);
561 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
562 sljit_emit_op1(compiler
, SLJIT_NOT
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R0
, 0);
563 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_UNUSED
, 0, SLJIT_ZERO
);
564 sljit_emit_op1(compiler
, SLJIT_NOT
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0);
565 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_UNUSED
, 0, SLJIT_ZERO
);
566 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_IMM
, 0xffff, SLJIT_R0
, 0);
567 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffff);
568 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_UNUSED
, 0, SLJIT_NOT_ZERO
);
569 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_IMM
, 0xffff, SLJIT_R1
, 0);
570 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 0xffff);
571 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
572 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
573 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
574 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0x1);
575 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, SLJIT_UNUSED
, 0, SLJIT_NOT_ZERO
);
576 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(1) << ((sizeof(sljit_sw
) << 3) - 1));
577 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
578 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
579 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 11, SLJIT_UNUSED
, 0, SLJIT_OVERFLOW
);
580 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
581 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 12, SLJIT_UNUSED
, 0, SLJIT_OVERFLOW
);
582 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
584 code
.code
= sljit_generate_code(compiler
);
586 sljit_free_compiler(compiler
);
588 code
.func1((sljit_sw
)&buf
);
589 FAILED(buf
[1] != 1, "test8 case 1 failed\n");
590 FAILED(buf
[2] != 0, "test8 case 2 failed\n");
591 FAILED(buf
[3] != 0, "test8 case 3 failed\n");
592 FAILED(buf
[4] != 1, "test8 case 4 failed\n");
593 FAILED(buf
[5] != 1, "test8 case 5 failed\n");
594 FAILED(buf
[6] != 1, "test8 case 6 failed\n");
595 FAILED(buf
[7] != 1, "test8 case 7 failed\n");
596 FAILED(buf
[8] != 0, "test8 case 8 failed\n");
597 FAILED(buf
[9] != 1, "test8 case 9 failed\n");
598 FAILED(buf
[10] != 0, "test8 case 10 failed\n");
599 FAILED(buf
[11] != 1, "test8 case 11 failed\n");
600 FAILED(buf
[12] != 0, "test8 case 12 failed\n");
602 sljit_free_code(code
.code
);
606 static void test9(void)
609 executable_code code
;
610 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
614 printf("Run test9\n");
616 FAILED(!compiler
, "cannot create compiler\n");
631 sljit_emit_enter(compiler
, 0, 1, 3, 2, 0, 0, 0);
632 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xf);
633 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 3);
634 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
635 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
636 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 2);
637 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
638 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R1
, 0, SLJIT_IMM
, 1);
639 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -64);
640 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_PREF_SHIFT_REG
, 0, SLJIT_IMM
, 2);
641 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, SLJIT_PREF_SHIFT_REG
, 0);
643 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_PREF_SHIFT_REG
, 0, SLJIT_IMM
, 0xff);
644 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
645 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_PREF_SHIFT_REG
, 0, SLJIT_PREF_SHIFT_REG
, 0, SLJIT_R0
, 0);
646 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_PREF_SHIFT_REG
, 0);
647 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_PREF_SHIFT_REG
, 0, SLJIT_IMM
, 0xff);
648 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
649 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R0
, 0);
650 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_PREF_SHIFT_REG
, 0, SLJIT_R0
, 0);
652 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, 0xf);
653 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
654 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_S1
, 0, SLJIT_S1
, 0, SLJIT_R0
, 0);
655 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_S1
, 0);
656 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_R0
, 0);
657 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_R0
, 0);
658 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0xf00);
659 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
660 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R1
, 0, SLJIT_R2
, 0, SLJIT_R0
, 0);
661 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_R1
, 0);
663 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)buf
);
664 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 9);
665 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), SLJIT_WORD_SHIFT
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), SLJIT_WORD_SHIFT
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), SLJIT_WORD_SHIFT
);
667 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_PREF_SHIFT_REG
, 0, SLJIT_IMM
, 4);
668 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_PREF_SHIFT_REG
, 0, SLJIT_IMM
, 2, SLJIT_PREF_SHIFT_REG
, 0);
669 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, SLJIT_PREF_SHIFT_REG
, 0);
671 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xa9);
672 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
673 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x7d00);
674 sljit_emit_op2(compiler
, SLJIT_LSHR32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 32);
675 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
676 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
678 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
679 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xe30000);
680 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
681 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffc0);
683 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffe0);
685 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
686 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x25000000);
687 sljit_emit_op2(compiler
, SLJIT_SHL32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xfffe1);
688 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
689 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
691 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 11, SLJIT_R1
, 0, SLJIT_R0
, 0);
693 SLJIT_ASSERT(SLJIT_R2
== SLJIT_PREF_SHIFT_REG
);
694 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_PREF_SHIFT_REG
, 0, SLJIT_IMM
, 0);
695 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x5c);
696 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_PREF_SHIFT_REG
, 0);
697 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0xf600);
698 sljit_emit_op2(compiler
, SLJIT_LSHR32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_PREF_SHIFT_REG
, 0);
699 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
700 /* Alternative form of uint32 type cast. */
701 sljit_emit_op2(compiler
, SLJIT_AND
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffffffff);
703 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
704 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x630000);
705 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_PREF_SHIFT_REG
, 0);
706 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 12, SLJIT_R1
, 0, SLJIT_R0
, 0);
708 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
710 code
.code
= sljit_generate_code(compiler
);
712 sljit_free_compiler(compiler
);
714 code
.func1((sljit_sw
)&buf
);
715 FAILED(buf
[0] != 0x3c, "test9 case 1 failed\n");
716 FAILED(buf
[1] != 0xf0, "test9 case 2 failed\n");
717 FAILED(buf
[2] != -16, "test9 case 3 failed\n");
718 FAILED(buf
[3] != 0xff0, "test9 case 4 failed\n");
719 FAILED(buf
[4] != 4, "test9 case 5 failed\n");
720 FAILED(buf
[5] != 0xff00, "test9 case 6 failed\n");
721 FAILED(buf
[6] != 0x3c, "test9 case 7 failed\n");
722 FAILED(buf
[7] != 0xf0, "test9 case 8 failed\n");
723 FAILED(buf
[8] != 0xf0, "test9 case 9 failed\n");
724 FAILED(buf
[9] != 0x18, "test9 case 10 failed\n");
725 FAILED(buf
[10] != 32, "test9 case 11 failed\n");
726 FAILED(buf
[11] != 0x4ae37da9, "test9 case 12 failed\n");
727 FAILED(buf
[12] != 0x63f65c, "test9 case 13 failed\n");
729 sljit_free_code(code
.code
);
733 static void test10(void)
735 /* Test multiplications. */
736 executable_code code
;
737 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
741 printf("Run test10\n");
743 FAILED(!compiler
, "cannot create compiler\n");
752 sljit_emit_enter(compiler
, 0, 1, 3, 1, 0, 0, 0);
753 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
754 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
755 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
756 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 7);
757 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 8);
758 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
759 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_IMM
, -3, SLJIT_IMM
, -4);
760 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0);
761 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -2);
762 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_R0
, 0);
763 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
) / 2);
764 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[3]);
765 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 1, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 1, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 1);
766 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 9);
767 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R0
, 0);
768 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R0
, 0);
769 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
770 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3);
771 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x123456789));
772 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_R0
, 0);
774 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 11, SLJIT_IMM
, 10);
775 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
777 code
.code
= sljit_generate_code(compiler
);
779 sljit_free_compiler(compiler
);
781 FAILED(code
.func1((sljit_sw
)&buf
) != 110, "test10 case 1 failed\n");
782 FAILED(buf
[0] != 15, "test10 case 2 failed\n");
783 FAILED(buf
[1] != 56, "test10 case 3 failed\n");
784 FAILED(buf
[2] != 12, "test10 case 4 failed\n");
785 FAILED(buf
[3] != -12, "test10 case 5 failed\n");
786 FAILED(buf
[4] != 100, "test10 case 6 failed\n");
787 FAILED(buf
[5] != 81, "test10 case 7 failed\n");
788 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
789 FAILED(buf
[6] != SLJIT_W(0x123456789) * 3, "test10 case 8 failed\n");
792 sljit_free_code(code
.code
);
796 static void test11(void)
798 /* Test rewritable constants. */
799 executable_code code
;
800 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
801 struct sljit_const
* const1
;
802 struct sljit_const
* const2
;
803 struct sljit_const
* const3
;
804 struct sljit_const
* const4
;
806 sljit_sw executable_offset
;
807 sljit_uw const1_addr
;
808 sljit_uw const2_addr
;
809 sljit_uw const3_addr
;
810 sljit_uw const4_addr
;
811 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
812 sljit_sw word_value1
= SLJIT_W(0xaaaaaaaaaaaaaaaa);
813 sljit_sw word_value2
= SLJIT_W(0xfee1deadfbadf00d);
815 sljit_sw word_value1
= 0xaaaaaaaal
;
816 sljit_sw word_value2
= 0xfbadf00dl
;
821 printf("Run test11\n");
823 FAILED(!compiler
, "cannot create compiler\n");
828 sljit_emit_enter(compiler
, 0, 1, 3, 1, 0, 0, 0);
830 SLJIT_ASSERT(!sljit_alloc_memory(compiler
, 0));
831 SLJIT_ASSERT(!sljit_alloc_memory(compiler
, 16 * sizeof(sljit_sw
) + 1));
833 const1
= sljit_emit_const(compiler
, SLJIT_MEM0(), (sljit_sw
)&buf
[0], -0x81b9);
835 value
= sljit_alloc_memory(compiler
, 16 * sizeof(sljit_sw
));
838 SLJIT_ASSERT(!((sljit_sw
)value
& (sizeof(sljit_sw
) - 1)));
839 memset(value
, 255, 16 * sizeof(sljit_sw
));
842 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
843 const2
= sljit_emit_const(compiler
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), SLJIT_WORD_SHIFT
- 1, -65535);
844 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[0] + 2 * sizeof(sljit_sw
) - 2);
845 const3
= sljit_emit_const(compiler
, SLJIT_MEM1(SLJIT_R0
), 0, word_value1
);
847 value
= sljit_alloc_memory(compiler
, 17);
850 SLJIT_ASSERT(!((sljit_sw
)value
& (sizeof(sljit_sw
) - 1)));
851 memset(value
, 255, 16);
854 const4
= sljit_emit_const(compiler
, SLJIT_RETURN_REG
, 0, 0xf7afcdb7);
856 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
858 code
.code
= sljit_generate_code(compiler
);
860 executable_offset
= sljit_get_executable_offset(compiler
);
861 const1_addr
= sljit_get_const_addr(const1
);
862 const2_addr
= sljit_get_const_addr(const2
);
863 const3_addr
= sljit_get_const_addr(const3
);
864 const4_addr
= sljit_get_const_addr(const4
);
865 sljit_free_compiler(compiler
);
867 FAILED(code
.func1((sljit_sw
)&buf
) != 0xf7afcdb7, "test11 case 1 failed\n");
868 FAILED(buf
[0] != -0x81b9, "test11 case 2 failed\n");
869 FAILED(buf
[1] != -65535, "test11 case 3 failed\n");
870 FAILED(buf
[2] != word_value1
, "test11 case 4 failed\n");
872 sljit_set_const(const1_addr
, -1, executable_offset
);
873 sljit_set_const(const2_addr
, word_value2
, executable_offset
);
874 sljit_set_const(const3_addr
, 0xbab0fea1, executable_offset
);
875 sljit_set_const(const4_addr
, -60089, executable_offset
);
877 FAILED(code
.func1((sljit_sw
)&buf
) != -60089, "test11 case 5 failed\n");
878 FAILED(buf
[0] != -1, "test11 case 6 failed\n");
879 FAILED(buf
[1] != word_value2
, "test11 case 7 failed\n");
880 FAILED(buf
[2] != 0xbab0fea1, "test11 case 8 failed\n");
882 sljit_free_code(code
.code
);
886 static void test12(void)
888 /* Test rewriteable jumps. */
889 executable_code code
;
890 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
891 struct sljit_label
*label1
;
892 struct sljit_label
*label2
;
893 struct sljit_label
*label3
;
894 struct sljit_jump
*jump1
;
895 struct sljit_jump
*jump2
;
896 struct sljit_jump
*jump3
;
897 sljit_sw executable_offset
;
900 sljit_uw label1_addr
;
901 sljit_uw label2_addr
;
905 printf("Run test12\n");
907 FAILED(!compiler
, "cannot create compiler\n");
910 sljit_emit_enter(compiler
, 0, 2, 3, 2, 0, 0, 0);
911 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_UNUSED
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 10);
912 jump1
= sljit_emit_jump(compiler
, SLJIT_REWRITABLE_JUMP
| SLJIT_SIG_GREATER
);
913 /* Default handler. */
914 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 5);
915 jump2
= sljit_emit_jump(compiler
, SLJIT_JUMP
);
917 value
= sljit_alloc_memory(compiler
, 15);
920 SLJIT_ASSERT(!((sljit_sw
)value
& (sizeof(sljit_sw
) - 1)));
921 memset(value
, 255, 15);
925 label1
= sljit_emit_label(compiler
);
926 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 6);
927 jump3
= sljit_emit_jump(compiler
, SLJIT_JUMP
);
929 label2
= sljit_emit_label(compiler
);
930 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 7);
932 label3
= sljit_emit_label(compiler
);
933 sljit_set_label(jump2
, label3
);
934 sljit_set_label(jump3
, label3
);
935 /* By default, set to handler 1. */
936 sljit_set_label(jump1
, label1
);
937 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
939 value
= sljit_alloc_memory(compiler
, 8);
942 SLJIT_ASSERT(!((sljit_sw
)value
& (sizeof(sljit_sw
) - 1)));
943 memset(value
, 255, 8);
946 code
.code
= sljit_generate_code(compiler
);
948 executable_offset
= sljit_get_executable_offset(compiler
);
949 jump1_addr
= sljit_get_jump_addr(jump1
);
950 label1_addr
= sljit_get_label_addr(label1
);
951 label2_addr
= sljit_get_label_addr(label2
);
952 sljit_free_compiler(compiler
);
954 code
.func2((sljit_sw
)&buf
, 4);
955 FAILED(buf
[0] != 5, "test12 case 1 failed\n");
957 code
.func2((sljit_sw
)&buf
, 11);
958 FAILED(buf
[0] != 6, "test12 case 2 failed\n");
960 sljit_set_jump_addr(jump1_addr
, label2_addr
, executable_offset
);
961 code
.func2((sljit_sw
)&buf
, 12);
962 FAILED(buf
[0] != 7, "test12 case 3 failed\n");
964 sljit_set_jump_addr(jump1_addr
, label1_addr
, executable_offset
);
965 code
.func2((sljit_sw
)&buf
, 13);
966 FAILED(buf
[0] != 6, "test12 case 4 failed\n");
968 sljit_free_code(code
.code
);
972 static void test13(void)
974 /* Test fpu monadic functions. */
975 executable_code code
;
976 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
981 printf("Run test13\n");
983 if (!sljit_is_fpu_available()) {
985 printf("no fpu available, test13 skipped\n");
988 sljit_free_compiler(compiler
);
992 FAILED(!compiler
, "cannot create compiler\n");
1008 sljit_emit_enter(compiler
, 0, 2, 3, 2, 6, 0, 0);
1009 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&buf
[2], SLJIT_MEM0(), (sljit_sw
)&buf
[1]);
1010 sljit_emit_fop1(compiler
, SLJIT_ABS_F64
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1011 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
1012 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2 * sizeof(sljit_f64
));
1013 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 0);
1014 sljit_emit_fop1(compiler
, SLJIT_NEG_F64
, SLJIT_FR2
, 0, SLJIT_FR0
, 0);
1015 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_FR2
, 0);
1016 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&buf
[4], SLJIT_FR3
, 0);
1017 sljit_emit_fop1(compiler
, SLJIT_ABS_F64
, SLJIT_FR4
, 0, SLJIT_FR1
, 0);
1018 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f64
), SLJIT_FR4
, 0);
1019 sljit_emit_fop1(compiler
, SLJIT_NEG_F64
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
), SLJIT_FR4
, 0);
1021 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
1022 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_GREATER_F
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1023 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_UNUSED
, 0, SLJIT_GREATER_F64
);
1024 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_GREATER_F
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
), SLJIT_FR5
, 0);
1025 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
), SLJIT_UNUSED
, 0, SLJIT_GREATER_F64
);
1026 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_FR5
, 0);
1027 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR1
, 0);
1028 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
), SLJIT_UNUSED
, 0, SLJIT_EQUAL_F64
);
1029 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_LESS_F
, SLJIT_FR1
, 0, SLJIT_FR1
, 0);
1030 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
), SLJIT_UNUSED
, 0, SLJIT_LESS_F64
);
1031 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1032 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_UNUSED
, 0, SLJIT_EQUAL_F64
);
1033 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_NOT_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1034 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_UNUSED
, 0, SLJIT_NOT_EQUAL_F64
);
1036 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
1038 code
.code
= sljit_generate_code(compiler
);
1040 sljit_free_compiler(compiler
);
1042 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&buf2
);
1043 FAILED(buf
[2] != -4.5, "test13 case 1 failed\n");
1044 FAILED(buf
[3] != 4.5, "test13 case 2 failed\n");
1045 FAILED(buf
[4] != -7.75, "test13 case 3 failed\n");
1046 FAILED(buf
[5] != 4.5, "test13 case 4 failed\n");
1047 FAILED(buf
[6] != -4.5, "test13 case 5 failed\n");
1049 FAILED(buf2
[0] != 1, "test13 case 6 failed\n");
1050 FAILED(buf2
[1] != 0, "test13 case 7 failed\n");
1051 FAILED(buf2
[2] != 1, "test13 case 8 failed\n");
1052 FAILED(buf2
[3] != 0, "test13 case 9 failed\n");
1053 FAILED(buf2
[4] != 0, "test13 case 10 failed\n");
1054 FAILED(buf2
[5] != 1, "test13 case 11 failed\n");
1056 sljit_free_code(code
.code
);
1060 static void test14(void)
1062 /* Test fpu diadic functions. */
1063 executable_code code
;
1064 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
1068 printf("Run test14\n");
1070 if (!sljit_is_fpu_available()) {
1072 printf("no fpu available, test14 skipped\n");
1075 sljit_free_compiler(compiler
);
1094 FAILED(!compiler
, "cannot create compiler\n");
1095 sljit_emit_enter(compiler
, 0, 1, 3, 1, 6, 0, 0);
1098 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_f64
));
1099 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1100 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2);
1101 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 3, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
1102 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_FR1
, 0);
1103 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR1
, 0, SLJIT_FR0
, 0, SLJIT_FR1
, 0);
1104 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 4, SLJIT_FR0
, 0);
1105 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 5, SLJIT_FR1
, 0);
1108 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
1109 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2);
1110 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 2);
1111 sljit_emit_fop2(compiler
, SLJIT_SUB_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 6, SLJIT_FR3
, 0, SLJIT_MEM2(SLJIT_S0
, SLJIT_R1
), SLJIT_F64_SHIFT
);
1112 sljit_emit_fop2(compiler
, SLJIT_SUB_F64
, SLJIT_FR2
, 0, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2);
1113 sljit_emit_fop2(compiler
, SLJIT_SUB_F64
, SLJIT_FR3
, 0, SLJIT_FR2
, 0, SLJIT_FR3
, 0);
1114 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 7, SLJIT_FR2
, 0);
1115 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 8, SLJIT_FR3
, 0);
1118 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
1119 sljit_emit_fop2(compiler
, SLJIT_MUL_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 9, SLJIT_MEM2(SLJIT_S0
, SLJIT_R1
), SLJIT_F64_SHIFT
, SLJIT_FR1
, 0);
1120 sljit_emit_fop2(compiler
, SLJIT_MUL_F64
, SLJIT_FR1
, 0, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
1121 sljit_emit_fop2(compiler
, SLJIT_MUL_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2, SLJIT_FR2
, 0);
1122 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 10, SLJIT_FR1
, 0);
1123 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 11, SLJIT_FR5
, 0);
1126 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 12);
1127 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 13);
1128 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR4
, 0, SLJIT_FR5
, 0);
1129 sljit_emit_fop2(compiler
, SLJIT_DIV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 12, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 12, SLJIT_FR1
, 0);
1130 sljit_emit_fop2(compiler
, SLJIT_DIV_F64
, SLJIT_FR5
, 0, SLJIT_FR5
, 0, SLJIT_FR1
, 0);
1131 sljit_emit_fop2(compiler
, SLJIT_DIV_F64
, SLJIT_FR4
, 0, SLJIT_FR1
, 0, SLJIT_FR4
, 0);
1132 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 13, SLJIT_FR5
, 0);
1133 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 14, SLJIT_FR4
, 0);
1135 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
1137 code
.code
= sljit_generate_code(compiler
);
1139 sljit_free_compiler(compiler
);
1141 code
.func1((sljit_sw
)&buf
);
1142 FAILED(buf
[3] != 10.75, "test14 case 1 failed\n");
1143 FAILED(buf
[4] != 5.25, "test14 case 2 failed\n");
1144 FAILED(buf
[5] != 7.0, "test14 case 3 failed\n");
1145 FAILED(buf
[6] != 0.0, "test14 case 4 failed\n");
1146 FAILED(buf
[7] != 5.5, "test14 case 5 failed\n");
1147 FAILED(buf
[8] != 3.75, "test14 case 6 failed\n");
1148 FAILED(buf
[9] != 24.5, "test14 case 7 failed\n");
1149 FAILED(buf
[10] != 38.5, "test14 case 8 failed\n");
1150 FAILED(buf
[11] != 9.625, "test14 case 9 failed\n");
1151 FAILED(buf
[12] != 2.0, "test14 case 10 failed\n");
1152 FAILED(buf
[13] != 2.0, "test14 case 11 failed\n");
1153 FAILED(buf
[14] != 0.5, "test14 case 12 failed\n");
1155 sljit_free_code(code
.code
);
1159 static sljit_sw SLJIT_CALL
func(sljit_sw a
, sljit_sw b
, sljit_sw c
)
1161 return a
+ b
+ c
+ 5;
1164 static void test15(void)
1166 /* Test function call. */
1167 executable_code code
;
1168 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
1169 struct sljit_jump
* jump
= NULL
;
1173 printf("Run test15\n");
1175 FAILED(!compiler
, "cannot create compiler\n");
1182 buf
[6] = SLJIT_FUNC_OFFSET(func
);
1184 sljit_emit_enter(compiler
, 0, 1, 4, 1, 0, 0, 0);
1186 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
1187 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 7);
1188 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -3);
1189 sljit_emit_ijump(compiler
, SLJIT_CALL3
, SLJIT_IMM
, SLJIT_FUNC_OFFSET(func
));
1190 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_RETURN_REG
, 0);
1192 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -5);
1193 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -10);
1194 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2);
1195 jump
= sljit_emit_jump(compiler
, SLJIT_CALL3
| SLJIT_REWRITABLE_JUMP
);
1196 sljit_set_target(jump
, (sljit_sw
)-1);
1197 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1199 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(func
));
1200 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 40);
1201 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -3);
1202 sljit_emit_ijump(compiler
, SLJIT_CALL3
, SLJIT_R0
, 0);
1203 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1205 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -60);
1206 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(func
));
1207 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -30);
1208 sljit_emit_ijump(compiler
, SLJIT_CALL3
, SLJIT_R1
, 0);
1209 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1211 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 10);
1212 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 16);
1213 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(func
));
1214 sljit_emit_ijump(compiler
, SLJIT_CALL3
, SLJIT_R2
, 0);
1215 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1217 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 100);
1218 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 110);
1219 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 120);
1220 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(func
));
1221 sljit_emit_ijump(compiler
, SLJIT_CALL3
, SLJIT_R3
, 0);
1222 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1224 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -10);
1225 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -16);
1226 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 6);
1227 sljit_emit_ijump(compiler
, SLJIT_CALL3
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
));
1228 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1230 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1232 code
.code
= sljit_generate_code(compiler
);
1234 sljit_set_jump_addr(sljit_get_jump_addr(jump
), SLJIT_FUNC_OFFSET(func
), sljit_get_executable_offset(compiler
));
1235 sljit_free_compiler(compiler
);
1237 FAILED(code
.func1((sljit_sw
)&buf
) != -15, "test15 case 1 failed\n");
1238 FAILED(buf
[0] != 14, "test15 case 2 failed\n");
1239 FAILED(buf
[1] != -8, "test15 case 3 failed\n");
1240 FAILED(buf
[2] != SLJIT_FUNC_OFFSET(func
) + 42, "test15 case 4 failed\n");
1241 FAILED(buf
[3] != SLJIT_FUNC_OFFSET(func
) - 85, "test15 case 5 failed\n");
1242 FAILED(buf
[4] != SLJIT_FUNC_OFFSET(func
) + 31, "test15 case 6 failed\n");
1243 FAILED(buf
[5] != 335, "test15 case 7 failed\n");
1244 FAILED(buf
[6] != -15, "test15 case 8 failed\n");
1246 sljit_free_code(code
.code
);
1250 static void test16(void)
1252 /* Ackermann benchmark. */
1253 executable_code code
;
1254 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
1255 struct sljit_label
*entry
;
1256 struct sljit_label
*label
;
1257 struct sljit_jump
*jump
;
1258 struct sljit_jump
*jump1
;
1259 struct sljit_jump
*jump2
;
1262 printf("Run test16\n");
1264 FAILED(!compiler
, "cannot create compiler\n");
1266 entry
= sljit_emit_label(compiler
);
1267 sljit_emit_enter(compiler
, 0, 2, 3, 2, 0, 0, 0);
1269 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0);
1270 jump1
= sljit_emit_jump(compiler
, SLJIT_EQUAL
);
1272 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0);
1273 jump2
= sljit_emit_jump(compiler
, SLJIT_EQUAL
);
1276 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
1277 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 1);
1278 jump
= sljit_emit_jump(compiler
, SLJIT_CALL2
);
1279 sljit_set_label(jump
, entry
);
1281 /* Returns with Ack(x-1, Ack(x,y-1)). */
1282 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_RETURN_REG
, 0);
1283 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
1284 jump
= sljit_emit_jump(compiler
, SLJIT_CALL2
);
1285 sljit_set_label(jump
, entry
);
1286 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1288 /* Returns with y+1. */
1289 label
= sljit_emit_label(compiler
);
1290 sljit_set_label(jump1
, label
);
1291 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 1, SLJIT_S1
, 0);
1292 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1294 /* Returns with Ack(x-1,1) */
1295 label
= sljit_emit_label(compiler
);
1296 sljit_set_label(jump2
, label
);
1297 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
1298 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
1299 jump
= sljit_emit_jump(compiler
, SLJIT_CALL2
);
1300 sljit_set_label(jump
, entry
);
1301 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1303 code
.code
= sljit_generate_code(compiler
);
1305 sljit_free_compiler(compiler
);
1307 FAILED(code
.func2(3, 3) != 61, "test16 case 1 failed\n");
1308 /* For benchmarking. */
1309 /* FAILED(code.func2(3, 11) != 16381, "test16 case 1 failed\n"); */
1311 sljit_free_code(code
.code
);
1315 static void test17(void)
1317 /* Test arm constant pool. */
1318 executable_code code
;
1319 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
1324 printf("Run test17\n");
1326 FAILED(!compiler
, "cannot create compiler\n");
1333 sljit_emit_enter(compiler
, 0, 1, 3, 1, 0, 0, 0);
1334 for (i
= 0; i
<= 0xfff; i
++) {
1335 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x81818000 | i
);
1336 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x81818000 | i
);
1337 if ((i
& 0x3ff) == 0)
1338 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), (i
>> 10) * sizeof(sljit_sw
), SLJIT_R0
, 0);
1340 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1341 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
1343 code
.code
= sljit_generate_code(compiler
);
1345 sljit_free_compiler(compiler
);
1347 code
.func1((sljit_sw
)&buf
);
1348 FAILED((sljit_uw
)buf
[0] != 0x81818000, "test17 case 1 failed\n");
1349 FAILED((sljit_uw
)buf
[1] != 0x81818400, "test17 case 2 failed\n");
1350 FAILED((sljit_uw
)buf
[2] != 0x81818800, "test17 case 3 failed\n");
1351 FAILED((sljit_uw
)buf
[3] != 0x81818c00, "test17 case 4 failed\n");
1352 FAILED((sljit_uw
)buf
[4] != 0x81818fff, "test17 case 5 failed\n");
1354 sljit_free_code(code
.code
);
1358 static void test18(void)
1361 executable_code code
;
1362 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
1366 printf("Run test18\n");
1368 FAILED(!compiler
, "cannot create compiler\n");
1379 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1380 buf
[10] = SLJIT_W(1) << 32;
1385 sljit_emit_enter(compiler
, 0, 1, 3, 2, 0, 0, 0);
1387 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1388 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, SLJIT_W(0x1122334455667788));
1389 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x1122334455667788));
1391 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(1000000000000));
1392 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(1000000000000));
1393 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_IMM
, SLJIT_W(5000000000000), SLJIT_R0
, 0);
1395 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x1108080808));
1396 sljit_emit_op2(compiler
, SLJIT_ADD32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x1120202020));
1398 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1108080808));
1399 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1120202020));
1400 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_UNUSED
, 0, SLJIT_ZERO
);
1401 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_S1
, 0);
1402 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
1403 sljit_emit_op2(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1120202020));
1404 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_UNUSED
, 0, SLJIT_ZERO32
);
1406 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1108080808));
1407 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x2208080808));
1408 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_UNUSED
, 0, SLJIT_LESS
);
1409 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
1410 sljit_emit_op2(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1104040404));
1411 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_UNUSED
, 0, SLJIT_NOT_ZERO32
);
1413 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
1414 sljit_emit_op2(compiler
, SLJIT_SHL32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_IMM
, SLJIT_W(0xffff0000), SLJIT_R0
, 0);
1416 sljit_emit_op2(compiler
, SLJIT_MUL32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, SLJIT_IMM
, -1);
1418 /* 32 bit operations. */
1420 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0x11223344);
1421 sljit_emit_op2(compiler
, SLJIT_ADD32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 0x44332211);
1425 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
1427 code
.code
= sljit_generate_code(compiler
);
1429 sljit_free_compiler(compiler
);
1431 code
.func1((sljit_sw
)&buf
);
1432 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1433 FAILED(buf
[0] != SLJIT_W(0x1122334455667788), "test18 case 1 failed\n");
1434 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1435 FAILED(buf
[1] != 0x55667788, "test18 case 2 failed\n");
1437 FAILED(buf
[1] != SLJIT_W(0x5566778800000000), "test18 case 2 failed\n");
1439 FAILED(buf
[2] != SLJIT_W(2000000000000), "test18 case 3 failed\n");
1440 FAILED(buf
[3] != SLJIT_W(4000000000000), "test18 case 4 failed\n");
1441 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1442 FAILED(buf
[4] != 0x28282828, "test18 case 5 failed\n");
1444 FAILED(buf
[4] != SLJIT_W(0x2828282800000000), "test18 case 5 failed\n");
1446 FAILED(buf
[5] != 0, "test18 case 6 failed\n");
1447 FAILED(buf
[6] != 1, "test18 case 7 failed\n");
1448 FAILED(buf
[7] != 1, "test18 case 8 failed\n");
1449 FAILED(buf
[8] != 0, "test18 case 9 failed\n");
1450 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1451 FAILED(buf
[9] != 0xfff00000, "test18 case 10 failed\n");
1452 FAILED(buf
[10] != 0xffffffff, "test18 case 11 failed\n");
1454 FAILED(buf
[9] != SLJIT_W(0xfff0000000000000), "test18 case 10 failed\n");
1455 FAILED(buf
[10] != SLJIT_W(0xffffffff00000000), "test18 case 11 failed\n");
1458 FAILED(buf
[0] != 0x11223344, "test18 case 1 failed\n");
1459 FAILED(buf
[1] != 0x44332211, "test18 case 2 failed\n");
1462 sljit_free_code(code
.code
);
1466 static void test19(void)
1468 /* Test arm partial instruction caching. */
1469 executable_code code
;
1470 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
1474 printf("Run test19\n");
1476 FAILED(!compiler
, "cannot create compiler\n");
1486 sljit_emit_enter(compiler
, 0, 1, 3, 1, 0, 0, 0);
1487 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
1488 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM0(), (sljit_sw
)&buf
[2], SLJIT_MEM0(), (sljit_sw
)&buf
[1], SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
1489 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
1490 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1491 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&buf
[0], SLJIT_MEM1(SLJIT_R1
), (sljit_sw
)&buf
[0]);
1492 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_MEM0(), (sljit_sw
)&buf
[0], SLJIT_IMM
, 2);
1493 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&buf
[0] + 4 * sizeof(sljit_sw
));
1494 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_IMM
, 10);
1495 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 7);
1496 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_R1
), (sljit_sw
)&buf
[5], SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_MEM1(SLJIT_R1
), (sljit_sw
)&buf
[5]);
1498 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
1500 code
.code
= sljit_generate_code(compiler
);
1502 sljit_free_compiler(compiler
);
1504 code
.func1((sljit_sw
)&buf
);
1505 FAILED(buf
[0] != 10, "test19 case 1 failed\n");
1506 FAILED(buf
[1] != 4, "test19 case 2 failed\n");
1507 FAILED(buf
[2] != 14, "test19 case 3 failed\n");
1508 FAILED(buf
[3] != 14, "test19 case 4 failed\n");
1509 FAILED(buf
[4] != 8, "test19 case 5 failed\n");
1510 FAILED(buf
[5] != 6, "test19 case 6 failed\n");
1511 FAILED(buf
[6] != 12, "test19 case 7 failed\n");
1512 FAILED(buf
[7] != 10, "test19 case 8 failed\n");
1514 sljit_free_code(code
.code
);
1518 static void test20(void)
1521 executable_code code
;
1522 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
1523 struct sljit_jump
* jump
;
1524 struct sljit_label
* label
;
1526 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1527 sljit_sw offset_value
= SLJIT_W(0x1234567812345678);
1529 sljit_sw offset_value
= SLJIT_W(0x12345678);
1533 printf("Run test20\n");
1535 FAILED(!compiler
, "cannot create compiler\n");
1543 sljit_emit_enter(compiler
, 0, 1, 5, 5, 0, 0, 4 * sizeof(sljit_sw
));
1544 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
), SLJIT_MEM1(SLJIT_S0
), 0);
1545 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
));
1546 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -1);
1547 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, -1);
1548 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, -1);
1549 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_IMM
, -1);
1550 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_uw
), SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
));
1551 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_uw
), SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
), SLJIT_MEM1(SLJIT_SP
), 0);
1552 sljit_get_local_base(compiler
, SLJIT_R0
, 0, -offset_value
);
1553 sljit_get_local_base(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, -0x1234);
1554 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
1555 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_uw
), SLJIT_MEM1(SLJIT_R0
), offset_value
, SLJIT_MEM1(SLJIT_R1
), 0x1234 + sizeof(sljit_sw
));
1556 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_uw
));
1557 /* Dummy last instructions. */
1558 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 23);
1559 sljit_emit_label(compiler
);
1561 code
.code
= sljit_generate_code(compiler
);
1563 sljit_free_compiler(compiler
);
1565 FAILED(code
.func1((sljit_sw
)&buf
) != -12345, "test20 case 1 failed\n")
1567 FAILED(buf
[2] != 60, "test20 case 2 failed\n");
1568 FAILED(buf
[3] != 17, "test20 case 3 failed\n");
1569 FAILED(buf
[4] != 7, "test20 case 4 failed\n");
1571 sljit_free_code(code
.code
);
1573 compiler
= sljit_create_compiler(NULL
);
1574 sljit_emit_enter(compiler
, 0, 0, 3, 0, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
1576 sljit_get_local_base(compiler
, SLJIT_R0
, 0, SLJIT_MAX_LOCAL_SIZE
- sizeof(sljit_sw
));
1577 sljit_get_local_base(compiler
, SLJIT_R1
, 0, -(sljit_sw
)sizeof(sljit_sw
));
1578 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -1);
1579 label
= sljit_emit_label(compiler
);
1580 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_sw
), SLJIT_R2
, 0);
1581 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
1582 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_EQUAL
);
1583 sljit_set_label(jump
, label
);
1585 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
1587 code
.code
= sljit_generate_code(compiler
);
1589 sljit_free_compiler(compiler
);
1591 /* Just survive this code. */
1594 sljit_free_code(code
.code
);
1598 static void test21(void)
1600 /* Test set context. The parts of the jit code can be separated in the memory. */
1601 executable_code code1
;
1602 executable_code code2
;
1603 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
1604 struct sljit_jump
* jump
= NULL
;
1606 sljit_sw executable_offset
;
1610 printf("Run test21\n");
1612 FAILED(!compiler
, "cannot create compiler\n");
1618 sljit_emit_enter(compiler
, 0, 1, 3, 2, 0, 0, 2 * sizeof(sljit_sw
));
1620 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 10);
1621 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_SP
), 0);
1623 jump
= sljit_emit_jump(compiler
, SLJIT_JUMP
| SLJIT_REWRITABLE_JUMP
);
1624 sljit_set_target(jump
, 0);
1626 code1
.code
= sljit_generate_code(compiler
);
1629 executable_offset
= sljit_get_executable_offset(compiler
);
1630 addr
= sljit_get_jump_addr(jump
);
1632 sljit_free_compiler(compiler
);
1634 compiler
= sljit_create_compiler(NULL
);
1635 FAILED(!compiler
, "cannot create compiler\n");
1637 /* Other part of the jit code. */
1638 sljit_set_context(compiler
, 0, 1, 3, 2, 0, 0, 2 * sizeof(sljit_sw
));
1640 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);
1641 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_MEM1(SLJIT_SP
), 0);
1642 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_sw
));
1644 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1646 code2
.code
= sljit_generate_code(compiler
);
1648 sljit_free_compiler(compiler
);
1650 sljit_set_jump_addr(addr
, SLJIT_FUNC_OFFSET(code2
.code
), executable_offset
);
1652 FAILED(code1
.func1((sljit_sw
)&buf
) != 19, "test21 case 1 failed\n");
1653 FAILED(buf
[2] != -16, "test21 case 2 failed\n");
1654 FAILED(buf
[3] != 100, "test21 case 3 failed\n");
1656 sljit_free_code(code1
.code
);
1657 sljit_free_code(code2
.code
);
1661 static void test22(void)
1663 /* Test simple byte and half-int data transfers. */
1664 executable_code code
;
1665 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
1671 printf("Run test22\n");
1673 FAILED(!compiler
, "cannot create compiler\n");
1698 sljit_emit_enter(compiler
, 0, 3, 3, 3, 0, 0, 0);
1700 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1701 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_S0
, 0);
1702 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_sw
), SLJIT_IMM
, -13);
1703 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_R2
, 0, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
));
1704 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_sw
), SLJIT_R2
, 0);
1705 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
));
1706 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1 << SLJIT_WORD_SHIFT
);
1707 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_R1
, 0);
1708 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 0, SLJIT_R2
, 0);
1709 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1710 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 0, SLJIT_R1
, 0);
1711 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2 << SLJIT_WORD_SHIFT
);
1712 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_R1
, 0);
1713 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 0, SLJIT_R2
, 0);
1715 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, -13);
1716 sljit_emit_op1(compiler
, SLJIT_MOVU_U16
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s16
), SLJIT_IMM
, 0x1234);
1717 sljit_emit_op1(compiler
, SLJIT_MOVU_S16
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s16
));
1718 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1719 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s16
), SLJIT_MEM1(SLJIT_S1
), -(sljit_sw
)sizeof(sljit_s16
));
1720 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xff0000 + 8000);
1721 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 2);
1722 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R1
), 1, SLJIT_R0
, 0);
1723 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 6);
1724 sljit_emit_op1(compiler
, SLJIT_MOVU_S16
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R1
), 0, SLJIT_R0
, 0);
1725 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, -9317);
1726 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 5 * sizeof(sljit_s16
));
1727 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -10);
1728 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R1
, 0, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 0);
1729 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s16
), SLJIT_R1
, 0);
1731 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM1(SLJIT_S2
), 0, SLJIT_IMM
, -45);
1732 sljit_emit_op1(compiler
, SLJIT_MOVU_U8
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_s8
), SLJIT_IMM
, 0x12);
1733 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s8
));
1734 sljit_emit_op1(compiler
, SLJIT_MOVU_S8
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_s8
));
1735 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_S1
, 0, SLJIT_R1
, 0);
1736 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_S1
, 0, SLJIT_S1
, 0);
1737 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R2
, 0, SLJIT_S1
, 0);
1738 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R2
, 0);
1739 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_s8
), SLJIT_S1
, 0);
1740 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM2(SLJIT_S2
, SLJIT_R0
), 0, SLJIT_R0
, 0);
1742 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
1744 code
.code
= sljit_generate_code(compiler
);
1746 sljit_free_compiler(compiler
);
1748 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&sbuf
, (sljit_sw
)&bbuf
);
1749 FAILED(buf
[1] != -13, "test22 case 1 failed\n");
1750 FAILED(buf
[2] != 5, "test22 case 2 failed\n");
1751 FAILED(buf
[3] != -13, "test22 case 3 failed\n");
1752 FAILED(buf
[4] != (sljit_sw
)&buf
[3], "test22 case 4 failed\n");
1753 FAILED(buf
[5] != (sljit_sw
)&buf
[4], "test22 case 5 failed\n");
1754 FAILED(buf
[6] != (sljit_sw
)&buf
[4], "test22 case 6 failed\n");
1755 FAILED(buf
[7] != -9, "test22 case 7 failed\n");
1756 FAILED(buf
[8] != -56, "test22 case 8 failed\n");
1758 FAILED(sbuf
[0] != -13, "test22 case 9 failed\n");
1759 FAILED(sbuf
[1] != 0x1234, "test22 case 10 failed\n");
1760 FAILED(sbuf
[3] != 0x1234, "test22 case 11 failed\n");
1761 FAILED(sbuf
[4] != 8000, "test22 case 12 failed\n");
1762 FAILED(sbuf
[5] != -9317, "test22 case 13 failed\n");
1763 FAILED(sbuf
[6] != -9317, "test22 case 14 failed\n");
1765 FAILED(bbuf
[0] != -45, "test22 case 15 failed\n");
1766 FAILED(bbuf
[1] != 0x12, "test22 case 16 failed\n");
1767 FAILED(bbuf
[3] != -56, "test22 case 17 failed\n");
1768 FAILED(bbuf
[4] != 2, "test22 case 18 failed\n");
1770 sljit_free_code(code
.code
);
1774 static void test23(void)
1776 /* Test 32 bit / 64 bit signed / unsigned int transfer and conversion.
1777 This test has do real things on 64 bit systems, but works on 32 bit systems as well. */
1778 executable_code code
;
1779 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
1784 sljit_u8 asbytes
[4];
1786 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1787 sljit_sw garbage
= SLJIT_W(0x1234567812345678);
1789 sljit_sw garbage
= 0x12345678;
1793 printf("Run test23\n");
1795 FAILED(!compiler
, "cannot create compiler\n");
1812 sljit_emit_enter(compiler
, 0, 2, 3, 3, 0, 0, 0);
1813 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, 34567);
1814 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
1815 sljit_emit_op1(compiler
, SLJIT_MOVU_S32
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), 0, SLJIT_IMM
, -7654);
1816 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, garbage
);
1817 sljit_emit_op1(compiler
, SLJIT_MOVU_S32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
));
1818 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
1819 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, garbage
);
1820 sljit_emit_op1(compiler
, SLJIT_MOVU_U32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
));
1821 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
1822 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, garbage
);
1823 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
));
1824 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
1825 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
1826 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x0f00f00);
1827 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x7777);
1828 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), 0x7777 + 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1829 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x7777);
1830 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), -0x7777 + (sljit_sw
)sizeof(sljit_sw
), SLJIT_R0
, 0);
1831 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1832 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 1);
1833 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R1
), 0, SLJIT_IMM
, 16);
1834 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_R1
), 0, SLJIT_IMM
, 64, SLJIT_MEM1(SLJIT_R1
), 0);
1835 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
1836 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&buf
[6], SLJIT_MEM0(), (sljit_sw
)&buf
[6]);
1837 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_IMM
, 0x123456);
1838 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_S0
, 0);
1839 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R1
, 0);
1840 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, sizeof(sljit_sw
));
1841 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 100000 * sizeof(sljit_sw
));
1842 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), 100001 * sizeof(sljit_sw
), SLJIT_IMM
, 123456);
1843 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 123);
1844 sljit_emit_op1(compiler
, SLJIT_MOVU_S32
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
), SLJIT_IMM
, 0x12345678);
1846 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x2bd700 | 243);
1847 sljit_emit_return(compiler
, SLJIT_MOV_S8
, SLJIT_R1
, 0);
1849 code
.code
= sljit_generate_code(compiler
);
1851 sljit_free_compiler(compiler
);
1853 FAILED(code
.func2((sljit_sw
)&buf
, (sljit_sw
)&ibuf
) != -13, "test23 case 1 failed\n");
1854 FAILED(buf
[0] != -5791, "test23 case 2 failed\n");
1855 FAILED(buf
[1] != 43579, "test23 case 3 failed\n");
1856 FAILED(buf
[2] != 658923, "test23 case 4 failed\n");
1857 FAILED(buf
[3] != 0x0f00f00, "test23 case 5 failed\n");
1858 FAILED(buf
[4] != 0x0f00f00, "test23 case 6 failed\n");
1859 FAILED(buf
[5] != 80, "test23 case 7 failed\n");
1860 FAILED(buf
[6] != 0x123456, "test23 case 8 failed\n");
1861 FAILED(buf
[7] != (sljit_sw
)&buf
[5], "test23 case 9 failed\n");
1862 FAILED(buf
[8] != 123456 + 123, "test23 case 10 failed\n");
1864 FAILED(ibuf
[0] != 34567, "test23 case 11 failed\n");
1865 FAILED(ibuf
[1] != -7654, "test23 case 12 failed\n");
1867 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1868 FAILED(u
.asbytes
[0] != 0x78, "test23 case 13 failed\n");
1869 FAILED(u
.asbytes
[1] != 0x56, "test23 case 14 failed\n");
1870 FAILED(u
.asbytes
[2] != 0x34, "test23 case 15 failed\n");
1871 FAILED(u
.asbytes
[3] != 0x12, "test23 case 16 failed\n");
1873 FAILED(u
.asbytes
[0] != 0x12, "test23 case 13 failed\n");
1874 FAILED(u
.asbytes
[1] != 0x34, "test23 case 14 failed\n");
1875 FAILED(u
.asbytes
[2] != 0x56, "test23 case 15 failed\n");
1876 FAILED(u
.asbytes
[3] != 0x78, "test23 case 16 failed\n");
1879 sljit_free_code(code
.code
);
1883 static void test24(void)
1885 /* Some complicated addressing modes. */
1886 executable_code code
;
1887 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
1893 printf("Run test24\n");
1895 FAILED(!compiler
, "cannot create compiler\n");
1921 sljit_emit_enter(compiler
, 0, 3, 3, 3, 0, 0, 0);
1923 /* Nothing should be updated. */
1924 sljit_emit_op1(compiler
, SLJIT_MOVU_S16
, SLJIT_MEM0(), (sljit_sw
)&sbuf
[1], SLJIT_MEM0(), (sljit_sw
)&sbuf
[0]);
1925 sljit_emit_op1(compiler
, SLJIT_MOVU_S8
, SLJIT_MEM0(), (sljit_sw
)&bbuf
[1], SLJIT_MEM0(), (sljit_sw
)&bbuf
[0]);
1926 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
1927 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), 1, SLJIT_MEM0(), (sljit_sw
)&sbuf
[3]);
1928 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[0]);
1929 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1930 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2);
1931 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);
1932 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_s8
));
1933 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_s8
));
1934 sljit_emit_op1(compiler
, SLJIT_MOVU_U8
, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&bbuf
[1], SLJIT_MEM1(SLJIT_R1
), (sljit_sw
)&bbuf
[0]);
1935 sljit_emit_op1(compiler
, SLJIT_MOVU_U8
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_MEM1(SLJIT_R1
), 2 * sizeof(sljit_s8
));
1937 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_s16
));
1938 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R1
), (sljit_sw
)&sbuf
[3], SLJIT_R1
, 0);
1940 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
1941 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
);
1942 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
1943 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_S0
, 0);
1944 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
);
1945 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
1946 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1947 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 4 << SLJIT_WORD_SHIFT
);
1948 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_R2
), 0);
1949 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);
1950 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);
1952 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
- 0x7fff8000 + 6 * sizeof(sljit_sw
));
1953 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 952467);
1954 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0x7fff8000, SLJIT_R1
, 0);
1955 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0x7fff8000 + sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_R0
), 0x7fff8000);
1957 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
+ 0x7fff7fff + 6 * sizeof(sljit_sw
));
1958 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);
1959 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
- 0x7fff7ffe + 3 * sizeof(sljit_s8
));
1960 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM1(SLJIT_R0
), 0x7fff7fff, SLJIT_MEM1(SLJIT_R0
), 0x7fff7ffe);
1961 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
+ 0x7fff7fff + 5 * sizeof(sljit_s8
));
1962 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM1(SLJIT_R0
), -0x7fff7fff, SLJIT_MEM1(SLJIT_R0
), -0x7fff8000);
1963 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1964 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
- SLJIT_W(0x123456123456));
1965 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
- SLJIT_W(0x123456123456));
1966 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));
1969 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
1971 code
.code
= sljit_generate_code(compiler
);
1973 sljit_free_compiler(compiler
);
1975 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&sbuf
, (sljit_sw
)&bbuf
);
1976 FAILED(buf
[2] != 176366, "test24 case 1 failed\n");
1977 FAILED(buf
[3] != 64, "test24 case 2 failed\n");
1978 FAILED(buf
[4] != -100, "test24 case 3 failed\n");
1979 FAILED(buf
[5] != -100 + (sljit_sw
)&buf
[5] + (sljit_sw
)&buf
[4], "test24 case 4 failed\n");
1980 FAILED(buf
[6] != 952467, "test24 case 5 failed\n");
1981 FAILED(buf
[7] != 952467, "test24 case 6 failed\n");
1982 FAILED(buf
[8] != 952467 * 2, "test24 case 7 failed\n");
1984 FAILED(sbuf
[1] != 30000, "test24 case 8 failed\n");
1985 FAILED(sbuf
[2] != -12345, "test24 case 9 failed\n");
1986 FAILED(sbuf
[4] != sizeof(sljit_s16
), "test24 case 10 failed\n");
1988 FAILED(bbuf
[1] != -128, "test24 case 11 failed\n");
1989 FAILED(bbuf
[2] != 99, "test24 case 12 failed\n");
1990 FAILED(bbuf
[4] != 99, "test24 case 13 failed\n");
1991 FAILED(bbuf
[5] != 99, "test24 case 14 failed\n");
1992 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1993 FAILED(bbuf
[6] != -128, "test24 case 15 failed\n");
1996 sljit_free_code(code
.code
);
2000 static void test25(void)
2002 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2004 executable_code code
;
2005 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
2009 printf("Run test25\n");
2011 FAILED(!compiler
, "cannot create compiler\n");
2027 sljit_emit_enter(compiler
, 0, 1, 3, 1, 0, 0, 0);
2029 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0);
2030 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 1 * sizeof(sljit_sw
), SLJIT_IMM
, 0x7fff);
2031 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_IMM
, -0x8000);
2032 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 0x7fffffff);
2033 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(-0x80000000));
2034 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x1234567887654321));
2035 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0xff80000000));
2036 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x3ff0000000));
2037 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0xfffffff800100000));
2038 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0xfffffff80010f000));
2039 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00000008001));
2040 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00080010000));
2041 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00080018001));
2042 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00ffff00000));
2044 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
2046 code
.code
= sljit_generate_code(compiler
);
2048 sljit_free_compiler(compiler
);
2050 code
.func1((sljit_sw
)&buf
);
2051 FAILED(buf
[0] != 0, "test25 case 1 failed\n");
2052 FAILED(buf
[1] != 0x7fff, "test25 case 2 failed\n");
2053 FAILED(buf
[2] != -0x8000, "test25 case 3 failed\n");
2054 FAILED(buf
[3] != 0x7fffffff, "test25 case 4 failed\n");
2055 FAILED(buf
[4] != SLJIT_W(-0x80000000), "test25 case 5 failed\n");
2056 FAILED(buf
[5] != SLJIT_W(0x1234567887654321), "test25 case 6 failed\n");
2057 FAILED(buf
[6] != SLJIT_W(0xff80000000), "test25 case 7 failed\n");
2058 FAILED(buf
[7] != SLJIT_W(0x3ff0000000), "test25 case 8 failed\n");
2059 FAILED((sljit_uw
)buf
[8] != SLJIT_W(0xfffffff800100000), "test25 case 9 failed\n");
2060 FAILED((sljit_uw
)buf
[9] != SLJIT_W(0xfffffff80010f000), "test25 case 10 failed\n");
2061 FAILED(buf
[10] != SLJIT_W(0x07fff00000008001), "test25 case 11 failed\n");
2062 FAILED(buf
[11] != SLJIT_W(0x07fff00080010000), "test25 case 12 failed\n");
2063 FAILED(buf
[12] != SLJIT_W(0x07fff00080018001), "test25 case 13 failed\n");
2064 FAILED(buf
[13] != SLJIT_W(0x07fff00ffff00000), "test25 case 14 failed\n");
2066 sljit_free_code(code
.code
);
2071 static void test26(void)
2073 /* Aligned access without aligned offsets. */
2074 executable_code code
;
2075 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
2081 printf("Run test26\n");
2083 FAILED(!compiler
, "cannot create compiler\n");
2100 sljit_emit_enter(compiler
, 0, 3, 3, 3, 0, 0, 0);
2102 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 3);
2103 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 1);
2104 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), -3);
2105 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
) - 1, SLJIT_R0
, 0);
2106 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), -1);
2107 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) - 3, SLJIT_R0
, 0);
2109 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 100);
2110 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);
2111 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 100);
2112 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);
2114 if (sljit_is_fpu_available()) {
2115 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 3);
2116 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f64
) - 3, SLJIT_MEM1(SLJIT_S2
), -3);
2117 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);
2118 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 2);
2119 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sizeof(sljit_f64
) * 3 - 4) >> 1);
2120 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 1);
2121 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);
2124 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
2126 code
.code
= sljit_generate_code(compiler
);
2128 sljit_free_compiler(compiler
);
2130 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&ibuf
, (sljit_sw
)&dbuf
);
2132 FAILED(buf
[1] != -689, "test26 case 1 failed\n");
2133 FAILED(buf
[2] != -16, "test26 case 2 failed\n");
2134 FAILED(ibuf
[1] != -2789, "test26 case 3 failed\n");
2135 FAILED(ibuf
[2] != -18, "test26 case 4 failed\n");
2137 if (sljit_is_fpu_available()) {
2138 FAILED(dbuf
[1] != 5.75, "test26 case 5 failed\n");
2139 FAILED(dbuf
[2] != 11.5, "test26 case 6 failed\n");
2140 FAILED(dbuf
[3] != -2.875, "test26 case 7 failed\n");
2143 sljit_free_code(code
.code
);
2147 static void test27(void)
2149 #define SET_NEXT_BYTE(type) \
2150 cond_set(compiler, SLJIT_R2, 0, type); \
2151 sljit_emit_op1(compiler, SLJIT_MOVU_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R2, 0);
2152 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2155 #define RESULT(i) (3 - i)
2158 /* Playing with conditional flags. */
2159 executable_code code
;
2160 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
2165 printf("Run test27\n");
2167 for (i
= 0; i
< 37; ++i
)
2170 FAILED(!compiler
, "cannot create compiler\n");
2172 /* 3 arguments passed, 3 arguments used. */
2173 sljit_emit_enter(compiler
, 0, 1, 3, 3, 0, 0, 0);
2175 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
2177 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1001);
2178 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 20);
2179 /* 0x100100000 on 64 bit machines, 0x100000 on 32 bit machines. */
2180 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x800000);
2181 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2182 sljit_emit_op0(compiler
, SLJIT_NOP
); /* Nop should keep the flags. */
2183 SET_NEXT_BYTE(SLJIT_GREATER
);
2184 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2185 SET_NEXT_BYTE(SLJIT_LESS
);
2186 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2187 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
2188 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2189 sljit_emit_op0(compiler
, SLJIT_NOP
); /* Nop should keep the flags. */
2190 SET_NEXT_BYTE(SLJIT_GREATER32
);
2191 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2192 SET_NEXT_BYTE(SLJIT_LESS32
);
2194 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1000);
2195 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 20);
2196 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x10);
2197 /* 0x100000010 on 64 bit machines, 0x10 on 32 bit machines. */
2198 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2199 SET_NEXT_BYTE(SLJIT_GREATER
);
2200 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2201 SET_NEXT_BYTE(SLJIT_LESS
);
2202 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2203 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2204 SET_NEXT_BYTE(SLJIT_GREATER32
);
2205 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2206 SET_NEXT_BYTE(SLJIT_LESS32
);
2208 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2209 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2210 /* 0xff..ff on all machines. */
2211 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2212 SET_NEXT_BYTE(SLJIT_LESS_EQUAL
);
2213 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2214 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL
);
2215 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R2
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -1);
2216 SET_NEXT_BYTE(SLJIT_SIG_GREATER
);
2217 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -1);
2218 SET_NEXT_BYTE(SLJIT_SIG_LESS
);
2219 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
2220 SET_NEXT_BYTE(SLJIT_EQUAL
);
2221 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
2222 SET_NEXT_BYTE(SLJIT_NOT_EQUAL
);
2223 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2224 SET_NEXT_BYTE(SLJIT_OVERFLOW
);
2225 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_NOT_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2226 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW
);
2227 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2228 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL
);
2229 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2230 SET_NEXT_BYTE(SLJIT_LESS_EQUAL
);
2232 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x80000000);
2233 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 16);
2234 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 16);
2235 /* 0x80..0 on 64 bit machines, 0 on 32 bit machines. */
2236 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0xffffffff);
2237 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2238 SET_NEXT_BYTE(SLJIT_OVERFLOW
);
2239 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_NOT_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2240 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW
);
2241 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2242 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
2243 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2244 SET_NEXT_BYTE(SLJIT_OVERFLOW32
);
2245 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_NOT_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2246 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW32
);
2248 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2249 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2250 sljit_emit_op2(compiler
, SLJIT_SUBC
| SLJIT_SET_CARRY
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2251 sljit_emit_op2(compiler
, SLJIT_SUBC
, SLJIT_R0
, 0, SLJIT_IMM
, 6, SLJIT_R0
, 0);
2252 sljit_emit_op1(compiler
, SLJIT_MOVU_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_R0
, 0);
2254 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
2255 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_CARRY
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2256 sljit_emit_op2(compiler
, SLJIT_ADDC
| SLJIT_SET_CARRY
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2257 sljit_emit_op2(compiler
, SLJIT_ADDC
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 9);
2258 sljit_emit_op1(compiler
, SLJIT_MOVU_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_R0
, 0);
2260 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2261 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, (8 * sizeof(sljit_sw
)) - 1);
2262 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2263 SET_NEXT_BYTE(SLJIT_EQUAL
);
2264 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R0
, 0);
2265 SET_NEXT_BYTE(SLJIT_EQUAL
);
2267 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2268 sljit_emit_op2(compiler
, SLJIT_ASHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2269 SET_NEXT_BYTE(SLJIT_EQUAL
);
2270 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2271 sljit_emit_op2(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffffc0);
2272 SET_NEXT_BYTE(SLJIT_NOT_EQUAL
);
2273 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_PREF_SHIFT_REG
, 0, SLJIT_IMM
, 0);
2274 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2275 sljit_emit_op2(compiler
, SLJIT_ASHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_PREF_SHIFT_REG
, 0);
2276 SET_NEXT_BYTE(SLJIT_EQUAL
);
2277 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_PREF_SHIFT_REG
, 0, SLJIT_IMM
, 0);
2278 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2279 sljit_emit_op2(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_PREF_SHIFT_REG
, 0);
2280 SET_NEXT_BYTE(SLJIT_NOT_EQUAL
);
2282 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2283 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2284 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R0
, 0);
2285 sljit_emit_op2(compiler
, SLJIT_SUBC
| SLJIT_SET_CARRY
, SLJIT_R2
, 0, SLJIT_IMM
, 1, SLJIT_R0
, 0);
2286 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_R2
, 0);
2287 sljit_emit_op2(compiler
, SLJIT_SUBC
| SLJIT_SET_CARRY
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2288 sljit_emit_op2(compiler
, SLJIT_SUBC
, SLJIT_R2
, 0, SLJIT_IMM
, 1, SLJIT_R0
, 0);
2289 sljit_emit_op1(compiler
, SLJIT_MOVU_U8
, SLJIT_MEM1(SLJIT_S0
), 2, SLJIT_R2
, 0);
2291 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -34);
2292 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x1234);
2293 SET_NEXT_BYTE(SLJIT_LESS
);
2294 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x1234);
2295 SET_NEXT_BYTE(SLJIT_SIG_LESS
);
2296 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2297 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x12300000000) - 43);
2299 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, -43);
2301 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -96);
2302 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2303 SET_NEXT_BYTE(SLJIT_LESS32
);
2304 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_SIG_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2305 SET_NEXT_BYTE(SLJIT_SIG_GREATER32
);
2307 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
2309 code
.code
= sljit_generate_code(compiler
);
2311 sljit_free_compiler(compiler
);
2313 code
.func1((sljit_sw
)&buf
);
2315 FAILED(buf
[0] != RESULT(1), "test27 case 1 failed\n");
2316 FAILED(buf
[1] != RESULT(2), "test27 case 2 failed\n");
2317 FAILED(buf
[2] != 2, "test27 case 3 failed\n");
2318 FAILED(buf
[3] != 1, "test27 case 4 failed\n");
2319 FAILED(buf
[4] != RESULT(1), "test27 case 5 failed\n");
2320 FAILED(buf
[5] != RESULT(2), "test27 case 6 failed\n");
2321 FAILED(buf
[6] != 2, "test27 case 7 failed\n");
2322 FAILED(buf
[7] != 1, "test27 case 8 failed\n");
2324 FAILED(buf
[8] != 2, "test27 case 9 failed\n");
2325 FAILED(buf
[9] != 1, "test27 case 10 failed\n");
2326 FAILED(buf
[10] != 2, "test27 case 11 failed\n");
2327 FAILED(buf
[11] != 1, "test27 case 12 failed\n");
2328 FAILED(buf
[12] != 1, "test27 case 13 failed\n");
2329 FAILED(buf
[13] != 2, "test27 case 14 failed\n");
2330 FAILED(buf
[14] != 2, "test27 case 15 failed\n");
2331 FAILED(buf
[15] != 1, "test27 case 16 failed\n");
2332 FAILED(buf
[16] != 1, "test27 case 17 failed\n");
2333 FAILED(buf
[17] != 2, "test27 case 18 failed\n");
2335 FAILED(buf
[18] != RESULT(1), "test27 case 19 failed\n");
2336 FAILED(buf
[19] != RESULT(2), "test27 case 20 failed\n");
2337 FAILED(buf
[20] != 2, "test27 case 21 failed\n");
2338 FAILED(buf
[21] != 1, "test27 case 22 failed\n");
2340 FAILED(buf
[22] != 5, "test27 case 23 failed\n");
2341 FAILED(buf
[23] != 9, "test27 case 24 failed\n");
2343 FAILED(buf
[24] != 2, "test27 case 25 failed\n");
2344 FAILED(buf
[25] != 1, "test27 case 26 failed\n");
2346 FAILED(buf
[26] != 1, "test27 case 27 failed\n");
2347 FAILED(buf
[27] != 1, "test27 case 28 failed\n");
2348 FAILED(buf
[28] != 1, "test27 case 29 failed\n");
2349 FAILED(buf
[29] != 1, "test27 case 30 failed\n");
2351 FAILED(buf
[30] != 1, "test27 case 31 failed\n");
2352 FAILED(buf
[31] != 0, "test27 case 32 failed\n");
2354 FAILED(buf
[32] != 2, "test27 case 33 failed\n");
2355 FAILED(buf
[33] != 1, "test27 case 34 failed\n");
2356 FAILED(buf
[34] != 2, "test27 case 35 failed\n");
2357 FAILED(buf
[35] != 1, "test27 case 36 failed\n");
2358 FAILED(buf
[36] != 10, "test27 case 37 failed\n");
2360 sljit_free_code(code
.code
);
2362 #undef SET_NEXT_BYTE
2366 static void test28(void)
2369 executable_code code
;
2370 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
2371 struct sljit_const
* const1
= NULL
;
2372 struct sljit_label
* label
= NULL
;
2373 sljit_uw label_addr
= 0;
2377 printf("Run test28\n");
2379 FAILED(!compiler
, "cannot create compiler\n");
2387 FAILED(!compiler
, "cannot create compiler\n");
2388 sljit_emit_enter(compiler
, 0, 1, 5, 5, 0, 0, 0);
2389 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -234);
2390 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
2391 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_S3
, 0, SLJIT_R3
, 0, SLJIT_R4
, 0);
2392 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_S3
, 0);
2393 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_S3
, 0, SLJIT_IMM
, 0);
2394 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_UNUSED
, 0, SLJIT_NOT_ZERO
);
2395 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_S3
, 0);
2396 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
));
2397 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S4
, 0, SLJIT_S4
, 0, SLJIT_R4
, 0);
2398 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_S4
, 0);
2400 const1
= sljit_emit_const(compiler
, SLJIT_S3
, 0, 0);
2401 sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_S3
, 0);
2402 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S3
, 0, SLJIT_S3
, 0, SLJIT_IMM
, 100);
2403 label
= sljit_emit_label(compiler
);
2404 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_S3
, 0);
2406 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R4
, 0);
2408 code
.code
= sljit_generate_code(compiler
);
2411 label_addr
= sljit_get_label_addr(label
);
2412 sljit_set_const(sljit_get_const_addr(const1
), label_addr
, sljit_get_executable_offset(compiler
));
2414 sljit_free_compiler(compiler
);
2416 FAILED(code
.func1((sljit_sw
)&buf
) != 8, "test28 case 1 failed\n");
2417 FAILED(buf
[1] != -1872, "test28 case 2 failed\n");
2418 FAILED(buf
[2] != 1, "test28 case 3 failed\n");
2419 FAILED(buf
[3] != 2, "test28 case 4 failed\n");
2420 FAILED(buf
[4] != label_addr
, "test28 case 5 failed\n");
2422 sljit_free_code(code
.code
);
2426 static void test29(void)
2428 /* Test signed/unsigned bytes and halfs. */
2429 executable_code code
;
2430 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
2434 printf("Run test29\n");
2462 FAILED(!compiler
, "cannot create compiler\n");
2463 sljit_emit_enter(compiler
, 0, 1, 5, 5, 0, 0, 0);
2465 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_IMM
, -187);
2466 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
2467 sljit_emit_op1(compiler
, SLJIT_MOVU_S8
, SLJIT_R0
, 0, SLJIT_IMM
, -605);
2468 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2469 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R0
, 0, SLJIT_IMM
, -56);
2470 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2471 sljit_emit_op1(compiler
, SLJIT_MOVU_U8
, SLJIT_R4
, 0, SLJIT_IMM
, 0xcde5);
2472 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R4
, 0);
2474 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_IMM
, -45896);
2475 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2476 sljit_emit_op1(compiler
, SLJIT_MOVU_S16
, SLJIT_R0
, 0, SLJIT_IMM
, -1472797);
2477 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2478 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R0
, 0, SLJIT_IMM
, -12890);
2479 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2480 sljit_emit_op1(compiler
, SLJIT_MOVU_U16
, SLJIT_R4
, 0, SLJIT_IMM
, 0x9cb0a6);
2481 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R4
, 0);
2483 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2484 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-3580429715));
2485 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2486 sljit_emit_op1(compiler
, SLJIT_MOVU_S32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-100722768662));
2487 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2488 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-1457052677972));
2489 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2490 sljit_emit_op1(compiler
, SLJIT_MOVU_U32
, SLJIT_R4
, 0, SLJIT_IMM
, SLJIT_W(0xcef97a70b5));
2491 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R4
, 0);
2493 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 4 * sizeof(sljit_uw
));
2496 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -187);
2497 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2498 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2499 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -605);
2500 sljit_emit_op1(compiler
, SLJIT_MOVU_S8
, SLJIT_R0
, 0, SLJIT_S2
, 0);
2501 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2502 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -56);
2503 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R0
, 0, SLJIT_R2
, 0);
2504 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2505 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0xcde5);
2506 sljit_emit_op1(compiler
, SLJIT_MOVU_U8
, SLJIT_R4
, 0, SLJIT_R3
, 0);
2507 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R4
, 0);
2509 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -45896);
2510 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2511 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2512 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1472797);
2513 sljit_emit_op1(compiler
, SLJIT_MOVU_S16
, SLJIT_R0
, 0, SLJIT_S2
, 0);
2514 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2515 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -12890);
2516 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R0
, 0, SLJIT_R2
, 0);
2517 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2518 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x9cb0a6);
2519 sljit_emit_op1(compiler
, SLJIT_MOVU_U16
, SLJIT_R4
, 0, SLJIT_R3
, 0);
2520 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R4
, 0);
2522 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2523 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(-3580429715));
2524 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2525 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2526 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, SLJIT_W(-100722768662));
2527 sljit_emit_op1(compiler
, SLJIT_MOVU_S32
, SLJIT_R0
, 0, SLJIT_S2
, 0);
2528 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2529 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, SLJIT_W(-1457052677972));
2530 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R2
, 0);
2531 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2532 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_W(0xcef97a70b5));
2533 sljit_emit_op1(compiler
, SLJIT_MOVU_U32
, SLJIT_R4
, 0, SLJIT_R3
, 0);
2534 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R4
, 0);
2536 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 4 * sizeof(sljit_uw
));
2539 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, 0x9faa5);
2540 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_S2
, 0, SLJIT_S2
, 0);
2541 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_S2
, 0);
2543 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
2545 code
.code
= sljit_generate_code(compiler
);
2547 sljit_free_compiler(compiler
);
2549 code
.func1((sljit_sw
)&buf
);
2550 FAILED(buf
[0] != 69, "test29 case 1 failed\n");
2551 FAILED(buf
[1] != -93, "test29 case 2 failed\n");
2552 FAILED(buf
[2] != 200, "test29 case 3 failed\n");
2553 FAILED(buf
[3] != 0xe5, "test29 case 4 failed\n");
2554 FAILED(buf
[4] != 19640, "test29 case 5 failed\n");
2555 FAILED(buf
[5] != -31005, "test29 case 6 failed\n");
2556 FAILED(buf
[6] != 52646, "test29 case 7 failed\n");
2557 FAILED(buf
[7] != 0xb0a6, "test29 case 8 failed\n");
2559 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2560 FAILED(buf
[8] != SLJIT_W(714537581), "test29 case 9 failed\n");
2561 FAILED(buf
[9] != SLJIT_W(-1938520854), "test29 case 10 failed\n");
2562 FAILED(buf
[10] != SLJIT_W(3236202668), "test29 case 11 failed\n");
2563 FAILED(buf
[11] != SLJIT_W(0xf97a70b5), "test29 case 12 failed\n");
2566 FAILED(buf
[12] != 69, "test29 case 13 failed\n");
2567 FAILED(buf
[13] != -93, "test29 case 14 failed\n");
2568 FAILED(buf
[14] != 200, "test29 case 15 failed\n");
2569 FAILED(buf
[15] != 0xe5, "test29 case 16 failed\n");
2570 FAILED(buf
[16] != 19640, "test29 case 17 failed\n");
2571 FAILED(buf
[17] != -31005, "test29 case 18 failed\n");
2572 FAILED(buf
[18] != 52646, "test29 case 19 failed\n");
2573 FAILED(buf
[19] != 0xb0a6, "test29 case 20 failed\n");
2575 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2576 FAILED(buf
[20] != SLJIT_W(714537581), "test29 case 21 failed\n");
2577 FAILED(buf
[21] != SLJIT_W(-1938520854), "test29 case 22 failed\n");
2578 FAILED(buf
[22] != SLJIT_W(3236202668), "test29 case 23 failed\n");
2579 FAILED(buf
[23] != SLJIT_W(0xf97a70b5), "test29 case 24 failed\n");
2582 FAILED(buf
[24] != -91, "test29 case 25 failed\n");
2584 sljit_free_code(code
.code
);
2588 static void test30(void)
2590 /* Test unused results. */
2591 executable_code code
;
2592 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
2596 printf("Run test30\n");
2598 FAILED(!compiler
, "cannot create compiler\n");
2600 sljit_emit_enter(compiler
, 0, 1, 5, 5, 0, 0, 0);
2602 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2603 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2604 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 1);
2605 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 1);
2606 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, 1);
2607 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2608 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S1
, 0, SLJIT_IMM
, SLJIT_W(-0x123ffffffff));
2610 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S1
, 0, SLJIT_IMM
, 1);
2612 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, 1);
2613 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, 1);
2614 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_IMM
, 1);
2616 /* Some calculations with unused results. */
2617 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0);
2618 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0);
2619 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
2620 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
2621 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_GREATER_EQUAL
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
2622 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_UNUSED
, 0, SLJIT_S0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
2623 sljit_emit_op2(compiler
, SLJIT_SHL
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_S3
, 0, SLJIT_R2
, 0);
2624 sljit_emit_op2(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 5);
2625 sljit_emit_op2(compiler
, SLJIT_AND
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0xff);
2626 sljit_emit_op1(compiler
, SLJIT_NOT32
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_S1
, 0);
2628 /* Testing that any change happens. */
2629 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2630 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R2
, 0);
2631 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R3
, 0);
2632 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R4
, 0);
2633 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_S1
, 0, SLJIT_S1
, 0);
2634 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S1
, 0);
2635 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S2
, 0);
2636 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S3
, 0);
2637 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0, SLJIT_S4
, 0);
2639 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
2641 code
.code
= sljit_generate_code(compiler
);
2643 sljit_free_compiler(compiler
);
2645 code
.func1((sljit_sw
)&buf
);
2646 FAILED(buf
[0] != 9, "test30 case 1 failed\n");
2648 sljit_free_code(code
.code
);
2652 static void test31(void)
2654 /* Integer mul and set flags. */
2655 executable_code code
;
2656 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
2658 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2659 sljit_sw big_word
= SLJIT_W(0x7fffffff00000000);
2660 sljit_sw big_word2
= SLJIT_W(0x7fffffff00000012);
2662 sljit_sw big_word
= 0x7fffffff;
2663 sljit_sw big_word2
= 0x00000012;
2667 printf("Run test31\n");
2682 FAILED(!compiler
, "cannot create compiler\n");
2684 sljit_emit_enter(compiler
, 0, 1, 3, 5, 0, 0, 0);
2685 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
2686 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_MUL_NOT_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -45);
2687 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MUL_NOT_OVERFLOW
);
2688 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_MUL_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -45);
2689 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_MUL_OVERFLOW
);
2691 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, big_word
);
2692 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_MUL_OVERFLOW
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, -2);
2693 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 33); /* Should not change flags. */
2694 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0); /* Should not change flags. */
2695 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_MUL_OVERFLOW
);
2696 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_MUL_NOT_OVERFLOW
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, -2);
2697 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_MUL_NOT_OVERFLOW
);
2699 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S3
, 0, SLJIT_IMM
, 0x3f6b0);
2700 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S4
, 0, SLJIT_IMM
, 0x2a783);
2701 sljit_emit_op2(compiler
, SLJIT_MUL32
| SLJIT_SET_MUL_OVERFLOW
, SLJIT_R1
, 0, SLJIT_S3
, 0, SLJIT_S4
, 0);
2702 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_MUL_OVERFLOW32
);
2703 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R1
, 0);
2705 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, big_word2
);
2706 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_R1
, 0);
2707 sljit_emit_op2(compiler
, SLJIT_MUL32
| SLJIT_SET_MUL_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 23);
2708 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_MUL_OVERFLOW32
);
2710 sljit_emit_op2(compiler
, SLJIT_MUL32
| SLJIT_SET_MUL_NOT_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, -23);
2711 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_MUL_NOT_OVERFLOW32
);
2712 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_MUL_NOT_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, -23);
2713 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_MUL_NOT_OVERFLOW
);
2715 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 67);
2716 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_MUL_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -23);
2717 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R1
, 0);
2719 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
2721 code
.code
= sljit_generate_code(compiler
);
2723 sljit_free_compiler(compiler
);
2725 code
.func1((sljit_sw
)&buf
);
2727 FAILED(buf
[0] != 1, "test31 case 1 failed\n");
2728 FAILED(buf
[1] != 2, "test31 case 2 failed\n");
2729 /* Qemu issues for 64 bit muls. */
2730 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2731 FAILED(buf
[2] != 1, "test31 case 3 failed\n");
2732 FAILED(buf
[3] != 2, "test31 case 4 failed\n");
2734 FAILED(buf
[4] != 1, "test31 case 5 failed\n");
2735 FAILED((buf
[5] & 0xffffffff) != 0x85540c10, "test31 case 6 failed\n");
2736 FAILED(buf
[6] != 2, "test31 case 7 failed\n");
2737 FAILED(buf
[7] != 1, "test31 case 8 failed\n");
2738 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2739 FAILED(buf
[8] != 1, "test31 case 9 failed\n");
2741 FAILED(buf
[9] != -1541, "test31 case 10 failed\n");
2743 sljit_free_code(code
.code
);
2747 static void test32(void)
2749 /* Floating point set flags. */
2750 executable_code code
;
2751 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
2763 printf("Run test32\n");
2783 dbuf
[0].u
.value1
= 0x7fffffff;
2784 dbuf
[0].u
.value2
= 0x7fffffff;
2785 dbuf
[1].u
.value1
= 0x7fffffff;
2786 dbuf
[1].u
.value2
= 0x7fffffff;
2787 dbuf
[2].value
= -13.0;
2788 dbuf
[3].value
= 27.0;
2790 if (!sljit_is_fpu_available()) {
2792 printf("no fpu available, test32 skipped\n");
2795 sljit_free_compiler(compiler
);
2799 FAILED(!compiler
, "cannot create compiler\n");
2800 SLJIT_ASSERT(sizeof(sljit_f64
) == 8 && sizeof(sljit_s32
) == 4 && sizeof(dbuf
[0]) == 8);
2802 sljit_emit_enter(compiler
, 0, 2, 1, 2, 4, 0, 0);
2804 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
2805 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED_F
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
2806 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f64
));
2807 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_UNORDERED_F64
);
2808 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_ORDERED_F
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
2809 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_ORDERED_F64
);
2811 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
));
2812 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2813 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_UNORDERED_F64
);
2814 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_ORDERED_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2815 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_ORDERED_F64
);
2816 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_LESS_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2817 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_LESS_F64
);
2818 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_GREATER_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2819 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_GREATER_EQUAL_F64
);
2820 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_GREATER_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2821 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_GREATER_F64
);
2822 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_LESS_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2823 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_LESS_EQUAL_F64
);
2824 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2825 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_EQUAL_F64
);
2826 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_NOT_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2827 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_NOT_EQUAL_F64
);
2829 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED_F
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
));
2830 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR3
, 0, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
));
2831 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_UNORDERED_F64
);
2832 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_EQUAL_F
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
));
2833 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_EQUAL_F64
);
2835 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_ORDERED_F
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
), SLJIT_FR0
, 0);
2836 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_ORDERED_F64
);
2838 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED_F
, SLJIT_FR3
, 0, SLJIT_FR2
, 0);
2839 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
2840 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_UNORDERED_F64
);
2842 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
2844 code
.code
= sljit_generate_code(compiler
);
2846 sljit_free_compiler(compiler
);
2848 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&dbuf
);
2850 FAILED(buf
[0] != 1, "test32 case 1 failed\n");
2851 FAILED(buf
[1] != 2, "test32 case 2 failed\n");
2852 FAILED(buf
[2] != 2, "test32 case 3 failed\n");
2853 FAILED(buf
[3] != 1, "test32 case 4 failed\n");
2854 FAILED(buf
[4] != 1, "test32 case 5 failed\n");
2855 FAILED(buf
[5] != 2, "test32 case 6 failed\n");
2856 FAILED(buf
[6] != 2, "test32 case 7 failed\n");
2857 FAILED(buf
[7] != 1, "test32 case 8 failed\n");
2858 FAILED(buf
[8] != 2, "test32 case 9 failed\n");
2859 FAILED(buf
[9] != 1, "test32 case 10 failed\n");
2860 FAILED(buf
[10] != 2, "test32 case 11 failed\n");
2861 FAILED(buf
[11] != 1, "test32 case 12 failed\n");
2862 FAILED(buf
[12] != 2, "test32 case 13 failed\n");
2863 FAILED(buf
[13] != 1, "test32 case 14 failed\n");
2865 sljit_free_code(code
.code
);
2869 static void test33(void)
2871 /* Test setting multiple flags. */
2872 executable_code code
;
2873 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
2874 struct sljit_jump
* jump
;
2878 printf("Run test33\n");
2891 FAILED(!compiler
, "cannot create compiler\n");
2893 sljit_emit_enter(compiler
, 0, 1, 3, 3, 0, 0, 0);
2895 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 20);
2896 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 10);
2897 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2898 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_UNUSED
, 0, SLJIT_ZERO
);
2899 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -10);
2900 jump
= sljit_emit_jump(compiler
, SLJIT_LESS
);
2901 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 11);
2902 sljit_set_label(jump
, sljit_emit_label(compiler
));
2904 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_SIG_GREATER
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2905 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_UNUSED
, 0, SLJIT_SIG_GREATER
);
2906 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 45);
2907 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_EQUAL
);
2908 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 55);
2909 sljit_set_label(jump
, sljit_emit_label(compiler
));
2911 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2912 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x8000000000000000));
2914 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x80000000));
2916 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2917 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_NOT_OVERFLOW
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2918 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, 33);
2919 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_OVERFLOW
);
2920 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_UNUSED
, 0, SLJIT_ZERO
);
2921 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, 13);
2922 sljit_set_label(jump
, sljit_emit_label(compiler
));
2924 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x80000000));
2925 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R0
, 0);
2926 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2927 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
2928 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_UNUSED
, 0, SLJIT_NOT_ZERO
);
2929 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, 78);
2930 jump
= sljit_emit_jump(compiler
, SLJIT_OVERFLOW32
);
2931 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, 48);
2932 sljit_set_label(jump
, sljit_emit_label(compiler
));
2934 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2935 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x8000000000000000));
2937 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x80000000));
2939 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_R0
, 0);
2940 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_Z
| SLJIT_SET_NOT_OVERFLOW
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2941 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_IMM
, 30);
2942 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_OVERFLOW
);
2943 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_IMM
, 50);
2944 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_UNUSED
, 0, SLJIT_ZERO
);
2945 sljit_set_label(jump
, sljit_emit_label(compiler
));
2947 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
2949 code
.code
= sljit_generate_code(compiler
);
2951 sljit_free_compiler(compiler
);
2953 code
.func1((sljit_sw
)&buf
);
2955 FAILED(buf
[0] != 0, "test33 case 1 failed\n");
2956 FAILED(buf
[1] != 11, "test33 case 2 failed\n");
2957 FAILED(buf
[2] != 1, "test33 case 3 failed\n");
2958 FAILED(buf
[3] != 45, "test33 case 4 failed\n");
2959 FAILED(buf
[4] != 13, "test33 case 5 failed\n");
2960 FAILED(buf
[5] != 0, "test33 case 6 failed\n");
2961 FAILED(buf
[6] != 0, "test33 case 7 failed\n");
2962 FAILED(buf
[7] != 48, "test33 case 8 failed\n");
2963 FAILED(buf
[8] != 50, "test33 case 9 failed\n");
2964 FAILED(buf
[9] != 1, "test33 case 10 failed\n");
2966 sljit_free_code(code
.code
);
2970 static void test34(void)
2972 /* Test fast calls. */
2973 executable_code codeA
;
2974 executable_code codeB
;
2975 executable_code codeC
;
2976 executable_code codeD
;
2977 executable_code codeE
;
2978 executable_code codeF
;
2979 struct sljit_compiler
* compiler
;
2980 struct sljit_jump
*jump
;
2981 struct sljit_label
* label
;
2986 printf("Run test34\n");
2992 compiler
= sljit_create_compiler(NULL
);
2993 FAILED(!compiler
, "cannot create compiler\n");
2994 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
2996 sljit_emit_fast_enter(compiler
, SLJIT_R1
, 0);
2997 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 4);
2998 sljit_emit_fast_return(compiler
, SLJIT_R1
, 0);
3000 codeA
.code
= sljit_generate_code(compiler
);
3002 sljit_free_compiler(compiler
);
3005 compiler
= sljit_create_compiler(NULL
);
3006 FAILED(!compiler
, "cannot create compiler\n");
3007 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3009 sljit_emit_fast_enter(compiler
, SLJIT_R4
, 0);
3010 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 6);
3011 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(codeA
.code
));
3012 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_R1
, 0);
3013 sljit_emit_fast_return(compiler
, SLJIT_R4
, 0);
3015 codeB
.code
= sljit_generate_code(compiler
);
3017 sljit_free_compiler(compiler
);
3020 compiler
= sljit_create_compiler(NULL
);
3021 FAILED(!compiler
, "cannot create compiler\n");
3022 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3024 sljit_emit_fast_enter(compiler
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_p
));
3025 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3026 jump
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
| SLJIT_REWRITABLE_JUMP
);
3027 sljit_set_target(jump
, SLJIT_FUNC_OFFSET(codeB
.code
));
3028 sljit_emit_fast_return(compiler
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_p
));
3030 codeC
.code
= sljit_generate_code(compiler
);
3032 sljit_free_compiler(compiler
);
3035 compiler
= sljit_create_compiler(NULL
);
3036 FAILED(!compiler
, "cannot create compiler\n");
3037 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3039 sljit_emit_fast_enter(compiler
, SLJIT_MEM1(SLJIT_SP
), 0);
3040 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 10);
3041 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_OFFSET(codeC
.code
));
3042 sljit_emit_fast_return(compiler
, SLJIT_MEM1(SLJIT_SP
), 0);
3044 codeD
.code
= sljit_generate_code(compiler
);
3046 sljit_free_compiler(compiler
);
3049 compiler
= sljit_create_compiler(NULL
);
3050 FAILED(!compiler
, "cannot create compiler\n");
3051 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3053 sljit_emit_fast_enter(compiler
, SLJIT_MEM1(SLJIT_S0
), 0);
3054 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 12);
3055 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_p
), SLJIT_IMM
, SLJIT_FUNC_OFFSET(codeD
.code
));
3056 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_p
));
3057 sljit_emit_fast_return(compiler
, SLJIT_MEM1(SLJIT_S0
), 0);
3059 codeE
.code
= sljit_generate_code(compiler
);
3061 sljit_free_compiler(compiler
);
3064 compiler
= sljit_create_compiler(NULL
);
3065 FAILED(!compiler
, "cannot create compiler\n");
3067 sljit_emit_enter(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3068 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3069 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_OFFSET(codeE
.code
));
3070 label
= sljit_emit_label(compiler
);
3071 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
3073 codeF
.code
= sljit_generate_code(compiler
);
3075 addr
= sljit_get_label_addr(label
);
3076 sljit_free_compiler(compiler
);
3078 FAILED(codeF
.func1((sljit_sw
)&buf
) != 40, "test34 case 1 failed\n");
3079 FAILED(buf
[0] != addr
- SLJIT_RETURN_ADDRESS_OFFSET
, "test34 case 2 failed\n");
3081 sljit_free_code(codeA
.code
);
3082 sljit_free_code(codeB
.code
);
3083 sljit_free_code(codeC
.code
);
3084 sljit_free_code(codeD
.code
);
3085 sljit_free_code(codeE
.code
);
3086 sljit_free_code(codeF
.code
);
3090 static void test35(void)
3092 /* More complicated tests for fast calls. */
3093 executable_code codeA
;
3094 executable_code codeB
;
3095 executable_code codeC
;
3096 struct sljit_compiler
* compiler
;
3097 struct sljit_jump
*jump
= NULL
;
3098 struct sljit_label
* label
;
3099 sljit_sw executable_offset
;
3100 sljit_uw return_addr
;
3101 sljit_uw jump_addr
= 0;
3105 printf("Run test35\n");
3110 compiler
= sljit_create_compiler(NULL
);
3111 FAILED(!compiler
, "cannot create compiler\n");
3112 sljit_set_context(compiler
, 0, 0, 2, 2, 0, 0, 0);
3114 sljit_emit_fast_enter(compiler
, SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
3115 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3117 jump
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
| SLJIT_REWRITABLE_JUMP
);
3118 sljit_set_target(jump
, 0);
3120 label
= sljit_emit_label(compiler
);
3121 sljit_emit_fast_return(compiler
, SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
3123 codeA
.code
= sljit_generate_code(compiler
);
3125 return_addr
= sljit_get_label_addr(label
) - SLJIT_RETURN_ADDRESS_OFFSET
;
3126 executable_offset
= sljit_get_executable_offset(compiler
);
3127 jump_addr
= sljit_get_jump_addr(jump
);
3128 sljit_free_compiler(compiler
);
3131 compiler
= sljit_create_compiler(NULL
);
3132 FAILED(!compiler
, "cannot create compiler\n");
3133 sljit_set_context(compiler
, 0, 0, 2, 2, 0, 0, 0);
3135 sljit_emit_fast_enter(compiler
, SLJIT_UNUSED
, 0);
3136 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 7);
3137 sljit_emit_fast_return(compiler
, SLJIT_IMM
, return_addr
);
3139 codeB
.code
= sljit_generate_code(compiler
);
3141 sljit_free_compiler(compiler
);
3143 sljit_set_jump_addr(jump_addr
, SLJIT_FUNC_OFFSET(codeB
.code
), executable_offset
);
3146 compiler
= sljit_create_compiler(NULL
);
3147 FAILED(!compiler
, "cannot create compiler\n");
3149 sljit_emit_enter(compiler
, 0, 0, 2, 2, 0, 0, 0);
3150 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3151 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_OFFSET(codeA
.code
));
3152 label
= sljit_emit_label(compiler
);
3153 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
3155 codeC
.code
= sljit_generate_code(compiler
);
3157 return_addr
= sljit_get_label_addr(label
);
3158 sljit_free_compiler(compiler
);
3160 FAILED(codeC
.func0() != 12, "test35 case 1 failed\n");
3161 FAILED(buf
[0] != return_addr
- SLJIT_RETURN_ADDRESS_OFFSET
, "test35 case 2 failed\n");
3163 sljit_free_code(codeA
.code
);
3164 sljit_free_code(codeB
.code
);
3165 sljit_free_code(codeC
.code
);
3169 static sljit_s32
cmp_test(struct sljit_compiler
*compiler
, sljit_s32 type
, sljit_s32 src1
, sljit_sw src1w
, sljit_s32 src2
, sljit_sw src2w
)
3171 /* 2 = true, 1 = false */
3172 struct sljit_jump
* jump
;
3173 struct sljit_label
* label
;
3175 if (sljit_emit_op1(compiler
, SLJIT_MOVU_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_IMM
, 2))
3176 return compiler
->error
;
3177 jump
= sljit_emit_cmp(compiler
, type
, src1
, src1w
, src2
, src2w
);
3179 return compiler
->error
;
3180 if (sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 1))
3181 return compiler
->error
;
3182 label
= sljit_emit_label(compiler
);
3184 return compiler
->error
;
3185 sljit_set_label(jump
, label
);
3186 return SLJIT_SUCCESS
;
3189 #define TEST_CASES (7 + 10 + 12 + 11 + 4)
3190 static void test36(void)
3192 /* Compare instruction. */
3193 executable_code code
;
3194 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
3196 sljit_s8 buf
[TEST_CASES
];
3197 sljit_s8 compare_buf
[TEST_CASES
] = {
3198 1, 1, 2, 2, 1, 2, 2,
3199 1, 1, 2, 2, 2, 1, 2, 2, 1, 1,
3200 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2,
3201 2, 1, 2, 1, 1, 1, 2, 1, 2, 1, 2,
3208 printf("Run test36\n");
3210 FAILED(!compiler
, "cannot create compiler\n");
3211 for (i
= 0; i
< TEST_CASES
; ++i
)
3218 sljit_emit_enter(compiler
, 0, 2, 3, 2, 0, 0, 0);
3219 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
3221 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 13);
3222 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 15);
3223 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_IMM
, 9, SLJIT_R0
, 0);
3224 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3225 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
3226 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_IMM
, -13);
3227 cmp_test(compiler
, SLJIT_NOT_EQUAL
, SLJIT_IMM
, 0, SLJIT_R0
, 0);
3228 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3229 cmp_test(compiler
, SLJIT_NOT_EQUAL
| SLJIT_REWRITABLE_JUMP
, SLJIT_IMM
, 0, SLJIT_R0
, 0);
3230 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
);
3231 cmp_test(compiler
, SLJIT_EQUAL
| SLJIT_REWRITABLE_JUMP
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3233 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, 0);
3234 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -8);
3235 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3236 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3237 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3238 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_REWRITABLE_JUMP
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3239 cmp_test(compiler
, SLJIT_SIG_GREATER_EQUAL
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3240 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
));
3241 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_IMM
, 0, SLJIT_R1
, 0);
3242 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
));
3243 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
));
3244 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_REWRITABLE_JUMP
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
));
3246 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3247 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3248 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
));
3249 cmp_test(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3250 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, -10);
3251 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3252 cmp_test(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_IMM
, 8, SLJIT_R1
, 0);
3253 cmp_test(compiler
, SLJIT_GREATER_EQUAL
| SLJIT_REWRITABLE_JUMP
, SLJIT_IMM
, 8, SLJIT_R1
, 0);
3254 cmp_test(compiler
, SLJIT_GREATER
, SLJIT_IMM
, 8, SLJIT_R1
, 0);
3255 cmp_test(compiler
, SLJIT_LESS_EQUAL
, SLJIT_IMM
, 7, SLJIT_R0
, 0);
3256 cmp_test(compiler
, SLJIT_GREATER
, SLJIT_IMM
, 1, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
));
3257 cmp_test(compiler
, SLJIT_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3258 cmp_test(compiler
, SLJIT_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3259 cmp_test(compiler
, SLJIT_GREATER
| SLJIT_REWRITABLE_JUMP
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3261 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -3);
3262 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3263 cmp_test(compiler
, SLJIT_SIG_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3264 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
3265 cmp_test(compiler
, SLJIT_SIG_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3266 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, -1);
3267 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_REWRITABLE_JUMP
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, -1);
3268 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3269 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3270 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_IMM
, -4, SLJIT_R0
, 0);
3271 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_IMM
, -1, SLJIT_R1
, 0);
3272 cmp_test(compiler
, SLJIT_SIG_GREATER
| SLJIT_REWRITABLE_JUMP
, SLJIT_R1
, 0, SLJIT_IMM
, -1);
3274 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3275 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xf00000004));
3276 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R0
, 0);
3277 cmp_test(compiler
, SLJIT_LESS32
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
3278 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3279 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xff0000004));
3280 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R0
, 0);
3281 cmp_test(compiler
, SLJIT_SIG_GREATER32
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
3282 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3284 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
3285 cmp_test(compiler
, SLJIT_LESS32
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3286 cmp_test(compiler
, SLJIT_GREATER32
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3287 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0xf0000004);
3288 cmp_test(compiler
, SLJIT_SIG_GREATER32
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3289 cmp_test(compiler
, SLJIT_SIG_LESS32
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3292 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
3294 code
.code
= sljit_generate_code(compiler
);
3296 sljit_free_compiler(compiler
);
3298 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&data
);
3300 for (i
= 0; i
< TEST_CASES
; ++i
)
3301 if (SLJIT_UNLIKELY(buf
[i
] != compare_buf
[i
])) {
3302 printf("test36 case %d failed\n", i
+ 1);
3306 sljit_free_code(code
.code
);
3311 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3312 #define BITN(n) (SLJIT_W(1) << (63 - (n)))
3315 #define BITN(n) (1 << (31 - ((n) & 0x1f)))
3316 #define RESN(n) ((n) & 0x1f)
3319 static void test37(void)
3321 /* Test count leading zeroes. */
3322 executable_code code
;
3323 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
3329 printf("Run test37\n");
3331 FAILED(!compiler
, "cannot create compiler\n");
3333 for (i
= 0; i
< 15; i
++)
3339 sljit_emit_enter(compiler
, 0, 2, 1, 2, 0, 0, 0);
3340 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, BITN(27));
3341 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
3342 sljit_emit_op1(compiler
, SLJIT_CLZ
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, BITN(47));
3343 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
3344 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_UNUSED
, 0, SLJIT_ZERO
);
3345 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
));
3346 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
3347 sljit_emit_op1(compiler
, SLJIT_CLZ
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3348 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_UNUSED
, 0, SLJIT_ZERO
);
3349 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3350 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3351 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_R0
, 0);
3352 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
3353 sljit_emit_op1(compiler
, SLJIT_CLZ
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0);
3354 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_UNUSED
, 0, SLJIT_ZERO
);
3355 sljit_emit_op1(compiler
, SLJIT_CLZ
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
));
3356 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3357 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_UNUSED
, 0, SLJIT_NOT_ZERO
);
3358 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, BITN(58));
3359 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3360 sljit_emit_op1(compiler
, SLJIT_CLZ
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
));
3361 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_UNUSED
, 0, SLJIT_NOT_ZERO
);
3362 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3363 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3364 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3365 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xff08a00000));
3367 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x08a00000);
3369 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
), SLJIT_R0
, 0);
3370 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3371 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3372 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3373 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xffc8a00000));
3375 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0xc8a00000);
3377 sljit_emit_op1(compiler
, SLJIT_CLZ32
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0);
3378 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_UNUSED
, 0, SLJIT_ZERO32
);
3379 sljit_emit_op1(compiler
, SLJIT_CLZ32
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3380 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3382 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
3384 code
.code
= sljit_generate_code(compiler
);
3386 sljit_free_compiler(compiler
);
3388 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&ibuf
);
3389 FAILED(buf
[0] != RESN(27), "test37 case 1 failed\n");
3390 FAILED(buf
[1] != RESN(47), "test37 case 2 failed\n");
3391 FAILED(buf
[2] != 0, "test37 case 3 failed\n");
3392 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3393 FAILED(buf
[3] != 64, "test37 case 4 failed\n");
3395 FAILED(buf
[3] != 32, "test37 case 4 failed\n");
3397 FAILED(buf
[4] != 1, "test37 case 5 failed\n");
3398 FAILED(buf
[5] != 0, "test37 case 6 failed\n");
3399 FAILED(ibuf
[0] != 32, "test37 case 7 failed\n");
3400 FAILED(buf
[6] != 1, "test37 case 8 failed\n");
3401 FAILED(buf
[7] != RESN(13), "test37 case 9 failed\n");
3402 #if !(defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3403 FAILED(buf
[8] != 1, "test37 case 10 failed\n");
3405 FAILED(buf
[9] != RESN(58), "test37 case 11 failed\n");
3406 FAILED(buf
[10] != 0, "test37 case 12 failed\n");
3407 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3408 FAILED(buf
[11] != 64, "test37 case 13 failed\n");
3410 FAILED(buf
[11] != 32, "test37 case 13 failed\n");
3412 FAILED(ibuf
[1] != 4, "test37 case 14 failed\n");
3413 FAILED((buf
[12] & 0xffffffff) != 4, "test37 case 15 failed\n");
3414 FAILED(buf
[13] != 1, "test37 case 16 failed\n");
3415 FAILED((buf
[14] & 0xffffffff) != 0, "test37 case 17 failed\n");
3417 sljit_free_code(code
.code
);
3423 static void test38(void)
3425 #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)
3426 /* Test stack utility. */
3427 executable_code code
;
3428 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
3429 struct sljit_jump
* alloc1_fail
;
3430 struct sljit_jump
* alloc2_fail
;
3431 struct sljit_jump
* alloc3_fail
;
3432 struct sljit_jump
* sanity1_fail
;
3433 struct sljit_jump
* sanity2_fail
;
3434 struct sljit_jump
* jump
;
3435 struct sljit_label
* label
;
3438 printf("Run test38\n");
3440 FAILED(!compiler
, "cannot create compiler\n");
3442 sljit_emit_enter(compiler
, 0, 0, 3, 1, 0, 0, 0);
3444 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8192);
3445 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 65536);
3446 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0);
3447 sljit_emit_ijump(compiler
, SLJIT_CALL3
, SLJIT_IMM
, SLJIT_FUNC_OFFSET(sljit_allocate_stack
));
3448 alloc1_fail
= sljit_emit_cmp(compiler
, SLJIT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0);
3449 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_RETURN_REG
, 0);
3451 /* Write 8k data. */
3452 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, limit
), SLJIT_IMM
, sizeof(sljit_sw
));
3453 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8192);
3454 label
= sljit_emit_label(compiler
);
3455 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_IMM
, -1);
3456 jump
= sljit_emit_cmp(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3457 sljit_set_label(jump
, label
);
3460 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
3461 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, base
), SLJIT_IMM
, 65536);
3462 sljit_emit_ijump(compiler
, SLJIT_CALL2
, SLJIT_IMM
, SLJIT_FUNC_OFFSET(sljit_stack_resize
));
3463 alloc2_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0);
3465 /* Write 64k data. */
3466 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, limit
), SLJIT_IMM
, sizeof(sljit_sw
));
3467 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 65536);
3468 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
));
3469 sanity1_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, 0, SLJIT_R2
, 0);
3470 label
= sljit_emit_label(compiler
);
3471 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_IMM
, -1);
3472 jump
= sljit_emit_cmp(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3473 sljit_set_label(jump
, label
);
3476 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
3477 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, base
), SLJIT_IMM
, 32768);
3478 sljit_emit_ijump(compiler
, SLJIT_CALL2
, SLJIT_IMM
, SLJIT_FUNC_OFFSET(sljit_stack_resize
));
3479 alloc3_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0);
3481 /* Write 32k data. */
3482 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, limit
), SLJIT_IMM
, sizeof(sljit_sw
));
3483 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, base
), SLJIT_IMM
, sizeof(sljit_sw
));
3484 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
));
3485 sanity2_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, 0, SLJIT_R2
, 0);
3486 label
= sljit_emit_label(compiler
);
3487 sljit_emit_op1(compiler
, SLJIT_MOVU
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_IMM
, -1);
3488 jump
= sljit_emit_cmp(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3489 sljit_set_label(jump
, label
);
3491 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
3492 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3493 sljit_emit_ijump(compiler
, SLJIT_CALL2
, SLJIT_IMM
, SLJIT_FUNC_OFFSET(sljit_free_stack
));
3495 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, 4567);
3497 label
= sljit_emit_label(compiler
);
3498 sljit_set_label(alloc1_fail
, label
);
3499 sljit_set_label(alloc2_fail
, label
);
3500 sljit_set_label(alloc3_fail
, label
);
3501 sljit_set_label(sanity1_fail
, label
);
3502 sljit_set_label(sanity2_fail
, label
);
3503 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, 0);
3505 code
.code
= sljit_generate_code(compiler
);
3507 sljit_free_compiler(compiler
);
3509 /* Just survive this. */
3510 FAILED(code
.func0() != 4567, "test38 case 1 failed\n");
3512 sljit_free_code(code
.code
);
3517 static void test39(void)
3519 /* Test error handling. */
3520 executable_code code
;
3521 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
3522 struct sljit_jump
* jump
;
3525 printf("Run test39\n");
3527 FAILED(!compiler
, "cannot create compiler\n");
3529 /* Such assignment should never happen in a regular program. */
3530 compiler
->error
= -3967;
3532 SLJIT_ASSERT(sljit_emit_enter(compiler
, 0, 2, 5, 5, 6, 0, 32) == -3967);
3533 SLJIT_ASSERT(sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R1
, 0) == -3967);
3534 SLJIT_ASSERT(sljit_emit_op0(compiler
, SLJIT_NOP
) == -3967);
3535 SLJIT_ASSERT(sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1) == -3967);
3536 SLJIT_ASSERT(sljit_emit_op2(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R0
), 64, SLJIT_MEM1(SLJIT_S0
), -64) == -3967);
3537 SLJIT_ASSERT(sljit_emit_fop1(compiler
, SLJIT_ABS_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_R1
), 0) == -3967);
3538 SLJIT_ASSERT(sljit_emit_fop2(compiler
, SLJIT_DIV_F64
, SLJIT_FR2
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_S0
), 0, SLJIT_FR2
, 0) == -3967);
3539 SLJIT_ASSERT(!sljit_emit_label(compiler
));
3540 jump
= sljit_emit_jump(compiler
, SLJIT_CALL3
);
3541 SLJIT_ASSERT(!jump
);
3542 sljit_set_label(jump
, (struct sljit_label
*)0x123450);
3543 sljit_set_target(jump
, 0x123450);
3544 jump
= sljit_emit_cmp(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3545 SLJIT_ASSERT(!jump
);
3546 SLJIT_ASSERT(sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_MEM1(SLJIT_R0
), 8) == -3967);
3547 SLJIT_ASSERT(sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_UNUSED
, 0, SLJIT_MUL_OVERFLOW
) == -3967);
3548 SLJIT_ASSERT(!sljit_emit_const(compiler
, SLJIT_R0
, 0, 99));
3550 SLJIT_ASSERT(!compiler
->labels
&& !compiler
->jumps
&& !compiler
->consts
);
3551 SLJIT_ASSERT(!compiler
->last_label
&& !compiler
->last_jump
&& !compiler
->last_const
);
3552 SLJIT_ASSERT(!compiler
->buf
->next
&& !compiler
->buf
->used_size
);
3553 SLJIT_ASSERT(!compiler
->abuf
->next
&& !compiler
->abuf
->used_size
);
3555 sljit_set_compiler_memory_error(compiler
);
3556 FAILED(sljit_get_compiler_error(compiler
) != -3967, "test39 case 1 failed\n");
3558 code
.code
= sljit_generate_code(compiler
);
3559 FAILED(sljit_get_compiler_error(compiler
) != -3967, "test39 case 2 failed\n");
3560 FAILED(!!code
.code
, "test39 case 3 failed\n");
3561 sljit_free_compiler(compiler
);
3563 compiler
= sljit_create_compiler(NULL
);
3564 FAILED(!compiler
, "cannot create compiler\n");
3566 FAILED(sljit_get_compiler_error(compiler
) != SLJIT_SUCCESS
, "test39 case 4 failed\n");
3567 sljit_set_compiler_memory_error(compiler
);
3568 FAILED(sljit_get_compiler_error(compiler
) != SLJIT_ERR_ALLOC_FAILED
, "test39 case 5 failed\n");
3569 sljit_free_compiler(compiler
);
3574 static void test40(void)
3576 /* Test emit_op_flags. */
3577 executable_code code
;
3578 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
3582 printf("Run test40\n");
3584 FAILED(!compiler
, "cannot create compiler\n");
3596 sljit_emit_enter(compiler
, 0, 1, 3, 4, 0, 0, sizeof(sljit_sw
));
3598 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -5);
3599 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_UNUSED
, 0, SLJIT_IMM
, -6, SLJIT_R0
, 0);
3600 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x123456);
3601 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_SIG_LESS
);
3602 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
3604 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -13);
3605 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_IMM
, -13, SLJIT_R0
, 0);
3606 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 0);
3607 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_EQUAL
);
3608 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_UNUSED
, 0, SLJIT_NOT_EQUAL
);
3609 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);
3610 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_IMM
, -13, SLJIT_R0
, 0);
3611 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3612 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_EQUAL
);
3613 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_UNUSED
, 0, SLJIT_EQUAL
);
3615 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -13);
3616 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3);
3617 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
3618 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
);
3620 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -8);
3621 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 33);
3622 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
3623 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, 0);
3624 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_UNUSED
, 0, SLJIT_GREATER
);
3625 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_S1
, 0, SLJIT_S1
, 0, SLJIT_EQUAL
);
3626 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
3627 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, 0x88);
3628 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_S3
, 0, SLJIT_S3
, 0, SLJIT_NOT_EQUAL
);
3629 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_S1
, 0);
3630 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_S3
, 0);
3632 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x84);
3633 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_IMM
, 0x180, SLJIT_R0
, 0);
3634 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
);
3635 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
);
3637 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3638 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3639 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_NOT_EQUAL
);
3640 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_UNUSED
, 0, SLJIT_NOT_EQUAL
);
3642 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x123456);
3643 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3644 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_GREATER
);
3645 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_R0
, 0);
3647 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 0xbaddead);
3648 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0);
3650 code
.code
= sljit_generate_code(compiler
);
3652 sljit_free_compiler(compiler
);
3654 FAILED(code
.func1((sljit_sw
)&buf
) != 0xbaddead, "test40 case 1 failed\n");
3655 FAILED(buf
[0] != 0x123457, "test40 case 2 failed\n");
3656 FAILED(buf
[1] != 1, "test40 case 3 failed\n");
3657 FAILED(buf
[2] != 0, "test40 case 4 failed\n");
3658 FAILED(buf
[3] != -7, "test40 case 5 failed\n");
3659 FAILED(buf
[4] != 0, "test40 case 6 failed\n");
3660 FAILED(buf
[5] != 0x89, "test40 case 7 failed\n");
3661 FAILED(buf
[6] != 0, "test40 case 8 failed\n");
3662 FAILED(buf
[7] != 1, "test40 case 9 failed\n");
3663 FAILED(buf
[8] != 1, "test40 case 10 failed\n");
3664 FAILED(buf
[9] != 0x123457, "test40 case 11 failed\n");
3666 sljit_free_code(code
.code
);
3670 static void test41(void)
3672 /* Test inline assembly. */
3673 executable_code code
;
3674 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
3677 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3679 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3687 printf("Run test41\n");
3689 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
3690 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3691 if (SLJIT_R(i
) >= SLJIT_R3
&& SLJIT_R(i
) <= SLJIT_R8
) {
3692 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i
)) == -1);
3696 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i
)) >= 0 && sljit_get_register_index(SLJIT_R(i
)) < 64);
3699 FAILED(!compiler
, "cannot create compiler\n");
3700 sljit_emit_enter(compiler
, 0, 2, 3, 3, 0, 0, 0);
3702 /* Returns with the sum of SLJIT_S0 and SLJIT_S1. */
3703 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3704 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3707 inst
[2] = 0x04 | ((sljit_get_register_index(SLJIT_RETURN_REG
) & 0x7) << 3);
3708 inst
[3] = (sljit_get_register_index(SLJIT_S0
) & 0x7)
3709 | ((sljit_get_register_index(SLJIT_S1
) & 0x7) << 3);
3710 sljit_emit_op_custom(compiler
, inst
, 4);
3711 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3712 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3713 inst
[0] = 0x48; /* REX_W */
3716 reg
= sljit_get_register_index(SLJIT_RETURN_REG
);
3717 inst
[2] |= ((reg
& 0x7) << 3);
3719 inst
[0] |= 0x04; /* REX_R */
3720 reg
= sljit_get_register_index(SLJIT_S0
);
3721 inst
[3] = reg
& 0x7;
3723 inst
[0] |= 0x01; /* REX_B */
3724 reg
= sljit_get_register_index(SLJIT_S1
);
3725 inst
[3] |= (reg
& 0x7) << 3;
3727 inst
[0] |= 0x02; /* REX_X */
3728 sljit_emit_op_custom(compiler
, inst
, 4);
3729 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
3730 /* add rd, rn, rm */
3731 inst
= 0xe0800000 | (sljit_get_register_index(SLJIT_RETURN_REG
) << 12)
3732 | (sljit_get_register_index(SLJIT_S0
) << 16)
3733 | sljit_get_register_index(SLJIT_S1
);
3734 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3735 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
3736 /* add rd, rn, rm */
3737 inst
= 0xeb000000 | (sljit_get_register_index(SLJIT_RETURN_REG
) << 8)
3738 | (sljit_get_register_index(SLJIT_S0
) << 16)
3739 | sljit_get_register_index(SLJIT_S1
);
3740 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3741 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3742 /* add rd, rn, rm */
3743 inst
= 0x8b000000 | sljit_get_register_index(SLJIT_RETURN_REG
)
3744 | (sljit_get_register_index(SLJIT_S0
) << 5)
3745 | (sljit_get_register_index(SLJIT_S1
) << 16);
3746 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3747 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3748 /* add rD, rA, rB */
3749 inst
= (31 << 26) | (266 << 1) | (sljit_get_register_index(SLJIT_RETURN_REG
) << 21)
3750 | (sljit_get_register_index(SLJIT_S0
) << 16)
3751 | (sljit_get_register_index(SLJIT_S1
) << 11);
3752 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3753 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
3754 /* addu rd, rs, rt */
3755 inst
= 33 | (sljit_get_register_index(SLJIT_RETURN_REG
) << 11)
3756 | (sljit_get_register_index(SLJIT_S0
) << 21)
3757 | (sljit_get_register_index(SLJIT_S1
) << 16);
3758 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3759 #elif (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
3760 /* daddu rd, rs, rt */
3761 inst
= 45 | (sljit_get_register_index(SLJIT_RETURN_REG
) << 11)
3762 | (sljit_get_register_index(SLJIT_S0
) << 21)
3763 | (sljit_get_register_index(SLJIT_S1
) << 16);
3764 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3765 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3766 /* add rd, rs1, rs2 */
3767 inst
= (0x2 << 30) | (sljit_get_register_index(SLJIT_RETURN_REG
) << 25)
3768 | (sljit_get_register_index(SLJIT_S0
) << 14)
3769 | sljit_get_register_index(SLJIT_S1
);
3770 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3773 sljit_emit_op_custom(compiler
, &inst
, 0);
3776 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
3778 code
.code
= sljit_generate_code(compiler
);
3780 sljit_free_compiler(compiler
);
3782 FAILED(code
.func2(32, -11) != 21, "test41 case 1 failed\n");
3783 FAILED(code
.func2(1000, 234) != 1234, "test41 case 2 failed\n");
3784 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3785 FAILED(code
.func2(SLJIT_W(0x20f0a04090c06070), SLJIT_W(0x020f0a04090c0607)) != SLJIT_W(0x22ffaa4499cc6677), "test41 case 3 failed\n");
3788 sljit_free_code(code
.code
);
3790 if (sljit_is_fpu_available()) {
3795 compiler
= sljit_create_compiler(NULL
);
3796 sljit_emit_enter(compiler
, 0, 1, 0, 1, 2, 0, 0);
3797 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
3798 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
3799 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3804 inst
[3] = 0xc0 | (sljit_get_float_register_index(SLJIT_FR0
) << 3)
3805 | sljit_get_float_register_index(SLJIT_FR1
);
3806 sljit_emit_op_custom(compiler
, inst
, 4);
3807 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3809 if (sljit_get_float_register_index(SLJIT_FR0
) > 7 || sljit_get_float_register_index(SLJIT_FR1
) > 7) {
3811 if (sljit_get_float_register_index(SLJIT_FR0
) > 7)
3812 inst
[0] |= 0x04; /* REX_R */
3813 if (sljit_get_float_register_index(SLJIT_FR1
) > 7)
3814 inst
[0] |= 0x01; /* REX_B */
3818 inst
[4] = 0xc0 | ((sljit_get_float_register_index(SLJIT_FR0
) & 0x7) << 3)
3819 | (sljit_get_float_register_index(SLJIT_FR1
) & 0x7);
3820 sljit_emit_op_custom(compiler
, inst
, 5);
3826 inst
[3] = 0xc0 | (sljit_get_float_register_index(SLJIT_FR0
) << 3)
3827 | sljit_get_float_register_index(SLJIT_FR1
);
3828 sljit_emit_op_custom(compiler
, inst
, 4);
3830 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
3831 /* vadd.f64 dd, dn, dm */
3832 inst
= 0xee300b00 | ((sljit_get_float_register_index(SLJIT_FR0
) >> 1) << 12)
3833 | ((sljit_get_float_register_index(SLJIT_FR0
) >> 1) << 16)
3834 | (sljit_get_float_register_index(SLJIT_FR1
) >> 1);
3835 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3836 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3837 /* fadd rd, rn, rm */
3838 inst
= 0x1e602800 | sljit_get_float_register_index(SLJIT_FR0
)
3839 | (sljit_get_float_register_index(SLJIT_FR0
) << 5)
3840 | (sljit_get_float_register_index(SLJIT_FR1
) << 16);
3841 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3842 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3843 /* fadd frD, frA, frB */
3844 inst
= (63 << 26) | (21 << 1) | (sljit_get_float_register_index(SLJIT_FR0
) << 21)
3845 | (sljit_get_float_register_index(SLJIT_FR0
) << 16)
3846 | (sljit_get_float_register_index(SLJIT_FR1
) << 11);
3847 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3848 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
3849 /* add.d fd, fs, ft */
3850 inst
= (17 << 26) | (17 << 21) | (sljit_get_float_register_index(SLJIT_FR0
) << 6)
3851 | (sljit_get_float_register_index(SLJIT_FR0
) << 11)
3852 | (sljit_get_float_register_index(SLJIT_FR1
) << 16);
3853 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3854 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3855 /* faddd rd, rs1, rs2 */
3856 inst
= (0x2 << 30) | (0x34 << 19) | (0x42 << 5)
3857 | (sljit_get_float_register_index(SLJIT_FR0
) << 25)
3858 | (sljit_get_float_register_index(SLJIT_FR0
) << 14)
3859 | sljit_get_float_register_index(SLJIT_FR1
);
3860 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3862 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
3863 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
3865 code
.code
= sljit_generate_code(compiler
);
3867 sljit_free_compiler(compiler
);
3869 code
.func1((sljit_sw
)&buf
);
3870 FAILED(buf
[2] != 11.25, "test41 case 3 failed\n");
3872 sljit_free_code(code
.code
);
3878 static void test42(void)
3880 /* Test long multiply and division. */
3881 executable_code code
;
3882 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
3884 sljit_sw buf
[7 + 4 + 8 + 8];
3887 printf("Run test42\n");
3889 FAILED(!compiler
, "cannot create compiler\n");
3890 for (i
= 0; i
< 7 + 4 + 8 + 8; i
++)
3893 sljit_emit_enter(compiler
, 0, 1, 5, 5, 0, 0, 0);
3895 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -0x1fb308a);
3896 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0xf50c873);
3897 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, 0x8a0475b);
3898 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, 0x9dc849b);
3899 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -0x7c69a35);
3900 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, 0x5a4d0c4);
3901 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_IMM
, 0x9a3b06d);
3903 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3904 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3905 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3906 sljit_emit_op0(compiler
, SLJIT_LMUL_UW
);
3907 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3908 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3910 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3911 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3912 sljit_emit_op0(compiler
, SLJIT_LMUL_SW
);
3913 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3914 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3916 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3917 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3918 sljit_emit_op0(compiler
, SLJIT_DIVMOD_UW
);
3919 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3920 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3922 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3923 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3924 sljit_emit_op0(compiler
, SLJIT_DIVMOD_SW
);
3925 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3926 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3928 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x5cf783d3cf0a74b0));
3929 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3d5df42d03a28fc7));
3930 sljit_emit_op0(compiler
, SLJIT_DIVMOD_U32
);
3931 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3932 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3933 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3934 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3936 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x371df5197ba26a28));
3937 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x46c78a5cfd6a420c));
3938 sljit_emit_op0(compiler
, SLJIT_DIVMOD_S32
);
3939 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3940 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3941 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3942 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3944 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xc456f048c28a611b));
3945 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3d4af2c543));
3946 sljit_emit_op0(compiler
, SLJIT_DIV_UW
);
3947 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 19 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3948 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3950 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x720fa4b74c329b14));
3951 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0xa64ae42b7d6));
3952 sljit_emit_op0(compiler
, SLJIT_DIV_SW
);
3953 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 21 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3954 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3956 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x4af51c027b34));
3957 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x9ba4ff2906b14));
3958 sljit_emit_op0(compiler
, SLJIT_DIV_U32
);
3959 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3960 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3961 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 23 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3962 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 24 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3964 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xc40b58a3f20d));
3965 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(-0xa63c923));
3966 sljit_emit_op0(compiler
, SLJIT_DIV_S32
);
3967 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3968 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3969 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 25 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3970 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 26 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3973 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
3974 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
3975 sljit_emit_op0(compiler
, SLJIT_LMUL_UW
);
3976 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3977 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3979 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
3980 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
3981 sljit_emit_op0(compiler
, SLJIT_LMUL_SW
);
3982 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3983 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3985 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
3986 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
3987 sljit_emit_op0(compiler
, SLJIT_DIVMOD_UW
);
3988 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3989 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3991 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
3992 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
3993 sljit_emit_op0(compiler
, SLJIT_DIVMOD_SW
);
3994 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3995 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3997 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0xcf0a74b0);
3998 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0x03a28fc7);
3999 sljit_emit_op0(compiler
, SLJIT_DIVMOD_U32
);
4000 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4001 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4003 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x7ba26a28);
4004 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)0xfd6a420c);
4005 sljit_emit_op0(compiler
, SLJIT_DIVMOD_S32
);
4006 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4007 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4009 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x9d4b7036));
4010 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0xb86d0));
4011 sljit_emit_op0(compiler
, SLJIT_DIV_UW
);
4012 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 19 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4013 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4015 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x58b0692c));
4016 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0xd357));
4017 sljit_emit_op0(compiler
, SLJIT_DIV_SW
);
4018 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 21 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4019 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4021 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1c027b34));
4022 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0xf2906b14));
4023 sljit_emit_op0(compiler
, SLJIT_DIV_U32
);
4024 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4025 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
4026 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 23 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4027 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 24 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4029 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x58a3f20d));
4030 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(-0xa63c923));
4031 sljit_emit_op0(compiler
, SLJIT_DIV_S32
);
4032 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4033 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
4034 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 25 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4035 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 26 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4038 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R2
, 0);
4039 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R3
, 0);
4040 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R4
, 0);
4041 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_S1
, 0);
4042 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_S2
, 0);
4043 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_S3
, 0);
4044 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_S4
, 0);
4046 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
4048 code
.code
= sljit_generate_code(compiler
);
4050 sljit_free_compiler(compiler
);
4052 code
.func1((sljit_sw
)&buf
);
4054 FAILED(buf
[0] != -0x1fb308a, "test42 case 1 failed\n");
4055 FAILED(buf
[1] != 0xf50c873, "test42 case 2 failed\n");
4056 FAILED(buf
[2] != 0x8a0475b, "test42 case 3 failed\n");
4057 FAILED(buf
[3] != 0x9dc849b, "test42 case 4 failed\n");
4058 FAILED(buf
[4] != -0x7c69a35, "test42 case 5 failed\n");
4059 FAILED(buf
[5] != 0x5a4d0c4, "test42 case 6 failed\n");
4060 FAILED(buf
[6] != 0x9a3b06d, "test42 case 7 failed\n");
4062 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4063 FAILED(buf
[7] != SLJIT_W(-4388959407985636971), "test42 case 8 failed\n");
4064 FAILED(buf
[8] != SLJIT_W(2901680654366567099), "test42 case 9 failed\n");
4065 FAILED(buf
[9] != SLJIT_W(-4388959407985636971), "test42 case 10 failed\n");
4066 FAILED(buf
[10] != SLJIT_W(-1677173957268872740), "test42 case 11 failed\n");
4067 FAILED(buf
[11] != SLJIT_W(2), "test42 case 12 failed\n");
4068 FAILED(buf
[12] != SLJIT_W(2532236178951865933), "test42 case 13 failed\n");
4069 FAILED(buf
[13] != SLJIT_W(-1), "test42 case 14 failed\n");
4070 FAILED(buf
[14] != SLJIT_W(-2177944059851366166), "test42 case 15 failed\n");
4072 FAILED(buf
[7] != -1587000939, "test42 case 8 failed\n");
4073 FAILED(buf
[8] != 665003983, "test42 case 9 failed\n");
4074 FAILED(buf
[9] != -1587000939, "test42 case 10 failed\n");
4075 FAILED(buf
[10] != -353198352, "test42 case 11 failed\n");
4076 FAILED(buf
[11] != 2, "test42 case 12 failed\n");
4077 FAILED(buf
[12] != 768706125, "test42 case 13 failed\n");
4078 FAILED(buf
[13] != -1, "test42 case 14 failed\n");
4079 FAILED(buf
[14] != -471654166, "test42 case 15 failed\n");
4082 FAILED(buf
[15] != SLJIT_W(56), "test42 case 16 failed\n");
4083 FAILED(buf
[16] != SLJIT_W(58392872), "test42 case 17 failed\n");
4084 FAILED(buf
[17] != SLJIT_W(-47), "test42 case 18 failed\n");
4085 FAILED(buf
[18] != SLJIT_W(35949148), "test42 case 19 failed\n");
4087 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4088 FAILED(buf
[19] != SLJIT_W(0x3340bfc), "test42 case 20 failed\n");
4089 FAILED(buf
[20] != SLJIT_W(0x3d4af2c543), "test42 case 21 failed\n");
4090 FAILED(buf
[21] != SLJIT_W(-0xaf978), "test42 case 22 failed\n");
4091 FAILED(buf
[22] != SLJIT_W(0xa64ae42b7d6), "test42 case 23 failed\n");
4093 FAILED(buf
[19] != SLJIT_W(0xda5), "test42 case 20 failed\n");
4094 FAILED(buf
[20] != SLJIT_W(0xb86d0), "test42 case 21 failed\n");
4095 FAILED(buf
[21] != SLJIT_W(-0x6b6e), "test42 case 22 failed\n");
4096 FAILED(buf
[22] != SLJIT_W(0xd357), "test42 case 23 failed\n");
4099 FAILED(buf
[23] != SLJIT_W(0x0), "test42 case 24 failed\n");
4100 FAILED(buf
[24] != SLJIT_W(0xf2906b14), "test42 case 25 failed\n");
4101 FAILED(buf
[25] != SLJIT_W(-0x8), "test42 case 26 failed\n");
4102 FAILED(buf
[26] != SLJIT_W(-0xa63c923), "test42 case 27 failed\n");
4104 sljit_free_code(code
.code
);
4108 static void test43(void)
4110 /* Test floating point compare. */
4111 executable_code code
;
4112 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
4113 struct sljit_jump
* jump
;
4124 printf("Run test43\n");
4126 if (!sljit_is_fpu_available()) {
4128 printf("no fpu available, test43 skipped\n");
4131 sljit_free_compiler(compiler
);
4135 FAILED(!compiler
, "cannot create compiler\n");
4137 dbuf
[0].value
= 12.125;
4139 dbuf
[1].u
.value1
= 0x7fffffff;
4140 dbuf
[1].u
.value2
= 0x7fffffff;
4141 dbuf
[2].value
= -13.5;
4142 dbuf
[3].value
= 12.125;
4144 sljit_emit_enter(compiler
, 0, 1, 1, 1, 3, 0, 0);
4145 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
4146 /* dbuf[0] < dbuf[2] -> -2 */
4147 jump
= sljit_emit_fcmp(compiler
, SLJIT_GREATER_EQUAL_F64
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), SLJIT_F64_SHIFT
);
4148 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, -2);
4150 sljit_set_label(jump
, sljit_emit_label(compiler
));
4151 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4152 /* dbuf[0] and dbuf[1] is not NaN -> 5 */
4153 jump
= sljit_emit_fcmp(compiler
, SLJIT_UNORDERED_F64
, SLJIT_MEM0(), (sljit_sw
)&dbuf
[1], SLJIT_FR1
, 0);
4154 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, 5);
4156 sljit_set_label(jump
, sljit_emit_label(compiler
));
4157 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
));
4158 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 11);
4159 /* dbuf[0] == dbuf[3] -> 11 */
4160 jump
= sljit_emit_fcmp(compiler
, SLJIT_EQUAL_F64
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_FR2
, 0);
4163 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, -17);
4164 sljit_set_label(jump
, sljit_emit_label(compiler
));
4165 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
4167 code
.code
= sljit_generate_code(compiler
);
4169 sljit_free_compiler(compiler
);
4171 FAILED(code
.func1((sljit_sw
)&dbuf
) != 11, "test43 case 1 failed\n");
4173 FAILED(code
.func1((sljit_sw
)&dbuf
) != -17, "test43 case 2 failed\n");
4175 FAILED(code
.func1((sljit_sw
)&dbuf
) != 5, "test43 case 3 failed\n");
4177 FAILED(code
.func1((sljit_sw
)&dbuf
) != -2, "test43 case 4 failed\n");
4179 sljit_free_code(code
.code
);
4183 static void test44(void)
4186 executable_code code
;
4187 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
4191 printf("Run test44\n");
4193 FAILED(!compiler
, "cannot create compiler\n");
4200 sljit_emit_enter(compiler
, 0, 1, 3, 2, 0, 0, 0);
4202 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4203 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_p
), SLJIT_R0
, 0);
4204 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_p
));
4205 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 2);
4206 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R1
), SLJIT_POINTER_SHIFT
, SLJIT_R0
, 0);
4207 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_p
));
4208 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3 << SLJIT_POINTER_SHIFT
);
4209 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_S0
, 0);
4210 sljit_emit_op1(compiler
, SLJIT_MOVU_P
, SLJIT_MEM2(SLJIT_R2
, SLJIT_R1
), 0, SLJIT_R0
, 0);
4211 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 2 * sizeof(sljit_p
));
4212 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM1(SLJIT_R2
), sizeof(sljit_p
), SLJIT_R0
, 0);
4214 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
4216 code
.code
= sljit_generate_code(compiler
);
4218 sljit_free_compiler(compiler
);
4220 FAILED(code
.func1((sljit_sw
)&buf
) != (sljit_sw
)(buf
+ 2), "test44 case 1 failed\n");
4221 FAILED(buf
[1] != buf
+ 2, "test44 case 2 failed\n");
4222 FAILED(buf
[2] != buf
+ 3, "test44 case 3 failed\n");
4223 FAILED(buf
[3] != buf
+ 4, "test44 case 4 failed\n");
4224 FAILED(buf
[4] != buf
+ 2, "test44 case 5 failed\n");
4226 sljit_free_code(code
.code
);
4230 static void test45(void)
4232 /* Test single precision floating point. */
4234 executable_code code
;
4235 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
4238 struct sljit_jump
* jump
;
4241 printf("Run test45\n");
4243 if (!sljit_is_fpu_available()) {
4245 printf("no fpu available, test45 skipped\n");
4248 sljit_free_compiler(compiler
);
4252 FAILED(!compiler
, "cannot create compiler\n");
4274 sljit_emit_enter(compiler
, 0, 2, 3, 2, 6, 0, 0);
4276 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4277 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4278 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
4279 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_FR1
, 0, SLJIT_FR5
, 0);
4280 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f32
), SLJIT_FR1
, 0);
4281 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f32
), SLJIT_FR5
, 0);
4282 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_FR4
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4283 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f32
), SLJIT_FR4
, 0);
4285 sljit_emit_fop2(compiler
, SLJIT_ADD_F32
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4286 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
4287 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);
4288 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4289 sljit_emit_fop2(compiler
, SLJIT_MUL_F32
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_f32
), SLJIT_FR0
, 0, SLJIT_FR0
, 0);
4290 sljit_emit_fop2(compiler
, SLJIT_DIV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
4291 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f32
), SLJIT_FR2
, 0);
4292 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x3d0ac);
4293 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_R0
), 0x3d0ac);
4294 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x3d0ac + sizeof(sljit_f32
));
4295 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_R0
), -0x3d0ac);
4297 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4298 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4299 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4300 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_EQUAL_F32
);
4301 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_LESS_F
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4302 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
), SLJIT_LESS_F32
);
4303 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
4304 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
), SLJIT_EQUAL_F32
);
4305 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_GREATER_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
4306 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
), SLJIT_GREATER_EQUAL_F32
);
4308 jump
= sljit_emit_fcmp(compiler
, SLJIT_LESS_EQUAL_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4309 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, 7);
4310 sljit_set_label(jump
, sljit_emit_label(compiler
));
4312 jump
= sljit_emit_fcmp(compiler
, SLJIT_GREATER_F32
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_FR2
, 0);
4313 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_IMM
, 6);
4314 sljit_set_label(jump
, sljit_emit_label(compiler
));
4316 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
4318 code
.code
= sljit_generate_code(compiler
);
4320 sljit_free_compiler(compiler
);
4322 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&buf2
);
4323 FAILED(buf
[2] != -5.5, "test45 case 1 failed\n");
4324 FAILED(buf
[3] != 7.25, "test45 case 2 failed\n");
4325 FAILED(buf
[4] != 7.25, "test45 case 3 failed\n");
4326 FAILED(buf
[5] != -5.5, "test45 case 4 failed\n");
4327 FAILED(buf
[6] != -1.75, "test45 case 5 failed\n");
4328 FAILED(buf
[7] != 16.0, "test45 case 6 failed\n");
4329 FAILED(buf
[8] != 30.25, "test45 case 7 failed\n");
4330 FAILED(buf
[9] != 3, "test45 case 8 failed\n");
4331 FAILED(buf
[10] != -5.5, "test45 case 9 failed\n");
4332 FAILED(buf
[11] != 7.25, "test45 case 10 failed\n");
4333 FAILED(buf2
[0] != 1, "test45 case 11 failed\n");
4334 FAILED(buf2
[1] != 2, "test45 case 12 failed\n");
4335 FAILED(buf2
[2] != 2, "test45 case 13 failed\n");
4336 FAILED(buf2
[3] != 1, "test45 case 14 failed\n");
4337 FAILED(buf2
[4] != 7, "test45 case 15 failed\n");
4338 FAILED(buf2
[5] != -1, "test45 case 16 failed\n");
4340 sljit_free_code(code
.code
);
4344 static void test46(void)
4346 /* Test sljit_emit_op_flags with 32 bit operations. */
4348 executable_code code
;
4349 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
4355 printf("Run test46\n");
4357 for (i
= 0; i
< 24; ++i
)
4360 for (i
= 0; i
< 6; ++i
)
4364 sljit_emit_enter(compiler
, 0, 2, 3, 3, 0, 0, 0);
4366 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4367 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 13);
4368 sljit_emit_op_flags(compiler
, SLJIT_MOV_S32
, SLJIT_MEM0(), (sljit_sw
)&buf
, SLJIT_UNUSED
, 0, SLJIT_LESS
);
4369 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
);
4371 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4372 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
);
4373 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
);
4374 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1235);
4375 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x1235);
4376 sljit_emit_op_flags(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_ZERO
);
4377 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
);
4378 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4380 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4381 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 12);
4382 sljit_emit_op_flags(compiler
, SLJIT_MOV_U32
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 2, SLJIT_UNUSED
, 0, SLJIT_EQUAL
);
4383 sljit_emit_op_flags(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_UNUSED
, 0, SLJIT_EQUAL
);
4384 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4385 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
4386 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
);
4387 sljit_emit_op_flags(compiler
, SLJIT_MOV_U32
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_s32
), SLJIT_UNUSED
, 0, SLJIT_NOT_EQUAL32
);
4389 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4390 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
);
4391 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 39);
4392 sljit_emit_op_flags(compiler
, SLJIT_XOR32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_NOT_ZERO
);
4393 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4395 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4396 sljit_emit_op_flags(compiler
, SLJIT_AND
, SLJIT_MEM0(), (sljit_sw
)&buf2
, SLJIT_MEM0(), (sljit_sw
)&buf2
, SLJIT_GREATER
);
4397 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 5);
4398 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
4399 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
);
4400 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
4401 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 5);
4402 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_UNUSED
, 0, SLJIT_LESS
);
4403 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_UNUSED
, 0, SLJIT_NOT_EQUAL
);
4404 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 5);
4405 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
), SLJIT_S2
, 0);
4406 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
);
4407 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
);
4408 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 0);
4409 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
);
4411 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
4413 code
.code
= sljit_generate_code(compiler
);
4415 sljit_free_compiler(compiler
);
4417 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&buf2
);
4418 FAILED(buf
[0] != 0, "test46 case 1 failed\n");
4419 FAILED(buf
[1] != -17, "test46 case 2 failed\n");
4420 FAILED(buf
[2] != 1, "test46 case 3 failed\n");
4421 FAILED(buf
[3] != -17, "test46 case 4 failed\n");
4422 FAILED(buf
[4] != 1, "test46 case 5 failed\n");
4423 FAILED(buf
[5] != -17, "test46 case 6 failed\n");
4424 FAILED(buf
[6] != 1, "test46 case 7 failed\n");
4425 FAILED(buf
[7] != -17, "test46 case 8 failed\n");
4426 FAILED(buf
[8] != 0, "test46 case 9 failed\n");
4427 FAILED(buf
[9] != -17, "test46 case 10 failed\n");
4428 FAILED(buf
[10] != 1, "test46 case 11 failed\n");
4429 FAILED(buf
[11] != -17, "test46 case 12 failed\n");
4430 FAILED(buf
[12] != 1, "test46 case 13 failed\n");
4431 FAILED(buf
[13] != -17, "test46 case 14 failed\n");
4432 FAILED(buf
[14] != 1, "test46 case 15 failed\n");
4433 FAILED(buf
[15] != -17, "test46 case 16 failed\n");
4434 FAILED(buf
[16] != 0, "test46 case 17 failed\n");
4435 FAILED(buf
[17] != -17, "test46 case 18 failed\n");
4436 FAILED(buf
[18] != 0, "test46 case 19 failed\n");
4437 FAILED(buf
[19] != -17, "test46 case 20 failed\n");
4438 FAILED(buf
[20] != -18, "test46 case 21 failed\n");
4439 FAILED(buf
[21] != -17, "test46 case 22 failed\n");
4440 FAILED(buf
[22] != 38, "test46 case 23 failed\n");
4441 FAILED(buf
[23] != -17, "test46 case 24 failed\n");
4443 FAILED(buf2
[0] != 0, "test46 case 25 failed\n");
4444 FAILED(buf2
[1] != 1, "test46 case 26 failed\n");
4445 FAILED(buf2
[2] != 0, "test46 case 27 failed\n");
4446 FAILED(buf2
[3] != 1, "test46 case 28 failed\n");
4447 FAILED(buf2
[4] != -123, "test46 case 29 failed\n");
4448 FAILED(buf2
[5] != -14, "test46 case 30 failed\n");
4450 sljit_free_code(code
.code
);
4454 static void test47(void)
4456 /* Test jump optimizations. */
4457 executable_code code
;
4458 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
4462 printf("Run test47\n");
4464 FAILED(!compiler
, "cannot create compiler\n");
4469 sljit_emit_enter(compiler
, 0, 1, 3, 1, 0, 0, 0);
4470 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x3a5c6f);
4471 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 3);
4472 sljit_set_target(sljit_emit_jump(compiler
, SLJIT_LESS
), 0x11223344);
4473 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
4474 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xd37c10);
4475 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4476 sljit_set_target(sljit_emit_jump(compiler
, SLJIT_LESS
), SLJIT_W(0x112233445566));
4478 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
4479 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x59b48e);
4480 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4481 sljit_set_target(sljit_emit_jump(compiler
, SLJIT_LESS
), SLJIT_W(0x1122334455667788));
4483 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4484 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
4486 code
.code
= sljit_generate_code(compiler
);
4488 sljit_free_compiler(compiler
);
4490 code
.func1((sljit_sw
)&buf
);
4491 FAILED(buf
[0] != 0x3a5c6f, "test47 case 1 failed\n");
4492 FAILED(buf
[1] != 0xd37c10, "test47 case 2 failed\n");
4493 FAILED(buf
[2] != 0x59b48e, "test47 case 3 failed\n");
4495 sljit_free_code(code
.code
);
4499 static void test48(void)
4501 /* Test floating point conversions. */
4502 executable_code code
;
4503 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
4511 printf("Run test48\n");
4513 if (!sljit_is_fpu_available()) {
4515 printf("no fpu available, test48 skipped\n");
4518 sljit_free_compiler(compiler
);
4522 FAILED(!compiler
, "cannot create compiler\n");
4523 for (i
= 0; i
< 9; i
++) {
4542 sljit_emit_enter(compiler
, 0, 0, 3, 3, 6, 0, 0);
4543 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
4544 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, (sljit_sw
)&sbuf
);
4545 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
4546 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
4549 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_F64
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S0
), 0);
4550 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4551 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
4553 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_F64
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_F32_SHIFT
, SLJIT_FR5
, 0);
4554 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_F32
, SLJIT_FR4
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
4556 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
), SLJIT_FR4
, 0);
4557 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
4558 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_F32
, SLJIT_FR2
, 0, SLJIT_FR3
, 0);
4560 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
4562 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_f32
), SLJIT_FR3
, 0);
4565 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
4566 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
4567 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_UNUSED
, 0, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), SLJIT_F64_SHIFT
);
4568 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_R0
, 0, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), SLJIT_F64_SHIFT
);
4570 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4571 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
4573 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F32
, SLJIT_MEM1(SLJIT_S2
), 3 * sizeof(sljit_sw
), SLJIT_FR5
, 0);
4574 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_FR0
, 0, SLJIT_FR5
, 0);
4575 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 4);
4577 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F32
, SLJIT_MEM2(SLJIT_S2
, SLJIT_R1
), SLJIT_WORD_SHIFT
, SLJIT_FR0
, 0);
4578 sljit_emit_fop1(compiler
, SLJIT_NEG_F64
, SLJIT_FR4
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
));
4580 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F64
, SLJIT_MEM1(SLJIT_R2
), 2 * sizeof(sljit_s32
), SLJIT_FR4
, 0);
4581 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
4582 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F32
, SLJIT_R0
, 0, SLJIT_FR1
, 0);
4584 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_R2
), 3 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4587 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S2
), 0);
4588 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_FR2
, 0, SLJIT_IMM
, -6213);
4590 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
4592 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_f64
), SLJIT_MEM0(), (sljit_sw
)&ibuf
[0]);
4593 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R2
), sizeof(sljit_s32
));
4594 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_FR1
, 0, SLJIT_R0
, 0);
4596 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_f64
), SLJIT_FR1
, 0);
4598 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_f32
), SLJIT_IMM
, -123);
4599 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 7190);
4600 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_FR3
, 0, SLJIT_R0
, 0);
4602 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 6 * sizeof(sljit_f32
), SLJIT_FR3
, 0);
4603 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 123);
4604 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 123 * sizeof(sljit_s32
));
4605 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_S32
, SLJIT_FR1
, 0, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 2);
4607 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 7 * sizeof(sljit_f32
), SLJIT_FR1
, 0);
4608 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
4609 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 3812);
4611 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_S32
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_F32_SHIFT
, SLJIT_R1
, 0);
4613 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
4615 code
.code
= sljit_generate_code(compiler
);
4617 sljit_free_compiler(compiler
);
4620 FAILED(dbuf
[3] != 476.25, "test48 case 1 failed\n");
4621 FAILED(dbuf
[4] != 476.25, "test48 case 2 failed\n");
4622 FAILED(dbuf
[5] != 2345.0, "test48 case 3 failed\n");
4623 FAILED(dbuf
[6] != -6213.0, "test48 case 4 failed\n");
4624 FAILED(dbuf
[7] != 312.0, "test48 case 5 failed\n");
4625 FAILED(dbuf
[8] != -9324.0, "test48 case 6 failed\n");
4627 FAILED(sbuf
[2] != 123.5, "test48 case 7 failed\n");
4628 FAILED(sbuf
[3] != 123.5, "test48 case 8 failed\n");
4629 FAILED(sbuf
[4] != 476.25, "test48 case 9 failed\n");
4630 FAILED(sbuf
[5] != -123, "test48 case 10 failed\n");
4631 FAILED(sbuf
[6] != 7190, "test48 case 11 failed\n");
4632 FAILED(sbuf
[7] != 312, "test48 case 12 failed\n");
4633 FAILED(sbuf
[8] != 3812, "test48 case 13 failed\n");
4635 FAILED(wbuf
[1] != -367, "test48 case 14 failed\n");
4636 FAILED(wbuf
[2] != 917, "test48 case 15 failed\n");
4637 FAILED(wbuf
[3] != 476, "test48 case 16 failed\n");
4638 FAILED(wbuf
[4] != -476, "test48 case 17 failed\n");
4640 FAILED(ibuf
[2] != -917, "test48 case 18 failed\n");
4641 FAILED(ibuf
[3] != -1689, "test48 case 19 failed\n");
4643 sljit_free_code(code
.code
);
4647 static void test49(void)
4649 /* Test floating point conversions. */
4650 executable_code code
;
4651 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
4657 sljit_s32
* dbuf_ptr
= (sljit_s32
*)dbuf
;
4658 sljit_s32
* sbuf_ptr
= (sljit_s32
*)sbuf
;
4661 printf("Run test49\n");
4663 if (!sljit_is_fpu_available()) {
4665 printf("no fpu available, test49 skipped\n");
4668 sljit_free_compiler(compiler
);
4672 FAILED(!compiler
, "cannot create compiler\n");
4674 for (i
= 0; i
< 9; i
++) {
4675 dbuf_ptr
[i
<< 1] = -1;
4676 dbuf_ptr
[(i
<< 1) + 1] = -1;
4682 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4683 dbuf
[9] = (sljit_f64
)SLJIT_W(0x1122334455);
4690 sljit_emit_enter(compiler
, 0, 0, 3, 3, 3, 0, 0);
4691 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
4692 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, (sljit_sw
)&sbuf
);
4693 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
4694 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
4697 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_F32
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S1
), 0);
4699 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_F64
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S0
), 0);
4701 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 0);
4703 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F32
, SLJIT_MEM1(SLJIT_S2
), 4 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S1
), 0);
4705 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F64
, SLJIT_MEM1(SLJIT_R2
), 2 * sizeof(sljit_s32
), SLJIT_MEM1(SLJIT_S0
), 0);
4707 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F32
, SLJIT_MEM1(SLJIT_R2
), 4 * sizeof(sljit_s32
), SLJIT_MEM1(SLJIT_S1
), 0);
4709 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S2
), 0);
4711 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S2
), 0);
4713 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_R2
), 0);
4715 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_S32
, SLJIT_MEM1(SLJIT_S1
), 6 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_R2
), 0);
4717 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4718 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f64
));
4720 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), 8 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4721 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f64
));
4722 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F64
, SLJIT_R0
, 0, SLJIT_FR2
, 0);
4723 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4724 sljit_emit_op2(compiler
, SLJIT_AND32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffff);
4726 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R2
), 8 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4727 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x4455667788));
4729 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_f64
), SLJIT_R0
, 0);
4731 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f64
), SLJIT_IMM
, SLJIT_W(0x7766554433));
4734 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
4736 code
.code
= sljit_generate_code(compiler
);
4738 sljit_free_compiler(compiler
);
4742 FAILED(dbuf_ptr
[(1 * 2) + 0] != -1, "test49 case 1 failed\n");
4743 FAILED(dbuf_ptr
[(1 * 2) + 1] != -1, "test49 case 2 failed\n");
4744 FAILED(dbuf
[2] != -879.75, "test49 case 3 failed\n");
4745 FAILED(dbuf_ptr
[(3 * 2) + 0] != -1, "test49 case 4 failed\n");
4746 FAILED(dbuf_ptr
[(3 * 2) + 1] != -1, "test49 case 5 failed\n");
4747 FAILED(dbuf
[4] != 345, "test49 case 6 failed\n");
4748 FAILED(dbuf_ptr
[(5 * 2) + 0] != -1, "test49 case 7 failed\n");
4749 FAILED(dbuf_ptr
[(5 * 2) + 1] != -1, "test49 case 8 failed\n");
4750 FAILED(dbuf
[6] != -249, "test49 case 9 failed\n");
4751 FAILED(dbuf_ptr
[(7 * 2) + 0] != -1, "test49 case 10 failed\n");
4752 FAILED(dbuf_ptr
[(7 * 2) + 1] != -1, "test49 case 11 failed\n");
4754 FAILED(sbuf_ptr
[1] != -1, "test49 case 12 failed\n");
4755 FAILED(sbuf
[2] != 673.75, "test49 case 13 failed\n");
4756 FAILED(sbuf_ptr
[3] != -1, "test49 case 14 failed\n");
4757 FAILED(sbuf
[4] != 345, "test49 case 15 failed\n");
4758 FAILED(sbuf_ptr
[5] != -1, "test49 case 16 failed\n");
4759 FAILED(sbuf
[6] != -249, "test49 case 17 failed\n");
4760 FAILED(sbuf_ptr
[7] != -1, "test49 case 18 failed\n");
4762 FAILED(wbuf
[1] != -1, "test49 case 19 failed\n");
4763 FAILED(wbuf
[2] != 673, "test49 case 20 failed\n");
4764 FAILED(wbuf
[3] != -1, "test49 case 21 failed\n");
4765 FAILED(wbuf
[4] != -879, "test49 case 22 failed\n");
4766 FAILED(wbuf
[5] != -1, "test49 case 23 failed\n");
4768 FAILED(ibuf
[1] != -1, "test49 case 24 failed\n");
4769 FAILED(ibuf
[2] != 673, "test49 case 25 failed\n");
4770 FAILED(ibuf
[3] != -1, "test49 case 26 failed\n");
4771 FAILED(ibuf
[4] != -879, "test49 case 27 failed\n");
4772 FAILED(ibuf
[5] != -1, "test49 case 28 failed\n");
4774 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4775 FAILED(dbuf
[8] != (sljit_f64
)SLJIT_W(0x4455667788), "test49 case 29 failed\n");
4776 FAILED(dbuf
[9] != (sljit_f64
)SLJIT_W(0x66554433), "test49 case 30 failed\n");
4777 FAILED(wbuf
[8] != SLJIT_W(0x1122334455), "test48 case 31 failed\n");
4778 FAILED(ibuf
[8] == 0x4455, "test48 case 32 failed\n");
4781 sljit_free_code(code
.code
);
4785 static void test50(void)
4787 /* Test stack and floating point operations. */
4788 executable_code code
;
4789 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
4790 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4791 sljit_uw size1
, size2
, size3
;
4797 printf("Run test50\n");
4799 if (!sljit_is_fpu_available()) {
4801 printf("no fpu available, test50 skipped\n");
4804 sljit_free_compiler(compiler
);
4808 FAILED(!compiler
, "cannot create compiler\n");
4814 sljit_emit_enter(compiler
, 0, 1, 3, 3, 6, 0, 8 * sizeof(sljit_f32
));
4816 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
4817 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), 0);
4819 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_f32
));
4820 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4821 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
));
4823 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), 2 * sizeof(sljit_f32
));
4824 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 2 * sizeof(sljit_f32
), SLJIT_IMM
, 5934);
4825 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
));
4827 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), 3 * sizeof(sljit_f32
));
4829 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4830 size1
= compiler
->size
;
4832 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f32
));
4833 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4834 size2
= compiler
->size
;
4836 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR5
, 0, SLJIT_FR2
, 0);
4837 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4838 size3
= compiler
->size
;
4841 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f32
), SLJIT_FR5
, 0);
4842 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4843 result
= (compiler
->size
- size3
) == (size3
- size2
) && (size3
- size2
) == (size2
- size1
);
4846 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
4848 code
.code
= sljit_generate_code(compiler
);
4850 sljit_free_compiler(compiler
);
4852 code
.func1((sljit_sw
)&sbuf
);
4854 FAILED(sbuf
[3] != 245.5, "test50 case 1 failed\n");
4855 FAILED(sbuf
[4] != 145.25, "test50 case 2 failed\n");
4856 FAILED(sbuf
[5] != 5934, "test50 case 3 failed\n");
4857 FAILED(sbuf
[6] != 713.75, "test50 case 4 failed\n");
4858 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4859 FAILED(!result
, "test50 case 5 failed\n");
4862 sljit_free_code(code
.code
);
4866 static void test51(void)
4868 /* Test all registers provided by the CPU. */
4869 executable_code code
;
4870 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
4871 struct sljit_jump
* jump
;
4875 FAILED(!compiler
, "cannot create compiler\n");
4879 sljit_emit_enter(compiler
, 0, 0, SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0, 0);
4881 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4882 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 32);
4884 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)buf
);
4885 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
4887 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
4888 if (sljit_get_register_index(SLJIT_R(i
)) >= 0) {
4889 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_R0
, 0);
4890 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_R(i
)), 0);
4892 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, buf
[0]);
4895 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 32);
4896 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
4897 if (sljit_get_register_index(SLJIT_R(i
)) >= 0) {
4898 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_R0
, 0);
4899 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_R(i
)), 32);
4901 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, buf
[0]);
4904 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
4905 if (sljit_get_register_index(SLJIT_R(i
)) >= 0) {
4906 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 32);
4907 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM2(SLJIT_R(i
), SLJIT_R0
), 0);
4908 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_R(i
)), 0);
4909 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 8);
4910 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_R(i
)), 2);
4912 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 3 * buf
[0]);
4915 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 32 + sizeof(sljit_sw
), SLJIT_R1
, 0);
4917 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
4919 code
.code
= sljit_generate_code(compiler
);
4921 sljit_free_compiler(compiler
);
4925 FAILED(buf
[1] != (39 * 5 * (SLJIT_NUMBER_OF_REGISTERS
- 2)), "test51 case 1 failed\n");
4927 sljit_free_code(code
.code
);
4931 compiler
= sljit_create_compiler(NULL
);
4933 FAILED(!compiler
, "cannot create compiler\n");
4935 sljit_emit_enter(compiler
, 0, 0, SLJIT_NUMBER_OF_SCRATCH_REGISTERS
, SLJIT_NUMBER_OF_SAVED_REGISTERS
, 0, 0, 0);
4937 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4938 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 17);
4940 jump
= sljit_emit_jump(compiler
, SLJIT_CALL0
);
4941 /* SLJIT_R0 contains the first value. */
4942 for (i
= 1; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4943 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
4945 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
4947 sljit_set_label(jump
, sljit_emit_label(compiler
));
4948 sljit_emit_enter(compiler
, 0, 0, SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0, 0);
4949 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4950 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 35);
4951 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
4953 code
.code
= sljit_generate_code(compiler
);
4955 sljit_free_compiler(compiler
);
4957 FAILED(code
.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS
* 35 + SLJIT_NUMBER_OF_SAVED_REGISTERS
* 17), "test51 case 2 failed\n");
4959 sljit_free_code(code
.code
);
4963 compiler
= sljit_create_compiler(NULL
);
4965 FAILED(!compiler
, "cannot create compiler\n");
4967 sljit_emit_enter(compiler
, 0, 0, SLJIT_NUMBER_OF_SCRATCH_REGISTERS
, SLJIT_NUMBER_OF_SAVED_REGISTERS
, 0, 0, 0);
4969 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4970 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 68);
4972 jump
= sljit_emit_jump(compiler
, SLJIT_CALL0
);
4973 /* SLJIT_R0 contains the first value. */
4974 for (i
= 1; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4975 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
4977 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
4979 sljit_set_label(jump
, sljit_emit_label(compiler
));
4980 sljit_emit_enter(compiler
, 0, 0, 0, SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0);
4981 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4982 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S(i
), 0, SLJIT_IMM
, 43);
4983 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
4985 code
.code
= sljit_generate_code(compiler
);
4987 sljit_free_compiler(compiler
);
4989 FAILED(code
.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS
* 43 + SLJIT_NUMBER_OF_SAVED_REGISTERS
* 68), "test51 case 3 failed\n");
4991 sljit_free_code(code
.code
);
4995 static void test52(void)
4997 /* Test all registers provided by the CPU. */
4998 executable_code code
;
4999 struct sljit_compiler
* compiler
;
5000 struct sljit_jump
* jump
;
5004 if (!sljit_is_fpu_available()) {
5006 printf("no fpu available, test52 skipped\n");
5013 compiler
= sljit_create_compiler(NULL
);
5014 FAILED(!compiler
, "cannot create compiler\n");
5018 sljit_emit_enter(compiler
, 0, 1, 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
, 0);
5020 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5021 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
5023 jump
= sljit_emit_jump(compiler
, SLJIT_CALL0
);
5024 /* SLJIT_FR0 contains the first value. */
5025 for (i
= 1; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5026 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_FR(i
), 0);
5027 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5029 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5031 sljit_set_label(jump
, sljit_emit_label(compiler
));
5032 sljit_emit_enter(compiler
, 0, 0, 1, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0, 0);
5033 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[1]);
5034 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5035 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_MEM1(SLJIT_R0
), 0);
5036 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5038 code
.code
= sljit_generate_code(compiler
);
5040 sljit_free_compiler(compiler
);
5042 code
.func1((sljit_sw
)&buf
);
5043 FAILED(buf
[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
* 17.75 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
* 6.25), "test52 case 1 failed\n");
5045 sljit_free_code(code
.code
);
5049 compiler
= sljit_create_compiler(NULL
);
5050 FAILED(!compiler
, "cannot create compiler\n");
5054 sljit_emit_enter(compiler
, 0, 1, 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
, 0);
5056 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5057 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
5059 jump
= sljit_emit_jump(compiler
, SLJIT_CALL0
);
5060 /* SLJIT_FR0 contains the first value. */
5061 for (i
= 1; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5062 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_FR(i
), 0);
5063 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5065 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5067 sljit_set_label(jump
, sljit_emit_label(compiler
));
5068 sljit_emit_enter(compiler
, 0, 0, 1, 0, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0);
5069 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[1]);
5070 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5071 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FS(i
), 0, SLJIT_MEM1(SLJIT_R0
), 0);
5072 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5074 code
.code
= sljit_generate_code(compiler
);
5076 sljit_free_compiler(compiler
);
5078 code
.func1((sljit_sw
)&buf
);
5079 FAILED(buf
[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
* -11.25 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
* -32.5), "test52 case 2 failed\n");
5081 sljit_free_code(code
.code
);
5085 static void test53(void)
5087 /* Check SLJIT_DOUBLE_ALIGNMENT. */
5088 executable_code code
;
5089 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
5093 printf("Run test53\n");
5095 FAILED(!compiler
, "cannot create compiler\n");
5098 sljit_emit_enter(compiler
, SLJIT_F64_ALIGNMENT
, 1, 1, 1, 0, 0, 2 * sizeof(sljit_sw
));
5100 sljit_get_local_base(compiler
, SLJIT_R0
, 0, 0);
5101 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
5103 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5105 code
.code
= sljit_generate_code(compiler
);
5107 sljit_free_compiler(compiler
);
5109 code
.func1((sljit_sw
)&buf
);
5111 FAILED((buf
[0] & (sizeof(sljit_f64
) - 1)) != 0, "test53 case 1 failed\n");
5113 sljit_free_code(code
.code
);
5117 compiler
= sljit_create_compiler(NULL
);
5118 FAILED(!compiler
, "cannot create compiler\n");
5121 /* One more saved register to break the alignment on x86-32. */
5122 sljit_emit_enter(compiler
, SLJIT_F64_ALIGNMENT
, 1, 1, 2, 0, 0, 2 * sizeof(sljit_sw
));
5124 sljit_get_local_base(compiler
, SLJIT_R0
, 0, 0);
5125 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
5127 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5129 code
.code
= sljit_generate_code(compiler
);
5131 sljit_free_compiler(compiler
);
5133 code
.func1((sljit_sw
)&buf
);
5135 FAILED((buf
[0] & (sizeof(sljit_f64
) - 1)) != 0, "test53 case 2 failed\n");
5137 sljit_free_code(code
.code
);
5141 static void test54(void)
5143 /* Check x86 cmov. */
5144 executable_code code
;
5145 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
5150 printf("Run test54\n");
5152 FAILED(!compiler
, "cannot create compiler\n");
5167 sljit_emit_enter(compiler
, 0, 2, 2, 2, 0, 0, 0);
5169 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
5170 if (sljit_x86_is_cmov_available()) {
5171 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 17);
5172 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 34);
5173 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -10);
5174 sljit_x86_emit_cmov(compiler
, SLJIT_SIG_LESS
, SLJIT_R0
, SLJIT_R1
, 0);
5175 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
5176 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -10);
5177 sljit_x86_emit_cmov(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, SLJIT_R1
, 0);
5178 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5180 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 24);
5181 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 24);
5182 sljit_x86_emit_cmov(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, SLJIT_MEM1(SLJIT_S0
), 0);
5183 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5184 sljit_x86_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R0
, SLJIT_MEM1(SLJIT_S0
), 0);
5185 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5186 sljit_x86_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R0
, SLJIT_IMM
, -135);
5187 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5189 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 177);
5190 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 177);
5191 sljit_x86_emit_cmov(compiler
, SLJIT_LESS32
, SLJIT_R0
| SLJIT_I32_OP
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_s32
));
5192 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_s32
), SLJIT_R0
, 0);
5194 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 177);
5195 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 177);
5196 sljit_x86_emit_cmov(compiler
, SLJIT_GREATER32
, SLJIT_R0
| SLJIT_I32_OP
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_s32
));
5197 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_s32
), SLJIT_R0
, 0);
5199 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 177);
5200 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS_EQUAL
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 177);
5201 sljit_x86_emit_cmov(compiler
, SLJIT_LESS_EQUAL32
, SLJIT_R0
| SLJIT_I32_OP
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_s32
));
5202 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
), SLJIT_R0
, 0);
5204 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 5 * sizeof(sljit_s32
));
5205 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_GREATER_EQUAL
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
5206 sljit_x86_emit_cmov(compiler
, SLJIT_GREATER_EQUAL32
, SLJIT_R0
| SLJIT_I32_OP
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R1
), 0);
5207 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_R0
, 0);
5211 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5213 code
.code
= sljit_generate_code(compiler
);
5215 sljit_free_compiler(compiler
);
5217 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&ibuf
);
5219 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
5220 if (sljit_x86_is_cmov_available()) {
5221 FAILED(buf
[1] != 17, "test54 case 1 failed\n");
5222 FAILED(buf
[2] != 34, "test54 case 2 failed\n");
5223 FAILED(buf
[3] != 24, "test54 case 3 failed\n");
5224 FAILED(buf
[4] != 98, "test54 case 4 failed\n");
5225 FAILED(buf
[5] != -135, "test54 case 5 failed\n");
5226 FAILED(ibuf
[0] != 38, "test54 case 6 failed\n");
5227 FAILED(ibuf
[1] != 67, "test54 case 7 failed\n");
5228 FAILED(ibuf
[2] != 177, "test54 case 8 failed\n");
5229 FAILED(ibuf
[3] != 177, "test54 case 9 failed\n");
5233 sljit_free_code(code
.code
);
5237 static void test55(void)
5239 /* Check value preservation. */
5240 executable_code code
;
5241 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
);
5246 printf("Run test55\n");
5248 FAILED(!compiler
, "cannot create compiler\n");
5252 sljit_emit_enter(compiler
, 0, 0, SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0, sizeof (sljit_sw
));
5254 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 217);
5257 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5258 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 118);
5260 sljit_emit_op0(compiler
, SLJIT_DIVMOD_SW
);
5262 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5264 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5265 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
5266 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_SP
), 0);
5268 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)(buf
+ 0), SLJIT_R0
, 0);
5271 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5272 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 146);
5274 sljit_emit_op0(compiler
, SLJIT_DIV_SW
);
5276 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5278 for (i
= 1; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5279 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
5280 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_SP
), 0);
5282 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)(buf
+ 1), SLJIT_R0
, 0);
5284 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5286 code
.code
= sljit_generate_code(compiler
);
5288 sljit_free_compiler(compiler
);
5292 FAILED(buf
[0] != (SLJIT_NUMBER_OF_REGISTERS
- 2) * 118 + 217, "test55 case 1 failed\n");
5293 FAILED(buf
[1] != (SLJIT_NUMBER_OF_REGISTERS
- 1) * 146 + 217, "test55 case 2 failed\n");
5295 sljit_free_code(code
.code
);
5299 void sljit_test(int argc
, char* argv
[])
5301 sljit_s32 has_arg
= (argc
>= 2 && argv
[1][0] == '-' && argv
[1][2] == '\0');
5302 verbose
= has_arg
&& argv
[1][1] == 'v';
5303 silent
= has_arg
&& argv
[1][1] == 's';
5305 if (!verbose
&& !silent
)
5306 printf("Pass -v to enable verbose, -s to disable this hint.\n\n");
5308 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
5309 test_exec_allocator();
5367 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
5368 sljit_free_unused_memory_exec();
5371 # define TEST_COUNT 55
5373 printf("SLJIT tests: ");
5374 if (successful_tests
== TEST_COUNT
)
5375 printf("all tests are " COLOR_GREEN
"PASSED" COLOR_DEFAULT
" ");
5377 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);
5378 printf("on " COLOR_ARCH
"%s" COLOR_DEFAULT
"%s\n", sljit_get_platform_name(), sljit_is_fpu_available() ? " (with fpu)" : " (without fpu)");