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 void (SLJIT_FUNC
*test70_f1
)(sljit_s32 a
, sljit_uw b
, sljit_u32 c
, sljit_sw d
);
59 void (SLJIT_FUNC
*test70_f2
)(sljit_s32 a
, sljit_u32 b
, sljit_sw c
, sljit_sw d
);
60 void (SLJIT_FUNC
*test70_f3
)(sljit_s32 a
, sljit_f32 b
, sljit_uw c
, sljit_f64 d
);
61 void (SLJIT_FUNC
*test70_f4
)(sljit_f32 a
, sljit_f64 b
, sljit_f32 c
, sljit_s32 d
);
62 void (SLJIT_FUNC
*test70_f5
)(sljit_f64 a
, sljit_f32 b
, sljit_u32 c
, sljit_f32 d
);
63 void (SLJIT_FUNC
*test70_f6
)(sljit_f64 a
, sljit_s32 b
, sljit_f32 c
, sljit_f64 d
);
64 void (SLJIT_FUNC
*test70_f7
)(sljit_f32 a
, sljit_s32 b
, sljit_uw c
, sljit_u32 d
);
65 void (SLJIT_FUNC
*test70_f8
)(sljit_f64 a
, sljit_f64 b
, sljit_uw c
, sljit_sw d
);
66 void (SLJIT_FUNC
*test70_f9
)(sljit_f64 a
, sljit_f64 b
, sljit_uw c
, sljit_f64 d
);
67 void (SLJIT_FUNC
*test70_f10
)(sljit_f64 a
, sljit_f64 b
, sljit_f64 c
, sljit_s32 d
);
69 sljit_sw (SLJIT_FUNC
*test71_f1
)(sljit_f64 a
, sljit_f64 b
, sljit_f64 c
, sljit_f64 d
);
71 typedef union executable_code executable_code
;
73 static sljit_s32 successful_tests
= 0;
74 static sljit_s32 verbose
= 0;
75 static sljit_s32 silent
= 0;
77 #define FAILED(cond, text) \
78 if (SLJIT_UNLIKELY(cond)) { \
83 #define CHECK(compiler) \
84 if (sljit_get_compiler_error(compiler) != SLJIT_ERR_COMPILED) { \
85 printf("Compiler error: %d\n", sljit_get_compiler_error(compiler)); \
86 sljit_free_compiler(compiler); \
90 static void cond_set(struct sljit_compiler
*compiler
, sljit_s32 dst
, sljit_sw dstw
, sljit_s32 type
)
92 /* Testing both sljit_emit_op_flags and sljit_emit_jump. */
93 struct sljit_jump
* jump
;
94 struct sljit_label
* label
;
96 sljit_emit_op_flags(compiler
, SLJIT_MOV
, dst
, dstw
, type
);
97 jump
= sljit_emit_jump(compiler
, type
);
98 sljit_emit_op2(compiler
, SLJIT_ADD
, dst
, dstw
, dst
, dstw
, SLJIT_IMM
, 2);
99 label
= sljit_emit_label(compiler
);
100 sljit_set_label(jump
, label
);
103 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
105 /* For interface testing and for test64. */
106 void *sljit_test_malloc_exec(sljit_uw size
, void *exec_allocator_data
)
108 if (exec_allocator_data
)
109 return exec_allocator_data
;
111 return SLJIT_BUILTIN_MALLOC_EXEC(size
, exec_allocator_data
);
114 /* For interface testing. */
115 void sljit_test_free_code(void* code
, void *exec_allocator_data
)
117 SLJIT_BUILTIN_FREE_EXEC(code
, exec_allocator_data
);
120 #define MALLOC_EXEC(result, size) \
121 result = SLJIT_MALLOC_EXEC(size, NULL); \
123 printf("Cannot allocate executable memory\n"); \
126 memset(result, 255, size);
128 #define FREE_EXEC(ptr) \
129 SLJIT_FREE_EXEC(((sljit_u8*)(ptr)) + SLJIT_EXEC_OFFSET(ptr), NULL);
131 static void test_exec_allocator(void)
133 /* This is not an sljit test. */
139 printf("Run executable allocator test\n");
141 MALLOC_EXEC(ptr1
, 32);
142 MALLOC_EXEC(ptr2
, 512);
143 MALLOC_EXEC(ptr3
, 512);
147 MALLOC_EXEC(ptr1
, 262104);
148 MALLOC_EXEC(ptr2
, 32000);
150 MALLOC_EXEC(ptr1
, 262104);
153 MALLOC_EXEC(ptr1
, 512);
154 MALLOC_EXEC(ptr2
, 512);
155 MALLOC_EXEC(ptr3
, 512);
157 MALLOC_EXEC(ptr2
, 512);
158 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
159 sljit_free_unused_memory_exec();
165 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
166 sljit_free_unused_memory_exec();
172 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
174 static void test1(void)
176 /* Enter and return from an sljit function. */
177 executable_code code
;
178 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
181 printf("Run test1\n");
183 FAILED(!compiler
, "cannot create compiler\n");
185 /* 3 arguments passed, 3 arguments used. */
186 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(W
, W
, W
, W
), 3, 3, 0, 0, 0);
187 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_S1
, 0);
189 SLJIT_ASSERT(sljit_get_generated_code_size(compiler
) == 0);
190 code
.code
= sljit_generate_code(compiler
);
192 SLJIT_ASSERT(compiler
->error
== SLJIT_ERR_COMPILED
);
193 SLJIT_ASSERT(sljit_get_generated_code_size(compiler
) > 0);
194 sljit_free_compiler(compiler
);
196 FAILED(code
.func3(3, -21, 86) != -21, "test1 case 1 failed\n");
197 FAILED(code
.func3(4789, 47890, 997) != 47890, "test1 case 2 failed\n");
199 sljit_free_code(code
.code
, NULL
);
203 static void test2(void)
206 executable_code code
;
207 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
209 static sljit_sw data
[2] = { 0, -9876 };
212 printf("Run test2\n");
214 FAILED(!compiler
, "cannot create compiler\n");
224 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 2, 0, 0, 0);
225 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 9999);
226 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_S0
, 0);
227 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
), SLJIT_R0
, 0);
228 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
229 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_MEM2(SLJIT_S1
, SLJIT_R1
), 0);
230 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 2);
231 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_S1
, SLJIT_S0
), SLJIT_WORD_SHIFT
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R1
), 0);
232 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 3);
233 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_S1
, SLJIT_S0
), SLJIT_WORD_SHIFT
, SLJIT_MEM0(), (sljit_sw
)&buf
);
234 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
235 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&data
);
236 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
237 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
- 0x12345678);
238 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R0
), 0x12345678);
239 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_R0
, 0);
240 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3456);
241 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
- 0xff890 + 6 * (sljit_sw
)sizeof(sljit_sw
));
242 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0xff890, SLJIT_R0
, 0);
243 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
+ 0xff890 + 7 * (sljit_sw
)sizeof(sljit_sw
));
244 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), -0xff890, SLJIT_R0
, 0);
245 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R2
, 0);
247 code
.code
= sljit_generate_code(compiler
);
249 sljit_free_compiler(compiler
);
251 FAILED(code
.func1((sljit_sw
)&buf
) != 9999, "test2 case 1 failed\n");
252 FAILED(buf
[1] != 9999, "test2 case 2 failed\n");
253 FAILED(buf
[2] != 9999, "test2 case 3 failed\n");
254 FAILED(buf
[3] != 5678, "test2 case 4 failed\n");
255 FAILED(buf
[4] != -9876, "test2 case 5 failed\n");
256 FAILED(buf
[5] != 5678, "test2 case 6 failed\n");
257 FAILED(buf
[6] != 3456, "test2 case 6 failed\n");
258 FAILED(buf
[7] != 3456, "test2 case 6 failed\n");
260 sljit_free_code(code
.code
, NULL
);
264 static void test3(void)
267 executable_code code
;
268 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
272 printf("Run test3\n");
274 FAILED(!compiler
, "cannot create compiler\n");
281 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 0);
282 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 0);
283 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_MEM0(), (sljit_sw
)&buf
[1], SLJIT_MEM0(), (sljit_sw
)&buf
[1]);
284 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_RETURN_REG
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
285 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2);
286 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[4] - 0xff0000 - 0x20);
287 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[4] - 0xff0000);
288 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_MEM1(SLJIT_R1
), 0xff0000 + 0x20, SLJIT_MEM1(SLJIT_R2
), 0xff0000);
289 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
291 code
.code
= sljit_generate_code(compiler
);
293 sljit_free_compiler(compiler
);
295 FAILED(code
.func1((sljit_sw
)&buf
) != ~1234, "test3 case 1 failed\n");
296 FAILED(buf
[1] != ~1234, "test3 case 2 failed\n");
297 FAILED(buf
[3] != ~9876, "test3 case 3 failed\n");
298 FAILED(buf
[4] != ~0x12345678, "test3 case 4 failed\n");
300 sljit_free_code(code
.code
, NULL
);
304 static void test4(void)
307 executable_code code
;
308 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
312 printf("Run test4\n");
314 FAILED(!compiler
, "cannot create compiler\n");
320 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(W
, P
, W
), 3, 2, 0, 0, 0);
321 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_S1
, 0);
322 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_MEM0(), (sljit_sw
)&buf
[0], SLJIT_MEM0(), (sljit_sw
)&buf
[1]);
323 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 299);
324 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_R1
, 0);
325 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_RETURN_REG
, 0, SLJIT_S1
, 0);
326 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
328 code
.code
= sljit_generate_code(compiler
);
330 sljit_free_compiler(compiler
);
332 FAILED(code
.func2((sljit_sw
)&buf
, 4567) != -4567, "test4 case 1 failed\n");
333 FAILED(buf
[0] != -1234, "test4 case 2 failed\n");
334 FAILED(buf
[2] != -4567, "test4 case 3 failed\n");
335 FAILED(buf
[3] != -299, "test4 case 4 failed\n");
337 sljit_free_code(code
.code
, NULL
);
341 static void test5(void)
344 executable_code code
;
345 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
349 printf("Run test5\n");
351 FAILED(!compiler
, "cannot create compiler\n");
362 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 2, 0, 0, 0);
363 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
364 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 50);
365 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);
366 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
) + 2);
367 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 50);
368 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
369 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
370 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_IMM
, 4, SLJIT_R0
, 0);
371 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_IMM
, 50, SLJIT_R1
, 0);
372 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
));
373 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R1
, 0);
374 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
));
375 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
));
376 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);
377 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x1e7d39f2);
378 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R1
, 0, SLJIT_IMM
, 0x23de7c06);
379 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, 0x3d72e452, SLJIT_R1
, 0);
380 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
));
381 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_IMM
, 1000, SLJIT_R0
, 0);
382 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1430);
383 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_IMM
, -99, SLJIT_R0
, 0);
385 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
387 code
.code
= sljit_generate_code(compiler
);
389 sljit_free_compiler(compiler
);
391 FAILED(code
.func1((sljit_sw
)&buf
) != 2437 + 2 * sizeof(sljit_sw
), "test5 case 1 failed\n");
392 FAILED(buf
[0] != 202 + 2 * sizeof(sljit_sw
), "test5 case 2 failed\n");
393 FAILED(buf
[2] != 500, "test5 case 3 failed\n");
394 FAILED(buf
[3] != 400, "test5 case 4 failed\n");
395 FAILED(buf
[4] != 200, "test5 case 5 failed\n");
396 FAILED(buf
[5] != 250, "test5 case 6 failed\n");
397 FAILED(buf
[6] != 0x425bb5f8, "test5 case 7 failed\n");
398 FAILED(buf
[7] != 0x5bf01e44, "test5 case 8 failed\n");
399 FAILED(buf
[8] != 270, "test5 case 9 failed\n");
401 sljit_free_code(code
.code
, NULL
);
405 static void test6(void)
407 /* Test addc, sub, subc. */
408 executable_code code
;
409 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
413 printf("Run test6\n");
415 FAILED(!compiler
, "cannot create compiler\n");
428 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 0);
429 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
430 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -1);
431 sljit_emit_op2(compiler
, SLJIT_ADDC
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0, SLJIT_IMM
, 0);
432 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R0
, 0);
433 sljit_emit_op2(compiler
, SLJIT_ADDC
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 4);
434 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 100);
435 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, SLJIT_IMM
, 50);
436 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 6000);
437 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_IMM
, 10);
438 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);
439 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 100);
440 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2);
441 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R0
, 0);
442 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5000);
443 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R0
, 0);
444 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
445 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R1
, 0);
446 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5000);
447 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_IMM
, 6000, SLJIT_R0
, 0);
448 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_R0
, 0);
449 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 100);
450 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 32768);
451 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_R1
, 0);
452 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -32767);
453 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_R1
, 0);
454 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x52cd3bf4);
455 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_R0
, 0, SLJIT_IMM
, 0x3da297c6);
456 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 6000);
457 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, SLJIT_R1
, 0);
458 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, SLJIT_R1
, 0);
459 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 10);
460 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_RETURN_REG
, 0, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 5);
461 sljit_emit_op2(compiler
, SLJIT_SUBC
, SLJIT_RETURN_REG
, 0, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 2);
462 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_RETURN_REG
, 0, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, -2220);
463 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
465 code
.code
= sljit_generate_code(compiler
);
467 sljit_free_compiler(compiler
);
469 FAILED(code
.func1((sljit_sw
)&buf
) != 2223, "test6 case 1 failed\n");
470 FAILED(buf
[0] != 1, "test6 case 2 failed\n");
471 FAILED(buf
[1] != 5, "test6 case 3 failed\n");
472 FAILED(buf
[2] != 50, "test6 case 4 failed\n");
473 FAILED(buf
[3] != 4, "test6 case 5 failed\n");
474 FAILED(buf
[4] != 50, "test6 case 6 failed\n");
475 FAILED(buf
[5] != 50, "test6 case 7 failed\n");
476 FAILED(buf
[6] != 1000, "test6 case 8 failed\n");
477 FAILED(buf
[7] != 100 - 32768, "test6 case 9 failed\n");
478 FAILED(buf
[8] != 100 + 32767, "test6 case 10 failed\n");
479 FAILED(buf
[9] != 0x152aa42e, "test6 case 11 failed\n");
480 FAILED(buf
[10] != -2000, "test6 case 12 failed\n");
482 sljit_free_code(code
.code
, NULL
);
486 static void test7(void)
488 /* Test logical operators. */
489 executable_code code
;
490 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
494 printf("Run test7\n");
496 FAILED(!compiler
, "cannot create compiler\n");
504 buf
[7] = (sljit_sw
)0xc43a7f95;
506 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 0);
507 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xf0C000);
508 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, SLJIT_IMM
, 0x308f);
509 sljit_emit_op2(compiler
, SLJIT_XOR
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
510 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);
511 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xC0F0);
512 sljit_emit_op2(compiler
, SLJIT_XOR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5);
513 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xff0000);
514 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R0
, 0);
515 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0xC0F0);
516 sljit_emit_op2(compiler
, SLJIT_AND
, SLJIT_R2
, 0, SLJIT_R2
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5);
517 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R2
, 0, SLJIT_IMM
, 0xff0000);
518 sljit_emit_op2(compiler
, SLJIT_XOR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 0xFFFFFF, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
519 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_IMM
, (sljit_sw
)0xa56c82c0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6);
520 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7);
521 sljit_emit_op2(compiler
, SLJIT_XOR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_IMM
, (sljit_sw
)0xff00ff00, SLJIT_R0
, 0);
522 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0xff00ff00);
523 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x0f);
524 sljit_emit_op2(compiler
, SLJIT_AND
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0x888888, SLJIT_R1
, 0);
525 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
527 code
.code
= sljit_generate_code(compiler
);
529 sljit_free_compiler(compiler
);
531 FAILED(code
.func1((sljit_sw
)&buf
) != 0x8808, "test7 case 1 failed\n");
532 FAILED(buf
[0] != 0x0F807F00, "test7 case 2 failed\n");
533 FAILED(buf
[1] != 0x0F7F7F7F, "test7 case 3 failed\n");
534 FAILED(buf
[2] != 0x00F0F08F, "test7 case 4 failed\n");
535 FAILED(buf
[3] != 0x00A0A0A0, "test7 case 5 failed\n");
536 FAILED(buf
[4] != 0x00FF80B0, "test7 case 6 failed\n");
537 FAILED(buf
[5] != 0x00FF4040, "test7 case 7 failed\n");
538 FAILED(buf
[6] != (sljit_sw
)0xa56c82c0, "test7 case 8 failed\n");
539 FAILED(buf
[7] != 0x3b3a8095, "test7 case 9 failed\n");
541 sljit_free_code(code
.code
, NULL
);
545 static void test8(void)
547 /* Test flags (neg, cmp, test). */
548 executable_code code
;
549 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
553 printf("Run test8\n");
555 FAILED(!compiler
, "cannot create compiler\n");
570 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 2, 0, 0, 0);
571 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 20);
572 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 10);
573 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_IMM
, 6, SLJIT_IMM
, 5);
574 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_NOT_EQUAL
);
575 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_EQUAL
);
576 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 3000);
577 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_GREATER
);
578 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 3000);
579 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_S1
, 0);
580 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_LESS
);
581 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R2
, 0);
582 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, -15);
583 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_SIG_GREATER
);
584 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R2
, 0);
585 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -(sljit_sw
)(~(sljit_uw
)0 >> 1) - 1);
586 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0);
587 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
588 sljit_emit_op1(compiler
, SLJIT_NEG
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0);
589 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_OVERFLOW
);
590 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
591 sljit_emit_op1(compiler
, SLJIT_NOT
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R0
, 0);
592 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_ZERO
);
593 sljit_emit_op1(compiler
, SLJIT_NOT
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R1
, 0);
594 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_ZERO
);
595 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_IMM
, 0xffff, SLJIT_R0
, 0);
596 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 0xffff);
597 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_NOT_ZERO
);
598 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_IMM
, 0xffff, SLJIT_R1
, 0);
599 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_IMM
, 0xffff);
600 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
601 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
602 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
603 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0x1);
604 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, SLJIT_NOT_ZERO
);
605 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -(sljit_sw
)(~(sljit_uw
)0 >> 1) - 1);
606 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
607 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0);
608 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 11, SLJIT_OVERFLOW
);
609 sljit_emit_op2u(compiler
, SLJIT_ADD
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0);
610 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 12, SLJIT_OVERFLOW
);
611 sljit_emit_return_void(compiler
);
613 code
.code
= sljit_generate_code(compiler
);
615 sljit_free_compiler(compiler
);
617 code
.func1((sljit_sw
)&buf
);
618 FAILED(buf
[1] != 1, "test8 case 1 failed\n");
619 FAILED(buf
[2] != 0, "test8 case 2 failed\n");
620 FAILED(buf
[3] != 0, "test8 case 3 failed\n");
621 FAILED(buf
[4] != 1, "test8 case 4 failed\n");
622 FAILED(buf
[5] != 1, "test8 case 5 failed\n");
623 FAILED(buf
[6] != 1, "test8 case 6 failed\n");
624 FAILED(buf
[7] != 1, "test8 case 7 failed\n");
625 FAILED(buf
[8] != 0, "test8 case 8 failed\n");
626 FAILED(buf
[9] != 1, "test8 case 9 failed\n");
627 FAILED(buf
[10] != 0, "test8 case 10 failed\n");
628 FAILED(buf
[11] != 1, "test8 case 11 failed\n");
629 FAILED(buf
[12] != 0, "test8 case 12 failed\n");
631 sljit_free_code(code
.code
, NULL
);
635 static void test9(void)
638 executable_code code
;
639 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
641 #ifdef SLJIT_PREF_SHIFT_REG
642 sljit_s32 shift_reg
= SLJIT_PREF_SHIFT_REG
;
644 sljit_s32 shift_reg
= SLJIT_R2
;
647 SLJIT_ASSERT(shift_reg
>= SLJIT_R2
&& shift_reg
<= SLJIT_R3
);
650 printf("Run test9\n");
652 FAILED(!compiler
, "cannot create compiler\n");
667 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 4, 2, 0, 0, 0);
668 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xf);
669 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 3);
670 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
671 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
672 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
673 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R1
, 0, SLJIT_IMM
, 1);
674 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -64);
675 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 2);
676 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, shift_reg
, 0);
678 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0xff);
679 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
680 sljit_emit_op2(compiler
, SLJIT_SHL
, shift_reg
, 0, shift_reg
, 0, SLJIT_R0
, 0);
681 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, shift_reg
, 0);
682 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0xff);
683 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
684 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);
685 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, shift_reg
, 0, SLJIT_R0
, 0);
687 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, 0xf);
688 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
689 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_S1
, 0, SLJIT_S1
, 0, SLJIT_R0
, 0);
690 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_S1
, 0);
691 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_R0
, 0);
692 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_R0
, 0);
693 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0xf00);
694 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
695 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R1
, 0, SLJIT_R2
, 0, SLJIT_R0
, 0);
696 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_R1
, 0);
698 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)buf
);
699 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 9);
700 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
);
702 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 4);
703 sljit_emit_op2(compiler
, SLJIT_SHL
, shift_reg
, 0, SLJIT_IMM
, 2, shift_reg
, 0);
704 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, shift_reg
, 0);
706 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xa9);
707 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
708 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x7d00);
709 sljit_emit_op2(compiler
, SLJIT_LSHR32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 32);
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_R1
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
714 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xe30000);
715 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
716 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffc0);
718 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffe0);
720 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
721 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x25000000);
722 sljit_emit_op2(compiler
, SLJIT_SHL32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xfffe1);
723 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
724 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
726 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 11, SLJIT_R1
, 0, SLJIT_R0
, 0);
728 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0);
729 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x5c);
730 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R1
, 0, SLJIT_R0
, 0, shift_reg
, 0);
731 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0xf600);
732 sljit_emit_op2(compiler
, SLJIT_LSHR32
, SLJIT_R0
, 0, SLJIT_R0
, 0, shift_reg
, 0);
733 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
734 /* Alternative form of uint32 type cast. */
735 sljit_emit_op2(compiler
, SLJIT_AND
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffffffff);
737 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
738 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x630000);
739 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, shift_reg
, 0);
740 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 12, SLJIT_R1
, 0, SLJIT_R0
, 0);
742 sljit_emit_return_void(compiler
);
744 code
.code
= sljit_generate_code(compiler
);
746 sljit_free_compiler(compiler
);
748 code
.func1((sljit_sw
)&buf
);
749 FAILED(buf
[0] != 0x3c, "test9 case 1 failed\n");
750 FAILED(buf
[1] != 0xf0, "test9 case 2 failed\n");
751 FAILED(buf
[2] != -16, "test9 case 3 failed\n");
752 FAILED(buf
[3] != 0xff0, "test9 case 4 failed\n");
753 FAILED(buf
[4] != 4, "test9 case 5 failed\n");
754 FAILED(buf
[5] != 0xff00, "test9 case 6 failed\n");
755 FAILED(buf
[6] != 0x3c, "test9 case 7 failed\n");
756 FAILED(buf
[7] != 0xf0, "test9 case 8 failed\n");
757 FAILED(buf
[8] != 0xf0, "test9 case 9 failed\n");
758 FAILED(buf
[9] != 0x18, "test9 case 10 failed\n");
759 FAILED(buf
[10] != 32, "test9 case 11 failed\n");
760 FAILED(buf
[11] != 0x4ae37da9, "test9 case 12 failed\n");
761 FAILED(buf
[12] != 0x63f65c, "test9 case 13 failed\n");
763 sljit_free_code(code
.code
, NULL
);
767 static void test10(void)
769 /* Test multiplications. */
770 executable_code code
;
771 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
775 printf("Run test10\n");
777 FAILED(!compiler
, "cannot create compiler\n");
786 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 0);
787 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
788 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
789 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
790 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 7);
791 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 8);
792 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
793 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_IMM
, -3, SLJIT_IMM
, -4);
794 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0);
795 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -2);
796 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);
797 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
) / 2);
798 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[3]);
799 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);
800 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 9);
801 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R0
, 0);
802 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R0
, 0);
803 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
804 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3);
805 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x123456789));
806 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_R0
, 0);
808 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 11, SLJIT_IMM
, 10);
809 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
811 code
.code
= sljit_generate_code(compiler
);
813 sljit_free_compiler(compiler
);
815 FAILED(code
.func1((sljit_sw
)&buf
) != 110, "test10 case 1 failed\n");
816 FAILED(buf
[0] != 15, "test10 case 2 failed\n");
817 FAILED(buf
[1] != 56, "test10 case 3 failed\n");
818 FAILED(buf
[2] != 12, "test10 case 4 failed\n");
819 FAILED(buf
[3] != -12, "test10 case 5 failed\n");
820 FAILED(buf
[4] != 100, "test10 case 6 failed\n");
821 FAILED(buf
[5] != 81, "test10 case 7 failed\n");
822 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
823 FAILED(buf
[6] != SLJIT_W(0x123456789) * 3, "test10 case 8 failed\n");
826 sljit_free_code(code
.code
, NULL
);
830 static void test11(void)
832 /* Test rewritable constants. */
833 executable_code code
;
834 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
835 struct sljit_const
* const1
;
836 struct sljit_const
* const2
;
837 struct sljit_const
* const3
;
838 struct sljit_const
* const4
;
840 sljit_sw executable_offset
;
841 sljit_uw const1_addr
;
842 sljit_uw const2_addr
;
843 sljit_uw const3_addr
;
844 sljit_uw const4_addr
;
845 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
846 sljit_sw word_value1
= (sljit_sw
)SLJIT_W(0xaaaaaaaaaaaaaaaa);
847 sljit_sw word_value2
= (sljit_sw
)SLJIT_W(0xfee1deadfbadf00d);
849 sljit_sw word_value1
= (sljit_sw
)0xaaaaaaaal
;
850 sljit_sw word_value2
= (sljit_sw
)0xfbadf00dl
;
855 printf("Run test11\n");
857 FAILED(!compiler
, "cannot create compiler\n");
862 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 0);
864 SLJIT_ASSERT(!sljit_alloc_memory(compiler
, 0));
865 SLJIT_ASSERT(!sljit_alloc_memory(compiler
, 16 * sizeof(sljit_sw
) + 1));
867 const1
= sljit_emit_const(compiler
, SLJIT_MEM0(), (sljit_sw
)&buf
[0], -0x81b9);
869 value
= sljit_alloc_memory(compiler
, 16 * sizeof(sljit_sw
));
872 SLJIT_ASSERT(!((sljit_sw
)value
& ((sljit_sw
)sizeof(sljit_sw
) - 1)));
873 memset(value
, 255, 16 * sizeof(sljit_sw
));
876 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
877 const2
= sljit_emit_const(compiler
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), SLJIT_WORD_SHIFT
- 1, -65535);
878 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[0] + 2 * (sljit_sw
)sizeof(sljit_sw
) - 2);
879 const3
= sljit_emit_const(compiler
, SLJIT_MEM1(SLJIT_R0
), 0, word_value1
);
881 value
= sljit_alloc_memory(compiler
, 17);
884 SLJIT_ASSERT(!((sljit_sw
)value
& ((sljit_sw
)sizeof(sljit_sw
) - 1)));
885 memset(value
, 255, 16);
888 const4
= sljit_emit_const(compiler
, SLJIT_RETURN_REG
, 0, (sljit_sw
)0xf7afcdb7);
890 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
892 code
.code
= sljit_generate_code(compiler
);
894 executable_offset
= sljit_get_executable_offset(compiler
);
895 const1_addr
= sljit_get_const_addr(const1
);
896 const2_addr
= sljit_get_const_addr(const2
);
897 const3_addr
= sljit_get_const_addr(const3
);
898 const4_addr
= sljit_get_const_addr(const4
);
899 sljit_free_compiler(compiler
);
901 FAILED(code
.func1((sljit_sw
)&buf
) != (sljit_sw
)0xf7afcdb7, "test11 case 1 failed\n");
902 FAILED(buf
[0] != -0x81b9, "test11 case 2 failed\n");
903 FAILED(buf
[1] != -65535, "test11 case 3 failed\n");
904 FAILED(buf
[2] != word_value1
, "test11 case 4 failed\n");
906 sljit_set_const(const1_addr
, -1, executable_offset
);
907 sljit_set_const(const2_addr
, word_value2
, executable_offset
);
908 sljit_set_const(const3_addr
, (sljit_sw
)0xbab0fea1, executable_offset
);
909 sljit_set_const(const4_addr
, -60089, executable_offset
);
911 FAILED(code
.func1((sljit_sw
)&buf
) != -60089, "test11 case 5 failed\n");
912 FAILED(buf
[0] != -1, "test11 case 6 failed\n");
913 FAILED(buf
[1] != word_value2
, "test11 case 7 failed\n");
914 FAILED(buf
[2] != (sljit_sw
)0xbab0fea1, "test11 case 8 failed\n");
916 sljit_free_code(code
.code
, NULL
);
920 static void test12(void)
922 /* Test rewriteable jumps. */
923 executable_code code
;
924 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
925 struct sljit_label
*label1
;
926 struct sljit_label
*label2
;
927 struct sljit_label
*label3
;
928 struct sljit_jump
*jump1
;
929 struct sljit_jump
*jump2
;
930 struct sljit_jump
*jump3
;
931 sljit_sw executable_offset
;
934 sljit_uw label1_addr
;
935 sljit_uw label2_addr
;
939 printf("Run test12\n");
941 FAILED(!compiler
, "cannot create compiler\n");
944 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, W
), 3, 2, 0, 0, 0);
945 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_S1
, 0, SLJIT_IMM
, 10);
946 jump1
= sljit_emit_jump(compiler
, SLJIT_REWRITABLE_JUMP
| SLJIT_SIG_GREATER
);
947 /* Default handler. */
948 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 5);
949 jump2
= sljit_emit_jump(compiler
, SLJIT_JUMP
);
951 value
= sljit_alloc_memory(compiler
, 15);
954 SLJIT_ASSERT(!((sljit_sw
)value
& ((sljit_sw
)sizeof(sljit_sw
) - 1)));
955 memset(value
, 255, 15);
959 label1
= sljit_emit_label(compiler
);
960 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
961 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 6);
962 jump3
= sljit_emit_jump(compiler
, SLJIT_JUMP
);
964 label2
= sljit_emit_label(compiler
);
965 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
966 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 7);
968 label3
= sljit_emit_label(compiler
);
969 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
970 sljit_set_label(jump2
, label3
);
971 sljit_set_label(jump3
, label3
);
972 /* By default, set to handler 1. */
973 sljit_set_label(jump1
, label1
);
974 sljit_emit_return_void(compiler
);
976 value
= sljit_alloc_memory(compiler
, 8);
979 SLJIT_ASSERT(!((sljit_sw
)value
& ((sljit_sw
)sizeof(sljit_sw
) - 1)));
980 memset(value
, 255, 8);
983 code
.code
= sljit_generate_code(compiler
);
985 executable_offset
= sljit_get_executable_offset(compiler
);
986 jump1_addr
= sljit_get_jump_addr(jump1
);
987 label1_addr
= sljit_get_label_addr(label1
);
988 label2_addr
= sljit_get_label_addr(label2
);
989 sljit_free_compiler(compiler
);
991 code
.func2((sljit_sw
)&buf
, 4);
992 FAILED(buf
[0] != 5, "test12 case 1 failed\n");
994 code
.func2((sljit_sw
)&buf
, 11);
995 FAILED(buf
[0] != 6, "test12 case 2 failed\n");
997 sljit_set_jump_addr(jump1_addr
, label2_addr
, executable_offset
);
998 code
.func2((sljit_sw
)&buf
, 12);
999 FAILED(buf
[0] != 7, "test12 case 3 failed\n");
1001 sljit_set_jump_addr(jump1_addr
, label1_addr
, executable_offset
);
1002 code
.func2((sljit_sw
)&buf
, 13);
1003 FAILED(buf
[0] != 6, "test12 case 4 failed\n");
1005 sljit_free_code(code
.code
, NULL
);
1009 static void test13(void)
1011 /* Test fpu monadic functions. */
1012 executable_code code
;
1013 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1018 printf("Run test13\n");
1020 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
1022 printf("no fpu available, test13 skipped\n");
1025 sljit_free_compiler(compiler
);
1029 FAILED(!compiler
, "cannot create compiler\n");
1045 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 3, 2, 6, 0, 0);
1046 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&buf
[2], SLJIT_MEM0(), (sljit_sw
)&buf
[1]);
1047 sljit_emit_fop1(compiler
, SLJIT_ABS_F64
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1048 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
1049 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2 * sizeof(sljit_f64
));
1050 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 0);
1051 sljit_emit_fop1(compiler
, SLJIT_NEG_F64
, SLJIT_FR2
, 0, SLJIT_FR0
, 0);
1052 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_FR2
, 0);
1053 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&buf
[4], SLJIT_FR3
, 0);
1054 sljit_emit_fop1(compiler
, SLJIT_ABS_F64
, SLJIT_FR4
, 0, SLJIT_FR1
, 0);
1055 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f64
), SLJIT_FR4
, 0);
1056 sljit_emit_fop1(compiler
, SLJIT_NEG_F64
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
), SLJIT_FR4
, 0);
1058 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
1059 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_GREATER_F
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1060 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_GREATER_F64
);
1061 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_GREATER_F
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
), SLJIT_FR5
, 0);
1062 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
), SLJIT_GREATER_F64
);
1063 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_FR5
, 0);
1064 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR1
, 0);
1065 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
), SLJIT_EQUAL_F64
);
1066 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_LESS_F
, SLJIT_FR1
, 0, SLJIT_FR1
, 0);
1067 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
), SLJIT_LESS_F64
);
1068 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1069 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_EQUAL_F64
);
1070 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_NOT_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1071 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_NOT_EQUAL_F64
);
1073 sljit_emit_return_void(compiler
);
1075 code
.code
= sljit_generate_code(compiler
);
1077 sljit_free_compiler(compiler
);
1079 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&buf2
);
1080 FAILED(buf
[2] != -4.5, "test13 case 1 failed\n");
1081 FAILED(buf
[3] != 4.5, "test13 case 2 failed\n");
1082 FAILED(buf
[4] != -7.75, "test13 case 3 failed\n");
1083 FAILED(buf
[5] != 4.5, "test13 case 4 failed\n");
1084 FAILED(buf
[6] != -4.5, "test13 case 5 failed\n");
1086 FAILED(buf2
[0] != 1, "test13 case 6 failed\n");
1087 FAILED(buf2
[1] != 0, "test13 case 7 failed\n");
1088 FAILED(buf2
[2] != 1, "test13 case 8 failed\n");
1089 FAILED(buf2
[3] != 0, "test13 case 9 failed\n");
1090 FAILED(buf2
[4] != 0, "test13 case 10 failed\n");
1091 FAILED(buf2
[5] != 1, "test13 case 11 failed\n");
1093 sljit_free_code(code
.code
, NULL
);
1097 static void test14(void)
1099 /* Test fpu diadic functions. */
1100 executable_code code
;
1101 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1105 printf("Run test14\n");
1107 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
1109 printf("no fpu available, test14 skipped\n");
1112 sljit_free_compiler(compiler
);
1131 FAILED(!compiler
, "cannot create compiler\n");
1132 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 6, 0, 0);
1135 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_f64
));
1136 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1137 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2);
1138 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);
1139 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_FR1
, 0);
1140 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR1
, 0, SLJIT_FR0
, 0, SLJIT_FR1
, 0);
1141 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 4, SLJIT_FR0
, 0);
1142 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 5, SLJIT_FR1
, 0);
1145 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
1146 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2);
1147 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 2);
1148 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
);
1149 sljit_emit_fop2(compiler
, SLJIT_SUB_F64
, SLJIT_FR2
, 0, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2);
1150 sljit_emit_fop2(compiler
, SLJIT_SUB_F64
, SLJIT_FR3
, 0, SLJIT_FR2
, 0, SLJIT_FR3
, 0);
1151 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 7, SLJIT_FR2
, 0);
1152 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 8, SLJIT_FR3
, 0);
1155 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
1156 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);
1157 sljit_emit_fop2(compiler
, SLJIT_MUL_F64
, SLJIT_FR1
, 0, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
1158 sljit_emit_fop2(compiler
, SLJIT_MUL_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2, SLJIT_FR2
, 0);
1159 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 10, SLJIT_FR1
, 0);
1160 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 11, SLJIT_FR5
, 0);
1163 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 12);
1164 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 13);
1165 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR4
, 0, SLJIT_FR5
, 0);
1166 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);
1167 sljit_emit_fop2(compiler
, SLJIT_DIV_F64
, SLJIT_FR5
, 0, SLJIT_FR5
, 0, SLJIT_FR1
, 0);
1168 sljit_emit_fop2(compiler
, SLJIT_DIV_F64
, SLJIT_FR4
, 0, SLJIT_FR1
, 0, SLJIT_FR4
, 0);
1169 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 13, SLJIT_FR5
, 0);
1170 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 14, SLJIT_FR4
, 0);
1172 sljit_emit_return_void(compiler
);
1174 code
.code
= sljit_generate_code(compiler
);
1176 sljit_free_compiler(compiler
);
1178 code
.func1((sljit_sw
)&buf
);
1179 FAILED(buf
[3] != 10.75, "test14 case 1 failed\n");
1180 FAILED(buf
[4] != 5.25, "test14 case 2 failed\n");
1181 FAILED(buf
[5] != 7.0, "test14 case 3 failed\n");
1182 FAILED(buf
[6] != 0.0, "test14 case 4 failed\n");
1183 FAILED(buf
[7] != 5.5, "test14 case 5 failed\n");
1184 FAILED(buf
[8] != 3.75, "test14 case 6 failed\n");
1185 FAILED(buf
[9] != 24.5, "test14 case 7 failed\n");
1186 FAILED(buf
[10] != 38.5, "test14 case 8 failed\n");
1187 FAILED(buf
[11] != 9.625, "test14 case 9 failed\n");
1188 FAILED(buf
[12] != 2.0, "test14 case 10 failed\n");
1189 FAILED(buf
[13] != 2.0, "test14 case 11 failed\n");
1190 FAILED(buf
[14] != 0.5, "test14 case 12 failed\n");
1192 sljit_free_code(code
.code
, NULL
);
1196 static sljit_sw SLJIT_FUNC
func(sljit_sw a
, sljit_sw b
, sljit_sw c
)
1198 return a
+ b
+ c
+ 5;
1201 static void test15(void)
1203 /* Test function call. */
1204 executable_code code
;
1205 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1206 struct sljit_jump
* jump
= NULL
;
1210 printf("Run test15\n");
1212 FAILED(!compiler
, "cannot create compiler\n");
1219 buf
[6] = SLJIT_FUNC_ADDR(func
);
1221 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 4, 1, 0, 0, 0);
1223 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
1224 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 7);
1225 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -3);
1226 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(func
));
1227 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_RETURN_REG
, 0);
1229 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -5);
1230 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -10);
1231 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2);
1232 jump
= sljit_emit_call(compiler
, SLJIT_CALL
| SLJIT_REWRITABLE_JUMP
, SLJIT_ARGS3(W
, W
, W
, W
));
1233 sljit_set_target(jump
, (sljit_uw
)-1);
1234 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1236 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(func
));
1237 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 40);
1238 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -3);
1239 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_R0
, 0);
1240 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1242 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -60);
1243 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(func
));
1244 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -30);
1245 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_R1
, 0);
1246 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * 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
, SLJIT_FUNC_ADDR(func
));
1251 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_R2
, 0);
1252 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1254 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 100);
1255 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 110);
1256 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 120);
1257 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(func
));
1258 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_R3
, 0);
1259 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1261 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -10);
1262 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -16);
1263 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 6);
1264 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
));
1265 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1267 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1269 code
.code
= sljit_generate_code(compiler
);
1271 sljit_set_jump_addr(sljit_get_jump_addr(jump
), SLJIT_FUNC_UADDR(func
), sljit_get_executable_offset(compiler
));
1272 sljit_free_compiler(compiler
);
1274 FAILED(code
.func1((sljit_sw
)&buf
) != -15, "test15 case 1 failed\n");
1275 FAILED(buf
[0] != 14, "test15 case 2 failed\n");
1276 FAILED(buf
[1] != -8, "test15 case 3 failed\n");
1277 FAILED(buf
[2] != SLJIT_FUNC_ADDR(func
) + 42, "test15 case 4 failed\n");
1278 FAILED(buf
[3] != SLJIT_FUNC_ADDR(func
) - 85, "test15 case 5 failed\n");
1279 FAILED(buf
[4] != SLJIT_FUNC_ADDR(func
) + 31, "test15 case 6 failed\n");
1280 FAILED(buf
[5] != 335, "test15 case 7 failed\n");
1281 FAILED(buf
[6] != -15, "test15 case 8 failed\n");
1283 sljit_free_code(code
.code
, NULL
);
1287 static void test16(void)
1289 /* Ackermann benchmark. */
1290 executable_code code
;
1291 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1292 struct sljit_label
*entry
;
1293 struct sljit_label
*label
;
1294 struct sljit_jump
*jump
;
1295 struct sljit_jump
*jump1
;
1296 struct sljit_jump
*jump2
;
1299 printf("Run test16\n");
1301 FAILED(!compiler
, "cannot create compiler\n");
1303 entry
= sljit_emit_label(compiler
);
1304 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(W
, W
, W
), 3, 2, 0, 0, 0);
1306 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_S0
, 0, SLJIT_IMM
, 0);
1307 jump1
= sljit_emit_jump(compiler
, SLJIT_EQUAL
);
1309 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_S1
, 0, SLJIT_IMM
, 0);
1310 jump2
= sljit_emit_jump(compiler
, SLJIT_EQUAL
);
1313 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
1314 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 1);
1315 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS2(W
, W
, W
));
1316 sljit_set_label(jump
, entry
);
1318 /* Returns with Ack(x-1, Ack(x,y-1)). */
1319 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_RETURN_REG
, 0);
1320 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
1321 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS2(W
, W
, W
));
1322 sljit_set_label(jump
, entry
);
1323 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1325 /* Returns with y+1. */
1326 label
= sljit_emit_label(compiler
);
1327 sljit_set_label(jump1
, label
);
1328 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 1, SLJIT_S1
, 0);
1329 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1331 /* Returns with Ack(x-1,1) */
1332 label
= sljit_emit_label(compiler
);
1333 sljit_set_label(jump2
, label
);
1334 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
1335 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
1336 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS2(W
, W
, W
));
1337 sljit_set_label(jump
, entry
);
1338 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1340 code
.code
= sljit_generate_code(compiler
);
1342 sljit_free_compiler(compiler
);
1344 FAILED(code
.func2(3, 3) != 61, "test16 case 1 failed\n");
1345 /* For benchmarking. */
1346 /* FAILED(code.func2(3, 11) != 16381, "test16 case 1 failed\n"); */
1348 sljit_free_code(code
.code
, NULL
);
1352 static void test17(void)
1354 /* Test arm constant pool. */
1355 executable_code code
;
1356 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1361 printf("Run test17\n");
1363 FAILED(!compiler
, "cannot create compiler\n");
1365 for (i
= 0; i
< 5; i
++)
1368 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 0, 0, 0);
1369 for (i
= 0; i
<= 0xfff; i
++) {
1370 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x81818000 | i
);
1371 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x81818000 | i
);
1372 if ((i
& 0x3ff) == 0)
1373 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), (i
>> 10) * (sljit_sw
)sizeof(sljit_sw
), SLJIT_R0
, 0);
1375 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1376 sljit_emit_return_void(compiler
);
1378 code
.code
= sljit_generate_code(compiler
);
1380 sljit_free_compiler(compiler
);
1382 code
.func1((sljit_sw
)&buf
);
1383 FAILED((sljit_uw
)buf
[0] != 0x81818000, "test17 case 1 failed\n");
1384 FAILED((sljit_uw
)buf
[1] != 0x81818400, "test17 case 2 failed\n");
1385 FAILED((sljit_uw
)buf
[2] != 0x81818800, "test17 case 3 failed\n");
1386 FAILED((sljit_uw
)buf
[3] != 0x81818c00, "test17 case 4 failed\n");
1387 FAILED((sljit_uw
)buf
[4] != 0x81818fff, "test17 case 5 failed\n");
1389 sljit_free_code(code
.code
, NULL
);
1393 static void test18(void)
1396 executable_code code
;
1397 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1401 printf("Run test18\n");
1403 FAILED(!compiler
, "cannot create compiler\n");
1414 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1415 buf
[10] = SLJIT_W(1) << 32;
1420 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 2, 0, 0, 0);
1422 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1423 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, SLJIT_W(0x1122334455667788));
1424 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x1122334455667788));
1426 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(1000000000000));
1427 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(1000000000000));
1428 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_IMM
, SLJIT_W(5000000000000), SLJIT_R0
, 0);
1430 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x1108080808));
1431 sljit_emit_op2(compiler
, SLJIT_ADD32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x1120202020));
1433 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1108080808));
1434 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1120202020));
1435 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_ZERO
);
1436 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_S1
, 0);
1437 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
1438 sljit_emit_op2u(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1120202020));
1439 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_ZERO
);
1441 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1108080808));
1442 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x2208080808));
1443 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_LESS
);
1444 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
1445 sljit_emit_op2u(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1104040404));
1446 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_NOT_ZERO
);
1448 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
1449 sljit_emit_op2(compiler
, SLJIT_SHL32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_IMM
, SLJIT_W(0xffff0000), SLJIT_R0
, 0);
1451 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);
1453 /* 32 bit operations. */
1455 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0x11223344);
1456 sljit_emit_op2(compiler
, SLJIT_ADD32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 0x44332211);
1460 sljit_emit_return_void(compiler
);
1462 code
.code
= sljit_generate_code(compiler
);
1464 sljit_free_compiler(compiler
);
1466 code
.func1((sljit_sw
)&buf
);
1467 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1468 FAILED(buf
[0] != SLJIT_W(0x1122334455667788), "test18 case 1 failed\n");
1469 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1470 FAILED(buf
[1] != 0x55667788, "test18 case 2 failed\n");
1472 FAILED(buf
[1] != SLJIT_W(0x5566778800000000), "test18 case 2 failed\n");
1474 FAILED(buf
[2] != SLJIT_W(2000000000000), "test18 case 3 failed\n");
1475 FAILED(buf
[3] != SLJIT_W(4000000000000), "test18 case 4 failed\n");
1476 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1477 FAILED(buf
[4] != 0x28282828, "test18 case 5 failed\n");
1479 FAILED(buf
[4] != SLJIT_W(0x2828282800000000), "test18 case 5 failed\n");
1481 FAILED(buf
[5] != 0, "test18 case 6 failed\n");
1482 FAILED(buf
[6] != 1, "test18 case 7 failed\n");
1483 FAILED(buf
[7] != 1, "test18 case 8 failed\n");
1484 FAILED(buf
[8] != 0, "test18 case 9 failed\n");
1485 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1486 FAILED(buf
[9] != (sljit_sw
)0xfff00000, "test18 case 10 failed\n");
1487 FAILED(buf
[10] != (sljit_sw
)0xffffffff, "test18 case 11 failed\n");
1489 FAILED(buf
[9] != (sljit_sw
)SLJIT_W(0xfff0000000000000), "test18 case 10 failed\n");
1490 FAILED(buf
[10] != (sljit_sw
)SLJIT_W(0xffffffff00000000), "test18 case 11 failed\n");
1493 FAILED(buf
[0] != 0x11223344, "test18 case 1 failed\n");
1494 FAILED(buf
[1] != 0x44332211, "test18 case 2 failed\n");
1497 sljit_free_code(code
.code
, NULL
);
1501 static void test19(void)
1503 /* Test arm partial instruction caching. */
1504 executable_code code
;
1505 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1509 printf("Run test19\n");
1511 FAILED(!compiler
, "cannot create compiler\n");
1521 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 0, 0, 0);
1522 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
1523 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM0(), (sljit_sw
)&buf
[2], SLJIT_MEM0(), (sljit_sw
)&buf
[1], SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
1524 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
1525 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1526 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]);
1527 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_MEM0(), (sljit_sw
)&buf
[0], SLJIT_IMM
, 2);
1528 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&buf
[0] + 4 * (sljit_sw
)sizeof(sljit_sw
));
1529 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_IMM
, 10);
1530 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 7);
1531 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]);
1533 sljit_emit_return_void(compiler
);
1535 code
.code
= sljit_generate_code(compiler
);
1537 sljit_free_compiler(compiler
);
1539 code
.func1((sljit_sw
)&buf
);
1540 FAILED(buf
[0] != 10, "test19 case 1 failed\n");
1541 FAILED(buf
[1] != 4, "test19 case 2 failed\n");
1542 FAILED(buf
[2] != 14, "test19 case 3 failed\n");
1543 FAILED(buf
[3] != 14, "test19 case 4 failed\n");
1544 FAILED(buf
[4] != 8, "test19 case 5 failed\n");
1545 FAILED(buf
[5] != 6, "test19 case 6 failed\n");
1546 FAILED(buf
[6] != 12, "test19 case 7 failed\n");
1547 FAILED(buf
[7] != 10, "test19 case 8 failed\n");
1549 sljit_free_code(code
.code
, NULL
);
1553 static void test20(void)
1556 executable_code code
;
1557 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1558 struct sljit_jump
* jump
;
1559 struct sljit_label
* label
;
1561 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1562 sljit_sw offset_value
= SLJIT_W(0x1234567812345678);
1564 sljit_sw offset_value
= SLJIT_W(0x12345678);
1568 printf("Run test20\n");
1570 FAILED(!compiler
, "cannot create compiler\n");
1578 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 5, 5, 0, 0, 4 * sizeof(sljit_sw
));
1579 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
), SLJIT_MEM1(SLJIT_S0
), 0);
1580 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
));
1581 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -1);
1582 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, -1);
1583 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, -1);
1584 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_IMM
, -1);
1585 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
));
1586 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);
1587 sljit_get_local_base(compiler
, SLJIT_R0
, 0, -offset_value
);
1588 sljit_get_local_base(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, -0x1234);
1589 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
1590 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
));
1591 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_uw
));
1592 /* Dummy last instructions. */
1593 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 23);
1594 sljit_emit_label(compiler
);
1596 code
.code
= sljit_generate_code(compiler
);
1598 sljit_free_compiler(compiler
);
1600 FAILED(code
.func1((sljit_sw
)&buf
) != -12345, "test20 case 1 failed\n")
1602 FAILED(buf
[2] != 60, "test20 case 2 failed\n");
1603 FAILED(buf
[3] != 17, "test20 case 3 failed\n");
1604 FAILED(buf
[4] != 7, "test20 case 4 failed\n");
1606 sljit_free_code(code
.code
, NULL
);
1608 compiler
= sljit_create_compiler(NULL
, NULL
);
1609 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(W
, W
, W
, W
), 3, 3, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
1611 sljit_get_local_base(compiler
, SLJIT_R0
, 0, SLJIT_MAX_LOCAL_SIZE
- sizeof(sljit_sw
));
1612 sljit_get_local_base(compiler
, SLJIT_R1
, 0, -(sljit_sw
)sizeof(sljit_sw
));
1613 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -1);
1614 label
= sljit_emit_label(compiler
);
1615 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1616 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0, SLJIT_R2
, 0);
1617 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R0
, 0);
1618 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_EQUAL
);
1619 sljit_set_label(jump
, label
);
1621 /* Saved registers should keep their value. */
1622 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_S1
, 0);
1623 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_S2
, 0);
1624 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
1626 code
.code
= sljit_generate_code(compiler
);
1628 sljit_free_compiler(compiler
);
1630 FAILED(code
.func3(1234, 5678, 9012) != 15924, "test20 case 5 failed\n");
1632 sljit_free_code(code
.code
, NULL
);
1634 compiler
= sljit_create_compiler(NULL
, NULL
);
1635 sljit_emit_enter(compiler
, SLJIT_F64_ALIGNMENT
, SLJIT_ARGS0(W
), 3, 0, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
1637 sljit_get_local_base(compiler
, SLJIT_R0
, 0, SLJIT_MAX_LOCAL_SIZE
- sizeof(sljit_sw
));
1638 sljit_get_local_base(compiler
, SLJIT_R1
, 0, -(sljit_sw
)sizeof(sljit_sw
));
1639 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -1);
1640 label
= sljit_emit_label(compiler
);
1641 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1642 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0, SLJIT_R2
, 0);
1643 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R0
, 0);
1644 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_EQUAL
);
1645 sljit_set_label(jump
, label
);
1647 sljit_get_local_base(compiler
, SLJIT_R0
, 0, 0);
1648 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
1650 code
.code
= sljit_generate_code(compiler
);
1652 sljit_free_compiler(compiler
);
1654 FAILED((sljit_uw
)code
.func0() % sizeof(sljit_f64
) != 0, "test20 case 6 failed\n");
1656 sljit_free_code(code
.code
, NULL
);
1660 static void test21(void)
1662 /* Test set context. The parts of the jit code can be separated in the memory. */
1663 executable_code code1
;
1664 executable_code code2
;
1665 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1666 struct sljit_jump
* jump
= NULL
;
1668 sljit_sw executable_offset
;
1672 printf("Run test21\n");
1674 FAILED(!compiler
, "cannot create compiler\n");
1680 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 2, 0, 0, 2 * sizeof(sljit_sw
));
1682 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 10);
1683 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_SP
), 0);
1685 jump
= sljit_emit_jump(compiler
, SLJIT_JUMP
| SLJIT_REWRITABLE_JUMP
);
1686 sljit_set_target(jump
, 0);
1688 code1
.code
= sljit_generate_code(compiler
);
1691 executable_offset
= sljit_get_executable_offset(compiler
);
1692 addr
= sljit_get_jump_addr(jump
);
1694 sljit_free_compiler(compiler
);
1696 compiler
= sljit_create_compiler(NULL
, NULL
);
1697 FAILED(!compiler
, "cannot create compiler\n");
1699 /* Other part of the jit code. */
1700 sljit_set_context(compiler
, 0, 1, 3, 2, 0, 0, 2 * sizeof(sljit_sw
));
1702 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
1703 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);
1704 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_MEM1(SLJIT_SP
), 0);
1705 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_sw
));
1707 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1709 code2
.code
= sljit_generate_code(compiler
);
1711 sljit_free_compiler(compiler
);
1713 sljit_set_jump_addr(addr
, SLJIT_FUNC_UADDR(code2
.code
), executable_offset
);
1715 FAILED(code1
.func1((sljit_sw
)&buf
) != 19, "test21 case 1 failed\n");
1716 FAILED(buf
[2] != -16, "test21 case 2 failed\n");
1717 FAILED(buf
[3] != 100, "test21 case 3 failed\n");
1719 sljit_free_code(code1
.code
, NULL
);
1720 sljit_free_code(code2
.code
, NULL
);
1724 static void test22(void)
1726 /* Test simple byte and half-int data transfers. */
1727 executable_code code
;
1728 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1734 printf("Run test22\n");
1736 FAILED(!compiler
, "cannot create compiler\n");
1756 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 3, 3, 0, 0, 0);
1758 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, -13);
1759 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s16
), SLJIT_IMM
, 0x1234);
1760 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_s16
));
1761 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
1762 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s16
));
1763 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s16
), SLJIT_MEM1(SLJIT_S1
), -(sljit_sw
)sizeof(sljit_s16
));
1764 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xff0000 + 8000);
1765 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 2);
1766 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R1
), 1, SLJIT_R0
, 0);
1767 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0x1234 - 3 * sizeof(sljit_s16
));
1768 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R2
), 0x1234, SLJIT_IMM
, -9317);
1769 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0x1234 + 4 * sizeof(sljit_s16
));
1770 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R2
), -0x1234, SLJIT_IMM
, -9317);
1771 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0x12348 - 5 * sizeof(sljit_s16
));
1772 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R2
), 0x12348, SLJIT_IMM
, -8888);
1773 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0x12348 + 6 * sizeof(sljit_s16
));
1774 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R2
), -0x12348, SLJIT_IMM
, -8888);
1776 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM1(SLJIT_S2
), 0, SLJIT_IMM
, -45);
1777 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_s8
), SLJIT_IMM
, 0x12);
1778 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4 * sizeof(sljit_s8
));
1779 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_s8
));
1780 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_S1
, 0, SLJIT_R1
, 0);
1781 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_S1
, 0, SLJIT_S1
, 0);
1782 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R2
, 0, SLJIT_S1
, 0);
1783 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R2
, 0);
1784 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S2
), 3 * sizeof(sljit_s8
), SLJIT_S1
, 0);
1785 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM2(SLJIT_S2
, SLJIT_R0
), 0, SLJIT_R0
, 0);
1786 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
1787 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
1788 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1789 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
1790 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
1791 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1793 sljit_emit_return_void(compiler
);
1795 code
.code
= sljit_generate_code(compiler
);
1797 sljit_free_compiler(compiler
);
1799 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&sbuf
, (sljit_sw
)&bbuf
);
1800 FAILED(buf
[0] != -9, "test22 case 1 failed\n");
1801 FAILED(buf
[1] != -56, "test22 case 2 failed\n");
1802 FAILED(buf
[2] != 0, "test22 case 3 failed\n");
1803 FAILED(buf
[3] != 0, "test22 case 4 failed\n");
1805 FAILED(sbuf
[0] != -13, "test22 case 5 failed\n");
1806 FAILED(sbuf
[1] != 0x1234, "test22 case 6 failed\n");
1807 FAILED(sbuf
[3] != 0x1234, "test22 case 7 failed\n");
1808 FAILED(sbuf
[4] != 8000, "test22 case 8 failed\n");
1809 FAILED(sbuf
[5] != -9317, "test22 case 9 failed\n");
1810 FAILED(sbuf
[6] != -9317, "test22 case 10 failed\n");
1811 FAILED(sbuf
[7] != -8888, "test22 case 11 failed\n");
1812 FAILED(sbuf
[8] != -8888, "test22 case 12 failed\n");
1814 FAILED(bbuf
[0] != -45, "test22 case 13 failed\n");
1815 FAILED(bbuf
[1] != 0x12, "test22 case 14 failed\n");
1816 FAILED(bbuf
[3] != -56, "test22 case 15 failed\n");
1817 FAILED(bbuf
[4] != 4, "test22 case 16 failed\n");
1819 sljit_free_code(code
.code
, NULL
);
1823 static void test23(void)
1825 /* Test 32 bit / 64 bit signed / unsigned int transfer and conversion.
1826 This test has do real things on 64 bit systems, but works on 32 bit systems as well. */
1827 executable_code code
;
1828 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1833 sljit_u8 asbytes
[4];
1835 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1836 sljit_sw garbage
= SLJIT_W(0x1234567812345678);
1838 sljit_sw garbage
= 0x12345678;
1842 printf("Run test23\n");
1844 FAILED(!compiler
, "cannot create compiler\n");
1861 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(W
, P
, P
), 3, 3, 0, 0, 0);
1862 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, 34567);
1863 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
1864 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), 0, SLJIT_IMM
, -7654);
1865 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, garbage
);
1866 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_s32
));
1867 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
1868 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, garbage
);
1869 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_s32
));
1870 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
1871 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, garbage
);
1872 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_s32
));
1873 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
1874 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1875 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x0f00f00);
1876 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x7777);
1877 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0x7777 + 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1878 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x7777);
1879 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), -0x7777 + 4 * (sljit_sw
)sizeof(sljit_sw
), SLJIT_R0
, 0);
1880 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 5 * sizeof(sljit_sw
));
1881 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 1);
1882 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R1
), 0, SLJIT_IMM
, 16);
1883 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
1884 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1, SLJIT_IMM
, 64, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1);
1885 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)&buf
[7], SLJIT_IMM
, 0x123456);
1886 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&buf
[6], SLJIT_MEM0(), (sljit_sw
)&buf
[7]);
1887 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 5 * sizeof(sljit_sw
));
1888 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 2 * sizeof(sljit_sw
), SLJIT_R1
, 0);
1889 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 7 * sizeof(sljit_sw
));
1890 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R2
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 1);
1891 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_MEM2(SLJIT_R2
, SLJIT_R2
), 0);
1892 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[8] - 0x12340);
1893 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0x12340, SLJIT_R2
, 0);
1894 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_R0
), 0x12340, SLJIT_MEM1(SLJIT_R2
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 6);
1895 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_s32
), SLJIT_IMM
, 0x12345678);
1896 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x2bd700 | 243);
1897 sljit_emit_return(compiler
, SLJIT_MOV_S8
, SLJIT_R1
, 0);
1899 code
.code
= sljit_generate_code(compiler
);
1901 sljit_free_compiler(compiler
);
1903 FAILED(code
.func2((sljit_sw
)&buf
, (sljit_sw
)&ibuf
) != -13, "test23 case 1 failed\n");
1904 FAILED(buf
[0] != -5791, "test23 case 2 failed\n");
1905 FAILED(buf
[1] != 43579, "test23 case 3 failed\n");
1906 FAILED(buf
[2] != 658923, "test23 case 4 failed\n");
1907 FAILED(buf
[3] != 0x0f00f00, "test23 case 5 failed\n");
1908 FAILED(buf
[4] != 0x0f00f00, "test23 case 6 failed\n");
1909 FAILED(buf
[5] != 80, "test23 case 7 failed\n");
1910 FAILED(buf
[6] != 0x123456, "test23 case 8 failed\n");
1911 FAILED(buf
[7] != (sljit_sw
)&buf
[5], "test23 case 9 failed\n");
1912 FAILED(buf
[8] != (sljit_sw
)&buf
[5] + 6, "test23 case 10 failed\n");
1914 FAILED(ibuf
[0] != 34567, "test23 case 11 failed\n");
1915 FAILED(ibuf
[1] != -7654, "test23 case 12 failed\n");
1917 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1918 FAILED(u
.asbytes
[0] != 0x78, "test23 case 13 failed\n");
1919 FAILED(u
.asbytes
[1] != 0x56, "test23 case 14 failed\n");
1920 FAILED(u
.asbytes
[2] != 0x34, "test23 case 15 failed\n");
1921 FAILED(u
.asbytes
[3] != 0x12, "test23 case 16 failed\n");
1923 FAILED(u
.asbytes
[0] != 0x12, "test23 case 13 failed\n");
1924 FAILED(u
.asbytes
[1] != 0x34, "test23 case 14 failed\n");
1925 FAILED(u
.asbytes
[2] != 0x56, "test23 case 15 failed\n");
1926 FAILED(u
.asbytes
[3] != 0x78, "test23 case 16 failed\n");
1929 sljit_free_code(code
.code
, NULL
);
1933 static void test24(void)
1935 /* Some complicated addressing modes. */
1936 executable_code code
;
1937 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1943 printf("Run test24\n");
1945 FAILED(!compiler
, "cannot create compiler\n");
1971 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 3, 3, 0, 0, 0);
1973 /* Nothing should be updated. */
1974 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM0(), (sljit_sw
)&sbuf
[1], SLJIT_MEM0(), (sljit_sw
)&sbuf
[0]);
1975 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM0(), (sljit_sw
)&bbuf
[1], SLJIT_MEM0(), (sljit_sw
)&bbuf
[0]);
1976 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
1977 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), 1, SLJIT_MEM0(), (sljit_sw
)&sbuf
[3]);
1978 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[0]);
1979 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1980 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2);
1981 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);
1982 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_s8
));
1983 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&bbuf
[1], SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&bbuf
[2]);
1985 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_s16
));
1986 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R1
), (sljit_sw
)&sbuf
[3], SLJIT_R1
, 0);
1988 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
1989 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
);
1990 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
1991 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_S0
, 0);
1992 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
);
1994 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 9 * sizeof(sljit_sw
));
1995 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 4 * sizeof(sljit_sw
));
1996 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -4 << SLJIT_WORD_SHIFT
);
1997 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R2
), 0, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
1999 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
- 0x7fff8000 + 6 * (sljit_sw
)sizeof(sljit_sw
));
2000 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 952467);
2001 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0x7fff8000, SLJIT_R1
, 0);
2002 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0x7fff8000 + sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_R0
), 0x7fff8000);
2004 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
+ 0x7fff7fff + 6 * (sljit_sw
)sizeof(sljit_sw
));
2005 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);
2006 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
- 0x7fff7ffe + 3 * (sljit_sw
)sizeof(sljit_s8
));
2007 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM1(SLJIT_R0
), 0x7fff7fff, SLJIT_MEM1(SLJIT_R0
), 0x7fff7ffe);
2008 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
+ 0x7fff7fff + 5 * (sljit_sw
)sizeof(sljit_s8
));
2009 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM1(SLJIT_R0
), -0x7fff7fff, SLJIT_MEM1(SLJIT_R0
), -0x7fff8000);
2010 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2011 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
- SLJIT_W(0x123456123456));
2012 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
- SLJIT_W(0x123456123456));
2013 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));
2016 sljit_emit_return_void(compiler
);
2018 code
.code
= sljit_generate_code(compiler
);
2020 sljit_free_compiler(compiler
);
2022 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&sbuf
, (sljit_sw
)&bbuf
);
2023 FAILED(buf
[2] != 176366, "test24 case 1 failed\n");
2024 FAILED(buf
[3] != 64, "test24 case 2 failed\n");
2025 FAILED(buf
[4] != -100, "test24 case 3 failed\n");
2026 FAILED(buf
[5] != 100567, "test24 case 4 failed\n");
2027 FAILED(buf
[6] != 952467, "test24 case 5 failed\n");
2028 FAILED(buf
[7] != 952467, "test24 case 6 failed\n");
2029 FAILED(buf
[8] != 952467 * 2, "test24 case 7 failed\n");
2031 FAILED(sbuf
[1] != 30000, "test24 case 8 failed\n");
2032 FAILED(sbuf
[2] != -12345, "test24 case 9 failed\n");
2033 FAILED(sbuf
[4] != sizeof(sljit_s16
), "test24 case 10 failed\n");
2035 FAILED(bbuf
[1] != -128, "test24 case 11 failed\n");
2036 FAILED(bbuf
[2] != 99, "test24 case 12 failed\n");
2037 FAILED(bbuf
[4] != 99, "test24 case 13 failed\n");
2038 FAILED(bbuf
[5] != 99, "test24 case 14 failed\n");
2039 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2040 FAILED(bbuf
[6] != -128, "test24 case 15 failed\n");
2043 sljit_free_code(code
.code
, NULL
);
2047 static void test25(void)
2049 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2051 executable_code code
;
2052 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2056 printf("Run test25\n");
2058 FAILED(!compiler
, "cannot create compiler\n");
2074 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 0, 0, 0);
2076 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0);
2077 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 1 * sizeof(sljit_sw
), SLJIT_IMM
, 0x7fff);
2078 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_IMM
, -0x8000);
2079 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 0x7fffffff);
2080 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(-0x80000000));
2081 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x1234567887654321));
2082 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0xff80000000));
2083 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x3ff0000000));
2084 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_IMM
, (sljit_sw
)SLJIT_W(0xfffffff800100000));
2085 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_IMM
, (sljit_sw
)SLJIT_W(0xfffffff80010f000));
2086 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00000008001));
2087 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00080010000));
2088 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00080018001));
2089 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00ffff00000));
2091 sljit_emit_return_void(compiler
);
2093 code
.code
= sljit_generate_code(compiler
);
2095 sljit_free_compiler(compiler
);
2097 code
.func1((sljit_sw
)&buf
);
2098 FAILED(buf
[0] != 0, "test25 case 1 failed\n");
2099 FAILED(buf
[1] != 0x7fff, "test25 case 2 failed\n");
2100 FAILED(buf
[2] != -0x8000, "test25 case 3 failed\n");
2101 FAILED(buf
[3] != 0x7fffffff, "test25 case 4 failed\n");
2102 FAILED(buf
[4] != SLJIT_W(-0x80000000), "test25 case 5 failed\n");
2103 FAILED(buf
[5] != SLJIT_W(0x1234567887654321), "test25 case 6 failed\n");
2104 FAILED(buf
[6] != SLJIT_W(0xff80000000), "test25 case 7 failed\n");
2105 FAILED(buf
[7] != SLJIT_W(0x3ff0000000), "test25 case 8 failed\n");
2106 FAILED((sljit_uw
)buf
[8] != SLJIT_W(0xfffffff800100000), "test25 case 9 failed\n");
2107 FAILED((sljit_uw
)buf
[9] != SLJIT_W(0xfffffff80010f000), "test25 case 10 failed\n");
2108 FAILED(buf
[10] != SLJIT_W(0x07fff00000008001), "test25 case 11 failed\n");
2109 FAILED(buf
[11] != SLJIT_W(0x07fff00080010000), "test25 case 12 failed\n");
2110 FAILED(buf
[12] != SLJIT_W(0x07fff00080018001), "test25 case 13 failed\n");
2111 FAILED(buf
[13] != SLJIT_W(0x07fff00ffff00000), "test25 case 14 failed\n");
2113 sljit_free_code(code
.code
, NULL
);
2118 static void test26(void)
2120 /* Aligned access without aligned offsets. */
2121 executable_code code
;
2122 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2128 printf("Run test26\n");
2130 FAILED(!compiler
, "cannot create compiler\n");
2147 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 3, 3, 0, 0, 0);
2149 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 3);
2150 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 1);
2151 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), -3);
2152 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
) - 1, SLJIT_R0
, 0);
2153 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), -1);
2154 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) - 3, SLJIT_R0
, 0);
2156 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 100);
2157 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)sizeof(sljit_sw
) * 2 - 103, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2 - 3, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3 - 3);
2158 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 100);
2159 sljit_emit_op2(compiler
, SLJIT_MUL32
, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)sizeof(sljit_s32
) * 2 - 101, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
) * 2 - 1, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
) * 3 - 1);
2161 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
2162 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 3);
2163 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f64
) - 3, SLJIT_MEM1(SLJIT_S2
), -3);
2164 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);
2165 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 2);
2166 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sizeof(sljit_f64
) * 3 - 4) >> 1);
2167 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 1);
2168 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);
2171 sljit_emit_return_void(compiler
);
2173 code
.code
= sljit_generate_code(compiler
);
2175 sljit_free_compiler(compiler
);
2177 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&ibuf
, (sljit_sw
)&dbuf
);
2179 FAILED(buf
[1] != -689, "test26 case 1 failed\n");
2180 FAILED(buf
[2] != -16, "test26 case 2 failed\n");
2181 FAILED(ibuf
[1] != -2789, "test26 case 3 failed\n");
2182 FAILED(ibuf
[2] != -18, "test26 case 4 failed\n");
2184 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
2185 FAILED(dbuf
[1] != 5.75, "test26 case 5 failed\n");
2186 FAILED(dbuf
[2] != 11.5, "test26 case 6 failed\n");
2187 FAILED(dbuf
[3] != -2.875, "test26 case 7 failed\n");
2190 sljit_free_code(code
.code
, NULL
);
2194 static void test27(void)
2196 #define SET_NEXT_BYTE(type) \
2197 cond_set(compiler, SLJIT_R2, 0, type); \
2198 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R2, 0); \
2199 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2200 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2203 #define RESULT(i) (3 - i)
2206 /* Playing with conditional flags. */
2207 executable_code code
;
2208 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2211 #ifdef SLJIT_PREF_SHIFT_REG
2212 sljit_s32 shift_reg
= SLJIT_PREF_SHIFT_REG
;
2214 sljit_s32 shift_reg
= SLJIT_R2
;
2217 SLJIT_ASSERT(shift_reg
>= SLJIT_R2
&& shift_reg
<= SLJIT_R3
);
2220 printf("Run test27\n");
2222 for (i
= 0; i
< sizeof(buf
); ++i
)
2225 FAILED(!compiler
, "cannot create compiler\n");
2227 /* 3 arguments passed, 3 arguments used. */
2228 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 4, 3, 0, 0, 0);
2230 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
2232 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1001);
2233 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 20);
2234 /* 0x100100000 on 64 bit machines, 0x100000 on 32 bit machines. */
2235 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x800000);
2236 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2237 sljit_emit_op0(compiler
, SLJIT_ENDBR
); /* ENDBR should keep the flags. */
2238 sljit_emit_op0(compiler
, SLJIT_NOP
); /* Nop should keep the flags. */
2239 SET_NEXT_BYTE(SLJIT_GREATER
);
2240 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2241 SET_NEXT_BYTE(SLJIT_LESS
);
2242 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2243 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
2244 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2245 sljit_emit_op0(compiler
, SLJIT_ENDBR
); /* ENDBR should keep the flags. */
2246 sljit_emit_op0(compiler
, SLJIT_NOP
); /* Nop should keep the flags. */
2247 SET_NEXT_BYTE(SLJIT_GREATER
);
2248 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2249 SET_NEXT_BYTE(SLJIT_LESS
);
2251 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1000);
2252 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 20);
2253 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x10);
2254 /* 0x100000010 on 64 bit machines, 0x10 on 32 bit machines. */
2255 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2256 SET_NEXT_BYTE(SLJIT_GREATER
);
2257 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2258 SET_NEXT_BYTE(SLJIT_LESS
);
2259 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2260 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2261 SET_NEXT_BYTE(SLJIT_GREATER
);
2262 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2263 SET_NEXT_BYTE(SLJIT_LESS
);
2265 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2266 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2267 /* 0xff..ff on all machines. */
2268 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2269 SET_NEXT_BYTE(SLJIT_LESS_EQUAL
);
2270 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2271 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL
);
2272 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R2
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -1);
2273 SET_NEXT_BYTE(SLJIT_SIG_GREATER
);
2274 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -1);
2275 SET_NEXT_BYTE(SLJIT_SIG_LESS
);
2276 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
2277 SET_NEXT_BYTE(SLJIT_EQUAL
);
2278 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
2279 SET_NEXT_BYTE(SLJIT_NOT_EQUAL
);
2280 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2281 SET_NEXT_BYTE(SLJIT_OVERFLOW
);
2282 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2283 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW
);
2284 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2285 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL
);
2286 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2287 SET_NEXT_BYTE(SLJIT_LESS_EQUAL
);
2288 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)-1 << ((8 * sizeof(sljit_sw
)) - 1));
2289 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2290 SET_NEXT_BYTE(SLJIT_SIG_LESS
);
2291 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -1);
2292 SET_NEXT_BYTE(SLJIT_SIG_GREATER
);
2293 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2294 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -2);
2295 SET_NEXT_BYTE(SLJIT_SIG_GREATER_EQUAL
);
2296 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 2);
2297 SET_NEXT_BYTE(SLJIT_SIG_GREATER
);
2299 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x80000000);
2300 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 16);
2301 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 16);
2302 /* 0x80..0 on 64 bit machines, 0 on 32 bit machines. */
2303 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)0xffffffff);
2304 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2305 SET_NEXT_BYTE(SLJIT_OVERFLOW
);
2306 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2307 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW
);
2308 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2309 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
2310 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2311 SET_NEXT_BYTE(SLJIT_OVERFLOW
);
2312 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2313 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW
);
2315 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2316 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2317 sljit_emit_op2u(compiler
, SLJIT_SUBC
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2318 sljit_emit_op2(compiler
, SLJIT_SUBC
, SLJIT_R0
, 0, SLJIT_IMM
, 6, SLJIT_R0
, 0);
2319 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_R0
, 0);
2320 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
2322 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
2323 sljit_emit_op2u(compiler
, SLJIT_ADD
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2324 sljit_emit_op2u(compiler
, SLJIT_ADDC
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2325 sljit_emit_op2(compiler
, SLJIT_ADDC
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 9);
2326 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_R0
, 0);
2327 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
2329 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2330 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, (8 * sizeof(sljit_sw
)) - 1);
2331 sljit_emit_op2u(compiler
, SLJIT_ADD
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2332 SET_NEXT_BYTE(SLJIT_EQUAL
);
2333 sljit_emit_op2u(compiler
, SLJIT_ADD
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2334 SET_NEXT_BYTE(SLJIT_EQUAL
);
2336 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2337 sljit_emit_op2(compiler
, SLJIT_ASHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2338 SET_NEXT_BYTE(SLJIT_EQUAL
);
2339 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2340 sljit_emit_op2(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffffc0);
2341 SET_NEXT_BYTE(SLJIT_NOT_EQUAL
);
2342 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0);
2343 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2344 sljit_emit_op2(compiler
, SLJIT_ASHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, shift_reg
, 0);
2345 SET_NEXT_BYTE(SLJIT_EQUAL
);
2346 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0);
2347 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2348 sljit_emit_op2(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, shift_reg
, 0);
2349 SET_NEXT_BYTE(SLJIT_NOT_EQUAL
);
2351 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2352 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2353 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2354 sljit_emit_op2(compiler
, SLJIT_SUBC
| SLJIT_SET_CARRY
, SLJIT_R2
, 0, SLJIT_IMM
, 1, SLJIT_R0
, 0);
2355 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_R2
, 0);
2356 sljit_emit_op2u(compiler
, SLJIT_SUBC
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2357 sljit_emit_op2(compiler
, SLJIT_SUBC
, SLJIT_R2
, 0, SLJIT_IMM
, 1, SLJIT_R0
, 0);
2358 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 2, SLJIT_R2
, 0);
2359 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 2);
2361 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -34);
2362 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1234);
2363 SET_NEXT_BYTE(SLJIT_LESS
);
2364 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1234);
2365 SET_NEXT_BYTE(SLJIT_SIG_LESS
);
2366 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2367 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x12300000000) - 43);
2369 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, -43);
2371 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -96);
2372 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2373 SET_NEXT_BYTE(SLJIT_LESS
);
2374 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2375 SET_NEXT_BYTE(SLJIT_SIG_GREATER
);
2377 sljit_emit_return_void(compiler
);
2379 code
.code
= sljit_generate_code(compiler
);
2381 sljit_free_compiler(compiler
);
2383 code
.func1((sljit_sw
)&buf
);
2385 FAILED(buf
[0] != RESULT(1), "test27 case 1 failed\n");
2386 FAILED(buf
[1] != RESULT(2), "test27 case 2 failed\n");
2387 FAILED(buf
[2] != 2, "test27 case 3 failed\n");
2388 FAILED(buf
[3] != 1, "test27 case 4 failed\n");
2389 FAILED(buf
[4] != RESULT(1), "test27 case 5 failed\n");
2390 FAILED(buf
[5] != RESULT(2), "test27 case 6 failed\n");
2391 FAILED(buf
[6] != 2, "test27 case 7 failed\n");
2392 FAILED(buf
[7] != 1, "test27 case 8 failed\n");
2394 FAILED(buf
[8] != 2, "test27 case 9 failed\n");
2395 FAILED(buf
[9] != 1, "test27 case 10 failed\n");
2396 FAILED(buf
[10] != 2, "test27 case 11 failed\n");
2397 FAILED(buf
[11] != 1, "test27 case 12 failed\n");
2398 FAILED(buf
[12] != 1, "test27 case 13 failed\n");
2399 FAILED(buf
[13] != 2, "test27 case 14 failed\n");
2400 FAILED(buf
[14] != 2, "test27 case 15 failed\n");
2401 FAILED(buf
[15] != 1, "test27 case 16 failed\n");
2402 FAILED(buf
[16] != 1, "test27 case 17 failed\n");
2403 FAILED(buf
[17] != 2, "test27 case 18 failed\n");
2404 FAILED(buf
[18] != 1, "test27 case 19 failed\n");
2405 FAILED(buf
[19] != 1, "test27 case 20 failed\n");
2406 FAILED(buf
[20] != 1, "test27 case 21 failed\n");
2407 FAILED(buf
[21] != 2, "test27 case 22 failed\n");
2409 FAILED(buf
[22] != RESULT(1), "test27 case 23 failed\n");
2410 FAILED(buf
[23] != RESULT(2), "test27 case 24 failed\n");
2411 FAILED(buf
[24] != 2, "test27 case 25 failed\n");
2412 FAILED(buf
[25] != 1, "test27 case 26 failed\n");
2414 FAILED(buf
[26] != 5, "test27 case 27 failed\n");
2415 FAILED(buf
[27] != 9, "test27 case 28 failed\n");
2417 FAILED(buf
[28] != 2, "test27 case 29 failed\n");
2418 FAILED(buf
[29] != 1, "test27 case 30 failed\n");
2420 FAILED(buf
[30] != 1, "test27 case 31 failed\n");
2421 FAILED(buf
[31] != 1, "test27 case 32 failed\n");
2422 FAILED(buf
[32] != 1, "test27 case 33 failed\n");
2423 FAILED(buf
[33] != 1, "test27 case 34 failed\n");
2425 FAILED(buf
[34] != 1, "test27 case 35 failed\n");
2426 FAILED(buf
[35] != 0, "test27 case 36 failed\n");
2428 FAILED(buf
[36] != 2, "test27 case 37 failed\n");
2429 FAILED(buf
[37] != 1, "test27 case 38 failed\n");
2430 FAILED(buf
[38] != 2, "test27 case 39 failed\n");
2431 FAILED(buf
[39] != 1, "test27 case 40 failed\n");
2432 FAILED(buf
[40] != 10, "test27 case 41 failed\n");
2434 sljit_free_code(code
.code
, NULL
);
2436 #undef SET_NEXT_BYTE
2440 static void test28(void)
2443 executable_code code
;
2444 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2445 struct sljit_const
* const1
= NULL
;
2446 struct sljit_label
* label
= NULL
;
2447 sljit_uw label_addr
= 0;
2451 printf("Run test28\n");
2453 FAILED(!compiler
, "cannot create compiler\n");
2461 FAILED(!compiler
, "cannot create compiler\n");
2462 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 5, 5, 0, 0, 0);
2463 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -234);
2464 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
2465 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_S3
, 0, SLJIT_R3
, 0, SLJIT_R4
, 0);
2466 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_S3
, 0);
2467 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_S3
, 0, SLJIT_IMM
, 0);
2468 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_NOT_ZERO
);
2469 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_S3
, 0);
2470 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
));
2471 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S4
, 0, SLJIT_S4
, 0, SLJIT_R4
, 0);
2472 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_S4
, 0);
2474 const1
= sljit_emit_const(compiler
, SLJIT_S3
, 0, 0);
2475 sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_S3
, 0);
2476 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S3
, 0, SLJIT_S3
, 0, SLJIT_IMM
, 100);
2477 label
= sljit_emit_label(compiler
);
2478 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
2479 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_S3
, 0);
2481 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R4
, 0);
2483 code
.code
= sljit_generate_code(compiler
);
2486 label_addr
= sljit_get_label_addr(label
);
2487 sljit_set_const(sljit_get_const_addr(const1
), (sljit_sw
)label_addr
, sljit_get_executable_offset(compiler
));
2489 sljit_free_compiler(compiler
);
2491 FAILED(code
.func1((sljit_sw
)&buf
) != 8, "test28 case 1 failed\n");
2492 FAILED(buf
[1] != -1872, "test28 case 2 failed\n");
2493 FAILED(buf
[2] != 1, "test28 case 3 failed\n");
2494 FAILED(buf
[3] != 2, "test28 case 4 failed\n");
2495 FAILED(buf
[4] != (sljit_sw
)label_addr
, "test28 case 5 failed\n");
2497 sljit_free_code(code
.code
, NULL
);
2501 static void test29(void)
2503 /* Test signed/unsigned bytes and halfs. */
2504 executable_code code
;
2505 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2510 printf("Run test29\n");
2512 for (i
= 0; i
< 25; i
++)
2515 FAILED(!compiler
, "cannot create compiler\n");
2516 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 5, 5, 0, 0, 0);
2518 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_IMM
, -187);
2519 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
2520 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_IMM
, -605);
2521 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2522 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R0
, 0, SLJIT_IMM
, -56);
2523 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2524 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R4
, 0, SLJIT_IMM
, 0xcde5);
2525 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2527 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_IMM
, -45896);
2528 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2529 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_IMM
, -1472797);
2530 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2531 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R0
, 0, SLJIT_IMM
, -12890);
2532 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2533 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R4
, 0, SLJIT_IMM
, 0x9cb0a6);
2534 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2536 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2537 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-3580429715));
2538 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2539 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-100722768662));
2540 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2541 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-1457052677972));
2542 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2543 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R4
, 0, SLJIT_IMM
, SLJIT_W(0xcef97a70b5));
2544 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2547 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -187);
2548 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2549 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2550 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -605);
2551 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_S2
, 0);
2552 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2553 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -56);
2554 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R0
, 0, SLJIT_R2
, 0);
2555 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2556 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0xcde5);
2557 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R4
, 0, SLJIT_R3
, 0);
2558 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2560 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -45896);
2561 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2562 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2563 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1472797);
2564 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_S2
, 0);
2565 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2566 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -12890);
2567 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R0
, 0, SLJIT_R2
, 0);
2568 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2569 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x9cb0a6);
2570 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R4
, 0, SLJIT_R3
, 0);
2571 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 19 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2573 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2574 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(-3580429715));
2575 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2576 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2577 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, SLJIT_W(-100722768662));
2578 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_S2
, 0);
2579 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 21 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2580 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, SLJIT_W(-1457052677972));
2581 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R2
, 0);
2582 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2583 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_W(0xcef97a70b5));
2584 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R4
, 0, SLJIT_R3
, 0);
2585 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 23 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2588 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, 0x9faa5);
2589 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_S2
, 0, SLJIT_S2
, 0);
2590 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 24 * sizeof(sljit_uw
), SLJIT_S2
, 0);
2592 sljit_emit_return_void(compiler
);
2594 code
.code
= sljit_generate_code(compiler
);
2596 sljit_free_compiler(compiler
);
2598 code
.func1((sljit_sw
)&buf
);
2599 FAILED(buf
[0] != 69, "test29 case 1 failed\n");
2600 FAILED(buf
[1] != -93, "test29 case 2 failed\n");
2601 FAILED(buf
[2] != 200, "test29 case 3 failed\n");
2602 FAILED(buf
[3] != 0xe5, "test29 case 4 failed\n");
2603 FAILED(buf
[4] != 19640, "test29 case 5 failed\n");
2604 FAILED(buf
[5] != -31005, "test29 case 6 failed\n");
2605 FAILED(buf
[6] != 52646, "test29 case 7 failed\n");
2606 FAILED(buf
[7] != 0xb0a6, "test29 case 8 failed\n");
2608 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2609 FAILED(buf
[8] != SLJIT_W(714537581), "test29 case 9 failed\n");
2610 FAILED(buf
[9] != SLJIT_W(-1938520854), "test29 case 10 failed\n");
2611 FAILED(buf
[10] != SLJIT_W(3236202668), "test29 case 11 failed\n");
2612 FAILED(buf
[11] != SLJIT_W(0xf97a70b5), "test29 case 12 failed\n");
2615 FAILED(buf
[12] != 69, "test29 case 13 failed\n");
2616 FAILED(buf
[13] != -93, "test29 case 14 failed\n");
2617 FAILED(buf
[14] != 200, "test29 case 15 failed\n");
2618 FAILED(buf
[15] != 0xe5, "test29 case 16 failed\n");
2619 FAILED(buf
[16] != 19640, "test29 case 17 failed\n");
2620 FAILED(buf
[17] != -31005, "test29 case 18 failed\n");
2621 FAILED(buf
[18] != 52646, "test29 case 19 failed\n");
2622 FAILED(buf
[19] != 0xb0a6, "test29 case 20 failed\n");
2624 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2625 FAILED(buf
[20] != SLJIT_W(714537581), "test29 case 21 failed\n");
2626 FAILED(buf
[21] != SLJIT_W(-1938520854), "test29 case 22 failed\n");
2627 FAILED(buf
[22] != SLJIT_W(3236202668), "test29 case 23 failed\n");
2628 FAILED(buf
[23] != SLJIT_W(0xf97a70b5), "test29 case 24 failed\n");
2631 FAILED(buf
[24] != -91, "test29 case 25 failed\n");
2633 sljit_free_code(code
.code
, NULL
);
2637 static void test30(void)
2639 /* Test unused results. */
2640 executable_code code
;
2641 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2645 printf("Run test30\n");
2647 FAILED(!compiler
, "cannot create compiler\n");
2649 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 5, 5, 0, 0, 0);
2651 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2652 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2653 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 1);
2654 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 1);
2655 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, 1);
2656 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2657 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S1
, 0, SLJIT_IMM
, SLJIT_W(-0x123ffffffff));
2659 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S1
, 0, SLJIT_IMM
, 1);
2661 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, 1);
2662 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, 1);
2663 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_IMM
, 1);
2665 /* Some calculations with unused results. */
2666 sljit_emit_op2u(compiler
, SLJIT_ADD
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
2667 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_GREATER_EQUAL
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
2668 sljit_emit_op2u(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_S0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
2669 sljit_emit_op2u(compiler
, SLJIT_SHL
| SLJIT_SET_Z
, SLJIT_S3
, 0, SLJIT_R2
, 0);
2670 sljit_emit_op2u(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 5);
2671 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0xff);
2673 /* Testing that any change happens. */
2674 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2675 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R2
, 0);
2676 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R3
, 0);
2677 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R4
, 0);
2678 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_S1
, 0, SLJIT_S1
, 0);
2679 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S1
, 0);
2680 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S2
, 0);
2681 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S3
, 0);
2682 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0, SLJIT_S4
, 0);
2684 sljit_emit_return_void(compiler
);
2686 code
.code
= sljit_generate_code(compiler
);
2688 sljit_free_compiler(compiler
);
2690 code
.func1((sljit_sw
)&buf
);
2691 FAILED(buf
[0] != 9, "test30 case 1 failed\n");
2693 sljit_free_code(code
.code
, NULL
);
2697 static void test31(void)
2699 /* Integer mul and set flags. */
2700 executable_code code
;
2701 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2704 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2705 sljit_sw big_word
= SLJIT_W(0x7fffffff00000000);
2706 sljit_sw big_word2
= SLJIT_W(0x7fffffff00000012);
2708 sljit_sw big_word
= 0x7fffffff;
2709 sljit_sw big_word2
= 0x00000012;
2713 printf("Run test31\n");
2715 for (i
= 0; i
< 12; i
++)
2718 FAILED(!compiler
, "cannot create compiler\n");
2720 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 5, 0, 0, 0);
2721 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
2722 sljit_emit_op2u(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_IMM
, -45);
2723 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_NOT_OVERFLOW
);
2724 sljit_emit_op2u(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_IMM
, -45);
2725 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_OVERFLOW
);
2727 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, big_word
);
2728 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, -2);
2729 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 33); /* Should not change flags. */
2730 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0); /* Should not change flags. */
2731 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
2732 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, -2);
2733 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_NOT_OVERFLOW
);
2735 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S3
, 0, SLJIT_IMM
, 0x3f6b0);
2736 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S4
, 0, SLJIT_IMM
, 0x2a783);
2737 sljit_emit_op2(compiler
, SLJIT_MUL32
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_S3
, 0, SLJIT_S4
, 0);
2738 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
2739 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R1
, 0);
2741 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, big_word2
);
2742 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_R1
, 0);
2743 sljit_emit_op2(compiler
, SLJIT_MUL32
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 23);
2744 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
2746 sljit_emit_op2u(compiler
, SLJIT_MUL32
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_IMM
, -23);
2747 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_NOT_OVERFLOW
);
2748 sljit_emit_op2u(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_IMM
, -23);
2749 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_NOT_OVERFLOW
);
2751 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 67);
2752 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -23);
2753 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R1
, 0);
2755 sljit_emit_return_void(compiler
);
2757 code
.code
= sljit_generate_code(compiler
);
2759 sljit_free_compiler(compiler
);
2761 code
.func1((sljit_sw
)&buf
);
2763 FAILED(buf
[0] != 1, "test31 case 1 failed\n");
2764 FAILED(buf
[1] != 2, "test31 case 2 failed\n");
2765 /* Qemu issues for 64 bit muls. */
2766 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2767 FAILED(buf
[2] != 1, "test31 case 3 failed\n");
2768 FAILED(buf
[3] != 2, "test31 case 4 failed\n");
2770 FAILED(buf
[4] != 1, "test31 case 5 failed\n");
2771 FAILED((buf
[5] & (sljit_sw
)0xffffffff) != (sljit_sw
)0x85540c10, "test31 case 6 failed\n");
2772 FAILED(buf
[6] != 2, "test31 case 7 failed\n");
2773 FAILED(buf
[7] != 1, "test31 case 8 failed\n");
2774 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2775 FAILED(buf
[8] != 1, "test31 case 9 failed\n");
2777 FAILED(buf
[9] != -1541, "test31 case 10 failed\n");
2779 sljit_free_code(code
.code
, NULL
);
2783 static void test32(void)
2785 /* Floating point set flags. */
2786 executable_code code
;
2787 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2800 printf("Run test32\n");
2802 for (i
= 0; i
< 16; i
++)
2806 dbuf
[0].u
.value1
= 0x7fffffff;
2807 dbuf
[0].u
.value2
= 0x7fffffff;
2808 dbuf
[1].u
.value1
= 0x7fffffff;
2809 dbuf
[1].u
.value2
= 0x7fffffff;
2810 dbuf
[2].value
= -13.0;
2811 dbuf
[3].value
= 27.0;
2813 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
2815 printf("no fpu available, test32 skipped\n");
2818 sljit_free_compiler(compiler
);
2822 FAILED(!compiler
, "cannot create compiler\n");
2823 SLJIT_ASSERT(sizeof(sljit_f64
) == 8 && sizeof(sljit_s32
) == 4 && sizeof(dbuf
[0]) == 8);
2825 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 1, 2, 4, 0, 0);
2827 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
2828 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED_F
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
2829 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f64
));
2830 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_UNORDERED_F64
);
2831 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_ORDERED_F
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
2832 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_ORDERED_F64
);
2834 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
));
2835 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2836 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_UNORDERED_F64
);
2837 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_ORDERED_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2838 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_ORDERED_F64
);
2839 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_LESS_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2840 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_LESS_F64
);
2841 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_GREATER_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2842 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_GREATER_EQUAL_F64
);
2843 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_GREATER_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2844 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_GREATER_F64
);
2845 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_LESS_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2846 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_LESS_EQUAL_F64
);
2847 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2848 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_EQUAL_F64
);
2849 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_NOT_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2850 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_NOT_EQUAL_F64
);
2852 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED_F
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
));
2853 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR3
, 0, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
));
2854 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_UNORDERED_F64
);
2855 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_EQUAL_F
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
));
2856 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_EQUAL_F64
);
2858 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_ORDERED_F
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
), SLJIT_FR0
, 0);
2859 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_ORDERED_F64
);
2861 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED_F
, SLJIT_FR3
, 0, SLJIT_FR2
, 0);
2862 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
2863 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_UNORDERED_F64
);
2865 sljit_emit_return_void(compiler
);
2867 code
.code
= sljit_generate_code(compiler
);
2869 sljit_free_compiler(compiler
);
2871 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&dbuf
);
2873 FAILED(buf
[0] != 1, "test32 case 1 failed\n");
2874 FAILED(buf
[1] != 2, "test32 case 2 failed\n");
2875 FAILED(buf
[2] != 2, "test32 case 3 failed\n");
2876 FAILED(buf
[3] != 1, "test32 case 4 failed\n");
2877 FAILED(buf
[4] != 1, "test32 case 5 failed\n");
2878 FAILED(buf
[5] != 2, "test32 case 6 failed\n");
2879 FAILED(buf
[6] != 2, "test32 case 7 failed\n");
2880 FAILED(buf
[7] != 1, "test32 case 8 failed\n");
2881 FAILED(buf
[8] != 2, "test32 case 9 failed\n");
2882 FAILED(buf
[9] != 1, "test32 case 10 failed\n");
2883 FAILED(buf
[10] != 2, "test32 case 11 failed\n");
2884 FAILED(buf
[11] != 1, "test32 case 12 failed\n");
2885 FAILED(buf
[12] != 2, "test32 case 13 failed\n");
2886 FAILED(buf
[13] != 1, "test32 case 14 failed\n");
2888 sljit_free_code(code
.code
, NULL
);
2892 static void test33(void)
2894 /* Test setting multiple flags. */
2895 executable_code code
;
2896 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2897 struct sljit_jump
* jump
;
2901 printf("Run test33\n");
2914 FAILED(!compiler
, "cannot create compiler\n");
2916 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 3, 0, 0, 0);
2918 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 20);
2919 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 10);
2920 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2921 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_ZERO
);
2922 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -10);
2923 jump
= sljit_emit_jump(compiler
, SLJIT_LESS
);
2924 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 11);
2925 sljit_set_label(jump
, sljit_emit_label(compiler
));
2927 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_SIG_GREATER
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2928 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_SIG_GREATER
);
2929 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 45);
2930 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_EQUAL
);
2931 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 55);
2932 sljit_set_label(jump
, sljit_emit_label(compiler
));
2934 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2935 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)SLJIT_W(0x8000000000000000));
2937 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)SLJIT_W(0x80000000));
2939 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2940 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2941 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, 33);
2942 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_OVERFLOW
);
2943 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_ZERO
);
2944 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, 13);
2945 sljit_set_label(jump
, sljit_emit_label(compiler
));
2947 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x80000000);
2948 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R0
, 0);
2949 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2950 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
2951 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_NOT_ZERO
);
2952 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, 78);
2953 jump
= sljit_emit_jump(compiler
, SLJIT_OVERFLOW
);
2954 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, 48);
2955 sljit_set_label(jump
, sljit_emit_label(compiler
));
2957 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2958 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)SLJIT_W(0x8000000000000000));
2960 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)SLJIT_W(0x80000000));
2962 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_R0
, 0);
2963 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2964 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_IMM
, 30);
2965 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_OVERFLOW
);
2966 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_IMM
, 50);
2967 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_ZERO
);
2968 sljit_set_label(jump
, sljit_emit_label(compiler
));
2970 sljit_emit_return_void(compiler
);
2972 code
.code
= sljit_generate_code(compiler
);
2974 sljit_free_compiler(compiler
);
2976 code
.func1((sljit_sw
)&buf
);
2978 FAILED(buf
[0] != 0, "test33 case 1 failed\n");
2979 FAILED(buf
[1] != 11, "test33 case 2 failed\n");
2980 FAILED(buf
[2] != 1, "test33 case 3 failed\n");
2981 FAILED(buf
[3] != 45, "test33 case 4 failed\n");
2982 FAILED(buf
[4] != 13, "test33 case 5 failed\n");
2983 FAILED(buf
[5] != 0, "test33 case 6 failed\n");
2984 FAILED(buf
[6] != 0, "test33 case 7 failed\n");
2985 FAILED(buf
[7] != 48, "test33 case 8 failed\n");
2986 FAILED(buf
[8] != 50, "test33 case 9 failed\n");
2987 FAILED(buf
[9] != 1, "test33 case 10 failed\n");
2989 sljit_free_code(code
.code
, NULL
);
2993 static void test34(void)
2995 /* Test fast calls. */
2996 executable_code codeA
;
2997 executable_code codeB
;
2998 executable_code codeC
;
2999 executable_code codeD
;
3000 executable_code codeE
;
3001 executable_code codeF
;
3002 struct sljit_compiler
* compiler
;
3003 struct sljit_jump
*jump
;
3004 struct sljit_label
* label
;
3009 printf("Run test34\n");
3015 compiler
= sljit_create_compiler(NULL
, NULL
);
3016 FAILED(!compiler
, "cannot create compiler\n");
3017 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3019 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3020 sljit_emit_fast_enter(compiler
, SLJIT_R1
, 0);
3021 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 4);
3022 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R1
, 0);
3024 codeA
.code
= sljit_generate_code(compiler
);
3026 sljit_free_compiler(compiler
);
3029 compiler
= sljit_create_compiler(NULL
, NULL
);
3030 FAILED(!compiler
, "cannot create compiler\n");
3031 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3033 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3034 sljit_emit_fast_enter(compiler
, SLJIT_R4
, 0);
3035 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 6);
3036 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(codeA
.code
));
3037 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_R1
, 0);
3038 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R4
, 0);
3040 codeB
.code
= sljit_generate_code(compiler
);
3042 sljit_free_compiler(compiler
);
3045 compiler
= sljit_create_compiler(NULL
, NULL
);
3046 FAILED(!compiler
, "cannot create compiler\n");
3047 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3049 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3050 sljit_emit_fast_enter(compiler
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_p
));
3051 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3052 jump
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
| SLJIT_REWRITABLE_JUMP
);
3053 sljit_set_target(jump
, SLJIT_FUNC_UADDR(codeB
.code
));
3054 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_p
));
3056 codeC
.code
= sljit_generate_code(compiler
);
3058 sljit_free_compiler(compiler
);
3061 compiler
= sljit_create_compiler(NULL
, NULL
);
3062 FAILED(!compiler
, "cannot create compiler\n");
3063 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3065 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3066 sljit_emit_fast_enter(compiler
, SLJIT_MEM1(SLJIT_SP
), 0);
3067 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 10);
3068 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_ADDR(codeC
.code
));
3069 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_MEM1(SLJIT_SP
), 0);
3071 codeD
.code
= sljit_generate_code(compiler
);
3073 sljit_free_compiler(compiler
);
3076 compiler
= sljit_create_compiler(NULL
, NULL
);
3077 FAILED(!compiler
, "cannot create compiler\n");
3078 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3080 sljit_emit_fast_enter(compiler
, SLJIT_MEM1(SLJIT_S0
), 0);
3081 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 12);
3082 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_p
), SLJIT_IMM
, SLJIT_FUNC_ADDR(codeD
.code
));
3083 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_p
));
3084 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_MEM1(SLJIT_S0
), 0);
3086 codeE
.code
= sljit_generate_code(compiler
);
3088 sljit_free_compiler(compiler
);
3091 compiler
= sljit_create_compiler(NULL
, NULL
);
3092 FAILED(!compiler
, "cannot create compiler\n");
3094 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3095 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3096 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_ADDR(codeE
.code
));
3097 label
= sljit_emit_label(compiler
);
3098 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
3100 codeF
.code
= sljit_generate_code(compiler
);
3102 addr
= sljit_get_label_addr(label
);
3103 sljit_free_compiler(compiler
);
3105 FAILED(codeF
.func1((sljit_sw
)&buf
) != 40, "test34 case 1 failed\n");
3106 FAILED(buf
[0] != addr
- SLJIT_RETURN_ADDRESS_OFFSET
, "test34 case 2 failed\n");
3108 sljit_free_code(codeA
.code
, NULL
);
3109 sljit_free_code(codeB
.code
, NULL
);
3110 sljit_free_code(codeC
.code
, NULL
);
3111 sljit_free_code(codeD
.code
, NULL
);
3112 sljit_free_code(codeE
.code
, NULL
);
3113 sljit_free_code(codeF
.code
, NULL
);
3117 static void test35(void)
3119 /* More complicated tests for fast calls. */
3120 executable_code codeA
;
3121 executable_code codeB
;
3122 executable_code codeC
;
3123 struct sljit_compiler
* compiler
;
3124 struct sljit_jump
*jump
= NULL
;
3125 struct sljit_label
* label
;
3126 sljit_sw executable_offset
;
3127 sljit_uw return_addr
;
3128 sljit_uw jump_addr
= 0;
3132 printf("Run test35\n");
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_fast_enter(compiler
, SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
3142 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3144 jump
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
| SLJIT_REWRITABLE_JUMP
);
3145 sljit_set_target(jump
, 0);
3147 label
= sljit_emit_label(compiler
);
3148 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
3150 codeA
.code
= sljit_generate_code(compiler
);
3152 executable_offset
= sljit_get_executable_offset(compiler
);
3153 jump_addr
= sljit_get_jump_addr(jump
);
3154 sljit_free_compiler(compiler
);
3157 compiler
= sljit_create_compiler(NULL
, NULL
);
3158 FAILED(!compiler
, "cannot create compiler\n");
3159 sljit_set_context(compiler
, 0, 0, 2, 2, 0, 0, 0);
3161 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3162 sljit_emit_fast_enter(compiler
, SLJIT_R1
, 0);
3163 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 7);
3164 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R1
, 0);
3166 codeB
.code
= sljit_generate_code(compiler
);
3168 sljit_free_compiler(compiler
);
3170 sljit_set_jump_addr(jump_addr
, SLJIT_FUNC_UADDR(codeB
.code
), executable_offset
);
3173 compiler
= sljit_create_compiler(NULL
, NULL
);
3174 FAILED(!compiler
, "cannot create compiler\n");
3176 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), 2, 2, 0, 0, 0);
3177 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3178 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_ADDR(codeA
.code
));
3179 label
= sljit_emit_label(compiler
);
3180 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
3182 codeC
.code
= sljit_generate_code(compiler
);
3184 return_addr
= sljit_get_label_addr(label
);
3185 sljit_free_compiler(compiler
);
3187 FAILED(codeC
.func0() != 12, "test35 case 1 failed\n");
3188 FAILED(buf
[0] != return_addr
- SLJIT_RETURN_ADDRESS_OFFSET
, "test35 case 2 failed\n");
3190 sljit_free_code(codeA
.code
, NULL
);
3191 sljit_free_code(codeB
.code
, NULL
);
3192 sljit_free_code(codeC
.code
, NULL
);
3196 static void cmp_test(struct sljit_compiler
*compiler
, sljit_s32 type
, sljit_s32 src1
, sljit_sw src1w
, sljit_s32 src2
, sljit_sw src2w
)
3198 /* 2 = true, 1 = false */
3199 struct sljit_jump
* jump
;
3200 struct sljit_label
* label
;
3202 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_IMM
, 2);
3203 jump
= sljit_emit_cmp(compiler
, type
, src1
, src1w
, src2
, src2w
);
3204 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_IMM
, 1);
3205 label
= sljit_emit_label(compiler
);
3206 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3207 sljit_set_label(jump
, label
);
3208 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
3211 #define TEST_CASES (7 + 10 + 12 + 11 + 4)
3212 static void test36(void)
3214 /* Compare instruction. */
3215 executable_code code
;
3216 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3218 sljit_s8 buf
[TEST_CASES
];
3219 sljit_s8 compare_buf
[TEST_CASES
] = {
3220 1, 1, 2, 2, 1, 2, 2,
3221 1, 1, 2, 2, 2, 1, 2, 2, 1, 1,
3222 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2,
3223 2, 1, 2, 1, 1, 1, 2, 1, 2, 1, 2,
3230 printf("Run test36\n");
3232 FAILED(!compiler
, "cannot create compiler\n");
3233 for (i
= 0; i
< TEST_CASES
; ++i
)
3240 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 3, 2, 0, 0, 0);
3241 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
3243 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 13);
3244 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 15);
3245 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_IMM
, 9, SLJIT_R0
, 0);
3246 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3247 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
3248 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_IMM
, -13);
3249 cmp_test(compiler
, SLJIT_NOT_EQUAL
, SLJIT_IMM
, 0, SLJIT_R0
, 0);
3250 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3251 cmp_test(compiler
, SLJIT_NOT_EQUAL
| SLJIT_REWRITABLE_JUMP
, SLJIT_IMM
, 0, SLJIT_R0
, 0);
3252 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
);
3253 cmp_test(compiler
, SLJIT_EQUAL
| SLJIT_REWRITABLE_JUMP
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3255 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, 0);
3256 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -8);
3257 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3258 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3259 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3260 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_REWRITABLE_JUMP
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3261 cmp_test(compiler
, SLJIT_SIG_GREATER_EQUAL
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3262 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
));
3263 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_IMM
, 0, SLJIT_R1
, 0);
3264 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
));
3265 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
));
3266 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_REWRITABLE_JUMP
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
));
3268 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3269 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3270 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
));
3271 cmp_test(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3272 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, -10);
3273 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3274 cmp_test(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_IMM
, 8, SLJIT_R1
, 0);
3275 cmp_test(compiler
, SLJIT_GREATER_EQUAL
| SLJIT_REWRITABLE_JUMP
, SLJIT_IMM
, 8, SLJIT_R1
, 0);
3276 cmp_test(compiler
, SLJIT_GREATER
, SLJIT_IMM
, 8, SLJIT_R1
, 0);
3277 cmp_test(compiler
, SLJIT_LESS_EQUAL
, SLJIT_IMM
, 7, SLJIT_R0
, 0);
3278 cmp_test(compiler
, SLJIT_GREATER
, SLJIT_IMM
, 1, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
));
3279 cmp_test(compiler
, SLJIT_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3280 cmp_test(compiler
, SLJIT_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3281 cmp_test(compiler
, SLJIT_GREATER
| SLJIT_REWRITABLE_JUMP
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3283 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -3);
3284 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3285 cmp_test(compiler
, SLJIT_SIG_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3286 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
3287 cmp_test(compiler
, SLJIT_SIG_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3288 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, -1);
3289 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_REWRITABLE_JUMP
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, -1);
3290 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3291 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3292 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_IMM
, -4, SLJIT_R0
, 0);
3293 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_IMM
, -1, SLJIT_R1
, 0);
3294 cmp_test(compiler
, SLJIT_SIG_GREATER
| SLJIT_REWRITABLE_JUMP
, SLJIT_R1
, 0, SLJIT_IMM
, -1);
3296 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3297 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xf00000004));
3298 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_R0
, 0);
3299 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3300 cmp_test(compiler
, SLJIT_LESS
| SLJIT_32
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
3301 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3302 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xff0000004));
3303 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R0
, 0);
3304 cmp_test(compiler
, SLJIT_SIG_GREATER
| SLJIT_32
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
3305 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3307 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
3308 cmp_test(compiler
, SLJIT_LESS
| SLJIT_32
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3309 cmp_test(compiler
, SLJIT_GREATER
| SLJIT_32
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3310 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0xf0000004);
3311 cmp_test(compiler
, SLJIT_SIG_GREATER
| SLJIT_32
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3312 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_32
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3315 sljit_emit_return_void(compiler
);
3317 code
.code
= sljit_generate_code(compiler
);
3319 sljit_free_compiler(compiler
);
3321 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&data
);
3323 for (i
= 0; i
< TEST_CASES
; ++i
)
3324 if (SLJIT_UNLIKELY(buf
[i
] != compare_buf
[i
])) {
3325 printf("test36 case %d failed\n", i
+ 1);
3329 sljit_free_code(code
.code
, NULL
);
3334 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3335 #define BITN(n) (SLJIT_W(1) << (63 - (n)))
3338 #define BITN(n) (1 << (31 - ((n) & 0x1f)))
3339 #define RESN(n) ((n) & 0x1f)
3342 static void test37(void)
3344 /* Test count leading zeroes. */
3345 executable_code code
;
3346 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3352 printf("Run test37\n");
3354 FAILED(!compiler
, "cannot create compiler\n");
3356 for (i
= 0; i
< 9; i
++)
3362 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 1, 3, 0, 0, 0);
3363 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, BITN(27));
3364 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
3365 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, BITN(47));
3366 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_R0
, 0, SLJIT_S2
, 0);
3367 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
3368 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
));
3369 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
3370 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3371 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3372 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3373 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_R0
, 0);
3374 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
3375 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
));
3376 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3377 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, BITN(58));
3378 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3379 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3380 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3381 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3382 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xff08a00000));
3384 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x08a00000);
3386 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
), SLJIT_R0
, 0);
3387 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3388 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3389 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3390 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xffc8a00000));
3392 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0xc8a00000);
3394 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3395 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3397 sljit_emit_return_void(compiler
);
3399 code
.code
= sljit_generate_code(compiler
);
3401 sljit_free_compiler(compiler
);
3403 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&ibuf
);
3404 FAILED(buf
[0] != RESN(27), "test37 case 1 failed\n");
3405 FAILED(buf
[1] != RESN(47), "test37 case 2 failed\n");
3406 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3407 FAILED(buf
[2] != 64, "test37 case 3 failed\n");
3409 FAILED(buf
[2] != 32, "test37 case 3 failed\n");
3411 FAILED(buf
[3] != 0, "test37 case 4 failed\n");
3412 FAILED(ibuf
[0] != 32, "test37 case 5 failed\n");
3413 FAILED(buf
[4] != RESN(13), "test37 case 6 failed\n");
3414 FAILED(buf
[5] != RESN(58), "test37 case 7 failed\n");
3415 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3416 FAILED(buf
[6] != 64, "test37 case 8 failed\n");
3418 FAILED(buf
[6] != 32, "test37 case 8 failed\n");
3420 FAILED(ibuf
[1] != 4, "test37 case 9 failed\n");
3422 FAILED((buf
[7] & (sljit_sw
)0xffffffff) != 4, "test37 case 10 failed\n");
3423 FAILED((buf
[8] & (sljit_sw
)0xffffffff) != 0, "test37 case 11 failed\n");
3425 sljit_free_code(code
.code
, NULL
);
3431 static void test38(void)
3433 #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)
3434 /* Test stack utility. */
3435 executable_code code
;
3436 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3437 struct sljit_jump
* alloc1_fail
;
3438 struct sljit_jump
* alloc2_fail
;
3439 struct sljit_jump
* alloc3_fail
;
3440 struct sljit_jump
* sanity1_fail
;
3441 struct sljit_jump
* sanity2_fail
;
3442 struct sljit_jump
* sanity3_fail
;
3443 struct sljit_jump
* sanity4_fail
;
3444 struct sljit_jump
* jump
;
3445 struct sljit_label
* label
;
3448 printf("Run test38\n");
3450 FAILED(!compiler
, "cannot create compiler\n");
3452 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), 3, 1, 0, 0, 0);
3454 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8192);
3455 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 65536);
3456 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0);
3457 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(P
, W
, W
, P
), SLJIT_IMM
, SLJIT_FUNC_ADDR(sljit_allocate_stack
));
3458 alloc1_fail
= sljit_emit_cmp(compiler
, SLJIT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0);
3459 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_RETURN_REG
, 0);
3461 /* Write 8k data. */
3462 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3463 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8192);
3464 label
= sljit_emit_label(compiler
);
3465 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_IMM
, -1);
3466 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
3467 jump
= sljit_emit_cmp(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3468 sljit_set_label(jump
, label
);
3471 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
3472 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, end
), SLJIT_IMM
, 65536);
3473 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS2(P
, P
, P
), SLJIT_IMM
, SLJIT_FUNC_ADDR(sljit_stack_resize
));
3474 alloc2_fail
= sljit_emit_cmp(compiler
, SLJIT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0);
3475 sanity1_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3477 /* Write 64k data. */
3478 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3479 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 65536);
3480 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, min_start
));
3481 sanity2_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, 0, SLJIT_R2
, 0);
3482 label
= sljit_emit_label(compiler
);
3483 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_IMM
, -1);
3484 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
3485 jump
= sljit_emit_cmp(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3486 sljit_set_label(jump
, label
);
3489 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
3490 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, end
), SLJIT_IMM
, 32768);
3491 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS2(P
, P
, P
), SLJIT_IMM
, SLJIT_FUNC_ADDR(sljit_stack_resize
));
3492 alloc3_fail
= sljit_emit_cmp(compiler
, SLJIT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0);
3493 sanity3_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3495 /* Write 32k data. */
3496 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3497 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, end
));
3498 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R2
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 32768);
3499 sanity4_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, 0, SLJIT_R2
, 0);
3500 label
= sljit_emit_label(compiler
);
3501 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_IMM
, -1);
3502 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
3503 jump
= sljit_emit_cmp(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3504 sljit_set_label(jump
, label
);
3506 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
3507 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3508 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS2(VOID
, P
, P
), SLJIT_IMM
, SLJIT_FUNC_ADDR(sljit_free_stack
));
3510 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, 4567);
3512 label
= sljit_emit_label(compiler
);
3513 sljit_set_label(alloc1_fail
, label
);
3514 sljit_set_label(alloc2_fail
, label
);
3515 sljit_set_label(alloc3_fail
, label
);
3516 sljit_set_label(sanity1_fail
, label
);
3517 sljit_set_label(sanity2_fail
, label
);
3518 sljit_set_label(sanity3_fail
, label
);
3519 sljit_set_label(sanity4_fail
, label
);
3520 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, 0);
3522 code
.code
= sljit_generate_code(compiler
);
3524 sljit_free_compiler(compiler
);
3526 /* Just survive this. */
3527 FAILED(code
.func0() != 4567, "test38 case 1 failed\n");
3529 sljit_free_code(code
.code
, NULL
);
3534 static void test39(void)
3536 /* Test error handling. */
3537 executable_code code
;
3538 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3539 struct sljit_jump
* jump
;
3542 printf("Run test39\n");
3544 FAILED(!compiler
, "cannot create compiler\n");
3546 /* Such assignment should never happen in a regular program. */
3547 compiler
->error
= -3967;
3549 SLJIT_ASSERT(sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, W
, W
), 5, 5, 6, 0, 32) == -3967);
3550 SLJIT_ASSERT(sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R1
, 0) == -3967);
3551 SLJIT_ASSERT(sljit_emit_op0(compiler
, SLJIT_NOP
) == -3967);
3552 SLJIT_ASSERT(sljit_emit_op0(compiler
, SLJIT_ENDBR
) == -3967);
3553 SLJIT_ASSERT(sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1) == -3967);
3554 SLJIT_ASSERT(sljit_emit_op2(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R0
), 64, SLJIT_MEM1(SLJIT_S0
), -64) == -3967);
3555 SLJIT_ASSERT(sljit_emit_fop1(compiler
, SLJIT_ABS_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_R1
), 0) == -3967);
3556 SLJIT_ASSERT(sljit_emit_fop2(compiler
, SLJIT_DIV_F64
, SLJIT_FR2
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_S0
), 0, SLJIT_FR2
, 0) == -3967);
3557 SLJIT_ASSERT(!sljit_emit_label(compiler
));
3558 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS4(W
, 32, P
, F32
, F64
));
3559 SLJIT_ASSERT(!jump
);
3560 sljit_set_label(jump
, (struct sljit_label
*)0x123450);
3561 sljit_set_target(jump
, 0x123450);
3562 jump
= sljit_emit_cmp(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3563 SLJIT_ASSERT(!jump
);
3564 SLJIT_ASSERT(sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_MEM1(SLJIT_R0
), 8) == -3967);
3565 SLJIT_ASSERT(sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_OVERFLOW
) == -3967);
3566 SLJIT_ASSERT(!sljit_emit_const(compiler
, SLJIT_R0
, 0, 99));
3568 SLJIT_ASSERT(!compiler
->labels
&& !compiler
->jumps
&& !compiler
->consts
);
3569 SLJIT_ASSERT(!compiler
->last_label
&& !compiler
->last_jump
&& !compiler
->last_const
);
3570 SLJIT_ASSERT(!compiler
->buf
->next
&& !compiler
->buf
->used_size
);
3571 SLJIT_ASSERT(!compiler
->abuf
->next
&& !compiler
->abuf
->used_size
);
3573 sljit_set_compiler_memory_error(compiler
);
3574 FAILED(sljit_get_compiler_error(compiler
) != -3967, "test39 case 1 failed\n");
3576 code
.code
= sljit_generate_code(compiler
);
3577 FAILED(sljit_get_compiler_error(compiler
) != -3967, "test39 case 2 failed\n");
3578 FAILED(!!code
.code
, "test39 case 3 failed\n");
3579 sljit_free_compiler(compiler
);
3581 compiler
= sljit_create_compiler(NULL
, NULL
);
3582 FAILED(!compiler
, "cannot create compiler\n");
3584 FAILED(sljit_get_compiler_error(compiler
) != SLJIT_SUCCESS
, "test39 case 4 failed\n");
3585 sljit_set_compiler_memory_error(compiler
);
3586 FAILED(sljit_get_compiler_error(compiler
) != SLJIT_ERR_ALLOC_FAILED
, "test39 case 5 failed\n");
3587 sljit_free_compiler(compiler
);
3592 static void test40(void)
3594 /* Test emit_op_flags. */
3595 executable_code code
;
3596 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3600 printf("Run test40\n");
3602 FAILED(!compiler
, "cannot create compiler\n");
3614 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 4, 0, 0, sizeof(sljit_sw
));
3616 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -5);
3617 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_IMM
, -6, SLJIT_R0
, 0);
3618 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x123456);
3619 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_SIG_LESS
);
3620 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
3622 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -13);
3623 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_IMM
, -13, SLJIT_R0
, 0);
3624 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 0);
3625 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_EQUAL
);
3626 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_NOT_EQUAL
);
3627 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);
3628 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_IMM
, -13, SLJIT_R0
, 0);
3629 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3630 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_EQUAL
);
3631 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_EQUAL
);
3633 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -13);
3634 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3);
3635 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
3636 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R1
), SLJIT_WORD_SHIFT
, SLJIT_SIG_LESS
);
3638 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -8);
3639 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 33);
3640 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3641 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, 0);
3642 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_GREATER
);
3643 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_S1
, 0, SLJIT_EQUAL
);
3644 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3645 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, 0x88);
3646 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_S3
, 0, SLJIT_NOT_EQUAL
);
3647 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_S1
, 0);
3648 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_S3
, 0);
3650 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x84);
3651 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_IMM
, 0x180, SLJIT_R0
, 0);
3652 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_EQUAL
);
3653 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_EQUAL
);
3655 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3656 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3657 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_NOT_EQUAL
);
3658 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_NOT_EQUAL
);
3660 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x123456);
3661 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3662 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_GREATER
);
3663 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_R0
, 0);
3665 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 0xbaddead);
3666 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0);
3668 code
.code
= sljit_generate_code(compiler
);
3670 sljit_free_compiler(compiler
);
3672 FAILED(code
.func1((sljit_sw
)&buf
) != 0xbaddead, "test40 case 1 failed\n");
3673 FAILED(buf
[0] != 0x123457, "test40 case 2 failed\n");
3674 FAILED(buf
[1] != 1, "test40 case 3 failed\n");
3675 FAILED(buf
[2] != 0, "test40 case 4 failed\n");
3676 FAILED(buf
[3] != -7, "test40 case 5 failed\n");
3677 FAILED(buf
[4] != 0, "test40 case 6 failed\n");
3678 FAILED(buf
[5] != 0x89, "test40 case 7 failed\n");
3679 FAILED(buf
[6] != 0, "test40 case 8 failed\n");
3680 FAILED(buf
[7] != 1, "test40 case 9 failed\n");
3681 FAILED(buf
[8] != 1, "test40 case 10 failed\n");
3682 FAILED(buf
[9] != 0x123457, "test40 case 11 failed\n");
3684 sljit_free_code(code
.code
, NULL
);
3688 static void test41(void)
3690 /* Test inline assembly. */
3691 executable_code code
;
3692 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3695 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3697 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3705 printf("Run test41\n");
3707 #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3708 SLJIT_ASSERT(sljit_has_cpu_feature(SLJIT_HAS_VIRTUAL_REGISTERS
) == 0);
3711 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
3712 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3713 if (SLJIT_R(i
) >= SLJIT_R3
&& SLJIT_R(i
) <= SLJIT_R8
) {
3714 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i
)) == -1);
3718 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i
)) >= 0 && sljit_get_register_index(SLJIT_R(i
)) < 64);
3721 FAILED(!compiler
, "cannot create compiler\n");
3722 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(W
, W
, W
), 3, 3, 0, 0, 0);
3724 /* Returns with the sum of SLJIT_S0 and SLJIT_S1. */
3725 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3726 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3729 inst
[2] = (sljit_u8
)(0x04 | ((sljit_get_register_index(SLJIT_RETURN_REG
) & 0x7) << 3));
3730 inst
[3] = (sljit_u8
)((sljit_get_register_index(SLJIT_S0
) & 0x7)
3731 | ((sljit_get_register_index(SLJIT_S1
) & 0x7) << 3));
3732 sljit_emit_op_custom(compiler
, inst
, 4);
3733 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3734 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3735 inst
[0] = 0x48; /* REX_W */
3737 reg
= sljit_get_register_index(SLJIT_RETURN_REG
);
3738 inst
[2] = (sljit_u8
)(0x04 | ((reg
& 0x7) << 3));
3740 inst
[0] |= 0x04; /* REX_R */
3741 reg
= sljit_get_register_index(SLJIT_S0
);
3742 inst
[3] = (sljit_u8
)(reg
& 0x7);
3744 inst
[0] |= 0x01; /* REX_B */
3745 reg
= sljit_get_register_index(SLJIT_S1
);
3746 inst
[3] = (sljit_u8
)(inst
[3] | ((reg
& 0x7) << 3));
3748 inst
[0] |= 0x02; /* REX_X */
3749 sljit_emit_op_custom(compiler
, inst
, 4);
3750 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
3751 /* add rd, rn, rm */
3752 inst
= 0xe0800000 | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 12)
3753 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 16)
3754 | (sljit_u32
)sljit_get_register_index(SLJIT_S1
);
3755 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3756 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
3757 /* add rd, rn, rm */
3758 inst
= 0xeb000000 | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 8)
3759 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 16)
3760 | (sljit_u32
)sljit_get_register_index(SLJIT_S1
);
3761 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3762 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3763 /* add rd, rn, rm */
3764 inst
= 0x8b000000 | (sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
)
3765 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 5)
3766 | ((sljit_u32
)sljit_get_register_index(SLJIT_S1
) << 16);
3767 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3768 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3769 /* add rD, rA, rB */
3770 inst
= (31 << 26) | (266 << 1) | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 21)
3771 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 16)
3772 | ((sljit_u32
)sljit_get_register_index(SLJIT_S1
) << 11);
3773 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3774 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
3775 /* addu rd, rs, rt */
3776 inst
= 33 | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 11)
3777 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 21)
3778 | ((sljit_u32
)sljit_get_register_index(SLJIT_S1
) << 16);
3779 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3780 #elif (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
3781 /* daddu rd, rs, rt */
3782 inst
= 45 | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 11)
3783 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 21)
3784 | ((sljit_u32
)sljit_get_register_index(SLJIT_S1
) << 16);
3785 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3786 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3787 /* add rd, rs1, rs2 */
3788 inst
= (0x2u
<< 30) | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 25)
3789 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 14)
3790 | (sljit_u32
)sljit_get_register_index(SLJIT_S1
);
3791 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3792 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
3793 /* agrk rd, rs1, rs2 */
3794 inst
= (0xb9e8u
<< 16)
3795 | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 4)
3796 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 12)
3797 | (sljit_u32
)sljit_get_register_index(SLJIT_S1
);
3798 sljit_emit_op_custom(compiler
, &inst
, sizeof(inst
));
3801 sljit_emit_op_custom(compiler
, &inst
, 0);
3804 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
3806 code
.code
= sljit_generate_code(compiler
);
3808 sljit_free_compiler(compiler
);
3810 FAILED(code
.func2(32, -11) != 21, "test41 case 1 failed\n");
3811 FAILED(code
.func2(1000, 234) != 1234, "test41 case 2 failed\n");
3812 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3813 FAILED(code
.func2(SLJIT_W(0x20f0a04090c06070), SLJIT_W(0x020f0a04090c0607)) != SLJIT_W(0x22ffaa4499cc6677), "test41 case 3 failed\n");
3816 sljit_free_code(code
.code
, NULL
);
3818 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
3823 compiler
= sljit_create_compiler(NULL
, NULL
);
3824 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 0, 1, 2, 0, 0);
3825 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
3826 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
3827 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3832 inst
[3] = (sljit_u8
)(0xc0 | (sljit_get_float_register_index(SLJIT_FR0
) << 3)
3833 | sljit_get_float_register_index(SLJIT_FR1
));
3834 sljit_emit_op_custom(compiler
, inst
, 4);
3835 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3837 if (sljit_get_float_register_index(SLJIT_FR0
) > 7 || sljit_get_float_register_index(SLJIT_FR1
) > 7) {
3839 if (sljit_get_float_register_index(SLJIT_FR0
) > 7)
3840 inst
[0] |= 0x04; /* REX_R */
3841 if (sljit_get_float_register_index(SLJIT_FR1
) > 7)
3842 inst
[0] |= 0x01; /* REX_B */
3846 inst
[4] = (sljit_u8
)(0xc0 | ((sljit_get_float_register_index(SLJIT_FR0
) & 0x7) << 3)
3847 | (sljit_get_float_register_index(SLJIT_FR1
) & 0x7));
3848 sljit_emit_op_custom(compiler
, inst
, 5);
3854 inst
[3] = (sljit_u8
)(0xc0 | (sljit_get_float_register_index(SLJIT_FR0
) << 3)
3855 | sljit_get_float_register_index(SLJIT_FR1
));
3856 sljit_emit_op_custom(compiler
, inst
, 4);
3858 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
3859 /* vadd.f64 dd, dn, dm */
3860 inst
= 0xee300b00 | (((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) >> 1) << 12)
3861 | (((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) >> 1) << 16)
3862 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
) >> 1);
3863 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3864 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3865 /* fadd rd, rn, rm */
3866 inst
= 0x1e602800 | (sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
)
3867 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 5)
3868 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
) << 16);
3869 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3870 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3871 /* fadd frD, frA, frB */
3872 inst
= (63u << 26) | (21u << 1) | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 21)
3873 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 16)
3874 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
) << 11);
3875 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3876 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
3877 /* add.d fd, fs, ft */
3878 inst
= (17 << 26) | (17 << 21) | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 6)
3879 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 11)
3880 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
) << 16);
3881 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3882 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3883 /* faddd rd, rs1, rs2 */
3884 inst
= (0x2u
<< 30) | (0x34u
<< 19) | (0x42u
<< 5)
3885 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 25)
3886 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 14)
3887 | (sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
);
3888 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3890 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
3891 sljit_emit_return_void(compiler
);
3893 code
.code
= sljit_generate_code(compiler
);
3895 sljit_free_compiler(compiler
);
3897 code
.func1((sljit_sw
)&buf
);
3898 FAILED(buf
[2] != 11.25, "test41 case 3 failed\n");
3900 sljit_free_code(code
.code
, NULL
);
3906 static void test42(void)
3908 /* Test long multiply and division. */
3909 executable_code code
;
3910 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3912 sljit_sw buf
[7 + 4 + 8 + 8];
3915 printf("Run test42\n");
3917 FAILED(!compiler
, "cannot create compiler\n");
3918 for (i
= 0; i
< 7 + 4 + 8 + 8; i
++)
3921 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 5, 5, 0, 0, 0);
3923 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -0x1fb308a);
3924 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0xf50c873);
3925 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, 0x8a0475b);
3926 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, 0x9dc849b);
3927 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -0x7c69a35);
3928 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, 0x5a4d0c4);
3929 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_IMM
, 0x9a3b06d);
3931 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3932 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3933 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3934 sljit_emit_op0(compiler
, SLJIT_LMUL_UW
);
3935 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3936 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3938 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3939 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3940 sljit_emit_op0(compiler
, SLJIT_LMUL_SW
);
3941 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3942 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3944 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3945 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3946 sljit_emit_op0(compiler
, SLJIT_DIVMOD_UW
);
3947 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3948 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3950 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3951 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3952 sljit_emit_op0(compiler
, SLJIT_DIVMOD_SW
);
3953 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3954 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3956 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x5cf783d3cf0a74b0));
3957 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3d5df42d03a28fc7));
3958 sljit_emit_op0(compiler
, SLJIT_DIVMOD_U32
);
3959 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3960 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3961 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3962 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3964 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x371df5197ba26a28));
3965 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x46c78a5cfd6a420c));
3966 sljit_emit_op0(compiler
, SLJIT_DIVMOD_S32
);
3967 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3968 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3969 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3970 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3972 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)SLJIT_W(0xc456f048c28a611b));
3973 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3d4af2c543));
3974 sljit_emit_op0(compiler
, SLJIT_DIV_UW
);
3975 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 19 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3976 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3978 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x720fa4b74c329b14));
3979 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0xa64ae42b7d6));
3980 sljit_emit_op0(compiler
, SLJIT_DIV_SW
);
3981 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 21 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3982 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3984 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x4af51c027b34));
3985 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x9ba4ff2906b14));
3986 sljit_emit_op0(compiler
, SLJIT_DIV_U32
);
3987 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3988 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3989 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 23 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3990 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 24 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3992 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xc40b58a3f20d));
3993 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(-0xa63c923));
3994 sljit_emit_op0(compiler
, SLJIT_DIV_S32
);
3995 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3996 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3997 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 25 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3998 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 26 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4001 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
4002 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
4003 sljit_emit_op0(compiler
, SLJIT_LMUL_UW
);
4004 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4005 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4007 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
4008 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
4009 sljit_emit_op0(compiler
, SLJIT_LMUL_SW
);
4010 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4011 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4013 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
4014 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
4015 sljit_emit_op0(compiler
, SLJIT_DIVMOD_UW
);
4016 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4017 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4019 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
4020 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
4021 sljit_emit_op0(compiler
, SLJIT_DIVMOD_SW
);
4022 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4023 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4025 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0xcf0a74b0);
4026 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0x03a28fc7);
4027 sljit_emit_op0(compiler
, SLJIT_DIVMOD_U32
);
4028 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4029 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4031 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x7ba26a28);
4032 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)0xfd6a420c);
4033 sljit_emit_op0(compiler
, SLJIT_DIVMOD_S32
);
4034 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4035 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4037 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x9d4b7036);
4038 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0xb86d0);
4039 sljit_emit_op0(compiler
, SLJIT_DIV_UW
);
4040 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 19 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4041 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4043 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58b0692c);
4044 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0xd357);
4045 sljit_emit_op0(compiler
, SLJIT_DIV_SW
);
4046 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 21 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4047 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4049 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1c027b34);
4050 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)0xf2906b14);
4051 sljit_emit_op0(compiler
, SLJIT_DIV_U32
);
4052 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4053 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
4054 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 23 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4055 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 24 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4057 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x58a3f20d);
4058 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -0xa63c923);
4059 sljit_emit_op0(compiler
, SLJIT_DIV_S32
);
4060 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4061 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
4062 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 25 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4063 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 26 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4066 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R2
, 0);
4067 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R3
, 0);
4068 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R4
, 0);
4069 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_S1
, 0);
4070 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_S2
, 0);
4071 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_S3
, 0);
4072 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_S4
, 0);
4074 sljit_emit_return_void(compiler
);
4076 code
.code
= sljit_generate_code(compiler
);
4078 sljit_free_compiler(compiler
);
4080 code
.func1((sljit_sw
)&buf
);
4082 FAILED(buf
[0] != -0x1fb308a, "test42 case 1 failed\n");
4083 FAILED(buf
[1] != 0xf50c873, "test42 case 2 failed\n");
4084 FAILED(buf
[2] != 0x8a0475b, "test42 case 3 failed\n");
4085 FAILED(buf
[3] != 0x9dc849b, "test42 case 4 failed\n");
4086 FAILED(buf
[4] != -0x7c69a35, "test42 case 5 failed\n");
4087 FAILED(buf
[5] != 0x5a4d0c4, "test42 case 6 failed\n");
4088 FAILED(buf
[6] != 0x9a3b06d, "test42 case 7 failed\n");
4090 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4091 FAILED(buf
[7] != SLJIT_W(-4388959407985636971), "test42 case 8 failed\n");
4092 FAILED(buf
[8] != SLJIT_W(2901680654366567099), "test42 case 9 failed\n");
4093 FAILED(buf
[9] != SLJIT_W(-4388959407985636971), "test42 case 10 failed\n");
4094 FAILED(buf
[10] != SLJIT_W(-1677173957268872740), "test42 case 11 failed\n");
4095 FAILED(buf
[11] != SLJIT_W(2), "test42 case 12 failed\n");
4096 FAILED(buf
[12] != SLJIT_W(2532236178951865933), "test42 case 13 failed\n");
4097 FAILED(buf
[13] != SLJIT_W(-1), "test42 case 14 failed\n");
4098 FAILED(buf
[14] != SLJIT_W(-2177944059851366166), "test42 case 15 failed\n");
4100 FAILED(buf
[7] != -1587000939, "test42 case 8 failed\n");
4101 FAILED(buf
[8] != 665003983, "test42 case 9 failed\n");
4102 FAILED(buf
[9] != -1587000939, "test42 case 10 failed\n");
4103 FAILED(buf
[10] != -353198352, "test42 case 11 failed\n");
4104 FAILED(buf
[11] != 2, "test42 case 12 failed\n");
4105 FAILED(buf
[12] != 768706125, "test42 case 13 failed\n");
4106 FAILED(buf
[13] != -1, "test42 case 14 failed\n");
4107 FAILED(buf
[14] != -471654166, "test42 case 15 failed\n");
4110 FAILED(buf
[15] != 56, "test42 case 16 failed\n");
4111 FAILED(buf
[16] != 58392872, "test42 case 17 failed\n");
4112 FAILED(buf
[17] != -47, "test42 case 18 failed\n");
4113 FAILED(buf
[18] != 35949148, "test42 case 19 failed\n");
4115 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4116 FAILED(buf
[19] != SLJIT_W(0x3340bfc), "test42 case 20 failed\n");
4117 FAILED(buf
[20] != SLJIT_W(0x3d4af2c543), "test42 case 21 failed\n");
4118 FAILED(buf
[21] != SLJIT_W(-0xaf978), "test42 case 22 failed\n");
4119 FAILED(buf
[22] != SLJIT_W(0xa64ae42b7d6), "test42 case 23 failed\n");
4121 FAILED(buf
[19] != SLJIT_W(0xda5), "test42 case 20 failed\n");
4122 FAILED(buf
[20] != SLJIT_W(0xb86d0), "test42 case 21 failed\n");
4123 FAILED(buf
[21] != SLJIT_W(-0x6b6e), "test42 case 22 failed\n");
4124 FAILED(buf
[22] != SLJIT_W(0xd357), "test42 case 23 failed\n");
4127 FAILED(buf
[23] != 0x0, "test42 case 24 failed\n");
4128 FAILED(buf
[24] != (sljit_sw
)0xf2906b14, "test42 case 25 failed\n");
4129 FAILED(buf
[25] != -0x8, "test42 case 26 failed\n");
4130 FAILED(buf
[26] != -0xa63c923, "test42 case 27 failed\n");
4132 sljit_free_code(code
.code
, NULL
);
4136 static void test43(void)
4138 /* Test floating point compare. */
4139 executable_code code
;
4140 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4141 struct sljit_jump
* jump
;
4152 printf("Run test43\n");
4154 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4156 printf("no fpu available, test43 skipped\n");
4159 sljit_free_compiler(compiler
);
4163 FAILED(!compiler
, "cannot create compiler\n");
4165 dbuf
[0].value
= 12.125;
4167 dbuf
[1].u
.value1
= 0x7fffffff;
4168 dbuf
[1].u
.value2
= 0x7fffffff;
4169 dbuf
[2].value
= -13.5;
4170 dbuf
[3].value
= 12.125;
4172 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 1, 1, 3, 0, 0);
4173 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
4174 /* dbuf[0] < dbuf[2] -> -2 */
4175 jump
= sljit_emit_fcmp(compiler
, SLJIT_GREATER_EQUAL_F64
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), SLJIT_F64_SHIFT
);
4176 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, -2);
4178 sljit_set_label(jump
, sljit_emit_label(compiler
));
4179 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4180 /* dbuf[0] and dbuf[1] is not NaN -> 5 */
4181 jump
= sljit_emit_fcmp(compiler
, SLJIT_UNORDERED_F64
, SLJIT_MEM0(), (sljit_sw
)&dbuf
[1], SLJIT_FR1
, 0);
4182 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, 5);
4184 sljit_set_label(jump
, sljit_emit_label(compiler
));
4185 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
));
4186 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 11);
4187 /* dbuf[0] == dbuf[3] -> 11 */
4188 jump
= sljit_emit_fcmp(compiler
, SLJIT_EQUAL_F64
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_FR2
, 0);
4191 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, -17);
4192 sljit_set_label(jump
, sljit_emit_label(compiler
));
4193 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
4195 code
.code
= sljit_generate_code(compiler
);
4197 sljit_free_compiler(compiler
);
4199 FAILED(code
.func1((sljit_sw
)&dbuf
) != 11, "test43 case 1 failed\n");
4201 FAILED(code
.func1((sljit_sw
)&dbuf
) != -17, "test43 case 2 failed\n");
4203 FAILED(code
.func1((sljit_sw
)&dbuf
) != 5, "test43 case 3 failed\n");
4205 FAILED(code
.func1((sljit_sw
)&dbuf
) != -2, "test43 case 4 failed\n");
4207 sljit_free_code(code
.code
, NULL
);
4211 static void test44(void)
4214 executable_code code
;
4215 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4219 printf("Run test44\n");
4221 FAILED(!compiler
, "cannot create compiler\n");
4228 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(P
, P
), 3, 2, 0, 0, 0);
4230 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4231 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_p
), SLJIT_R0
, 0);
4232 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_p
));
4233 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 2);
4234 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R1
), SLJIT_POINTER_SHIFT
, SLJIT_R0
, 0);
4235 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_p
));
4236 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3 << SLJIT_POINTER_SHIFT
);
4237 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_S0
, 0);
4238 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM2(SLJIT_R2
, SLJIT_R1
), 0, SLJIT_R0
, 0);
4239 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 2 * sizeof(sljit_p
));
4240 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1 << SLJIT_POINTER_SHIFT
);
4241 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM2(SLJIT_R2
, SLJIT_R1
), 2, SLJIT_R0
, 0);
4243 sljit_emit_return(compiler
, SLJIT_MOV_P
, SLJIT_R0
, 0);
4245 code
.code
= sljit_generate_code(compiler
);
4247 sljit_free_compiler(compiler
);
4249 FAILED(code
.func1((sljit_sw
)&buf
) != (sljit_sw
)(buf
+ 2), "test44 case 1 failed\n");
4250 FAILED(buf
[1] != buf
+ 2, "test44 case 2 failed\n");
4251 FAILED(buf
[2] != buf
+ 3, "test44 case 3 failed\n");
4252 FAILED(buf
[3] != buf
+ 4, "test44 case 4 failed\n");
4253 FAILED(buf
[4] != buf
+ 2, "test44 case 5 failed\n");
4255 sljit_free_code(code
.code
, NULL
);
4259 static void test45(void)
4261 /* Test single precision floating point. */
4263 executable_code code
;
4264 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4267 struct sljit_jump
* jump
;
4270 printf("Run test45\n");
4272 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4274 printf("no fpu available, test45 skipped\n");
4277 sljit_free_compiler(compiler
);
4281 FAILED(!compiler
, "cannot create compiler\n");
4303 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 3, 2, 6, 0, 0);
4305 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4306 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4307 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
4308 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_FR1
, 0, SLJIT_FR5
, 0);
4309 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f32
), SLJIT_FR1
, 0);
4310 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f32
), SLJIT_FR5
, 0);
4311 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_FR4
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4312 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f32
), SLJIT_FR4
, 0);
4314 sljit_emit_fop2(compiler
, SLJIT_ADD_F32
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4315 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
4316 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);
4317 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4318 sljit_emit_fop2(compiler
, SLJIT_MUL_F32
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_f32
), SLJIT_FR0
, 0, SLJIT_FR0
, 0);
4319 sljit_emit_fop2(compiler
, SLJIT_DIV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
4320 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f32
), SLJIT_FR2
, 0);
4321 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x3d0ac);
4322 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_R0
), 0x3d0ac);
4323 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x3d0ac + sizeof(sljit_f32
));
4324 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_R0
), -0x3d0ac);
4326 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4327 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4328 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4329 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_EQUAL_F32
);
4330 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_LESS_F
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4331 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
), SLJIT_LESS_F32
);
4332 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
4333 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
), SLJIT_EQUAL_F32
);
4334 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_GREATER_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
4335 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
), SLJIT_GREATER_EQUAL_F32
);
4337 jump
= sljit_emit_fcmp(compiler
, SLJIT_LESS_EQUAL_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4338 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, 7);
4339 sljit_set_label(jump
, sljit_emit_label(compiler
));
4341 jump
= sljit_emit_fcmp(compiler
, SLJIT_GREATER_F32
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_FR2
, 0);
4342 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_IMM
, 6);
4343 sljit_set_label(jump
, sljit_emit_label(compiler
));
4345 sljit_emit_return_void(compiler
);
4347 code
.code
= sljit_generate_code(compiler
);
4349 sljit_free_compiler(compiler
);
4351 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&buf2
);
4352 FAILED(buf
[2] != -5.5, "test45 case 1 failed\n");
4353 FAILED(buf
[3] != 7.25, "test45 case 2 failed\n");
4354 FAILED(buf
[4] != 7.25, "test45 case 3 failed\n");
4355 FAILED(buf
[5] != -5.5, "test45 case 4 failed\n");
4356 FAILED(buf
[6] != -1.75, "test45 case 5 failed\n");
4357 FAILED(buf
[7] != 16.0, "test45 case 6 failed\n");
4358 FAILED(buf
[8] != 30.25, "test45 case 7 failed\n");
4359 FAILED(buf
[9] != 3, "test45 case 8 failed\n");
4360 FAILED(buf
[10] != -5.5, "test45 case 9 failed\n");
4361 FAILED(buf
[11] != 7.25, "test45 case 10 failed\n");
4362 FAILED(buf2
[0] != 1, "test45 case 11 failed\n");
4363 FAILED(buf2
[1] != 2, "test45 case 12 failed\n");
4364 FAILED(buf2
[2] != 2, "test45 case 13 failed\n");
4365 FAILED(buf2
[3] != 1, "test45 case 14 failed\n");
4366 FAILED(buf2
[4] != 7, "test45 case 15 failed\n");
4367 FAILED(buf2
[5] != -1, "test45 case 16 failed\n");
4369 sljit_free_code(code
.code
, NULL
);
4373 static void test46(void)
4375 /* Test sljit_emit_op_flags with 32 bit operations. */
4377 executable_code code
;
4378 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4384 printf("Run test46\n");
4386 for (i
= 0; i
< 24; ++i
)
4389 for (i
= 0; i
< 6; ++i
)
4393 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 3, 3, 0, 0, 0);
4395 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4396 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_R2
, 0, SLJIT_IMM
, 13);
4397 sljit_emit_op_flags(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&buf
, SLJIT_LESS
);
4398 sljit_emit_op_flags(compiler
, SLJIT_AND32
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_s32
), SLJIT_NOT_ZERO
);
4400 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4401 sljit_emit_op_flags(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_s32
), SLJIT_EQUAL
);
4402 sljit_emit_op_flags(compiler
, SLJIT_AND32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_s32
), SLJIT_NOT_EQUAL
);
4403 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1235);
4404 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1235);
4405 sljit_emit_op_flags(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_ZERO
);
4406 sljit_emit_op_flags(compiler
, SLJIT_AND32
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_s32
), SLJIT_ZERO
);
4407 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4409 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4410 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 12);
4411 sljit_emit_op_flags(compiler
, SLJIT_MOV32
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 2, SLJIT_EQUAL
);
4412 sljit_emit_op_flags(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_EQUAL
);
4413 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4414 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
4415 sljit_emit_op_flags(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 2, SLJIT_EQUAL
);
4416 sljit_emit_op_flags(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_s32
), SLJIT_NOT_EQUAL
);
4418 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4419 sljit_emit_op_flags(compiler
, SLJIT_XOR32
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_s32
), SLJIT_ZERO
);
4420 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 39);
4421 sljit_emit_op_flags(compiler
, SLJIT_XOR32
, SLJIT_R0
, 0, SLJIT_NOT_ZERO
);
4422 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4424 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4425 sljit_emit_op_flags(compiler
, SLJIT_AND
, SLJIT_MEM0(), (sljit_sw
)&buf2
, SLJIT_GREATER
);
4426 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R2
, 0, SLJIT_IMM
, 5);
4427 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
4428 sljit_emit_op_flags(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_SIG_LESS
);
4429 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
4430 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_R2
, 0, SLJIT_IMM
, 5);
4431 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_LESS
);
4432 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_NOT_EQUAL
);
4433 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R2
, 0, SLJIT_IMM
, 5);
4434 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
), SLJIT_S2
, 0);
4435 sljit_emit_op_flags(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_SIG_LESS
);
4436 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_ZERO
);
4437 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R2
, 0, SLJIT_IMM
, 0);
4438 sljit_emit_op_flags(compiler
, SLJIT_XOR
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_GREATER
);
4440 sljit_emit_return_void(compiler
);
4442 code
.code
= sljit_generate_code(compiler
);
4444 sljit_free_compiler(compiler
);
4446 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&buf2
);
4447 FAILED(buf
[0] != 0, "test46 case 1 failed\n");
4448 FAILED(buf
[1] != -17, "test46 case 2 failed\n");
4449 FAILED(buf
[2] != 1, "test46 case 3 failed\n");
4450 FAILED(buf
[3] != -17, "test46 case 4 failed\n");
4451 FAILED(buf
[4] != 1, "test46 case 5 failed\n");
4452 FAILED(buf
[5] != -17, "test46 case 6 failed\n");
4453 FAILED(buf
[6] != 1, "test46 case 7 failed\n");
4454 FAILED(buf
[7] != -17, "test46 case 8 failed\n");
4455 FAILED(buf
[8] != 0, "test46 case 9 failed\n");
4456 FAILED(buf
[9] != -17, "test46 case 10 failed\n");
4457 FAILED(buf
[10] != 1, "test46 case 11 failed\n");
4458 FAILED(buf
[11] != -17, "test46 case 12 failed\n");
4459 FAILED(buf
[12] != 1, "test46 case 13 failed\n");
4460 FAILED(buf
[13] != -17, "test46 case 14 failed\n");
4461 FAILED(buf
[14] != 1, "test46 case 15 failed\n");
4462 FAILED(buf
[15] != -17, "test46 case 16 failed\n");
4463 FAILED(buf
[16] != 0, "test46 case 17 failed\n");
4464 FAILED(buf
[17] != -17, "test46 case 18 failed\n");
4465 FAILED(buf
[18] != 0, "test46 case 19 failed\n");
4466 FAILED(buf
[19] != -17, "test46 case 20 failed\n");
4467 FAILED(buf
[20] != -18, "test46 case 21 failed\n");
4468 FAILED(buf
[21] != -17, "test46 case 22 failed\n");
4469 FAILED(buf
[22] != 38, "test46 case 23 failed\n");
4470 FAILED(buf
[23] != -17, "test46 case 24 failed\n");
4472 FAILED(buf2
[0] != 0, "test46 case 25 failed\n");
4473 FAILED(buf2
[1] != 1, "test46 case 26 failed\n");
4474 FAILED(buf2
[2] != 0, "test46 case 27 failed\n");
4475 FAILED(buf2
[3] != 1, "test46 case 28 failed\n");
4476 FAILED(buf2
[4] != -123, "test46 case 29 failed\n");
4477 FAILED(buf2
[5] != -14, "test46 case 30 failed\n");
4479 sljit_free_code(code
.code
, NULL
);
4483 static void test47(void)
4485 /* Test jump optimizations. */
4486 executable_code code
;
4487 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4491 printf("Run test47\n");
4493 FAILED(!compiler
, "cannot create compiler\n");
4498 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 0);
4499 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x3a5c6f);
4500 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
4501 sljit_set_target(sljit_emit_jump(compiler
, SLJIT_LESS
), 0x11223344);
4502 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
4503 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xd37c10);
4504 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4505 sljit_set_target(sljit_emit_jump(compiler
, SLJIT_LESS
), SLJIT_W(0x112233445566));
4507 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
4508 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x59b48e);
4509 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4510 sljit_set_target(sljit_emit_jump(compiler
, SLJIT_LESS
), SLJIT_W(0x1122334455667788));
4512 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4513 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
4515 code
.code
= sljit_generate_code(compiler
);
4517 sljit_free_compiler(compiler
);
4519 FAILED(code
.func1((sljit_sw
)&buf
) != 0x59b48e, "test47 case 1 failed\n");
4520 FAILED(buf
[0] != 0x3a5c6f, "test47 case 2 failed\n");
4521 FAILED(buf
[1] != 0xd37c10, "test47 case 3 failed\n");
4522 FAILED(buf
[2] != 0x59b48e, "test47 case 4 failed\n");
4524 sljit_free_code(code
.code
, NULL
);
4528 static void test48(void)
4530 /* Test floating point conversions. */
4531 executable_code code
;
4532 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4540 printf("Run test48\n");
4542 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4544 printf("no fpu available, test48 skipped\n");
4547 sljit_free_compiler(compiler
);
4551 FAILED(!compiler
, "cannot create compiler\n");
4552 for (i
= 0; i
< 10; i
++) {
4571 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 3, 3, 6, 0, 0);
4572 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
4573 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, (sljit_sw
)&sbuf
);
4574 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
4575 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
4578 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_F64
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S0
), 0);
4579 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4580 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
4582 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_F64
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_F32_SHIFT
, SLJIT_FR5
, 0);
4583 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_F32
, SLJIT_FR4
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
4585 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
), SLJIT_FR4
, 0);
4586 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
4587 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_F32
, SLJIT_FR2
, 0, SLJIT_FR3
, 0);
4589 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
4591 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_f32
), SLJIT_FR3
, 0);
4594 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
4595 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
4596 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_R0
, 0, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), SLJIT_F64_SHIFT
);
4598 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4599 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
4601 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F32
, SLJIT_MEM1(SLJIT_S2
), 3 * sizeof(sljit_sw
), SLJIT_FR5
, 0);
4602 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_FR0
, 0, SLJIT_FR5
, 0);
4603 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 4);
4605 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F32
, SLJIT_MEM2(SLJIT_S2
, SLJIT_R1
), SLJIT_WORD_SHIFT
, SLJIT_FR0
, 0);
4606 sljit_emit_fop1(compiler
, SLJIT_NEG_F64
, SLJIT_FR4
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
));
4608 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F64
, SLJIT_MEM1(SLJIT_R2
), 2 * sizeof(sljit_s32
), SLJIT_FR4
, 0);
4609 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
4610 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F32
, SLJIT_R0
, 0, SLJIT_FR1
, 0);
4612 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_R2
), 3 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4615 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S2
), 0);
4616 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_FR2
, 0, SLJIT_IMM
, -6213);
4618 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
4620 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_f64
), SLJIT_MEM0(), (sljit_sw
)&ibuf
[0]);
4621 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R2
), sizeof(sljit_s32
));
4622 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_FR1
, 0, SLJIT_R0
, 0);
4624 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_f64
), SLJIT_FR1
, 0);
4626 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM0(), (sljit_sw
)(dbuf
+ 9), SLJIT_IMM
, -77);
4628 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_f32
), SLJIT_IMM
, -123);
4629 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 7190);
4630 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_FR3
, 0, SLJIT_R0
, 0);
4632 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 6 * sizeof(sljit_f32
), SLJIT_FR3
, 0);
4633 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 123);
4634 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 123 * sizeof(sljit_s32
));
4635 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_S32
, SLJIT_FR1
, 0, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 2);
4637 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 7 * sizeof(sljit_f32
), SLJIT_FR1
, 0);
4638 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
4639 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 3812);
4641 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_S32
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_F32_SHIFT
, SLJIT_R1
, 0);
4643 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_MEM0(), (sljit_sw
)(sbuf
+ 9), SLJIT_IMM
, -79);
4645 sljit_emit_return_void(compiler
);
4647 code
.code
= sljit_generate_code(compiler
);
4649 sljit_free_compiler(compiler
);
4652 FAILED(dbuf
[3] != 476.25, "test48 case 1 failed\n");
4653 FAILED(dbuf
[4] != 476.25, "test48 case 2 failed\n");
4654 FAILED(dbuf
[5] != 2345.0, "test48 case 3 failed\n");
4655 FAILED(dbuf
[6] != -6213.0, "test48 case 4 failed\n");
4656 FAILED(dbuf
[7] != 312.0, "test48 case 5 failed\n");
4657 FAILED(dbuf
[8] != -9324.0, "test48 case 6 failed\n");
4658 FAILED(dbuf
[9] != -77.0, "test48 case 7 failed\n");
4660 FAILED(sbuf
[2] != 123.5, "test48 case 8 failed\n");
4661 FAILED(sbuf
[3] != 123.5, "test48 case 9 failed\n");
4662 FAILED(sbuf
[4] != 476.25, "test48 case 10 failed\n");
4663 FAILED(sbuf
[5] != -123, "test48 case 11 failed\n");
4664 FAILED(sbuf
[6] != 7190, "test48 case 12 failed\n");
4665 FAILED(sbuf
[7] != 312, "test48 case 13 failed\n");
4666 FAILED(sbuf
[8] != 3812, "test48 case 14 failed\n");
4667 FAILED(sbuf
[9] != -79.0, "test48 case 15 failed\n");
4669 FAILED(wbuf
[1] != -367, "test48 case 16 failed\n");
4670 FAILED(wbuf
[2] != 917, "test48 case 17 failed\n");
4671 FAILED(wbuf
[3] != 476, "test48 case 18 failed\n");
4672 FAILED(wbuf
[4] != -476, "test48 case 19 failed\n");
4674 FAILED(ibuf
[2] != -917, "test48 case 20 failed\n");
4675 FAILED(ibuf
[3] != -1689, "test48 case 21 failed\n");
4677 sljit_free_code(code
.code
, NULL
);
4681 static void test49(void)
4683 /* Test floating point conversions. */
4684 executable_code code
;
4685 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4691 sljit_s32
* dbuf_ptr
= (sljit_s32
*)dbuf
;
4692 sljit_s32
* sbuf_ptr
= (sljit_s32
*)sbuf
;
4695 printf("Run test49\n");
4697 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4699 printf("no fpu available, test49 skipped\n");
4702 sljit_free_compiler(compiler
);
4706 FAILED(!compiler
, "cannot create compiler\n");
4708 for (i
= 0; i
< 9; i
++) {
4709 dbuf_ptr
[i
<< 1] = -1;
4710 dbuf_ptr
[(i
<< 1) + 1] = -1;
4716 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4717 dbuf
[9] = (sljit_f64
)SLJIT_W(0x1122334455);
4724 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 3, 3, 3, 0, 0);
4725 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
4726 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, (sljit_sw
)&sbuf
);
4727 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
4728 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
4731 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_F32
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S1
), 0);
4733 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_F64
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S0
), 0);
4735 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 0);
4737 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F32
, SLJIT_MEM1(SLJIT_S2
), 4 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S1
), 0);
4739 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F64
, SLJIT_MEM1(SLJIT_R2
), 2 * sizeof(sljit_s32
), SLJIT_MEM1(SLJIT_S0
), 0);
4741 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F32
, SLJIT_MEM1(SLJIT_R2
), 4 * sizeof(sljit_s32
), SLJIT_MEM1(SLJIT_S1
), 0);
4743 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S2
), 0);
4745 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S2
), 0);
4747 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_R2
), 0);
4749 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_S32
, SLJIT_MEM1(SLJIT_S1
), 6 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_R2
), 0);
4751 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4752 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f64
));
4754 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), 8 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4755 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f64
));
4756 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F64
, SLJIT_R0
, 0, SLJIT_FR2
, 0);
4757 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4758 sljit_emit_op2(compiler
, SLJIT_AND32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffff);
4760 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R2
), 8 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4761 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x4455667788));
4763 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_f64
), SLJIT_R0
, 0);
4765 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f64
), SLJIT_IMM
, SLJIT_W(0x7766554433));
4768 sljit_emit_return_void(compiler
);
4770 code
.code
= sljit_generate_code(compiler
);
4772 sljit_free_compiler(compiler
);
4776 FAILED(dbuf_ptr
[(1 * 2) + 0] != -1, "test49 case 1 failed\n");
4777 FAILED(dbuf_ptr
[(1 * 2) + 1] != -1, "test49 case 2 failed\n");
4778 FAILED(dbuf
[2] != -879.75, "test49 case 3 failed\n");
4779 FAILED(dbuf_ptr
[(3 * 2) + 0] != -1, "test49 case 4 failed\n");
4780 FAILED(dbuf_ptr
[(3 * 2) + 1] != -1, "test49 case 5 failed\n");
4781 FAILED(dbuf
[4] != 345, "test49 case 6 failed\n");
4782 FAILED(dbuf_ptr
[(5 * 2) + 0] != -1, "test49 case 7 failed\n");
4783 FAILED(dbuf_ptr
[(5 * 2) + 1] != -1, "test49 case 8 failed\n");
4784 FAILED(dbuf
[6] != -249, "test49 case 9 failed\n");
4785 FAILED(dbuf_ptr
[(7 * 2) + 0] != -1, "test49 case 10 failed\n");
4786 FAILED(dbuf_ptr
[(7 * 2) + 1] != -1, "test49 case 11 failed\n");
4788 FAILED(sbuf_ptr
[1] != -1, "test49 case 12 failed\n");
4789 FAILED(sbuf
[2] != 673.75, "test49 case 13 failed\n");
4790 FAILED(sbuf_ptr
[3] != -1, "test49 case 14 failed\n");
4791 FAILED(sbuf
[4] != 345, "test49 case 15 failed\n");
4792 FAILED(sbuf_ptr
[5] != -1, "test49 case 16 failed\n");
4793 FAILED(sbuf
[6] != -249, "test49 case 17 failed\n");
4794 FAILED(sbuf_ptr
[7] != -1, "test49 case 18 failed\n");
4796 FAILED(wbuf
[1] != -1, "test49 case 19 failed\n");
4797 FAILED(wbuf
[2] != 673, "test49 case 20 failed\n");
4798 FAILED(wbuf
[3] != -1, "test49 case 21 failed\n");
4799 FAILED(wbuf
[4] != -879, "test49 case 22 failed\n");
4800 FAILED(wbuf
[5] != -1, "test49 case 23 failed\n");
4802 FAILED(ibuf
[1] != -1, "test49 case 24 failed\n");
4803 FAILED(ibuf
[2] != 673, "test49 case 25 failed\n");
4804 FAILED(ibuf
[3] != -1, "test49 case 26 failed\n");
4805 FAILED(ibuf
[4] != -879, "test49 case 27 failed\n");
4806 FAILED(ibuf
[5] != -1, "test49 case 28 failed\n");
4808 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4809 FAILED(dbuf
[8] != (sljit_f64
)SLJIT_W(0x4455667788), "test49 case 29 failed\n");
4810 FAILED(dbuf
[9] != (sljit_f64
)SLJIT_W(0x66554433), "test49 case 30 failed\n");
4811 FAILED(wbuf
[8] != SLJIT_W(0x1122334455), "test48 case 31 failed\n");
4812 FAILED(ibuf
[8] == 0x4455, "test48 case 32 failed\n");
4815 sljit_free_code(code
.code
, NULL
);
4819 static void test50(void)
4821 /* Test stack and floating point operations. */
4822 executable_code code
;
4823 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4824 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4825 sljit_uw size1
, size2
, size3
;
4831 printf("Run test50\n");
4833 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4835 printf("no fpu available, test50 skipped\n");
4838 sljit_free_compiler(compiler
);
4842 FAILED(!compiler
, "cannot create compiler\n");
4848 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 3, 6, 0, 8 * sizeof(sljit_f32
));
4850 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
4851 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), 0);
4853 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_f32
));
4854 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4855 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
));
4857 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), 2 * sizeof(sljit_f32
));
4858 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 2 * sizeof(sljit_f32
), SLJIT_IMM
, 5934);
4859 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
));
4861 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), 3 * sizeof(sljit_f32
));
4863 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4864 size1
= compiler
->size
;
4866 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f32
));
4867 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4868 size2
= compiler
->size
;
4870 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR5
, 0, SLJIT_FR2
, 0);
4871 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4872 size3
= compiler
->size
;
4875 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f32
), SLJIT_FR5
, 0);
4876 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4877 result
= (compiler
->size
- size3
) == (size3
- size2
) && (size3
- size2
) == (size2
- size1
);
4880 sljit_emit_return_void(compiler
);
4882 code
.code
= sljit_generate_code(compiler
);
4884 sljit_free_compiler(compiler
);
4886 code
.func1((sljit_sw
)&sbuf
);
4888 FAILED(sbuf
[3] != 245.5, "test50 case 1 failed\n");
4889 FAILED(sbuf
[4] != 145.25, "test50 case 2 failed\n");
4890 FAILED(sbuf
[5] != 5934, "test50 case 3 failed\n");
4891 FAILED(sbuf
[6] != 713.75, "test50 case 4 failed\n");
4892 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4893 FAILED(!result
, "test50 case 5 failed\n");
4896 sljit_free_code(code
.code
, NULL
);
4900 static void test51(void)
4902 /* Test all registers provided by the CPU. */
4903 executable_code code
;
4904 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4905 struct sljit_jump
* jump
;
4910 printf("Run test51\n");
4912 FAILED(!compiler
, "cannot create compiler\n");
4916 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0, 0);
4918 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4919 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 32);
4921 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)buf
);
4922 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
4924 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
4925 if (sljit_get_register_index(SLJIT_R(i
)) >= 0) {
4926 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_R0
, 0);
4927 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_R(i
)), 0);
4929 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, buf
[0]);
4932 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 32);
4933 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
4934 if (sljit_get_register_index(SLJIT_R(i
)) >= 0) {
4935 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_R0
, 0);
4936 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_R(i
)), 32);
4938 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, buf
[0]);
4941 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
4942 if (sljit_get_register_index(SLJIT_R(i
)) >= 0) {
4943 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 32);
4944 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM2(SLJIT_R(i
), SLJIT_R0
), 0);
4945 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_R(i
)), 0);
4946 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 8);
4947 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_R(i
)), 2);
4949 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 3 * buf
[0]);
4952 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 32 + sizeof(sljit_sw
), SLJIT_R1
, 0);
4954 sljit_emit_return_void(compiler
);
4956 code
.code
= sljit_generate_code(compiler
);
4958 sljit_free_compiler(compiler
);
4962 FAILED(buf
[1] != (39 * 5 * (SLJIT_NUMBER_OF_REGISTERS
- 2)), "test51 case 1 failed\n");
4964 sljit_free_code(code
.code
, NULL
);
4968 compiler
= sljit_create_compiler(NULL
, NULL
);
4970 FAILED(!compiler
, "cannot create compiler\n");
4972 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), SLJIT_NUMBER_OF_SCRATCH_REGISTERS
, SLJIT_NUMBER_OF_SAVED_REGISTERS
, 0, 0, 0);
4974 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4975 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 17);
4977 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS0(W
));
4978 /* SLJIT_R0 contains the first value. */
4979 for (i
= 1; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4980 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
4982 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
4984 sljit_set_label(jump
, sljit_emit_label(compiler
));
4985 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), SLJIT_NUMBER_OF_REGISTERS
, 0, 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
, 35);
4988 sljit_emit_return_void(compiler
);
4990 code
.code
= sljit_generate_code(compiler
);
4992 sljit_free_compiler(compiler
);
4994 FAILED(code
.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS
* 35 + SLJIT_NUMBER_OF_SAVED_REGISTERS
* 17), "test51 case 2 failed\n");
4996 sljit_free_code(code
.code
, NULL
);
5000 compiler
= sljit_create_compiler(NULL
, NULL
);
5002 FAILED(!compiler
, "cannot create compiler\n");
5004 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), SLJIT_NUMBER_OF_SCRATCH_REGISTERS
, SLJIT_NUMBER_OF_SAVED_REGISTERS
, 0, 0, 0);
5006 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5007 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 68);
5009 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS0(W
));
5010 /* SLJIT_R0 contains the first value. */
5011 for (i
= 1; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5012 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
5014 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
5016 sljit_set_label(jump
, sljit_emit_label(compiler
));
5017 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 0, SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0);
5018 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5019 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S(i
), 0, SLJIT_IMM
, 43);
5020 sljit_emit_return_void(compiler
);
5022 code
.code
= sljit_generate_code(compiler
);
5024 sljit_free_compiler(compiler
);
5026 FAILED(code
.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS
* 43 + SLJIT_NUMBER_OF_SAVED_REGISTERS
* 68), "test51 case 3 failed\n");
5028 sljit_free_code(code
.code
, NULL
);
5032 static void test52(void)
5034 /* Test all registers provided by the CPU. */
5035 executable_code code
;
5036 struct sljit_compiler
* compiler
;
5037 struct sljit_jump
* jump
;
5042 printf("Run test52\n");
5044 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5046 printf("no fpu available, test52 skipped\n");
5053 compiler
= sljit_create_compiler(NULL
, NULL
);
5054 FAILED(!compiler
, "cannot create compiler\n");
5058 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
, 0);
5060 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5061 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
5063 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS0(VOID
));
5064 /* SLJIT_FR0 contains the first value. */
5065 for (i
= 1; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5066 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_FR(i
), 0);
5067 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5069 sljit_emit_return_void(compiler
);
5071 sljit_set_label(jump
, sljit_emit_label(compiler
));
5072 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 1, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0, 0);
5073 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[1]);
5074 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5075 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_MEM1(SLJIT_R0
), 0);
5076 sljit_emit_return_void(compiler
);
5078 code
.code
= sljit_generate_code(compiler
);
5080 sljit_free_compiler(compiler
);
5082 code
.func1((sljit_sw
)&buf
);
5083 FAILED(buf
[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
* 17.75 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
* 6.25), "test52 case 1 failed\n");
5085 sljit_free_code(code
.code
, NULL
);
5089 compiler
= sljit_create_compiler(NULL
, NULL
);
5090 FAILED(!compiler
, "cannot create compiler\n");
5094 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
, 0);
5096 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5097 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
5099 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS0(VOID
));
5100 /* SLJIT_FR0 contains the first value. */
5101 for (i
= 1; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5102 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_FR(i
), 0);
5103 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5105 sljit_emit_return_void(compiler
);
5107 sljit_set_label(jump
, sljit_emit_label(compiler
));
5108 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 1, 0, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0);
5109 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[1]);
5110 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5111 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FS(i
), 0, SLJIT_MEM1(SLJIT_R0
), 0);
5112 sljit_emit_return_void(compiler
);
5114 code
.code
= sljit_generate_code(compiler
);
5116 sljit_free_compiler(compiler
);
5118 code
.func1((sljit_sw
)&buf
);
5119 FAILED(buf
[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
* -11.25 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
* -32.5), "test52 case 2 failed\n");
5121 sljit_free_code(code
.code
, NULL
);
5125 static void test53(void)
5127 /* Check SLJIT_DOUBLE_ALIGNMENT. */
5128 executable_code code
;
5129 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5133 printf("Run test53\n");
5135 FAILED(!compiler
, "cannot create compiler\n");
5138 sljit_emit_enter(compiler
, SLJIT_F64_ALIGNMENT
, SLJIT_ARGS1(VOID
, P
), 1, 1, 0, 0, 2 * sizeof(sljit_sw
));
5140 sljit_get_local_base(compiler
, SLJIT_R0
, 0, 0);
5141 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
5143 sljit_emit_return_void(compiler
);
5145 code
.code
= sljit_generate_code(compiler
);
5147 sljit_free_compiler(compiler
);
5149 code
.func1((sljit_sw
)&buf
);
5151 FAILED((buf
[0] & ((sljit_sw
)sizeof(sljit_f64
) - 1)) != 0, "test53 case 1 failed\n");
5153 sljit_free_code(code
.code
, NULL
);
5157 compiler
= sljit_create_compiler(NULL
, NULL
);
5158 FAILED(!compiler
, "cannot create compiler\n");
5161 /* One more saved register to break the alignment on x86-32. */
5162 sljit_emit_enter(compiler
, SLJIT_F64_ALIGNMENT
, SLJIT_ARGS1(VOID
, P
), 1, 2, 0, 0, 2 * sizeof(sljit_sw
));
5164 sljit_get_local_base(compiler
, SLJIT_R0
, 0, 0);
5165 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
5167 sljit_emit_return_void(compiler
);
5169 code
.code
= sljit_generate_code(compiler
);
5171 sljit_free_compiler(compiler
);
5173 code
.func1((sljit_sw
)&buf
);
5175 FAILED((buf
[0] & ((sljit_sw
)sizeof(sljit_f64
) - 1)) != 0, "test53 case 2 failed\n");
5177 sljit_free_code(code
.code
, NULL
);
5181 static void test54(void)
5184 executable_code code
;
5185 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5186 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
5187 sljit_sw large_num
= SLJIT_W(0x1234567812345678);
5189 sljit_sw large_num
= SLJIT_W(0x12345678);
5197 sljit_s32 s32_value
;
5200 sbuf
[0].s32_value
= 0x7fffffff;
5201 sbuf
[1].value
= 7.5;
5202 sbuf
[2].value
= -14.75;
5205 printf("Run test54\n");
5207 FAILED(!compiler
, "cannot create compiler\n");
5209 for (i
= 0; i
< 19; i
++)
5211 for (i
= 0; i
< 4; i
++)
5214 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 5, 3, 3, 0, 0);
5216 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 17);
5217 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 34);
5218 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, -10);
5219 sljit_emit_cmov(compiler
, SLJIT_SIG_LESS
, SLJIT_R0
, SLJIT_R1
, 0);
5220 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
5221 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, -10);
5222 sljit_emit_cmov(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, SLJIT_R1
, 0);
5223 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
5225 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 24);
5226 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 24);
5227 sljit_emit_cmov(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, SLJIT_IMM
, 66);
5228 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5229 sljit_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R0
, SLJIT_IMM
, 78);
5230 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5231 sljit_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R0
, SLJIT_IMM
, large_num
);
5232 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5234 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
5235 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R3
) == -1 && sljit_get_register_index(SLJIT_R4
) == -1);
5237 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 7);
5238 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -45);
5239 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5240 sljit_emit_cmov(compiler
, SLJIT_OVERFLOW
, SLJIT_R3
, SLJIT_IMM
, 35);
5241 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5242 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, large_num
);
5243 sljit_emit_op2u(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_IMM
, large_num
);
5244 sljit_emit_cmov(compiler
, SLJIT_OVERFLOW
, SLJIT_R3
, SLJIT_IMM
, 35);
5245 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5247 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 71);
5248 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 13);
5249 sljit_emit_op2(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5250 sljit_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R3
, SLJIT_R0
, 0);
5251 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5253 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 12);
5254 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -29);
5255 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5256 sljit_emit_cmov(compiler
, SLJIT_NOT_OVERFLOW
, SLJIT_R0
, SLJIT_R3
, 0);
5257 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5259 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
5260 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -12);
5261 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, 21);
5262 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5263 sljit_emit_cmov(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R3
, SLJIT_R4
, 0);
5264 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5265 sljit_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R3
, SLJIT_R4
, 0);
5266 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5268 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5269 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S2
), 0);
5270 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
5271 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_f32
));
5273 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
5274 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5275 sljit_emit_cmov(compiler
, SLJIT_EQUAL_F32
, SLJIT_R0
, SLJIT_IMM
, -45);
5276 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5277 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_GREATER_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5278 sljit_emit_cmov(compiler
, SLJIT_GREATER_F32
, SLJIT_R0
, SLJIT_IMM
, -45);
5279 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5280 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_GREATER_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5281 sljit_emit_cmov(compiler
, SLJIT_GREATER_EQUAL_F32
, SLJIT_R0
, SLJIT_IMM
, 33);
5282 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5284 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5285 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_LESS_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5286 sljit_emit_cmov(compiler
, SLJIT_LESS_F32
, SLJIT_R0
, SLJIT_IMM
, -70);
5287 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5288 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_LESS_EQUAL_F
, SLJIT_FR2
, 0, SLJIT_FR1
, 0);
5289 sljit_emit_cmov(compiler
, SLJIT_LESS_EQUAL_F32
, SLJIT_R0
, SLJIT_IMM
, -60);
5290 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5291 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_NOT_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5292 sljit_emit_cmov(compiler
, SLJIT_NOT_EQUAL_F32
, SLJIT_R0
, SLJIT_IMM
, 31);
5293 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5295 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 53);
5296 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_ORDERED_F
, SLJIT_FR1
, 0, SLJIT_FR0
, 0);
5297 sljit_emit_cmov(compiler
, SLJIT_ORDERED_F32
, SLJIT_R0
, SLJIT_IMM
, 17);
5298 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5299 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_UNORDERED_F
, SLJIT_FR1
, 0, SLJIT_FR0
, 0);
5300 sljit_emit_cmov(compiler
, SLJIT_UNORDERED_F32
, SLJIT_R0
, SLJIT_IMM
, 59);
5301 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5304 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 177);
5305 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 178);
5306 sljit_emit_cmov(compiler
, SLJIT_LESS
, SLJIT_R0
| SLJIT_32
, SLJIT_IMM
, 200);
5307 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_R0
, 0);
5309 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 95);
5310 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R3
, 0, SLJIT_IMM
, 177);
5311 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 95);
5312 sljit_emit_cmov(compiler
, SLJIT_LESS_EQUAL
, SLJIT_R3
| SLJIT_32
, SLJIT_R0
, 0);
5313 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5314 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
), SLJIT_R3
, 0);
5316 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R3
, 0, SLJIT_IMM
, 56);
5317 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R4
, 0, SLJIT_IMM
, -63);
5318 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_SIG_LESS
, SLJIT_R3
, 0, SLJIT_R4
, 0);
5319 sljit_emit_cmov(compiler
, SLJIT_SIG_LESS
, SLJIT_R3
| SLJIT_32
, SLJIT_R4
, 0);
5320 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_s32
), SLJIT_R3
, 0);
5321 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_SIG_GREATER
, SLJIT_R3
, 0, SLJIT_R4
, 0);
5322 sljit_emit_cmov(compiler
, SLJIT_SIG_GREATER
, SLJIT_R3
| SLJIT_32
, SLJIT_R4
, 0);
5323 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_s32
), SLJIT_R3
, 0);
5325 sljit_emit_return_void(compiler
);
5327 code
.code
= sljit_generate_code(compiler
);
5329 sljit_free_compiler(compiler
);
5331 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&ibuf
, (sljit_sw
)&sbuf
);
5333 FAILED(buf
[0] != 17, "test54 case 1 failed\n");
5334 FAILED(buf
[1] != 34, "test54 case 2 failed\n");
5335 FAILED(buf
[2] != 24, "test54 case 3 failed\n");
5336 FAILED(buf
[3] != 78, "test54 case 4 failed\n");
5337 FAILED(buf
[4] != large_num
, "test54 case 5 failed\n");
5338 FAILED(buf
[5] != -45, "test54 case 6 failed\n");
5339 FAILED(buf
[6] != 35, "test54 case 7 failed\n");
5340 FAILED(buf
[7] != 71, "test54 case 8 failed\n");
5341 FAILED(buf
[8] != -29, "test54 case 9 failed\n");
5342 FAILED(buf
[9] != -12, "test54 case 10 failed\n");
5343 FAILED(buf
[10] != 21, "test54 case 11 failed\n");
5345 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5346 FAILED(buf
[11] != 16, "test54 case 12 failed\n");
5347 FAILED(buf
[12] != -45, "test54 case 13 failed\n");
5348 FAILED(buf
[13] != 33, "test54 case 14 failed\n");
5349 FAILED(buf
[14] != 8, "test54 case 15 failed\n");
5350 FAILED(buf
[15] != -60, "test54 case 16 failed\n");
5351 FAILED(buf
[16] != 31, "test54 case 17 failed\n");
5352 FAILED(buf
[17] != 53, "test54 case 18 failed\n");
5353 FAILED(buf
[18] != 59, "test54 case 19 failed\n");
5356 FAILED(ibuf
[0] != 200, "test54 case 12 failed\n");
5357 FAILED(ibuf
[1] != 95, "test54 case 13 failed\n");
5358 FAILED(ibuf
[2] != 56, "test54 case 14 failed\n");
5359 FAILED(ibuf
[3] != -63, "test54 case 15 failed\n");
5361 sljit_free_code(code
.code
, NULL
);
5365 static void test55(void)
5367 /* Check value preservation. */
5368 executable_code code
;
5369 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5374 printf("Run test55\n");
5376 FAILED(!compiler
, "cannot create compiler\n");
5380 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0, sizeof (sljit_sw
));
5382 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 217);
5385 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5386 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 118);
5388 sljit_emit_op0(compiler
, SLJIT_DIVMOD_SW
);
5390 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5392 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5393 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
5394 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_SP
), 0);
5396 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)(buf
+ 0), SLJIT_R0
, 0);
5399 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5400 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 146);
5402 sljit_emit_op0(compiler
, SLJIT_DIV_SW
);
5404 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5406 for (i
= 1; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5407 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
5408 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_SP
), 0);
5410 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)(buf
+ 1), SLJIT_R0
, 0);
5412 sljit_emit_return_void(compiler
);
5414 code
.code
= sljit_generate_code(compiler
);
5416 sljit_free_compiler(compiler
);
5420 FAILED(buf
[0] != (SLJIT_NUMBER_OF_REGISTERS
- 2) * 118 + 217, "test55 case 1 failed\n");
5421 FAILED(buf
[1] != (SLJIT_NUMBER_OF_REGISTERS
- 1) * 146 + 217, "test55 case 2 failed\n");
5423 sljit_free_code(code
.code
, NULL
);
5427 static void test56(void)
5429 /* Check integer substraction with negative immediate. */
5430 executable_code code
;
5431 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5436 printf("Run test56\n");
5438 for (i
= 0; i
< 13; i
++)
5441 FAILED(!compiler
, "cannot create compiler\n");
5443 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 0, 0, 0);
5445 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 90 << 12);
5446 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5447 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
5448 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_SIG_GREATER
);
5449 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5450 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5451 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_LESS
);
5452 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5453 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_SIG_GREATER_EQUAL
);
5454 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5455 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_LESS_EQUAL
);
5456 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5457 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_GREATER
);
5458 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5459 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_SIG_LESS
);
5461 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 90);
5462 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -91);
5463 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5464 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_SIG_GREATER
);
5465 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 90);
5466 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -91);
5467 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_LESS_EQUAL
);
5469 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, -0x7fffffff);
5470 sljit_emit_op2(compiler
, SLJIT_ADD32
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5471 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
5473 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, -0x7fffffff-1);
5474 sljit_emit_op1(compiler
, SLJIT_NEG32
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R0
, 0);
5475 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
5477 sljit_emit_return_void(compiler
);
5479 code
.code
= sljit_generate_code(compiler
);
5481 sljit_free_compiler(compiler
);
5483 code
.func1((sljit_sw
)&buf
);
5485 FAILED(buf
[0] != (181 << 12), "test56 case 1 failed\n");
5486 FAILED(buf
[1] != 1, "test56 case 2 failed\n");
5487 FAILED(buf
[2] != (181 << 12), "test56 case 3 failed\n");
5488 FAILED(buf
[3] != 1, "test56 case 4 failed\n");
5489 FAILED(buf
[4] != 1, "test56 case 5 failed\n");
5490 FAILED(buf
[5] != 1, "test56 case 6 failed\n");
5491 FAILED(buf
[6] != 0, "test56 case 7 failed\n");
5492 FAILED(buf
[7] != 0, "test56 case 8 failed\n");
5493 FAILED(buf
[8] != 181, "test56 case 9 failed\n");
5494 FAILED(buf
[9] != 1, "test56 case 10 failed\n");
5495 FAILED(buf
[10] != 1, "test56 case 11 failed\n");
5496 FAILED(buf
[11] != 1, "test56 case 12 failed\n");
5497 FAILED(buf
[12] != 1, "test56 case 13 failed\n");
5499 sljit_free_code(code
.code
, NULL
);
5503 static void test57(void)
5505 /* Check prefetch instructions. */
5506 executable_code code
;
5507 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5508 struct sljit_label
* labels
[5];
5513 printf("Run test57\n");
5515 FAILED(!compiler
, "cannot create compiler\n");
5517 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 3, 1, 0, 0, 0);
5519 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5520 labels
[0] = sljit_emit_label(compiler
);
5521 /* Should never crash. */
5522 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_L1
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R0
), 2);
5523 labels
[1] = sljit_emit_label(compiler
);
5524 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_L2
, SLJIT_MEM0(), 0);
5525 labels
[2] = sljit_emit_label(compiler
);
5526 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
5527 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_L3
, SLJIT_MEM1(SLJIT_R0
), SLJIT_W(0x1122334455667788));
5529 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_L3
, SLJIT_MEM1(SLJIT_R0
), 0x11223344);
5531 labels
[3] = sljit_emit_label(compiler
);
5532 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_ONCE
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
));
5533 labels
[4] = sljit_emit_label(compiler
);
5535 sljit_emit_return_void(compiler
);
5537 code
.code
= sljit_generate_code(compiler
);
5540 for (i
= 0; i
< 5; i
++)
5541 addr
[i
] = sljit_get_label_addr(labels
[i
]);
5543 sljit_free_compiler(compiler
);
5547 if (sljit_has_cpu_feature(SLJIT_HAS_PREFETCH
)) {
5548 FAILED(addr
[0] == addr
[1], "test57 case 1 failed\n");
5549 FAILED(addr
[1] == addr
[2], "test57 case 2 failed\n");
5550 FAILED(addr
[2] == addr
[3], "test57 case 3 failed\n");
5551 FAILED(addr
[3] == addr
[4], "test57 case 4 failed\n");
5554 FAILED(addr
[0] != addr
[1], "test57 case 1 failed\n");
5555 FAILED(addr
[1] != addr
[2], "test57 case 2 failed\n");
5556 FAILED(addr
[2] != addr
[3], "test57 case 3 failed\n");
5557 FAILED(addr
[3] != addr
[4], "test57 case 4 failed\n");
5560 sljit_free_code(code
.code
, NULL
);
5564 static sljit_f64 SLJIT_FUNC
test58_f1(sljit_f32 a
, sljit_f32 b
, sljit_f64 c
)
5566 return (sljit_f64
)a
+ (sljit_f64
)b
+ c
;
5569 static sljit_f32 SLJIT_FUNC
test58_f2(sljit_sw a
, sljit_f64 b
, sljit_f32 c
)
5571 return (sljit_f32
)((sljit_f64
)a
+ b
+ (sljit_f64
)c
);
5574 static sljit_f64 SLJIT_FUNC
test58_f3(sljit_sw a
, sljit_f32 b
, sljit_sw c
)
5576 return (sljit_f64
)a
+ (sljit_f64
)b
+ (sljit_f64
)c
;
5579 static sljit_f64
test58_f4(sljit_f32 a
, sljit_sw b
)
5581 return (sljit_f64
)a
+ (sljit_f64
)b
;
5584 static sljit_f32
test58_f5(sljit_f32 a
, sljit_f64 b
, sljit_s32 c
)
5586 return (sljit_f32
)((sljit_f64
)a
+ b
+ (sljit_f64
)c
);
5589 static sljit_sw SLJIT_FUNC
test58_f6(sljit_f64 a
, sljit_sw b
)
5591 return (sljit_sw
)(a
+ (sljit_f64
)b
);
5594 static void test58(void)
5596 /* Check function calls with floating point arguments. */
5597 executable_code code
;
5598 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5599 struct sljit_jump
* jump
= NULL
;
5605 printf("Run test58\n");
5607 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5609 printf("no fpu available, test58 skipped\n");
5612 sljit_free_compiler(compiler
);
5633 FAILED(!compiler
, "cannot create compiler\n");
5635 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 3, 3, 4, 0, sizeof(sljit_sw
));
5637 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
5638 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
5639 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
5640 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(F64
, F32
, F32
, F64
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test58_f1
));
5642 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
), SLJIT_FR0
, 0);
5644 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
5645 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
));
5646 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
));
5647 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS3(F64
, F32
, F32
, F64
));
5648 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test58_f1
));
5650 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5652 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test58_f2
));
5653 sljit_get_local_base(compiler
, SLJIT_R1
, 0, -16);
5654 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
5655 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
5656 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
5657 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(F32
, W
, F64
, F32
), SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 0);
5659 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
5661 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -4);
5662 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 9);
5663 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0);
5664 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
5665 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS3(F64
, W
, F32
, W
));
5666 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test58_f3
));
5668 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5670 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
5671 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -6);
5672 jump
= sljit_emit_call(compiler
, SLJIT_CALL_CDECL
, SLJIT_ARGS2(F64
, F32
, W
));
5673 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test58_f4
));
5675 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5677 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test58_f5
));
5678 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
));
5679 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
));
5680 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5681 sljit_emit_icall(compiler
, SLJIT_CALL_CDECL
, SLJIT_ARGS3(F32
, F32
, F64
, 32), SLJIT_MEM1(SLJIT_SP
), 0);
5683 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
5685 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
));
5686 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test58_f6
));
5687 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS2(W
, F64
, W
), SLJIT_R0
, 0);
5689 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), 0, SLJIT_R0
, 0);
5691 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
));
5692 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 319);
5693 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test58_f6
));
5694 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS2(W
, F64
, W
), SLJIT_R1
, 0);
5696 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_sw
), SLJIT_R0
, 0);
5698 sljit_emit_return_void(compiler
);
5700 code
.code
= sljit_generate_code(compiler
);
5702 sljit_free_compiler(compiler
);
5704 code
.func3((sljit_sw
)&dbuf
, (sljit_sw
)&sbuf
, (sljit_sw
)&wbuf
);
5706 FAILED(dbuf
[1] != 8.5, "test58 case 1 failed\n");
5707 FAILED(dbuf
[3] != 0.5, "test58 case 2 failed\n");
5708 FAILED(sbuf
[3] != 17.75, "test58 case 3 failed\n");
5709 FAILED(dbuf
[4] != 11.75, "test58 case 4 failed\n");
5710 FAILED(dbuf
[5] != -9.5, "test58 case 5 failed\n");
5711 FAILED(sbuf
[4] != 12, "test58 case 6 failed\n");
5712 FAILED(wbuf
[0] != SLJIT_FUNC_ADDR(test58_f6
) - 18, "test58 case 7 failed\n");
5713 FAILED(wbuf
[1] != 301, "test58 case 8 failed\n");
5715 sljit_free_code(code
.code
, NULL
);
5719 static sljit_sw SLJIT_FUNC
test59_f1(sljit_sw a
, sljit_s32 b
, sljit_sw c
, sljit_sw d
)
5721 return (sljit_sw
)(a
+ b
+ c
+ d
- SLJIT_FUNC_ADDR(test59_f1
));
5724 static sljit_sw
test59_f2(sljit_sw a
, sljit_s32 b
, sljit_sw c
, sljit_sw d
)
5726 return (sljit_sw
)(a
+ b
+ c
+ d
- SLJIT_FUNC_ADDR(test59_f2
));
5729 static sljit_s32 SLJIT_FUNC
test59_f3(sljit_f64 a
, sljit_f32 b
, sljit_f64 c
, sljit_sw d
)
5731 return (sljit_s32
)(a
+ b
+ c
+ (sljit_f64
)d
);
5734 static sljit_f32 SLJIT_FUNC
test59_f4(sljit_f32 a
, sljit_s32 b
, sljit_f64 c
, sljit_sw d
)
5736 return (sljit_f32
)(a
+ (sljit_f64
)b
+ c
+ (sljit_f64
)d
);
5739 static sljit_f32 SLJIT_FUNC
test59_f5(sljit_f32 a
, sljit_f64 b
, sljit_f32 c
, sljit_f64 d
)
5741 return (sljit_f32
)(a
+ b
+ c
+ (sljit_f64
)d
);
5744 static void test59(void)
5746 /* Check function calls with four arguments. */
5747 executable_code code
;
5748 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5749 struct sljit_jump
* jump
= NULL
;
5755 printf("Run test59\n");
5760 wbuf
[3] = SLJIT_FUNC_ADDR(test59_f1
);
5764 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5775 FAILED(!compiler
, "cannot create compiler\n");
5777 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 4, 3, 4, 0, sizeof(sljit_sw
));
5779 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 33);
5780 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -20);
5781 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f1
));
5782 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -40);
5783 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS4(W
, W
, 32, W
, W
), SLJIT_R2
, 0);
5785 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
5787 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
5788 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -30);
5789 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 50);
5790 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f2
));
5791 sljit_emit_icall(compiler
, SLJIT_CALL_CDECL
, SLJIT_ARGS4(W
, W
, 32, W
, W
), SLJIT_R3
, 0);
5793 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
5795 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f1
));
5796 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -25);
5797 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 100);
5798 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -10);
5799 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS4(W
, W
, 32, W
, W
), SLJIT_R0
, 0);
5801 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5803 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
5804 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 231);
5805 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 3);
5806 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f1
) - 100);
5807 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS4(W
, W
, 32, W
, W
), SLJIT_MEM2(SLJIT_R0
, SLJIT_R2
), SLJIT_WORD_SHIFT
);
5809 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5811 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5812 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
5813 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S2
), 0);
5814 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
));
5815 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -100);
5816 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS4(32, F64
, F32
, F64
, W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f3
));
5817 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
5819 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5821 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
5822 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f64
));
5823 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 36);
5824 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 41);
5825 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS4(F32
, F32
, 32, F64
, W
));
5826 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test59_f4
));
5828 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
5830 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f5
));
5831 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S2
), 0);
5832 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
5833 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
5834 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f64
));
5835 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS4(F32
, F32
, F64
, F32
, F64
), SLJIT_R0
, 0);
5837 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S2
), 3 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
5840 sljit_emit_return_void(compiler
);
5842 code
.code
= sljit_generate_code(compiler
);
5844 sljit_free_compiler(compiler
);
5846 code
.func3((sljit_sw
)&wbuf
, (sljit_sw
)&dbuf
, (sljit_sw
)&sbuf
);
5848 FAILED(wbuf
[0] != -27, "test59 case 1 failed\n");
5849 FAILED(wbuf
[1] != 36, "test59 case 2 failed\n");
5850 FAILED(wbuf
[2] != 65, "test59 case 3 failed\n");
5851 FAILED(wbuf
[4] != (sljit_sw
)wbuf
+ 134, "test59 case 4 failed\n");
5853 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5854 FAILED(wbuf
[5] != -88, "test59 case 5 failed\n");
5855 FAILED(sbuf
[2] != 79.75, "test59 case 6 failed\n");
5856 FAILED(sbuf
[3] != 8.625, "test59 case 7 failed\n");
5859 sljit_free_code(code
.code
, NULL
);
5863 static void test60(void)
5865 /* Test memory accesses with pre/post updates. */
5866 executable_code code
;
5867 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5869 sljit_s32 supported
[10];
5874 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
5875 static sljit_u8 expected
[10] = { 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 };
5876 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
5877 static sljit_u8 expected
[10] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
5878 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32)
5879 static sljit_u8 expected
[10] = { 1, 0, 1, 1, 0, 1, 1, 1, 0, 0 };
5880 #elif (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
5881 static sljit_u8 expected
[10] = { 1, 0, 0, 1, 0, 0, 1, 1, 0, 0 };
5883 static sljit_u8 expected
[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
5887 printf("Run test60\n");
5889 for (i
= 0; i
< 18; i
++)
5901 FAILED(!compiler
, "cannot create compiler\n");
5903 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 4, 3, 4, 0, sizeof(sljit_sw
));
5905 supported
[0] = sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_sw
));
5906 if (supported
[0] == SLJIT_SUCCESS
) {
5907 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
5908 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_sw
));
5909 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
5910 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
5913 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
));
5914 if (supported
[1] == SLJIT_SUCCESS
) {
5915 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s8
));
5916 sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM1(SLJIT_R2
), -2 * (sljit_sw
)sizeof(sljit_s8
));
5917 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5918 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R2
, 0);
5921 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
));
5922 if (supported
[2] == SLJIT_SUCCESS
) {
5923 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s32
));
5924 sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_PRE
, SLJIT_R2
, SLJIT_MEM1(SLJIT_R1
), -2 * (sljit_sw
)sizeof(sljit_s32
));
5925 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R2
, 0);
5926 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5929 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
));
5930 if (supported
[3] == SLJIT_SUCCESS
) {
5931 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -8765);
5932 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, sizeof(sljit_s32
));
5933 sljit_emit_mem(compiler
, SLJIT_MOV32
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R2
), 2 * sizeof(sljit_s32
));
5934 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R2
, 0);
5937 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
));
5938 if (supported
[4] == SLJIT_SUCCESS
) {
5939 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -121);
5940 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_S1
, 0);
5941 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
));
5942 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R2
, 0);
5945 supported
[5] = sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 1);
5946 if (supported
[5] == SLJIT_SUCCESS
) {
5947 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 9 * sizeof(sljit_sw
) - 1);
5948 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -881199);
5949 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 1);
5950 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5953 supported
[6] = sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5954 if (supported
[6] == SLJIT_SUCCESS
) {
5955 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 213);
5956 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -213);
5957 sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_PRE
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5958 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5959 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5962 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);
5963 if (supported
[7] == SLJIT_SUCCESS
) {
5964 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_S2
, 0);
5965 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s32
));
5966 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -7890);
5967 sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5968 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5971 supported
[8] = sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 2);
5972 if (supported
[8] == SLJIT_SUCCESS
) {
5973 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 2 * sizeof(sljit_sw
));
5974 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2 * sizeof(sljit_sw
));
5975 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 2);
5976 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5977 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5980 supported
[9] = sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5981 if (supported
[9] == SLJIT_SUCCESS
) {
5982 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s8
));
5983 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -2 * (sljit_sw
)sizeof(sljit_s8
));
5984 sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5985 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5986 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5989 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
);
5990 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
);
5992 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
5993 /* TODO: at least for ARM (both V5 and V7) the range below needs further fixing */
5994 SLJIT_ASSERT(sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 256) == SLJIT_ERR_UNSUPPORTED
);
5995 SLJIT_ASSERT(sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), -257) == SLJIT_ERR_UNSUPPORTED
);
5998 sljit_emit_return_void(compiler
);
6000 code
.code
= sljit_generate_code(compiler
);
6002 sljit_free_compiler(compiler
);
6004 code
.func3((sljit_sw
)&wbuf
, (sljit_sw
)&bbuf
, (sljit_sw
)&ibuf
);
6006 FAILED(sizeof(expected
) != sizeof(supported
) / sizeof(sljit_s32
), "test60 case 1 failed\n");
6008 for (i
= 0; i
< sizeof(expected
); i
++) {
6010 if (supported
[i
] != SLJIT_SUCCESS
) {
6011 printf("tast60 case %d should be supported\n", i
+ 1);
6015 if (supported
[i
] == SLJIT_SUCCESS
) {
6016 printf("test60 case %d should not be supported\n", i
+ 1);
6022 FAILED(supported
[0] == SLJIT_SUCCESS
&& wbuf
[0] != -887766, "test60 case 2 failed\n");
6023 FAILED(supported
[0] == SLJIT_SUCCESS
&& wbuf
[1] != (sljit_sw
)(wbuf
+ 2), "test60 case 3 failed\n");
6024 FAILED(supported
[1] == SLJIT_SUCCESS
&& wbuf
[3] != -13, "test60 case 4 failed\n");
6025 FAILED(supported
[1] == SLJIT_SUCCESS
&& wbuf
[4] != (sljit_sw
)(bbuf
), "test60 case 5 failed\n");
6026 FAILED(supported
[2] == SLJIT_SUCCESS
&& wbuf
[5] != -5678, "test60 case 6 failed\n");
6027 FAILED(supported
[2] == SLJIT_SUCCESS
&& wbuf
[6] != (sljit_sw
)(ibuf
), "test60 case 7 failed\n");
6028 FAILED(supported
[3] == SLJIT_SUCCESS
&& ibuf
[1] != -8765, "test60 case 8 failed\n");
6029 FAILED(supported
[3] == SLJIT_SUCCESS
&& wbuf
[7] != (sljit_sw
)(ibuf
+ 1), "test60 case 9 failed\n");
6030 FAILED(supported
[4] == SLJIT_SUCCESS
&& bbuf
[0] != -121, "test60 case 10 failed\n");
6031 FAILED(supported
[4] == SLJIT_SUCCESS
&& wbuf
[8] != (sljit_sw
)(bbuf
) - 128 * (sljit_sw
)sizeof(sljit_s8
), "test60 case 11 failed\n");
6032 FAILED(supported
[5] == SLJIT_SUCCESS
&& wbuf
[9] != -881199, "test60 case 12 failed\n");
6033 FAILED(supported
[5] == SLJIT_SUCCESS
&& wbuf
[10] != (sljit_sw
)(wbuf
+ 9), "test60 case 13 failed\n");
6034 FAILED(supported
[6] == SLJIT_SUCCESS
&& wbuf
[11] != -5678, "test60 case 14 failed\n");
6035 FAILED(supported
[6] == SLJIT_SUCCESS
&& wbuf
[12] != (sljit_sw
)(ibuf
), "test60 case 15 failed\n");
6036 FAILED(supported
[7] == SLJIT_SUCCESS
&& ibuf
[2] != -7890, "test60 case 16 failed\n");
6037 FAILED(supported
[7] == SLJIT_SUCCESS
&& wbuf
[13] != (sljit_sw
)(ibuf
+ 2), "test60 case 17 failed\n");
6038 FAILED(supported
[8] == SLJIT_SUCCESS
&& wbuf
[14] != -887766, "test60 case 18 failed\n");
6039 FAILED(supported
[8] == SLJIT_SUCCESS
&& wbuf
[15] != (sljit_sw
)(wbuf
+ 10), "test60 case 19 failed\n");
6040 FAILED(supported
[9] == SLJIT_SUCCESS
&& wbuf
[16] != -13, "test60 case 20 failed\n");
6041 FAILED(supported
[9] == SLJIT_SUCCESS
&& wbuf
[17] != (sljit_sw
)(bbuf
), "test60 case 21 failed\n");
6043 sljit_free_code(code
.code
, NULL
);
6047 static void test61(void)
6049 /* Test float memory accesses with pre/post updates. */
6050 executable_code code
;
6051 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6053 sljit_s32 supported
[6];
6057 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
6058 static sljit_u8 expected
[6] = { 1, 1, 1, 1, 0, 0 };
6059 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
6060 static sljit_u8 expected
[6] = { 1, 0, 1, 0, 1, 1 };
6062 static sljit_u8 expected
[6] = { 0, 0, 0, 0, 0, 0 };
6065 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
6067 printf("no fpu available, test61 skipped\n");
6070 sljit_free_compiler(compiler
);
6075 printf("Run test61\n");
6077 for (i
= 0; i
< 6; i
++)
6090 FAILED(!compiler
, "cannot create compiler\n");
6092 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 4, 3, 4, 0, sizeof(sljit_sw
));
6094 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
));
6095 if (supported
[0] == SLJIT_SUCCESS
) {
6096 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 4 * sizeof(sljit_f64
));
6097 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_PRE
, SLJIT_FR0
, SLJIT_MEM1(SLJIT_R0
), 4 * sizeof(sljit_f64
));
6098 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
), SLJIT_FR0
, 0);
6099 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
6102 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
));
6103 if (supported
[1] == SLJIT_SUCCESS
) {
6104 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 2 * sizeof(sljit_f64
));
6105 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
6106 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_STORE
| SLJIT_MEM_POST
, SLJIT_FR2
, SLJIT_MEM1(SLJIT_R0
), -(sljit_sw
)sizeof(sljit_f64
));
6107 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
6110 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
));
6111 if (supported
[2] == SLJIT_SUCCESS
) {
6112 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 4 * sizeof(sljit_f32
));
6113 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
6114 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
));
6115 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R2
, 0);
6118 supported
[3] = sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_FR1
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_f32
));
6119 if (supported
[3] == SLJIT_SUCCESS
) {
6120 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S2
, 0, SLJIT_IMM
, sizeof(sljit_f32
));
6121 sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_POST
, SLJIT_FR1
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_f32
));
6122 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_f32
), SLJIT_FR1
, 0);
6123 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R1
, 0);
6126 supported
[4] = sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_FR0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 0);
6127 if (supported
[4] == SLJIT_SUCCESS
) {
6128 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 8 * sizeof(sljit_f64
));
6129 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -8 * (sljit_sw
)sizeof(sljit_f64
));
6130 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_PRE
, SLJIT_FR0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 0);
6131 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
6132 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R1
, 0);
6135 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);
6136 if (supported
[5] == SLJIT_SUCCESS
) {
6137 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_S2
, 0);
6138 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3 * sizeof(sljit_f32
));
6139 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
6140 sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_FR2
, SLJIT_MEM2(SLJIT_R2
, SLJIT_R1
), 0);
6141 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R2
, 0);
6144 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
);
6145 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
);
6147 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
6148 /* TODO: at least for ARM (both V5 and V7) the range below needs further fixing */
6149 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
);
6150 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
);
6153 sljit_emit_return_void(compiler
);
6155 code
.code
= sljit_generate_code(compiler
);
6157 sljit_free_compiler(compiler
);
6159 code
.func3((sljit_sw
)&wbuf
, (sljit_sw
)&dbuf
, (sljit_sw
)&sbuf
);
6161 FAILED(sizeof(expected
) != sizeof(supported
) / sizeof(sljit_s32
), "test61 case 1 failed\n");
6163 for (i
= 0; i
< sizeof(expected
); i
++) {
6165 if (supported
[i
] != SLJIT_SUCCESS
) {
6166 printf("tast61 case %d should be supported\n", i
+ 1);
6170 if (supported
[i
] == SLJIT_SUCCESS
) {
6171 printf("test61 case %d should not be supported\n", i
+ 1);
6177 FAILED(supported
[0] == SLJIT_SUCCESS
&& dbuf
[1] != 66.725, "test61 case 2 failed\n");
6178 FAILED(supported
[0] == SLJIT_SUCCESS
&& wbuf
[0] != (sljit_sw
)(dbuf
), "test61 case 3 failed\n");
6179 FAILED(supported
[1] == SLJIT_SUCCESS
&& dbuf
[2] != 66.725, "test61 case 4 failed\n");
6180 FAILED(supported
[1] == SLJIT_SUCCESS
&& wbuf
[1] != (sljit_sw
)(dbuf
+ 1), "test61 case 5 failed\n");
6181 FAILED(supported
[2] == SLJIT_SUCCESS
&& sbuf
[0] != -22.125, "test61 case 6 failed\n");
6182 FAILED(supported
[2] == SLJIT_SUCCESS
&& wbuf
[2] != (sljit_sw
)(sbuf
), "test61 case 7 failed\n");
6183 FAILED(supported
[3] == SLJIT_SUCCESS
&& sbuf
[2] != -22.125, "test61 case 8 failed\n");
6184 FAILED(supported
[3] == SLJIT_SUCCESS
&& wbuf
[3] != (sljit_sw
)(sbuf
+ 2), "test61 case 9 failed\n");
6185 FAILED(supported
[4] == SLJIT_SUCCESS
&& dbuf
[3] != 66.725, "test61 case 10 failed\n");
6186 FAILED(supported
[4] == SLJIT_SUCCESS
&& wbuf
[4] != (sljit_sw
)(dbuf
), "test61 case 11 failed\n");
6187 FAILED(supported
[5] == SLJIT_SUCCESS
&& sbuf
[3] != -22.125, "test61 case 12 failed\n");
6188 FAILED(supported
[5] == SLJIT_SUCCESS
&& wbuf
[5] != (sljit_sw
)(sbuf
+ 3), "test61 case 13 failed\n");
6190 sljit_free_code(code
.code
, NULL
);
6194 static void test62(void)
6196 /* Test fast calls flag preservation. */
6197 executable_code code1
;
6198 executable_code code2
;
6199 struct sljit_compiler
* compiler
;
6202 printf("Run test62\n");
6205 compiler
= sljit_create_compiler(NULL
, NULL
);
6206 FAILED(!compiler
, "cannot create compiler\n");
6207 sljit_set_context(compiler
, 0, SLJIT_ARGS1(W
, W
), 1, 1, 0, 0, 0);
6209 sljit_emit_fast_enter(compiler
, SLJIT_R0
, 0);
6210 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_S0
, 0, SLJIT_IMM
, 42);
6211 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R0
, 0);
6213 code1
.code
= sljit_generate_code(compiler
);
6215 sljit_free_compiler(compiler
);
6218 compiler
= sljit_create_compiler(NULL
, NULL
);
6219 FAILED(!compiler
, "cannot create compiler\n");
6221 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, W
), 1, 1, 0, 0, 0);
6222 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_ADDR(code1
.code
));
6223 sljit_set_current_flags(compiler
, SLJIT_CURRENT_FLAGS_ADD_SUB
| SLJIT_CURRENT_FLAGS_COMPARE
| SLJIT_SET_Z
| SLJIT_SET_LESS
);
6224 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_ZERO
);
6225 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_LESS
);
6226 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
6227 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S0
, 0);
6228 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
6230 code2
.code
= sljit_generate_code(compiler
);
6232 sljit_free_compiler(compiler
);
6234 FAILED(code2
.func1(88) != 0, "test62 case 1 failed\n");
6235 FAILED(code2
.func1(42) != 1, "test62 case 2 failed\n");
6236 FAILED(code2
.func1(0) != 2, "test62 case 3 failed\n");
6238 sljit_free_code(code1
.code
, NULL
);
6239 sljit_free_code(code2
.code
, NULL
);
6243 static void test63(void)
6245 /* Test put label. */
6246 executable_code code
;
6247 struct sljit_label
*label
[2];
6248 struct sljit_put_label
*put_label
[5];
6249 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6252 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
6253 sljit_sw offs
= SLJIT_W(0x123456789012);
6255 sljit_sw offs
= 0x12345678;
6259 printf("Run test63\n");
6261 FAILED(!compiler
, "cannot create compiler\n");
6267 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 2 * sizeof(sljit_sw
));
6269 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_R0
, 0);
6270 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
6272 put_label
[1] = sljit_emit_put_label(compiler
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
));
6273 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
));
6275 label
[0] = sljit_emit_label(compiler
);
6276 sljit_set_put_label(put_label
[0], label
[0]);
6277 sljit_set_put_label(put_label
[1], label
[0]);
6279 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)(buf
+ 2) - offs
);
6280 put_label
[2] = sljit_emit_put_label(compiler
, SLJIT_MEM1(SLJIT_R0
), offs
);
6282 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (offs
+ (sljit_sw
)sizeof(sljit_uw
)) >> 1);
6283 put_label
[3] = sljit_emit_put_label(compiler
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1);
6285 label
[1] = sljit_emit_label(compiler
);
6286 sljit_set_put_label(put_label
[2], label
[1]);
6287 sljit_set_put_label(put_label
[3], label
[1]);
6289 put_label
[4] = sljit_emit_put_label(compiler
, SLJIT_RETURN_REG
, 0);
6290 sljit_set_put_label(put_label
[4], label
[0]);
6291 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
6293 code
.code
= sljit_generate_code(compiler
);
6296 addr
[0] = sljit_get_label_addr(label
[0]);
6297 addr
[1] = sljit_get_label_addr(label
[1]);
6299 sljit_free_compiler(compiler
);
6301 FAILED(code
.func1((sljit_sw
)&buf
) != (sljit_sw
)addr
[0], "test63 case 1 failed\n");
6302 FAILED(buf
[0] != addr
[0], "test63 case 2 failed\n");
6303 FAILED(buf
[1] != addr
[0], "test63 case 3 failed\n");
6304 FAILED(buf
[2] != addr
[1], "test63 case 4 failed\n");
6305 FAILED(buf
[3] != addr
[1], "test63 case 5 failed\n");
6307 sljit_free_code(code
.code
, NULL
);
6311 static void test64(void)
6313 /* Test put label with absolute label addresses */
6314 executable_code code
;
6315 sljit_uw malloc_addr
;
6316 struct sljit_label label
[4];
6317 struct sljit_put_label
*put_label
[2];
6318 struct sljit_compiler
* compiler
;
6320 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
6321 sljit_sw offs1
= SLJIT_W(0x123456781122);
6322 sljit_sw offs2
= SLJIT_W(0x1234567811223344);
6323 #else /* !SLJIT_64BIT_ARCHITECTURE */
6324 sljit_sw offs1
= 0x12345678;
6325 sljit_sw offs2
= (sljit_sw
)0x80000000;
6326 #endif /* SLJIT_64BIT_ARCHITECTURE */
6329 printf("Run test64\n");
6331 /* lock next allocation; see sljit_test_malloc_exec() */
6332 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
6333 malloc_addr
= (sljit_uw
)SLJIT_MALLOC_EXEC(1024, NULL
);
6336 printf("Cannot allocate executable memory\n");
6340 compiler
= sljit_create_compiler(NULL
, (void*)malloc_addr
);
6341 malloc_addr
+= (sljit_uw
)SLJIT_EXEC_OFFSET((void*)malloc_addr
);
6342 #else /* SLJIT_CONFIG_UNSUPPORTED */
6344 compiler
= sljit_create_compiler(NULL
, (void*)malloc_addr
);
6345 #endif /* !SLJIT_CONFIG_UNSUPPORTED */
6347 label
[0].addr
= 0x1234;
6348 label
[0].size
= (sljit_uw
)0x1234 - malloc_addr
;
6350 label
[1].addr
= 0x12345678;
6351 label
[1].size
= (sljit_uw
)0x12345678 - malloc_addr
;
6353 label
[2].addr
= (sljit_uw
)offs1
;
6354 label
[2].size
= (sljit_uw
)offs1
- malloc_addr
;
6356 label
[3].addr
= (sljit_uw
)offs2
;
6357 label
[3].size
= (sljit_uw
)offs2
- malloc_addr
;
6359 FAILED(!compiler
, "cannot create compiler\n");
6366 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 2 * sizeof(sljit_sw
));
6368 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_R0
, 0);
6369 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
6371 put_label
[1] = sljit_emit_put_label(compiler
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
));
6372 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
));
6374 sljit_set_put_label(put_label
[0], &label
[0]);
6375 sljit_set_put_label(put_label
[1], &label
[0]);
6377 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)(buf
+ 2) - offs1
);
6378 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_MEM1(SLJIT_R0
), offs1
);
6380 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (offs1
+ (sljit_sw
)sizeof(sljit_uw
)) >> 1);
6381 put_label
[1] = sljit_emit_put_label(compiler
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1);
6383 sljit_set_put_label(put_label
[0], &label
[1]);
6384 sljit_set_put_label(put_label
[1], &label
[1]);
6386 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_R2
, 0);
6387 sljit_set_put_label(put_label
[0], &label
[2]);
6388 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_uw
), SLJIT_R2
, 0);
6390 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_RETURN_REG
, 0);
6391 sljit_set_put_label(put_label
[0], &label
[3]);
6392 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
6394 code
.code
= sljit_generate_code(compiler
);
6396 sljit_free_compiler(compiler
);
6397 SLJIT_ASSERT(SLJIT_FUNC_UADDR(code
.code
) >= malloc_addr
&& SLJIT_FUNC_UADDR(code
.code
) <= malloc_addr
+ 8);
6399 FAILED(code
.func1((sljit_sw
)&buf
) != (sljit_sw
)label
[3].addr
, "test64 case 1 failed\n");
6400 FAILED(buf
[0] != label
[0].addr
, "test64 case 2 failed\n");
6401 FAILED(buf
[1] != label
[0].addr
, "test64 case 3 failed\n");
6402 FAILED(buf
[2] != label
[1].addr
, "test64 case 4 failed\n");
6403 FAILED(buf
[3] != label
[1].addr
, "test64 case 5 failed\n");
6404 FAILED(buf
[4] != label
[2].addr
, "test64 case 6 failed\n");
6406 sljit_free_code(code
.code
, NULL
);
6411 static void test65(void)
6413 /* Test jump tables. */
6414 executable_code code
;
6415 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6417 /* Normally this table is allocated on the heap. */
6419 struct sljit_label
*labels
[64];
6420 struct sljit_jump
*jump
;
6423 printf("Run test65\n");
6425 FAILED(!compiler
, "cannot create compiler\n");
6427 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(W
, W
, W
), 1, 2, 0, 0, 0);
6429 jump
= sljit_emit_cmp(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_S0
, 0, SLJIT_IMM
, 64);
6430 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)addr
);
6431 sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_MEM2(SLJIT_R0
, SLJIT_S0
), SLJIT_WORD_SHIFT
);
6433 for (i
= 0; i
< 64; i
++) {
6434 labels
[i
] = sljit_emit_label(compiler
);
6435 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
6436 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, i
* 2);
6437 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
6440 sljit_set_label(jump
, sljit_emit_label(compiler
));
6441 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, -1);
6443 code
.code
= sljit_generate_code(compiler
);
6446 for (i
= 0; i
< 64; i
++) {
6447 addr
[i
] = sljit_get_label_addr(labels
[i
]);
6450 sljit_free_compiler(compiler
);
6452 FAILED(code
.func2(64, 0) != -1, "test65 case 1 failed\n");
6454 for (i
= 0; i
< 64; i
++) {
6455 FAILED(code
.func2(i
, i
* 2) != i
* 4, "test65 case 2 failed\n");
6458 sljit_free_code(code
.code
, NULL
);
6462 static void test66(void)
6464 /* Test direct jumps (computed goto). */
6465 executable_code code
;
6466 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6469 struct sljit_label
*labels
[64];
6472 printf("Run test66\n");
6474 FAILED(!compiler
, "cannot create compiler\n");
6476 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(W
, W
, W
), 1, 2, 0, 0, 0);
6477 sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_S0
, 0);
6479 for (i
= 0; i
< 64; i
++) {
6480 labels
[i
] = sljit_emit_label(compiler
);
6481 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
6482 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, i
* 2);
6483 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
6486 code
.code
= sljit_generate_code(compiler
);
6489 for (i
= 0; i
< 64; i
++) {
6490 addr
[i
] = sljit_get_label_addr(labels
[i
]);
6493 sljit_free_compiler(compiler
);
6495 for (i
= 0; i
< 64; i
++) {
6496 FAILED(code
.func2((sljit_sw
)addr
[i
], i
) != i
* 3, "test66 case 1 failed\n");
6499 sljit_free_code(code
.code
, NULL
);
6503 static void test67(void)
6505 /* Test skipping returns from fast calls (return type is fast). */
6506 executable_code code
;
6507 struct sljit_compiler
*compiler
= sljit_create_compiler(NULL
, NULL
);
6508 struct sljit_jump
*call
, *jump
;
6509 struct sljit_label
*label
;
6512 printf("Run test67\n");
6514 FAILED(!compiler
, "cannot create compiler\n");
6516 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), 3, 1, 0, 0, 0);
6518 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
6519 call
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
);
6521 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
6523 /* First function, never returns. */
6524 label
= sljit_emit_label(compiler
);
6525 sljit_set_label(call
, label
);
6526 sljit_emit_fast_enter(compiler
, SLJIT_R1
, 0);
6528 call
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
);
6530 /* Should never return here, marked by a segmentation fault if it does. */
6531 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
6533 /* Second function, skips the first function. */
6534 sljit_set_label(call
, sljit_emit_label(compiler
));
6535 sljit_emit_fast_enter(compiler
, SLJIT_R2
, 0);
6537 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
6539 jump
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
6541 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_R1
, 0);
6542 sljit_set_label(sljit_emit_jump(compiler
, SLJIT_FAST_CALL
), label
);
6543 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
6544 sljit_emit_op_src(compiler
, SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN
, SLJIT_S0
, 0);
6545 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_S0
, 0);
6547 sljit_set_label(jump
, sljit_emit_label(compiler
));
6548 sljit_emit_op_src(compiler
, SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN
, SLJIT_R1
, 0);
6549 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R1
, 0);
6551 code
.code
= sljit_generate_code(compiler
);
6554 sljit_free_compiler(compiler
);
6556 FAILED(code
.func0() != 3, "test67 case 1 failed\n");
6558 sljit_free_code(code
.code
, NULL
);
6562 static void test68(void)
6564 /* Test skipping returns from fast calls (return type is normal). */
6565 executable_code code
;
6566 struct sljit_compiler
*compiler
;
6567 struct sljit_jump
*call
, *jump
;
6568 struct sljit_label
*label
;
6572 printf("Run test68\n");
6574 for (i
= 0; i
< 6 * 2; i
++) {
6575 compiler
= sljit_create_compiler(NULL
, NULL
);
6576 FAILED(!compiler
, "cannot create compiler\n");
6578 sljit_emit_enter(compiler
, (i
>= 6 ? SLJIT_F64_ALIGNMENT
: 0), SLJIT_ARGS0(W
), 2 + (i
% 6), (i
% 6), 0, 0, 0);
6580 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
6581 call
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
);
6583 /* Should never return here, marked by a segmentation fault if it does. */
6584 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
6586 /* Recursive fast call. */
6587 label
= sljit_emit_label(compiler
);
6588 sljit_set_label(call
, label
);
6589 sljit_emit_fast_enter(compiler
, SLJIT_R1
, 0);
6591 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
6593 jump
= sljit_emit_cmp(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
6595 sljit_set_label(sljit_emit_jump(compiler
, SLJIT_FAST_CALL
), label
);
6597 sljit_set_label(jump
, sljit_emit_label(compiler
));
6598 sljit_emit_op0(compiler
, SLJIT_SKIP_FRAMES_BEFORE_RETURN
);
6599 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
6601 code
.code
= sljit_generate_code(compiler
);
6604 sljit_free_compiler(compiler
);
6606 if (SLJIT_UNLIKELY(code
.func0() != 4)) {
6607 printf("test68 case %d failed\n", i
+ 1);
6610 sljit_free_code(code
.code
, NULL
);
6616 static void test69(void)
6618 /* Test sljit_set_current_flags. */
6619 executable_code code
;
6620 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6625 printf("Run test69\n");
6627 for (i
= 0; i
< 8; i
++)
6630 FAILED(!compiler
, "cannot create compiler\n");
6632 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 0, 0, 0);
6634 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)1 << ((sizeof (sljit_sw
) * 8) - 2));
6635 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_R0
, 0);
6636 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
6637 sljit_emit_label(compiler
);
6638 sljit_set_current_flags(compiler
, SLJIT_SET_OVERFLOW
| SLJIT_CURRENT_FLAGS_ADD_SUB
);
6639 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_OVERFLOW
);
6641 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
6642 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
6643 sljit_emit_label(compiler
);
6644 sljit_set_current_flags(compiler
, SLJIT_SET_OVERFLOW
| SLJIT_CURRENT_FLAGS_ADD_SUB
);
6645 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_OVERFLOW
);
6647 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_R0
, 0);
6648 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
6649 sljit_emit_label(compiler
);
6650 sljit_set_current_flags(compiler
, SLJIT_SET_OVERFLOW
);
6651 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
6653 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
6654 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R1
, 0);
6655 sljit_emit_label(compiler
);
6656 sljit_set_current_flags(compiler
, SLJIT_SET_OVERFLOW
);
6657 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
6659 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 6);
6660 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 5);
6661 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R1
, 0, SLJIT_R2
, 0);
6662 sljit_emit_label(compiler
);
6663 sljit_set_current_flags(compiler
, SLJIT_SET_GREATER
| SLJIT_CURRENT_FLAGS_ADD_SUB
| SLJIT_CURRENT_FLAGS_COMPARE
);
6664 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_GREATER
);
6666 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R2
, 0);
6667 sljit_emit_label(compiler
);
6668 sljit_set_current_flags(compiler
, SLJIT_SET_Z
| SLJIT_CURRENT_FLAGS_ADD_SUB
| SLJIT_CURRENT_FLAGS_COMPARE
);
6669 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_ZERO
);
6671 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -1 << 31);
6672 sljit_emit_op2u(compiler
, SLJIT_ADD32
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R1
, 0);
6673 sljit_emit_label(compiler
);
6674 sljit_set_current_flags(compiler
, SLJIT_SET_Z
| SLJIT_CURRENT_FLAGS_32
| SLJIT_CURRENT_FLAGS_ADD_SUB
);
6675 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_ZERO
);
6677 sljit_emit_op2u(compiler
, SLJIT_SHL32
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
6678 sljit_emit_label(compiler
);
6679 sljit_set_current_flags(compiler
, SLJIT_SET_Z
| SLJIT_CURRENT_FLAGS_32
);
6680 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_NOT_ZERO
);
6682 sljit_emit_return_void(compiler
);
6684 code
.code
= sljit_generate_code(compiler
);
6686 sljit_free_compiler(compiler
);
6688 code
.func1((sljit_sw
)&buf
);
6690 FAILED(buf
[0] != 1, "test69 case 1 failed\n");
6691 FAILED(buf
[1] != 2, "test69 case 2 failed\n");
6692 FAILED(buf
[2] != 1, "test69 case 3 failed\n");
6693 FAILED(buf
[3] != 2, "test69 case 4 failed\n");
6694 FAILED(buf
[4] != 1, "test69 case 5 failed\n");
6695 FAILED(buf
[5] != 2, "test69 case 6 failed\n");
6696 FAILED(buf
[6] != 1, "test69 case 7 failed\n");
6697 FAILED(buf
[7] != 2, "test69 case 8 failed\n");
6699 sljit_free_code(code
.code
, NULL
);
6703 static void test70(void)
6705 /* Test argument passing to sljit_emit_enter. */
6706 executable_code code
;
6707 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6714 printf("Run test70\n");
6721 FAILED(!compiler
, "cannot create compiler\n");
6723 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, 32, W
, 32, W
), 1, 4, 0, 0, 0);
6724 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
6725 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S1
, 0);
6726 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_S3
, 0);
6727 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
6728 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
6729 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_s32
), SLJIT_S2
, 0);
6730 sljit_emit_return_void(compiler
);
6732 code
.code
= sljit_generate_code(compiler
);
6734 sljit_free_compiler(compiler
);
6736 code
.test70_f1(-1478, 9476, 4928, -6832);
6738 FAILED(wbuf
[0] != 9476, "test70 case 1 failed\n");
6739 FAILED(wbuf
[1] != -6832, "test70 case 2 failed\n");
6740 FAILED(ibuf
[0] != -1478, "test70 case 3 failed\n");
6741 FAILED(ibuf
[1] != 4928, "test70 case 4 failed\n");
6743 sljit_free_code(code
.code
, NULL
);
6745 compiler
= sljit_create_compiler(NULL
, NULL
);
6746 FAILED(!compiler
, "cannot create compiler\n");
6748 sljit_emit_enter(compiler
, SLJIT_F64_ALIGNMENT
, SLJIT_ARGS4(VOID
, 32, 32, W
, W
), 1, 4, 0, 0, 0);
6749 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
6750 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
6751 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_S1
, 0);
6752 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
6753 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S2
, 0);
6754 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_s32
), SLJIT_S3
, 0);
6755 sljit_emit_return_void(compiler
);
6757 code
.code
= sljit_generate_code(compiler
);
6759 sljit_free_compiler(compiler
);
6761 code
.test70_f2(4721, 7892, -3579, -4830);
6763 FAILED(wbuf
[0] != 4721, "test70 case 5 failed\n");
6764 FAILED(wbuf
[1] != 7892, "test70 case 6 failed\n");
6765 FAILED(ibuf
[0] != -3579, "test70 case 7 failed\n");
6766 FAILED(ibuf
[1] != -4830, "test70 case 8 failed\n");
6768 sljit_free_code(code
.code
, NULL
);
6770 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
6776 compiler
= sljit_create_compiler(NULL
, NULL
);
6777 FAILED(!compiler
, "cannot create compiler\n");
6779 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, 32, F32
, W
, F64
), 2, 2, 2, 0, 0);
6780 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)&wbuf
, SLJIT_S1
, 0);
6781 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&ibuf
, SLJIT_S0
, 0);
6782 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&dbuf
, SLJIT_FR1
, 0);
6783 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM0(), (sljit_sw
)&fbuf
, SLJIT_FR0
, 0);
6784 sljit_emit_return_void(compiler
);
6786 code
.code
= sljit_generate_code(compiler
);
6788 sljit_free_compiler(compiler
);
6790 code
.test70_f3(-6834, 674.5, 2789, -895.25);
6792 FAILED(wbuf
[0] != 2789, "test70 case 9 failed\n");
6793 FAILED(ibuf
[0] != -6834, "test70 case 10 failed\n");
6794 FAILED(dbuf
[0] != -895.25, "test70 case 11 failed\n");
6795 FAILED(fbuf
[0] != 674.5, "test70 case 12 failed\n");
6802 compiler
= sljit_create_compiler(NULL
, NULL
);
6803 FAILED(!compiler
, "cannot create compiler\n");
6805 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F32
, F64
, F32
, 32), 1, 1, 3, 0, 0);
6806 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&ibuf
, SLJIT_S0
, 0);
6807 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&dbuf
, SLJIT_FR1
, 0);
6808 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&fbuf
);
6809 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
6810 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f32
), SLJIT_FR2
, 0);
6811 sljit_emit_return_void(compiler
);
6813 code
.code
= sljit_generate_code(compiler
);
6815 sljit_free_compiler(compiler
);
6817 code
.test70_f4(-4712.5, 5342.25, 2904.25, -4607);
6819 FAILED(ibuf
[0] != -4607, "test70 case 13 failed\n");
6820 FAILED(dbuf
[0] != 5342.25, "test70 case 14 failed\n");
6821 FAILED(fbuf
[0] != -4712.5, "test70 case 15 failed\n");
6822 FAILED(fbuf
[1] != 2904.25, "test70 case 16 failed\n");
6829 compiler
= sljit_create_compiler(NULL
, NULL
);
6830 FAILED(!compiler
, "cannot create compiler\n");
6832 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, F32
, 32, F32
), 1, 1, 3, 0, 0);
6833 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&ibuf
, SLJIT_S0
, 0);
6834 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&dbuf
, SLJIT_FR0
, 0);
6835 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&fbuf
);
6836 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR1
, 0);
6837 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f32
), SLJIT_FR2
, 0);
6839 sljit_emit_return_void(compiler
);
6841 code
.code
= sljit_generate_code(compiler
);
6843 sljit_free_compiler(compiler
);
6845 code
.test70_f5(3578.5, 4619.25, 6859, -1807.75);
6847 FAILED(ibuf
[0] != 6859, "test70 case 17 failed\n");
6848 FAILED(dbuf
[0] != 3578.5, "test70 case 18 failed\n");
6849 FAILED(fbuf
[0] != 4619.25, "test70 case 19 failed\n");
6850 FAILED(fbuf
[1] != -1807.75, "test70 case 20 failed\n");
6857 compiler
= sljit_create_compiler(NULL
, NULL
);
6858 FAILED(!compiler
, "cannot create compiler\n");
6860 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, 32, F32
, F64
), SLJIT_NUMBER_OF_SCRATCH_REGISTERS
+ 2, 1, 3, 0, 33);
6861 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&ibuf
, SLJIT_S0
, 0);
6862 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
6863 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
6864 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
), SLJIT_FR2
, 0);
6865 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM0(), (sljit_sw
)&fbuf
, SLJIT_FR1
, 0);
6866 sljit_emit_return_void(compiler
);
6868 code
.code
= sljit_generate_code(compiler
);
6870 sljit_free_compiler(compiler
);
6872 code
.test70_f6(2740.75, -2651, -7909.25, 3671.5);
6874 FAILED(ibuf
[0] != -2651, "test70 case 21 failed\n");
6875 FAILED(dbuf
[0] != 2740.75, "test70 case 22 failed\n");
6876 FAILED(dbuf
[1] != 3671.5, "test70 case 23 failed\n");
6877 FAILED(fbuf
[0] != -7909.25, "test70 case 24 failed\n");
6884 compiler
= sljit_create_compiler(NULL
, NULL
);
6885 FAILED(!compiler
, "cannot create compiler\n");
6887 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F32
, 32, W
, 32), 1, 3, 1, 0, 1);
6888 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)&wbuf
, SLJIT_S1
, 0);
6889 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
6890 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
6891 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_s32
), SLJIT_S2
, 0);
6892 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM0(), (sljit_sw
)&fbuf
, SLJIT_FR0
, 0);
6893 sljit_emit_return_void(compiler
);
6895 code
.code
= sljit_generate_code(compiler
);
6897 sljit_free_compiler(compiler
);
6899 code
.test70_f7(-5219.25, -4530, 7214, 6741);
6901 FAILED(wbuf
[0] != 7214, "test70 case 25 failed\n");
6902 FAILED(ibuf
[0] != -4530, "test70 case 26 failed\n");
6903 FAILED(ibuf
[1] != 6741, "test70 case 27 failed\n");
6904 FAILED(fbuf
[0] != -5219.25, "test70 case 28 failed\n");
6911 compiler
= sljit_create_compiler(NULL
, NULL
);
6912 FAILED(!compiler
, "cannot create compiler\n");
6914 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, F64
, W
, W
), 1, 5, 2, 0, SLJIT_MAX_LOCAL_SIZE
- 1);
6915 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_S0
, 0);
6916 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_SP
), SLJIT_MAX_LOCAL_SIZE
- 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
6917 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
6918 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
6919 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_S1
, 0);
6920 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
6921 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
6922 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
), SLJIT_FR1
, 0);
6923 sljit_emit_return_void(compiler
);
6925 code
.code
= sljit_generate_code(compiler
);
6927 sljit_free_compiler(compiler
);
6929 code
.test70_f8(-3749.75, 5280.5, 9134, -6506);
6931 FAILED(wbuf
[0] != 9134, "test70 case 29 failed\n");
6932 FAILED(wbuf
[1] != -6506, "test70 case 30 failed\n");
6933 FAILED(dbuf
[0] != -3749.75, "test70 case 31 failed\n");
6934 FAILED(dbuf
[1] != 5280.5, "test70 case 32 failed\n");
6941 compiler
= sljit_create_compiler(NULL
, NULL
);
6942 FAILED(!compiler
, "cannot create compiler\n");
6944 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, F64
, W
, F64
), 1, 1, 3, 0, SLJIT_MAX_LOCAL_SIZE
);
6945 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)&wbuf
, SLJIT_S0
, 0);
6946 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
6947 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
6948 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
), SLJIT_FR1
, 0);
6949 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
6951 sljit_emit_return_void(compiler
);
6953 code
.code
= sljit_generate_code(compiler
);
6955 sljit_free_compiler(compiler
);
6957 code
.test70_f9(-6049.25, 7301.5, 4610, -4312.75);
6959 FAILED(wbuf
[0] != 4610, "test70 case 33 failed\n");
6960 FAILED(dbuf
[0] != -6049.25, "test70 case 34 failed\n");
6961 FAILED(dbuf
[1] != 7301.5, "test70 case 35 failed\n");
6962 FAILED(dbuf
[2] != -4312.75, "test70 case 36 failed\n");
6969 compiler
= sljit_create_compiler(NULL
, NULL
);
6970 FAILED(!compiler
, "cannot create compiler\n");
6972 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, F64
, F64
, 32), 1, 1, 3, 0, 0);
6973 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&ibuf
, SLJIT_S0
, 0);
6974 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
6975 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
6976 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
), SLJIT_FR1
, 0);
6977 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
6979 sljit_emit_return_void(compiler
);
6981 code
.code
= sljit_generate_code(compiler
);
6983 sljit_free_compiler(compiler
);
6985 code
.test70_f10(4810.5, -9148.75, 8601.25, 6703);
6987 FAILED(ibuf
[0] != 6703, "test70 case 37 failed\n");
6988 FAILED(dbuf
[0] != 4810.5, "test70 case 38 failed\n");
6989 FAILED(dbuf
[1] != -9148.75, "test70 case 39 failed\n");
6990 FAILED(dbuf
[2] != 8601.25, "test70 case 40 failed\n");
6996 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
6998 static sljit_sw SLJIT_FUNC
test71_f1(sljit_sw a
)
7003 static sljit_sw SLJIT_FUNC
test71_f2(sljit_sw a
, sljit_s32 b
, sljit_s32 c
, sljit_sw d
)
7005 return a
| b
| c
| d
;
7008 static sljit_sw
test71_f3(sljit_sw a
, sljit_s32 b
, sljit_s32 c
, sljit_sw d
)
7010 return a
| b
| c
| d
;
7013 static sljit_sw
test71_f4(sljit_sw a
, sljit_s32 b
, sljit_s32 c
, sljit_sw d
)
7015 SLJIT_UNUSED_ARG(a
);
7019 static sljit_sw
test71_f5(void)
7024 static sljit_sw SLJIT_FUNC
test71_f6(sljit_f64 a
, sljit_f64 b
, sljit_f64 c
, sljit_f64 d
)
7026 if (a
== 1345.5 && b
== -8724.25 && c
== 9034.75 && d
== 6307.5)
7031 #endif /* SLJIT_CONFIG_X86 */
7033 static void test71(void)
7035 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
7036 /* Test tail calls. */
7037 executable_code code
;
7038 struct sljit_compiler
* compiler
;
7039 struct sljit_jump
*jump
;
7041 sljit_sw executable_offset
;
7046 printf("Run test71\n");
7048 compiler
= sljit_create_compiler(NULL
, NULL
);
7049 FAILED(!compiler
, "cannot create compiler\n");
7051 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, W
), 4, 4, 0, 0, 0);
7052 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
7053 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
7054 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0);
7055 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0);
7056 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -1);
7057 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1);
7058 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1);
7059 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, -1);
7060 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_TAIL_CALL
, SLJIT_ARGS1(W
, W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f1
));
7062 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7064 code
.code
= sljit_generate_code(compiler
);
7066 sljit_free_compiler(compiler
);
7068 FAILED(code
.func1(7987) != 17987, "test71 case 1 failed\n");
7070 compiler
= sljit_create_compiler(NULL
, NULL
);
7071 FAILED(!compiler
, "cannot create compiler\n");
7073 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, W
), 1, 4, 0, 0, 0);
7074 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
7075 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -1);
7076 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1);
7077 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1);
7078 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, -1);
7079 jump
= sljit_emit_call(compiler
, SLJIT_CALL
| SLJIT_REWRITABLE_JUMP
| SLJIT_TAIL_CALL
, SLJIT_ARGS1(W
, W
));
7080 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7082 sljit_set_target(jump
, 0);
7084 code
.code
= sljit_generate_code(compiler
);
7087 executable_offset
= sljit_get_executable_offset(compiler
);
7088 jump_addr
= sljit_get_jump_addr(jump
);
7089 sljit_free_compiler(compiler
);
7091 sljit_set_jump_addr(jump_addr
, SLJIT_FUNC_UADDR(test71_f1
), executable_offset
);
7093 FAILED(code
.func1(3903) != 13903, "test71 case 2 failed\n");
7095 compiler
= sljit_create_compiler(NULL
, NULL
);
7096 FAILED(!compiler
, "cannot create compiler\n");
7098 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), 4, 2, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
7099 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f2
));
7100 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x28000000);
7101 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0x00140000);
7102 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_IMM
, 0x00002800);
7103 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x00000041);
7104 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -1);
7105 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1);
7106 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_TAIL_CALL
, SLJIT_ARGS4(W
, W
, 32, 32, W
), SLJIT_MEM1(SLJIT_SP
), 0);
7107 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7109 code
.code
= sljit_generate_code(compiler
);
7111 sljit_free_compiler(compiler
);
7113 FAILED(code
.func0() != 0x28142841, "test71 case 3 failed\n");
7115 compiler
= sljit_create_compiler(NULL
, NULL
);
7116 FAILED(!compiler
, "cannot create compiler\n");
7118 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), 4, 4, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
7119 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f2
));
7120 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x81000000);
7121 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0x00480000);
7122 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_IMM
, 0x00002100);
7123 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x00000014);
7124 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -1);
7125 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1);
7126 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1);
7127 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_TAIL_CALL
, SLJIT_ARGS4(W
, W
, 32, 32, W
), SLJIT_S3
, 0);
7128 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7130 code
.code
= sljit_generate_code(compiler
);
7132 sljit_free_compiler(compiler
);
7134 FAILED(code
.func0() != (sljit_sw
)0x81482114, "test71 case 4 failed\n");
7136 sljit_free_code(code
.code
, NULL
);
7138 compiler
= sljit_create_compiler(NULL
, NULL
);
7139 FAILED(!compiler
, "cannot create compiler\n");
7141 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(W
, W
, W
, W
), 4, 4, 0, 0, 0);
7142 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
7143 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_S1
, 0);
7144 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_S2
, 0);
7145 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x48000000);
7146 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -1);
7147 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1);
7148 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1);
7149 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, -1);
7150 sljit_emit_icall(compiler
, SLJIT_CALL_CDECL
| SLJIT_TAIL_CALL
, SLJIT_ARGS4(W
, W
, 32, 32, W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f3
));
7151 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7153 code
.code
= sljit_generate_code(compiler
);
7155 sljit_free_compiler(compiler
);
7157 FAILED(code
.func3(0x12, 0x8800, 0x240000) != 0x48248812, "test71 case 5 failed\n");
7159 sljit_free_code(code
.code
, NULL
);
7161 compiler
= sljit_create_compiler(NULL
, NULL
);
7162 FAILED(!compiler
, "cannot create compiler\n");
7164 sljit_emit_enter(compiler
, SLJIT_F64_ALIGNMENT
, SLJIT_ARGS0(W
), 4, 0, 0, 0, 0);
7165 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f4
));
7166 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0x342);
7167 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_IMM
, 0x451000);
7168 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x21000000);
7169 sljit_emit_icall(compiler
, SLJIT_CALL_CDECL
| SLJIT_TAIL_CALL
, SLJIT_ARGS4(W
, W
, 32, 32, W
), SLJIT_R0
, 0);
7170 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7172 code
.code
= sljit_generate_code(compiler
);
7174 sljit_free_compiler(compiler
);
7176 FAILED(code
.func0() != 0x21451342, "test71 case 6 failed\n");
7178 sljit_free_code(code
.code
, NULL
);
7180 compiler
= sljit_create_compiler(NULL
, NULL
);
7181 FAILED(!compiler
, "cannot create compiler\n");
7183 sljit_emit_enter(compiler
, SLJIT_F64_ALIGNMENT
, SLJIT_ARGS0(W
), 1, 0, 0, 0, 9);
7184 sljit_emit_icall(compiler
, SLJIT_CALL_CDECL
| SLJIT_TAIL_CALL
, SLJIT_ARGS0(W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f5
));
7185 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7187 code
.code
= sljit_generate_code(compiler
);
7189 sljit_free_compiler(compiler
);
7191 FAILED(code
.func0() != 7461932, "test71 case 7 failed\n");
7193 sljit_free_code(code
.code
, NULL
);
7195 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
7201 compiler
= sljit_create_compiler(NULL
, NULL
);
7202 FAILED(!compiler
, "cannot create compiler\n");
7204 sljit_emit_enter(compiler
, SLJIT_F64_ALIGNMENT
, SLJIT_ARGS0(W
), 1, 0, 4, 0, 0);
7205 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
7206 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_R0
), 0);
7207 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
));
7208 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_f64
));
7209 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_R0
), 3 * sizeof(sljit_f64
));
7210 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_TAIL_CALL
, SLJIT_ARGS4(W
, F64
, F64
, F64
, F64
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f6
));
7211 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7213 code
.code
= sljit_generate_code(compiler
);
7215 sljit_free_compiler(compiler
);
7217 FAILED(code
.func0() != 8920567, "test71 case 8 failed\n");
7219 sljit_free_code(code
.code
, NULL
);
7221 wbuf
[0] = SLJIT_FUNC_ADDR(test71_f6
);
7223 compiler
= sljit_create_compiler(NULL
, NULL
);
7224 FAILED(!compiler
, "cannot create compiler\n");
7226 sljit_emit_enter(compiler
, SLJIT_F64_ALIGNMENT
, SLJIT_ARGS4(W
, F64
, F64
, F64
, F64
), 1, 0, 4, 0, 0);
7227 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_TAIL_CALL
, SLJIT_ARGS4(W
, F64
, F64
, F64
, F64
), SLJIT_MEM0(), (sljit_sw
)wbuf
);
7228 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7230 code
.code
= sljit_generate_code(compiler
);
7232 sljit_free_compiler(compiler
);
7234 FAILED(code
.test71_f1(1345.5, -8724.25, 9034.75, 6307.5) != 8920567, "test71 case 9 failed\n");
7236 sljit_free_code(code
.code
, NULL
);
7238 #endif /* SLJIT_CONFIG_X86 */
7243 int sljit_test(int argc
, char* argv
[])
7245 sljit_s32 has_arg
= (argc
>= 2 && argv
[1][0] == '-' && argv
[1][2] == '\0');
7246 verbose
= has_arg
&& argv
[1][1] == 'v';
7247 silent
= has_arg
&& argv
[1][1] == 's';
7249 if (!verbose
&& !silent
)
7250 printf("Pass -v to enable verbose, -s to disable this hint.\n\n");
7252 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
7253 test_exec_allocator();
7327 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
7328 sljit_free_unused_memory_exec();
7331 # define TEST_COUNT 71
7333 printf("SLJIT tests: ");
7334 if (successful_tests
== TEST_COUNT
)
7335 printf("all tests are " COLOR_GREEN
"PASSED" COLOR_DEFAULT
" ");
7337 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
);
7338 printf("on " COLOR_ARCH
"%s" COLOR_DEFAULT
"%s\n", sljit_get_platform_name(), sljit_has_cpu_feature(SLJIT_HAS_FPU
) ? " (with fpu)" : " (without fpu)");
7340 return TEST_COUNT
- successful_tests
;
7346 #pragma warning(pop)