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. */
36 #pragma warning(disable: 4127) /* conditional expression is constant */
39 #if defined _WIN32 || defined _WIN64
45 #define COLOR_RED "\33[31m"
46 #define COLOR_GREEN "\33[32m"
47 #define COLOR_ARCH "\33[33m"
48 #define COLOR_DEFAULT "\33[0m"
51 union executable_code
{
53 sljit_sw (SLJIT_FUNC
*func0
)(void);
54 sljit_sw (SLJIT_FUNC
*func1
)(sljit_sw a
);
55 sljit_sw (SLJIT_FUNC
*func2
)(sljit_sw a
, sljit_sw b
);
56 sljit_sw (SLJIT_FUNC
*func3
)(sljit_sw a
, sljit_sw b
, sljit_sw c
);
58 typedef union executable_code executable_code
;
60 static sljit_s32 successful_tests
= 0;
61 static sljit_s32 verbose
= 0;
62 static sljit_s32 silent
= 0;
64 #define FAILED(cond, text) \
65 if (SLJIT_UNLIKELY(cond)) { \
70 #define CHECK(compiler) \
71 if (sljit_get_compiler_error(compiler) != SLJIT_ERR_COMPILED) { \
72 printf("Compiler error: %d\n", sljit_get_compiler_error(compiler)); \
73 sljit_free_compiler(compiler); \
77 static void cond_set(struct sljit_compiler
*compiler
, sljit_s32 dst
, sljit_sw dstw
, sljit_s32 type
)
79 /* Testing both sljit_emit_op_flags and sljit_emit_jump. */
80 struct sljit_jump
* jump
;
81 struct sljit_label
* label
;
83 sljit_emit_op_flags(compiler
, SLJIT_MOV
, dst
, dstw
, type
);
84 jump
= sljit_emit_jump(compiler
, type
);
85 sljit_emit_op2(compiler
, SLJIT_ADD
, dst
, dstw
, dst
, dstw
, SLJIT_IMM
, 2);
86 label
= sljit_emit_label(compiler
);
87 sljit_set_label(jump
, label
);
90 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
92 /* For interface testing and for test64. */
93 void *sljit_test_malloc_exec(sljit_uw size
, void *exec_allocator_data
)
95 if (exec_allocator_data
)
96 return exec_allocator_data
;
98 return SLJIT_BUILTIN_MALLOC_EXEC(size
, exec_allocator_data
);
101 /* For interface testing. */
102 void sljit_test_free_code(void* code
, void *exec_allocator_data
)
104 SLJIT_BUILTIN_FREE_EXEC(code
, exec_allocator_data
);
107 #define MALLOC_EXEC(result, size) \
108 result = SLJIT_MALLOC_EXEC(size, NULL); \
110 printf("Cannot allocate executable memory\n"); \
113 memset(result, 255, size);
115 #define FREE_EXEC(ptr) \
116 SLJIT_FREE_EXEC(((sljit_u8*)(ptr)) + SLJIT_EXEC_OFFSET(ptr), NULL);
118 static void test_exec_allocator(void)
120 /* This is not an sljit test. */
126 printf("Run executable allocator test\n");
128 MALLOC_EXEC(ptr1
, 32);
129 MALLOC_EXEC(ptr2
, 512);
130 MALLOC_EXEC(ptr3
, 512);
134 MALLOC_EXEC(ptr1
, 262104);
135 MALLOC_EXEC(ptr2
, 32000);
137 MALLOC_EXEC(ptr1
, 262104);
140 MALLOC_EXEC(ptr1
, 512);
141 MALLOC_EXEC(ptr2
, 512);
142 MALLOC_EXEC(ptr3
, 512);
144 MALLOC_EXEC(ptr2
, 512);
145 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
146 sljit_free_unused_memory_exec();
152 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
153 sljit_free_unused_memory_exec();
159 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
161 static void test1(void)
163 /* Enter and return from an sljit function. */
164 executable_code code
;
165 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
168 printf("Run test1\n");
170 FAILED(!compiler
, "cannot create compiler\n");
172 /* 3 arguments passed, 3 arguments used. */
173 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
), 3, 3, 0, 0, 0);
174 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_S1
, 0);
176 SLJIT_ASSERT(sljit_get_generated_code_size(compiler
) == 0);
177 code
.code
= sljit_generate_code(compiler
);
179 SLJIT_ASSERT(compiler
->error
== SLJIT_ERR_COMPILED
);
180 SLJIT_ASSERT(sljit_get_generated_code_size(compiler
) > 0);
181 sljit_free_compiler(compiler
);
183 FAILED(code
.func3(3, -21, 86) != -21, "test1 case 1 failed\n");
184 FAILED(code
.func3(4789, 47890, 997) != 47890, "test1 case 2 failed\n");
186 sljit_free_code(code
.code
, NULL
);
190 static void test2(void)
193 executable_code code
;
194 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
196 static sljit_sw data
[2] = { 0, -9876 };
199 printf("Run test2\n");
201 FAILED(!compiler
, "cannot create compiler\n");
211 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 2, 0, 0, 0);
212 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 9999);
213 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_S0
, 0);
214 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
), SLJIT_R0
, 0);
215 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
216 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_MEM2(SLJIT_S1
, SLJIT_R1
), 0);
217 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 2);
218 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_S1
, SLJIT_S0
), SLJIT_WORD_SHIFT
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R1
), 0);
219 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 3);
220 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_S1
, SLJIT_S0
), SLJIT_WORD_SHIFT
, SLJIT_MEM0(), (sljit_sw
)&buf
);
221 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
222 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&data
);
223 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
224 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
- 0x12345678);
225 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R0
), 0x12345678);
226 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_R0
, 0);
227 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3456);
228 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
- 0xff890 + 6 * sizeof(sljit_sw
));
229 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0xff890, SLJIT_R0
, 0);
230 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
+ 0xff890 + 7 * sizeof(sljit_sw
));
231 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), -0xff890, SLJIT_R0
, 0);
232 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R2
, 0);
234 code
.code
= sljit_generate_code(compiler
);
236 sljit_free_compiler(compiler
);
238 FAILED(code
.func1((sljit_sw
)&buf
) != 9999, "test2 case 1 failed\n");
239 FAILED(buf
[1] != 9999, "test2 case 2 failed\n");
240 FAILED(buf
[2] != 9999, "test2 case 3 failed\n");
241 FAILED(buf
[3] != 5678, "test2 case 4 failed\n");
242 FAILED(buf
[4] != -9876, "test2 case 5 failed\n");
243 FAILED(buf
[5] != 5678, "test2 case 6 failed\n");
244 FAILED(buf
[6] != 3456, "test2 case 6 failed\n");
245 FAILED(buf
[7] != 3456, "test2 case 6 failed\n");
247 sljit_free_code(code
.code
, NULL
);
251 static void test3(void)
254 executable_code code
;
255 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
259 printf("Run test3\n");
261 FAILED(!compiler
, "cannot create compiler\n");
268 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 1, 0, 0, 0);
269 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 0);
270 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_MEM0(), (sljit_sw
)&buf
[1], SLJIT_MEM0(), (sljit_sw
)&buf
[1]);
271 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_RETURN_REG
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
272 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2);
273 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[4] - 0xff0000 - 0x20);
274 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[4] - 0xff0000);
275 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_MEM1(SLJIT_R1
), 0xff0000 + 0x20, SLJIT_MEM1(SLJIT_R2
), 0xff0000);
276 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
278 code
.code
= sljit_generate_code(compiler
);
280 sljit_free_compiler(compiler
);
282 FAILED(code
.func1((sljit_sw
)&buf
) != ~1234, "test3 case 1 failed\n");
283 FAILED(buf
[1] != ~1234, "test3 case 2 failed\n");
284 FAILED(buf
[3] != ~9876, "test3 case 3 failed\n");
285 FAILED(buf
[4] != ~0x12345678, "test3 case 4 failed\n");
287 sljit_free_code(code
.code
, NULL
);
291 static void test4(void)
294 executable_code code
;
295 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
299 printf("Run test4\n");
301 FAILED(!compiler
, "cannot create compiler\n");
307 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
), 3, 2, 0, 0, 0);
308 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_S1
, 0);
309 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_MEM0(), (sljit_sw
)&buf
[0], SLJIT_MEM0(), (sljit_sw
)&buf
[1]);
310 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 299);
311 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_R1
, 0);
312 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_RETURN_REG
, 0, SLJIT_S1
, 0);
313 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
315 code
.code
= sljit_generate_code(compiler
);
317 sljit_free_compiler(compiler
);
319 FAILED(code
.func2((sljit_sw
)&buf
, 4567) != -4567, "test4 case 1 failed\n");
320 FAILED(buf
[0] != -1234, "test4 case 2 failed\n");
321 FAILED(buf
[2] != -4567, "test4 case 3 failed\n");
322 FAILED(buf
[3] != -299, "test4 case 4 failed\n");
324 sljit_free_code(code
.code
, NULL
);
328 static void test5(void)
331 executable_code code
;
332 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
336 printf("Run test5\n");
338 FAILED(!compiler
, "cannot create compiler\n");
349 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 2, 0, 0, 0);
350 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
351 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 50);
352 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);
353 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
) + 2);
354 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 50);
355 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
356 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
357 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_IMM
, 4, SLJIT_R0
, 0);
358 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_IMM
, 50, SLJIT_R1
, 0);
359 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
));
360 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R1
, 0);
361 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
));
362 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
));
363 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);
364 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x1e7d39f2);
365 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R1
, 0, SLJIT_IMM
, 0x23de7c06);
366 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, 0x3d72e452, SLJIT_R1
, 0);
367 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
));
368 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_IMM
, 1000, SLJIT_R0
, 0);
369 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1430);
370 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_IMM
, -99, SLJIT_R0
, 0);
372 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
374 code
.code
= sljit_generate_code(compiler
);
376 sljit_free_compiler(compiler
);
378 FAILED(code
.func1((sljit_sw
)&buf
) != 2437 + 2 * sizeof(sljit_sw
), "test5 case 1 failed\n");
379 FAILED(buf
[0] != 202 + 2 * sizeof(sljit_sw
), "test5 case 2 failed\n");
380 FAILED(buf
[2] != 500, "test5 case 3 failed\n");
381 FAILED(buf
[3] != 400, "test5 case 4 failed\n");
382 FAILED(buf
[4] != 200, "test5 case 5 failed\n");
383 FAILED(buf
[5] != 250, "test5 case 6 failed\n");
384 FAILED(buf
[6] != 0x425bb5f8, "test5 case 7 failed\n");
385 FAILED(buf
[7] != 0x5bf01e44, "test5 case 8 failed\n");
386 FAILED(buf
[8] != 270, "test5 case 9 failed\n");
388 sljit_free_code(code
.code
, NULL
);
392 static void test6(void)
394 /* Test addc, sub, subc. */
395 executable_code code
;
396 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
400 printf("Run test6\n");
402 FAILED(!compiler
, "cannot create compiler\n");
415 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 1, 0, 0, 0);
416 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
417 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -1);
418 sljit_emit_op2(compiler
, SLJIT_ADDC
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0, SLJIT_IMM
, 0);
419 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R0
, 0);
420 sljit_emit_op2(compiler
, SLJIT_ADDC
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 4);
421 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 100);
422 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, SLJIT_IMM
, 50);
423 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 6000);
424 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_IMM
, 10);
425 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);
426 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 100);
427 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2);
428 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R0
, 0);
429 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5000);
430 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R0
, 0);
431 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
432 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R1
, 0);
433 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5000);
434 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_IMM
, 6000, SLJIT_R0
, 0);
435 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_R0
, 0);
436 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 100);
437 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 32768);
438 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_R1
, 0);
439 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -32767);
440 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_R1
, 0);
441 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x52cd3bf4);
442 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_R0
, 0, SLJIT_IMM
, 0x3da297c6);
443 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 6000);
444 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, SLJIT_R1
, 0);
445 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, SLJIT_R1
, 0);
446 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 10);
447 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_RETURN_REG
, 0, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 5);
448 sljit_emit_op2(compiler
, SLJIT_SUBC
, SLJIT_RETURN_REG
, 0, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 2);
449 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_RETURN_REG
, 0, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, -2220);
450 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
452 code
.code
= sljit_generate_code(compiler
);
454 sljit_free_compiler(compiler
);
456 FAILED(code
.func1((sljit_sw
)&buf
) != 2223, "test6 case 1 failed\n");
457 FAILED(buf
[0] != 1, "test6 case 2 failed\n");
458 FAILED(buf
[1] != 5, "test6 case 3 failed\n");
459 FAILED(buf
[2] != 50, "test6 case 4 failed\n");
460 FAILED(buf
[3] != 4, "test6 case 5 failed\n");
461 FAILED(buf
[4] != 50, "test6 case 6 failed\n");
462 FAILED(buf
[5] != 50, "test6 case 7 failed\n");
463 FAILED(buf
[6] != 1000, "test6 case 8 failed\n");
464 FAILED(buf
[7] != 100 - 32768, "test6 case 9 failed\n");
465 FAILED(buf
[8] != 100 + 32767, "test6 case 10 failed\n");
466 FAILED(buf
[9] != 0x152aa42e, "test6 case 11 failed\n");
467 FAILED(buf
[10] != -2000, "test6 case 12 failed\n");
469 sljit_free_code(code
.code
, NULL
);
473 static void test7(void)
475 /* Test logical operators. */
476 executable_code code
;
477 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
481 printf("Run test7\n");
483 FAILED(!compiler
, "cannot create compiler\n");
493 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 1, 0, 0, 0);
494 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xf0C000);
495 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, SLJIT_IMM
, 0x308f);
496 sljit_emit_op2(compiler
, SLJIT_XOR
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
497 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);
498 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xC0F0);
499 sljit_emit_op2(compiler
, SLJIT_XOR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5);
500 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xff0000);
501 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R0
, 0);
502 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0xC0F0);
503 sljit_emit_op2(compiler
, SLJIT_AND
, SLJIT_R2
, 0, SLJIT_R2
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5);
504 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R2
, 0, SLJIT_IMM
, 0xff0000);
505 sljit_emit_op2(compiler
, SLJIT_XOR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 0xFFFFFF, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
506 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);
507 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7);
508 sljit_emit_op2(compiler
, SLJIT_XOR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_IMM
, 0xff00ff00, SLJIT_R0
, 0);
509 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xff00ff00);
510 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x0f);
511 sljit_emit_op2(compiler
, SLJIT_AND
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0x888888, SLJIT_R1
, 0);
512 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
514 code
.code
= sljit_generate_code(compiler
);
516 sljit_free_compiler(compiler
);
518 FAILED(code
.func1((sljit_sw
)&buf
) != 0x8808, "test7 case 1 failed\n");
519 FAILED(buf
[0] != 0x0F807F00, "test7 case 2 failed\n");
520 FAILED(buf
[1] != 0x0F7F7F7F, "test7 case 3 failed\n");
521 FAILED(buf
[2] != 0x00F0F08F, "test7 case 4 failed\n");
522 FAILED(buf
[3] != 0x00A0A0A0, "test7 case 5 failed\n");
523 FAILED(buf
[4] != 0x00FF80B0, "test7 case 6 failed\n");
524 FAILED(buf
[5] != 0x00FF4040, "test7 case 7 failed\n");
525 FAILED(buf
[6] != 0xa56c82c0, "test7 case 8 failed\n");
526 FAILED(buf
[7] != 0x3b3a8095, "test7 case 9 failed\n");
528 sljit_free_code(code
.code
, NULL
);
532 static void test8(void)
534 /* Test flags (neg, cmp, test). */
535 executable_code code
;
536 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
540 printf("Run test8\n");
542 FAILED(!compiler
, "cannot create compiler\n");
557 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 2, 0, 0, 0);
558 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 20);
559 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 10);
560 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_IMM
, 6, SLJIT_IMM
, 5);
561 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_NOT_EQUAL
);
562 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_EQUAL
);
563 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 3000);
564 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_GREATER
);
565 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 3000);
566 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_S1
, 0);
567 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_LESS
);
568 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R2
, 0);
569 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -15);
570 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_SIG_GREATER
);
571 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R2
, 0);
572 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -(sljit_sw
)(~(sljit_uw
)0 >> 1) - 1);
573 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
574 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
575 sljit_emit_op1(compiler
, SLJIT_NEG
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0);
576 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_OVERFLOW
);
577 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
578 sljit_emit_op1(compiler
, SLJIT_NOT
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R0
, 0);
579 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_ZERO
);
580 sljit_emit_op1(compiler
, SLJIT_NOT
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0);
581 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_ZERO
);
582 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_IMM
, 0xffff, SLJIT_R0
, 0);
583 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffff);
584 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_NOT_ZERO
);
585 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_IMM
, 0xffff, SLJIT_R1
, 0);
586 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 0xffff);
587 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
588 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
589 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
590 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0x1);
591 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, SLJIT_NOT_ZERO
);
592 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -(sljit_sw
)(~(sljit_uw
)0 >> 1) - 1);
593 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
594 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
595 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 11, SLJIT_OVERFLOW
);
596 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
597 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 12, SLJIT_OVERFLOW
);
598 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
600 code
.code
= sljit_generate_code(compiler
);
602 sljit_free_compiler(compiler
);
604 code
.func1((sljit_sw
)&buf
);
605 FAILED(buf
[1] != 1, "test8 case 1 failed\n");
606 FAILED(buf
[2] != 0, "test8 case 2 failed\n");
607 FAILED(buf
[3] != 0, "test8 case 3 failed\n");
608 FAILED(buf
[4] != 1, "test8 case 4 failed\n");
609 FAILED(buf
[5] != 1, "test8 case 5 failed\n");
610 FAILED(buf
[6] != 1, "test8 case 6 failed\n");
611 FAILED(buf
[7] != 1, "test8 case 7 failed\n");
612 FAILED(buf
[8] != 0, "test8 case 8 failed\n");
613 FAILED(buf
[9] != 1, "test8 case 9 failed\n");
614 FAILED(buf
[10] != 0, "test8 case 10 failed\n");
615 FAILED(buf
[11] != 1, "test8 case 11 failed\n");
616 FAILED(buf
[12] != 0, "test8 case 12 failed\n");
618 sljit_free_code(code
.code
, NULL
);
622 static void test9(void)
625 executable_code code
;
626 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
628 #ifdef SLJIT_PREF_SHIFT_REG
629 sljit_s32 shift_reg
= SLJIT_PREF_SHIFT_REG
;
631 sljit_s32 shift_reg
= SLJIT_R2
;
634 SLJIT_ASSERT(shift_reg
>= SLJIT_R2
&& shift_reg
<= SLJIT_R3
);
637 printf("Run test9\n");
639 FAILED(!compiler
, "cannot create compiler\n");
654 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 4, 2, 0, 0, 0);
655 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xf);
656 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 3);
657 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
658 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
659 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
660 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R1
, 0, SLJIT_IMM
, 1);
661 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -64);
662 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 2);
663 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, shift_reg
, 0);
665 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0xff);
666 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
667 sljit_emit_op2(compiler
, SLJIT_SHL
, shift_reg
, 0, shift_reg
, 0, SLJIT_R0
, 0);
668 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, shift_reg
, 0);
669 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0xff);
670 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
671 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);
672 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, shift_reg
, 0, SLJIT_R0
, 0);
674 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, 0xf);
675 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
676 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_S1
, 0, SLJIT_S1
, 0, SLJIT_R0
, 0);
677 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_S1
, 0);
678 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_R0
, 0);
679 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_R0
, 0);
680 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0xf00);
681 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
682 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R1
, 0, SLJIT_R2
, 0, SLJIT_R0
, 0);
683 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_R1
, 0);
685 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)buf
);
686 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 9);
687 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
);
689 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 4);
690 sljit_emit_op2(compiler
, SLJIT_SHL
, shift_reg
, 0, SLJIT_IMM
, 2, shift_reg
, 0);
691 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, shift_reg
, 0);
693 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xa9);
694 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
695 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x7d00);
696 sljit_emit_op2(compiler
, SLJIT_LSHR32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 32);
697 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
698 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
700 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
701 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xe30000);
702 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
703 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffc0);
705 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffe0);
707 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
708 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x25000000);
709 sljit_emit_op2(compiler
, SLJIT_SHL32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xfffe1);
710 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
711 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
713 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 11, SLJIT_R1
, 0, SLJIT_R0
, 0);
715 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0);
716 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x5c);
717 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R1
, 0, SLJIT_R0
, 0, shift_reg
, 0);
718 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0xf600);
719 sljit_emit_op2(compiler
, SLJIT_LSHR32
, SLJIT_R0
, 0, SLJIT_R0
, 0, shift_reg
, 0);
720 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
721 /* Alternative form of uint32 type cast. */
722 sljit_emit_op2(compiler
, SLJIT_AND
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffffffff);
724 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
725 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x630000);
726 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, shift_reg
, 0);
727 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 12, SLJIT_R1
, 0, SLJIT_R0
, 0);
729 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
731 code
.code
= sljit_generate_code(compiler
);
733 sljit_free_compiler(compiler
);
735 code
.func1((sljit_sw
)&buf
);
736 FAILED(buf
[0] != 0x3c, "test9 case 1 failed\n");
737 FAILED(buf
[1] != 0xf0, "test9 case 2 failed\n");
738 FAILED(buf
[2] != -16, "test9 case 3 failed\n");
739 FAILED(buf
[3] != 0xff0, "test9 case 4 failed\n");
740 FAILED(buf
[4] != 4, "test9 case 5 failed\n");
741 FAILED(buf
[5] != 0xff00, "test9 case 6 failed\n");
742 FAILED(buf
[6] != 0x3c, "test9 case 7 failed\n");
743 FAILED(buf
[7] != 0xf0, "test9 case 8 failed\n");
744 FAILED(buf
[8] != 0xf0, "test9 case 9 failed\n");
745 FAILED(buf
[9] != 0x18, "test9 case 10 failed\n");
746 FAILED(buf
[10] != 32, "test9 case 11 failed\n");
747 FAILED(buf
[11] != 0x4ae37da9, "test9 case 12 failed\n");
748 FAILED(buf
[12] != 0x63f65c, "test9 case 13 failed\n");
750 sljit_free_code(code
.code
, NULL
);
754 static void test10(void)
756 /* Test multiplications. */
757 executable_code code
;
758 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
762 printf("Run test10\n");
764 FAILED(!compiler
, "cannot create compiler\n");
773 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 1, 0, 0, 0);
774 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
775 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
776 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
777 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 7);
778 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 8);
779 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
780 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_IMM
, -3, SLJIT_IMM
, -4);
781 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0);
782 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -2);
783 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);
784 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
) / 2);
785 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[3]);
786 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);
787 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 9);
788 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R0
, 0);
789 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R0
, 0);
790 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
791 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3);
792 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x123456789));
793 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_R0
, 0);
795 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 11, SLJIT_IMM
, 10);
796 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
798 code
.code
= sljit_generate_code(compiler
);
800 sljit_free_compiler(compiler
);
802 FAILED(code
.func1((sljit_sw
)&buf
) != 110, "test10 case 1 failed\n");
803 FAILED(buf
[0] != 15, "test10 case 2 failed\n");
804 FAILED(buf
[1] != 56, "test10 case 3 failed\n");
805 FAILED(buf
[2] != 12, "test10 case 4 failed\n");
806 FAILED(buf
[3] != -12, "test10 case 5 failed\n");
807 FAILED(buf
[4] != 100, "test10 case 6 failed\n");
808 FAILED(buf
[5] != 81, "test10 case 7 failed\n");
809 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
810 FAILED(buf
[6] != SLJIT_W(0x123456789) * 3, "test10 case 8 failed\n");
813 sljit_free_code(code
.code
, NULL
);
817 static void test11(void)
819 /* Test rewritable constants. */
820 executable_code code
;
821 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
822 struct sljit_const
* const1
;
823 struct sljit_const
* const2
;
824 struct sljit_const
* const3
;
825 struct sljit_const
* const4
;
827 sljit_sw executable_offset
;
828 sljit_uw const1_addr
;
829 sljit_uw const2_addr
;
830 sljit_uw const3_addr
;
831 sljit_uw const4_addr
;
832 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
833 sljit_sw word_value1
= SLJIT_W(0xaaaaaaaaaaaaaaaa);
834 sljit_sw word_value2
= SLJIT_W(0xfee1deadfbadf00d);
836 sljit_sw word_value1
= 0xaaaaaaaal
;
837 sljit_sw word_value2
= 0xfbadf00dl
;
842 printf("Run test11\n");
844 FAILED(!compiler
, "cannot create compiler\n");
849 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 1, 0, 0, 0);
851 SLJIT_ASSERT(!sljit_alloc_memory(compiler
, 0));
852 SLJIT_ASSERT(!sljit_alloc_memory(compiler
, 16 * sizeof(sljit_sw
) + 1));
854 const1
= sljit_emit_const(compiler
, SLJIT_MEM0(), (sljit_sw
)&buf
[0], -0x81b9);
856 value
= sljit_alloc_memory(compiler
, 16 * sizeof(sljit_sw
));
859 SLJIT_ASSERT(!((sljit_sw
)value
& (sizeof(sljit_sw
) - 1)));
860 memset(value
, 255, 16 * sizeof(sljit_sw
));
863 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
864 const2
= sljit_emit_const(compiler
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), SLJIT_WORD_SHIFT
- 1, -65535);
865 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[0] + 2 * sizeof(sljit_sw
) - 2);
866 const3
= sljit_emit_const(compiler
, SLJIT_MEM1(SLJIT_R0
), 0, word_value1
);
868 value
= sljit_alloc_memory(compiler
, 17);
871 SLJIT_ASSERT(!((sljit_sw
)value
& (sizeof(sljit_sw
) - 1)));
872 memset(value
, 255, 16);
875 const4
= sljit_emit_const(compiler
, SLJIT_RETURN_REG
, 0, 0xf7afcdb7);
877 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
879 code
.code
= sljit_generate_code(compiler
);
881 executable_offset
= sljit_get_executable_offset(compiler
);
882 const1_addr
= sljit_get_const_addr(const1
);
883 const2_addr
= sljit_get_const_addr(const2
);
884 const3_addr
= sljit_get_const_addr(const3
);
885 const4_addr
= sljit_get_const_addr(const4
);
886 sljit_free_compiler(compiler
);
888 FAILED(code
.func1((sljit_sw
)&buf
) != 0xf7afcdb7, "test11 case 1 failed\n");
889 FAILED(buf
[0] != -0x81b9, "test11 case 2 failed\n");
890 FAILED(buf
[1] != -65535, "test11 case 3 failed\n");
891 FAILED(buf
[2] != word_value1
, "test11 case 4 failed\n");
893 sljit_set_const(const1_addr
, -1, executable_offset
);
894 sljit_set_const(const2_addr
, word_value2
, executable_offset
);
895 sljit_set_const(const3_addr
, 0xbab0fea1, executable_offset
);
896 sljit_set_const(const4_addr
, -60089, executable_offset
);
898 FAILED(code
.func1((sljit_sw
)&buf
) != -60089, "test11 case 5 failed\n");
899 FAILED(buf
[0] != -1, "test11 case 6 failed\n");
900 FAILED(buf
[1] != word_value2
, "test11 case 7 failed\n");
901 FAILED(buf
[2] != 0xbab0fea1, "test11 case 8 failed\n");
903 sljit_free_code(code
.code
, NULL
);
907 static void test12(void)
909 /* Test rewriteable jumps. */
910 executable_code code
;
911 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
912 struct sljit_label
*label1
;
913 struct sljit_label
*label2
;
914 struct sljit_label
*label3
;
915 struct sljit_jump
*jump1
;
916 struct sljit_jump
*jump2
;
917 struct sljit_jump
*jump3
;
918 sljit_sw executable_offset
;
921 sljit_uw label1_addr
;
922 sljit_uw label2_addr
;
926 printf("Run test12\n");
928 FAILED(!compiler
, "cannot create compiler\n");
931 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
), 3, 2, 0, 0, 0);
932 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_UNUSED
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 10);
933 jump1
= sljit_emit_jump(compiler
, SLJIT_REWRITABLE_JUMP
| SLJIT_SIG_GREATER
);
934 /* Default handler. */
935 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 5);
936 jump2
= sljit_emit_jump(compiler
, SLJIT_JUMP
);
938 value
= sljit_alloc_memory(compiler
, 15);
941 SLJIT_ASSERT(!((sljit_sw
)value
& (sizeof(sljit_sw
) - 1)));
942 memset(value
, 255, 15);
946 label1
= sljit_emit_label(compiler
);
947 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
948 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 6);
949 jump3
= sljit_emit_jump(compiler
, SLJIT_JUMP
);
951 label2
= sljit_emit_label(compiler
);
952 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
953 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 7);
955 label3
= sljit_emit_label(compiler
);
956 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
957 sljit_set_label(jump2
, label3
);
958 sljit_set_label(jump3
, label3
);
959 /* By default, set to handler 1. */
960 sljit_set_label(jump1
, label1
);
961 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
963 value
= sljit_alloc_memory(compiler
, 8);
966 SLJIT_ASSERT(!((sljit_sw
)value
& (sizeof(sljit_sw
) - 1)));
967 memset(value
, 255, 8);
970 code
.code
= sljit_generate_code(compiler
);
972 executable_offset
= sljit_get_executable_offset(compiler
);
973 jump1_addr
= sljit_get_jump_addr(jump1
);
974 label1_addr
= sljit_get_label_addr(label1
);
975 label2_addr
= sljit_get_label_addr(label2
);
976 sljit_free_compiler(compiler
);
978 code
.func2((sljit_sw
)&buf
, 4);
979 FAILED(buf
[0] != 5, "test12 case 1 failed\n");
981 code
.func2((sljit_sw
)&buf
, 11);
982 FAILED(buf
[0] != 6, "test12 case 2 failed\n");
984 sljit_set_jump_addr(jump1_addr
, label2_addr
, executable_offset
);
985 code
.func2((sljit_sw
)&buf
, 12);
986 FAILED(buf
[0] != 7, "test12 case 3 failed\n");
988 sljit_set_jump_addr(jump1_addr
, label1_addr
, executable_offset
);
989 code
.func2((sljit_sw
)&buf
, 13);
990 FAILED(buf
[0] != 6, "test12 case 4 failed\n");
992 sljit_free_code(code
.code
, NULL
);
996 static void test13(void)
998 /* Test fpu monadic functions. */
999 executable_code code
;
1000 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1005 printf("Run test13\n");
1007 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
1009 printf("no fpu available, test13 skipped\n");
1012 sljit_free_compiler(compiler
);
1016 FAILED(!compiler
, "cannot create compiler\n");
1032 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
), 3, 2, 6, 0, 0);
1033 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&buf
[2], SLJIT_MEM0(), (sljit_sw
)&buf
[1]);
1034 sljit_emit_fop1(compiler
, SLJIT_ABS_F64
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1035 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
1036 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2 * sizeof(sljit_f64
));
1037 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 0);
1038 sljit_emit_fop1(compiler
, SLJIT_NEG_F64
, SLJIT_FR2
, 0, SLJIT_FR0
, 0);
1039 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_FR2
, 0);
1040 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&buf
[4], SLJIT_FR3
, 0);
1041 sljit_emit_fop1(compiler
, SLJIT_ABS_F64
, SLJIT_FR4
, 0, SLJIT_FR1
, 0);
1042 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f64
), SLJIT_FR4
, 0);
1043 sljit_emit_fop1(compiler
, SLJIT_NEG_F64
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
), SLJIT_FR4
, 0);
1045 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
1046 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_GREATER_F
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1047 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_GREATER_F64
);
1048 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_GREATER_F
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
), SLJIT_FR5
, 0);
1049 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
), SLJIT_GREATER_F64
);
1050 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_FR5
, 0);
1051 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR1
, 0);
1052 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
), SLJIT_EQUAL_F64
);
1053 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_LESS_F
, SLJIT_FR1
, 0, SLJIT_FR1
, 0);
1054 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
), SLJIT_LESS_F64
);
1055 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1056 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_EQUAL_F64
);
1057 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_NOT_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1058 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_NOT_EQUAL_F64
);
1060 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
1062 code
.code
= sljit_generate_code(compiler
);
1064 sljit_free_compiler(compiler
);
1066 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&buf2
);
1067 FAILED(buf
[2] != -4.5, "test13 case 1 failed\n");
1068 FAILED(buf
[3] != 4.5, "test13 case 2 failed\n");
1069 FAILED(buf
[4] != -7.75, "test13 case 3 failed\n");
1070 FAILED(buf
[5] != 4.5, "test13 case 4 failed\n");
1071 FAILED(buf
[6] != -4.5, "test13 case 5 failed\n");
1073 FAILED(buf2
[0] != 1, "test13 case 6 failed\n");
1074 FAILED(buf2
[1] != 0, "test13 case 7 failed\n");
1075 FAILED(buf2
[2] != 1, "test13 case 8 failed\n");
1076 FAILED(buf2
[3] != 0, "test13 case 9 failed\n");
1077 FAILED(buf2
[4] != 0, "test13 case 10 failed\n");
1078 FAILED(buf2
[5] != 1, "test13 case 11 failed\n");
1080 sljit_free_code(code
.code
, NULL
);
1084 static void test14(void)
1086 /* Test fpu diadic functions. */
1087 executable_code code
;
1088 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1092 printf("Run test14\n");
1094 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
1096 printf("no fpu available, test14 skipped\n");
1099 sljit_free_compiler(compiler
);
1118 FAILED(!compiler
, "cannot create compiler\n");
1119 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 1, 6, 0, 0);
1122 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_f64
));
1123 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1124 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2);
1125 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);
1126 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_FR1
, 0);
1127 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR1
, 0, SLJIT_FR0
, 0, SLJIT_FR1
, 0);
1128 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 4, SLJIT_FR0
, 0);
1129 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 5, SLJIT_FR1
, 0);
1132 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
1133 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2);
1134 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 2);
1135 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
);
1136 sljit_emit_fop2(compiler
, SLJIT_SUB_F64
, SLJIT_FR2
, 0, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2);
1137 sljit_emit_fop2(compiler
, SLJIT_SUB_F64
, SLJIT_FR3
, 0, SLJIT_FR2
, 0, SLJIT_FR3
, 0);
1138 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 7, SLJIT_FR2
, 0);
1139 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 8, SLJIT_FR3
, 0);
1142 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
1143 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);
1144 sljit_emit_fop2(compiler
, SLJIT_MUL_F64
, SLJIT_FR1
, 0, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
1145 sljit_emit_fop2(compiler
, SLJIT_MUL_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2, SLJIT_FR2
, 0);
1146 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 10, SLJIT_FR1
, 0);
1147 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 11, SLJIT_FR5
, 0);
1150 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 12);
1151 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 13);
1152 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR4
, 0, SLJIT_FR5
, 0);
1153 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);
1154 sljit_emit_fop2(compiler
, SLJIT_DIV_F64
, SLJIT_FR5
, 0, SLJIT_FR5
, 0, SLJIT_FR1
, 0);
1155 sljit_emit_fop2(compiler
, SLJIT_DIV_F64
, SLJIT_FR4
, 0, SLJIT_FR1
, 0, SLJIT_FR4
, 0);
1156 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 13, SLJIT_FR5
, 0);
1157 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 14, SLJIT_FR4
, 0);
1159 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
1161 code
.code
= sljit_generate_code(compiler
);
1163 sljit_free_compiler(compiler
);
1165 code
.func1((sljit_sw
)&buf
);
1166 FAILED(buf
[3] != 10.75, "test14 case 1 failed\n");
1167 FAILED(buf
[4] != 5.25, "test14 case 2 failed\n");
1168 FAILED(buf
[5] != 7.0, "test14 case 3 failed\n");
1169 FAILED(buf
[6] != 0.0, "test14 case 4 failed\n");
1170 FAILED(buf
[7] != 5.5, "test14 case 5 failed\n");
1171 FAILED(buf
[8] != 3.75, "test14 case 6 failed\n");
1172 FAILED(buf
[9] != 24.5, "test14 case 7 failed\n");
1173 FAILED(buf
[10] != 38.5, "test14 case 8 failed\n");
1174 FAILED(buf
[11] != 9.625, "test14 case 9 failed\n");
1175 FAILED(buf
[12] != 2.0, "test14 case 10 failed\n");
1176 FAILED(buf
[13] != 2.0, "test14 case 11 failed\n");
1177 FAILED(buf
[14] != 0.5, "test14 case 12 failed\n");
1179 sljit_free_code(code
.code
, NULL
);
1183 static sljit_sw SLJIT_FUNC
func(sljit_sw a
, sljit_sw b
, sljit_sw c
)
1185 return a
+ b
+ c
+ 5;
1188 static void test15(void)
1190 /* Test function call. */
1191 executable_code code
;
1192 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1193 struct sljit_jump
* jump
= NULL
;
1197 printf("Run test15\n");
1199 FAILED(!compiler
, "cannot create compiler\n");
1206 buf
[6] = SLJIT_FUNC_OFFSET(func
);
1208 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 4, 1, 0, 0, 0);
1210 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
1211 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 7);
1212 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -3);
1213 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
), SLJIT_IMM
, SLJIT_FUNC_OFFSET(func
));
1214 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_RETURN_REG
, 0);
1216 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -5);
1217 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -10);
1218 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2);
1219 jump
= sljit_emit_call(compiler
, SLJIT_CALL
| SLJIT_REWRITABLE_JUMP
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
));
1220 sljit_set_target(jump
, (sljit_uw
)-1);
1221 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1223 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(func
));
1224 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 40);
1225 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -3);
1226 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
), SLJIT_R0
, 0);
1227 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1229 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -60);
1230 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(func
));
1231 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -30);
1232 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
), SLJIT_R1
, 0);
1233 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1235 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 10);
1236 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 16);
1237 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(func
));
1238 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
), SLJIT_R2
, 0);
1239 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1241 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 100);
1242 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 110);
1243 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 120);
1244 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(func
));
1245 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
), SLJIT_R3
, 0);
1246 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1248 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -10);
1249 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -16);
1250 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 6);
1251 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
), SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
));
1252 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1254 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1256 code
.code
= sljit_generate_code(compiler
);
1258 sljit_set_jump_addr(sljit_get_jump_addr(jump
), SLJIT_FUNC_OFFSET(func
), sljit_get_executable_offset(compiler
));
1259 sljit_free_compiler(compiler
);
1261 FAILED(code
.func1((sljit_sw
)&buf
) != -15, "test15 case 1 failed\n");
1262 FAILED(buf
[0] != 14, "test15 case 2 failed\n");
1263 FAILED(buf
[1] != -8, "test15 case 3 failed\n");
1264 FAILED(buf
[2] != SLJIT_FUNC_OFFSET(func
) + 42, "test15 case 4 failed\n");
1265 FAILED(buf
[3] != SLJIT_FUNC_OFFSET(func
) - 85, "test15 case 5 failed\n");
1266 FAILED(buf
[4] != SLJIT_FUNC_OFFSET(func
) + 31, "test15 case 6 failed\n");
1267 FAILED(buf
[5] != 335, "test15 case 7 failed\n");
1268 FAILED(buf
[6] != -15, "test15 case 8 failed\n");
1270 sljit_free_code(code
.code
, NULL
);
1274 static void test16(void)
1276 /* Ackermann benchmark. */
1277 executable_code code
;
1278 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1279 struct sljit_label
*entry
;
1280 struct sljit_label
*label
;
1281 struct sljit_jump
*jump
;
1282 struct sljit_jump
*jump1
;
1283 struct sljit_jump
*jump2
;
1286 printf("Run test16\n");
1288 FAILED(!compiler
, "cannot create compiler\n");
1290 entry
= sljit_emit_label(compiler
);
1291 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
), 3, 2, 0, 0, 0);
1293 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0);
1294 jump1
= sljit_emit_jump(compiler
, SLJIT_EQUAL
);
1296 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0);
1297 jump2
= sljit_emit_jump(compiler
, SLJIT_EQUAL
);
1300 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
1301 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 1);
1302 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
));
1303 sljit_set_label(jump
, entry
);
1305 /* Returns with Ack(x-1, Ack(x,y-1)). */
1306 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_RETURN_REG
, 0);
1307 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
1308 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
));
1309 sljit_set_label(jump
, entry
);
1310 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1312 /* Returns with y+1. */
1313 label
= sljit_emit_label(compiler
);
1314 sljit_set_label(jump1
, label
);
1315 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 1, SLJIT_S1
, 0);
1316 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1318 /* Returns with Ack(x-1,1) */
1319 label
= sljit_emit_label(compiler
);
1320 sljit_set_label(jump2
, label
);
1321 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
1322 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
1323 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
));
1324 sljit_set_label(jump
, entry
);
1325 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1327 code
.code
= sljit_generate_code(compiler
);
1329 sljit_free_compiler(compiler
);
1331 FAILED(code
.func2(3, 3) != 61, "test16 case 1 failed\n");
1332 /* For benchmarking. */
1333 /* FAILED(code.func2(3, 11) != 16381, "test16 case 1 failed\n"); */
1335 sljit_free_code(code
.code
, NULL
);
1339 static void test17(void)
1341 /* Test arm constant pool. */
1342 executable_code code
;
1343 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1348 printf("Run test17\n");
1350 FAILED(!compiler
, "cannot create compiler\n");
1352 for (i
= 0; i
< 5; i
++)
1355 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 1, 0, 0, 0);
1356 for (i
= 0; i
<= 0xfff; i
++) {
1357 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x81818000 | i
);
1358 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x81818000 | i
);
1359 if ((i
& 0x3ff) == 0)
1360 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), (i
>> 10) * sizeof(sljit_sw
), SLJIT_R0
, 0);
1362 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1363 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
1365 code
.code
= sljit_generate_code(compiler
);
1367 sljit_free_compiler(compiler
);
1369 code
.func1((sljit_sw
)&buf
);
1370 FAILED((sljit_uw
)buf
[0] != 0x81818000, "test17 case 1 failed\n");
1371 FAILED((sljit_uw
)buf
[1] != 0x81818400, "test17 case 2 failed\n");
1372 FAILED((sljit_uw
)buf
[2] != 0x81818800, "test17 case 3 failed\n");
1373 FAILED((sljit_uw
)buf
[3] != 0x81818c00, "test17 case 4 failed\n");
1374 FAILED((sljit_uw
)buf
[4] != 0x81818fff, "test17 case 5 failed\n");
1376 sljit_free_code(code
.code
, NULL
);
1380 static void test18(void)
1383 executable_code code
;
1384 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1388 printf("Run test18\n");
1390 FAILED(!compiler
, "cannot create compiler\n");
1401 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1402 buf
[10] = SLJIT_W(1) << 32;
1407 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 2, 0, 0, 0);
1409 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1410 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, SLJIT_W(0x1122334455667788));
1411 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x1122334455667788));
1413 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(1000000000000));
1414 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(1000000000000));
1415 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_IMM
, SLJIT_W(5000000000000), SLJIT_R0
, 0);
1417 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x1108080808));
1418 sljit_emit_op2(compiler
, SLJIT_ADD32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x1120202020));
1420 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1108080808));
1421 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1120202020));
1422 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_ZERO
);
1423 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_S1
, 0);
1424 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
1425 sljit_emit_op2(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1120202020));
1426 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_ZERO
);
1428 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1108080808));
1429 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x2208080808));
1430 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_LESS
);
1431 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
1432 sljit_emit_op2(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1104040404));
1433 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_NOT_ZERO
);
1435 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
1436 sljit_emit_op2(compiler
, SLJIT_SHL32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_IMM
, SLJIT_W(0xffff0000), SLJIT_R0
, 0);
1438 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);
1440 /* 32 bit operations. */
1442 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0x11223344);
1443 sljit_emit_op2(compiler
, SLJIT_ADD32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 0x44332211);
1447 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
1449 code
.code
= sljit_generate_code(compiler
);
1451 sljit_free_compiler(compiler
);
1453 code
.func1((sljit_sw
)&buf
);
1454 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1455 FAILED(buf
[0] != SLJIT_W(0x1122334455667788), "test18 case 1 failed\n");
1456 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1457 FAILED(buf
[1] != 0x55667788, "test18 case 2 failed\n");
1459 FAILED(buf
[1] != SLJIT_W(0x5566778800000000), "test18 case 2 failed\n");
1461 FAILED(buf
[2] != SLJIT_W(2000000000000), "test18 case 3 failed\n");
1462 FAILED(buf
[3] != SLJIT_W(4000000000000), "test18 case 4 failed\n");
1463 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1464 FAILED(buf
[4] != 0x28282828, "test18 case 5 failed\n");
1466 FAILED(buf
[4] != SLJIT_W(0x2828282800000000), "test18 case 5 failed\n");
1468 FAILED(buf
[5] != 0, "test18 case 6 failed\n");
1469 FAILED(buf
[6] != 1, "test18 case 7 failed\n");
1470 FAILED(buf
[7] != 1, "test18 case 8 failed\n");
1471 FAILED(buf
[8] != 0, "test18 case 9 failed\n");
1472 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1473 FAILED(buf
[9] != 0xfff00000, "test18 case 10 failed\n");
1474 FAILED(buf
[10] != 0xffffffff, "test18 case 11 failed\n");
1476 FAILED(buf
[9] != SLJIT_W(0xfff0000000000000), "test18 case 10 failed\n");
1477 FAILED(buf
[10] != SLJIT_W(0xffffffff00000000), "test18 case 11 failed\n");
1480 FAILED(buf
[0] != 0x11223344, "test18 case 1 failed\n");
1481 FAILED(buf
[1] != 0x44332211, "test18 case 2 failed\n");
1484 sljit_free_code(code
.code
, NULL
);
1488 static void test19(void)
1490 /* Test arm partial instruction caching. */
1491 executable_code code
;
1492 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1496 printf("Run test19\n");
1498 FAILED(!compiler
, "cannot create compiler\n");
1508 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 1, 0, 0, 0);
1509 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
1510 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM0(), (sljit_sw
)&buf
[2], SLJIT_MEM0(), (sljit_sw
)&buf
[1], SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
1511 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
1512 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1513 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]);
1514 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_MEM0(), (sljit_sw
)&buf
[0], SLJIT_IMM
, 2);
1515 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
));
1516 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_IMM
, 10);
1517 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 7);
1518 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]);
1520 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
1522 code
.code
= sljit_generate_code(compiler
);
1524 sljit_free_compiler(compiler
);
1526 code
.func1((sljit_sw
)&buf
);
1527 FAILED(buf
[0] != 10, "test19 case 1 failed\n");
1528 FAILED(buf
[1] != 4, "test19 case 2 failed\n");
1529 FAILED(buf
[2] != 14, "test19 case 3 failed\n");
1530 FAILED(buf
[3] != 14, "test19 case 4 failed\n");
1531 FAILED(buf
[4] != 8, "test19 case 5 failed\n");
1532 FAILED(buf
[5] != 6, "test19 case 6 failed\n");
1533 FAILED(buf
[6] != 12, "test19 case 7 failed\n");
1534 FAILED(buf
[7] != 10, "test19 case 8 failed\n");
1536 sljit_free_code(code
.code
, NULL
);
1540 static void test20(void)
1543 executable_code code
;
1544 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1545 struct sljit_jump
* jump
;
1546 struct sljit_label
* label
;
1548 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1549 sljit_sw offset_value
= SLJIT_W(0x1234567812345678);
1551 sljit_sw offset_value
= SLJIT_W(0x12345678);
1555 printf("Run test20\n");
1557 FAILED(!compiler
, "cannot create compiler\n");
1565 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 5, 5, 0, 0, 4 * sizeof(sljit_sw
));
1566 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
), SLJIT_MEM1(SLJIT_S0
), 0);
1567 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
));
1568 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -1);
1569 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, -1);
1570 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, -1);
1571 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_IMM
, -1);
1572 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
));
1573 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);
1574 sljit_get_local_base(compiler
, SLJIT_R0
, 0, -offset_value
);
1575 sljit_get_local_base(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, -0x1234);
1576 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
1577 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
));
1578 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_uw
));
1579 /* Dummy last instructions. */
1580 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 23);
1581 sljit_emit_label(compiler
);
1583 code
.code
= sljit_generate_code(compiler
);
1585 sljit_free_compiler(compiler
);
1587 FAILED(code
.func1((sljit_sw
)&buf
) != -12345, "test20 case 1 failed\n")
1589 FAILED(buf
[2] != 60, "test20 case 2 failed\n");
1590 FAILED(buf
[3] != 17, "test20 case 3 failed\n");
1591 FAILED(buf
[4] != 7, "test20 case 4 failed\n");
1593 sljit_free_code(code
.code
, NULL
);
1595 compiler
= sljit_create_compiler(NULL
, NULL
);
1596 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
), 3, 3, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
1598 sljit_get_local_base(compiler
, SLJIT_R0
, 0, SLJIT_MAX_LOCAL_SIZE
- sizeof(sljit_sw
));
1599 sljit_get_local_base(compiler
, SLJIT_R1
, 0, -(sljit_sw
)sizeof(sljit_sw
));
1600 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -1);
1601 label
= sljit_emit_label(compiler
);
1602 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1603 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0, SLJIT_R2
, 0);
1604 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
1605 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_EQUAL
);
1606 sljit_set_label(jump
, label
);
1608 /* Saved registers should keep their value. */
1609 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_S1
, 0);
1610 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_S2
, 0);
1611 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
1613 code
.code
= sljit_generate_code(compiler
);
1615 sljit_free_compiler(compiler
);
1617 FAILED(code
.func3(1234, 5678, 9012) != 15924, "test20 case 5 failed\n");
1619 sljit_free_code(code
.code
, NULL
);
1621 compiler
= sljit_create_compiler(NULL
, NULL
);
1622 sljit_emit_enter(compiler
, SLJIT_F64_ALIGNMENT
, 0, 3, 0, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
1624 sljit_get_local_base(compiler
, SLJIT_R0
, 0, SLJIT_MAX_LOCAL_SIZE
- sizeof(sljit_sw
));
1625 sljit_get_local_base(compiler
, SLJIT_R1
, 0, -(sljit_sw
)sizeof(sljit_sw
));
1626 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -1);
1627 label
= sljit_emit_label(compiler
);
1628 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1629 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0, SLJIT_R2
, 0);
1630 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
1631 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_EQUAL
);
1632 sljit_set_label(jump
, label
);
1634 sljit_get_local_base(compiler
, SLJIT_R0
, 0, 0);
1635 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
1637 code
.code
= sljit_generate_code(compiler
);
1639 sljit_free_compiler(compiler
);
1641 FAILED(code
.func0() % sizeof(sljit_f64
) != 0, "test20 case 6 failed\n");
1643 sljit_free_code(code
.code
, NULL
);
1647 static void test21(void)
1649 /* Test set context. The parts of the jit code can be separated in the memory. */
1650 executable_code code1
;
1651 executable_code code2
;
1652 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1653 struct sljit_jump
* jump
= NULL
;
1655 sljit_sw executable_offset
;
1659 printf("Run test21\n");
1661 FAILED(!compiler
, "cannot create compiler\n");
1667 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 2, 0, 0, 2 * sizeof(sljit_sw
));
1669 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 10);
1670 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_SP
), 0);
1672 jump
= sljit_emit_jump(compiler
, SLJIT_JUMP
| SLJIT_REWRITABLE_JUMP
);
1673 sljit_set_target(jump
, 0);
1675 code1
.code
= sljit_generate_code(compiler
);
1678 executable_offset
= sljit_get_executable_offset(compiler
);
1679 addr
= sljit_get_jump_addr(jump
);
1681 sljit_free_compiler(compiler
);
1683 compiler
= sljit_create_compiler(NULL
, NULL
);
1684 FAILED(!compiler
, "cannot create compiler\n");
1686 /* Other part of the jit code. */
1687 sljit_set_context(compiler
, 0, 1, 3, 2, 0, 0, 2 * sizeof(sljit_sw
));
1689 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
1690 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);
1691 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_MEM1(SLJIT_SP
), 0);
1692 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_sw
));
1694 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1696 code2
.code
= sljit_generate_code(compiler
);
1698 sljit_free_compiler(compiler
);
1700 sljit_set_jump_addr(addr
, SLJIT_FUNC_OFFSET(code2
.code
), executable_offset
);
1702 FAILED(code1
.func1((sljit_sw
)&buf
) != 19, "test21 case 1 failed\n");
1703 FAILED(buf
[2] != -16, "test21 case 2 failed\n");
1704 FAILED(buf
[3] != 100, "test21 case 3 failed\n");
1706 sljit_free_code(code1
.code
, NULL
);
1707 sljit_free_code(code2
.code
, NULL
);
1711 static void test22(void)
1713 /* Test simple byte and half-int data transfers. */
1714 executable_code code
;
1715 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1721 printf("Run test22\n");
1723 FAILED(!compiler
, "cannot create compiler\n");
1741 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
), 3, 3, 0, 0, 0);
1743 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, -13);
1744 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s16
), SLJIT_IMM
, 0x1234);
1745 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_s16
));
1746 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
1747 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s16
));
1748 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s16
), SLJIT_MEM1(SLJIT_S1
), -(sljit_sw
)sizeof(sljit_s16
));
1749 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xff0000 + 8000);
1750 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 2);
1751 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R1
), 1, SLJIT_R0
, 0);
1752 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0x1234 - 3 * sizeof(sljit_s16
));
1753 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R2
), 0x1234, SLJIT_IMM
, -9317);
1754 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0x1234 + 4 * sizeof(sljit_s16
));
1755 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R2
), -0x1234, SLJIT_IMM
, -9317);
1756 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0x12348 - 5 * sizeof(sljit_s16
));
1757 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R2
), 0x12348, SLJIT_IMM
, -8888);
1758 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0x12348 + 6 * sizeof(sljit_s16
));
1759 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R2
), -0x12348, SLJIT_IMM
, -8888);
1761 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM1(SLJIT_S2
), 0, SLJIT_IMM
, -45);
1762 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_s8
), SLJIT_IMM
, 0x12);
1763 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4 * sizeof(sljit_s8
));
1764 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_s8
));
1765 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_S1
, 0, SLJIT_R1
, 0);
1766 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_S1
, 0, SLJIT_S1
, 0);
1767 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R2
, 0, SLJIT_S1
, 0);
1768 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R2
, 0);
1769 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S2
), 3 * sizeof(sljit_s8
), SLJIT_S1
, 0);
1770 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM2(SLJIT_S2
, SLJIT_R0
), 0, SLJIT_R0
, 0);
1772 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
1774 code
.code
= sljit_generate_code(compiler
);
1776 sljit_free_compiler(compiler
);
1778 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&sbuf
, (sljit_sw
)&bbuf
);
1779 FAILED(buf
[0] != -9, "test22 case 1 failed\n");
1780 FAILED(buf
[1] != -56, "test22 case 2 failed\n");
1782 FAILED(sbuf
[0] != -13, "test22 case 3 failed\n");
1783 FAILED(sbuf
[1] != 0x1234, "test22 case 4 failed\n");
1784 FAILED(sbuf
[3] != 0x1234, "test22 case 5 failed\n");
1785 FAILED(sbuf
[4] != 8000, "test22 case 6 failed\n");
1786 FAILED(sbuf
[5] != -9317, "test22 case 7 failed\n");
1787 FAILED(sbuf
[6] != -9317, "test22 case 8 failed\n");
1788 FAILED(sbuf
[7] != -8888, "test22 case 9 failed\n");
1789 FAILED(sbuf
[8] != -8888, "test22 case 10 failed\n");
1791 FAILED(bbuf
[0] != -45, "test22 case 11 failed\n");
1792 FAILED(bbuf
[1] != 0x12, "test22 case 12 failed\n");
1793 FAILED(bbuf
[3] != -56, "test22 case 13 failed\n");
1794 FAILED(bbuf
[4] != 4, "test22 case 14 failed\n");
1796 sljit_free_code(code
.code
, NULL
);
1800 static void test23(void)
1802 /* Test 32 bit / 64 bit signed / unsigned int transfer and conversion.
1803 This test has do real things on 64 bit systems, but works on 32 bit systems as well. */
1804 executable_code code
;
1805 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1810 sljit_u8 asbytes
[4];
1812 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1813 sljit_sw garbage
= SLJIT_W(0x1234567812345678);
1815 sljit_sw garbage
= 0x12345678;
1819 printf("Run test23\n");
1821 FAILED(!compiler
, "cannot create compiler\n");
1838 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
), 3, 3, 0, 0, 0);
1839 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, 34567);
1840 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
1841 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), 0, SLJIT_IMM
, -7654);
1842 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, garbage
);
1843 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_s32
));
1844 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
1845 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, garbage
);
1846 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_s32
));
1847 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
1848 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, garbage
);
1849 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_s32
));
1850 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
1851 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1852 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x0f00f00);
1853 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x7777);
1854 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0x7777 + 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1855 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x7777);
1856 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), -0x7777 + 4 * (sljit_sw
)sizeof(sljit_sw
), SLJIT_R0
, 0);
1857 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 5 * sizeof(sljit_sw
));
1858 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 1);
1859 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R1
), 0, SLJIT_IMM
, 16);
1860 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
1861 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1, SLJIT_IMM
, 64, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1);
1862 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)&buf
[7], SLJIT_IMM
, 0x123456);
1863 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&buf
[6], SLJIT_MEM0(), (sljit_sw
)&buf
[7]);
1864 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 5 * sizeof(sljit_sw
));
1865 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 2 * sizeof(sljit_sw
), SLJIT_R1
, 0);
1866 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 7 * sizeof(sljit_sw
));
1867 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R2
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 1);
1868 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_MEM2(SLJIT_R2
, SLJIT_R2
), 0);
1869 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[8] - 0x12340);
1870 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0x12340, SLJIT_R2
, 0);
1871 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_R0
), 0x12340, SLJIT_MEM1(SLJIT_R2
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 6);
1872 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_s32
), SLJIT_IMM
, 0x12345678);
1873 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x2bd700 | 243);
1874 sljit_emit_return(compiler
, SLJIT_MOV_S8
, SLJIT_R1
, 0);
1876 code
.code
= sljit_generate_code(compiler
);
1878 sljit_free_compiler(compiler
);
1880 FAILED(code
.func2((sljit_sw
)&buf
, (sljit_sw
)&ibuf
) != -13, "test23 case 1 failed\n");
1881 FAILED(buf
[0] != -5791, "test23 case 2 failed\n");
1882 FAILED(buf
[1] != 43579, "test23 case 3 failed\n");
1883 FAILED(buf
[2] != 658923, "test23 case 4 failed\n");
1884 FAILED(buf
[3] != 0x0f00f00, "test23 case 5 failed\n");
1885 FAILED(buf
[4] != 0x0f00f00, "test23 case 6 failed\n");
1886 FAILED(buf
[5] != 80, "test23 case 7 failed\n");
1887 FAILED(buf
[6] != 0x123456, "test23 case 8 failed\n");
1888 FAILED(buf
[7] != (sljit_sw
)&buf
[5], "test23 case 9 failed\n");
1889 FAILED(buf
[8] != (sljit_sw
)&buf
[5] + 6, "test23 case 10 failed\n");
1891 FAILED(ibuf
[0] != 34567, "test23 case 11 failed\n");
1892 FAILED(ibuf
[1] != -7654, "test23 case 12 failed\n");
1894 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1895 FAILED(u
.asbytes
[0] != 0x78, "test23 case 13 failed\n");
1896 FAILED(u
.asbytes
[1] != 0x56, "test23 case 14 failed\n");
1897 FAILED(u
.asbytes
[2] != 0x34, "test23 case 15 failed\n");
1898 FAILED(u
.asbytes
[3] != 0x12, "test23 case 16 failed\n");
1900 FAILED(u
.asbytes
[0] != 0x12, "test23 case 13 failed\n");
1901 FAILED(u
.asbytes
[1] != 0x34, "test23 case 14 failed\n");
1902 FAILED(u
.asbytes
[2] != 0x56, "test23 case 15 failed\n");
1903 FAILED(u
.asbytes
[3] != 0x78, "test23 case 16 failed\n");
1906 sljit_free_code(code
.code
, NULL
);
1910 static void test24(void)
1912 /* Some complicated addressing modes. */
1913 executable_code code
;
1914 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1920 printf("Run test24\n");
1922 FAILED(!compiler
, "cannot create compiler\n");
1948 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
), 3, 3, 0, 0, 0);
1950 /* Nothing should be updated. */
1951 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM0(), (sljit_sw
)&sbuf
[1], SLJIT_MEM0(), (sljit_sw
)&sbuf
[0]);
1952 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM0(), (sljit_sw
)&bbuf
[1], SLJIT_MEM0(), (sljit_sw
)&bbuf
[0]);
1953 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
1954 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), 1, SLJIT_MEM0(), (sljit_sw
)&sbuf
[3]);
1955 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[0]);
1956 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1957 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2);
1958 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);
1959 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_s8
));
1960 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&bbuf
[1], SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&bbuf
[2]);
1962 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_s16
));
1963 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R1
), (sljit_sw
)&sbuf
[3], SLJIT_R1
, 0);
1965 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
1966 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
);
1967 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
1968 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_S0
, 0);
1969 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
);
1971 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 9 * sizeof(sljit_sw
));
1972 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 4 * sizeof(sljit_sw
));
1973 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -4 << SLJIT_WORD_SHIFT
);
1974 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R2
), 0, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
1976 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
- 0x7fff8000 + 6 * sizeof(sljit_sw
));
1977 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 952467);
1978 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0x7fff8000, SLJIT_R1
, 0);
1979 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0x7fff8000 + sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_R0
), 0x7fff8000);
1981 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
+ 0x7fff7fff + 6 * sizeof(sljit_sw
));
1982 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_R0
), -0x7fff7fff + 2 * (sljit_sw
)sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_R0
), -0x7fff7fff + (sljit_sw
)sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_R0
), -0x7fff7fff);
1983 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
- 0x7fff7ffe + 3 * sizeof(sljit_s8
));
1984 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM1(SLJIT_R0
), 0x7fff7fff, SLJIT_MEM1(SLJIT_R0
), 0x7fff7ffe);
1985 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
+ 0x7fff7fff + 5 * sizeof(sljit_s8
));
1986 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM1(SLJIT_R0
), -0x7fff7fff, SLJIT_MEM1(SLJIT_R0
), -0x7fff8000);
1987 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1988 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
- SLJIT_W(0x123456123456));
1989 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
- SLJIT_W(0x123456123456));
1990 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));
1993 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
1995 code
.code
= sljit_generate_code(compiler
);
1997 sljit_free_compiler(compiler
);
1999 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&sbuf
, (sljit_sw
)&bbuf
);
2000 FAILED(buf
[2] != 176366, "test24 case 1 failed\n");
2001 FAILED(buf
[3] != 64, "test24 case 2 failed\n");
2002 FAILED(buf
[4] != -100, "test24 case 3 failed\n");
2003 FAILED(buf
[5] != 100567, "test24 case 4 failed\n");
2004 FAILED(buf
[6] != 952467, "test24 case 5 failed\n");
2005 FAILED(buf
[7] != 952467, "test24 case 6 failed\n");
2006 FAILED(buf
[8] != 952467 * 2, "test24 case 7 failed\n");
2008 FAILED(sbuf
[1] != 30000, "test24 case 8 failed\n");
2009 FAILED(sbuf
[2] != -12345, "test24 case 9 failed\n");
2010 FAILED(sbuf
[4] != sizeof(sljit_s16
), "test24 case 10 failed\n");
2012 FAILED(bbuf
[1] != -128, "test24 case 11 failed\n");
2013 FAILED(bbuf
[2] != 99, "test24 case 12 failed\n");
2014 FAILED(bbuf
[4] != 99, "test24 case 13 failed\n");
2015 FAILED(bbuf
[5] != 99, "test24 case 14 failed\n");
2016 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2017 FAILED(bbuf
[6] != -128, "test24 case 15 failed\n");
2020 sljit_free_code(code
.code
, NULL
);
2024 static void test25(void)
2026 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2028 executable_code code
;
2029 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2033 printf("Run test25\n");
2035 FAILED(!compiler
, "cannot create compiler\n");
2051 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 1, 0, 0, 0);
2053 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0);
2054 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 1 * sizeof(sljit_sw
), SLJIT_IMM
, 0x7fff);
2055 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_IMM
, -0x8000);
2056 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 0x7fffffff);
2057 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(-0x80000000));
2058 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x1234567887654321));
2059 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0xff80000000));
2060 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x3ff0000000));
2061 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0xfffffff800100000));
2062 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0xfffffff80010f000));
2063 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00000008001));
2064 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00080010000));
2065 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00080018001));
2066 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00ffff00000));
2068 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
2070 code
.code
= sljit_generate_code(compiler
);
2072 sljit_free_compiler(compiler
);
2074 code
.func1((sljit_sw
)&buf
);
2075 FAILED(buf
[0] != 0, "test25 case 1 failed\n");
2076 FAILED(buf
[1] != 0x7fff, "test25 case 2 failed\n");
2077 FAILED(buf
[2] != -0x8000, "test25 case 3 failed\n");
2078 FAILED(buf
[3] != 0x7fffffff, "test25 case 4 failed\n");
2079 FAILED(buf
[4] != SLJIT_W(-0x80000000), "test25 case 5 failed\n");
2080 FAILED(buf
[5] != SLJIT_W(0x1234567887654321), "test25 case 6 failed\n");
2081 FAILED(buf
[6] != SLJIT_W(0xff80000000), "test25 case 7 failed\n");
2082 FAILED(buf
[7] != SLJIT_W(0x3ff0000000), "test25 case 8 failed\n");
2083 FAILED((sljit_uw
)buf
[8] != SLJIT_W(0xfffffff800100000), "test25 case 9 failed\n");
2084 FAILED((sljit_uw
)buf
[9] != SLJIT_W(0xfffffff80010f000), "test25 case 10 failed\n");
2085 FAILED(buf
[10] != SLJIT_W(0x07fff00000008001), "test25 case 11 failed\n");
2086 FAILED(buf
[11] != SLJIT_W(0x07fff00080010000), "test25 case 12 failed\n");
2087 FAILED(buf
[12] != SLJIT_W(0x07fff00080018001), "test25 case 13 failed\n");
2088 FAILED(buf
[13] != SLJIT_W(0x07fff00ffff00000), "test25 case 14 failed\n");
2090 sljit_free_code(code
.code
, NULL
);
2095 static void test26(void)
2097 /* Aligned access without aligned offsets. */
2098 executable_code code
;
2099 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2105 printf("Run test26\n");
2107 FAILED(!compiler
, "cannot create compiler\n");
2124 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
), 3, 3, 0, 0, 0);
2126 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 3);
2127 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 1);
2128 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), -3);
2129 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
) - 1, SLJIT_R0
, 0);
2130 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), -1);
2131 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) - 3, SLJIT_R0
, 0);
2133 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 100);
2134 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);
2135 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 100);
2136 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);
2138 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
2139 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 3);
2140 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f64
) - 3, SLJIT_MEM1(SLJIT_S2
), -3);
2141 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);
2142 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 2);
2143 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sizeof(sljit_f64
) * 3 - 4) >> 1);
2144 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 1);
2145 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);
2148 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
2150 code
.code
= sljit_generate_code(compiler
);
2152 sljit_free_compiler(compiler
);
2154 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&ibuf
, (sljit_sw
)&dbuf
);
2156 FAILED(buf
[1] != -689, "test26 case 1 failed\n");
2157 FAILED(buf
[2] != -16, "test26 case 2 failed\n");
2158 FAILED(ibuf
[1] != -2789, "test26 case 3 failed\n");
2159 FAILED(ibuf
[2] != -18, "test26 case 4 failed\n");
2161 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
2162 FAILED(dbuf
[1] != 5.75, "test26 case 5 failed\n");
2163 FAILED(dbuf
[2] != 11.5, "test26 case 6 failed\n");
2164 FAILED(dbuf
[3] != -2.875, "test26 case 7 failed\n");
2167 sljit_free_code(code
.code
, NULL
);
2171 static void test27(void)
2173 #define SET_NEXT_BYTE(type) \
2174 cond_set(compiler, SLJIT_R2, 0, type); \
2175 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R2, 0); \
2176 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2177 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2180 #define RESULT(i) (3 - i)
2183 /* Playing with conditional flags. */
2184 executable_code code
;
2185 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2188 #ifdef SLJIT_PREF_SHIFT_REG
2189 sljit_s32 shift_reg
= SLJIT_PREF_SHIFT_REG
;
2191 sljit_s32 shift_reg
= SLJIT_R2
;
2194 SLJIT_ASSERT(shift_reg
>= SLJIT_R2
&& shift_reg
<= SLJIT_R3
);
2197 printf("Run test27\n");
2199 for (i
= 0; i
< sizeof(buf
); ++i
)
2202 FAILED(!compiler
, "cannot create compiler\n");
2204 /* 3 arguments passed, 3 arguments used. */
2205 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 4, 3, 0, 0, 0);
2207 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
2209 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1001);
2210 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 20);
2211 /* 0x100100000 on 64 bit machines, 0x100000 on 32 bit machines. */
2212 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x800000);
2213 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2214 sljit_emit_op0(compiler
, SLJIT_ENDBR
); /* ENDBR should keep the flags. */
2215 sljit_emit_op0(compiler
, SLJIT_NOP
); /* Nop should keep the flags. */
2216 SET_NEXT_BYTE(SLJIT_GREATER
);
2217 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2218 SET_NEXT_BYTE(SLJIT_LESS
);
2219 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2220 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
2221 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2222 sljit_emit_op0(compiler
, SLJIT_ENDBR
); /* ENDBR should keep the flags. */
2223 sljit_emit_op0(compiler
, SLJIT_NOP
); /* Nop should keep the flags. */
2224 SET_NEXT_BYTE(SLJIT_GREATER
);
2225 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2226 SET_NEXT_BYTE(SLJIT_LESS
);
2228 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1000);
2229 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 20);
2230 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x10);
2231 /* 0x100000010 on 64 bit machines, 0x10 on 32 bit machines. */
2232 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2233 SET_NEXT_BYTE(SLJIT_GREATER
);
2234 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2235 SET_NEXT_BYTE(SLJIT_LESS
);
2236 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2237 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2238 SET_NEXT_BYTE(SLJIT_GREATER
);
2239 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2240 SET_NEXT_BYTE(SLJIT_LESS
);
2242 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2243 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2244 /* 0xff..ff on all machines. */
2245 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2246 SET_NEXT_BYTE(SLJIT_LESS_EQUAL
);
2247 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2248 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL
);
2249 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R2
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -1);
2250 SET_NEXT_BYTE(SLJIT_SIG_GREATER
);
2251 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -1);
2252 SET_NEXT_BYTE(SLJIT_SIG_LESS
);
2253 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
2254 SET_NEXT_BYTE(SLJIT_EQUAL
);
2255 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
2256 SET_NEXT_BYTE(SLJIT_NOT_EQUAL
);
2257 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2258 SET_NEXT_BYTE(SLJIT_OVERFLOW
);
2259 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2260 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW
);
2261 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2262 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL
);
2263 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2264 SET_NEXT_BYTE(SLJIT_LESS_EQUAL
);
2265 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)-1 << ((8 * sizeof(sljit_sw
)) - 1));
2266 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2267 SET_NEXT_BYTE(SLJIT_SIG_LESS
);
2268 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -1);
2269 SET_NEXT_BYTE(SLJIT_SIG_GREATER
);
2270 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2271 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -2);
2272 SET_NEXT_BYTE(SLJIT_SIG_GREATER_EQUAL
);
2273 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 2);
2274 SET_NEXT_BYTE(SLJIT_SIG_GREATER
);
2276 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x80000000);
2277 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 16);
2278 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 16);
2279 /* 0x80..0 on 64 bit machines, 0 on 32 bit machines. */
2280 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0xffffffff);
2281 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2282 SET_NEXT_BYTE(SLJIT_OVERFLOW
);
2283 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2284 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW
);
2285 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2286 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
2287 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2288 SET_NEXT_BYTE(SLJIT_OVERFLOW
);
2289 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2290 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW
);
2292 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2293 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2294 sljit_emit_op2(compiler
, SLJIT_SUBC
| SLJIT_SET_CARRY
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2295 sljit_emit_op2(compiler
, SLJIT_SUBC
, SLJIT_R0
, 0, SLJIT_IMM
, 6, SLJIT_R0
, 0);
2296 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_R0
, 0);
2297 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
2299 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
2300 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_CARRY
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2301 sljit_emit_op2(compiler
, SLJIT_ADDC
| SLJIT_SET_CARRY
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2302 sljit_emit_op2(compiler
, SLJIT_ADDC
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 9);
2303 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_R0
, 0);
2304 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
2306 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2307 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, (8 * sizeof(sljit_sw
)) - 1);
2308 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2309 SET_NEXT_BYTE(SLJIT_EQUAL
);
2310 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R0
, 0);
2311 SET_NEXT_BYTE(SLJIT_EQUAL
);
2313 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2314 sljit_emit_op2(compiler
, SLJIT_ASHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2315 SET_NEXT_BYTE(SLJIT_EQUAL
);
2316 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2317 sljit_emit_op2(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffffc0);
2318 SET_NEXT_BYTE(SLJIT_NOT_EQUAL
);
2319 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0);
2320 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2321 sljit_emit_op2(compiler
, SLJIT_ASHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, shift_reg
, 0);
2322 SET_NEXT_BYTE(SLJIT_EQUAL
);
2323 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0);
2324 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2325 sljit_emit_op2(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, shift_reg
, 0);
2326 SET_NEXT_BYTE(SLJIT_NOT_EQUAL
);
2328 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2329 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2330 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R0
, 0);
2331 sljit_emit_op2(compiler
, SLJIT_SUBC
| SLJIT_SET_CARRY
, SLJIT_R2
, 0, SLJIT_IMM
, 1, SLJIT_R0
, 0);
2332 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_R2
, 0);
2333 sljit_emit_op2(compiler
, SLJIT_SUBC
| SLJIT_SET_CARRY
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2334 sljit_emit_op2(compiler
, SLJIT_SUBC
, SLJIT_R2
, 0, SLJIT_IMM
, 1, SLJIT_R0
, 0);
2335 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 2, SLJIT_R2
, 0);
2336 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 2);
2338 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -34);
2339 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x1234);
2340 SET_NEXT_BYTE(SLJIT_LESS
);
2341 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x1234);
2342 SET_NEXT_BYTE(SLJIT_SIG_LESS
);
2343 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2344 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x12300000000) - 43);
2346 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, -43);
2348 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -96);
2349 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2350 SET_NEXT_BYTE(SLJIT_LESS
);
2351 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_SIG_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2352 SET_NEXT_BYTE(SLJIT_SIG_GREATER
);
2354 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
2356 code
.code
= sljit_generate_code(compiler
);
2358 sljit_free_compiler(compiler
);
2360 code
.func1((sljit_sw
)&buf
);
2362 FAILED(buf
[0] != RESULT(1), "test27 case 1 failed\n");
2363 FAILED(buf
[1] != RESULT(2), "test27 case 2 failed\n");
2364 FAILED(buf
[2] != 2, "test27 case 3 failed\n");
2365 FAILED(buf
[3] != 1, "test27 case 4 failed\n");
2366 FAILED(buf
[4] != RESULT(1), "test27 case 5 failed\n");
2367 FAILED(buf
[5] != RESULT(2), "test27 case 6 failed\n");
2368 FAILED(buf
[6] != 2, "test27 case 7 failed\n");
2369 FAILED(buf
[7] != 1, "test27 case 8 failed\n");
2371 FAILED(buf
[8] != 2, "test27 case 9 failed\n");
2372 FAILED(buf
[9] != 1, "test27 case 10 failed\n");
2373 FAILED(buf
[10] != 2, "test27 case 11 failed\n");
2374 FAILED(buf
[11] != 1, "test27 case 12 failed\n");
2375 FAILED(buf
[12] != 1, "test27 case 13 failed\n");
2376 FAILED(buf
[13] != 2, "test27 case 14 failed\n");
2377 FAILED(buf
[14] != 2, "test27 case 15 failed\n");
2378 FAILED(buf
[15] != 1, "test27 case 16 failed\n");
2379 FAILED(buf
[16] != 1, "test27 case 17 failed\n");
2380 FAILED(buf
[17] != 2, "test27 case 18 failed\n");
2381 FAILED(buf
[18] != 1, "test27 case 19 failed\n");
2382 FAILED(buf
[19] != 1, "test27 case 20 failed\n");
2383 FAILED(buf
[20] != 1, "test27 case 21 failed\n");
2384 FAILED(buf
[21] != 2, "test27 case 22 failed\n");
2386 FAILED(buf
[22] != RESULT(1), "test27 case 23 failed\n");
2387 FAILED(buf
[23] != RESULT(2), "test27 case 24 failed\n");
2388 FAILED(buf
[24] != 2, "test27 case 25 failed\n");
2389 FAILED(buf
[25] != 1, "test27 case 26 failed\n");
2391 FAILED(buf
[26] != 5, "test27 case 27 failed\n");
2392 FAILED(buf
[27] != 9, "test27 case 28 failed\n");
2394 FAILED(buf
[28] != 2, "test27 case 29 failed\n");
2395 FAILED(buf
[29] != 1, "test27 case 30 failed\n");
2397 FAILED(buf
[30] != 1, "test27 case 31 failed\n");
2398 FAILED(buf
[31] != 1, "test27 case 32 failed\n");
2399 FAILED(buf
[32] != 1, "test27 case 33 failed\n");
2400 FAILED(buf
[33] != 1, "test27 case 34 failed\n");
2402 FAILED(buf
[34] != 1, "test27 case 35 failed\n");
2403 FAILED(buf
[35] != 0, "test27 case 36 failed\n");
2405 FAILED(buf
[36] != 2, "test27 case 37 failed\n");
2406 FAILED(buf
[37] != 1, "test27 case 38 failed\n");
2407 FAILED(buf
[38] != 2, "test27 case 39 failed\n");
2408 FAILED(buf
[39] != 1, "test27 case 40 failed\n");
2409 FAILED(buf
[40] != 10, "test27 case 41 failed\n");
2411 sljit_free_code(code
.code
, NULL
);
2413 #undef SET_NEXT_BYTE
2417 static void test28(void)
2420 executable_code code
;
2421 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2422 struct sljit_const
* const1
= NULL
;
2423 struct sljit_label
* label
= NULL
;
2424 sljit_uw label_addr
= 0;
2428 printf("Run test28\n");
2430 FAILED(!compiler
, "cannot create compiler\n");
2438 FAILED(!compiler
, "cannot create compiler\n");
2439 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 5, 5, 0, 0, 0);
2440 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -234);
2441 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
2442 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_S3
, 0, SLJIT_R3
, 0, SLJIT_R4
, 0);
2443 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_S3
, 0);
2444 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_S3
, 0, SLJIT_IMM
, 0);
2445 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_NOT_ZERO
);
2446 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_S3
, 0);
2447 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
));
2448 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S4
, 0, SLJIT_S4
, 0, SLJIT_R4
, 0);
2449 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_S4
, 0);
2451 const1
= sljit_emit_const(compiler
, SLJIT_S3
, 0, 0);
2452 sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_S3
, 0);
2453 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S3
, 0, SLJIT_S3
, 0, SLJIT_IMM
, 100);
2454 label
= sljit_emit_label(compiler
);
2455 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
2456 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_S3
, 0);
2458 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R4
, 0);
2460 code
.code
= sljit_generate_code(compiler
);
2463 label_addr
= sljit_get_label_addr(label
);
2464 sljit_set_const(sljit_get_const_addr(const1
), label_addr
, sljit_get_executable_offset(compiler
));
2466 sljit_free_compiler(compiler
);
2468 FAILED(code
.func1((sljit_sw
)&buf
) != 8, "test28 case 1 failed\n");
2469 FAILED(buf
[1] != -1872, "test28 case 2 failed\n");
2470 FAILED(buf
[2] != 1, "test28 case 3 failed\n");
2471 FAILED(buf
[3] != 2, "test28 case 4 failed\n");
2472 FAILED(buf
[4] != label_addr
, "test28 case 5 failed\n");
2474 sljit_free_code(code
.code
, NULL
);
2478 static void test29(void)
2480 /* Test signed/unsigned bytes and halfs. */
2481 executable_code code
;
2482 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2487 printf("Run test29\n");
2489 for (i
= 0; i
< 25; i
++)
2492 FAILED(!compiler
, "cannot create compiler\n");
2493 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 5, 5, 0, 0, 0);
2495 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_IMM
, -187);
2496 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
2497 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_IMM
, -605);
2498 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2499 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R0
, 0, SLJIT_IMM
, -56);
2500 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2501 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R4
, 0, SLJIT_IMM
, 0xcde5);
2502 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2504 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_IMM
, -45896);
2505 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2506 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_IMM
, -1472797);
2507 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2508 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R0
, 0, SLJIT_IMM
, -12890);
2509 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2510 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R4
, 0, SLJIT_IMM
, 0x9cb0a6);
2511 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2513 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2514 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-3580429715));
2515 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2516 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-100722768662));
2517 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2518 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-1457052677972));
2519 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2520 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R4
, 0, SLJIT_IMM
, SLJIT_W(0xcef97a70b5));
2521 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2524 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -187);
2525 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2526 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2527 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -605);
2528 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_S2
, 0);
2529 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2530 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -56);
2531 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R0
, 0, SLJIT_R2
, 0);
2532 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2533 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0xcde5);
2534 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R4
, 0, SLJIT_R3
, 0);
2535 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2537 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -45896);
2538 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2539 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2540 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1472797);
2541 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_S2
, 0);
2542 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2543 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -12890);
2544 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R0
, 0, SLJIT_R2
, 0);
2545 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2546 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x9cb0a6);
2547 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R4
, 0, SLJIT_R3
, 0);
2548 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 19 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2550 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2551 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(-3580429715));
2552 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2553 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2554 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, SLJIT_W(-100722768662));
2555 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_S2
, 0);
2556 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 21 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2557 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, SLJIT_W(-1457052677972));
2558 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R2
, 0);
2559 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2560 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_W(0xcef97a70b5));
2561 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R4
, 0, SLJIT_R3
, 0);
2562 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 23 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2565 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, 0x9faa5);
2566 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_S2
, 0, SLJIT_S2
, 0);
2567 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 24 * sizeof(sljit_uw
), SLJIT_S2
, 0);
2569 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
2571 code
.code
= sljit_generate_code(compiler
);
2573 sljit_free_compiler(compiler
);
2575 code
.func1((sljit_sw
)&buf
);
2576 FAILED(buf
[0] != 69, "test29 case 1 failed\n");
2577 FAILED(buf
[1] != -93, "test29 case 2 failed\n");
2578 FAILED(buf
[2] != 200, "test29 case 3 failed\n");
2579 FAILED(buf
[3] != 0xe5, "test29 case 4 failed\n");
2580 FAILED(buf
[4] != 19640, "test29 case 5 failed\n");
2581 FAILED(buf
[5] != -31005, "test29 case 6 failed\n");
2582 FAILED(buf
[6] != 52646, "test29 case 7 failed\n");
2583 FAILED(buf
[7] != 0xb0a6, "test29 case 8 failed\n");
2585 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2586 FAILED(buf
[8] != SLJIT_W(714537581), "test29 case 9 failed\n");
2587 FAILED(buf
[9] != SLJIT_W(-1938520854), "test29 case 10 failed\n");
2588 FAILED(buf
[10] != SLJIT_W(3236202668), "test29 case 11 failed\n");
2589 FAILED(buf
[11] != SLJIT_W(0xf97a70b5), "test29 case 12 failed\n");
2592 FAILED(buf
[12] != 69, "test29 case 13 failed\n");
2593 FAILED(buf
[13] != -93, "test29 case 14 failed\n");
2594 FAILED(buf
[14] != 200, "test29 case 15 failed\n");
2595 FAILED(buf
[15] != 0xe5, "test29 case 16 failed\n");
2596 FAILED(buf
[16] != 19640, "test29 case 17 failed\n");
2597 FAILED(buf
[17] != -31005, "test29 case 18 failed\n");
2598 FAILED(buf
[18] != 52646, "test29 case 19 failed\n");
2599 FAILED(buf
[19] != 0xb0a6, "test29 case 20 failed\n");
2601 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2602 FAILED(buf
[20] != SLJIT_W(714537581), "test29 case 21 failed\n");
2603 FAILED(buf
[21] != SLJIT_W(-1938520854), "test29 case 22 failed\n");
2604 FAILED(buf
[22] != SLJIT_W(3236202668), "test29 case 23 failed\n");
2605 FAILED(buf
[23] != SLJIT_W(0xf97a70b5), "test29 case 24 failed\n");
2608 FAILED(buf
[24] != -91, "test29 case 25 failed\n");
2610 sljit_free_code(code
.code
, NULL
);
2614 static void test30(void)
2616 /* Test unused results. */
2617 executable_code code
;
2618 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2622 printf("Run test30\n");
2624 FAILED(!compiler
, "cannot create compiler\n");
2626 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 5, 5, 0, 0, 0);
2628 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2629 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2630 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 1);
2631 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 1);
2632 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, 1);
2633 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2634 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S1
, 0, SLJIT_IMM
, SLJIT_W(-0x123ffffffff));
2636 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S1
, 0, SLJIT_IMM
, 1);
2638 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, 1);
2639 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, 1);
2640 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_IMM
, 1);
2642 /* Some calculations with unused results. */
2643 sljit_emit_op1(compiler
, SLJIT_NOT
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0);
2644 sljit_emit_op1(compiler
, SLJIT_NEG
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
2645 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
2646 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_GREATER_EQUAL
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
2647 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_S0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
2648 sljit_emit_op2(compiler
, SLJIT_SHL
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_S3
, 0, SLJIT_R2
, 0);
2649 sljit_emit_op2(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 5);
2650 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0xff);
2651 sljit_emit_op1(compiler
, SLJIT_NOT32
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_S1
, 0);
2653 /* Testing that any change happens. */
2654 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2655 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R2
, 0);
2656 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R3
, 0);
2657 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R4
, 0);
2658 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_S1
, 0, SLJIT_S1
, 0);
2659 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S1
, 0);
2660 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S2
, 0);
2661 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S3
, 0);
2662 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0, SLJIT_S4
, 0);
2664 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
2666 code
.code
= sljit_generate_code(compiler
);
2668 sljit_free_compiler(compiler
);
2670 code
.func1((sljit_sw
)&buf
);
2671 FAILED(buf
[0] != 9, "test30 case 1 failed\n");
2673 sljit_free_code(code
.code
, NULL
);
2677 static void test31(void)
2679 /* Integer mul and set flags. */
2680 executable_code code
;
2681 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2684 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2685 sljit_sw big_word
= SLJIT_W(0x7fffffff00000000);
2686 sljit_sw big_word2
= SLJIT_W(0x7fffffff00000012);
2688 sljit_sw big_word
= 0x7fffffff;
2689 sljit_sw big_word2
= 0x00000012;
2693 printf("Run test31\n");
2695 for (i
= 0; i
< 12; i
++)
2698 FAILED(!compiler
, "cannot create compiler\n");
2700 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 5, 0, 0, 0);
2701 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
2702 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -45);
2703 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_NOT_OVERFLOW
);
2704 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -45);
2705 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_OVERFLOW
);
2707 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, big_word
);
2708 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, -2);
2709 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 33); /* Should not change flags. */
2710 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0); /* Should not change flags. */
2711 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
2712 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, -2);
2713 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_NOT_OVERFLOW
);
2715 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S3
, 0, SLJIT_IMM
, 0x3f6b0);
2716 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S4
, 0, SLJIT_IMM
, 0x2a783);
2717 sljit_emit_op2(compiler
, SLJIT_MUL32
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_S3
, 0, SLJIT_S4
, 0);
2718 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
2719 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R1
, 0);
2721 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, big_word2
);
2722 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_R1
, 0);
2723 sljit_emit_op2(compiler
, SLJIT_MUL32
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 23);
2724 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
2726 sljit_emit_op2(compiler
, SLJIT_MUL32
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, -23);
2727 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_NOT_OVERFLOW
);
2728 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, -23);
2729 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_NOT_OVERFLOW
);
2731 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 67);
2732 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -23);
2733 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R1
, 0);
2735 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
2737 code
.code
= sljit_generate_code(compiler
);
2739 sljit_free_compiler(compiler
);
2741 code
.func1((sljit_sw
)&buf
);
2743 FAILED(buf
[0] != 1, "test31 case 1 failed\n");
2744 FAILED(buf
[1] != 2, "test31 case 2 failed\n");
2745 /* Qemu issues for 64 bit muls. */
2746 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2747 FAILED(buf
[2] != 1, "test31 case 3 failed\n");
2748 FAILED(buf
[3] != 2, "test31 case 4 failed\n");
2750 FAILED(buf
[4] != 1, "test31 case 5 failed\n");
2751 FAILED((buf
[5] & 0xffffffff) != 0x85540c10, "test31 case 6 failed\n");
2752 FAILED(buf
[6] != 2, "test31 case 7 failed\n");
2753 FAILED(buf
[7] != 1, "test31 case 8 failed\n");
2754 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2755 FAILED(buf
[8] != 1, "test31 case 9 failed\n");
2757 FAILED(buf
[9] != -1541, "test31 case 10 failed\n");
2759 sljit_free_code(code
.code
, NULL
);
2763 static void test32(void)
2765 /* Floating point set flags. */
2766 executable_code code
;
2767 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2780 printf("Run test32\n");
2782 for (i
= 0; i
< 16; i
++)
2786 dbuf
[0].u
.value1
= 0x7fffffff;
2787 dbuf
[0].u
.value2
= 0x7fffffff;
2788 dbuf
[1].u
.value1
= 0x7fffffff;
2789 dbuf
[1].u
.value2
= 0x7fffffff;
2790 dbuf
[2].value
= -13.0;
2791 dbuf
[3].value
= 27.0;
2793 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
2795 printf("no fpu available, test32 skipped\n");
2798 sljit_free_compiler(compiler
);
2802 FAILED(!compiler
, "cannot create compiler\n");
2803 SLJIT_ASSERT(sizeof(sljit_f64
) == 8 && sizeof(sljit_s32
) == 4 && sizeof(dbuf
[0]) == 8);
2805 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
), 1, 2, 4, 0, 0);
2807 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
2808 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED_F
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
2809 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f64
));
2810 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_UNORDERED_F64
);
2811 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_ORDERED_F
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
2812 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_ORDERED_F64
);
2814 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
));
2815 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2816 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_UNORDERED_F64
);
2817 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_ORDERED_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2818 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_ORDERED_F64
);
2819 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_LESS_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2820 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_LESS_F64
);
2821 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_GREATER_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2822 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_GREATER_EQUAL_F64
);
2823 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_GREATER_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2824 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_GREATER_F64
);
2825 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_LESS_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2826 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_LESS_EQUAL_F64
);
2827 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2828 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_EQUAL_F64
);
2829 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_NOT_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2830 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_NOT_EQUAL_F64
);
2832 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED_F
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
));
2833 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR3
, 0, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
));
2834 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_UNORDERED_F64
);
2835 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_EQUAL_F
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
));
2836 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_EQUAL_F64
);
2838 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_ORDERED_F
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
), SLJIT_FR0
, 0);
2839 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_ORDERED_F64
);
2841 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED_F
, SLJIT_FR3
, 0, SLJIT_FR2
, 0);
2842 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
2843 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_UNORDERED_F64
);
2845 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
2847 code
.code
= sljit_generate_code(compiler
);
2849 sljit_free_compiler(compiler
);
2851 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&dbuf
);
2853 FAILED(buf
[0] != 1, "test32 case 1 failed\n");
2854 FAILED(buf
[1] != 2, "test32 case 2 failed\n");
2855 FAILED(buf
[2] != 2, "test32 case 3 failed\n");
2856 FAILED(buf
[3] != 1, "test32 case 4 failed\n");
2857 FAILED(buf
[4] != 1, "test32 case 5 failed\n");
2858 FAILED(buf
[5] != 2, "test32 case 6 failed\n");
2859 FAILED(buf
[6] != 2, "test32 case 7 failed\n");
2860 FAILED(buf
[7] != 1, "test32 case 8 failed\n");
2861 FAILED(buf
[8] != 2, "test32 case 9 failed\n");
2862 FAILED(buf
[9] != 1, "test32 case 10 failed\n");
2863 FAILED(buf
[10] != 2, "test32 case 11 failed\n");
2864 FAILED(buf
[11] != 1, "test32 case 12 failed\n");
2865 FAILED(buf
[12] != 2, "test32 case 13 failed\n");
2866 FAILED(buf
[13] != 1, "test32 case 14 failed\n");
2868 sljit_free_code(code
.code
, NULL
);
2872 static void test33(void)
2874 /* Test setting multiple flags. */
2875 executable_code code
;
2876 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2877 struct sljit_jump
* jump
;
2881 printf("Run test33\n");
2894 FAILED(!compiler
, "cannot create compiler\n");
2896 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 3, 0, 0, 0);
2898 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 20);
2899 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 10);
2900 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2901 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_ZERO
);
2902 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -10);
2903 jump
= sljit_emit_jump(compiler
, SLJIT_LESS
);
2904 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 11);
2905 sljit_set_label(jump
, sljit_emit_label(compiler
));
2907 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_SIG_GREATER
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2908 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_SIG_GREATER
);
2909 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 45);
2910 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_EQUAL
);
2911 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 55);
2912 sljit_set_label(jump
, sljit_emit_label(compiler
));
2914 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2915 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x8000000000000000));
2917 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x80000000));
2919 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2920 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2921 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, 33);
2922 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_OVERFLOW
);
2923 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_ZERO
);
2924 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, 13);
2925 sljit_set_label(jump
, sljit_emit_label(compiler
));
2927 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x80000000));
2928 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R0
, 0);
2929 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2930 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
2931 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_NOT_ZERO
);
2932 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, 78);
2933 jump
= sljit_emit_jump(compiler
, SLJIT_OVERFLOW
);
2934 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, 48);
2935 sljit_set_label(jump
, sljit_emit_label(compiler
));
2937 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2938 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x8000000000000000));
2940 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x80000000));
2942 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_R0
, 0);
2943 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2944 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_IMM
, 30);
2945 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_OVERFLOW
);
2946 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_IMM
, 50);
2947 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_ZERO
);
2948 sljit_set_label(jump
, sljit_emit_label(compiler
));
2950 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
2952 code
.code
= sljit_generate_code(compiler
);
2954 sljit_free_compiler(compiler
);
2956 code
.func1((sljit_sw
)&buf
);
2958 FAILED(buf
[0] != 0, "test33 case 1 failed\n");
2959 FAILED(buf
[1] != 11, "test33 case 2 failed\n");
2960 FAILED(buf
[2] != 1, "test33 case 3 failed\n");
2961 FAILED(buf
[3] != 45, "test33 case 4 failed\n");
2962 FAILED(buf
[4] != 13, "test33 case 5 failed\n");
2963 FAILED(buf
[5] != 0, "test33 case 6 failed\n");
2964 FAILED(buf
[6] != 0, "test33 case 7 failed\n");
2965 FAILED(buf
[7] != 48, "test33 case 8 failed\n");
2966 FAILED(buf
[8] != 50, "test33 case 9 failed\n");
2967 FAILED(buf
[9] != 1, "test33 case 10 failed\n");
2969 sljit_free_code(code
.code
, NULL
);
2973 static void test34(void)
2975 /* Test fast calls. */
2976 executable_code codeA
;
2977 executable_code codeB
;
2978 executable_code codeC
;
2979 executable_code codeD
;
2980 executable_code codeE
;
2981 executable_code codeF
;
2982 struct sljit_compiler
* compiler
;
2983 struct sljit_jump
*jump
;
2984 struct sljit_label
* label
;
2989 printf("Run test34\n");
2995 compiler
= sljit_create_compiler(NULL
, NULL
);
2996 FAILED(!compiler
, "cannot create compiler\n");
2997 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
2999 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3000 sljit_emit_fast_enter(compiler
, SLJIT_R1
, 0);
3001 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 4);
3002 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R1
, 0);
3004 codeA
.code
= sljit_generate_code(compiler
);
3006 sljit_free_compiler(compiler
);
3009 compiler
= sljit_create_compiler(NULL
, NULL
);
3010 FAILED(!compiler
, "cannot create compiler\n");
3011 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3013 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3014 sljit_emit_fast_enter(compiler
, SLJIT_R4
, 0);
3015 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 6);
3016 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(codeA
.code
));
3017 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_R1
, 0);
3018 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R4
, 0);
3020 codeB
.code
= sljit_generate_code(compiler
);
3022 sljit_free_compiler(compiler
);
3025 compiler
= sljit_create_compiler(NULL
, NULL
);
3026 FAILED(!compiler
, "cannot create compiler\n");
3027 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3029 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3030 sljit_emit_fast_enter(compiler
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_p
));
3031 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3032 jump
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
| SLJIT_REWRITABLE_JUMP
);
3033 sljit_set_target(jump
, SLJIT_FUNC_OFFSET(codeB
.code
));
3034 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_p
));
3036 codeC
.code
= sljit_generate_code(compiler
);
3038 sljit_free_compiler(compiler
);
3041 compiler
= sljit_create_compiler(NULL
, NULL
);
3042 FAILED(!compiler
, "cannot create compiler\n");
3043 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3045 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3046 sljit_emit_fast_enter(compiler
, SLJIT_MEM1(SLJIT_SP
), 0);
3047 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 10);
3048 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_OFFSET(codeC
.code
));
3049 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_MEM1(SLJIT_SP
), 0);
3051 codeD
.code
= sljit_generate_code(compiler
);
3053 sljit_free_compiler(compiler
);
3056 compiler
= sljit_create_compiler(NULL
, NULL
);
3057 FAILED(!compiler
, "cannot create compiler\n");
3058 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3060 sljit_emit_fast_enter(compiler
, SLJIT_MEM1(SLJIT_S0
), 0);
3061 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 12);
3062 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_p
), SLJIT_IMM
, SLJIT_FUNC_OFFSET(codeD
.code
));
3063 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_p
));
3064 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_MEM1(SLJIT_S0
), 0);
3066 codeE
.code
= sljit_generate_code(compiler
);
3068 sljit_free_compiler(compiler
);
3071 compiler
= sljit_create_compiler(NULL
, NULL
);
3072 FAILED(!compiler
, "cannot create compiler\n");
3074 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3075 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3076 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_OFFSET(codeE
.code
));
3077 label
= sljit_emit_label(compiler
);
3078 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
3080 codeF
.code
= sljit_generate_code(compiler
);
3082 addr
= sljit_get_label_addr(label
);
3083 sljit_free_compiler(compiler
);
3085 FAILED(codeF
.func1((sljit_sw
)&buf
) != 40, "test34 case 1 failed\n");
3086 FAILED(buf
[0] != addr
- SLJIT_RETURN_ADDRESS_OFFSET
, "test34 case 2 failed\n");
3088 sljit_free_code(codeA
.code
, NULL
);
3089 sljit_free_code(codeB
.code
, NULL
);
3090 sljit_free_code(codeC
.code
, NULL
);
3091 sljit_free_code(codeD
.code
, NULL
);
3092 sljit_free_code(codeE
.code
, NULL
);
3093 sljit_free_code(codeF
.code
, NULL
);
3097 static void test35(void)
3099 /* More complicated tests for fast calls. */
3100 executable_code codeA
;
3101 executable_code codeB
;
3102 executable_code codeC
;
3103 struct sljit_compiler
* compiler
;
3104 struct sljit_jump
*jump
= NULL
;
3105 struct sljit_label
* label
;
3106 sljit_sw executable_offset
;
3107 sljit_uw return_addr
;
3108 sljit_uw jump_addr
= 0;
3112 printf("Run test35\n");
3117 compiler
= sljit_create_compiler(NULL
, NULL
);
3118 FAILED(!compiler
, "cannot create compiler\n");
3119 sljit_set_context(compiler
, 0, 0, 2, 2, 0, 0, 0);
3121 sljit_emit_fast_enter(compiler
, SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
3122 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3124 jump
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
| SLJIT_REWRITABLE_JUMP
);
3125 sljit_set_target(jump
, 0);
3127 label
= sljit_emit_label(compiler
);
3128 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
3130 codeA
.code
= sljit_generate_code(compiler
);
3132 executable_offset
= sljit_get_executable_offset(compiler
);
3133 jump_addr
= sljit_get_jump_addr(jump
);
3134 sljit_free_compiler(compiler
);
3137 compiler
= sljit_create_compiler(NULL
, NULL
);
3138 FAILED(!compiler
, "cannot create compiler\n");
3139 sljit_set_context(compiler
, 0, 0, 2, 2, 0, 0, 0);
3141 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3142 sljit_emit_fast_enter(compiler
, SLJIT_R1
, 0);
3143 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 7);
3144 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R1
, 0);
3146 codeB
.code
= sljit_generate_code(compiler
);
3148 sljit_free_compiler(compiler
);
3150 sljit_set_jump_addr(jump_addr
, SLJIT_FUNC_OFFSET(codeB
.code
), executable_offset
);
3153 compiler
= sljit_create_compiler(NULL
, NULL
);
3154 FAILED(!compiler
, "cannot create compiler\n");
3156 sljit_emit_enter(compiler
, 0, 0, 2, 2, 0, 0, 0);
3157 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3158 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_OFFSET(codeA
.code
));
3159 label
= sljit_emit_label(compiler
);
3160 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
3162 codeC
.code
= sljit_generate_code(compiler
);
3164 return_addr
= sljit_get_label_addr(label
);
3165 sljit_free_compiler(compiler
);
3167 FAILED(codeC
.func0() != 12, "test35 case 1 failed\n");
3168 FAILED(buf
[0] != return_addr
- SLJIT_RETURN_ADDRESS_OFFSET
, "test35 case 2 failed\n");
3170 sljit_free_code(codeA
.code
, NULL
);
3171 sljit_free_code(codeB
.code
, NULL
);
3172 sljit_free_code(codeC
.code
, NULL
);
3176 static void cmp_test(struct sljit_compiler
*compiler
, sljit_s32 type
, sljit_s32 src1
, sljit_sw src1w
, sljit_s32 src2
, sljit_sw src2w
)
3178 /* 2 = true, 1 = false */
3179 struct sljit_jump
* jump
;
3180 struct sljit_label
* label
;
3182 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_IMM
, 2);
3183 jump
= sljit_emit_cmp(compiler
, type
, src1
, src1w
, src2
, src2w
);
3184 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_IMM
, 1);
3185 label
= sljit_emit_label(compiler
);
3186 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3187 sljit_set_label(jump
, label
);
3188 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
3191 #define TEST_CASES (7 + 10 + 12 + 11 + 4)
3192 static void test36(void)
3194 /* Compare instruction. */
3195 executable_code code
;
3196 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3198 sljit_s8 buf
[TEST_CASES
];
3199 sljit_s8 compare_buf
[TEST_CASES
] = {
3200 1, 1, 2, 2, 1, 2, 2,
3201 1, 1, 2, 2, 2, 1, 2, 2, 1, 1,
3202 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2,
3203 2, 1, 2, 1, 1, 1, 2, 1, 2, 1, 2,
3210 printf("Run test36\n");
3212 FAILED(!compiler
, "cannot create compiler\n");
3213 for (i
= 0; i
< TEST_CASES
; ++i
)
3220 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
), 3, 2, 0, 0, 0);
3221 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
3223 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 13);
3224 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 15);
3225 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_IMM
, 9, SLJIT_R0
, 0);
3226 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3227 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
3228 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_IMM
, -13);
3229 cmp_test(compiler
, SLJIT_NOT_EQUAL
, SLJIT_IMM
, 0, SLJIT_R0
, 0);
3230 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3231 cmp_test(compiler
, SLJIT_NOT_EQUAL
| SLJIT_REWRITABLE_JUMP
, SLJIT_IMM
, 0, SLJIT_R0
, 0);
3232 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
);
3233 cmp_test(compiler
, SLJIT_EQUAL
| SLJIT_REWRITABLE_JUMP
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3235 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, 0);
3236 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -8);
3237 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3238 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3239 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3240 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_REWRITABLE_JUMP
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3241 cmp_test(compiler
, SLJIT_SIG_GREATER_EQUAL
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3242 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
));
3243 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_IMM
, 0, SLJIT_R1
, 0);
3244 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
));
3245 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
));
3246 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_REWRITABLE_JUMP
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
));
3248 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3249 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3250 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
));
3251 cmp_test(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3252 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, -10);
3253 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3254 cmp_test(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_IMM
, 8, SLJIT_R1
, 0);
3255 cmp_test(compiler
, SLJIT_GREATER_EQUAL
| SLJIT_REWRITABLE_JUMP
, SLJIT_IMM
, 8, SLJIT_R1
, 0);
3256 cmp_test(compiler
, SLJIT_GREATER
, SLJIT_IMM
, 8, SLJIT_R1
, 0);
3257 cmp_test(compiler
, SLJIT_LESS_EQUAL
, SLJIT_IMM
, 7, SLJIT_R0
, 0);
3258 cmp_test(compiler
, SLJIT_GREATER
, SLJIT_IMM
, 1, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
));
3259 cmp_test(compiler
, SLJIT_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3260 cmp_test(compiler
, SLJIT_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3261 cmp_test(compiler
, SLJIT_GREATER
| SLJIT_REWRITABLE_JUMP
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3263 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -3);
3264 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3265 cmp_test(compiler
, SLJIT_SIG_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3266 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
3267 cmp_test(compiler
, SLJIT_SIG_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3268 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, -1);
3269 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_REWRITABLE_JUMP
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, -1);
3270 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3271 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3272 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_IMM
, -4, SLJIT_R0
, 0);
3273 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_IMM
, -1, SLJIT_R1
, 0);
3274 cmp_test(compiler
, SLJIT_SIG_GREATER
| SLJIT_REWRITABLE_JUMP
, SLJIT_R1
, 0, SLJIT_IMM
, -1);
3276 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3277 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xf00000004));
3278 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R0
, 0);
3279 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
3280 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3281 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xff0000004));
3282 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R0
, 0);
3283 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
3284 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3286 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
3287 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3288 cmp_test(compiler
, SLJIT_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3289 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0xf0000004);
3290 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3291 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3294 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
3296 code
.code
= sljit_generate_code(compiler
);
3298 sljit_free_compiler(compiler
);
3300 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&data
);
3302 for (i
= 0; i
< TEST_CASES
; ++i
)
3303 if (SLJIT_UNLIKELY(buf
[i
] != compare_buf
[i
])) {
3304 printf("test36 case %d failed\n", i
+ 1);
3308 sljit_free_code(code
.code
, NULL
);
3313 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3314 #define BITN(n) (SLJIT_W(1) << (63 - (n)))
3317 #define BITN(n) (1 << (31 - ((n) & 0x1f)))
3318 #define RESN(n) ((n) & 0x1f)
3321 static void test37(void)
3323 /* Test count leading zeroes. */
3324 executable_code code
;
3325 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3331 printf("Run test37\n");
3333 FAILED(!compiler
, "cannot create compiler\n");
3335 for (i
= 0; i
< 9; i
++)
3341 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
), 1, 3, 0, 0, 0);
3342 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, BITN(27));
3343 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
3344 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, BITN(47));
3345 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_R0
, 0, SLJIT_S2
, 0);
3346 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
3347 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
));
3348 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
3349 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3350 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3351 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3352 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_R0
, 0);
3353 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
3354 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
));
3355 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3356 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, BITN(58));
3357 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3358 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3359 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3360 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3361 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xff08a00000));
3363 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x08a00000);
3365 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
), SLJIT_R0
, 0);
3366 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3367 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3368 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3369 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xffc8a00000));
3371 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0xc8a00000);
3373 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3374 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3376 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
3378 code
.code
= sljit_generate_code(compiler
);
3380 sljit_free_compiler(compiler
);
3382 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&ibuf
);
3383 FAILED(buf
[0] != RESN(27), "test37 case 1 failed\n");
3384 FAILED(buf
[1] != RESN(47), "test37 case 2 failed\n");
3385 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3386 FAILED(buf
[2] != 64, "test37 case 3 failed\n");
3388 FAILED(buf
[2] != 32, "test37 case 3 failed\n");
3390 FAILED(buf
[3] != 0, "test37 case 4 failed\n");
3391 FAILED(ibuf
[0] != 32, "test37 case 5 failed\n");
3392 FAILED(buf
[4] != RESN(13), "test37 case 6 failed\n");
3393 FAILED(buf
[5] != RESN(58), "test37 case 7 failed\n");
3394 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3395 FAILED(buf
[6] != 64, "test37 case 8 failed\n");
3397 FAILED(buf
[6] != 32, "test37 case 8 failed\n");
3399 FAILED(ibuf
[1] != 4, "test37 case 9 failed\n");
3401 FAILED((buf
[7] & 0xffffffff) != 4, "test37 case 10 failed\n");
3402 FAILED((buf
[8] & 0xffffffff) != 0, "test37 case 11 failed\n");
3404 sljit_free_code(code
.code
, NULL
);
3410 static void test38(void)
3412 #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)
3413 /* Test stack utility. */
3414 executable_code code
;
3415 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3416 struct sljit_jump
* alloc1_fail
;
3417 struct sljit_jump
* alloc2_fail
;
3418 struct sljit_jump
* alloc3_fail
;
3419 struct sljit_jump
* sanity1_fail
;
3420 struct sljit_jump
* sanity2_fail
;
3421 struct sljit_jump
* sanity3_fail
;
3422 struct sljit_jump
* sanity4_fail
;
3423 struct sljit_jump
* jump
;
3424 struct sljit_label
* label
;
3427 printf("Run test38\n");
3429 FAILED(!compiler
, "cannot create compiler\n");
3431 sljit_emit_enter(compiler
, 0, 0, 3, 1, 0, 0, 0);
3433 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8192);
3434 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 65536);
3435 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0);
3436 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
), SLJIT_IMM
, SLJIT_FUNC_OFFSET(sljit_allocate_stack
));
3437 alloc1_fail
= sljit_emit_cmp(compiler
, SLJIT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0);
3438 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_RETURN_REG
, 0);
3440 /* Write 8k data. */
3441 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3442 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8192);
3443 label
= sljit_emit_label(compiler
);
3444 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_IMM
, -1);
3445 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
3446 jump
= sljit_emit_cmp(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3447 sljit_set_label(jump
, label
);
3450 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
3451 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, end
), SLJIT_IMM
, 65536);
3452 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
), SLJIT_IMM
, SLJIT_FUNC_OFFSET(sljit_stack_resize
));
3453 alloc2_fail
= sljit_emit_cmp(compiler
, SLJIT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0);
3454 sanity1_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3456 /* Write 64k data. */
3457 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3458 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 65536);
3459 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, min_start
));
3460 sanity2_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, 0, SLJIT_R2
, 0);
3461 label
= sljit_emit_label(compiler
);
3462 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_IMM
, -1);
3463 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
3464 jump
= sljit_emit_cmp(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3465 sljit_set_label(jump
, label
);
3468 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
3469 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, end
), SLJIT_IMM
, 32768);
3470 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
), SLJIT_IMM
, SLJIT_FUNC_OFFSET(sljit_stack_resize
));
3471 alloc3_fail
= sljit_emit_cmp(compiler
, SLJIT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0);
3472 sanity3_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3474 /* Write 32k data. */
3475 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3476 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, end
));
3477 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R2
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 32768);
3478 sanity4_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, 0, SLJIT_R2
, 0);
3479 label
= sljit_emit_label(compiler
);
3480 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_IMM
, -1);
3481 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
3482 jump
= sljit_emit_cmp(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3483 sljit_set_label(jump
, label
);
3485 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
3486 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3487 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
), SLJIT_IMM
, SLJIT_FUNC_OFFSET(sljit_free_stack
));
3489 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, 4567);
3491 label
= sljit_emit_label(compiler
);
3492 sljit_set_label(alloc1_fail
, label
);
3493 sljit_set_label(alloc2_fail
, label
);
3494 sljit_set_label(alloc3_fail
, label
);
3495 sljit_set_label(sanity1_fail
, label
);
3496 sljit_set_label(sanity2_fail
, label
);
3497 sljit_set_label(sanity3_fail
, label
);
3498 sljit_set_label(sanity4_fail
, label
);
3499 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, 0);
3501 code
.code
= sljit_generate_code(compiler
);
3503 sljit_free_compiler(compiler
);
3505 /* Just survive this. */
3506 FAILED(code
.func0() != 4567, "test38 case 1 failed\n");
3508 sljit_free_code(code
.code
, NULL
);
3513 static void test39(void)
3515 /* Test error handling. */
3516 executable_code code
;
3517 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3518 struct sljit_jump
* jump
;
3521 printf("Run test39\n");
3523 FAILED(!compiler
, "cannot create compiler\n");
3525 /* Such assignment should never happen in a regular program. */
3526 compiler
->error
= -3967;
3528 SLJIT_ASSERT(sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
), 5, 5, 6, 0, 32) == -3967);
3529 SLJIT_ASSERT(sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R1
, 0) == -3967);
3530 SLJIT_ASSERT(sljit_emit_op0(compiler
, SLJIT_NOP
) == -3967);
3531 SLJIT_ASSERT(sljit_emit_op0(compiler
, SLJIT_ENDBR
) == -3967);
3532 SLJIT_ASSERT(sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1) == -3967);
3533 SLJIT_ASSERT(sljit_emit_op2(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R0
), 64, SLJIT_MEM1(SLJIT_S0
), -64) == -3967);
3534 SLJIT_ASSERT(sljit_emit_fop1(compiler
, SLJIT_ABS_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_R1
), 0) == -3967);
3535 SLJIT_ASSERT(sljit_emit_fop2(compiler
, SLJIT_DIV_F64
, SLJIT_FR2
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_S0
), 0, SLJIT_FR2
, 0) == -3967);
3536 SLJIT_ASSERT(!sljit_emit_label(compiler
));
3537 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
));
3538 SLJIT_ASSERT(!jump
);
3539 sljit_set_label(jump
, (struct sljit_label
*)0x123450);
3540 sljit_set_target(jump
, 0x123450);
3541 jump
= sljit_emit_cmp(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3542 SLJIT_ASSERT(!jump
);
3543 SLJIT_ASSERT(sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_MEM1(SLJIT_R0
), 8) == -3967);
3544 SLJIT_ASSERT(sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_OVERFLOW
) == -3967);
3545 SLJIT_ASSERT(!sljit_emit_const(compiler
, SLJIT_R0
, 0, 99));
3547 SLJIT_ASSERT(!compiler
->labels
&& !compiler
->jumps
&& !compiler
->consts
);
3548 SLJIT_ASSERT(!compiler
->last_label
&& !compiler
->last_jump
&& !compiler
->last_const
);
3549 SLJIT_ASSERT(!compiler
->buf
->next
&& !compiler
->buf
->used_size
);
3550 SLJIT_ASSERT(!compiler
->abuf
->next
&& !compiler
->abuf
->used_size
);
3552 sljit_set_compiler_memory_error(compiler
);
3553 FAILED(sljit_get_compiler_error(compiler
) != -3967, "test39 case 1 failed\n");
3555 code
.code
= sljit_generate_code(compiler
);
3556 FAILED(sljit_get_compiler_error(compiler
) != -3967, "test39 case 2 failed\n");
3557 FAILED(!!code
.code
, "test39 case 3 failed\n");
3558 sljit_free_compiler(compiler
);
3560 compiler
= sljit_create_compiler(NULL
, NULL
);
3561 FAILED(!compiler
, "cannot create compiler\n");
3563 FAILED(sljit_get_compiler_error(compiler
) != SLJIT_SUCCESS
, "test39 case 4 failed\n");
3564 sljit_set_compiler_memory_error(compiler
);
3565 FAILED(sljit_get_compiler_error(compiler
) != SLJIT_ERR_ALLOC_FAILED
, "test39 case 5 failed\n");
3566 sljit_free_compiler(compiler
);
3571 static void test40(void)
3573 /* Test emit_op_flags. */
3574 executable_code code
;
3575 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3579 printf("Run test40\n");
3581 FAILED(!compiler
, "cannot create compiler\n");
3593 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 4, 0, 0, sizeof(sljit_sw
));
3595 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -5);
3596 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_UNUSED
, 0, SLJIT_IMM
, -6, SLJIT_R0
, 0);
3597 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x123456);
3598 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_SIG_LESS
);
3599 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
3601 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -13);
3602 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_IMM
, -13, SLJIT_R0
, 0);
3603 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 0);
3604 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_EQUAL
);
3605 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_NOT_EQUAL
);
3606 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);
3607 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_IMM
, -13, SLJIT_R0
, 0);
3608 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3609 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_EQUAL
);
3610 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_EQUAL
);
3612 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -13);
3613 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3);
3614 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
3615 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R1
), SLJIT_WORD_SHIFT
, SLJIT_SIG_LESS
);
3617 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -8);
3618 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 33);
3619 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
3620 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, 0);
3621 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_GREATER
);
3622 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_S1
, 0, SLJIT_EQUAL
);
3623 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
3624 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, 0x88);
3625 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_S3
, 0, SLJIT_NOT_EQUAL
);
3626 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_S1
, 0);
3627 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_S3
, 0);
3629 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x84);
3630 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_IMM
, 0x180, SLJIT_R0
, 0);
3631 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_EQUAL
);
3632 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_EQUAL
);
3634 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3635 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3636 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_NOT_EQUAL
);
3637 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_NOT_EQUAL
);
3639 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x123456);
3640 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3641 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_GREATER
);
3642 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_R0
, 0);
3644 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 0xbaddead);
3645 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0);
3647 code
.code
= sljit_generate_code(compiler
);
3649 sljit_free_compiler(compiler
);
3651 FAILED(code
.func1((sljit_sw
)&buf
) != 0xbaddead, "test40 case 1 failed\n");
3652 FAILED(buf
[0] != 0x123457, "test40 case 2 failed\n");
3653 FAILED(buf
[1] != 1, "test40 case 3 failed\n");
3654 FAILED(buf
[2] != 0, "test40 case 4 failed\n");
3655 FAILED(buf
[3] != -7, "test40 case 5 failed\n");
3656 FAILED(buf
[4] != 0, "test40 case 6 failed\n");
3657 FAILED(buf
[5] != 0x89, "test40 case 7 failed\n");
3658 FAILED(buf
[6] != 0, "test40 case 8 failed\n");
3659 FAILED(buf
[7] != 1, "test40 case 9 failed\n");
3660 FAILED(buf
[8] != 1, "test40 case 10 failed\n");
3661 FAILED(buf
[9] != 0x123457, "test40 case 11 failed\n");
3663 sljit_free_code(code
.code
, NULL
);
3667 static void test41(void)
3669 /* Test inline assembly. */
3670 executable_code code
;
3671 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3674 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3676 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3684 printf("Run test41\n");
3686 #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3687 SLJIT_ASSERT(sljit_has_cpu_feature(SLJIT_HAS_VIRTUAL_REGISTERS
) == 0);
3690 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
3691 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3692 if (SLJIT_R(i
) >= SLJIT_R3
&& SLJIT_R(i
) <= SLJIT_R8
) {
3693 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i
)) == -1);
3697 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i
)) >= 0 && sljit_get_register_index(SLJIT_R(i
)) < 64);
3700 FAILED(!compiler
, "cannot create compiler\n");
3701 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
), 3, 3, 0, 0, 0);
3703 /* Returns with the sum of SLJIT_S0 and SLJIT_S1. */
3704 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3705 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3708 inst
[2] = 0x04 | ((sljit_get_register_index(SLJIT_RETURN_REG
) & 0x7) << 3);
3709 inst
[3] = (sljit_get_register_index(SLJIT_S0
) & 0x7)
3710 | ((sljit_get_register_index(SLJIT_S1
) & 0x7) << 3);
3711 sljit_emit_op_custom(compiler
, inst
, 4);
3712 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3713 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3714 inst
[0] = 0x48; /* REX_W */
3717 reg
= sljit_get_register_index(SLJIT_RETURN_REG
);
3718 inst
[2] |= ((reg
& 0x7) << 3);
3720 inst
[0] |= 0x04; /* REX_R */
3721 reg
= sljit_get_register_index(SLJIT_S0
);
3722 inst
[3] = reg
& 0x7;
3724 inst
[0] |= 0x01; /* REX_B */
3725 reg
= sljit_get_register_index(SLJIT_S1
);
3726 inst
[3] |= (reg
& 0x7) << 3;
3728 inst
[0] |= 0x02; /* REX_X */
3729 sljit_emit_op_custom(compiler
, inst
, 4);
3730 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
3731 /* add rd, rn, rm */
3732 inst
= 0xe0800000 | (sljit_get_register_index(SLJIT_RETURN_REG
) << 12)
3733 | (sljit_get_register_index(SLJIT_S0
) << 16)
3734 | sljit_get_register_index(SLJIT_S1
);
3735 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3736 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
3737 /* add rd, rn, rm */
3738 inst
= 0xeb000000 | (sljit_get_register_index(SLJIT_RETURN_REG
) << 8)
3739 | (sljit_get_register_index(SLJIT_S0
) << 16)
3740 | sljit_get_register_index(SLJIT_S1
);
3741 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3742 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3743 /* add rd, rn, rm */
3744 inst
= 0x8b000000 | sljit_get_register_index(SLJIT_RETURN_REG
)
3745 | (sljit_get_register_index(SLJIT_S0
) << 5)
3746 | (sljit_get_register_index(SLJIT_S1
) << 16);
3747 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3748 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3749 /* add rD, rA, rB */
3750 inst
= (31 << 26) | (266 << 1) | (sljit_get_register_index(SLJIT_RETURN_REG
) << 21)
3751 | (sljit_get_register_index(SLJIT_S0
) << 16)
3752 | (sljit_get_register_index(SLJIT_S1
) << 11);
3753 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3754 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
3755 /* addu rd, rs, rt */
3756 inst
= 33 | (sljit_get_register_index(SLJIT_RETURN_REG
) << 11)
3757 | (sljit_get_register_index(SLJIT_S0
) << 21)
3758 | (sljit_get_register_index(SLJIT_S1
) << 16);
3759 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3760 #elif (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
3761 /* daddu rd, rs, rt */
3762 inst
= 45 | (sljit_get_register_index(SLJIT_RETURN_REG
) << 11)
3763 | (sljit_get_register_index(SLJIT_S0
) << 21)
3764 | (sljit_get_register_index(SLJIT_S1
) << 16);
3765 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3766 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3767 /* add rd, rs1, rs2 */
3768 inst
= (0x2 << 30) | (sljit_get_register_index(SLJIT_RETURN_REG
) << 25)
3769 | (sljit_get_register_index(SLJIT_S0
) << 14)
3770 | sljit_get_register_index(SLJIT_S1
);
3771 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3772 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
3773 /* agrk rd, rs1, rs2 */
3774 inst
= (0xb9e8 << 16)
3775 | (sljit_get_register_index(SLJIT_RETURN_REG
) << 4)
3776 | (sljit_get_register_index(SLJIT_S0
) << 12)
3777 | sljit_get_register_index(SLJIT_S1
);
3778 sljit_emit_op_custom(compiler
, &inst
, sizeof(inst
));
3781 sljit_emit_op_custom(compiler
, &inst
, 0);
3784 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
3786 code
.code
= sljit_generate_code(compiler
);
3788 sljit_free_compiler(compiler
);
3790 FAILED(code
.func2(32, -11) != 21, "test41 case 1 failed\n");
3791 FAILED(code
.func2(1000, 234) != 1234, "test41 case 2 failed\n");
3792 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3793 FAILED(code
.func2(SLJIT_W(0x20f0a04090c06070), SLJIT_W(0x020f0a04090c0607)) != SLJIT_W(0x22ffaa4499cc6677), "test41 case 3 failed\n");
3796 sljit_free_code(code
.code
, NULL
);
3798 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
3803 compiler
= sljit_create_compiler(NULL
, NULL
);
3804 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 0, 1, 2, 0, 0);
3805 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
3806 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
3807 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3812 inst
[3] = 0xc0 | (sljit_get_float_register_index(SLJIT_FR0
) << 3)
3813 | sljit_get_float_register_index(SLJIT_FR1
);
3814 sljit_emit_op_custom(compiler
, inst
, 4);
3815 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3817 if (sljit_get_float_register_index(SLJIT_FR0
) > 7 || sljit_get_float_register_index(SLJIT_FR1
) > 7) {
3819 if (sljit_get_float_register_index(SLJIT_FR0
) > 7)
3820 inst
[0] |= 0x04; /* REX_R */
3821 if (sljit_get_float_register_index(SLJIT_FR1
) > 7)
3822 inst
[0] |= 0x01; /* REX_B */
3826 inst
[4] = 0xc0 | ((sljit_get_float_register_index(SLJIT_FR0
) & 0x7) << 3)
3827 | (sljit_get_float_register_index(SLJIT_FR1
) & 0x7);
3828 sljit_emit_op_custom(compiler
, inst
, 5);
3834 inst
[3] = 0xc0 | (sljit_get_float_register_index(SLJIT_FR0
) << 3)
3835 | sljit_get_float_register_index(SLJIT_FR1
);
3836 sljit_emit_op_custom(compiler
, inst
, 4);
3838 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
3839 /* vadd.f64 dd, dn, dm */
3840 inst
= 0xee300b00 | ((sljit_get_float_register_index(SLJIT_FR0
) >> 1) << 12)
3841 | ((sljit_get_float_register_index(SLJIT_FR0
) >> 1) << 16)
3842 | (sljit_get_float_register_index(SLJIT_FR1
) >> 1);
3843 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3844 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3845 /* fadd rd, rn, rm */
3846 inst
= 0x1e602800 | sljit_get_float_register_index(SLJIT_FR0
)
3847 | (sljit_get_float_register_index(SLJIT_FR0
) << 5)
3848 | (sljit_get_float_register_index(SLJIT_FR1
) << 16);
3849 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3850 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3851 /* fadd frD, frA, frB */
3852 inst
= (63 << 26) | (21 << 1) | (sljit_get_float_register_index(SLJIT_FR0
) << 21)
3853 | (sljit_get_float_register_index(SLJIT_FR0
) << 16)
3854 | (sljit_get_float_register_index(SLJIT_FR1
) << 11);
3855 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3856 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
3857 /* add.d fd, fs, ft */
3858 inst
= (17 << 26) | (17 << 21) | (sljit_get_float_register_index(SLJIT_FR0
) << 6)
3859 | (sljit_get_float_register_index(SLJIT_FR0
) << 11)
3860 | (sljit_get_float_register_index(SLJIT_FR1
) << 16);
3861 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3862 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3863 /* faddd rd, rs1, rs2 */
3864 inst
= (0x2 << 30) | (0x34 << 19) | (0x42 << 5)
3865 | (sljit_get_float_register_index(SLJIT_FR0
) << 25)
3866 | (sljit_get_float_register_index(SLJIT_FR0
) << 14)
3867 | sljit_get_float_register_index(SLJIT_FR1
);
3868 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3870 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
3871 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
3873 code
.code
= sljit_generate_code(compiler
);
3875 sljit_free_compiler(compiler
);
3877 code
.func1((sljit_sw
)&buf
);
3878 FAILED(buf
[2] != 11.25, "test41 case 3 failed\n");
3880 sljit_free_code(code
.code
, NULL
);
3886 static void test42(void)
3888 /* Test long multiply and division. */
3889 executable_code code
;
3890 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3892 sljit_sw buf
[7 + 4 + 8 + 8];
3895 printf("Run test42\n");
3897 FAILED(!compiler
, "cannot create compiler\n");
3898 for (i
= 0; i
< 7 + 4 + 8 + 8; i
++)
3901 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 5, 5, 0, 0, 0);
3903 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -0x1fb308a);
3904 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0xf50c873);
3905 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, 0x8a0475b);
3906 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, 0x9dc849b);
3907 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -0x7c69a35);
3908 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, 0x5a4d0c4);
3909 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_IMM
, 0x9a3b06d);
3911 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3912 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3913 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3914 sljit_emit_op0(compiler
, SLJIT_LMUL_UW
);
3915 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3916 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3918 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3919 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3920 sljit_emit_op0(compiler
, SLJIT_LMUL_SW
);
3921 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3922 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3924 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3925 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3926 sljit_emit_op0(compiler
, SLJIT_DIVMOD_UW
);
3927 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3928 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3930 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3931 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3932 sljit_emit_op0(compiler
, SLJIT_DIVMOD_SW
);
3933 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3934 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3936 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x5cf783d3cf0a74b0));
3937 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3d5df42d03a28fc7));
3938 sljit_emit_op0(compiler
, SLJIT_DIVMOD_U32
);
3939 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3940 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3941 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3942 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3944 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x371df5197ba26a28));
3945 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x46c78a5cfd6a420c));
3946 sljit_emit_op0(compiler
, SLJIT_DIVMOD_S32
);
3947 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3948 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3949 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3950 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3952 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xc456f048c28a611b));
3953 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3d4af2c543));
3954 sljit_emit_op0(compiler
, SLJIT_DIV_UW
);
3955 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 19 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3956 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3958 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x720fa4b74c329b14));
3959 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0xa64ae42b7d6));
3960 sljit_emit_op0(compiler
, SLJIT_DIV_SW
);
3961 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 21 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3962 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3964 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x4af51c027b34));
3965 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x9ba4ff2906b14));
3966 sljit_emit_op0(compiler
, SLJIT_DIV_U32
);
3967 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3968 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3969 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 23 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3970 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 24 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3972 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xc40b58a3f20d));
3973 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(-0xa63c923));
3974 sljit_emit_op0(compiler
, SLJIT_DIV_S32
);
3975 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3976 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3977 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 25 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3978 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 26 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3981 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
3982 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
3983 sljit_emit_op0(compiler
, SLJIT_LMUL_UW
);
3984 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3985 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3987 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
3988 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
3989 sljit_emit_op0(compiler
, SLJIT_LMUL_SW
);
3990 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3991 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3993 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
3994 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
3995 sljit_emit_op0(compiler
, SLJIT_DIVMOD_UW
);
3996 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3997 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3999 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
4000 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
4001 sljit_emit_op0(compiler
, SLJIT_DIVMOD_SW
);
4002 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4003 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4005 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0xcf0a74b0);
4006 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0x03a28fc7);
4007 sljit_emit_op0(compiler
, SLJIT_DIVMOD_U32
);
4008 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4009 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4011 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x7ba26a28);
4012 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)0xfd6a420c);
4013 sljit_emit_op0(compiler
, SLJIT_DIVMOD_S32
);
4014 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4015 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4017 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x9d4b7036));
4018 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0xb86d0));
4019 sljit_emit_op0(compiler
, SLJIT_DIV_UW
);
4020 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 19 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4021 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4023 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x58b0692c));
4024 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0xd357));
4025 sljit_emit_op0(compiler
, SLJIT_DIV_SW
);
4026 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 21 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4027 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4029 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1c027b34));
4030 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0xf2906b14));
4031 sljit_emit_op0(compiler
, SLJIT_DIV_U32
);
4032 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4033 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
4034 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 23 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4035 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 24 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4037 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x58a3f20d));
4038 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(-0xa63c923));
4039 sljit_emit_op0(compiler
, SLJIT_DIV_S32
);
4040 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4041 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
4042 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 25 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4043 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 26 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4046 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R2
, 0);
4047 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R3
, 0);
4048 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R4
, 0);
4049 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_S1
, 0);
4050 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_S2
, 0);
4051 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_S3
, 0);
4052 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_S4
, 0);
4054 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
4056 code
.code
= sljit_generate_code(compiler
);
4058 sljit_free_compiler(compiler
);
4060 code
.func1((sljit_sw
)&buf
);
4062 FAILED(buf
[0] != -0x1fb308a, "test42 case 1 failed\n");
4063 FAILED(buf
[1] != 0xf50c873, "test42 case 2 failed\n");
4064 FAILED(buf
[2] != 0x8a0475b, "test42 case 3 failed\n");
4065 FAILED(buf
[3] != 0x9dc849b, "test42 case 4 failed\n");
4066 FAILED(buf
[4] != -0x7c69a35, "test42 case 5 failed\n");
4067 FAILED(buf
[5] != 0x5a4d0c4, "test42 case 6 failed\n");
4068 FAILED(buf
[6] != 0x9a3b06d, "test42 case 7 failed\n");
4070 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4071 FAILED(buf
[7] != SLJIT_W(-4388959407985636971), "test42 case 8 failed\n");
4072 FAILED(buf
[8] != SLJIT_W(2901680654366567099), "test42 case 9 failed\n");
4073 FAILED(buf
[9] != SLJIT_W(-4388959407985636971), "test42 case 10 failed\n");
4074 FAILED(buf
[10] != SLJIT_W(-1677173957268872740), "test42 case 11 failed\n");
4075 FAILED(buf
[11] != SLJIT_W(2), "test42 case 12 failed\n");
4076 FAILED(buf
[12] != SLJIT_W(2532236178951865933), "test42 case 13 failed\n");
4077 FAILED(buf
[13] != SLJIT_W(-1), "test42 case 14 failed\n");
4078 FAILED(buf
[14] != SLJIT_W(-2177944059851366166), "test42 case 15 failed\n");
4080 FAILED(buf
[7] != -1587000939, "test42 case 8 failed\n");
4081 FAILED(buf
[8] != 665003983, "test42 case 9 failed\n");
4082 FAILED(buf
[9] != -1587000939, "test42 case 10 failed\n");
4083 FAILED(buf
[10] != -353198352, "test42 case 11 failed\n");
4084 FAILED(buf
[11] != 2, "test42 case 12 failed\n");
4085 FAILED(buf
[12] != 768706125, "test42 case 13 failed\n");
4086 FAILED(buf
[13] != -1, "test42 case 14 failed\n");
4087 FAILED(buf
[14] != -471654166, "test42 case 15 failed\n");
4090 FAILED(buf
[15] != SLJIT_W(56), "test42 case 16 failed\n");
4091 FAILED(buf
[16] != SLJIT_W(58392872), "test42 case 17 failed\n");
4092 FAILED(buf
[17] != SLJIT_W(-47), "test42 case 18 failed\n");
4093 FAILED(buf
[18] != SLJIT_W(35949148), "test42 case 19 failed\n");
4095 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4096 FAILED(buf
[19] != SLJIT_W(0x3340bfc), "test42 case 20 failed\n");
4097 FAILED(buf
[20] != SLJIT_W(0x3d4af2c543), "test42 case 21 failed\n");
4098 FAILED(buf
[21] != SLJIT_W(-0xaf978), "test42 case 22 failed\n");
4099 FAILED(buf
[22] != SLJIT_W(0xa64ae42b7d6), "test42 case 23 failed\n");
4101 FAILED(buf
[19] != SLJIT_W(0xda5), "test42 case 20 failed\n");
4102 FAILED(buf
[20] != SLJIT_W(0xb86d0), "test42 case 21 failed\n");
4103 FAILED(buf
[21] != SLJIT_W(-0x6b6e), "test42 case 22 failed\n");
4104 FAILED(buf
[22] != SLJIT_W(0xd357), "test42 case 23 failed\n");
4107 FAILED(buf
[23] != SLJIT_W(0x0), "test42 case 24 failed\n");
4108 FAILED(buf
[24] != SLJIT_W(0xf2906b14), "test42 case 25 failed\n");
4109 FAILED(buf
[25] != SLJIT_W(-0x8), "test42 case 26 failed\n");
4110 FAILED(buf
[26] != SLJIT_W(-0xa63c923), "test42 case 27 failed\n");
4112 sljit_free_code(code
.code
, NULL
);
4116 static void test43(void)
4118 /* Test floating point compare. */
4119 executable_code code
;
4120 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4121 struct sljit_jump
* jump
;
4132 printf("Run test43\n");
4134 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4136 printf("no fpu available, test43 skipped\n");
4139 sljit_free_compiler(compiler
);
4143 FAILED(!compiler
, "cannot create compiler\n");
4145 dbuf
[0].value
= 12.125;
4147 dbuf
[1].u
.value1
= 0x7fffffff;
4148 dbuf
[1].u
.value2
= 0x7fffffff;
4149 dbuf
[2].value
= -13.5;
4150 dbuf
[3].value
= 12.125;
4152 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 1, 1, 3, 0, 0);
4153 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
4154 /* dbuf[0] < dbuf[2] -> -2 */
4155 jump
= sljit_emit_fcmp(compiler
, SLJIT_GREATER_EQUAL_F64
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), SLJIT_F64_SHIFT
);
4156 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, -2);
4158 sljit_set_label(jump
, sljit_emit_label(compiler
));
4159 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4160 /* dbuf[0] and dbuf[1] is not NaN -> 5 */
4161 jump
= sljit_emit_fcmp(compiler
, SLJIT_UNORDERED_F64
, SLJIT_MEM0(), (sljit_sw
)&dbuf
[1], SLJIT_FR1
, 0);
4162 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, 5);
4164 sljit_set_label(jump
, sljit_emit_label(compiler
));
4165 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
));
4166 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 11);
4167 /* dbuf[0] == dbuf[3] -> 11 */
4168 jump
= sljit_emit_fcmp(compiler
, SLJIT_EQUAL_F64
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_FR2
, 0);
4171 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, -17);
4172 sljit_set_label(jump
, sljit_emit_label(compiler
));
4173 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
4175 code
.code
= sljit_generate_code(compiler
);
4177 sljit_free_compiler(compiler
);
4179 FAILED(code
.func1((sljit_sw
)&dbuf
) != 11, "test43 case 1 failed\n");
4181 FAILED(code
.func1((sljit_sw
)&dbuf
) != -17, "test43 case 2 failed\n");
4183 FAILED(code
.func1((sljit_sw
)&dbuf
) != 5, "test43 case 3 failed\n");
4185 FAILED(code
.func1((sljit_sw
)&dbuf
) != -2, "test43 case 4 failed\n");
4187 sljit_free_code(code
.code
, NULL
);
4191 static void test44(void)
4194 executable_code code
;
4195 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4199 printf("Run test44\n");
4201 FAILED(!compiler
, "cannot create compiler\n");
4208 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 2, 0, 0, 0);
4210 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4211 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_p
), SLJIT_R0
, 0);
4212 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_p
));
4213 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 2);
4214 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R1
), SLJIT_POINTER_SHIFT
, SLJIT_R0
, 0);
4215 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_p
));
4216 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3 << SLJIT_POINTER_SHIFT
);
4217 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_S0
, 0);
4218 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM2(SLJIT_R2
, SLJIT_R1
), 0, SLJIT_R0
, 0);
4219 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 2 * sizeof(sljit_p
));
4220 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1 << SLJIT_POINTER_SHIFT
);
4221 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM2(SLJIT_R2
, SLJIT_R1
), 2, SLJIT_R0
, 0);
4223 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
4225 code
.code
= sljit_generate_code(compiler
);
4227 sljit_free_compiler(compiler
);
4229 FAILED(code
.func1((sljit_sw
)&buf
) != (sljit_sw
)(buf
+ 2), "test44 case 1 failed\n");
4230 FAILED(buf
[1] != buf
+ 2, "test44 case 2 failed\n");
4231 FAILED(buf
[2] != buf
+ 3, "test44 case 3 failed\n");
4232 FAILED(buf
[3] != buf
+ 4, "test44 case 4 failed\n");
4233 FAILED(buf
[4] != buf
+ 2, "test44 case 5 failed\n");
4235 sljit_free_code(code
.code
, NULL
);
4239 static void test45(void)
4241 /* Test single precision floating point. */
4243 executable_code code
;
4244 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4247 struct sljit_jump
* jump
;
4250 printf("Run test45\n");
4252 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4254 printf("no fpu available, test45 skipped\n");
4257 sljit_free_compiler(compiler
);
4261 FAILED(!compiler
, "cannot create compiler\n");
4283 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
), 3, 2, 6, 0, 0);
4285 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4286 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4287 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
4288 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_FR1
, 0, SLJIT_FR5
, 0);
4289 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f32
), SLJIT_FR1
, 0);
4290 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f32
), SLJIT_FR5
, 0);
4291 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_FR4
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4292 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f32
), SLJIT_FR4
, 0);
4294 sljit_emit_fop2(compiler
, SLJIT_ADD_F32
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4295 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
4296 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);
4297 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4298 sljit_emit_fop2(compiler
, SLJIT_MUL_F32
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_f32
), SLJIT_FR0
, 0, SLJIT_FR0
, 0);
4299 sljit_emit_fop2(compiler
, SLJIT_DIV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
4300 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f32
), SLJIT_FR2
, 0);
4301 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x3d0ac);
4302 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_R0
), 0x3d0ac);
4303 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x3d0ac + sizeof(sljit_f32
));
4304 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_R0
), -0x3d0ac);
4306 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4307 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4308 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4309 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_EQUAL_F32
);
4310 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_LESS_F
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4311 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
), SLJIT_LESS_F32
);
4312 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
4313 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
), SLJIT_EQUAL_F32
);
4314 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_GREATER_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
4315 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
), SLJIT_GREATER_EQUAL_F32
);
4317 jump
= sljit_emit_fcmp(compiler
, SLJIT_LESS_EQUAL_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4318 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, 7);
4319 sljit_set_label(jump
, sljit_emit_label(compiler
));
4321 jump
= sljit_emit_fcmp(compiler
, SLJIT_GREATER_F32
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_FR2
, 0);
4322 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_IMM
, 6);
4323 sljit_set_label(jump
, sljit_emit_label(compiler
));
4325 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
4327 code
.code
= sljit_generate_code(compiler
);
4329 sljit_free_compiler(compiler
);
4331 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&buf2
);
4332 FAILED(buf
[2] != -5.5, "test45 case 1 failed\n");
4333 FAILED(buf
[3] != 7.25, "test45 case 2 failed\n");
4334 FAILED(buf
[4] != 7.25, "test45 case 3 failed\n");
4335 FAILED(buf
[5] != -5.5, "test45 case 4 failed\n");
4336 FAILED(buf
[6] != -1.75, "test45 case 5 failed\n");
4337 FAILED(buf
[7] != 16.0, "test45 case 6 failed\n");
4338 FAILED(buf
[8] != 30.25, "test45 case 7 failed\n");
4339 FAILED(buf
[9] != 3, "test45 case 8 failed\n");
4340 FAILED(buf
[10] != -5.5, "test45 case 9 failed\n");
4341 FAILED(buf
[11] != 7.25, "test45 case 10 failed\n");
4342 FAILED(buf2
[0] != 1, "test45 case 11 failed\n");
4343 FAILED(buf2
[1] != 2, "test45 case 12 failed\n");
4344 FAILED(buf2
[2] != 2, "test45 case 13 failed\n");
4345 FAILED(buf2
[3] != 1, "test45 case 14 failed\n");
4346 FAILED(buf2
[4] != 7, "test45 case 15 failed\n");
4347 FAILED(buf2
[5] != -1, "test45 case 16 failed\n");
4349 sljit_free_code(code
.code
, NULL
);
4353 static void test46(void)
4355 /* Test sljit_emit_op_flags with 32 bit operations. */
4357 executable_code code
;
4358 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4364 printf("Run test46\n");
4366 for (i
= 0; i
< 24; ++i
)
4369 for (i
= 0; i
< 6; ++i
)
4373 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
), 3, 3, 0, 0, 0);
4375 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4376 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 13);
4377 sljit_emit_op_flags(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&buf
, SLJIT_LESS
);
4378 sljit_emit_op_flags(compiler
, SLJIT_AND32
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_s32
), SLJIT_NOT_ZERO
);
4380 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4381 sljit_emit_op_flags(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_s32
), SLJIT_EQUAL
);
4382 sljit_emit_op_flags(compiler
, SLJIT_AND32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_s32
), SLJIT_NOT_EQUAL
);
4383 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1235);
4384 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x1235);
4385 sljit_emit_op_flags(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_ZERO
);
4386 sljit_emit_op_flags(compiler
, SLJIT_AND32
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_s32
), SLJIT_ZERO
);
4387 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4389 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4390 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 12);
4391 sljit_emit_op_flags(compiler
, SLJIT_MOV32
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 2, SLJIT_EQUAL
);
4392 sljit_emit_op_flags(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_EQUAL
);
4393 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4394 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
4395 sljit_emit_op_flags(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 2, SLJIT_EQUAL
);
4396 sljit_emit_op_flags(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_s32
), SLJIT_NOT_EQUAL
);
4398 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4399 sljit_emit_op_flags(compiler
, SLJIT_XOR32
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_s32
), SLJIT_ZERO
);
4400 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 39);
4401 sljit_emit_op_flags(compiler
, SLJIT_XOR32
, SLJIT_R0
, 0, SLJIT_NOT_ZERO
);
4402 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4404 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4405 sljit_emit_op_flags(compiler
, SLJIT_AND
, SLJIT_MEM0(), (sljit_sw
)&buf2
, SLJIT_GREATER
);
4406 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 5);
4407 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
4408 sljit_emit_op_flags(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_SIG_LESS
);
4409 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
4410 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 5);
4411 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_LESS
);
4412 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_NOT_EQUAL
);
4413 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 5);
4414 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
), SLJIT_S2
, 0);
4415 sljit_emit_op_flags(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_SIG_LESS
);
4416 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_ZERO
);
4417 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 0);
4418 sljit_emit_op_flags(compiler
, SLJIT_XOR
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_GREATER
);
4420 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
4422 code
.code
= sljit_generate_code(compiler
);
4424 sljit_free_compiler(compiler
);
4426 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&buf2
);
4427 FAILED(buf
[0] != 0, "test46 case 1 failed\n");
4428 FAILED(buf
[1] != -17, "test46 case 2 failed\n");
4429 FAILED(buf
[2] != 1, "test46 case 3 failed\n");
4430 FAILED(buf
[3] != -17, "test46 case 4 failed\n");
4431 FAILED(buf
[4] != 1, "test46 case 5 failed\n");
4432 FAILED(buf
[5] != -17, "test46 case 6 failed\n");
4433 FAILED(buf
[6] != 1, "test46 case 7 failed\n");
4434 FAILED(buf
[7] != -17, "test46 case 8 failed\n");
4435 FAILED(buf
[8] != 0, "test46 case 9 failed\n");
4436 FAILED(buf
[9] != -17, "test46 case 10 failed\n");
4437 FAILED(buf
[10] != 1, "test46 case 11 failed\n");
4438 FAILED(buf
[11] != -17, "test46 case 12 failed\n");
4439 FAILED(buf
[12] != 1, "test46 case 13 failed\n");
4440 FAILED(buf
[13] != -17, "test46 case 14 failed\n");
4441 FAILED(buf
[14] != 1, "test46 case 15 failed\n");
4442 FAILED(buf
[15] != -17, "test46 case 16 failed\n");
4443 FAILED(buf
[16] != 0, "test46 case 17 failed\n");
4444 FAILED(buf
[17] != -17, "test46 case 18 failed\n");
4445 FAILED(buf
[18] != 0, "test46 case 19 failed\n");
4446 FAILED(buf
[19] != -17, "test46 case 20 failed\n");
4447 FAILED(buf
[20] != -18, "test46 case 21 failed\n");
4448 FAILED(buf
[21] != -17, "test46 case 22 failed\n");
4449 FAILED(buf
[22] != 38, "test46 case 23 failed\n");
4450 FAILED(buf
[23] != -17, "test46 case 24 failed\n");
4452 FAILED(buf2
[0] != 0, "test46 case 25 failed\n");
4453 FAILED(buf2
[1] != 1, "test46 case 26 failed\n");
4454 FAILED(buf2
[2] != 0, "test46 case 27 failed\n");
4455 FAILED(buf2
[3] != 1, "test46 case 28 failed\n");
4456 FAILED(buf2
[4] != -123, "test46 case 29 failed\n");
4457 FAILED(buf2
[5] != -14, "test46 case 30 failed\n");
4459 sljit_free_code(code
.code
, NULL
);
4463 static void test47(void)
4465 /* Test jump optimizations. */
4466 executable_code code
;
4467 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4471 printf("Run test47\n");
4473 FAILED(!compiler
, "cannot create compiler\n");
4478 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 1, 0, 0, 0);
4479 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x3a5c6f);
4480 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 3);
4481 sljit_set_target(sljit_emit_jump(compiler
, SLJIT_LESS
), 0x11223344);
4482 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
4483 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xd37c10);
4484 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4485 sljit_set_target(sljit_emit_jump(compiler
, SLJIT_LESS
), SLJIT_W(0x112233445566));
4487 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
4488 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x59b48e);
4489 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4490 sljit_set_target(sljit_emit_jump(compiler
, SLJIT_LESS
), SLJIT_W(0x1122334455667788));
4492 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4493 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
4495 code
.code
= sljit_generate_code(compiler
);
4497 sljit_free_compiler(compiler
);
4499 code
.func1((sljit_sw
)&buf
);
4500 FAILED(buf
[0] != 0x3a5c6f, "test47 case 1 failed\n");
4501 FAILED(buf
[1] != 0xd37c10, "test47 case 2 failed\n");
4502 FAILED(buf
[2] != 0x59b48e, "test47 case 3 failed\n");
4504 sljit_free_code(code
.code
, NULL
);
4508 static void test48(void)
4510 /* Test floating point conversions. */
4511 executable_code code
;
4512 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4520 printf("Run test48\n");
4522 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4524 printf("no fpu available, test48 skipped\n");
4527 sljit_free_compiler(compiler
);
4531 FAILED(!compiler
, "cannot create compiler\n");
4532 for (i
= 0; i
< 10; i
++) {
4551 sljit_emit_enter(compiler
, 0, 0, 3, 3, 6, 0, 0);
4552 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
4553 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, (sljit_sw
)&sbuf
);
4554 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
4555 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
4558 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_F64
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S0
), 0);
4559 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4560 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
4562 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_F64
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_F32_SHIFT
, SLJIT_FR5
, 0);
4563 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_F32
, SLJIT_FR4
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
4565 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
), SLJIT_FR4
, 0);
4566 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
4567 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_F32
, SLJIT_FR2
, 0, SLJIT_FR3
, 0);
4569 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
4571 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_f32
), SLJIT_FR3
, 0);
4574 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
4575 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
4576 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_R0
, 0, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), SLJIT_F64_SHIFT
);
4578 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4579 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
4581 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F32
, SLJIT_MEM1(SLJIT_S2
), 3 * sizeof(sljit_sw
), SLJIT_FR5
, 0);
4582 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_FR0
, 0, SLJIT_FR5
, 0);
4583 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 4);
4585 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F32
, SLJIT_MEM2(SLJIT_S2
, SLJIT_R1
), SLJIT_WORD_SHIFT
, SLJIT_FR0
, 0);
4586 sljit_emit_fop1(compiler
, SLJIT_NEG_F64
, SLJIT_FR4
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
));
4588 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F64
, SLJIT_MEM1(SLJIT_R2
), 2 * sizeof(sljit_s32
), SLJIT_FR4
, 0);
4589 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
4590 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F32
, SLJIT_R0
, 0, SLJIT_FR1
, 0);
4592 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_R2
), 3 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4595 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S2
), 0);
4596 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_FR2
, 0, SLJIT_IMM
, -6213);
4598 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
4600 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_f64
), SLJIT_MEM0(), (sljit_sw
)&ibuf
[0]);
4601 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R2
), sizeof(sljit_s32
));
4602 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_FR1
, 0, SLJIT_R0
, 0);
4604 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_f64
), SLJIT_FR1
, 0);
4606 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM0(), (sljit_sw
)(dbuf
+ 9), SLJIT_IMM
, -77);
4608 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_f32
), SLJIT_IMM
, -123);
4609 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 7190);
4610 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_FR3
, 0, SLJIT_R0
, 0);
4612 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 6 * sizeof(sljit_f32
), SLJIT_FR3
, 0);
4613 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 123);
4614 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 123 * sizeof(sljit_s32
));
4615 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_S32
, SLJIT_FR1
, 0, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 2);
4617 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 7 * sizeof(sljit_f32
), SLJIT_FR1
, 0);
4618 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
4619 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 3812);
4621 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_S32
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_F32_SHIFT
, SLJIT_R1
, 0);
4623 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_MEM0(), (sljit_sw
)(sbuf
+ 9), SLJIT_IMM
, -79);
4625 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
4627 code
.code
= sljit_generate_code(compiler
);
4629 sljit_free_compiler(compiler
);
4632 FAILED(dbuf
[3] != 476.25, "test48 case 1 failed\n");
4633 FAILED(dbuf
[4] != 476.25, "test48 case 2 failed\n");
4634 FAILED(dbuf
[5] != 2345.0, "test48 case 3 failed\n");
4635 FAILED(dbuf
[6] != -6213.0, "test48 case 4 failed\n");
4636 FAILED(dbuf
[7] != 312.0, "test48 case 5 failed\n");
4637 FAILED(dbuf
[8] != -9324.0, "test48 case 6 failed\n");
4638 FAILED(dbuf
[9] != -77.0, "test48 case 7 failed\n");
4640 FAILED(sbuf
[2] != 123.5, "test48 case 8 failed\n");
4641 FAILED(sbuf
[3] != 123.5, "test48 case 9 failed\n");
4642 FAILED(sbuf
[4] != 476.25, "test48 case 10 failed\n");
4643 FAILED(sbuf
[5] != -123, "test48 case 11 failed\n");
4644 FAILED(sbuf
[6] != 7190, "test48 case 12 failed\n");
4645 FAILED(sbuf
[7] != 312, "test48 case 13 failed\n");
4646 FAILED(sbuf
[8] != 3812, "test48 case 14 failed\n");
4647 FAILED(sbuf
[9] != -79.0, "test48 case 15 failed\n");
4649 FAILED(wbuf
[1] != -367, "test48 case 16 failed\n");
4650 FAILED(wbuf
[2] != 917, "test48 case 17 failed\n");
4651 FAILED(wbuf
[3] != 476, "test48 case 18 failed\n");
4652 FAILED(wbuf
[4] != -476, "test48 case 19 failed\n");
4654 FAILED(ibuf
[2] != -917, "test48 case 20 failed\n");
4655 FAILED(ibuf
[3] != -1689, "test48 case 21 failed\n");
4657 sljit_free_code(code
.code
, NULL
);
4661 static void test49(void)
4663 /* Test floating point conversions. */
4664 executable_code code
;
4665 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4671 sljit_s32
* dbuf_ptr
= (sljit_s32
*)dbuf
;
4672 sljit_s32
* sbuf_ptr
= (sljit_s32
*)sbuf
;
4675 printf("Run test49\n");
4677 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4679 printf("no fpu available, test49 skipped\n");
4682 sljit_free_compiler(compiler
);
4686 FAILED(!compiler
, "cannot create compiler\n");
4688 for (i
= 0; i
< 9; i
++) {
4689 dbuf_ptr
[i
<< 1] = -1;
4690 dbuf_ptr
[(i
<< 1) + 1] = -1;
4696 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4697 dbuf
[9] = (sljit_f64
)SLJIT_W(0x1122334455);
4704 sljit_emit_enter(compiler
, 0, 0, 3, 3, 3, 0, 0);
4705 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
4706 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, (sljit_sw
)&sbuf
);
4707 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
4708 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
4711 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_F32
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S1
), 0);
4713 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_F64
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S0
), 0);
4715 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 0);
4717 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F32
, SLJIT_MEM1(SLJIT_S2
), 4 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S1
), 0);
4719 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F64
, SLJIT_MEM1(SLJIT_R2
), 2 * sizeof(sljit_s32
), SLJIT_MEM1(SLJIT_S0
), 0);
4721 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F32
, SLJIT_MEM1(SLJIT_R2
), 4 * sizeof(sljit_s32
), SLJIT_MEM1(SLJIT_S1
), 0);
4723 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S2
), 0);
4725 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S2
), 0);
4727 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_R2
), 0);
4729 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_S32
, SLJIT_MEM1(SLJIT_S1
), 6 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_R2
), 0);
4731 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4732 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f64
));
4734 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), 8 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4735 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f64
));
4736 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F64
, SLJIT_R0
, 0, SLJIT_FR2
, 0);
4737 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4738 sljit_emit_op2(compiler
, SLJIT_AND32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffff);
4740 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R2
), 8 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4741 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x4455667788));
4743 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_f64
), SLJIT_R0
, 0);
4745 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f64
), SLJIT_IMM
, SLJIT_W(0x7766554433));
4748 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
4750 code
.code
= sljit_generate_code(compiler
);
4752 sljit_free_compiler(compiler
);
4756 FAILED(dbuf_ptr
[(1 * 2) + 0] != -1, "test49 case 1 failed\n");
4757 FAILED(dbuf_ptr
[(1 * 2) + 1] != -1, "test49 case 2 failed\n");
4758 FAILED(dbuf
[2] != -879.75, "test49 case 3 failed\n");
4759 FAILED(dbuf_ptr
[(3 * 2) + 0] != -1, "test49 case 4 failed\n");
4760 FAILED(dbuf_ptr
[(3 * 2) + 1] != -1, "test49 case 5 failed\n");
4761 FAILED(dbuf
[4] != 345, "test49 case 6 failed\n");
4762 FAILED(dbuf_ptr
[(5 * 2) + 0] != -1, "test49 case 7 failed\n");
4763 FAILED(dbuf_ptr
[(5 * 2) + 1] != -1, "test49 case 8 failed\n");
4764 FAILED(dbuf
[6] != -249, "test49 case 9 failed\n");
4765 FAILED(dbuf_ptr
[(7 * 2) + 0] != -1, "test49 case 10 failed\n");
4766 FAILED(dbuf_ptr
[(7 * 2) + 1] != -1, "test49 case 11 failed\n");
4768 FAILED(sbuf_ptr
[1] != -1, "test49 case 12 failed\n");
4769 FAILED(sbuf
[2] != 673.75, "test49 case 13 failed\n");
4770 FAILED(sbuf_ptr
[3] != -1, "test49 case 14 failed\n");
4771 FAILED(sbuf
[4] != 345, "test49 case 15 failed\n");
4772 FAILED(sbuf_ptr
[5] != -1, "test49 case 16 failed\n");
4773 FAILED(sbuf
[6] != -249, "test49 case 17 failed\n");
4774 FAILED(sbuf_ptr
[7] != -1, "test49 case 18 failed\n");
4776 FAILED(wbuf
[1] != -1, "test49 case 19 failed\n");
4777 FAILED(wbuf
[2] != 673, "test49 case 20 failed\n");
4778 FAILED(wbuf
[3] != -1, "test49 case 21 failed\n");
4779 FAILED(wbuf
[4] != -879, "test49 case 22 failed\n");
4780 FAILED(wbuf
[5] != -1, "test49 case 23 failed\n");
4782 FAILED(ibuf
[1] != -1, "test49 case 24 failed\n");
4783 FAILED(ibuf
[2] != 673, "test49 case 25 failed\n");
4784 FAILED(ibuf
[3] != -1, "test49 case 26 failed\n");
4785 FAILED(ibuf
[4] != -879, "test49 case 27 failed\n");
4786 FAILED(ibuf
[5] != -1, "test49 case 28 failed\n");
4788 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4789 FAILED(dbuf
[8] != (sljit_f64
)SLJIT_W(0x4455667788), "test49 case 29 failed\n");
4790 FAILED(dbuf
[9] != (sljit_f64
)SLJIT_W(0x66554433), "test49 case 30 failed\n");
4791 FAILED(wbuf
[8] != SLJIT_W(0x1122334455), "test48 case 31 failed\n");
4792 FAILED(ibuf
[8] == 0x4455, "test48 case 32 failed\n");
4795 sljit_free_code(code
.code
, NULL
);
4799 static void test50(void)
4801 /* Test stack and floating point operations. */
4802 executable_code code
;
4803 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4804 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4805 sljit_uw size1
, size2
, size3
;
4811 printf("Run test50\n");
4813 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4815 printf("no fpu available, test50 skipped\n");
4818 sljit_free_compiler(compiler
);
4822 FAILED(!compiler
, "cannot create compiler\n");
4828 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 3, 6, 0, 8 * sizeof(sljit_f32
));
4830 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
4831 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), 0);
4833 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_f32
));
4834 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4835 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
));
4837 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), 2 * sizeof(sljit_f32
));
4838 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 2 * sizeof(sljit_f32
), SLJIT_IMM
, 5934);
4839 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
));
4841 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), 3 * sizeof(sljit_f32
));
4843 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4844 size1
= compiler
->size
;
4846 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f32
));
4847 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4848 size2
= compiler
->size
;
4850 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR5
, 0, SLJIT_FR2
, 0);
4851 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4852 size3
= compiler
->size
;
4855 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f32
), SLJIT_FR5
, 0);
4856 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4857 result
= (compiler
->size
- size3
) == (size3
- size2
) && (size3
- size2
) == (size2
- size1
);
4860 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
4862 code
.code
= sljit_generate_code(compiler
);
4864 sljit_free_compiler(compiler
);
4866 code
.func1((sljit_sw
)&sbuf
);
4868 FAILED(sbuf
[3] != 245.5, "test50 case 1 failed\n");
4869 FAILED(sbuf
[4] != 145.25, "test50 case 2 failed\n");
4870 FAILED(sbuf
[5] != 5934, "test50 case 3 failed\n");
4871 FAILED(sbuf
[6] != 713.75, "test50 case 4 failed\n");
4872 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4873 FAILED(!result
, "test50 case 5 failed\n");
4876 sljit_free_code(code
.code
, NULL
);
4880 static void test51(void)
4882 /* Test all registers provided by the CPU. */
4883 executable_code code
;
4884 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4885 struct sljit_jump
* jump
;
4890 printf("Run test51\n");
4892 FAILED(!compiler
, "cannot create compiler\n");
4896 sljit_emit_enter(compiler
, 0, 0, SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0, 0);
4898 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4899 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 32);
4901 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)buf
);
4902 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 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_R0
, 0);
4907 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_R(i
)), 0);
4909 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, buf
[0]);
4912 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 32);
4913 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
4914 if (sljit_get_register_index(SLJIT_R(i
)) >= 0) {
4915 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_R0
, 0);
4916 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_R(i
)), 32);
4918 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, buf
[0]);
4921 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
4922 if (sljit_get_register_index(SLJIT_R(i
)) >= 0) {
4923 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 32);
4924 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM2(SLJIT_R(i
), SLJIT_R0
), 0);
4925 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_R(i
)), 0);
4926 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 8);
4927 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_R(i
)), 2);
4929 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 3 * buf
[0]);
4932 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 32 + sizeof(sljit_sw
), SLJIT_R1
, 0);
4934 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
4936 code
.code
= sljit_generate_code(compiler
);
4938 sljit_free_compiler(compiler
);
4942 FAILED(buf
[1] != (39 * 5 * (SLJIT_NUMBER_OF_REGISTERS
- 2)), "test51 case 1 failed\n");
4944 sljit_free_code(code
.code
, NULL
);
4948 compiler
= sljit_create_compiler(NULL
, NULL
);
4950 FAILED(!compiler
, "cannot create compiler\n");
4952 sljit_emit_enter(compiler
, 0, 0, SLJIT_NUMBER_OF_SCRATCH_REGISTERS
, SLJIT_NUMBER_OF_SAVED_REGISTERS
, 0, 0, 0);
4954 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4955 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 17);
4957 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_RET(SW
));
4958 /* SLJIT_R0 contains the first value. */
4959 for (i
= 1; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4960 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
4962 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
4964 sljit_set_label(jump
, sljit_emit_label(compiler
));
4965 sljit_emit_enter(compiler
, 0, 0, SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0, 0);
4966 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4967 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 35);
4968 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
4970 code
.code
= sljit_generate_code(compiler
);
4972 sljit_free_compiler(compiler
);
4974 FAILED(code
.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS
* 35 + SLJIT_NUMBER_OF_SAVED_REGISTERS
* 17), "test51 case 2 failed\n");
4976 sljit_free_code(code
.code
, NULL
);
4980 compiler
= sljit_create_compiler(NULL
, NULL
);
4982 FAILED(!compiler
, "cannot create compiler\n");
4984 sljit_emit_enter(compiler
, 0, 0, SLJIT_NUMBER_OF_SCRATCH_REGISTERS
, SLJIT_NUMBER_OF_SAVED_REGISTERS
, 0, 0, 0);
4986 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4987 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 68);
4989 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_RET(SW
));
4990 /* SLJIT_R0 contains the first value. */
4991 for (i
= 1; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4992 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
4994 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
4996 sljit_set_label(jump
, sljit_emit_label(compiler
));
4997 sljit_emit_enter(compiler
, 0, 0, 0, SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0);
4998 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4999 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S(i
), 0, SLJIT_IMM
, 43);
5000 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5002 code
.code
= sljit_generate_code(compiler
);
5004 sljit_free_compiler(compiler
);
5006 FAILED(code
.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS
* 43 + SLJIT_NUMBER_OF_SAVED_REGISTERS
* 68), "test51 case 3 failed\n");
5008 sljit_free_code(code
.code
, NULL
);
5012 static void test52(void)
5014 /* Test all registers provided by the CPU. */
5015 executable_code code
;
5016 struct sljit_compiler
* compiler
;
5017 struct sljit_jump
* jump
;
5022 printf("Run test52\n");
5024 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5026 printf("no fpu available, test52 skipped\n");
5033 compiler
= sljit_create_compiler(NULL
, NULL
);
5034 FAILED(!compiler
, "cannot create compiler\n");
5038 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
, 0);
5040 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5041 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
5043 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_RET(VOID
));
5044 /* SLJIT_FR0 contains the first value. */
5045 for (i
= 1; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5046 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_FR(i
), 0);
5047 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5049 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5051 sljit_set_label(jump
, sljit_emit_label(compiler
));
5052 sljit_emit_enter(compiler
, 0, 0, 1, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0, 0);
5053 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[1]);
5054 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5055 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_MEM1(SLJIT_R0
), 0);
5056 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5058 code
.code
= sljit_generate_code(compiler
);
5060 sljit_free_compiler(compiler
);
5062 code
.func1((sljit_sw
)&buf
);
5063 FAILED(buf
[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
* 17.75 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
* 6.25), "test52 case 1 failed\n");
5065 sljit_free_code(code
.code
, NULL
);
5069 compiler
= sljit_create_compiler(NULL
, NULL
);
5070 FAILED(!compiler
, "cannot create compiler\n");
5074 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
, 0);
5076 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5077 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
5079 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_RET(VOID
));
5080 /* SLJIT_FR0 contains the first value. */
5081 for (i
= 1; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5082 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_FR(i
), 0);
5083 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5085 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5087 sljit_set_label(jump
, sljit_emit_label(compiler
));
5088 sljit_emit_enter(compiler
, 0, 0, 1, 0, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0);
5089 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[1]);
5090 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5091 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FS(i
), 0, SLJIT_MEM1(SLJIT_R0
), 0);
5092 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5094 code
.code
= sljit_generate_code(compiler
);
5096 sljit_free_compiler(compiler
);
5098 code
.func1((sljit_sw
)&buf
);
5099 FAILED(buf
[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
* -11.25 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
* -32.5), "test52 case 2 failed\n");
5101 sljit_free_code(code
.code
, NULL
);
5105 static void test53(void)
5107 /* Check SLJIT_DOUBLE_ALIGNMENT. */
5108 executable_code code
;
5109 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5113 printf("Run test53\n");
5115 FAILED(!compiler
, "cannot create compiler\n");
5118 sljit_emit_enter(compiler
, SLJIT_F64_ALIGNMENT
, SLJIT_ARG1(SW
), 1, 1, 0, 0, 2 * sizeof(sljit_sw
));
5120 sljit_get_local_base(compiler
, SLJIT_R0
, 0, 0);
5121 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
5123 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5125 code
.code
= sljit_generate_code(compiler
);
5127 sljit_free_compiler(compiler
);
5129 code
.func1((sljit_sw
)&buf
);
5131 FAILED((buf
[0] & (sizeof(sljit_f64
) - 1)) != 0, "test53 case 1 failed\n");
5133 sljit_free_code(code
.code
, NULL
);
5137 compiler
= sljit_create_compiler(NULL
, NULL
);
5138 FAILED(!compiler
, "cannot create compiler\n");
5141 /* One more saved register to break the alignment on x86-32. */
5142 sljit_emit_enter(compiler
, SLJIT_F64_ALIGNMENT
, SLJIT_ARG1(SW
), 1, 2, 0, 0, 2 * sizeof(sljit_sw
));
5144 sljit_get_local_base(compiler
, SLJIT_R0
, 0, 0);
5145 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
5147 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5149 code
.code
= sljit_generate_code(compiler
);
5151 sljit_free_compiler(compiler
);
5153 code
.func1((sljit_sw
)&buf
);
5155 FAILED((buf
[0] & (sizeof(sljit_f64
) - 1)) != 0, "test53 case 2 failed\n");
5157 sljit_free_code(code
.code
, NULL
);
5161 static void test54(void)
5164 executable_code code
;
5165 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5166 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
5167 sljit_sw large_num
= SLJIT_W(0x1234567812345678);
5169 sljit_sw large_num
= SLJIT_W(0x12345678);
5177 sljit_s32 s32_value
;
5180 sbuf
[0].s32_value
= 0x7fffffff;
5181 sbuf
[1].value
= 7.5;
5182 sbuf
[2].value
= -14.75;
5185 printf("Run test54\n");
5187 FAILED(!compiler
, "cannot create compiler\n");
5189 for (i
= 0; i
< 19; i
++)
5191 for (i
= 0; i
< 4; i
++)
5194 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
), 5, 3, 3, 0, 0);
5196 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 17);
5197 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 34);
5198 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -10);
5199 sljit_emit_cmov(compiler
, SLJIT_SIG_LESS
, SLJIT_R0
, SLJIT_R1
, 0);
5200 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
5201 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -10);
5202 sljit_emit_cmov(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, SLJIT_R1
, 0);
5203 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
5205 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 24);
5206 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 24);
5207 sljit_emit_cmov(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, SLJIT_IMM
, 66);
5208 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5209 sljit_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R0
, SLJIT_IMM
, 78);
5210 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5211 sljit_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R0
, SLJIT_IMM
, large_num
);
5212 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5214 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
5215 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R3
) == -1 && sljit_get_register_index(SLJIT_R4
) == -1);
5217 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 7);
5218 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -45);
5219 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5220 sljit_emit_cmov(compiler
, SLJIT_OVERFLOW
, SLJIT_R3
, SLJIT_IMM
, 35);
5221 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5222 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, large_num
);
5223 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, large_num
);
5224 sljit_emit_cmov(compiler
, SLJIT_OVERFLOW
, SLJIT_R3
, SLJIT_IMM
, 35);
5225 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5227 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 71);
5228 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 13);
5229 sljit_emit_op2(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5230 sljit_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R3
, SLJIT_R0
, 0);
5231 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5233 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 12);
5234 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -29);
5235 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5236 sljit_emit_cmov(compiler
, SLJIT_NOT_OVERFLOW
, SLJIT_R0
, SLJIT_R3
, 0);
5237 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5239 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
5240 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -12);
5241 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, 21);
5242 sljit_emit_op2(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5243 sljit_emit_cmov(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R3
, SLJIT_R4
, 0);
5244 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5245 sljit_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R3
, SLJIT_R4
, 0);
5246 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5248 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5249 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S2
), 0);
5250 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
5251 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_f32
));
5253 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
5254 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5255 sljit_emit_cmov(compiler
, SLJIT_EQUAL_F32
, SLJIT_R0
, SLJIT_IMM
, -45);
5256 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5257 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_GREATER_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5258 sljit_emit_cmov(compiler
, SLJIT_GREATER_F32
, SLJIT_R0
, SLJIT_IMM
, -45);
5259 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5260 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_GREATER_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5261 sljit_emit_cmov(compiler
, SLJIT_GREATER_EQUAL_F32
, SLJIT_R0
, SLJIT_IMM
, 33);
5262 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5264 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5265 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_LESS_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5266 sljit_emit_cmov(compiler
, SLJIT_LESS_F32
, SLJIT_R0
, SLJIT_IMM
, -70);
5267 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5268 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_LESS_EQUAL_F
, SLJIT_FR2
, 0, SLJIT_FR1
, 0);
5269 sljit_emit_cmov(compiler
, SLJIT_LESS_EQUAL_F32
, SLJIT_R0
, SLJIT_IMM
, -60);
5270 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5271 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_NOT_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5272 sljit_emit_cmov(compiler
, SLJIT_NOT_EQUAL_F32
, SLJIT_R0
, SLJIT_IMM
, 31);
5273 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5275 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 53);
5276 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_ORDERED_F
, SLJIT_FR1
, 0, SLJIT_FR0
, 0);
5277 sljit_emit_cmov(compiler
, SLJIT_ORDERED_F32
, SLJIT_R0
, SLJIT_IMM
, 17);
5278 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5279 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_UNORDERED_F
, SLJIT_FR1
, 0, SLJIT_FR0
, 0);
5280 sljit_emit_cmov(compiler
, SLJIT_UNORDERED_F32
, SLJIT_R0
, SLJIT_IMM
, 59);
5281 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5284 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 177);
5285 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 178);
5286 sljit_emit_cmov(compiler
, SLJIT_LESS
, SLJIT_R0
| SLJIT_I32_OP
, SLJIT_IMM
, 200);
5287 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_R0
, 0);
5289 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 95);
5290 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R3
, 0, SLJIT_IMM
, 177);
5291 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS_EQUAL
, SLJIT_UNUSED
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 95);
5292 sljit_emit_cmov(compiler
, SLJIT_LESS_EQUAL
, SLJIT_R3
| SLJIT_I32_OP
, SLJIT_R0
, 0);
5293 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5294 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
), SLJIT_R3
, 0);
5296 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R3
, 0, SLJIT_IMM
, 56);
5297 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R4
, 0, SLJIT_IMM
, -63);
5298 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_SIG_LESS
, SLJIT_UNUSED
, 0, SLJIT_R3
, 0, SLJIT_R4
, 0);
5299 sljit_emit_cmov(compiler
, SLJIT_SIG_LESS
, SLJIT_R3
| SLJIT_I32_OP
, SLJIT_R4
, 0);
5300 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_s32
), SLJIT_R3
, 0);
5301 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_SIG_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R3
, 0, SLJIT_R4
, 0);
5302 sljit_emit_cmov(compiler
, SLJIT_SIG_GREATER
, SLJIT_R3
| SLJIT_I32_OP
, SLJIT_R4
, 0);
5303 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_s32
), SLJIT_R3
, 0);
5305 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5307 code
.code
= sljit_generate_code(compiler
);
5309 sljit_free_compiler(compiler
);
5311 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&ibuf
, (sljit_sw
)&sbuf
);
5313 FAILED(buf
[0] != 17, "test54 case 1 failed\n");
5314 FAILED(buf
[1] != 34, "test54 case 2 failed\n");
5315 FAILED(buf
[2] != 24, "test54 case 3 failed\n");
5316 FAILED(buf
[3] != 78, "test54 case 4 failed\n");
5317 FAILED(buf
[4] != large_num
, "test54 case 5 failed\n");
5318 FAILED(buf
[5] != -45, "test54 case 6 failed\n");
5319 FAILED(buf
[6] != 35, "test54 case 7 failed\n");
5320 FAILED(buf
[7] != 71, "test54 case 8 failed\n");
5321 FAILED(buf
[8] != -29, "test54 case 9 failed\n");
5322 FAILED(buf
[9] != -12, "test54 case 10 failed\n");
5323 FAILED(buf
[10] != 21, "test54 case 11 failed\n");
5325 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5326 FAILED(buf
[11] != 16, "test54 case 12 failed\n");
5327 FAILED(buf
[12] != -45, "test54 case 13 failed\n");
5328 FAILED(buf
[13] != 33, "test54 case 14 failed\n");
5329 FAILED(buf
[14] != 8, "test54 case 15 failed\n");
5330 FAILED(buf
[15] != -60, "test54 case 16 failed\n");
5331 FAILED(buf
[16] != 31, "test54 case 17 failed\n");
5332 FAILED(buf
[17] != 53, "test54 case 18 failed\n");
5333 FAILED(buf
[18] != 59, "test54 case 19 failed\n");
5336 FAILED(ibuf
[0] != 200, "test54 case 12 failed\n");
5337 FAILED(ibuf
[1] != 95, "test54 case 13 failed\n");
5338 FAILED(ibuf
[2] != 56, "test54 case 14 failed\n");
5339 FAILED(ibuf
[3] != -63, "test54 case 15 failed\n");
5341 sljit_free_code(code
.code
, NULL
);
5345 static void test55(void)
5347 /* Check value preservation. */
5348 executable_code code
;
5349 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5354 printf("Run test55\n");
5356 FAILED(!compiler
, "cannot create compiler\n");
5360 sljit_emit_enter(compiler
, 0, 0, SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0, sizeof (sljit_sw
));
5362 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 217);
5365 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5366 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 118);
5368 sljit_emit_op0(compiler
, SLJIT_DIVMOD_SW
);
5370 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5372 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5373 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
5374 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_SP
), 0);
5376 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)(buf
+ 0), SLJIT_R0
, 0);
5379 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5380 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 146);
5382 sljit_emit_op0(compiler
, SLJIT_DIV_SW
);
5384 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5386 for (i
= 1; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5387 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
5388 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_SP
), 0);
5390 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)(buf
+ 1), SLJIT_R0
, 0);
5392 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5394 code
.code
= sljit_generate_code(compiler
);
5396 sljit_free_compiler(compiler
);
5400 FAILED(buf
[0] != (SLJIT_NUMBER_OF_REGISTERS
- 2) * 118 + 217, "test55 case 1 failed\n");
5401 FAILED(buf
[1] != (SLJIT_NUMBER_OF_REGISTERS
- 1) * 146 + 217, "test55 case 2 failed\n");
5403 sljit_free_code(code
.code
, NULL
);
5407 static void test56(void)
5409 /* Check integer substraction with negative immediate. */
5410 executable_code code
;
5411 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5416 printf("Run test56\n");
5418 for (i
= 0; i
< 13; i
++)
5421 FAILED(!compiler
, "cannot create compiler\n");
5423 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 1, 0, 0, 0);
5425 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 90 << 12);
5426 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5427 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
5428 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_SIG_GREATER
);
5429 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5430 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5431 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_LESS
);
5432 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5433 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_SIG_GREATER_EQUAL
);
5434 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5435 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_LESS_EQUAL
);
5436 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5437 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_GREATER
);
5438 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5439 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_SIG_LESS
);
5441 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 90);
5442 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -91);
5443 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5444 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_SIG_GREATER
);
5445 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 90);
5446 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -91);
5447 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_LESS_EQUAL
);
5449 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, -0x7fffffff);
5450 sljit_emit_op2(compiler
, SLJIT_ADD32
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5451 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
5453 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, -0x7fffffff-1);
5454 sljit_emit_op1(compiler
, SLJIT_NEG32
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R0
, 0);
5455 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
5457 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5459 code
.code
= sljit_generate_code(compiler
);
5461 sljit_free_compiler(compiler
);
5463 code
.func1((sljit_sw
)&buf
);
5465 FAILED(buf
[0] != (181 << 12), "test56 case 1 failed\n");
5466 FAILED(buf
[1] != 1, "test56 case 2 failed\n");
5467 FAILED(buf
[2] != (181 << 12), "test56 case 3 failed\n");
5468 FAILED(buf
[3] != 1, "test56 case 4 failed\n");
5469 FAILED(buf
[4] != 1, "test56 case 5 failed\n");
5470 FAILED(buf
[5] != 1, "test56 case 6 failed\n");
5471 FAILED(buf
[6] != 0, "test56 case 7 failed\n");
5472 FAILED(buf
[7] != 0, "test56 case 8 failed\n");
5473 FAILED(buf
[8] != 181, "test56 case 9 failed\n");
5474 FAILED(buf
[9] != 1, "test56 case 10 failed\n");
5475 FAILED(buf
[10] != 1, "test56 case 11 failed\n");
5476 FAILED(buf
[11] != 1, "test56 case 12 failed\n");
5477 FAILED(buf
[12] != 1, "test56 case 13 failed\n");
5479 sljit_free_code(code
.code
, NULL
);
5483 static void test57(void)
5485 /* Check prefetch instructions. */
5486 executable_code code
;
5487 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5488 struct sljit_label
* labels
[5];
5493 printf("Run test57\n");
5495 FAILED(!compiler
, "cannot create compiler\n");
5497 sljit_emit_enter(compiler
, 0, 0, 3, 1, 0, 0, 0);
5499 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5500 labels
[0] = sljit_emit_label(compiler
);
5501 /* Should never crash. */
5502 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_L1
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R0
), 2);
5503 labels
[1] = sljit_emit_label(compiler
);
5504 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_L2
, SLJIT_MEM0(), 0);
5505 labels
[2] = sljit_emit_label(compiler
);
5506 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
5507 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_L3
, SLJIT_MEM1(SLJIT_R0
), SLJIT_W(0x1122334455667788));
5509 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_L3
, SLJIT_MEM1(SLJIT_R0
), 0x11223344);
5511 labels
[3] = sljit_emit_label(compiler
);
5512 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_ONCE
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
));
5513 labels
[4] = sljit_emit_label(compiler
);
5515 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5517 code
.code
= sljit_generate_code(compiler
);
5520 for (i
= 0; i
< 5; i
++)
5521 addr
[i
] = sljit_get_label_addr(labels
[i
]);
5523 sljit_free_compiler(compiler
);
5527 if (sljit_has_cpu_feature(SLJIT_HAS_PREFETCH
)) {
5528 FAILED(addr
[0] == addr
[1], "test57 case 1 failed\n");
5529 FAILED(addr
[1] == addr
[2], "test57 case 2 failed\n");
5530 FAILED(addr
[2] == addr
[3], "test57 case 3 failed\n");
5531 FAILED(addr
[3] == addr
[4], "test57 case 4 failed\n");
5534 FAILED(addr
[0] != addr
[1], "test57 case 1 failed\n");
5535 FAILED(addr
[1] != addr
[2], "test57 case 2 failed\n");
5536 FAILED(addr
[2] != addr
[3], "test57 case 3 failed\n");
5537 FAILED(addr
[3] != addr
[4], "test57 case 4 failed\n");
5540 sljit_free_code(code
.code
, NULL
);
5544 static sljit_f64 SLJIT_FUNC
test58_f1(sljit_f32 a
, sljit_f32 b
, sljit_f64 c
)
5549 static sljit_f32 SLJIT_FUNC
test58_f2(sljit_sw a
, sljit_f64 b
, sljit_f32 c
)
5554 static sljit_f64 SLJIT_FUNC
test58_f3(sljit_sw a
, sljit_f32 b
, sljit_sw c
)
5559 static sljit_f64
test58_f4(sljit_f32 a
, sljit_sw b
)
5564 static sljit_f32
test58_f5(sljit_f32 a
, sljit_f64 b
, sljit_s32 c
)
5569 static sljit_sw SLJIT_FUNC
test58_f6(sljit_f64 a
, sljit_sw b
)
5571 return (sljit_sw
)a
+ b
;
5574 static void test58(void)
5576 /* Check function calls with floating point arguments. */
5577 executable_code code
;
5578 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5579 struct sljit_jump
* jump
= NULL
;
5585 printf("Run test58\n");
5587 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5589 printf("no fpu available, test58 skipped\n");
5592 sljit_free_compiler(compiler
);
5613 FAILED(!compiler
, "cannot create compiler\n");
5615 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
), 3, 3, 4, 0, sizeof(sljit_sw
));
5617 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
5618 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
5619 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
5620 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(F64
) | SLJIT_ARG1(F32
) | SLJIT_ARG2(F32
) | SLJIT_ARG3(F64
), SLJIT_IMM
, SLJIT_FUNC_OFFSET(test58_f1
));
5622 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
), SLJIT_FR0
, 0);
5624 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
5625 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
));
5626 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
));
5627 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_RET(F64
) | SLJIT_ARG1(F32
) | SLJIT_ARG2(F32
) | SLJIT_ARG3(F64
));
5628 sljit_set_target(jump
, SLJIT_FUNC_OFFSET(test58_f1
));
5630 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5632 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(test58_f2
));
5633 sljit_get_local_base(compiler
, SLJIT_R1
, 0, -16);
5634 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
5635 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
5636 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
5637 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(F32
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(F64
) | SLJIT_ARG3(F32
), SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 0);
5639 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
5641 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -4);
5642 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 9);
5643 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0);
5644 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
5645 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_RET(F64
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(F32
) | SLJIT_ARG3(SW
));
5646 sljit_set_target(jump
, SLJIT_FUNC_OFFSET(test58_f3
));
5648 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5650 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
5651 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -6);
5652 jump
= sljit_emit_call(compiler
, SLJIT_CALL_CDECL
, SLJIT_RET(F64
) | SLJIT_ARG1(F32
) | SLJIT_ARG2(SW
));
5653 sljit_set_target(jump
, SLJIT_FUNC_OFFSET(test58_f4
));
5655 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5657 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(test58_f5
));
5658 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
));
5659 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
));
5660 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5661 sljit_emit_icall(compiler
, SLJIT_CALL_CDECL
, SLJIT_RET(F32
) | SLJIT_ARG1(F32
) | SLJIT_ARG2(F64
) | SLJIT_ARG3(S32
), SLJIT_MEM1(SLJIT_SP
), 0);
5663 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
5665 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
));
5666 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(test58_f6
));
5667 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(F64
) | SLJIT_ARG2(SW
), SLJIT_R0
, 0);
5669 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), 0, SLJIT_R0
, 0);
5671 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
));
5672 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 319);
5673 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(test58_f6
));
5674 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(F64
) | SLJIT_ARG2(SW
), SLJIT_R1
, 0);
5676 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_sw
), SLJIT_R0
, 0);
5678 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5680 code
.code
= sljit_generate_code(compiler
);
5682 sljit_free_compiler(compiler
);
5684 code
.func3((sljit_sw
)&dbuf
, (sljit_sw
)&sbuf
, (sljit_sw
)&wbuf
);
5686 FAILED(dbuf
[1] != 8.5, "test58 case 1 failed\n");
5687 FAILED(dbuf
[3] != 0.5, "test58 case 2 failed\n");
5688 FAILED(sbuf
[3] != 17.75, "test58 case 3 failed\n");
5689 FAILED(dbuf
[4] != 11.75, "test58 case 4 failed\n");
5690 FAILED(dbuf
[5] != -9.5, "test58 case 5 failed\n");
5691 FAILED(sbuf
[4] != 12, "test58 case 6 failed\n");
5692 FAILED(wbuf
[0] != SLJIT_FUNC_OFFSET(test58_f6
) - 18, "test58 case 7 failed\n");
5693 FAILED(wbuf
[1] != 301, "test58 case 8 failed\n");
5695 sljit_free_code(code
.code
, NULL
);
5699 static sljit_sw SLJIT_FUNC
test59_f1(sljit_sw a
, sljit_s32 b
, sljit_sw c
, sljit_sw d
)
5701 return (sljit_sw
)(a
+ b
+ c
+ d
- SLJIT_FUNC_OFFSET(test59_f1
));
5704 static sljit_sw
test59_f2(sljit_sw a
, sljit_s32 b
, sljit_sw c
, sljit_sw d
)
5706 return (sljit_sw
)(a
+ b
+ c
+ d
- SLJIT_FUNC_OFFSET(test59_f2
));
5709 static sljit_s32 SLJIT_FUNC
test59_f3(sljit_f64 a
, sljit_f32 b
, sljit_f64 c
, sljit_sw d
)
5711 return (sljit_s32
)(a
+ b
+ c
+ d
);
5714 static sljit_f32 SLJIT_FUNC
test59_f4(sljit_f32 a
, sljit_s32 b
, sljit_f64 c
, sljit_sw d
)
5716 return (sljit_f32
)(a
+ b
+ c
+ d
);
5719 static sljit_f32 SLJIT_FUNC
test59_f5(sljit_f32 a
, sljit_f64 b
, sljit_f32 c
, sljit_f64 d
)
5721 return (sljit_f32
)(a
+ b
+ c
+ d
);
5724 static void test59(void)
5726 /* Check function calls with four arguments. */
5727 executable_code code
;
5728 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5729 struct sljit_jump
* jump
= NULL
;
5735 printf("Run test59\n");
5740 wbuf
[3] = SLJIT_FUNC_OFFSET(test59_f1
);
5744 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5755 FAILED(!compiler
, "cannot create compiler\n");
5757 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
), 4, 3, 4, 0, sizeof(sljit_sw
));
5759 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 33);
5760 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -20);
5761 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(test59_f1
));
5762 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -40);
5763 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(S32
) | SLJIT_ARG3(SW
) | SLJIT_ARG4(SW
), SLJIT_R2
, 0);
5765 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
5767 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
5768 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -30);
5769 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 50);
5770 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(test59_f2
));
5771 sljit_emit_icall(compiler
, SLJIT_CALL_CDECL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(S32
) | SLJIT_ARG3(SW
) | SLJIT_ARG4(SW
), SLJIT_R3
, 0);
5773 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
5775 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(test59_f1
));
5776 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -25);
5777 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 100);
5778 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -10);
5779 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(S32
) | SLJIT_ARG3(SW
) | SLJIT_ARG4(SW
), SLJIT_R0
, 0);
5781 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5783 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
5784 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 231);
5785 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 3);
5786 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(test59_f1
) - 100);
5787 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(SW
) | SLJIT_ARG1(SW
) | SLJIT_ARG2(S32
) | SLJIT_ARG3(SW
) | SLJIT_ARG4(SW
), SLJIT_MEM2(SLJIT_R0
, SLJIT_R2
), SLJIT_WORD_SHIFT
);
5789 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5791 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5792 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
5793 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S2
), 0);
5794 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
));
5795 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -100);
5796 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(S32
) | SLJIT_ARG1(F64
) | SLJIT_ARG2(F32
) | SLJIT_ARG3(F64
) | SLJIT_ARG4(SW
), SLJIT_IMM
, SLJIT_FUNC_OFFSET(test59_f3
));
5797 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
5799 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5801 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
5802 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f64
));
5803 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 36);
5804 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 41);
5805 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_RET(F32
) | SLJIT_ARG1(F32
) | SLJIT_ARG2(S32
) | SLJIT_ARG3(F64
) | SLJIT_ARG4(SW
));
5806 sljit_set_target(jump
, SLJIT_FUNC_OFFSET(test59_f4
));
5808 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
5810 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_OFFSET(test59_f5
));
5811 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S2
), 0);
5812 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
5813 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
5814 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f64
));
5815 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_RET(F32
) | SLJIT_ARG1(F32
) | SLJIT_ARG2(F64
) | SLJIT_ARG3(F32
) | SLJIT_ARG4(F64
), SLJIT_R0
, 0);
5817 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S2
), 3 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
5820 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5822 code
.code
= sljit_generate_code(compiler
);
5824 sljit_free_compiler(compiler
);
5826 code
.func3((sljit_sw
)&wbuf
, (sljit_sw
)&dbuf
, (sljit_sw
)&sbuf
);
5828 FAILED(wbuf
[0] != -27, "test59 case 1 failed\n");
5829 FAILED(wbuf
[1] != 36, "test59 case 2 failed\n");
5830 FAILED(wbuf
[2] != 65, "test59 case 3 failed\n");
5831 FAILED(wbuf
[4] != (sljit_sw
)wbuf
+ 134, "test59 case 4 failed\n");
5833 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5834 FAILED(wbuf
[5] != -88, "test59 case 5 failed\n");
5835 FAILED(sbuf
[2] != 79.75, "test59 case 6 failed\n");
5836 FAILED(sbuf
[3] != 8.625, "test59 case 7 failed\n");
5839 sljit_free_code(code
.code
, NULL
);
5843 static void test60(void)
5845 /* Test memory accesses with pre/post updates. */
5846 executable_code code
;
5847 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5849 sljit_s32 supported
[10];
5854 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
5855 static sljit_u8 expected
[10] = { 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 };
5856 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
5857 static sljit_u8 expected
[10] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
5858 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32)
5859 static sljit_u8 expected
[10] = { 1, 0, 1, 1, 0, 1, 1, 1, 0, 0 };
5860 #elif (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
5861 static sljit_u8 expected
[10] = { 1, 0, 0, 1, 0, 0, 1, 1, 0, 0 };
5863 static sljit_u8 expected
[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
5867 printf("Run test60\n");
5869 for (i
= 0; i
< 18; i
++)
5881 FAILED(!compiler
, "cannot create compiler\n");
5883 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
), 4, 3, 4, 0, sizeof(sljit_sw
));
5885 supported
[0] = sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_sw
));
5886 if (supported
[0] == SLJIT_SUCCESS
) {
5887 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
5888 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_sw
));
5889 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
5890 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
5893 supported
[1] = sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM1(SLJIT_R2
), -2 * (sljit_sw
)sizeof(sljit_s8
));
5894 if (supported
[1] == SLJIT_SUCCESS
) {
5895 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s8
));
5896 sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM1(SLJIT_R2
), -2 * (sljit_sw
)sizeof(sljit_s8
));
5897 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5898 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R2
, 0);
5901 supported
[2] = sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_R2
, SLJIT_MEM1(SLJIT_R1
), -2 * (sljit_sw
)sizeof(sljit_s32
));
5902 if (supported
[2] == SLJIT_SUCCESS
) {
5903 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s32
));
5904 sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_PRE
, SLJIT_R2
, SLJIT_MEM1(SLJIT_R1
), -2 * (sljit_sw
)sizeof(sljit_s32
));
5905 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R2
, 0);
5906 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5909 supported
[3] = sljit_emit_mem(compiler
, SLJIT_MOV32
| SLJIT_MEM_SUPP
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R2
), 2 * sizeof(sljit_s32
));
5910 if (supported
[3] == SLJIT_SUCCESS
) {
5911 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -8765);
5912 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, sizeof(sljit_s32
));
5913 sljit_emit_mem(compiler
, SLJIT_MOV32
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R2
), 2 * sizeof(sljit_s32
));
5914 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R2
, 0);
5917 supported
[4] = sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_SUPP
| SLJIT_MEM_STORE
| SLJIT_MEM_POST
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R2
), -128 * (sljit_sw
)sizeof(sljit_s8
));
5918 if (supported
[4] == SLJIT_SUCCESS
) {
5919 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -121);
5920 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_S1
, 0);
5921 sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_STORE
| SLJIT_MEM_POST
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R2
), -128 * (sljit_sw
)sizeof(sljit_s8
));
5922 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R2
, 0);
5925 supported
[5] = sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 1);
5926 if (supported
[5] == SLJIT_SUCCESS
) {
5927 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 9 * sizeof(sljit_sw
) - 1);
5928 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -881199);
5929 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 1);
5930 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5933 supported
[6] = sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5934 if (supported
[6] == SLJIT_SUCCESS
) {
5935 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 213);
5936 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -213);
5937 sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_PRE
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5938 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5939 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5942 supported
[7] = sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_SUPP
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5943 if (supported
[7] == SLJIT_SUCCESS
) {
5944 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_S2
, 0);
5945 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s32
));
5946 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -7890);
5947 sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5948 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5951 supported
[8] = sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 2);
5952 if (supported
[8] == SLJIT_SUCCESS
) {
5953 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 2 * sizeof(sljit_sw
));
5954 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2 * sizeof(sljit_sw
));
5955 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 2);
5956 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5957 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5960 supported
[9] = sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5961 if (supported
[9] == SLJIT_SUCCESS
) {
5962 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s8
));
5963 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -2 * (sljit_sw
)sizeof(sljit_s8
));
5964 sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5965 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5966 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5969 SLJIT_ASSERT(sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 1) == SLJIT_ERR_UNSUPPORTED
);
5970 SLJIT_ASSERT(sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 1) == SLJIT_ERR_UNSUPPORTED
);
5972 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
5973 /* TODO: at least for ARM (both V5 and V7) the range below needs further fixing */
5974 SLJIT_ASSERT(sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 256) == SLJIT_ERR_UNSUPPORTED
);
5975 SLJIT_ASSERT(sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), -257) == SLJIT_ERR_UNSUPPORTED
);
5978 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
5980 code
.code
= sljit_generate_code(compiler
);
5982 sljit_free_compiler(compiler
);
5984 code
.func3((sljit_sw
)&wbuf
, (sljit_sw
)&bbuf
, (sljit_sw
)&ibuf
);
5986 FAILED(sizeof(expected
) != sizeof(supported
) / sizeof(sljit_s32
), "test60 case 1 failed\n");
5988 for (i
= 0; i
< sizeof(expected
); i
++) {
5990 if (supported
[i
] != SLJIT_SUCCESS
) {
5991 printf("tast60 case %d should be supported\n", i
+ 1);
5995 if (supported
[i
] == SLJIT_SUCCESS
) {
5996 printf("test60 case %d should not be supported\n", i
+ 1);
6002 FAILED(supported
[0] == SLJIT_SUCCESS
&& wbuf
[0] != -887766, "test60 case 2 failed\n");
6003 FAILED(supported
[0] == SLJIT_SUCCESS
&& wbuf
[1] != (sljit_sw
)(wbuf
+ 2), "test60 case 3 failed\n");
6004 FAILED(supported
[1] == SLJIT_SUCCESS
&& wbuf
[3] != -13, "test60 case 4 failed\n");
6005 FAILED(supported
[1] == SLJIT_SUCCESS
&& wbuf
[4] != (sljit_sw
)(bbuf
), "test60 case 5 failed\n");
6006 FAILED(supported
[2] == SLJIT_SUCCESS
&& wbuf
[5] != -5678, "test60 case 6 failed\n");
6007 FAILED(supported
[2] == SLJIT_SUCCESS
&& wbuf
[6] != (sljit_sw
)(ibuf
), "test60 case 7 failed\n");
6008 FAILED(supported
[3] == SLJIT_SUCCESS
&& ibuf
[1] != -8765, "test60 case 8 failed\n");
6009 FAILED(supported
[3] == SLJIT_SUCCESS
&& wbuf
[7] != (sljit_sw
)(ibuf
+ 1), "test60 case 9 failed\n");
6010 FAILED(supported
[4] == SLJIT_SUCCESS
&& bbuf
[0] != -121, "test60 case 10 failed\n");
6011 FAILED(supported
[4] == SLJIT_SUCCESS
&& wbuf
[8] != (sljit_sw
)(bbuf
) - 128 * sizeof(sljit_s8
), "test60 case 11 failed\n");
6012 FAILED(supported
[5] == SLJIT_SUCCESS
&& wbuf
[9] != -881199, "test60 case 12 failed\n");
6013 FAILED(supported
[5] == SLJIT_SUCCESS
&& wbuf
[10] != (sljit_sw
)(wbuf
+ 9), "test60 case 13 failed\n");
6014 FAILED(supported
[6] == SLJIT_SUCCESS
&& wbuf
[11] != -5678, "test60 case 14 failed\n");
6015 FAILED(supported
[6] == SLJIT_SUCCESS
&& wbuf
[12] != (sljit_sw
)(ibuf
), "test60 case 15 failed\n");
6016 FAILED(supported
[7] == SLJIT_SUCCESS
&& ibuf
[2] != -7890, "test60 case 16 failed\n");
6017 FAILED(supported
[7] == SLJIT_SUCCESS
&& wbuf
[13] != (sljit_sw
)(ibuf
+ 2), "test60 case 17 failed\n");
6018 FAILED(supported
[8] == SLJIT_SUCCESS
&& wbuf
[14] != -887766, "test60 case 18 failed\n");
6019 FAILED(supported
[8] == SLJIT_SUCCESS
&& wbuf
[15] != (sljit_sw
)(wbuf
+ 10), "test60 case 19 failed\n");
6020 FAILED(supported
[9] == SLJIT_SUCCESS
&& wbuf
[16] != -13, "test60 case 20 failed\n");
6021 FAILED(supported
[9] == SLJIT_SUCCESS
&& wbuf
[17] != (sljit_sw
)(bbuf
), "test60 case 21 failed\n");
6023 sljit_free_code(code
.code
, NULL
);
6027 static void test61(void)
6029 /* Test float memory accesses with pre/post updates. */
6030 executable_code code
;
6031 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6033 sljit_s32 supported
[6];
6037 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
6038 static sljit_u8 expected
[6] = { 1, 1, 1, 1, 0, 0 };
6039 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
6040 static sljit_u8 expected
[6] = { 1, 0, 1, 0, 1, 1 };
6042 static sljit_u8 expected
[6] = { 0, 0, 0, 0, 0, 0 };
6045 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
6047 printf("no fpu available, test61 skipped\n");
6050 sljit_free_compiler(compiler
);
6055 printf("Run test61\n");
6057 for (i
= 0; i
< 6; i
++)
6070 FAILED(!compiler
, "cannot create compiler\n");
6072 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
) | SLJIT_ARG3(SW
), 4, 3, 4, 0, sizeof(sljit_sw
));
6074 supported
[0] = sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_FR0
, SLJIT_MEM1(SLJIT_R0
), 4 * sizeof(sljit_f64
));
6075 if (supported
[0] == SLJIT_SUCCESS
) {
6076 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 4 * sizeof(sljit_f64
));
6077 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_PRE
, SLJIT_FR0
, SLJIT_MEM1(SLJIT_R0
), 4 * sizeof(sljit_f64
));
6078 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
), SLJIT_FR0
, 0);
6079 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
6082 supported
[1] = sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_SUPP
| SLJIT_MEM_STORE
| SLJIT_MEM_POST
, SLJIT_FR2
, SLJIT_MEM1(SLJIT_R0
), -(sljit_sw
)sizeof(sljit_f64
));
6083 if (supported
[1] == SLJIT_SUCCESS
) {
6084 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 2 * sizeof(sljit_f64
));
6085 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
6086 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_STORE
| SLJIT_MEM_POST
, SLJIT_FR2
, SLJIT_MEM1(SLJIT_R0
), -(sljit_sw
)sizeof(sljit_f64
));
6087 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
6090 supported
[2] = sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_SUPP
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_FR1
, SLJIT_MEM1(SLJIT_R2
), -4 * (sljit_sw
)sizeof(sljit_f32
));
6091 if (supported
[2] == SLJIT_SUCCESS
) {
6092 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 4 * sizeof(sljit_f32
));
6093 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
6094 sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_FR1
, SLJIT_MEM1(SLJIT_R2
), -4 * (sljit_sw
)sizeof(sljit_f32
));
6095 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R2
, 0);
6098 supported
[3] = sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_FR1
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_f32
));
6099 if (supported
[3] == SLJIT_SUCCESS
) {
6100 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S2
, 0, SLJIT_IMM
, sizeof(sljit_f32
));
6101 sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_POST
, SLJIT_FR1
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_f32
));
6102 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_f32
), SLJIT_FR1
, 0);
6103 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R1
, 0);
6106 supported
[4] = sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_FR0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 0);
6107 if (supported
[4] == SLJIT_SUCCESS
) {
6108 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 8 * sizeof(sljit_f64
));
6109 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -8 * (sljit_sw
)sizeof(sljit_f64
));
6110 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_PRE
, SLJIT_FR0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 0);
6111 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
6112 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R1
, 0);
6115 supported
[5] = sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_SUPP
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_FR2
, SLJIT_MEM2(SLJIT_R2
, SLJIT_R1
), 0);
6116 if (supported
[5] == SLJIT_SUCCESS
) {
6117 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_S2
, 0);
6118 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3 * sizeof(sljit_f32
));
6119 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
6120 sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_FR2
, SLJIT_MEM2(SLJIT_R2
, SLJIT_R1
), 0);
6121 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R2
, 0);
6124 SLJIT_ASSERT(sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_FR0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0) == SLJIT_ERR_UNSUPPORTED
);
6125 SLJIT_ASSERT(sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_SUPP
| SLJIT_MEM_STORE
| SLJIT_MEM_POST
, SLJIT_FR0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0) == SLJIT_ERR_UNSUPPORTED
);
6127 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
6128 /* TODO: at least for ARM (both V5 and V7) the range below needs further fixing */
6129 SLJIT_ASSERT(sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_FR0
, SLJIT_MEM1(SLJIT_R0
), 256) == SLJIT_ERR_UNSUPPORTED
);
6130 SLJIT_ASSERT(sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_FR0
, SLJIT_MEM1(SLJIT_R0
), -257) == SLJIT_ERR_UNSUPPORTED
);
6133 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
6135 code
.code
= sljit_generate_code(compiler
);
6137 sljit_free_compiler(compiler
);
6139 code
.func3((sljit_sw
)&wbuf
, (sljit_sw
)&dbuf
, (sljit_sw
)&sbuf
);
6141 FAILED(sizeof(expected
) != sizeof(supported
) / sizeof(sljit_s32
), "test61 case 1 failed\n");
6143 for (i
= 0; i
< sizeof(expected
); i
++) {
6145 if (supported
[i
] != SLJIT_SUCCESS
) {
6146 printf("tast61 case %d should be supported\n", i
+ 1);
6150 if (supported
[i
] == SLJIT_SUCCESS
) {
6151 printf("test61 case %d should not be supported\n", i
+ 1);
6157 FAILED(supported
[0] == SLJIT_SUCCESS
&& dbuf
[1] != 66.725, "test61 case 2 failed\n");
6158 FAILED(supported
[0] == SLJIT_SUCCESS
&& wbuf
[0] != (sljit_sw
)(dbuf
), "test61 case 3 failed\n");
6159 FAILED(supported
[1] == SLJIT_SUCCESS
&& dbuf
[2] != 66.725, "test61 case 4 failed\n");
6160 FAILED(supported
[1] == SLJIT_SUCCESS
&& wbuf
[1] != (sljit_sw
)(dbuf
+ 1), "test61 case 5 failed\n");
6161 FAILED(supported
[2] == SLJIT_SUCCESS
&& sbuf
[0] != -22.125, "test61 case 6 failed\n");
6162 FAILED(supported
[2] == SLJIT_SUCCESS
&& wbuf
[2] != (sljit_sw
)(sbuf
), "test61 case 7 failed\n");
6163 FAILED(supported
[3] == SLJIT_SUCCESS
&& sbuf
[2] != -22.125, "test61 case 8 failed\n");
6164 FAILED(supported
[3] == SLJIT_SUCCESS
&& wbuf
[3] != (sljit_sw
)(sbuf
+ 2), "test61 case 9 failed\n");
6165 FAILED(supported
[4] == SLJIT_SUCCESS
&& dbuf
[3] != 66.725, "test61 case 10 failed\n");
6166 FAILED(supported
[4] == SLJIT_SUCCESS
&& wbuf
[4] != (sljit_sw
)(dbuf
), "test61 case 11 failed\n");
6167 FAILED(supported
[5] == SLJIT_SUCCESS
&& sbuf
[3] != -22.125, "test61 case 12 failed\n");
6168 FAILED(supported
[5] == SLJIT_SUCCESS
&& wbuf
[5] != (sljit_sw
)(sbuf
+ 3), "test61 case 13 failed\n");
6170 sljit_free_code(code
.code
, NULL
);
6174 static void test62(void)
6176 /* Test fast calls flag preservation. */
6177 executable_code code1
;
6178 executable_code code2
;
6179 struct sljit_compiler
* compiler
;
6182 printf("Run test62\n");
6185 compiler
= sljit_create_compiler(NULL
, NULL
);
6186 FAILED(!compiler
, "cannot create compiler\n");
6187 sljit_set_context(compiler
, 0, SLJIT_ARG1(SW
), 1, 1, 0, 0, 0);
6189 sljit_emit_fast_enter(compiler
, SLJIT_R0
, 0);
6190 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_UNUSED
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 42);
6191 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R0
, 0);
6193 code1
.code
= sljit_generate_code(compiler
);
6195 sljit_free_compiler(compiler
);
6198 compiler
= sljit_create_compiler(NULL
, NULL
);
6199 FAILED(!compiler
, "cannot create compiler\n");
6201 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 1, 1, 0, 0, 0);
6202 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_OFFSET(code1
.code
));
6203 sljit_set_current_flags(compiler
, SLJIT_CURRENT_FLAGS_ADD_SUB
| SLJIT_CURRENT_FLAGS_COMPARE
| SLJIT_SET_Z
| SLJIT_SET_LESS
);
6204 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_ZERO
);
6205 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_LESS
);
6206 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
6207 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S0
, 0);
6208 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
6210 code2
.code
= sljit_generate_code(compiler
);
6212 sljit_free_compiler(compiler
);
6214 FAILED(code2
.func1(88) != 0, "test62 case 1 failed\n");
6215 FAILED(code2
.func1(42) != 1, "test62 case 2 failed\n");
6216 FAILED(code2
.func1(0) != 2, "test62 case 3 failed\n");
6218 sljit_free_code(code1
.code
, NULL
);
6219 sljit_free_code(code2
.code
, NULL
);
6223 static void test63(void)
6225 /* Test put label. */
6226 executable_code code
;
6227 struct sljit_label
*label
[2];
6228 struct sljit_put_label
*put_label
[5];
6229 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6232 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
6233 sljit_sw offs
= SLJIT_W(0x123456789012);
6235 sljit_sw offs
= 0x12345678;
6239 printf("Run test63\n");
6241 FAILED(!compiler
, "cannot create compiler\n");
6247 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 1, 0, 0, 2 * sizeof(sljit_sw
));
6249 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_R0
, 0);
6250 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
6252 put_label
[1] = sljit_emit_put_label(compiler
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
));
6253 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
));
6255 label
[0] = sljit_emit_label(compiler
);
6256 sljit_set_put_label(put_label
[0], label
[0]);
6257 sljit_set_put_label(put_label
[1], label
[0]);
6259 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)(buf
+ 2) - offs
);
6260 put_label
[2] = sljit_emit_put_label(compiler
, SLJIT_MEM1(SLJIT_R0
), offs
);
6262 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (offs
+ sizeof(sljit_uw
)) >> 1);
6263 put_label
[3] = sljit_emit_put_label(compiler
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1);
6265 label
[1] = sljit_emit_label(compiler
);
6266 sljit_set_put_label(put_label
[2], label
[1]);
6267 sljit_set_put_label(put_label
[3], label
[1]);
6269 put_label
[4] = sljit_emit_put_label(compiler
, SLJIT_RETURN_REG
, 0);
6270 sljit_set_put_label(put_label
[4], label
[0]);
6271 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
6273 code
.code
= sljit_generate_code(compiler
);
6276 addr
[0] = sljit_get_label_addr(label
[0]);
6277 addr
[1] = sljit_get_label_addr(label
[1]);
6279 sljit_free_compiler(compiler
);
6281 FAILED(code
.func1((sljit_sw
)&buf
) != addr
[0], "test63 case 1 failed\n");
6282 FAILED(buf
[0] != addr
[0], "test63 case 2 failed\n");
6283 FAILED(buf
[1] != addr
[0], "test63 case 3 failed\n");
6284 FAILED(buf
[2] != addr
[1], "test63 case 4 failed\n");
6285 FAILED(buf
[3] != addr
[1], "test63 case 5 failed\n");
6287 sljit_free_code(code
.code
, NULL
);
6291 static void test64(void)
6293 /* Test put label with absolute label addresses */
6294 executable_code code
;
6295 sljit_uw malloc_addr
;
6296 struct sljit_label label
[4];
6297 struct sljit_put_label
*put_label
[2];
6298 struct sljit_compiler
* compiler
;
6300 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
6301 sljit_sw offs1
= SLJIT_W(0x123456781122);
6302 sljit_sw offs2
= SLJIT_W(0x1234567811223344);
6303 #else /* !SLJIT_64BIT_ARCHITECTURE */
6304 sljit_sw offs1
= 0x12345678;
6305 sljit_sw offs2
= 0x80000000;
6306 #endif /* SLJIT_64BIT_ARCHITECTURE */
6309 printf("Run test64\n");
6311 /* lock next allocation; see sljit_test_malloc_exec() */
6312 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
6313 malloc_addr
= (sljit_uw
)SLJIT_MALLOC_EXEC(1024, NULL
);
6316 printf("Cannot allocate executable memory\n");
6320 compiler
= sljit_create_compiler(NULL
, (void*)malloc_addr
);
6321 malloc_addr
+= SLJIT_EXEC_OFFSET((void*)malloc_addr
);
6322 #else /* SLJIT_CONFIG_UNSUPPORTED */
6324 compiler
= sljit_create_compiler(NULL
, (void*)malloc_addr
);
6325 #endif /* !SLJIT_CONFIG_UNSUPPORTED */
6327 label
[0].addr
= 0x1234;
6328 label
[0].size
= (sljit_uw
)(0x1234 - malloc_addr
);
6330 label
[1].addr
= 0x12345678;
6331 label
[1].size
= (sljit_uw
)(0x12345678 - malloc_addr
);
6333 label
[2].addr
= offs1
;
6334 label
[2].size
= (sljit_uw
)(offs1
- malloc_addr
);
6336 label
[3].addr
= offs2
;
6337 label
[3].size
= (sljit_uw
)(offs2
- malloc_addr
);
6339 FAILED(!compiler
, "cannot create compiler\n");
6346 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 1, 0, 0, 2 * sizeof(sljit_sw
));
6348 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_R0
, 0);
6349 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
6351 put_label
[1] = sljit_emit_put_label(compiler
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
));
6352 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
));
6354 sljit_set_put_label(put_label
[0], &label
[0]);
6355 sljit_set_put_label(put_label
[1], &label
[0]);
6357 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)(buf
+ 2) - offs1
);
6358 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_MEM1(SLJIT_R0
), offs1
);
6360 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (offs1
+ sizeof(sljit_uw
)) >> 1);
6361 put_label
[1] = sljit_emit_put_label(compiler
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1);
6363 sljit_set_put_label(put_label
[0], &label
[1]);
6364 sljit_set_put_label(put_label
[1], &label
[1]);
6366 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_R2
, 0);
6367 sljit_set_put_label(put_label
[0], &label
[2]);
6368 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_uw
), SLJIT_R2
, 0);
6370 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_RETURN_REG
, 0);
6371 sljit_set_put_label(put_label
[0], &label
[3]);
6372 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
6374 code
.code
= sljit_generate_code(compiler
);
6376 sljit_free_compiler(compiler
);
6377 SLJIT_ASSERT(SLJIT_FUNC_OFFSET(code
.code
) >= (sljit_sw
)malloc_addr
&& SLJIT_FUNC_OFFSET(code
.code
) <= (sljit_sw
)malloc_addr
+ 8);
6379 FAILED(code
.func1((sljit_sw
)&buf
) != label
[3].addr
, "test64 case 1 failed\n");
6380 FAILED(buf
[0] != label
[0].addr
, "test64 case 2 failed\n");
6381 FAILED(buf
[1] != label
[0].addr
, "test64 case 3 failed\n");
6382 FAILED(buf
[2] != label
[1].addr
, "test64 case 4 failed\n");
6383 FAILED(buf
[3] != label
[1].addr
, "test64 case 5 failed\n");
6384 FAILED(buf
[4] != label
[2].addr
, "test64 case 6 failed\n");
6386 sljit_free_code(code
.code
, NULL
);
6391 static void test65(void)
6393 /* Test jump tables. */
6394 executable_code code
;
6395 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6397 /* Normally this table is allocated on the heap. */
6399 struct sljit_label
*labels
[64];
6400 struct sljit_jump
*jump
;
6403 printf("Run test65\n");
6405 FAILED(!compiler
, "cannot create compiler\n");
6407 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
), 1, 2, 0, 0, 0);
6409 jump
= sljit_emit_cmp(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_S0
, 0, SLJIT_IMM
, 64);
6410 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)addr
);
6411 sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_MEM2(SLJIT_R0
, SLJIT_S0
), SLJIT_WORD_SHIFT
);
6413 for (i
= 0; i
< 64; i
++) {
6414 labels
[i
] = sljit_emit_label(compiler
);
6415 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
6416 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, i
* 2);
6417 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
6420 sljit_set_label(jump
, sljit_emit_label(compiler
));
6421 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, -1);
6423 code
.code
= sljit_generate_code(compiler
);
6426 for (i
= 0; i
< 64; i
++) {
6427 addr
[i
] = sljit_get_label_addr(labels
[i
]);
6430 sljit_free_compiler(compiler
);
6432 FAILED(code
.func2(64, 0) != -1, "test65 case 1 failed\n");
6434 for (i
= 0; i
< 64; i
++) {
6435 FAILED(code
.func2(i
, i
* 2) != i
* 4, "test65 case 2 failed\n");
6438 sljit_free_code(code
.code
, NULL
);
6442 static void test66(void)
6444 /* Test direct jumps (computed goto). */
6445 executable_code code
;
6446 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6449 struct sljit_label
*labels
[64];
6452 printf("Run test66\n");
6454 FAILED(!compiler
, "cannot create compiler\n");
6456 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
) | SLJIT_ARG2(SW
), 1, 2, 0, 0, 0);
6457 sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_S0
, 0);
6459 for (i
= 0; i
< 64; i
++) {
6460 labels
[i
] = sljit_emit_label(compiler
);
6461 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
6462 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, i
* 2);
6463 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
6466 code
.code
= sljit_generate_code(compiler
);
6469 for (i
= 0; i
< 64; i
++) {
6470 addr
[i
] = sljit_get_label_addr(labels
[i
]);
6473 sljit_free_compiler(compiler
);
6475 for (i
= 0; i
< 64; i
++) {
6476 FAILED(code
.func2(addr
[i
], i
) != i
* 3, "test66 case 1 failed\n");
6479 sljit_free_code(code
.code
, NULL
);
6483 static void test67(void)
6485 /* Test skipping returns from fast calls (return type is fast). */
6486 executable_code code
;
6487 struct sljit_compiler
*compiler
= sljit_create_compiler(NULL
, NULL
);
6488 struct sljit_jump
*call
, *jump
;
6489 struct sljit_label
*label
;
6492 printf("Run test67\n");
6494 FAILED(!compiler
, "cannot create compiler\n");
6496 sljit_emit_enter(compiler
, 0, 0, 3, 1, 0, 0, 0);
6498 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
6499 call
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
);
6501 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
6503 /* First function, never returns. */
6504 label
= sljit_emit_label(compiler
);
6505 sljit_set_label(call
, label
);
6506 sljit_emit_fast_enter(compiler
, SLJIT_R1
, 0);
6508 call
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
);
6510 /* Should never return here, marked by a segmentation fault if it does. */
6511 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
6513 /* Second function, skips the first function. */
6514 sljit_set_label(call
, sljit_emit_label(compiler
));
6515 sljit_emit_fast_enter(compiler
, SLJIT_R2
, 0);
6517 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
6519 jump
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
6521 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_R1
, 0);
6522 sljit_set_label(sljit_emit_jump(compiler
, SLJIT_FAST_CALL
), label
);
6523 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
6524 sljit_emit_op_src(compiler
, SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN
, SLJIT_S0
, 0);
6525 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_S0
, 0);
6527 sljit_set_label(jump
, sljit_emit_label(compiler
));
6528 sljit_emit_op_src(compiler
, SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN
, SLJIT_R1
, 0);
6529 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R1
, 0);
6531 code
.code
= sljit_generate_code(compiler
);
6534 sljit_free_compiler(compiler
);
6536 FAILED(code
.func0() != 3, "test67 case 1 failed\n");
6538 sljit_free_code(code
.code
, NULL
);
6542 static void test68(void)
6544 /* Test skipping returns from fast calls (return type is normal). */
6545 executable_code code
;
6546 struct sljit_compiler
*compiler
;
6547 struct sljit_jump
*call
, *jump
;
6548 struct sljit_label
*label
;
6552 printf("Run test68\n");
6554 for (i
= 0; i
< 6 * 2; i
++) {
6555 compiler
= sljit_create_compiler(NULL
, NULL
);
6556 FAILED(!compiler
, "cannot create compiler\n");
6558 sljit_emit_enter(compiler
, (i
>= 6 ? SLJIT_F64_ALIGNMENT
: 0), 0, 2 + (i
% 6), (i
% 6), 0, 0, 0);
6560 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
6561 call
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
);
6563 /* Should never return here, marked by a segmentation fault if it does. */
6564 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
6566 /* Recursive fast call. */
6567 label
= sljit_emit_label(compiler
);
6568 sljit_set_label(call
, label
);
6569 sljit_emit_fast_enter(compiler
, SLJIT_R1
, 0);
6571 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
6573 jump
= sljit_emit_cmp(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
6575 sljit_set_label(sljit_emit_jump(compiler
, SLJIT_FAST_CALL
), label
);
6577 sljit_set_label(jump
, sljit_emit_label(compiler
));
6578 sljit_emit_op0(compiler
, SLJIT_SKIP_FRAMES_BEFORE_RETURN
);
6579 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
6581 code
.code
= sljit_generate_code(compiler
);
6584 sljit_free_compiler(compiler
);
6586 if (SLJIT_UNLIKELY(code
.func0() != 4)) {
6587 printf("test68 case %d failed\n", i
+ 1);
6590 sljit_free_code(code
.code
, NULL
);
6596 static void test69(void)
6598 /* Test sljit_set_current_flags. */
6599 executable_code code
;
6600 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6605 printf("Run test69\n");
6607 for (i
= 0; i
< 8; i
++)
6610 FAILED(!compiler
, "cannot create compiler\n");
6612 sljit_emit_enter(compiler
, 0, SLJIT_ARG1(SW
), 3, 1, 0, 0, 0);
6614 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)1 << ((sizeof (sljit_sw
) * 8) - 2));
6615 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_R0
, 0);
6616 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
6617 sljit_emit_label(compiler
);
6618 sljit_set_current_flags(compiler
, SLJIT_SET_OVERFLOW
| SLJIT_CURRENT_FLAGS_ADD_SUB
);
6619 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_OVERFLOW
);
6621 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
6622 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
6623 sljit_emit_label(compiler
);
6624 sljit_set_current_flags(compiler
, SLJIT_SET_OVERFLOW
| SLJIT_CURRENT_FLAGS_ADD_SUB
);
6625 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_OVERFLOW
);
6627 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_R0
, 0);
6628 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
6629 sljit_emit_label(compiler
);
6630 sljit_set_current_flags(compiler
, SLJIT_SET_OVERFLOW
);
6631 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
6633 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
6634 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R1
, 0);
6635 sljit_emit_label(compiler
);
6636 sljit_set_current_flags(compiler
, SLJIT_SET_OVERFLOW
);
6637 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
6639 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 6);
6640 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 5);
6641 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_R2
, 0);
6642 sljit_emit_label(compiler
);
6643 sljit_set_current_flags(compiler
, SLJIT_SET_GREATER
| SLJIT_CURRENT_FLAGS_ADD_SUB
| SLJIT_CURRENT_FLAGS_COMPARE
);
6644 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_GREATER
);
6646 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_R2
, 0);
6647 sljit_emit_label(compiler
);
6648 sljit_set_current_flags(compiler
, SLJIT_SET_Z
| SLJIT_CURRENT_FLAGS_ADD_SUB
| SLJIT_CURRENT_FLAGS_COMPARE
);
6649 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_ZERO
);
6651 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -1 << 31);
6652 sljit_emit_op2(compiler
, SLJIT_ADD32
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_R1
, 0);
6653 sljit_emit_label(compiler
);
6654 sljit_set_current_flags(compiler
, SLJIT_SET_Z
| SLJIT_CURRENT_FLAGS_I32_OP
| SLJIT_CURRENT_FLAGS_ADD_SUB
);
6655 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_ZERO
);
6657 sljit_emit_op2(compiler
, SLJIT_SHL32
| SLJIT_SET_Z
, SLJIT_UNUSED
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 1);
6658 sljit_emit_label(compiler
);
6659 sljit_set_current_flags(compiler
, SLJIT_SET_Z
| SLJIT_CURRENT_FLAGS_I32_OP
);
6660 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_NOT_ZERO
);
6662 sljit_emit_return(compiler
, SLJIT_UNUSED
, 0, 0);
6664 code
.code
= sljit_generate_code(compiler
);
6666 sljit_free_compiler(compiler
);
6668 code
.func1((sljit_sw
)&buf
);
6670 FAILED(buf
[0] != 1, "test69 case 1 failed\n");
6671 FAILED(buf
[1] != 2, "test69 case 2 failed\n");
6672 FAILED(buf
[2] != 1, "test69 case 3 failed\n");
6673 FAILED(buf
[3] != 2, "test69 case 4 failed\n");
6674 FAILED(buf
[4] != 1, "test69 case 5 failed\n");
6675 FAILED(buf
[5] != 2, "test69 case 6 failed\n");
6676 FAILED(buf
[6] != 1, "test69 case 7 failed\n");
6677 FAILED(buf
[7] != 2, "test69 case 8 failed\n");
6679 sljit_free_code(code
.code
, NULL
);
6683 int sljit_test(int argc
, char* argv
[])
6685 sljit_s32 has_arg
= (argc
>= 2 && argv
[1][0] == '-' && argv
[1][2] == '\0');
6686 verbose
= has_arg
&& argv
[1][1] == 'v';
6687 silent
= has_arg
&& argv
[1][1] == 's';
6689 if (!verbose
&& !silent
)
6690 printf("Pass -v to enable verbose, -s to disable this hint.\n\n");
6692 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
6693 test_exec_allocator();
6765 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
6766 sljit_free_unused_memory_exec();
6769 # define TEST_COUNT 69
6771 printf("SLJIT tests: ");
6772 if (successful_tests
== TEST_COUNT
)
6773 printf("all tests are " COLOR_GREEN
"PASSED" COLOR_DEFAULT
" ");
6775 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 / TEST_COUNT
);
6776 printf("on " COLOR_ARCH
"%s" COLOR_DEFAULT
"%s\n", sljit_get_platform_name(), sljit_has_cpu_feature(SLJIT_HAS_FPU
) ? " (with fpu)" : " (without fpu)");
6778 return TEST_COUNT
- successful_tests
;
6784 #pragma warning(pop)