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 sljit_sw (*test53_f1
)(sljit_sw a
, sljit_sw b
, sljit_sw c
);
60 void (SLJIT_FUNC
*test70_f1
)(sljit_s32 a
, sljit_uw b
, sljit_u32 c
, sljit_sw d
);
61 void (*test70_f2
)(sljit_s32 a
, sljit_u32 b
, sljit_sw c
, sljit_sw d
);
62 void (SLJIT_FUNC
*test70_f3
)(sljit_s32 a
, sljit_f32 b
, sljit_uw c
, sljit_f64 d
);
63 void (SLJIT_FUNC
*test70_f4
)(sljit_f32 a
, sljit_f64 b
, sljit_f32 c
, sljit_s32 d
);
64 void (SLJIT_FUNC
*test70_f5
)(sljit_f64 a
, sljit_f32 b
, sljit_u32 c
, sljit_f32 d
);
65 void (SLJIT_FUNC
*test70_f6
)(sljit_f64 a
, sljit_s32 b
, sljit_f32 c
, sljit_f64 d
);
66 void (SLJIT_FUNC
*test70_f7
)(sljit_f32 a
, sljit_s32 b
, sljit_uw c
, sljit_u32 d
);
67 void (SLJIT_FUNC
*test70_f8
)(sljit_f64 a
, sljit_f64 b
, sljit_uw c
, sljit_sw d
);
68 void (SLJIT_FUNC
*test70_f9
)(sljit_f64 a
, sljit_f64 b
, sljit_uw c
, sljit_f64 d
);
69 void (SLJIT_FUNC
*test70_f10
)(sljit_f64 a
, sljit_f64 b
, sljit_f64 c
, sljit_s32 d
);
71 sljit_sw (*test71_f1
)(sljit_sw a
, sljit_sw b
, sljit_sw c
, sljit_sw d
);
72 sljit_sw (*test71_f2
)(sljit_f64 a
, sljit_f64 b
);
73 sljit_sw (SLJIT_FUNC
*test71_f3
)(sljit_f64 a
, sljit_f64 b
, sljit_f64 c
, sljit_f64 d
);
74 sljit_sw (SLJIT_FUNC
*test71_f4
)(sljit_f64 a
, sljit_f64 b
, sljit_f64 c
);
76 void (SLJIT_FUNC
*test73_f1
)(sljit_s32 a
, sljit_sw b
, sljit_sw c
, sljit_s32 d
);
77 void (*test73_f2
)(sljit_sw a
, sljit_sw b
, sljit_s32 c
, sljit_s32 d
);
78 void (SLJIT_FUNC
*test73_f3
)(sljit_f64 a
, sljit_f64 b
, sljit_f64 c
, sljit_sw d
);
79 void (SLJIT_FUNC
*test73_f4
)(sljit_f64 a
, sljit_f64 b
, sljit_sw c
, sljit_sw d
);
81 typedef union executable_code executable_code
;
83 static sljit_s32 successful_tests
= 0;
84 static sljit_s32 verbose
= 0;
85 static sljit_s32 silent
= 0;
87 #define FAILED(cond, text) \
88 if (SLJIT_UNLIKELY(cond)) { \
93 #define CHECK(compiler) \
94 if (sljit_get_compiler_error(compiler) != SLJIT_ERR_COMPILED) { \
95 printf("Compiler error: %d\n", sljit_get_compiler_error(compiler)); \
96 sljit_free_compiler(compiler); \
100 static void cond_set(struct sljit_compiler
*compiler
, sljit_s32 dst
, sljit_sw dstw
, sljit_s32 type
)
102 /* Testing both sljit_emit_op_flags and sljit_emit_jump. */
103 struct sljit_jump
* jump
;
104 struct sljit_label
* label
;
106 sljit_emit_op_flags(compiler
, SLJIT_MOV
, dst
, dstw
, type
);
107 jump
= sljit_emit_jump(compiler
, type
);
108 sljit_emit_op2(compiler
, SLJIT_ADD
, dst
, dstw
, dst
, dstw
, SLJIT_IMM
, 2);
109 label
= sljit_emit_label(compiler
);
110 sljit_set_label(jump
, label
);
113 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
115 /* For interface testing and for test64. */
116 void *sljit_test_malloc_exec(sljit_uw size
, void *exec_allocator_data
)
118 if (exec_allocator_data
)
119 return exec_allocator_data
;
121 return SLJIT_BUILTIN_MALLOC_EXEC(size
, exec_allocator_data
);
124 /* For interface testing. */
125 void sljit_test_free_code(void* code
, void *exec_allocator_data
)
127 SLJIT_UNUSED_ARG(exec_allocator_data
);
128 SLJIT_BUILTIN_FREE_EXEC(code
, exec_allocator_data
);
131 #define MALLOC_EXEC(result, size) \
132 result = SLJIT_MALLOC_EXEC(size, NULL); \
134 printf("Cannot allocate executable memory\n"); \
137 memset(result, 255, size);
139 #define FREE_EXEC(ptr) \
140 SLJIT_FREE_EXEC(((sljit_u8*)(ptr)) + SLJIT_EXEC_OFFSET(ptr), NULL);
142 static void test_exec_allocator(void)
144 /* This is not an sljit test. */
150 printf("Run executable allocator test\n");
152 MALLOC_EXEC(ptr1
, 32);
153 MALLOC_EXEC(ptr2
, 512);
154 MALLOC_EXEC(ptr3
, 512);
158 MALLOC_EXEC(ptr1
, 262104);
159 MALLOC_EXEC(ptr2
, 32000);
161 MALLOC_EXEC(ptr1
, 262104);
164 MALLOC_EXEC(ptr1
, 512);
165 MALLOC_EXEC(ptr2
, 512);
166 MALLOC_EXEC(ptr3
, 512);
168 MALLOC_EXEC(ptr2
, 512);
169 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
170 sljit_free_unused_memory_exec();
176 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
177 sljit_free_unused_memory_exec();
183 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
185 static void test1(void)
187 /* Enter and return from an sljit function. */
188 executable_code code
;
189 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
192 printf("Run test1\n");
194 FAILED(!compiler
, "cannot create compiler\n");
196 /* 3 arguments passed, 3 arguments used. */
197 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(W
, W
, W
, W
), 3, 3, 0, 0, 0);
198 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_S1
, 0);
200 SLJIT_ASSERT(sljit_get_generated_code_size(compiler
) == 0);
201 code
.code
= sljit_generate_code(compiler
);
203 SLJIT_ASSERT(compiler
->error
== SLJIT_ERR_COMPILED
);
204 SLJIT_ASSERT(sljit_get_generated_code_size(compiler
) > 0);
205 sljit_free_compiler(compiler
);
207 FAILED(code
.func3(3, -21, 86) != -21, "test1 case 1 failed\n");
208 FAILED(code
.func3(4789, 47890, 997) != 47890, "test1 case 2 failed\n");
210 sljit_free_code(code
.code
, NULL
);
214 static void test2(void)
217 executable_code code
;
218 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
220 static sljit_sw data
[2] = { 0, -9876 };
223 printf("Run test2\n");
225 FAILED(!compiler
, "cannot create compiler\n");
235 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 2, 0, 0, 0);
236 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 9999);
237 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_S0
, 0);
238 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
), SLJIT_R0
, 0);
239 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
240 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_MEM2(SLJIT_S1
, SLJIT_R1
), 0);
241 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 2);
242 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_S1
, SLJIT_S0
), SLJIT_WORD_SHIFT
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R1
), 0);
243 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 3);
244 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_S1
, SLJIT_S0
), SLJIT_WORD_SHIFT
, SLJIT_MEM0(), (sljit_sw
)&buf
);
245 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
246 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&data
);
247 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
248 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
- 0x12345678);
249 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R0
), 0x12345678);
250 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_R0
, 0);
251 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3456);
252 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
- 0xff890 + 6 * (sljit_sw
)sizeof(sljit_sw
));
253 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0xff890, SLJIT_R0
, 0);
254 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
+ 0xff890 + 7 * (sljit_sw
)sizeof(sljit_sw
));
255 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), -0xff890, SLJIT_R0
, 0);
256 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R2
, 0);
258 code
.code
= sljit_generate_code(compiler
);
260 sljit_free_compiler(compiler
);
262 FAILED(code
.func1((sljit_sw
)&buf
) != 9999, "test2 case 1 failed\n");
263 FAILED(buf
[1] != 9999, "test2 case 2 failed\n");
264 FAILED(buf
[2] != 9999, "test2 case 3 failed\n");
265 FAILED(buf
[3] != 5678, "test2 case 4 failed\n");
266 FAILED(buf
[4] != -9876, "test2 case 5 failed\n");
267 FAILED(buf
[5] != 5678, "test2 case 6 failed\n");
268 FAILED(buf
[6] != 3456, "test2 case 6 failed\n");
269 FAILED(buf
[7] != 3456, "test2 case 6 failed\n");
271 sljit_free_code(code
.code
, NULL
);
275 static void test3(void)
278 executable_code code
;
279 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
283 printf("Run test3\n");
285 FAILED(!compiler
, "cannot create compiler\n");
292 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 0);
293 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 0);
294 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_MEM0(), (sljit_sw
)&buf
[1], SLJIT_MEM0(), (sljit_sw
)&buf
[1]);
295 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_RETURN_REG
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
296 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2);
297 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[4] - 0xff0000 - 0x20);
298 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[4] - 0xff0000);
299 sljit_emit_op1(compiler
, SLJIT_NOT
, SLJIT_MEM1(SLJIT_R1
), 0xff0000 + 0x20, SLJIT_MEM1(SLJIT_R2
), 0xff0000);
300 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
302 code
.code
= sljit_generate_code(compiler
);
304 sljit_free_compiler(compiler
);
306 FAILED(code
.func1((sljit_sw
)&buf
) != ~1234, "test3 case 1 failed\n");
307 FAILED(buf
[1] != ~1234, "test3 case 2 failed\n");
308 FAILED(buf
[3] != ~9876, "test3 case 3 failed\n");
309 FAILED(buf
[4] != ~0x12345678, "test3 case 4 failed\n");
311 sljit_free_code(code
.code
, NULL
);
315 static void test4(void)
318 executable_code code
;
319 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
323 printf("Run test4\n");
325 FAILED(!compiler
, "cannot create compiler\n");
331 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(W
, P
, W
), 3, 2, 0, 0, 0);
332 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_S1
, 0);
333 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_MEM0(), (sljit_sw
)&buf
[0], SLJIT_MEM0(), (sljit_sw
)&buf
[1]);
334 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 299);
335 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_R1
, 0);
336 sljit_emit_op1(compiler
, SLJIT_NEG
, SLJIT_RETURN_REG
, 0, SLJIT_S1
, 0);
337 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
339 code
.code
= sljit_generate_code(compiler
);
341 sljit_free_compiler(compiler
);
343 FAILED(code
.func2((sljit_sw
)&buf
, 4567) != -4567, "test4 case 1 failed\n");
344 FAILED(buf
[0] != -1234, "test4 case 2 failed\n");
345 FAILED(buf
[2] != -4567, "test4 case 3 failed\n");
346 FAILED(buf
[3] != -299, "test4 case 4 failed\n");
348 sljit_free_code(code
.code
, NULL
);
352 static void test5(void)
355 executable_code code
;
356 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
360 printf("Run test5\n");
362 FAILED(!compiler
, "cannot create compiler\n");
373 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 2, 0, 0, 0);
374 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
375 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 50);
376 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);
377 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
) + 2);
378 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 50);
379 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
380 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
381 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_IMM
, 4, SLJIT_R0
, 0);
382 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_IMM
, 50, SLJIT_R1
, 0);
383 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
));
384 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R1
, 0);
385 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
));
386 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
));
387 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);
388 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x1e7d39f2);
389 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R1
, 0, SLJIT_IMM
, 0x23de7c06);
390 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, 0x3d72e452, SLJIT_R1
, 0);
391 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
));
392 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_IMM
, 1000, SLJIT_R0
, 0);
393 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1430);
394 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_IMM
, -99, SLJIT_R0
, 0);
396 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
398 code
.code
= sljit_generate_code(compiler
);
400 sljit_free_compiler(compiler
);
402 FAILED(code
.func1((sljit_sw
)&buf
) != 2437 + 2 * sizeof(sljit_sw
), "test5 case 1 failed\n");
403 FAILED(buf
[0] != 202 + 2 * sizeof(sljit_sw
), "test5 case 2 failed\n");
404 FAILED(buf
[2] != 500, "test5 case 3 failed\n");
405 FAILED(buf
[3] != 400, "test5 case 4 failed\n");
406 FAILED(buf
[4] != 200, "test5 case 5 failed\n");
407 FAILED(buf
[5] != 250, "test5 case 6 failed\n");
408 FAILED(buf
[6] != 0x425bb5f8, "test5 case 7 failed\n");
409 FAILED(buf
[7] != 0x5bf01e44, "test5 case 8 failed\n");
410 FAILED(buf
[8] != 270, "test5 case 9 failed\n");
412 sljit_free_code(code
.code
, NULL
);
416 static void test6(void)
418 /* Test addc, sub, subc. */
419 executable_code code
;
420 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
424 printf("Run test6\n");
426 FAILED(!compiler
, "cannot create compiler\n");
439 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 0);
440 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
441 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -1);
442 sljit_emit_op2(compiler
, SLJIT_ADDC
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0, SLJIT_IMM
, 0);
443 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R0
, 0);
444 sljit_emit_op2(compiler
, SLJIT_ADDC
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 4);
445 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 100);
446 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, SLJIT_IMM
, 50);
447 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 6000);
448 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_IMM
, 10);
449 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);
450 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 100);
451 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2);
452 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R0
, 0);
453 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5000);
454 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R0
, 0);
455 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
456 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R1
, 0);
457 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5000);
458 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_IMM
, 6000, SLJIT_R0
, 0);
459 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_R0
, 0);
460 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 100);
461 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 32768);
462 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_R1
, 0);
463 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -32767);
464 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_R1
, 0);
465 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x52cd3bf4);
466 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_R0
, 0, SLJIT_IMM
, 0x3da297c6);
467 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 6000);
468 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, SLJIT_R1
, 0);
469 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, SLJIT_R1
, 0);
470 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 10);
471 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_RETURN_REG
, 0, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 5);
472 sljit_emit_op2(compiler
, SLJIT_SUBC
, SLJIT_RETURN_REG
, 0, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 2);
473 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_RETURN_REG
, 0, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, -2220);
474 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
476 code
.code
= sljit_generate_code(compiler
);
478 sljit_free_compiler(compiler
);
480 FAILED(code
.func1((sljit_sw
)&buf
) != 2223, "test6 case 1 failed\n");
481 FAILED(buf
[0] != 1, "test6 case 2 failed\n");
482 FAILED(buf
[1] != 5, "test6 case 3 failed\n");
483 FAILED(buf
[2] != 50, "test6 case 4 failed\n");
484 FAILED(buf
[3] != 4, "test6 case 5 failed\n");
485 FAILED(buf
[4] != 50, "test6 case 6 failed\n");
486 FAILED(buf
[5] != 50, "test6 case 7 failed\n");
487 FAILED(buf
[6] != 1000, "test6 case 8 failed\n");
488 FAILED(buf
[7] != 100 - 32768, "test6 case 9 failed\n");
489 FAILED(buf
[8] != 100 + 32767, "test6 case 10 failed\n");
490 FAILED(buf
[9] != 0x152aa42e, "test6 case 11 failed\n");
491 FAILED(buf
[10] != -2000, "test6 case 12 failed\n");
493 sljit_free_code(code
.code
, NULL
);
497 static void test7(void)
499 /* Test logical operators. */
500 executable_code code
;
501 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
505 printf("Run test7\n");
507 FAILED(!compiler
, "cannot create compiler\n");
515 buf
[7] = (sljit_sw
)0xc43a7f95;
517 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 0);
518 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xf0C000);
519 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, SLJIT_IMM
, 0x308f);
520 sljit_emit_op2(compiler
, SLJIT_XOR
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
521 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);
522 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xC0F0);
523 sljit_emit_op2(compiler
, SLJIT_XOR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5);
524 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xff0000);
525 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R0
, 0);
526 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0xC0F0);
527 sljit_emit_op2(compiler
, SLJIT_AND
, SLJIT_R2
, 0, SLJIT_R2
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5);
528 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R2
, 0, SLJIT_IMM
, 0xff0000);
529 sljit_emit_op2(compiler
, SLJIT_XOR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 0xFFFFFF, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
530 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);
531 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7);
532 sljit_emit_op2(compiler
, SLJIT_XOR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_IMM
, (sljit_sw
)0xff00ff00, SLJIT_R0
, 0);
533 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0xff00ff00);
534 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x0f);
535 sljit_emit_op2(compiler
, SLJIT_AND
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0x888888, SLJIT_R1
, 0);
536 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
538 code
.code
= sljit_generate_code(compiler
);
540 sljit_free_compiler(compiler
);
542 FAILED(code
.func1((sljit_sw
)&buf
) != 0x8808, "test7 case 1 failed\n");
543 FAILED(buf
[0] != 0x0F807F00, "test7 case 2 failed\n");
544 FAILED(buf
[1] != 0x0F7F7F7F, "test7 case 3 failed\n");
545 FAILED(buf
[2] != 0x00F0F08F, "test7 case 4 failed\n");
546 FAILED(buf
[3] != 0x00A0A0A0, "test7 case 5 failed\n");
547 FAILED(buf
[4] != 0x00FF80B0, "test7 case 6 failed\n");
548 FAILED(buf
[5] != 0x00FF4040, "test7 case 7 failed\n");
549 FAILED(buf
[6] != (sljit_sw
)0xa56c82c0, "test7 case 8 failed\n");
550 FAILED(buf
[7] != 0x3b3a8095, "test7 case 9 failed\n");
552 sljit_free_code(code
.code
, NULL
);
556 static void test8(void)
558 /* Test flags (neg, cmp, test). */
559 executable_code code
;
560 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
564 printf("Run test8\n");
566 FAILED(!compiler
, "cannot create compiler\n");
581 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 2, 0, 0, 0);
582 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 20);
583 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 10);
584 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_IMM
, 6, SLJIT_IMM
, 5);
585 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_NOT_EQUAL
);
586 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_EQUAL
);
587 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 3000);
588 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_GREATER
);
589 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 3000);
590 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_S1
, 0);
591 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_LESS
);
592 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R2
, 0);
593 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, -15);
594 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_SIG_GREATER
);
595 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R2
, 0);
596 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -(sljit_sw
)(~(sljit_uw
)0 >> 1) - 1);
597 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0);
598 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
599 sljit_emit_op1(compiler
, SLJIT_NEG
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0);
600 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_OVERFLOW
);
601 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
602 sljit_emit_op1(compiler
, SLJIT_NOT
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R0
, 0);
603 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_ZERO
);
604 sljit_emit_op1(compiler
, SLJIT_NOT
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R1
, 0);
605 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_ZERO
);
606 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_IMM
, 0xffff, SLJIT_R0
, 0);
607 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 0xffff);
608 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_NOT_ZERO
);
609 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_IMM
, 0xffff, SLJIT_R1
, 0);
610 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_IMM
, 0xffff);
611 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
612 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
613 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
614 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0x1);
615 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, SLJIT_NOT_ZERO
);
616 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -(sljit_sw
)(~(sljit_uw
)0 >> 1) - 1);
617 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
618 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0);
619 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 11, SLJIT_OVERFLOW
);
620 sljit_emit_op2u(compiler
, SLJIT_ADD
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0);
621 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 12, SLJIT_OVERFLOW
);
622 sljit_emit_return_void(compiler
);
624 code
.code
= sljit_generate_code(compiler
);
626 sljit_free_compiler(compiler
);
628 code
.func1((sljit_sw
)&buf
);
629 FAILED(buf
[1] != 1, "test8 case 1 failed\n");
630 FAILED(buf
[2] != 0, "test8 case 2 failed\n");
631 FAILED(buf
[3] != 0, "test8 case 3 failed\n");
632 FAILED(buf
[4] != 1, "test8 case 4 failed\n");
633 FAILED(buf
[5] != 1, "test8 case 5 failed\n");
634 FAILED(buf
[6] != 1, "test8 case 6 failed\n");
635 FAILED(buf
[7] != 1, "test8 case 7 failed\n");
636 FAILED(buf
[8] != 0, "test8 case 8 failed\n");
637 FAILED(buf
[9] != 1, "test8 case 9 failed\n");
638 FAILED(buf
[10] != 0, "test8 case 10 failed\n");
639 FAILED(buf
[11] != 1, "test8 case 11 failed\n");
640 FAILED(buf
[12] != 0, "test8 case 12 failed\n");
642 sljit_free_code(code
.code
, NULL
);
646 static void test9(void)
649 executable_code code
;
650 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
652 #ifdef SLJIT_PREF_SHIFT_REG
653 sljit_s32 shift_reg
= SLJIT_PREF_SHIFT_REG
;
655 sljit_s32 shift_reg
= SLJIT_R2
;
658 SLJIT_ASSERT(shift_reg
>= SLJIT_R2
&& shift_reg
<= SLJIT_R3
);
661 printf("Run test9\n");
663 FAILED(!compiler
, "cannot create compiler\n");
678 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 4, 2, 0, 0, 0);
679 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xf);
680 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 3);
681 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
682 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
683 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
684 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R1
, 0, SLJIT_IMM
, 1);
685 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -64);
686 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 2);
687 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, shift_reg
, 0);
689 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0xff);
690 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
691 sljit_emit_op2(compiler
, SLJIT_SHL
, shift_reg
, 0, shift_reg
, 0, SLJIT_R0
, 0);
692 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, shift_reg
, 0);
693 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0xff);
694 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
695 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);
696 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, shift_reg
, 0, SLJIT_R0
, 0);
698 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, 0xf);
699 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
700 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_S1
, 0, SLJIT_S1
, 0, SLJIT_R0
, 0);
701 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_S1
, 0);
702 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_R0
, 0);
703 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_R0
, 0);
704 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0xf00);
705 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
706 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R1
, 0, SLJIT_R2
, 0, SLJIT_R0
, 0);
707 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_R1
, 0);
709 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)buf
);
710 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 9);
711 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
);
713 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 4);
714 sljit_emit_op2(compiler
, SLJIT_SHL
, shift_reg
, 0, SLJIT_IMM
, 2, shift_reg
, 0);
715 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, shift_reg
, 0);
717 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xa9);
718 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
719 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x7d00);
720 sljit_emit_op2(compiler
, SLJIT_LSHR32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 32);
721 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
722 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
724 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
725 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xe30000);
726 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
727 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffc0);
729 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffe0);
731 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
732 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x25000000);
733 sljit_emit_op2(compiler
, SLJIT_SHL32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xfffe1);
734 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
735 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
737 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 11, SLJIT_R1
, 0, SLJIT_R0
, 0);
739 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0);
740 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x5c);
741 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R1
, 0, SLJIT_R0
, 0, shift_reg
, 0);
742 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0xf600);
743 sljit_emit_op2(compiler
, SLJIT_LSHR32
, SLJIT_R0
, 0, SLJIT_R0
, 0, shift_reg
, 0);
744 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
745 /* Alternative form of uint32 type cast. */
746 sljit_emit_op2(compiler
, SLJIT_AND
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffffffff);
748 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
749 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x630000);
750 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, shift_reg
, 0);
751 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 12, SLJIT_R1
, 0, SLJIT_R0
, 0);
753 sljit_emit_return_void(compiler
);
755 code
.code
= sljit_generate_code(compiler
);
757 sljit_free_compiler(compiler
);
759 code
.func1((sljit_sw
)&buf
);
760 FAILED(buf
[0] != 0x3c, "test9 case 1 failed\n");
761 FAILED(buf
[1] != 0xf0, "test9 case 2 failed\n");
762 FAILED(buf
[2] != -16, "test9 case 3 failed\n");
763 FAILED(buf
[3] != 0xff0, "test9 case 4 failed\n");
764 FAILED(buf
[4] != 4, "test9 case 5 failed\n");
765 FAILED(buf
[5] != 0xff00, "test9 case 6 failed\n");
766 FAILED(buf
[6] != 0x3c, "test9 case 7 failed\n");
767 FAILED(buf
[7] != 0xf0, "test9 case 8 failed\n");
768 FAILED(buf
[8] != 0xf0, "test9 case 9 failed\n");
769 FAILED(buf
[9] != 0x18, "test9 case 10 failed\n");
770 FAILED(buf
[10] != 32, "test9 case 11 failed\n");
771 FAILED(buf
[11] != 0x4ae37da9, "test9 case 12 failed\n");
772 FAILED(buf
[12] != 0x63f65c, "test9 case 13 failed\n");
774 sljit_free_code(code
.code
, NULL
);
778 static void test10(void)
780 /* Test multiplications. */
781 executable_code code
;
782 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
786 printf("Run test10\n");
788 FAILED(!compiler
, "cannot create compiler\n");
797 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 0);
798 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
799 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
800 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
801 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 7);
802 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 8);
803 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
804 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_IMM
, -3, SLJIT_IMM
, -4);
805 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0);
806 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -2);
807 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);
808 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
) / 2);
809 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[3]);
810 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);
811 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 9);
812 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R0
, 0);
813 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R0
, 0);
814 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
815 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3);
816 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x123456789));
817 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_R0
, 0);
819 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 11, SLJIT_IMM
, 10);
820 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
822 code
.code
= sljit_generate_code(compiler
);
824 sljit_free_compiler(compiler
);
826 FAILED(code
.func1((sljit_sw
)&buf
) != 110, "test10 case 1 failed\n");
827 FAILED(buf
[0] != 15, "test10 case 2 failed\n");
828 FAILED(buf
[1] != 56, "test10 case 3 failed\n");
829 FAILED(buf
[2] != 12, "test10 case 4 failed\n");
830 FAILED(buf
[3] != -12, "test10 case 5 failed\n");
831 FAILED(buf
[4] != 100, "test10 case 6 failed\n");
832 FAILED(buf
[5] != 81, "test10 case 7 failed\n");
833 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
834 FAILED(buf
[6] != SLJIT_W(0x123456789) * 3, "test10 case 8 failed\n");
837 sljit_free_code(code
.code
, NULL
);
841 static void test11(void)
843 /* Test rewritable constants. */
844 executable_code code
;
845 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
846 struct sljit_const
* const1
;
847 struct sljit_const
* const2
;
848 struct sljit_const
* const3
;
849 struct sljit_const
* const4
;
851 sljit_sw executable_offset
;
852 sljit_uw const1_addr
;
853 sljit_uw const2_addr
;
854 sljit_uw const3_addr
;
855 sljit_uw const4_addr
;
856 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
857 sljit_sw word_value1
= (sljit_sw
)SLJIT_W(0xaaaaaaaaaaaaaaaa);
858 sljit_sw word_value2
= (sljit_sw
)SLJIT_W(0xfee1deadfbadf00d);
860 sljit_sw word_value1
= (sljit_sw
)0xaaaaaaaal
;
861 sljit_sw word_value2
= (sljit_sw
)0xfbadf00dl
;
866 printf("Run test11\n");
868 FAILED(!compiler
, "cannot create compiler\n");
873 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 0);
875 SLJIT_ASSERT(!sljit_alloc_memory(compiler
, 0));
876 SLJIT_ASSERT(!sljit_alloc_memory(compiler
, 16 * sizeof(sljit_sw
) + 1));
878 const1
= sljit_emit_const(compiler
, SLJIT_MEM0(), (sljit_sw
)&buf
[0], -0x81b9);
880 value
= sljit_alloc_memory(compiler
, 16 * sizeof(sljit_sw
));
883 SLJIT_ASSERT(!((sljit_sw
)value
& ((sljit_sw
)sizeof(sljit_sw
) - 1)));
884 memset(value
, 255, 16 * sizeof(sljit_sw
));
887 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
888 const2
= sljit_emit_const(compiler
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), SLJIT_WORD_SHIFT
- 1, -65535);
889 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);
890 const3
= sljit_emit_const(compiler
, SLJIT_MEM1(SLJIT_R0
), 0, word_value1
);
892 value
= sljit_alloc_memory(compiler
, 17);
895 SLJIT_ASSERT(!((sljit_sw
)value
& ((sljit_sw
)sizeof(sljit_sw
) - 1)));
896 memset(value
, 255, 16);
899 const4
= sljit_emit_const(compiler
, SLJIT_RETURN_REG
, 0, (sljit_sw
)0xf7afcdb7);
901 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
903 code
.code
= sljit_generate_code(compiler
);
905 executable_offset
= sljit_get_executable_offset(compiler
);
906 const1_addr
= sljit_get_const_addr(const1
);
907 const2_addr
= sljit_get_const_addr(const2
);
908 const3_addr
= sljit_get_const_addr(const3
);
909 const4_addr
= sljit_get_const_addr(const4
);
910 sljit_free_compiler(compiler
);
912 FAILED(code
.func1((sljit_sw
)&buf
) != (sljit_sw
)0xf7afcdb7, "test11 case 1 failed\n");
913 FAILED(buf
[0] != -0x81b9, "test11 case 2 failed\n");
914 FAILED(buf
[1] != -65535, "test11 case 3 failed\n");
915 FAILED(buf
[2] != word_value1
, "test11 case 4 failed\n");
917 sljit_set_const(const1_addr
, -1, executable_offset
);
918 sljit_set_const(const2_addr
, word_value2
, executable_offset
);
919 sljit_set_const(const3_addr
, (sljit_sw
)0xbab0fea1, executable_offset
);
920 sljit_set_const(const4_addr
, -60089, executable_offset
);
922 FAILED(code
.func1((sljit_sw
)&buf
) != -60089, "test11 case 5 failed\n");
923 FAILED(buf
[0] != -1, "test11 case 6 failed\n");
924 FAILED(buf
[1] != word_value2
, "test11 case 7 failed\n");
925 FAILED(buf
[2] != (sljit_sw
)0xbab0fea1, "test11 case 8 failed\n");
927 sljit_free_code(code
.code
, NULL
);
931 static void test12(void)
933 /* Test rewriteable jumps. */
934 executable_code code
;
935 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
936 struct sljit_label
*label1
;
937 struct sljit_label
*label2
;
938 struct sljit_label
*label3
;
939 struct sljit_jump
*jump1
;
940 struct sljit_jump
*jump2
;
941 struct sljit_jump
*jump3
;
942 sljit_sw executable_offset
;
945 sljit_uw label1_addr
;
946 sljit_uw label2_addr
;
950 printf("Run test12\n");
952 FAILED(!compiler
, "cannot create compiler\n");
955 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, W
), 3, 2, 0, 0, 0);
956 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_S1
, 0, SLJIT_IMM
, 10);
957 jump1
= sljit_emit_jump(compiler
, SLJIT_REWRITABLE_JUMP
| SLJIT_SIG_GREATER
);
958 /* Default handler. */
959 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 5);
960 jump2
= sljit_emit_jump(compiler
, SLJIT_JUMP
);
962 value
= sljit_alloc_memory(compiler
, 15);
965 SLJIT_ASSERT(!((sljit_sw
)value
& ((sljit_sw
)sizeof(sljit_sw
) - 1)));
966 memset(value
, 255, 15);
970 label1
= sljit_emit_label(compiler
);
971 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
972 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 6);
973 jump3
= sljit_emit_jump(compiler
, SLJIT_JUMP
);
975 label2
= sljit_emit_label(compiler
);
976 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
977 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 7);
979 label3
= sljit_emit_label(compiler
);
980 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
981 sljit_set_label(jump2
, label3
);
982 sljit_set_label(jump3
, label3
);
983 /* By default, set to handler 1. */
984 sljit_set_label(jump1
, label1
);
985 sljit_emit_return_void(compiler
);
987 value
= sljit_alloc_memory(compiler
, 8);
990 SLJIT_ASSERT(!((sljit_sw
)value
& ((sljit_sw
)sizeof(sljit_sw
) - 1)));
991 memset(value
, 255, 8);
994 code
.code
= sljit_generate_code(compiler
);
996 executable_offset
= sljit_get_executable_offset(compiler
);
997 jump1_addr
= sljit_get_jump_addr(jump1
);
998 label1_addr
= sljit_get_label_addr(label1
);
999 label2_addr
= sljit_get_label_addr(label2
);
1000 sljit_free_compiler(compiler
);
1002 code
.func2((sljit_sw
)&buf
, 4);
1003 FAILED(buf
[0] != 5, "test12 case 1 failed\n");
1005 code
.func2((sljit_sw
)&buf
, 11);
1006 FAILED(buf
[0] != 6, "test12 case 2 failed\n");
1008 sljit_set_jump_addr(jump1_addr
, label2_addr
, executable_offset
);
1009 code
.func2((sljit_sw
)&buf
, 12);
1010 FAILED(buf
[0] != 7, "test12 case 3 failed\n");
1012 sljit_set_jump_addr(jump1_addr
, label1_addr
, executable_offset
);
1013 code
.func2((sljit_sw
)&buf
, 13);
1014 FAILED(buf
[0] != 6, "test12 case 4 failed\n");
1016 sljit_free_code(code
.code
, NULL
);
1020 static void test13(void)
1022 /* Test fpu monadic functions. */
1023 executable_code code
;
1024 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1029 printf("Run test13\n");
1031 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
1033 printf("no fpu available, test13 skipped\n");
1036 sljit_free_compiler(compiler
);
1040 FAILED(!compiler
, "cannot create compiler\n");
1056 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 3, 2, 6, 0, 0);
1057 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&buf
[2], SLJIT_MEM0(), (sljit_sw
)&buf
[1]);
1058 sljit_emit_fop1(compiler
, SLJIT_ABS_F64
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1059 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
1060 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2 * sizeof(sljit_f64
));
1061 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 0);
1062 sljit_emit_fop1(compiler
, SLJIT_NEG_F64
, SLJIT_FR2
, 0, SLJIT_FR0
, 0);
1063 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_FR2
, 0);
1064 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&buf
[4], SLJIT_FR3
, 0);
1065 sljit_emit_fop1(compiler
, SLJIT_ABS_F64
, SLJIT_FR4
, 0, SLJIT_FR1
, 0);
1066 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f64
), SLJIT_FR4
, 0);
1067 sljit_emit_fop1(compiler
, SLJIT_NEG_F64
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
), SLJIT_FR4
, 0);
1069 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
1070 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_GREATER_F
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1071 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_GREATER_F64
);
1072 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_GREATER_F
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
), SLJIT_FR5
, 0);
1073 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
), SLJIT_GREATER_F64
);
1074 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_FR5
, 0);
1075 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR1
, 0);
1076 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
), SLJIT_EQUAL_F64
);
1077 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_LESS_F
, SLJIT_FR1
, 0, SLJIT_FR1
, 0);
1078 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
), SLJIT_LESS_F64
);
1079 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1080 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_EQUAL_F64
);
1081 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_NOT_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1082 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_NOT_EQUAL_F64
);
1084 sljit_emit_return_void(compiler
);
1086 code
.code
= sljit_generate_code(compiler
);
1088 sljit_free_compiler(compiler
);
1090 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&buf2
);
1091 FAILED(buf
[2] != -4.5, "test13 case 1 failed\n");
1092 FAILED(buf
[3] != 4.5, "test13 case 2 failed\n");
1093 FAILED(buf
[4] != -7.75, "test13 case 3 failed\n");
1094 FAILED(buf
[5] != 4.5, "test13 case 4 failed\n");
1095 FAILED(buf
[6] != -4.5, "test13 case 5 failed\n");
1097 FAILED(buf2
[0] != 1, "test13 case 6 failed\n");
1098 FAILED(buf2
[1] != 0, "test13 case 7 failed\n");
1099 FAILED(buf2
[2] != 1, "test13 case 8 failed\n");
1100 FAILED(buf2
[3] != 0, "test13 case 9 failed\n");
1101 FAILED(buf2
[4] != 0, "test13 case 10 failed\n");
1102 FAILED(buf2
[5] != 1, "test13 case 11 failed\n");
1104 sljit_free_code(code
.code
, NULL
);
1108 static void test14(void)
1110 /* Test fpu diadic functions. */
1111 executable_code code
;
1112 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1116 printf("Run test14\n");
1118 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
1120 printf("no fpu available, test14 skipped\n");
1123 sljit_free_compiler(compiler
);
1142 FAILED(!compiler
, "cannot create compiler\n");
1143 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 6, 0, 0);
1146 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_f64
));
1147 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1148 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2);
1149 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);
1150 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_FR1
, 0);
1151 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR1
, 0, SLJIT_FR0
, 0, SLJIT_FR1
, 0);
1152 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 4, SLJIT_FR0
, 0);
1153 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 5, SLJIT_FR1
, 0);
1156 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
1157 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2);
1158 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 2);
1159 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
);
1160 sljit_emit_fop2(compiler
, SLJIT_SUB_F64
, SLJIT_FR2
, 0, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2);
1161 sljit_emit_fop2(compiler
, SLJIT_SUB_F64
, SLJIT_FR3
, 0, SLJIT_FR2
, 0, SLJIT_FR3
, 0);
1162 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 7, SLJIT_FR2
, 0);
1163 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 8, SLJIT_FR3
, 0);
1166 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
1167 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);
1168 sljit_emit_fop2(compiler
, SLJIT_MUL_F64
, SLJIT_FR1
, 0, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
1169 sljit_emit_fop2(compiler
, SLJIT_MUL_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2, SLJIT_FR2
, 0);
1170 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 10, SLJIT_FR1
, 0);
1171 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 11, SLJIT_FR5
, 0);
1174 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 12);
1175 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 13);
1176 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR4
, 0, SLJIT_FR5
, 0);
1177 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);
1178 sljit_emit_fop2(compiler
, SLJIT_DIV_F64
, SLJIT_FR5
, 0, SLJIT_FR5
, 0, SLJIT_FR1
, 0);
1179 sljit_emit_fop2(compiler
, SLJIT_DIV_F64
, SLJIT_FR4
, 0, SLJIT_FR1
, 0, SLJIT_FR4
, 0);
1180 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 13, SLJIT_FR5
, 0);
1181 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 14, SLJIT_FR4
, 0);
1183 sljit_emit_return_void(compiler
);
1185 code
.code
= sljit_generate_code(compiler
);
1187 sljit_free_compiler(compiler
);
1189 code
.func1((sljit_sw
)&buf
);
1190 FAILED(buf
[3] != 10.75, "test14 case 1 failed\n");
1191 FAILED(buf
[4] != 5.25, "test14 case 2 failed\n");
1192 FAILED(buf
[5] != 7.0, "test14 case 3 failed\n");
1193 FAILED(buf
[6] != 0.0, "test14 case 4 failed\n");
1194 FAILED(buf
[7] != 5.5, "test14 case 5 failed\n");
1195 FAILED(buf
[8] != 3.75, "test14 case 6 failed\n");
1196 FAILED(buf
[9] != 24.5, "test14 case 7 failed\n");
1197 FAILED(buf
[10] != 38.5, "test14 case 8 failed\n");
1198 FAILED(buf
[11] != 9.625, "test14 case 9 failed\n");
1199 FAILED(buf
[12] != 2.0, "test14 case 10 failed\n");
1200 FAILED(buf
[13] != 2.0, "test14 case 11 failed\n");
1201 FAILED(buf
[14] != 0.5, "test14 case 12 failed\n");
1203 sljit_free_code(code
.code
, NULL
);
1207 static sljit_sw SLJIT_FUNC
func(sljit_sw a
, sljit_sw b
, sljit_sw c
)
1209 return a
+ b
+ c
+ 5;
1212 static void test15(void)
1214 /* Test function call. */
1215 executable_code code
;
1216 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1217 struct sljit_jump
* jump
= NULL
;
1221 printf("Run test15\n");
1223 FAILED(!compiler
, "cannot create compiler\n");
1230 buf
[6] = SLJIT_FUNC_ADDR(func
);
1232 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 4, 1, 0, 0, 0);
1234 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
1235 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 7);
1236 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -3);
1237 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(func
));
1238 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_RETURN_REG
, 0);
1240 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -5);
1241 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -10);
1242 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2);
1243 jump
= sljit_emit_call(compiler
, SLJIT_CALL
| SLJIT_REWRITABLE_JUMP
, SLJIT_ARGS3(W
, W
, W
, W
));
1244 sljit_set_target(jump
, (sljit_uw
)-1);
1245 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1247 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(func
));
1248 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 40);
1249 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -3);
1250 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_R0
, 0);
1251 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1253 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -60);
1254 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(func
));
1255 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -30);
1256 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_R1
, 0);
1257 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1259 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 10);
1260 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 16);
1261 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(func
));
1262 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_R2
, 0);
1263 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1265 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 100);
1266 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 110);
1267 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 120);
1268 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(func
));
1269 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_R3
, 0);
1270 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1272 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -10);
1273 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -16);
1274 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 6);
1275 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
));
1276 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1278 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1280 code
.code
= sljit_generate_code(compiler
);
1282 sljit_set_jump_addr(sljit_get_jump_addr(jump
), SLJIT_FUNC_UADDR(func
), sljit_get_executable_offset(compiler
));
1283 sljit_free_compiler(compiler
);
1285 FAILED(code
.func1((sljit_sw
)&buf
) != -15, "test15 case 1 failed\n");
1286 FAILED(buf
[0] != 14, "test15 case 2 failed\n");
1287 FAILED(buf
[1] != -8, "test15 case 3 failed\n");
1288 FAILED(buf
[2] != SLJIT_FUNC_ADDR(func
) + 42, "test15 case 4 failed\n");
1289 FAILED(buf
[3] != SLJIT_FUNC_ADDR(func
) - 85, "test15 case 5 failed\n");
1290 FAILED(buf
[4] != SLJIT_FUNC_ADDR(func
) + 31, "test15 case 6 failed\n");
1291 FAILED(buf
[5] != 335, "test15 case 7 failed\n");
1292 FAILED(buf
[6] != -15, "test15 case 8 failed\n");
1294 sljit_free_code(code
.code
, NULL
);
1298 static void test16(void)
1300 /* Ackermann benchmark. */
1301 executable_code code
;
1302 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1303 struct sljit_label
*entry
;
1304 struct sljit_label
*label
;
1305 struct sljit_jump
*jump
;
1306 struct sljit_jump
*jump1
;
1307 struct sljit_jump
*jump2
;
1310 printf("Run test16\n");
1312 FAILED(!compiler
, "cannot create compiler\n");
1314 entry
= sljit_emit_label(compiler
);
1315 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(W
, W
, W
), 3, 2, 0, 0, 0);
1317 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_S0
, 0, SLJIT_IMM
, 0);
1318 jump1
= sljit_emit_jump(compiler
, SLJIT_EQUAL
);
1320 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_S1
, 0, SLJIT_IMM
, 0);
1321 jump2
= sljit_emit_jump(compiler
, SLJIT_EQUAL
);
1324 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
1325 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 1);
1326 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS2(W
, W
, W
));
1327 sljit_set_label(jump
, entry
);
1329 /* Returns with Ack(x-1, Ack(x,y-1)). */
1330 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_RETURN_REG
, 0);
1331 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
1332 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS2(W
, W
, W
));
1333 sljit_set_label(jump
, entry
);
1334 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1336 /* Returns with y+1. */
1337 label
= sljit_emit_label(compiler
);
1338 sljit_set_label(jump1
, label
);
1339 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 1, SLJIT_S1
, 0);
1340 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1342 /* Returns with Ack(x-1,1) */
1343 label
= sljit_emit_label(compiler
);
1344 sljit_set_label(jump2
, label
);
1345 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
1346 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
1347 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS2(W
, W
, W
));
1348 sljit_set_label(jump
, entry
);
1349 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1351 code
.code
= sljit_generate_code(compiler
);
1353 sljit_free_compiler(compiler
);
1355 FAILED(code
.func2(3, 3) != 61, "test16 case 1 failed\n");
1356 /* For benchmarking. */
1357 /* FAILED(code.func2(3, 11) != 16381, "test16 case 1 failed\n"); */
1359 sljit_free_code(code
.code
, NULL
);
1363 static void test17(void)
1365 /* Test arm constant pool. */
1366 executable_code code
;
1367 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1372 printf("Run test17\n");
1374 FAILED(!compiler
, "cannot create compiler\n");
1376 for (i
= 0; i
< 5; i
++)
1379 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 0, 0, 0);
1380 for (i
= 0; i
<= 0xfff; i
++) {
1381 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x81818000 | i
);
1382 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x81818000 | i
);
1383 if ((i
& 0x3ff) == 0)
1384 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), (i
>> 10) * (sljit_sw
)sizeof(sljit_sw
), SLJIT_R0
, 0);
1386 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1387 sljit_emit_return_void(compiler
);
1389 code
.code
= sljit_generate_code(compiler
);
1391 sljit_free_compiler(compiler
);
1393 code
.func1((sljit_sw
)&buf
);
1394 FAILED((sljit_uw
)buf
[0] != 0x81818000, "test17 case 1 failed\n");
1395 FAILED((sljit_uw
)buf
[1] != 0x81818400, "test17 case 2 failed\n");
1396 FAILED((sljit_uw
)buf
[2] != 0x81818800, "test17 case 3 failed\n");
1397 FAILED((sljit_uw
)buf
[3] != 0x81818c00, "test17 case 4 failed\n");
1398 FAILED((sljit_uw
)buf
[4] != 0x81818fff, "test17 case 5 failed\n");
1400 sljit_free_code(code
.code
, NULL
);
1404 static void test18(void)
1407 executable_code code
;
1408 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1412 printf("Run test18\n");
1414 FAILED(!compiler
, "cannot create compiler\n");
1425 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1426 buf
[10] = SLJIT_W(1) << 32;
1431 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 2, 0, 0, 0);
1433 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1434 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, SLJIT_W(0x1122334455667788));
1435 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x1122334455667788));
1437 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(1000000000000));
1438 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(1000000000000));
1439 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_IMM
, SLJIT_W(5000000000000), SLJIT_R0
, 0);
1441 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x1108080808));
1442 sljit_emit_op2(compiler
, SLJIT_ADD32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x1120202020));
1444 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1108080808));
1445 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1120202020));
1446 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_ZERO
);
1447 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_S1
, 0);
1448 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
1449 sljit_emit_op2u(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1120202020));
1450 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_ZERO
);
1452 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1108080808));
1453 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x2208080808));
1454 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_LESS
);
1455 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
1456 sljit_emit_op2u(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1104040404));
1457 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_NOT_ZERO
);
1459 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
1460 sljit_emit_op2(compiler
, SLJIT_SHL32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_IMM
, SLJIT_W(0xffff0000), SLJIT_R0
, 0);
1462 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);
1464 /* 32 bit operations. */
1466 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0x11223344);
1467 sljit_emit_op2(compiler
, SLJIT_ADD32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 0x44332211);
1471 sljit_emit_return_void(compiler
);
1473 code
.code
= sljit_generate_code(compiler
);
1475 sljit_free_compiler(compiler
);
1477 code
.func1((sljit_sw
)&buf
);
1478 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1479 FAILED(buf
[0] != SLJIT_W(0x1122334455667788), "test18 case 1 failed\n");
1480 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1481 FAILED(buf
[1] != 0x55667788, "test18 case 2 failed\n");
1483 FAILED(buf
[1] != SLJIT_W(0x5566778800000000), "test18 case 2 failed\n");
1485 FAILED(buf
[2] != SLJIT_W(2000000000000), "test18 case 3 failed\n");
1486 FAILED(buf
[3] != SLJIT_W(4000000000000), "test18 case 4 failed\n");
1487 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1488 FAILED(buf
[4] != 0x28282828, "test18 case 5 failed\n");
1490 FAILED(buf
[4] != SLJIT_W(0x2828282800000000), "test18 case 5 failed\n");
1492 FAILED(buf
[5] != 0, "test18 case 6 failed\n");
1493 FAILED(buf
[6] != 1, "test18 case 7 failed\n");
1494 FAILED(buf
[7] != 1, "test18 case 8 failed\n");
1495 FAILED(buf
[8] != 0, "test18 case 9 failed\n");
1496 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1497 FAILED(buf
[9] != (sljit_sw
)0xfff00000, "test18 case 10 failed\n");
1498 FAILED(buf
[10] != (sljit_sw
)0xffffffff, "test18 case 11 failed\n");
1500 FAILED(buf
[9] != (sljit_sw
)SLJIT_W(0xfff0000000000000), "test18 case 10 failed\n");
1501 FAILED(buf
[10] != (sljit_sw
)SLJIT_W(0xffffffff00000000), "test18 case 11 failed\n");
1504 FAILED(buf
[0] != 0x11223344, "test18 case 1 failed\n");
1505 FAILED(buf
[1] != 0x44332211, "test18 case 2 failed\n");
1508 sljit_free_code(code
.code
, NULL
);
1512 static void test19(void)
1514 /* Test arm partial instruction caching. */
1515 executable_code code
;
1516 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1520 printf("Run test19\n");
1522 FAILED(!compiler
, "cannot create compiler\n");
1532 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 0, 0, 0);
1533 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
1534 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM0(), (sljit_sw
)&buf
[2], SLJIT_MEM0(), (sljit_sw
)&buf
[1], SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
1535 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
1536 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1537 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]);
1538 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_MEM0(), (sljit_sw
)&buf
[0], SLJIT_IMM
, 2);
1539 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
));
1540 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_IMM
, 10);
1541 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 7);
1542 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]);
1544 sljit_emit_return_void(compiler
);
1546 code
.code
= sljit_generate_code(compiler
);
1548 sljit_free_compiler(compiler
);
1550 code
.func1((sljit_sw
)&buf
);
1551 FAILED(buf
[0] != 10, "test19 case 1 failed\n");
1552 FAILED(buf
[1] != 4, "test19 case 2 failed\n");
1553 FAILED(buf
[2] != 14, "test19 case 3 failed\n");
1554 FAILED(buf
[3] != 14, "test19 case 4 failed\n");
1555 FAILED(buf
[4] != 8, "test19 case 5 failed\n");
1556 FAILED(buf
[5] != 6, "test19 case 6 failed\n");
1557 FAILED(buf
[6] != 12, "test19 case 7 failed\n");
1558 FAILED(buf
[7] != 10, "test19 case 8 failed\n");
1560 sljit_free_code(code
.code
, NULL
);
1564 static void test20(void)
1567 executable_code code
;
1568 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1569 struct sljit_jump
* jump
;
1570 struct sljit_label
* label
;
1572 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1573 sljit_sw offset_value
= SLJIT_W(0x1234567812345678);
1575 sljit_sw offset_value
= SLJIT_W(0x12345678);
1579 printf("Run test20\n");
1581 FAILED(!compiler
, "cannot create compiler\n");
1589 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 5, 5, 0, 0, 4 * sizeof(sljit_sw
));
1590 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
), SLJIT_MEM1(SLJIT_S0
), 0);
1591 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
));
1592 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -1);
1593 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, -1);
1594 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, -1);
1595 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_IMM
, -1);
1596 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
));
1597 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);
1598 sljit_get_local_base(compiler
, SLJIT_R0
, 0, -offset_value
);
1599 sljit_get_local_base(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, -0x1234);
1600 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
1601 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
));
1602 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_uw
));
1603 /* Dummy last instructions. */
1604 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 23);
1605 sljit_emit_label(compiler
);
1607 code
.code
= sljit_generate_code(compiler
);
1609 sljit_free_compiler(compiler
);
1611 FAILED(code
.func1((sljit_sw
)&buf
) != -12345, "test20 case 1 failed\n")
1613 FAILED(buf
[2] != 60, "test20 case 2 failed\n");
1614 FAILED(buf
[3] != 17, "test20 case 3 failed\n");
1615 FAILED(buf
[4] != 7, "test20 case 4 failed\n");
1617 sljit_free_code(code
.code
, NULL
);
1619 compiler
= sljit_create_compiler(NULL
, NULL
);
1620 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(W
, W
, W
, W
), 3, 3, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
1622 sljit_get_local_base(compiler
, SLJIT_R0
, 0, SLJIT_MAX_LOCAL_SIZE
- sizeof(sljit_sw
));
1623 sljit_get_local_base(compiler
, SLJIT_R1
, 0, -(sljit_sw
)sizeof(sljit_sw
));
1624 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -1);
1625 label
= sljit_emit_label(compiler
);
1626 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1627 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0, SLJIT_R2
, 0);
1628 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R0
, 0);
1629 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_EQUAL
);
1630 sljit_set_label(jump
, label
);
1632 /* Saved registers should keep their value. */
1633 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_S1
, 0);
1634 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_S2
, 0);
1635 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
1637 code
.code
= sljit_generate_code(compiler
);
1639 sljit_free_compiler(compiler
);
1641 FAILED(code
.func3(1234, 5678, 9012) != 15924, "test20 case 5 failed\n");
1643 sljit_free_code(code
.code
, NULL
);
1647 static void test21(void)
1649 /* Test set context. The parts of the jit code can be separated in the memory. */
1650 executable_code code1
;
1651 executable_code code2
;
1652 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1653 struct sljit_jump
* jump
= NULL
;
1655 sljit_sw executable_offset
;
1659 printf("Run test21\n");
1661 FAILED(!compiler
, "cannot create compiler\n");
1667 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 2, 0, 0, 2 * sizeof(sljit_sw
));
1669 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 10);
1670 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_SP
), 0);
1672 jump
= sljit_emit_jump(compiler
, SLJIT_JUMP
| SLJIT_REWRITABLE_JUMP
);
1673 sljit_set_target(jump
, 0);
1675 code1
.code
= sljit_generate_code(compiler
);
1678 executable_offset
= sljit_get_executable_offset(compiler
);
1679 addr
= sljit_get_jump_addr(jump
);
1681 sljit_free_compiler(compiler
);
1683 compiler
= sljit_create_compiler(NULL
, NULL
);
1684 FAILED(!compiler
, "cannot create compiler\n");
1686 /* Other part of the jit code. */
1687 sljit_set_context(compiler
, 0, 1, 3, 2, 0, 0, 2 * sizeof(sljit_sw
));
1689 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
1690 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_SP
), 0);
1691 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_MEM1(SLJIT_SP
), 0);
1692 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_sw
));
1694 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1696 code2
.code
= sljit_generate_code(compiler
);
1698 sljit_free_compiler(compiler
);
1700 sljit_set_jump_addr(addr
, SLJIT_FUNC_UADDR(code2
.code
), executable_offset
);
1702 FAILED(code1
.func1((sljit_sw
)&buf
) != 19, "test21 case 1 failed\n");
1703 FAILED(buf
[2] != -16, "test21 case 2 failed\n");
1704 FAILED(buf
[3] != 100, "test21 case 3 failed\n");
1706 sljit_free_code(code1
.code
, NULL
);
1707 sljit_free_code(code2
.code
, NULL
);
1711 static void test22(void)
1713 /* Test simple byte and half-int data transfers. */
1714 executable_code code
;
1715 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1721 printf("Run test22\n");
1723 FAILED(!compiler
, "cannot create compiler\n");
1743 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 3, 3, 0, 0, 0);
1745 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, -13);
1746 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s16
), SLJIT_IMM
, 0x1234);
1747 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_s16
));
1748 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
1749 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s16
));
1750 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s16
), SLJIT_MEM1(SLJIT_S1
), -(sljit_sw
)sizeof(sljit_s16
));
1751 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xff0000 + 8000);
1752 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 2);
1753 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R1
), 1, SLJIT_R0
, 0);
1754 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0x1234 - 3 * sizeof(sljit_s16
));
1755 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R2
), 0x1234, SLJIT_IMM
, -9317);
1756 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0x1234 + 4 * sizeof(sljit_s16
));
1757 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R2
), -0x1234, SLJIT_IMM
, -9317);
1758 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0x12348 - 5 * sizeof(sljit_s16
));
1759 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R2
), 0x12348, SLJIT_IMM
, -8888);
1760 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0x12348 + 6 * sizeof(sljit_s16
));
1761 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R2
), -0x12348, SLJIT_IMM
, -8888);
1763 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM1(SLJIT_S2
), 0, SLJIT_IMM
, -45);
1764 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_s8
), SLJIT_IMM
, 0x12);
1765 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4 * sizeof(sljit_s8
));
1766 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_s8
));
1767 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_S1
, 0, SLJIT_R1
, 0);
1768 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_S1
, 0, SLJIT_S1
, 0);
1769 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R2
, 0, SLJIT_S1
, 0);
1770 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R2
, 0);
1771 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S2
), 3 * sizeof(sljit_s8
), SLJIT_S1
, 0);
1772 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM2(SLJIT_S2
, SLJIT_R0
), 0, SLJIT_R0
, 0);
1773 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
1774 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
1775 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1776 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
1777 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
1778 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1780 sljit_emit_return_void(compiler
);
1782 code
.code
= sljit_generate_code(compiler
);
1784 sljit_free_compiler(compiler
);
1786 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&sbuf
, (sljit_sw
)&bbuf
);
1787 FAILED(buf
[0] != -9, "test22 case 1 failed\n");
1788 FAILED(buf
[1] != -56, "test22 case 2 failed\n");
1789 FAILED(buf
[2] != 0, "test22 case 3 failed\n");
1790 FAILED(buf
[3] != 0, "test22 case 4 failed\n");
1792 FAILED(sbuf
[0] != -13, "test22 case 5 failed\n");
1793 FAILED(sbuf
[1] != 0x1234, "test22 case 6 failed\n");
1794 FAILED(sbuf
[3] != 0x1234, "test22 case 7 failed\n");
1795 FAILED(sbuf
[4] != 8000, "test22 case 8 failed\n");
1796 FAILED(sbuf
[5] != -9317, "test22 case 9 failed\n");
1797 FAILED(sbuf
[6] != -9317, "test22 case 10 failed\n");
1798 FAILED(sbuf
[7] != -8888, "test22 case 11 failed\n");
1799 FAILED(sbuf
[8] != -8888, "test22 case 12 failed\n");
1801 FAILED(bbuf
[0] != -45, "test22 case 13 failed\n");
1802 FAILED(bbuf
[1] != 0x12, "test22 case 14 failed\n");
1803 FAILED(bbuf
[3] != -56, "test22 case 15 failed\n");
1804 FAILED(bbuf
[4] != 4, "test22 case 16 failed\n");
1806 sljit_free_code(code
.code
, NULL
);
1810 static void test23(void)
1812 /* Test 32 bit / 64 bit signed / unsigned int transfer and conversion.
1813 This test has do real things on 64 bit systems, but works on 32 bit systems as well. */
1814 executable_code code
;
1815 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1820 sljit_u8 asbytes
[4];
1822 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1823 sljit_sw garbage
= SLJIT_W(0x1234567812345678);
1825 sljit_sw garbage
= 0x12345678;
1829 printf("Run test23\n");
1831 FAILED(!compiler
, "cannot create compiler\n");
1848 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(W
, P
, P
), 3, 3, 0, 0, 0);
1849 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, 34567);
1850 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
1851 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), 0, SLJIT_IMM
, -7654);
1852 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, garbage
);
1853 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_s32
));
1854 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
1855 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, garbage
);
1856 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_s32
));
1857 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
1858 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, garbage
);
1859 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_s32
));
1860 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
1861 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1862 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x0f00f00);
1863 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x7777);
1864 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0x7777 + 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1865 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x7777);
1866 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), -0x7777 + 4 * (sljit_sw
)sizeof(sljit_sw
), SLJIT_R0
, 0);
1867 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 5 * sizeof(sljit_sw
));
1868 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 1);
1869 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R1
), 0, SLJIT_IMM
, 16);
1870 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
1871 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1, SLJIT_IMM
, 64, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1);
1872 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)&buf
[7], SLJIT_IMM
, 0x123456);
1873 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&buf
[6], SLJIT_MEM0(), (sljit_sw
)&buf
[7]);
1874 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 5 * sizeof(sljit_sw
));
1875 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 2 * sizeof(sljit_sw
), SLJIT_R1
, 0);
1876 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 7 * sizeof(sljit_sw
));
1877 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R2
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 1);
1878 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_MEM2(SLJIT_R2
, SLJIT_R2
), 0);
1879 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[8] - 0x12340);
1880 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0x12340, SLJIT_R2
, 0);
1881 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_R0
), 0x12340, SLJIT_MEM1(SLJIT_R2
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 6);
1882 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_s32
), SLJIT_IMM
, 0x12345678);
1883 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x2bd700 | 243);
1884 sljit_emit_return(compiler
, SLJIT_MOV_S8
, SLJIT_R1
, 0);
1886 code
.code
= sljit_generate_code(compiler
);
1888 sljit_free_compiler(compiler
);
1890 FAILED(code
.func2((sljit_sw
)&buf
, (sljit_sw
)&ibuf
) != -13, "test23 case 1 failed\n");
1891 FAILED(buf
[0] != -5791, "test23 case 2 failed\n");
1892 FAILED(buf
[1] != 43579, "test23 case 3 failed\n");
1893 FAILED(buf
[2] != 658923, "test23 case 4 failed\n");
1894 FAILED(buf
[3] != 0x0f00f00, "test23 case 5 failed\n");
1895 FAILED(buf
[4] != 0x0f00f00, "test23 case 6 failed\n");
1896 FAILED(buf
[5] != 80, "test23 case 7 failed\n");
1897 FAILED(buf
[6] != 0x123456, "test23 case 8 failed\n");
1898 FAILED(buf
[7] != (sljit_sw
)&buf
[5], "test23 case 9 failed\n");
1899 FAILED(buf
[8] != (sljit_sw
)&buf
[5] + 6, "test23 case 10 failed\n");
1901 FAILED(ibuf
[0] != 34567, "test23 case 11 failed\n");
1902 FAILED(ibuf
[1] != -7654, "test23 case 12 failed\n");
1904 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1905 FAILED(u
.asbytes
[0] != 0x78, "test23 case 13 failed\n");
1906 FAILED(u
.asbytes
[1] != 0x56, "test23 case 14 failed\n");
1907 FAILED(u
.asbytes
[2] != 0x34, "test23 case 15 failed\n");
1908 FAILED(u
.asbytes
[3] != 0x12, "test23 case 16 failed\n");
1910 FAILED(u
.asbytes
[0] != 0x12, "test23 case 13 failed\n");
1911 FAILED(u
.asbytes
[1] != 0x34, "test23 case 14 failed\n");
1912 FAILED(u
.asbytes
[2] != 0x56, "test23 case 15 failed\n");
1913 FAILED(u
.asbytes
[3] != 0x78, "test23 case 16 failed\n");
1916 sljit_free_code(code
.code
, NULL
);
1920 static void test24(void)
1922 /* Some complicated addressing modes. */
1923 executable_code code
;
1924 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1930 printf("Run test24\n");
1932 FAILED(!compiler
, "cannot create compiler\n");
1958 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 3, 3, 0, 0, 0);
1960 /* Nothing should be updated. */
1961 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM0(), (sljit_sw
)&sbuf
[1], SLJIT_MEM0(), (sljit_sw
)&sbuf
[0]);
1962 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM0(), (sljit_sw
)&bbuf
[1], SLJIT_MEM0(), (sljit_sw
)&bbuf
[0]);
1963 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
1964 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), 1, SLJIT_MEM0(), (sljit_sw
)&sbuf
[3]);
1965 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[0]);
1966 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1967 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2);
1968 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);
1969 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_s8
));
1970 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&bbuf
[1], SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&bbuf
[2]);
1972 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_s16
));
1973 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R1
), (sljit_sw
)&sbuf
[3], SLJIT_R1
, 0);
1975 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
1976 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
);
1977 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
1978 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_S0
, 0);
1979 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
);
1981 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 9 * sizeof(sljit_sw
));
1982 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 4 * sizeof(sljit_sw
));
1983 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -(4 << SLJIT_WORD_SHIFT
));
1984 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R2
), 0, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
1986 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
- 0x7fff8000 + 6 * (sljit_sw
)sizeof(sljit_sw
));
1987 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 952467);
1988 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0x7fff8000, SLJIT_R1
, 0);
1989 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0x7fff8000 + sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_R0
), 0x7fff8000);
1991 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
+ 0x7fff7fff + 6 * (sljit_sw
)sizeof(sljit_sw
));
1992 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);
1993 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
- 0x7fff7ffe + 3 * (sljit_sw
)sizeof(sljit_s8
));
1994 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM1(SLJIT_R0
), 0x7fff7fff, SLJIT_MEM1(SLJIT_R0
), 0x7fff7ffe);
1995 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
+ 0x7fff7fff + 5 * (sljit_sw
)sizeof(sljit_s8
));
1996 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM1(SLJIT_R0
), -0x7fff7fff, SLJIT_MEM1(SLJIT_R0
), -0x7fff8000);
1997 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1998 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
- SLJIT_W(0x123456123456));
1999 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
- SLJIT_W(0x123456123456));
2000 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));
2003 sljit_emit_return_void(compiler
);
2005 code
.code
= sljit_generate_code(compiler
);
2007 sljit_free_compiler(compiler
);
2009 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&sbuf
, (sljit_sw
)&bbuf
);
2010 FAILED(buf
[2] != 176366, "test24 case 1 failed\n");
2011 FAILED(buf
[3] != 64, "test24 case 2 failed\n");
2012 FAILED(buf
[4] != -100, "test24 case 3 failed\n");
2013 FAILED(buf
[5] != 100567, "test24 case 4 failed\n");
2014 FAILED(buf
[6] != 952467, "test24 case 5 failed\n");
2015 FAILED(buf
[7] != 952467, "test24 case 6 failed\n");
2016 FAILED(buf
[8] != 952467 * 2, "test24 case 7 failed\n");
2018 FAILED(sbuf
[1] != 30000, "test24 case 8 failed\n");
2019 FAILED(sbuf
[2] != -12345, "test24 case 9 failed\n");
2020 FAILED(sbuf
[4] != sizeof(sljit_s16
), "test24 case 10 failed\n");
2022 FAILED(bbuf
[1] != -128, "test24 case 11 failed\n");
2023 FAILED(bbuf
[2] != 99, "test24 case 12 failed\n");
2024 FAILED(bbuf
[4] != 99, "test24 case 13 failed\n");
2025 FAILED(bbuf
[5] != 99, "test24 case 14 failed\n");
2026 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2027 FAILED(bbuf
[6] != -128, "test24 case 15 failed\n");
2030 sljit_free_code(code
.code
, NULL
);
2034 static void test25(void)
2036 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2038 executable_code code
;
2039 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2043 printf("Run test25\n");
2045 FAILED(!compiler
, "cannot create compiler\n");
2061 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 0, 0, 0);
2063 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0);
2064 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 1 * sizeof(sljit_sw
), SLJIT_IMM
, 0x7fff);
2065 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_IMM
, -0x8000);
2066 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 0x7fffffff);
2067 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(-0x80000000));
2068 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x1234567887654321));
2069 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0xff80000000));
2070 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x3ff0000000));
2071 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_IMM
, (sljit_sw
)SLJIT_W(0xfffffff800100000));
2072 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_IMM
, (sljit_sw
)SLJIT_W(0xfffffff80010f000));
2073 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00000008001));
2074 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00080010000));
2075 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00080018001));
2076 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00ffff00000));
2078 sljit_emit_return_void(compiler
);
2080 code
.code
= sljit_generate_code(compiler
);
2082 sljit_free_compiler(compiler
);
2084 code
.func1((sljit_sw
)&buf
);
2085 FAILED(buf
[0] != 0, "test25 case 1 failed\n");
2086 FAILED(buf
[1] != 0x7fff, "test25 case 2 failed\n");
2087 FAILED(buf
[2] != -0x8000, "test25 case 3 failed\n");
2088 FAILED(buf
[3] != 0x7fffffff, "test25 case 4 failed\n");
2089 FAILED(buf
[4] != SLJIT_W(-0x80000000), "test25 case 5 failed\n");
2090 FAILED(buf
[5] != SLJIT_W(0x1234567887654321), "test25 case 6 failed\n");
2091 FAILED(buf
[6] != SLJIT_W(0xff80000000), "test25 case 7 failed\n");
2092 FAILED(buf
[7] != SLJIT_W(0x3ff0000000), "test25 case 8 failed\n");
2093 FAILED((sljit_uw
)buf
[8] != SLJIT_W(0xfffffff800100000), "test25 case 9 failed\n");
2094 FAILED((sljit_uw
)buf
[9] != SLJIT_W(0xfffffff80010f000), "test25 case 10 failed\n");
2095 FAILED(buf
[10] != SLJIT_W(0x07fff00000008001), "test25 case 11 failed\n");
2096 FAILED(buf
[11] != SLJIT_W(0x07fff00080010000), "test25 case 12 failed\n");
2097 FAILED(buf
[12] != SLJIT_W(0x07fff00080018001), "test25 case 13 failed\n");
2098 FAILED(buf
[13] != SLJIT_W(0x07fff00ffff00000), "test25 case 14 failed\n");
2100 sljit_free_code(code
.code
, NULL
);
2105 static void test26(void)
2107 /* Aligned access without aligned offsets. */
2108 executable_code code
;
2109 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2115 printf("Run test26\n");
2117 FAILED(!compiler
, "cannot create compiler\n");
2134 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 3, 3, 0, 0, 0);
2136 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 3);
2137 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 1);
2138 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), -3);
2139 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
) - 1, SLJIT_R0
, 0);
2140 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), -1);
2141 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) - 3, SLJIT_R0
, 0);
2143 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 100);
2144 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);
2145 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 100);
2146 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);
2148 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
2149 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 3);
2150 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f64
) - 3, SLJIT_MEM1(SLJIT_S2
), -3);
2151 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);
2152 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 2);
2153 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sizeof(sljit_f64
) * 3 - 4) >> 1);
2154 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 1);
2155 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);
2158 sljit_emit_return_void(compiler
);
2160 code
.code
= sljit_generate_code(compiler
);
2162 sljit_free_compiler(compiler
);
2164 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&ibuf
, (sljit_sw
)&dbuf
);
2166 FAILED(buf
[1] != -689, "test26 case 1 failed\n");
2167 FAILED(buf
[2] != -16, "test26 case 2 failed\n");
2168 FAILED(ibuf
[1] != -2789, "test26 case 3 failed\n");
2169 FAILED(ibuf
[2] != -18, "test26 case 4 failed\n");
2171 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
2172 FAILED(dbuf
[1] != 5.75, "test26 case 5 failed\n");
2173 FAILED(dbuf
[2] != 11.5, "test26 case 6 failed\n");
2174 FAILED(dbuf
[3] != -2.875, "test26 case 7 failed\n");
2177 sljit_free_code(code
.code
, NULL
);
2181 static void test27(void)
2183 #define SET_NEXT_BYTE(type) \
2184 cond_set(compiler, SLJIT_R2, 0, type); \
2185 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R2, 0); \
2186 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2187 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2190 #define RESULT(i) (3 - i)
2193 /* Playing with conditional flags. */
2194 executable_code code
;
2195 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2198 #ifdef SLJIT_PREF_SHIFT_REG
2199 sljit_s32 shift_reg
= SLJIT_PREF_SHIFT_REG
;
2201 sljit_s32 shift_reg
= SLJIT_R2
;
2204 SLJIT_ASSERT(shift_reg
>= SLJIT_R2
&& shift_reg
<= SLJIT_R3
);
2207 printf("Run test27\n");
2209 for (i
= 0; i
< sizeof(buf
); ++i
)
2212 FAILED(!compiler
, "cannot create compiler\n");
2214 /* 3 arguments passed, 3 arguments used. */
2215 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 4, 3, 0, 0, 0);
2217 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
2219 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1001);
2220 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 20);
2221 /* 0x100100000 on 64 bit machines, 0x100000 on 32 bit machines. */
2222 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x800000);
2223 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2224 sljit_emit_op0(compiler
, SLJIT_ENDBR
); /* ENDBR should keep the flags. */
2225 sljit_emit_op0(compiler
, SLJIT_NOP
); /* Nop should keep the flags. */
2226 SET_NEXT_BYTE(SLJIT_GREATER
);
2227 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2228 SET_NEXT_BYTE(SLJIT_LESS
);
2229 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2230 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
2231 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2232 sljit_emit_op0(compiler
, SLJIT_ENDBR
); /* ENDBR should keep the flags. */
2233 sljit_emit_op0(compiler
, SLJIT_NOP
); /* Nop should keep the flags. */
2234 SET_NEXT_BYTE(SLJIT_GREATER
);
2235 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2236 SET_NEXT_BYTE(SLJIT_LESS
);
2238 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1000);
2239 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 20);
2240 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x10);
2241 /* 0x100000010 on 64 bit machines, 0x10 on 32 bit machines. */
2242 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2243 SET_NEXT_BYTE(SLJIT_GREATER
);
2244 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2245 SET_NEXT_BYTE(SLJIT_LESS
);
2246 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2247 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2248 SET_NEXT_BYTE(SLJIT_GREATER
);
2249 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2250 SET_NEXT_BYTE(SLJIT_LESS
);
2252 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2253 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2254 /* 0xff..ff on all machines. */
2255 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2256 SET_NEXT_BYTE(SLJIT_LESS_EQUAL
);
2257 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2258 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL
);
2259 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R2
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -1);
2260 SET_NEXT_BYTE(SLJIT_SIG_GREATER
);
2261 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -1);
2262 SET_NEXT_BYTE(SLJIT_SIG_LESS
);
2263 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
2264 SET_NEXT_BYTE(SLJIT_EQUAL
);
2265 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
2266 SET_NEXT_BYTE(SLJIT_NOT_EQUAL
);
2267 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2268 SET_NEXT_BYTE(SLJIT_OVERFLOW
);
2269 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2270 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW
);
2271 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2272 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL
);
2273 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2274 SET_NEXT_BYTE(SLJIT_LESS_EQUAL
);
2275 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)((sljit_uw
)1 << ((8 * sizeof(sljit_uw
)) - 1)));
2276 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2277 SET_NEXT_BYTE(SLJIT_SIG_LESS
);
2278 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -1);
2279 SET_NEXT_BYTE(SLJIT_SIG_GREATER
);
2280 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2281 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -2);
2282 SET_NEXT_BYTE(SLJIT_SIG_GREATER_EQUAL
);
2283 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 2);
2284 SET_NEXT_BYTE(SLJIT_SIG_GREATER
);
2286 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x80000000);
2287 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 16);
2288 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 16);
2289 /* 0x80..0 on 64 bit machines, 0 on 32 bit machines. */
2290 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)0xffffffff);
2291 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2292 SET_NEXT_BYTE(SLJIT_OVERFLOW
);
2293 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2294 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW
);
2295 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2296 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
2297 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2298 SET_NEXT_BYTE(SLJIT_OVERFLOW
);
2299 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2300 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW
);
2302 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2303 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2304 sljit_emit_op2u(compiler
, SLJIT_SUBC
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2305 sljit_emit_op2(compiler
, SLJIT_SUBC
, SLJIT_R0
, 0, SLJIT_IMM
, 6, SLJIT_R0
, 0);
2306 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_R0
, 0);
2307 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
2309 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
2310 sljit_emit_op2u(compiler
, SLJIT_ADD
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2311 sljit_emit_op2u(compiler
, SLJIT_ADDC
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2312 sljit_emit_op2(compiler
, SLJIT_ADDC
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 9);
2313 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_R0
, 0);
2314 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
2316 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2317 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, (8 * sizeof(sljit_sw
)) - 1);
2318 sljit_emit_op2u(compiler
, SLJIT_ADD
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2319 SET_NEXT_BYTE(SLJIT_EQUAL
);
2320 sljit_emit_op2u(compiler
, SLJIT_ADD
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2321 SET_NEXT_BYTE(SLJIT_EQUAL
);
2323 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2324 sljit_emit_op2(compiler
, SLJIT_ASHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2325 SET_NEXT_BYTE(SLJIT_EQUAL
);
2326 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2327 sljit_emit_op2(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffffc0);
2328 SET_NEXT_BYTE(SLJIT_NOT_EQUAL
);
2329 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0);
2330 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2331 sljit_emit_op2(compiler
, SLJIT_ASHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, shift_reg
, 0);
2332 SET_NEXT_BYTE(SLJIT_EQUAL
);
2333 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0);
2334 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2335 sljit_emit_op2(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, shift_reg
, 0);
2336 SET_NEXT_BYTE(SLJIT_NOT_EQUAL
);
2338 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2339 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2340 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2341 sljit_emit_op2(compiler
, SLJIT_SUBC
| SLJIT_SET_CARRY
, SLJIT_R2
, 0, SLJIT_IMM
, 1, SLJIT_R0
, 0);
2342 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_R2
, 0);
2343 sljit_emit_op2u(compiler
, SLJIT_SUBC
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2344 sljit_emit_op2(compiler
, SLJIT_SUBC
, SLJIT_R2
, 0, SLJIT_IMM
, 1, SLJIT_R0
, 0);
2345 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 2, SLJIT_R2
, 0);
2346 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 2);
2348 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -34);
2349 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1234);
2350 SET_NEXT_BYTE(SLJIT_LESS
);
2351 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1234);
2352 SET_NEXT_BYTE(SLJIT_SIG_LESS
);
2353 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2354 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x12300000000) - 43);
2356 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, -43);
2358 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -96);
2359 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2360 SET_NEXT_BYTE(SLJIT_LESS
);
2361 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2362 SET_NEXT_BYTE(SLJIT_SIG_GREATER
);
2364 sljit_emit_return_void(compiler
);
2366 code
.code
= sljit_generate_code(compiler
);
2368 sljit_free_compiler(compiler
);
2370 code
.func1((sljit_sw
)&buf
);
2372 FAILED(buf
[0] != RESULT(1), "test27 case 1 failed\n");
2373 FAILED(buf
[1] != RESULT(2), "test27 case 2 failed\n");
2374 FAILED(buf
[2] != 2, "test27 case 3 failed\n");
2375 FAILED(buf
[3] != 1, "test27 case 4 failed\n");
2376 FAILED(buf
[4] != RESULT(1), "test27 case 5 failed\n");
2377 FAILED(buf
[5] != RESULT(2), "test27 case 6 failed\n");
2378 FAILED(buf
[6] != 2, "test27 case 7 failed\n");
2379 FAILED(buf
[7] != 1, "test27 case 8 failed\n");
2381 FAILED(buf
[8] != 2, "test27 case 9 failed\n");
2382 FAILED(buf
[9] != 1, "test27 case 10 failed\n");
2383 FAILED(buf
[10] != 2, "test27 case 11 failed\n");
2384 FAILED(buf
[11] != 1, "test27 case 12 failed\n");
2385 FAILED(buf
[12] != 1, "test27 case 13 failed\n");
2386 FAILED(buf
[13] != 2, "test27 case 14 failed\n");
2387 FAILED(buf
[14] != 2, "test27 case 15 failed\n");
2388 FAILED(buf
[15] != 1, "test27 case 16 failed\n");
2389 FAILED(buf
[16] != 1, "test27 case 17 failed\n");
2390 FAILED(buf
[17] != 2, "test27 case 18 failed\n");
2391 FAILED(buf
[18] != 1, "test27 case 19 failed\n");
2392 FAILED(buf
[19] != 1, "test27 case 20 failed\n");
2393 FAILED(buf
[20] != 1, "test27 case 21 failed\n");
2394 FAILED(buf
[21] != 2, "test27 case 22 failed\n");
2396 FAILED(buf
[22] != RESULT(1), "test27 case 23 failed\n");
2397 FAILED(buf
[23] != RESULT(2), "test27 case 24 failed\n");
2398 FAILED(buf
[24] != 2, "test27 case 25 failed\n");
2399 FAILED(buf
[25] != 1, "test27 case 26 failed\n");
2401 FAILED(buf
[26] != 5, "test27 case 27 failed\n");
2402 FAILED(buf
[27] != 9, "test27 case 28 failed\n");
2404 FAILED(buf
[28] != 2, "test27 case 29 failed\n");
2405 FAILED(buf
[29] != 1, "test27 case 30 failed\n");
2407 FAILED(buf
[30] != 1, "test27 case 31 failed\n");
2408 FAILED(buf
[31] != 1, "test27 case 32 failed\n");
2409 FAILED(buf
[32] != 1, "test27 case 33 failed\n");
2410 FAILED(buf
[33] != 1, "test27 case 34 failed\n");
2412 FAILED(buf
[34] != 1, "test27 case 35 failed\n");
2413 FAILED(buf
[35] != 0, "test27 case 36 failed\n");
2415 FAILED(buf
[36] != 2, "test27 case 37 failed\n");
2416 FAILED(buf
[37] != 1, "test27 case 38 failed\n");
2417 FAILED(buf
[38] != 2, "test27 case 39 failed\n");
2418 FAILED(buf
[39] != 1, "test27 case 40 failed\n");
2419 FAILED(buf
[40] != 10, "test27 case 41 failed\n");
2421 sljit_free_code(code
.code
, NULL
);
2423 #undef SET_NEXT_BYTE
2427 static void test28(void)
2430 executable_code code
;
2431 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2432 struct sljit_const
* const1
= NULL
;
2433 struct sljit_label
* label
= NULL
;
2434 sljit_uw label_addr
= 0;
2438 printf("Run test28\n");
2440 FAILED(!compiler
, "cannot create compiler\n");
2448 FAILED(!compiler
, "cannot create compiler\n");
2449 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 5, 5, 0, 0, 0);
2450 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -234);
2451 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
2452 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_S3
, 0, SLJIT_R3
, 0, SLJIT_R4
, 0);
2453 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_S3
, 0);
2454 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_S3
, 0, SLJIT_IMM
, 0);
2455 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_NOT_ZERO
);
2456 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_S3
, 0);
2457 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
));
2458 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S4
, 0, SLJIT_S4
, 0, SLJIT_R4
, 0);
2459 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_S4
, 0);
2461 const1
= sljit_emit_const(compiler
, SLJIT_S3
, 0, 0);
2462 sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_S3
, 0);
2463 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S3
, 0, SLJIT_S3
, 0, SLJIT_IMM
, 100);
2464 label
= sljit_emit_label(compiler
);
2465 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
2466 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_S3
, 0);
2468 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R4
, 0);
2470 code
.code
= sljit_generate_code(compiler
);
2473 label_addr
= sljit_get_label_addr(label
);
2474 sljit_set_const(sljit_get_const_addr(const1
), (sljit_sw
)label_addr
, sljit_get_executable_offset(compiler
));
2476 sljit_free_compiler(compiler
);
2478 FAILED(code
.func1((sljit_sw
)&buf
) != 8, "test28 case 1 failed\n");
2479 FAILED(buf
[1] != -1872, "test28 case 2 failed\n");
2480 FAILED(buf
[2] != 1, "test28 case 3 failed\n");
2481 FAILED(buf
[3] != 2, "test28 case 4 failed\n");
2482 FAILED(buf
[4] != (sljit_sw
)label_addr
, "test28 case 5 failed\n");
2484 sljit_free_code(code
.code
, NULL
);
2488 static void test29(void)
2490 /* Test signed/unsigned bytes and halfs. */
2491 executable_code code
;
2492 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2497 printf("Run test29\n");
2499 for (i
= 0; i
< 25; i
++)
2502 FAILED(!compiler
, "cannot create compiler\n");
2503 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 5, 5, 0, 0, 0);
2505 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_IMM
, -187);
2506 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
2507 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_IMM
, -605);
2508 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2509 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R0
, 0, SLJIT_IMM
, -56);
2510 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2511 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R4
, 0, SLJIT_IMM
, 0xcde5);
2512 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2514 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_IMM
, -45896);
2515 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2516 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_IMM
, -1472797);
2517 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2518 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R0
, 0, SLJIT_IMM
, -12890);
2519 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2520 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R4
, 0, SLJIT_IMM
, 0x9cb0a6);
2521 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2523 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2524 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-3580429715));
2525 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2526 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-100722768662));
2527 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2528 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-1457052677972));
2529 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2530 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R4
, 0, SLJIT_IMM
, SLJIT_W(0xcef97a70b5));
2531 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2534 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -187);
2535 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2536 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2537 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -605);
2538 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_S2
, 0);
2539 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2540 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -56);
2541 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R0
, 0, SLJIT_R2
, 0);
2542 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2543 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0xcde5);
2544 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R4
, 0, SLJIT_R3
, 0);
2545 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2547 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -45896);
2548 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2549 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2550 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1472797);
2551 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_S2
, 0);
2552 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2553 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -12890);
2554 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R0
, 0, SLJIT_R2
, 0);
2555 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2556 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x9cb0a6);
2557 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R4
, 0, SLJIT_R3
, 0);
2558 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 19 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2560 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2561 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(-3580429715));
2562 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2563 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2564 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, SLJIT_W(-100722768662));
2565 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_S2
, 0);
2566 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 21 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2567 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, SLJIT_W(-1457052677972));
2568 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R2
, 0);
2569 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2570 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_W(0xcef97a70b5));
2571 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R4
, 0, SLJIT_R3
, 0);
2572 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 23 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2575 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, 0x9faa5);
2576 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_S2
, 0, SLJIT_S2
, 0);
2577 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 24 * sizeof(sljit_uw
), SLJIT_S2
, 0);
2579 sljit_emit_return_void(compiler
);
2581 code
.code
= sljit_generate_code(compiler
);
2583 sljit_free_compiler(compiler
);
2585 code
.func1((sljit_sw
)&buf
);
2586 FAILED(buf
[0] != 69, "test29 case 1 failed\n");
2587 FAILED(buf
[1] != -93, "test29 case 2 failed\n");
2588 FAILED(buf
[2] != 200, "test29 case 3 failed\n");
2589 FAILED(buf
[3] != 0xe5, "test29 case 4 failed\n");
2590 FAILED(buf
[4] != 19640, "test29 case 5 failed\n");
2591 FAILED(buf
[5] != -31005, "test29 case 6 failed\n");
2592 FAILED(buf
[6] != 52646, "test29 case 7 failed\n");
2593 FAILED(buf
[7] != 0xb0a6, "test29 case 8 failed\n");
2595 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2596 FAILED(buf
[8] != SLJIT_W(714537581), "test29 case 9 failed\n");
2597 FAILED(buf
[9] != SLJIT_W(-1938520854), "test29 case 10 failed\n");
2598 FAILED(buf
[10] != SLJIT_W(3236202668), "test29 case 11 failed\n");
2599 FAILED(buf
[11] != SLJIT_W(0xf97a70b5), "test29 case 12 failed\n");
2602 FAILED(buf
[12] != 69, "test29 case 13 failed\n");
2603 FAILED(buf
[13] != -93, "test29 case 14 failed\n");
2604 FAILED(buf
[14] != 200, "test29 case 15 failed\n");
2605 FAILED(buf
[15] != 0xe5, "test29 case 16 failed\n");
2606 FAILED(buf
[16] != 19640, "test29 case 17 failed\n");
2607 FAILED(buf
[17] != -31005, "test29 case 18 failed\n");
2608 FAILED(buf
[18] != 52646, "test29 case 19 failed\n");
2609 FAILED(buf
[19] != 0xb0a6, "test29 case 20 failed\n");
2611 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2612 FAILED(buf
[20] != SLJIT_W(714537581), "test29 case 21 failed\n");
2613 FAILED(buf
[21] != SLJIT_W(-1938520854), "test29 case 22 failed\n");
2614 FAILED(buf
[22] != SLJIT_W(3236202668), "test29 case 23 failed\n");
2615 FAILED(buf
[23] != SLJIT_W(0xf97a70b5), "test29 case 24 failed\n");
2618 FAILED(buf
[24] != -91, "test29 case 25 failed\n");
2620 sljit_free_code(code
.code
, NULL
);
2624 static void test30(void)
2626 /* Test unused results. */
2627 executable_code code
;
2628 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2632 printf("Run test30\n");
2634 FAILED(!compiler
, "cannot create compiler\n");
2636 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 5, 5, 0, 0, 0);
2638 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2639 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2640 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 1);
2641 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 1);
2642 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, 1);
2643 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2644 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S1
, 0, SLJIT_IMM
, SLJIT_W(-0x123ffffffff));
2646 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S1
, 0, SLJIT_IMM
, 1);
2648 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, 1);
2649 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, 1);
2650 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_IMM
, 1);
2652 /* Some calculations with unused results. */
2653 sljit_emit_op2u(compiler
, SLJIT_ADD
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
2654 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_GREATER_EQUAL
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
2655 sljit_emit_op2u(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_S0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
2656 sljit_emit_op2u(compiler
, SLJIT_SHL
| SLJIT_SET_Z
, SLJIT_S3
, 0, SLJIT_R2
, 0);
2657 sljit_emit_op2u(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 5);
2658 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0xff);
2660 /* Testing that any change happens. */
2661 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2662 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R2
, 0);
2663 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R3
, 0);
2664 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R4
, 0);
2665 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_S1
, 0, SLJIT_S1
, 0);
2666 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S1
, 0);
2667 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S2
, 0);
2668 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S3
, 0);
2669 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0, SLJIT_S4
, 0);
2671 sljit_emit_return_void(compiler
);
2673 code
.code
= sljit_generate_code(compiler
);
2675 sljit_free_compiler(compiler
);
2677 code
.func1((sljit_sw
)&buf
);
2678 FAILED(buf
[0] != 9, "test30 case 1 failed\n");
2680 sljit_free_code(code
.code
, NULL
);
2684 static void test31(void)
2686 /* Integer mul and set flags. */
2687 executable_code code
;
2688 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2691 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2692 sljit_sw big_word
= SLJIT_W(0x7fffffff00000000);
2693 sljit_sw big_word2
= SLJIT_W(0x7fffffff00000012);
2695 sljit_sw big_word
= 0x7fffffff;
2696 sljit_sw big_word2
= 0x00000012;
2700 printf("Run test31\n");
2702 for (i
= 0; i
< 12; i
++)
2705 FAILED(!compiler
, "cannot create compiler\n");
2707 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 5, 0, 0, 0);
2708 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
2709 sljit_emit_op2u(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_IMM
, -45);
2710 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_NOT_OVERFLOW
);
2711 sljit_emit_op2u(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_IMM
, -45);
2712 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_OVERFLOW
);
2714 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, big_word
);
2715 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, -2);
2716 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 33); /* Should not change flags. */
2717 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0); /* Should not change flags. */
2718 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
2719 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, -2);
2720 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_NOT_OVERFLOW
);
2722 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S3
, 0, SLJIT_IMM
, 0x3f6b0);
2723 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S4
, 0, SLJIT_IMM
, 0x2a783);
2724 sljit_emit_op2(compiler
, SLJIT_MUL32
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_S3
, 0, SLJIT_S4
, 0);
2725 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
2726 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R1
, 0);
2728 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, big_word2
);
2729 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_R1
, 0);
2730 sljit_emit_op2(compiler
, SLJIT_MUL32
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 23);
2731 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
2733 sljit_emit_op2u(compiler
, SLJIT_MUL32
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_IMM
, -23);
2734 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_NOT_OVERFLOW
);
2735 sljit_emit_op2u(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_IMM
, -23);
2736 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_NOT_OVERFLOW
);
2738 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 67);
2739 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -23);
2740 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R1
, 0);
2742 sljit_emit_return_void(compiler
);
2744 code
.code
= sljit_generate_code(compiler
);
2746 sljit_free_compiler(compiler
);
2748 code
.func1((sljit_sw
)&buf
);
2750 FAILED(buf
[0] != 1, "test31 case 1 failed\n");
2751 FAILED(buf
[1] != 2, "test31 case 2 failed\n");
2752 /* Qemu issues for 64 bit muls. */
2753 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2754 FAILED(buf
[2] != 1, "test31 case 3 failed\n");
2755 FAILED(buf
[3] != 2, "test31 case 4 failed\n");
2757 FAILED(buf
[4] != 1, "test31 case 5 failed\n");
2758 FAILED((buf
[5] & (sljit_sw
)0xffffffff) != (sljit_sw
)0x85540c10, "test31 case 6 failed\n");
2759 FAILED(buf
[6] != 2, "test31 case 7 failed\n");
2760 FAILED(buf
[7] != 1, "test31 case 8 failed\n");
2761 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2762 FAILED(buf
[8] != 1, "test31 case 9 failed\n");
2764 FAILED(buf
[9] != -1541, "test31 case 10 failed\n");
2766 sljit_free_code(code
.code
, NULL
);
2770 static void test32(void)
2772 /* Floating point set flags. */
2773 executable_code code
;
2774 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2787 printf("Run test32\n");
2789 for (i
= 0; i
< 16; i
++)
2793 dbuf
[0].u
.value1
= 0x7fffffff;
2794 dbuf
[0].u
.value2
= 0x7fffffff;
2795 dbuf
[1].u
.value1
= 0x7fffffff;
2796 dbuf
[1].u
.value2
= 0x7fffffff;
2797 dbuf
[2].value
= -13.0;
2798 dbuf
[3].value
= 27.0;
2800 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
2802 printf("no fpu available, test32 skipped\n");
2805 sljit_free_compiler(compiler
);
2809 FAILED(!compiler
, "cannot create compiler\n");
2810 SLJIT_ASSERT(sizeof(sljit_f64
) == 8 && sizeof(sljit_s32
) == 4 && sizeof(dbuf
[0]) == 8);
2812 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 1, 2, 4, 0, 0);
2814 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
2815 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED_F
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
2816 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f64
));
2817 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_UNORDERED_F64
);
2818 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_ORDERED_F
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
2819 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_ORDERED_F64
);
2821 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
));
2822 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2823 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_UNORDERED_F64
);
2824 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_ORDERED_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2825 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_ORDERED_F64
);
2826 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_LESS_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2827 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_LESS_F64
);
2828 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_GREATER_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2829 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_GREATER_EQUAL_F64
);
2830 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_GREATER_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2831 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_GREATER_F64
);
2832 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_LESS_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2833 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_LESS_EQUAL_F64
);
2834 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2835 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_EQUAL_F64
);
2836 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_NOT_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2837 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_NOT_EQUAL_F64
);
2839 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR3
, 0, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
));
2840 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED_F
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
));
2841 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_UNORDERED_F64
);
2842 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_EQUAL_F
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
));
2843 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_EQUAL_F64
);
2845 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_ORDERED_F
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
), SLJIT_FR0
, 0);
2846 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_ORDERED_F64
);
2848 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED_F
, SLJIT_FR3
, 0, SLJIT_FR2
, 0);
2849 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
2850 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_UNORDERED_F64
);
2852 sljit_emit_return_void(compiler
);
2854 code
.code
= sljit_generate_code(compiler
);
2856 sljit_free_compiler(compiler
);
2858 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&dbuf
);
2860 FAILED(buf
[0] != 1, "test32 case 1 failed\n");
2861 FAILED(buf
[1] != 2, "test32 case 2 failed\n");
2862 FAILED(buf
[2] != 2, "test32 case 3 failed\n");
2863 FAILED(buf
[3] != 1, "test32 case 4 failed\n");
2864 FAILED(buf
[4] != 1, "test32 case 5 failed\n");
2865 FAILED(buf
[5] != 2, "test32 case 6 failed\n");
2866 FAILED(buf
[6] != 2, "test32 case 7 failed\n");
2867 FAILED(buf
[7] != 1, "test32 case 8 failed\n");
2868 FAILED(buf
[8] != 2, "test32 case 9 failed\n");
2869 FAILED(buf
[9] != 1, "test32 case 10 failed\n");
2870 FAILED(buf
[10] != 2, "test32 case 11 failed\n");
2871 FAILED(buf
[11] != 1, "test32 case 12 failed\n");
2872 FAILED(buf
[12] != 2, "test32 case 13 failed\n");
2873 FAILED(buf
[13] != 1, "test32 case 14 failed\n");
2875 sljit_free_code(code
.code
, NULL
);
2879 static void test33(void)
2881 /* Test setting multiple flags. */
2882 executable_code code
;
2883 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2884 struct sljit_jump
* jump
;
2888 printf("Run test33\n");
2901 FAILED(!compiler
, "cannot create compiler\n");
2903 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 3, 0, 0, 0);
2905 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 20);
2906 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 10);
2907 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2908 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_ZERO
);
2909 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -10);
2910 jump
= sljit_emit_jump(compiler
, SLJIT_LESS
);
2911 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 11);
2912 sljit_set_label(jump
, sljit_emit_label(compiler
));
2914 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_SIG_GREATER
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2915 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_SIG_GREATER
);
2916 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 45);
2917 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_EQUAL
);
2918 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 55);
2919 sljit_set_label(jump
, sljit_emit_label(compiler
));
2921 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2922 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)SLJIT_W(0x8000000000000000));
2924 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)SLJIT_W(0x80000000));
2926 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2927 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2928 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, 33);
2929 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_OVERFLOW
);
2930 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_ZERO
);
2931 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, 13);
2932 sljit_set_label(jump
, sljit_emit_label(compiler
));
2934 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x80000000);
2935 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R0
, 0);
2936 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2937 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
2938 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_NOT_ZERO
);
2939 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, 78);
2940 jump
= sljit_emit_jump(compiler
, SLJIT_OVERFLOW
);
2941 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, 48);
2942 sljit_set_label(jump
, sljit_emit_label(compiler
));
2944 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2945 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)SLJIT_W(0x8000000000000000));
2947 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)SLJIT_W(0x80000000));
2949 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_R0
, 0);
2950 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2951 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_IMM
, 30);
2952 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_OVERFLOW
);
2953 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_IMM
, 50);
2954 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_ZERO
);
2955 sljit_set_label(jump
, sljit_emit_label(compiler
));
2957 sljit_emit_return_void(compiler
);
2959 code
.code
= sljit_generate_code(compiler
);
2961 sljit_free_compiler(compiler
);
2963 code
.func1((sljit_sw
)&buf
);
2965 FAILED(buf
[0] != 0, "test33 case 1 failed\n");
2966 FAILED(buf
[1] != 11, "test33 case 2 failed\n");
2967 FAILED(buf
[2] != 1, "test33 case 3 failed\n");
2968 FAILED(buf
[3] != 45, "test33 case 4 failed\n");
2969 FAILED(buf
[4] != 13, "test33 case 5 failed\n");
2970 FAILED(buf
[5] != 0, "test33 case 6 failed\n");
2971 FAILED(buf
[6] != 0, "test33 case 7 failed\n");
2972 FAILED(buf
[7] != 48, "test33 case 8 failed\n");
2973 FAILED(buf
[8] != 50, "test33 case 9 failed\n");
2974 FAILED(buf
[9] != 1, "test33 case 10 failed\n");
2976 sljit_free_code(code
.code
, NULL
);
2980 static void test34(void)
2982 /* Test fast calls. */
2983 executable_code codeA
;
2984 executable_code codeB
;
2985 executable_code codeC
;
2986 executable_code codeD
;
2987 executable_code codeE
;
2988 executable_code codeF
;
2989 struct sljit_compiler
* compiler
;
2990 struct sljit_jump
*jump
;
2991 struct sljit_label
* label
;
2996 printf("Run test34\n");
3002 compiler
= sljit_create_compiler(NULL
, NULL
);
3003 FAILED(!compiler
, "cannot create compiler\n");
3004 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3006 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3007 sljit_emit_fast_enter(compiler
, SLJIT_R1
, 0);
3008 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 4);
3009 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R1
, 0);
3011 codeA
.code
= sljit_generate_code(compiler
);
3013 sljit_free_compiler(compiler
);
3016 compiler
= sljit_create_compiler(NULL
, NULL
);
3017 FAILED(!compiler
, "cannot create compiler\n");
3018 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3020 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3021 sljit_emit_fast_enter(compiler
, SLJIT_R4
, 0);
3022 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 6);
3023 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(codeA
.code
));
3024 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_R1
, 0);
3025 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R4
, 0);
3027 codeB
.code
= sljit_generate_code(compiler
);
3029 sljit_free_compiler(compiler
);
3032 compiler
= sljit_create_compiler(NULL
, NULL
);
3033 FAILED(!compiler
, "cannot create compiler\n");
3034 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3036 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3037 sljit_emit_fast_enter(compiler
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_p
));
3038 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3039 jump
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
| SLJIT_REWRITABLE_JUMP
);
3040 sljit_set_target(jump
, SLJIT_FUNC_UADDR(codeB
.code
));
3041 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_p
));
3043 codeC
.code
= sljit_generate_code(compiler
);
3045 sljit_free_compiler(compiler
);
3048 compiler
= sljit_create_compiler(NULL
, NULL
);
3049 FAILED(!compiler
, "cannot create compiler\n");
3050 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3052 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3053 sljit_emit_fast_enter(compiler
, SLJIT_MEM1(SLJIT_SP
), 0);
3054 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 10);
3055 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_ADDR(codeC
.code
));
3056 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_MEM1(SLJIT_SP
), 0);
3058 codeD
.code
= sljit_generate_code(compiler
);
3060 sljit_free_compiler(compiler
);
3063 compiler
= sljit_create_compiler(NULL
, NULL
);
3064 FAILED(!compiler
, "cannot create compiler\n");
3065 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3067 sljit_emit_fast_enter(compiler
, SLJIT_MEM1(SLJIT_S0
), 0);
3068 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 12);
3069 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_p
), SLJIT_IMM
, SLJIT_FUNC_ADDR(codeD
.code
));
3070 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_p
));
3071 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_MEM1(SLJIT_S0
), 0);
3073 codeE
.code
= sljit_generate_code(compiler
);
3075 sljit_free_compiler(compiler
);
3078 compiler
= sljit_create_compiler(NULL
, NULL
);
3079 FAILED(!compiler
, "cannot create compiler\n");
3081 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3082 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3083 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_ADDR(codeE
.code
));
3084 label
= sljit_emit_label(compiler
);
3085 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
3087 codeF
.code
= sljit_generate_code(compiler
);
3089 addr
= sljit_get_label_addr(label
);
3090 sljit_free_compiler(compiler
);
3092 FAILED(codeF
.func1((sljit_sw
)&buf
) != 40, "test34 case 1 failed\n");
3093 FAILED(buf
[0] != addr
- SLJIT_RETURN_ADDRESS_OFFSET
, "test34 case 2 failed\n");
3095 sljit_free_code(codeA
.code
, NULL
);
3096 sljit_free_code(codeB
.code
, NULL
);
3097 sljit_free_code(codeC
.code
, NULL
);
3098 sljit_free_code(codeD
.code
, NULL
);
3099 sljit_free_code(codeE
.code
, NULL
);
3100 sljit_free_code(codeF
.code
, NULL
);
3104 static void test35(void)
3106 /* More complicated tests for fast calls. */
3107 executable_code codeA
;
3108 executable_code codeB
;
3109 executable_code codeC
;
3110 struct sljit_compiler
* compiler
;
3111 struct sljit_jump
*jump
= NULL
;
3112 struct sljit_label
* label
;
3113 sljit_sw executable_offset
;
3114 sljit_uw return_addr
;
3115 sljit_uw jump_addr
= 0;
3119 printf("Run test35\n");
3124 compiler
= sljit_create_compiler(NULL
, NULL
);
3125 FAILED(!compiler
, "cannot create compiler\n");
3126 sljit_set_context(compiler
, 0, 0, 2, 2, 0, 0, 0);
3128 sljit_emit_fast_enter(compiler
, SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
3129 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3131 jump
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
| SLJIT_REWRITABLE_JUMP
);
3132 sljit_set_target(jump
, 0);
3134 label
= sljit_emit_label(compiler
);
3135 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
3137 codeA
.code
= sljit_generate_code(compiler
);
3139 executable_offset
= sljit_get_executable_offset(compiler
);
3140 jump_addr
= sljit_get_jump_addr(jump
);
3141 sljit_free_compiler(compiler
);
3144 compiler
= sljit_create_compiler(NULL
, NULL
);
3145 FAILED(!compiler
, "cannot create compiler\n");
3146 sljit_set_context(compiler
, 0, 0, 2, 2, 0, 0, 0);
3148 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3149 sljit_emit_fast_enter(compiler
, SLJIT_R1
, 0);
3150 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 7);
3151 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R1
, 0);
3153 codeB
.code
= sljit_generate_code(compiler
);
3155 sljit_free_compiler(compiler
);
3157 sljit_set_jump_addr(jump_addr
, SLJIT_FUNC_UADDR(codeB
.code
), executable_offset
);
3160 compiler
= sljit_create_compiler(NULL
, NULL
);
3161 FAILED(!compiler
, "cannot create compiler\n");
3163 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), 2, 2, 0, 0, 0);
3164 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3165 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_ADDR(codeA
.code
));
3166 label
= sljit_emit_label(compiler
);
3167 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
3169 codeC
.code
= sljit_generate_code(compiler
);
3171 return_addr
= sljit_get_label_addr(label
);
3172 sljit_free_compiler(compiler
);
3174 FAILED(codeC
.func0() != 12, "test35 case 1 failed\n");
3175 FAILED(buf
[0] != return_addr
- SLJIT_RETURN_ADDRESS_OFFSET
, "test35 case 2 failed\n");
3177 sljit_free_code(codeA
.code
, NULL
);
3178 sljit_free_code(codeB
.code
, NULL
);
3179 sljit_free_code(codeC
.code
, NULL
);
3183 static void cmp_test(struct sljit_compiler
*compiler
, sljit_s32 type
, sljit_s32 src1
, sljit_sw src1w
, sljit_s32 src2
, sljit_sw src2w
)
3185 /* 2 = true, 1 = false */
3186 struct sljit_jump
* jump
;
3187 struct sljit_label
* label
;
3189 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_IMM
, 2);
3190 jump
= sljit_emit_cmp(compiler
, type
, src1
, src1w
, src2
, src2w
);
3191 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_IMM
, 1);
3192 label
= sljit_emit_label(compiler
);
3193 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3194 sljit_set_label(jump
, label
);
3195 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
3198 #define TEST_CASES (7 + 10 + 12 + 11 + 4)
3199 static void test36(void)
3201 /* Compare instruction. */
3202 executable_code code
;
3203 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3205 sljit_s8 buf
[TEST_CASES
];
3206 sljit_s8 compare_buf
[TEST_CASES
] = {
3207 1, 1, 2, 2, 1, 2, 2,
3208 1, 1, 2, 2, 2, 1, 2, 2, 1, 1,
3209 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2,
3210 2, 1, 2, 1, 1, 1, 2, 1, 2, 1, 2,
3217 printf("Run test36\n");
3219 FAILED(!compiler
, "cannot create compiler\n");
3220 for (i
= 0; i
< TEST_CASES
; ++i
)
3227 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 3, 2, 0, 0, 0);
3228 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
3230 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 13);
3231 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 15);
3232 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_IMM
, 9, SLJIT_R0
, 0);
3233 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3234 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
3235 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_IMM
, -13);
3236 cmp_test(compiler
, SLJIT_NOT_EQUAL
, SLJIT_IMM
, 0, SLJIT_R0
, 0);
3237 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3238 cmp_test(compiler
, SLJIT_NOT_EQUAL
| SLJIT_REWRITABLE_JUMP
, SLJIT_IMM
, 0, SLJIT_R0
, 0);
3239 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
);
3240 cmp_test(compiler
, SLJIT_EQUAL
| SLJIT_REWRITABLE_JUMP
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3242 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, 0);
3243 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -8);
3244 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3245 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3246 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3247 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_REWRITABLE_JUMP
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3248 cmp_test(compiler
, SLJIT_SIG_GREATER_EQUAL
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3249 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
));
3250 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_IMM
, 0, SLJIT_R1
, 0);
3251 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
));
3252 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
));
3253 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_REWRITABLE_JUMP
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
));
3255 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3256 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3257 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
));
3258 cmp_test(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3259 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, -10);
3260 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3261 cmp_test(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_IMM
, 8, SLJIT_R1
, 0);
3262 cmp_test(compiler
, SLJIT_GREATER_EQUAL
| SLJIT_REWRITABLE_JUMP
, SLJIT_IMM
, 8, SLJIT_R1
, 0);
3263 cmp_test(compiler
, SLJIT_GREATER
, SLJIT_IMM
, 8, SLJIT_R1
, 0);
3264 cmp_test(compiler
, SLJIT_LESS_EQUAL
, SLJIT_IMM
, 7, SLJIT_R0
, 0);
3265 cmp_test(compiler
, SLJIT_GREATER
, SLJIT_IMM
, 1, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
));
3266 cmp_test(compiler
, SLJIT_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3267 cmp_test(compiler
, SLJIT_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3268 cmp_test(compiler
, SLJIT_GREATER
| SLJIT_REWRITABLE_JUMP
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3270 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -3);
3271 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3272 cmp_test(compiler
, SLJIT_SIG_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3273 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
3274 cmp_test(compiler
, SLJIT_SIG_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3275 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, -1);
3276 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_REWRITABLE_JUMP
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, -1);
3277 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3278 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3279 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_IMM
, -4, SLJIT_R0
, 0);
3280 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_IMM
, -1, SLJIT_R1
, 0);
3281 cmp_test(compiler
, SLJIT_SIG_GREATER
| SLJIT_REWRITABLE_JUMP
, SLJIT_R1
, 0, SLJIT_IMM
, -1);
3283 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3284 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xf00000004));
3285 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_R0
, 0);
3286 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3287 cmp_test(compiler
, SLJIT_LESS
| SLJIT_32
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
3288 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3289 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xff0000004));
3290 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R0
, 0);
3291 cmp_test(compiler
, SLJIT_SIG_GREATER
| SLJIT_32
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
3292 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3294 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
3295 cmp_test(compiler
, SLJIT_LESS
| SLJIT_32
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3296 cmp_test(compiler
, SLJIT_GREATER
| SLJIT_32
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3297 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0xf0000004);
3298 cmp_test(compiler
, SLJIT_SIG_GREATER
| SLJIT_32
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3299 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_32
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3302 sljit_emit_return_void(compiler
);
3304 code
.code
= sljit_generate_code(compiler
);
3306 sljit_free_compiler(compiler
);
3308 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&data
);
3310 for (i
= 0; i
< TEST_CASES
; ++i
)
3311 if (SLJIT_UNLIKELY(buf
[i
] != compare_buf
[i
])) {
3312 printf("test36 case %d failed\n", i
+ 1);
3316 sljit_free_code(code
.code
, NULL
);
3321 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3322 #define BITN(n) (SLJIT_W(1) << (63 - (n)))
3325 #define BITN(n) (1 << (31 - ((n) & 0x1f)))
3326 #define RESN(n) ((n) & 0x1f)
3329 static void test37(void)
3331 /* Test count leading zeroes. */
3332 executable_code code
;
3333 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3339 printf("Run test37\n");
3341 FAILED(!compiler
, "cannot create compiler\n");
3343 for (i
= 0; i
< 9; i
++)
3349 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 1, 3, 0, 0, 0);
3350 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, BITN(27));
3351 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
3352 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, BITN(47));
3353 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_R0
, 0, SLJIT_S2
, 0);
3354 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
3355 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
));
3356 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
3357 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3358 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3359 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3360 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_R0
, 0);
3361 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
3362 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
));
3363 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3364 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, BITN(58));
3365 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3366 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3367 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3368 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3369 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xff08a00000));
3371 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x08a00000);
3373 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
), SLJIT_R0
, 0);
3374 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3375 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3376 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3377 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xffc8a00000));
3379 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0xc8a00000);
3381 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3382 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3384 sljit_emit_return_void(compiler
);
3386 code
.code
= sljit_generate_code(compiler
);
3388 sljit_free_compiler(compiler
);
3390 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&ibuf
);
3391 FAILED(buf
[0] != RESN(27), "test37 case 1 failed\n");
3392 FAILED(buf
[1] != RESN(47), "test37 case 2 failed\n");
3393 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3394 FAILED(buf
[2] != 64, "test37 case 3 failed\n");
3396 FAILED(buf
[2] != 32, "test37 case 3 failed\n");
3398 FAILED(buf
[3] != 0, "test37 case 4 failed\n");
3399 FAILED(ibuf
[0] != 32, "test37 case 5 failed\n");
3400 FAILED(buf
[4] != RESN(13), "test37 case 6 failed\n");
3401 FAILED(buf
[5] != RESN(58), "test37 case 7 failed\n");
3402 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3403 FAILED(buf
[6] != 64, "test37 case 8 failed\n");
3405 FAILED(buf
[6] != 32, "test37 case 8 failed\n");
3407 FAILED(ibuf
[1] != 4, "test37 case 9 failed\n");
3409 FAILED((buf
[7] & (sljit_sw
)0xffffffff) != 4, "test37 case 10 failed\n");
3410 FAILED((buf
[8] & (sljit_sw
)0xffffffff) != 0, "test37 case 11 failed\n");
3412 sljit_free_code(code
.code
, NULL
);
3418 static void test38(void)
3420 #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)
3421 /* Test stack utility. */
3422 executable_code code
;
3423 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3424 struct sljit_jump
* alloc1_fail
;
3425 struct sljit_jump
* alloc2_fail
;
3426 struct sljit_jump
* alloc3_fail
;
3427 struct sljit_jump
* sanity1_fail
;
3428 struct sljit_jump
* sanity2_fail
;
3429 struct sljit_jump
* sanity3_fail
;
3430 struct sljit_jump
* sanity4_fail
;
3431 struct sljit_jump
* jump
;
3432 struct sljit_label
* label
;
3435 printf("Run test38\n");
3437 FAILED(!compiler
, "cannot create compiler\n");
3439 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), 3, 1, 0, 0, 0);
3441 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8192);
3442 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 65536);
3443 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0);
3444 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(P
, W
, W
, P
), SLJIT_IMM
, SLJIT_FUNC_ADDR(sljit_allocate_stack
));
3445 alloc1_fail
= sljit_emit_cmp(compiler
, SLJIT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0);
3446 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_RETURN_REG
, 0);
3448 /* Write 8k data. */
3449 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3450 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8192);
3451 label
= sljit_emit_label(compiler
);
3452 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_IMM
, -1);
3453 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
3454 jump
= sljit_emit_cmp(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3455 sljit_set_label(jump
, label
);
3458 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
3459 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, end
), SLJIT_IMM
, 65536);
3460 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS2(P
, P
, P
), SLJIT_IMM
, SLJIT_FUNC_ADDR(sljit_stack_resize
));
3461 alloc2_fail
= sljit_emit_cmp(compiler
, SLJIT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0);
3462 sanity1_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3464 /* Write 64k data. */
3465 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3466 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 65536);
3467 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, min_start
));
3468 sanity2_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, 0, SLJIT_R2
, 0);
3469 label
= sljit_emit_label(compiler
);
3470 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_IMM
, -1);
3471 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
3472 jump
= sljit_emit_cmp(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3473 sljit_set_label(jump
, label
);
3476 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
3477 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, end
), SLJIT_IMM
, 32768);
3478 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS2(P
, P
, P
), SLJIT_IMM
, SLJIT_FUNC_ADDR(sljit_stack_resize
));
3479 alloc3_fail
= sljit_emit_cmp(compiler
, SLJIT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0);
3480 sanity3_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3482 /* Write 32k data. */
3483 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3484 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, end
));
3485 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R2
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 32768);
3486 sanity4_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, 0, SLJIT_R2
, 0);
3487 label
= sljit_emit_label(compiler
);
3488 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_IMM
, -1);
3489 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
3490 jump
= sljit_emit_cmp(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3491 sljit_set_label(jump
, label
);
3493 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
3494 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3495 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS2(VOID
, P
, P
), SLJIT_IMM
, SLJIT_FUNC_ADDR(sljit_free_stack
));
3497 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, 4567);
3499 label
= sljit_emit_label(compiler
);
3500 sljit_set_label(alloc1_fail
, label
);
3501 sljit_set_label(alloc2_fail
, label
);
3502 sljit_set_label(alloc3_fail
, label
);
3503 sljit_set_label(sanity1_fail
, label
);
3504 sljit_set_label(sanity2_fail
, label
);
3505 sljit_set_label(sanity3_fail
, label
);
3506 sljit_set_label(sanity4_fail
, label
);
3507 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, 0);
3509 code
.code
= sljit_generate_code(compiler
);
3511 sljit_free_compiler(compiler
);
3513 /* Just survive this. */
3514 FAILED(code
.func0() != 4567, "test38 case 1 failed\n");
3516 sljit_free_code(code
.code
, NULL
);
3521 static void test39(void)
3523 /* Test error handling. */
3524 executable_code code
;
3525 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3526 struct sljit_jump
* jump
;
3529 printf("Run test39\n");
3531 FAILED(!compiler
, "cannot create compiler\n");
3533 /* Such assignment should never happen in a regular program. */
3534 compiler
->error
= -3967;
3536 SLJIT_ASSERT(sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, W
, W
), 5, 5, 6, 0, 32) == -3967);
3537 SLJIT_ASSERT(sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R1
, 0) == -3967);
3538 SLJIT_ASSERT(sljit_emit_op0(compiler
, SLJIT_NOP
) == -3967);
3539 SLJIT_ASSERT(sljit_emit_op0(compiler
, SLJIT_ENDBR
) == -3967);
3540 SLJIT_ASSERT(sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1) == -3967);
3541 SLJIT_ASSERT(sljit_emit_op2(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R0
), 64, SLJIT_MEM1(SLJIT_S0
), -64) == -3967);
3542 SLJIT_ASSERT(sljit_emit_fop1(compiler
, SLJIT_ABS_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_R1
), 0) == -3967);
3543 SLJIT_ASSERT(sljit_emit_fop2(compiler
, SLJIT_DIV_F64
, SLJIT_FR2
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_S0
), 0, SLJIT_FR2
, 0) == -3967);
3544 SLJIT_ASSERT(!sljit_emit_label(compiler
));
3545 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS4(W
, 32, P
, F32
, F64
));
3546 SLJIT_ASSERT(!jump
);
3547 sljit_set_label(jump
, (struct sljit_label
*)0x123450);
3548 sljit_set_target(jump
, 0x123450);
3549 jump
= sljit_emit_cmp(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3550 SLJIT_ASSERT(!jump
);
3551 SLJIT_ASSERT(sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_MEM1(SLJIT_R0
), 8) == -3967);
3552 SLJIT_ASSERT(sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_OVERFLOW
) == -3967);
3553 SLJIT_ASSERT(!sljit_emit_const(compiler
, SLJIT_R0
, 0, 99));
3555 SLJIT_ASSERT(!compiler
->labels
&& !compiler
->jumps
&& !compiler
->consts
);
3556 SLJIT_ASSERT(!compiler
->last_label
&& !compiler
->last_jump
&& !compiler
->last_const
);
3557 SLJIT_ASSERT(!compiler
->buf
->next
&& !compiler
->buf
->used_size
);
3558 SLJIT_ASSERT(!compiler
->abuf
->next
&& !compiler
->abuf
->used_size
);
3560 sljit_set_compiler_memory_error(compiler
);
3561 FAILED(sljit_get_compiler_error(compiler
) != -3967, "test39 case 1 failed\n");
3563 code
.code
= sljit_generate_code(compiler
);
3564 FAILED(sljit_get_compiler_error(compiler
) != -3967, "test39 case 2 failed\n");
3565 FAILED(!!code
.code
, "test39 case 3 failed\n");
3566 sljit_free_compiler(compiler
);
3568 compiler
= sljit_create_compiler(NULL
, NULL
);
3569 FAILED(!compiler
, "cannot create compiler\n");
3571 FAILED(sljit_get_compiler_error(compiler
) != SLJIT_SUCCESS
, "test39 case 4 failed\n");
3572 sljit_set_compiler_memory_error(compiler
);
3573 FAILED(sljit_get_compiler_error(compiler
) != SLJIT_ERR_ALLOC_FAILED
, "test39 case 5 failed\n");
3574 sljit_free_compiler(compiler
);
3579 static void test40(void)
3581 /* Test emit_op_flags. */
3582 executable_code code
;
3583 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3587 printf("Run test40\n");
3589 FAILED(!compiler
, "cannot create compiler\n");
3601 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 4, 0, 0, sizeof(sljit_sw
));
3603 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -5);
3604 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_IMM
, -6, SLJIT_R0
, 0);
3605 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x123456);
3606 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_SIG_LESS
);
3607 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
3609 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -13);
3610 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_IMM
, -13, SLJIT_R0
, 0);
3611 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 0);
3612 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_EQUAL
);
3613 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_NOT_EQUAL
);
3614 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);
3615 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_IMM
, -13, SLJIT_R0
, 0);
3616 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3617 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_EQUAL
);
3618 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_EQUAL
);
3620 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -13);
3621 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3);
3622 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
3623 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R1
), SLJIT_WORD_SHIFT
, SLJIT_SIG_LESS
);
3625 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -8);
3626 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 33);
3627 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3628 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, 0);
3629 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_GREATER
);
3630 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_S1
, 0, SLJIT_EQUAL
);
3631 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3632 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, 0x88);
3633 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_S3
, 0, SLJIT_NOT_EQUAL
);
3634 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_S1
, 0);
3635 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_S3
, 0);
3637 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x84);
3638 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_IMM
, 0x180, SLJIT_R0
, 0);
3639 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_EQUAL
);
3640 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_EQUAL
);
3642 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3643 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3644 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_NOT_EQUAL
);
3645 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_NOT_EQUAL
);
3647 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x123456);
3648 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3649 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_GREATER
);
3650 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_R0
, 0);
3652 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 0xbaddead);
3653 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0);
3655 code
.code
= sljit_generate_code(compiler
);
3657 sljit_free_compiler(compiler
);
3659 FAILED(code
.func1((sljit_sw
)&buf
) != 0xbaddead, "test40 case 1 failed\n");
3660 FAILED(buf
[0] != 0x123457, "test40 case 2 failed\n");
3661 FAILED(buf
[1] != 1, "test40 case 3 failed\n");
3662 FAILED(buf
[2] != 0, "test40 case 4 failed\n");
3663 FAILED(buf
[3] != -7, "test40 case 5 failed\n");
3664 FAILED(buf
[4] != 0, "test40 case 6 failed\n");
3665 FAILED(buf
[5] != 0x89, "test40 case 7 failed\n");
3666 FAILED(buf
[6] != 0, "test40 case 8 failed\n");
3667 FAILED(buf
[7] != 1, "test40 case 9 failed\n");
3668 FAILED(buf
[8] != 1, "test40 case 10 failed\n");
3669 FAILED(buf
[9] != 0x123457, "test40 case 11 failed\n");
3671 sljit_free_code(code
.code
, NULL
);
3675 static void test41(void)
3677 /* Test inline assembly. */
3678 executable_code code
;
3679 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3682 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3684 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3692 printf("Run test41\n");
3694 #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3695 SLJIT_ASSERT(sljit_has_cpu_feature(SLJIT_HAS_VIRTUAL_REGISTERS
) == 0);
3698 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
3699 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3700 if (SLJIT_R(i
) >= SLJIT_R3
&& SLJIT_R(i
) <= SLJIT_R8
) {
3701 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i
)) == -1);
3705 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i
)) >= 0 && sljit_get_register_index(SLJIT_R(i
)) < 64);
3708 FAILED(!compiler
, "cannot create compiler\n");
3709 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(W
, W
, W
), 3, 3, 0, 0, 0);
3711 /* Returns with the sum of SLJIT_S0 and SLJIT_S1. */
3712 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3713 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3716 inst
[2] = (sljit_u8
)(0x04 | ((sljit_get_register_index(SLJIT_RETURN_REG
) & 0x7) << 3));
3717 inst
[3] = (sljit_u8
)((sljit_get_register_index(SLJIT_S0
) & 0x7)
3718 | ((sljit_get_register_index(SLJIT_S1
) & 0x7) << 3));
3719 sljit_emit_op_custom(compiler
, inst
, 4);
3720 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3721 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3722 inst
[0] = 0x48; /* REX_W */
3724 reg
= sljit_get_register_index(SLJIT_RETURN_REG
);
3725 inst
[2] = (sljit_u8
)(0x04 | ((reg
& 0x7) << 3));
3727 inst
[0] |= 0x04; /* REX_R */
3728 reg
= sljit_get_register_index(SLJIT_S0
);
3729 inst
[3] = (sljit_u8
)(reg
& 0x7);
3731 inst
[0] |= 0x01; /* REX_B */
3732 reg
= sljit_get_register_index(SLJIT_S1
);
3733 inst
[3] = (sljit_u8
)(inst
[3] | ((reg
& 0x7) << 3));
3735 inst
[0] |= 0x02; /* REX_X */
3736 sljit_emit_op_custom(compiler
, inst
, 4);
3737 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
3738 /* add rd, rn, rm */
3739 inst
= 0xe0800000 | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 12)
3740 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 16)
3741 | (sljit_u32
)sljit_get_register_index(SLJIT_S1
);
3742 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3743 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
3744 /* add rd, rn, rm */
3745 inst
= 0xeb000000 | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 8)
3746 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 16)
3747 | (sljit_u32
)sljit_get_register_index(SLJIT_S1
);
3748 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3749 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3750 /* add rd, rn, rm */
3751 inst
= 0x8b000000 | (sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
)
3752 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 5)
3753 | ((sljit_u32
)sljit_get_register_index(SLJIT_S1
) << 16);
3754 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3755 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3756 /* add rD, rA, rB */
3757 inst
= (31 << 26) | (266 << 1) | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 21)
3758 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 16)
3759 | ((sljit_u32
)sljit_get_register_index(SLJIT_S1
) << 11);
3760 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3761 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
3762 /* addu rd, rs, rt */
3763 inst
= 33 | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 11)
3764 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 21)
3765 | ((sljit_u32
)sljit_get_register_index(SLJIT_S1
) << 16);
3766 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3767 #elif (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
3768 /* daddu rd, rs, rt */
3769 inst
= 45 | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 11)
3770 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 21)
3771 | ((sljit_u32
)sljit_get_register_index(SLJIT_S1
) << 16);
3772 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3773 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3774 /* add rd, rs1, rs2 */
3775 inst
= (0x2u
<< 30) | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 25)
3776 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 14)
3777 | (sljit_u32
)sljit_get_register_index(SLJIT_S1
);
3778 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3779 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
3780 /* agrk rd, rs1, rs2 */
3781 inst
= (0xb9e8u
<< 16)
3782 | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 4)
3783 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 12)
3784 | (sljit_u32
)sljit_get_register_index(SLJIT_S1
);
3785 sljit_emit_op_custom(compiler
, &inst
, sizeof(inst
));
3788 sljit_emit_op_custom(compiler
, &inst
, 0);
3791 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
3793 code
.code
= sljit_generate_code(compiler
);
3795 sljit_free_compiler(compiler
);
3797 FAILED(code
.func2(32, -11) != 21, "test41 case 1 failed\n");
3798 FAILED(code
.func2(1000, 234) != 1234, "test41 case 2 failed\n");
3799 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3800 FAILED(code
.func2(SLJIT_W(0x20f0a04090c06070), SLJIT_W(0x020f0a04090c0607)) != SLJIT_W(0x22ffaa4499cc6677), "test41 case 3 failed\n");
3803 sljit_free_code(code
.code
, NULL
);
3805 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
3810 compiler
= sljit_create_compiler(NULL
, NULL
);
3811 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 0, 1, 2, 0, 0);
3812 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
3813 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
3814 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3819 inst
[3] = (sljit_u8
)(0xc0 | (sljit_get_float_register_index(SLJIT_FR0
) << 3)
3820 | sljit_get_float_register_index(SLJIT_FR1
));
3821 sljit_emit_op_custom(compiler
, inst
, 4);
3822 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3824 if (sljit_get_float_register_index(SLJIT_FR0
) > 7 || sljit_get_float_register_index(SLJIT_FR1
) > 7) {
3826 if (sljit_get_float_register_index(SLJIT_FR0
) > 7)
3827 inst
[0] |= 0x04; /* REX_R */
3828 if (sljit_get_float_register_index(SLJIT_FR1
) > 7)
3829 inst
[0] |= 0x01; /* REX_B */
3833 inst
[4] = (sljit_u8
)(0xc0 | ((sljit_get_float_register_index(SLJIT_FR0
) & 0x7) << 3)
3834 | (sljit_get_float_register_index(SLJIT_FR1
) & 0x7));
3835 sljit_emit_op_custom(compiler
, inst
, 5);
3841 inst
[3] = (sljit_u8
)(0xc0 | (sljit_get_float_register_index(SLJIT_FR0
) << 3)
3842 | sljit_get_float_register_index(SLJIT_FR1
));
3843 sljit_emit_op_custom(compiler
, inst
, 4);
3845 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
3846 /* vadd.f64 dd, dn, dm */
3847 inst
= 0xee300b00 | (((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) >> 1) << 12)
3848 | (((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) >> 1) << 16)
3849 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
) >> 1);
3850 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3851 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3852 /* fadd rd, rn, rm */
3853 inst
= 0x1e602800 | (sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
)
3854 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 5)
3855 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
) << 16);
3856 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3857 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3858 /* fadd frD, frA, frB */
3859 inst
= (63u << 26) | (21u << 1) | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 21)
3860 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 16)
3861 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
) << 11);
3862 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3863 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
3864 /* add.d fd, fs, ft */
3865 inst
= (17 << 26) | (17 << 21) | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 6)
3866 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 11)
3867 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
) << 16);
3868 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3869 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3870 /* faddd rd, rs1, rs2 */
3871 inst
= (0x2u
<< 30) | (0x34u
<< 19) | (0x42u
<< 5)
3872 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 25)
3873 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 14)
3874 | (sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
);
3875 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3876 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
3879 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 4)
3880 | (sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
);
3881 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3883 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
3884 sljit_emit_return_void(compiler
);
3886 code
.code
= sljit_generate_code(compiler
);
3888 sljit_free_compiler(compiler
);
3890 code
.func1((sljit_sw
)&buf
);
3891 FAILED(buf
[2] != 11.25, "test41 case 3 failed\n");
3893 sljit_free_code(code
.code
, NULL
);
3899 static void test42(void)
3901 /* Test long multiply and division. */
3902 executable_code code
;
3903 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3905 sljit_sw buf
[7 + 4 + 8 + 8];
3908 printf("Run test42\n");
3910 FAILED(!compiler
, "cannot create compiler\n");
3911 for (i
= 0; i
< 7 + 4 + 8 + 8; i
++)
3914 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 5, 5, 0, 0, 0);
3916 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -0x1fb308a);
3917 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0xf50c873);
3918 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, 0x8a0475b);
3919 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, 0x9dc849b);
3920 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -0x7c69a35);
3921 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, 0x5a4d0c4);
3922 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_IMM
, 0x9a3b06d);
3924 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3925 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3926 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3927 sljit_emit_op0(compiler
, SLJIT_LMUL_UW
);
3928 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3929 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3931 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3932 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3933 sljit_emit_op0(compiler
, SLJIT_LMUL_SW
);
3934 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3935 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3937 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3938 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3939 sljit_emit_op0(compiler
, SLJIT_DIVMOD_UW
);
3940 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3941 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3943 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3944 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3945 sljit_emit_op0(compiler
, SLJIT_DIVMOD_SW
);
3946 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3947 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3949 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x5cf783d3cf0a74b0));
3950 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3d5df42d03a28fc7));
3951 sljit_emit_op0(compiler
, SLJIT_DIVMOD_U32
);
3952 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3953 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3954 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3955 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3957 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x371df5197ba26a28));
3958 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x46c78a5cfd6a420c));
3959 sljit_emit_op0(compiler
, SLJIT_DIVMOD_S32
);
3960 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3961 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3962 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3963 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3965 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)SLJIT_W(0xc456f048c28a611b));
3966 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3d4af2c543));
3967 sljit_emit_op0(compiler
, SLJIT_DIV_UW
);
3968 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 19 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3969 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3971 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x720fa4b74c329b14));
3972 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0xa64ae42b7d6));
3973 sljit_emit_op0(compiler
, SLJIT_DIV_SW
);
3974 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 21 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3975 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3977 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x4af51c027b34));
3978 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x9ba4ff2906b14));
3979 sljit_emit_op0(compiler
, SLJIT_DIV_U32
);
3980 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3981 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3982 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 23 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3983 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 24 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3985 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xc40b58a3f20d));
3986 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(-0xa63c923));
3987 sljit_emit_op0(compiler
, SLJIT_DIV_S32
);
3988 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3989 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3990 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 25 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3991 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 26 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3994 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
3995 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
3996 sljit_emit_op0(compiler
, SLJIT_LMUL_UW
);
3997 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3998 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4000 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
4001 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
4002 sljit_emit_op0(compiler
, SLJIT_LMUL_SW
);
4003 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4004 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4006 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
4007 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
4008 sljit_emit_op0(compiler
, SLJIT_DIVMOD_UW
);
4009 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4010 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4012 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
4013 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
4014 sljit_emit_op0(compiler
, SLJIT_DIVMOD_SW
);
4015 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4016 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4018 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0xcf0a74b0);
4019 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0x03a28fc7);
4020 sljit_emit_op0(compiler
, SLJIT_DIVMOD_U32
);
4021 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4022 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4024 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x7ba26a28);
4025 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)0xfd6a420c);
4026 sljit_emit_op0(compiler
, SLJIT_DIVMOD_S32
);
4027 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4028 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4030 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x9d4b7036);
4031 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0xb86d0);
4032 sljit_emit_op0(compiler
, SLJIT_DIV_UW
);
4033 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 19 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4034 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4036 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58b0692c);
4037 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0xd357);
4038 sljit_emit_op0(compiler
, SLJIT_DIV_SW
);
4039 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 21 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4040 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4042 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1c027b34);
4043 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)0xf2906b14);
4044 sljit_emit_op0(compiler
, SLJIT_DIV_U32
);
4045 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4046 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
4047 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 23 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4048 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 24 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4050 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x58a3f20d);
4051 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -0xa63c923);
4052 sljit_emit_op0(compiler
, SLJIT_DIV_S32
);
4053 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4054 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
4055 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 25 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4056 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 26 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4059 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R2
, 0);
4060 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R3
, 0);
4061 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R4
, 0);
4062 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_S1
, 0);
4063 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_S2
, 0);
4064 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_S3
, 0);
4065 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_S4
, 0);
4067 sljit_emit_return_void(compiler
);
4069 code
.code
= sljit_generate_code(compiler
);
4071 sljit_free_compiler(compiler
);
4073 code
.func1((sljit_sw
)&buf
);
4075 FAILED(buf
[0] != -0x1fb308a, "test42 case 1 failed\n");
4076 FAILED(buf
[1] != 0xf50c873, "test42 case 2 failed\n");
4077 FAILED(buf
[2] != 0x8a0475b, "test42 case 3 failed\n");
4078 FAILED(buf
[3] != 0x9dc849b, "test42 case 4 failed\n");
4079 FAILED(buf
[4] != -0x7c69a35, "test42 case 5 failed\n");
4080 FAILED(buf
[5] != 0x5a4d0c4, "test42 case 6 failed\n");
4081 FAILED(buf
[6] != 0x9a3b06d, "test42 case 7 failed\n");
4083 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4084 FAILED(buf
[7] != SLJIT_W(-4388959407985636971), "test42 case 8 failed\n");
4085 FAILED(buf
[8] != SLJIT_W(2901680654366567099), "test42 case 9 failed\n");
4086 FAILED(buf
[9] != SLJIT_W(-4388959407985636971), "test42 case 10 failed\n");
4087 FAILED(buf
[10] != SLJIT_W(-1677173957268872740), "test42 case 11 failed\n");
4088 FAILED(buf
[11] != SLJIT_W(2), "test42 case 12 failed\n");
4089 FAILED(buf
[12] != SLJIT_W(2532236178951865933), "test42 case 13 failed\n");
4090 FAILED(buf
[13] != SLJIT_W(-1), "test42 case 14 failed\n");
4091 FAILED(buf
[14] != SLJIT_W(-2177944059851366166), "test42 case 15 failed\n");
4093 FAILED(buf
[7] != -1587000939, "test42 case 8 failed\n");
4094 FAILED(buf
[8] != 665003983, "test42 case 9 failed\n");
4095 FAILED(buf
[9] != -1587000939, "test42 case 10 failed\n");
4096 FAILED(buf
[10] != -353198352, "test42 case 11 failed\n");
4097 FAILED(buf
[11] != 2, "test42 case 12 failed\n");
4098 FAILED(buf
[12] != 768706125, "test42 case 13 failed\n");
4099 FAILED(buf
[13] != -1, "test42 case 14 failed\n");
4100 FAILED(buf
[14] != -471654166, "test42 case 15 failed\n");
4103 FAILED(buf
[15] != 56, "test42 case 16 failed\n");
4104 FAILED(buf
[16] != 58392872, "test42 case 17 failed\n");
4105 FAILED(buf
[17] != -47, "test42 case 18 failed\n");
4106 FAILED(buf
[18] != 35949148, "test42 case 19 failed\n");
4108 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4109 FAILED(buf
[19] != SLJIT_W(0x3340bfc), "test42 case 20 failed\n");
4110 FAILED(buf
[20] != SLJIT_W(0x3d4af2c543), "test42 case 21 failed\n");
4111 FAILED(buf
[21] != SLJIT_W(-0xaf978), "test42 case 22 failed\n");
4112 FAILED(buf
[22] != SLJIT_W(0xa64ae42b7d6), "test42 case 23 failed\n");
4114 FAILED(buf
[19] != SLJIT_W(0xda5), "test42 case 20 failed\n");
4115 FAILED(buf
[20] != SLJIT_W(0xb86d0), "test42 case 21 failed\n");
4116 FAILED(buf
[21] != SLJIT_W(-0x6b6e), "test42 case 22 failed\n");
4117 FAILED(buf
[22] != SLJIT_W(0xd357), "test42 case 23 failed\n");
4120 FAILED(buf
[23] != 0x0, "test42 case 24 failed\n");
4121 FAILED(buf
[24] != (sljit_sw
)0xf2906b14, "test42 case 25 failed\n");
4122 FAILED(buf
[25] != -0x8, "test42 case 26 failed\n");
4123 FAILED(buf
[26] != -0xa63c923, "test42 case 27 failed\n");
4125 sljit_free_code(code
.code
, NULL
);
4129 static void test43(void)
4131 /* Test floating point compare. */
4132 executable_code code
;
4133 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4134 struct sljit_jump
* jump
;
4145 printf("Run test43\n");
4147 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4149 printf("no fpu available, test43 skipped\n");
4152 sljit_free_compiler(compiler
);
4156 FAILED(!compiler
, "cannot create compiler\n");
4158 dbuf
[0].value
= 12.125;
4160 dbuf
[1].u
.value1
= 0x7fffffff;
4161 dbuf
[1].u
.value2
= 0x7fffffff;
4162 dbuf
[2].value
= -13.5;
4163 dbuf
[3].value
= 12.125;
4165 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 1, 1, 3, 0, 0);
4166 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
4167 /* dbuf[0] < dbuf[2] -> -2 */
4168 jump
= sljit_emit_fcmp(compiler
, SLJIT_GREATER_EQUAL_F64
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), SLJIT_F64_SHIFT
);
4169 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, -2);
4171 sljit_set_label(jump
, sljit_emit_label(compiler
));
4172 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4173 /* dbuf[0] and dbuf[1] is not NaN -> 5 */
4174 jump
= sljit_emit_fcmp(compiler
, SLJIT_UNORDERED_F64
, SLJIT_MEM0(), (sljit_sw
)&dbuf
[1], SLJIT_FR1
, 0);
4175 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, 5);
4177 sljit_set_label(jump
, sljit_emit_label(compiler
));
4178 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
));
4179 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 11);
4180 /* dbuf[0] == dbuf[3] -> 11 */
4181 jump
= sljit_emit_fcmp(compiler
, SLJIT_EQUAL_F64
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_FR2
, 0);
4184 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, -17);
4185 sljit_set_label(jump
, sljit_emit_label(compiler
));
4186 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
4188 code
.code
= sljit_generate_code(compiler
);
4190 sljit_free_compiler(compiler
);
4192 FAILED(code
.func1((sljit_sw
)&dbuf
) != 11, "test43 case 1 failed\n");
4194 FAILED(code
.func1((sljit_sw
)&dbuf
) != -17, "test43 case 2 failed\n");
4196 FAILED(code
.func1((sljit_sw
)&dbuf
) != 5, "test43 case 3 failed\n");
4198 FAILED(code
.func1((sljit_sw
)&dbuf
) != -2, "test43 case 4 failed\n");
4200 sljit_free_code(code
.code
, NULL
);
4204 static void test44(void)
4207 executable_code code
;
4208 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4212 printf("Run test44\n");
4214 FAILED(!compiler
, "cannot create compiler\n");
4221 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(P
, P
), 3, 2, 0, 0, 0);
4223 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4224 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_p
), SLJIT_R0
, 0);
4225 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_p
));
4226 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 2);
4227 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R1
), SLJIT_POINTER_SHIFT
, SLJIT_R0
, 0);
4228 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_p
));
4229 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3 << SLJIT_POINTER_SHIFT
);
4230 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_S0
, 0);
4231 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM2(SLJIT_R2
, SLJIT_R1
), 0, SLJIT_R0
, 0);
4232 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 2 * sizeof(sljit_p
));
4233 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1 << SLJIT_POINTER_SHIFT
);
4234 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM2(SLJIT_R2
, SLJIT_R1
), 2, SLJIT_R0
, 0);
4236 sljit_emit_return(compiler
, SLJIT_MOV_P
, SLJIT_R0
, 0);
4238 code
.code
= sljit_generate_code(compiler
);
4240 sljit_free_compiler(compiler
);
4242 FAILED(code
.func1((sljit_sw
)&buf
) != (sljit_sw
)(buf
+ 2), "test44 case 1 failed\n");
4243 FAILED(buf
[1] != buf
+ 2, "test44 case 2 failed\n");
4244 FAILED(buf
[2] != buf
+ 3, "test44 case 3 failed\n");
4245 FAILED(buf
[3] != buf
+ 4, "test44 case 4 failed\n");
4246 FAILED(buf
[4] != buf
+ 2, "test44 case 5 failed\n");
4248 sljit_free_code(code
.code
, NULL
);
4252 static void test45(void)
4254 /* Test single precision floating point. */
4256 executable_code code
;
4257 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4260 struct sljit_jump
* jump
;
4263 printf("Run test45\n");
4265 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4267 printf("no fpu available, test45 skipped\n");
4270 sljit_free_compiler(compiler
);
4274 FAILED(!compiler
, "cannot create compiler\n");
4296 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 3, 2, 6, 0, 0);
4298 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4299 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4300 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
4301 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_FR1
, 0, SLJIT_FR5
, 0);
4302 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f32
), SLJIT_FR1
, 0);
4303 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f32
), SLJIT_FR5
, 0);
4304 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_FR4
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4305 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f32
), SLJIT_FR4
, 0);
4307 sljit_emit_fop2(compiler
, SLJIT_ADD_F32
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4308 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
4309 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);
4310 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4311 sljit_emit_fop2(compiler
, SLJIT_MUL_F32
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_f32
), SLJIT_FR0
, 0, SLJIT_FR0
, 0);
4312 sljit_emit_fop2(compiler
, SLJIT_DIV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
4313 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f32
), SLJIT_FR2
, 0);
4314 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x3d0ac);
4315 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_R0
), 0x3d0ac);
4316 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x3d0ac + sizeof(sljit_f32
));
4317 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_R0
), -0x3d0ac);
4319 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4320 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4321 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4322 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_EQUAL_F32
);
4323 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_LESS_F
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4324 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
), SLJIT_LESS_F32
);
4325 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
4326 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
), SLJIT_EQUAL_F32
);
4327 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_GREATER_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
4328 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
), SLJIT_GREATER_EQUAL_F32
);
4330 jump
= sljit_emit_fcmp(compiler
, SLJIT_LESS_EQUAL_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4331 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, 7);
4332 sljit_set_label(jump
, sljit_emit_label(compiler
));
4334 jump
= sljit_emit_fcmp(compiler
, SLJIT_GREATER_F32
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_FR2
, 0);
4335 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_IMM
, 6);
4336 sljit_set_label(jump
, sljit_emit_label(compiler
));
4338 sljit_emit_return_void(compiler
);
4340 code
.code
= sljit_generate_code(compiler
);
4342 sljit_free_compiler(compiler
);
4344 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&buf2
);
4345 FAILED(buf
[2] != -5.5, "test45 case 1 failed\n");
4346 FAILED(buf
[3] != 7.25, "test45 case 2 failed\n");
4347 FAILED(buf
[4] != 7.25, "test45 case 3 failed\n");
4348 FAILED(buf
[5] != -5.5, "test45 case 4 failed\n");
4349 FAILED(buf
[6] != -1.75, "test45 case 5 failed\n");
4350 FAILED(buf
[7] != 16.0, "test45 case 6 failed\n");
4351 FAILED(buf
[8] != 30.25, "test45 case 7 failed\n");
4352 FAILED(buf
[9] != 3, "test45 case 8 failed\n");
4353 FAILED(buf
[10] != -5.5, "test45 case 9 failed\n");
4354 FAILED(buf
[11] != 7.25, "test45 case 10 failed\n");
4355 FAILED(buf2
[0] != 1, "test45 case 11 failed\n");
4356 FAILED(buf2
[1] != 2, "test45 case 12 failed\n");
4357 FAILED(buf2
[2] != 2, "test45 case 13 failed\n");
4358 FAILED(buf2
[3] != 1, "test45 case 14 failed\n");
4359 FAILED(buf2
[4] != 7, "test45 case 15 failed\n");
4360 FAILED(buf2
[5] != -1, "test45 case 16 failed\n");
4362 sljit_free_code(code
.code
, NULL
);
4366 static void test46(void)
4368 /* Test sljit_emit_op_flags with 32 bit operations. */
4370 executable_code code
;
4371 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4377 printf("Run test46\n");
4379 for (i
= 0; i
< 24; ++i
)
4382 for (i
= 0; i
< 6; ++i
)
4386 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 3, 3, 0, 0, 0);
4388 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4389 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_R2
, 0, SLJIT_IMM
, 13);
4390 sljit_emit_op_flags(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&buf
, SLJIT_LESS
);
4391 sljit_emit_op_flags(compiler
, SLJIT_AND32
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_s32
), SLJIT_NOT_ZERO
);
4393 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4394 sljit_emit_op_flags(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_s32
), SLJIT_EQUAL
);
4395 sljit_emit_op_flags(compiler
, SLJIT_AND32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_s32
), SLJIT_NOT_EQUAL
);
4396 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1235);
4397 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1235);
4398 sljit_emit_op_flags(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_ZERO
);
4399 sljit_emit_op_flags(compiler
, SLJIT_AND32
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_s32
), SLJIT_ZERO
);
4400 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4402 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4403 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 12);
4404 sljit_emit_op_flags(compiler
, SLJIT_MOV32
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 2, SLJIT_EQUAL
);
4405 sljit_emit_op_flags(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_EQUAL
);
4406 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4407 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
4408 sljit_emit_op_flags(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 2, SLJIT_EQUAL
);
4409 sljit_emit_op_flags(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_s32
), SLJIT_NOT_EQUAL
);
4411 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4412 sljit_emit_op_flags(compiler
, SLJIT_XOR32
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_s32
), SLJIT_ZERO
);
4413 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 39);
4414 sljit_emit_op_flags(compiler
, SLJIT_XOR32
, SLJIT_R0
, 0, SLJIT_NOT_ZERO
);
4415 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4417 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4418 sljit_emit_op_flags(compiler
, SLJIT_AND
, SLJIT_MEM0(), (sljit_sw
)&buf2
, SLJIT_GREATER
);
4419 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R2
, 0, SLJIT_IMM
, 5);
4420 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
4421 sljit_emit_op_flags(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_SIG_LESS
);
4422 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
4423 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_R2
, 0, SLJIT_IMM
, 5);
4424 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_LESS
);
4425 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_NOT_EQUAL
);
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_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
), SLJIT_S2
, 0);
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_op_flags(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_ZERO
);
4430 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R2
, 0, SLJIT_IMM
, 0);
4431 sljit_emit_op_flags(compiler
, SLJIT_XOR
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_GREATER
);
4433 sljit_emit_return_void(compiler
);
4435 code
.code
= sljit_generate_code(compiler
);
4437 sljit_free_compiler(compiler
);
4439 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&buf2
);
4440 FAILED(buf
[0] != 0, "test46 case 1 failed\n");
4441 FAILED(buf
[1] != -17, "test46 case 2 failed\n");
4442 FAILED(buf
[2] != 1, "test46 case 3 failed\n");
4443 FAILED(buf
[3] != -17, "test46 case 4 failed\n");
4444 FAILED(buf
[4] != 1, "test46 case 5 failed\n");
4445 FAILED(buf
[5] != -17, "test46 case 6 failed\n");
4446 FAILED(buf
[6] != 1, "test46 case 7 failed\n");
4447 FAILED(buf
[7] != -17, "test46 case 8 failed\n");
4448 FAILED(buf
[8] != 0, "test46 case 9 failed\n");
4449 FAILED(buf
[9] != -17, "test46 case 10 failed\n");
4450 FAILED(buf
[10] != 1, "test46 case 11 failed\n");
4451 FAILED(buf
[11] != -17, "test46 case 12 failed\n");
4452 FAILED(buf
[12] != 1, "test46 case 13 failed\n");
4453 FAILED(buf
[13] != -17, "test46 case 14 failed\n");
4454 FAILED(buf
[14] != 1, "test46 case 15 failed\n");
4455 FAILED(buf
[15] != -17, "test46 case 16 failed\n");
4456 FAILED(buf
[16] != 0, "test46 case 17 failed\n");
4457 FAILED(buf
[17] != -17, "test46 case 18 failed\n");
4458 FAILED(buf
[18] != 0, "test46 case 19 failed\n");
4459 FAILED(buf
[19] != -17, "test46 case 20 failed\n");
4460 FAILED(buf
[20] != -18, "test46 case 21 failed\n");
4461 FAILED(buf
[21] != -17, "test46 case 22 failed\n");
4462 FAILED(buf
[22] != 38, "test46 case 23 failed\n");
4463 FAILED(buf
[23] != -17, "test46 case 24 failed\n");
4465 FAILED(buf2
[0] != 0, "test46 case 25 failed\n");
4466 FAILED(buf2
[1] != 1, "test46 case 26 failed\n");
4467 FAILED(buf2
[2] != 0, "test46 case 27 failed\n");
4468 FAILED(buf2
[3] != 1, "test46 case 28 failed\n");
4469 FAILED(buf2
[4] != -123, "test46 case 29 failed\n");
4470 FAILED(buf2
[5] != -14, "test46 case 30 failed\n");
4472 sljit_free_code(code
.code
, NULL
);
4476 static void test47(void)
4478 /* Test jump optimizations. */
4479 executable_code code
;
4480 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4484 printf("Run test47\n");
4486 FAILED(!compiler
, "cannot create compiler\n");
4491 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 0);
4492 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x3a5c6f);
4493 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
4494 sljit_set_target(sljit_emit_jump(compiler
, SLJIT_LESS
), 0x11223344);
4495 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
4496 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xd37c10);
4497 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4498 sljit_set_target(sljit_emit_jump(compiler
, SLJIT_LESS
), SLJIT_W(0x112233445566));
4500 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
4501 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x59b48e);
4502 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4503 sljit_set_target(sljit_emit_jump(compiler
, SLJIT_LESS
), SLJIT_W(0x1122334455667788));
4505 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4506 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
4508 code
.code
= sljit_generate_code(compiler
);
4510 sljit_free_compiler(compiler
);
4512 FAILED(code
.func1((sljit_sw
)&buf
) != 0x59b48e, "test47 case 1 failed\n");
4513 FAILED(buf
[0] != 0x3a5c6f, "test47 case 2 failed\n");
4514 FAILED(buf
[1] != 0xd37c10, "test47 case 3 failed\n");
4515 FAILED(buf
[2] != 0x59b48e, "test47 case 4 failed\n");
4517 sljit_free_code(code
.code
, NULL
);
4521 static void test48(void)
4523 /* Test floating point conversions. */
4524 executable_code code
;
4525 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4533 printf("Run test48\n");
4535 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4537 printf("no fpu available, test48 skipped\n");
4540 sljit_free_compiler(compiler
);
4544 FAILED(!compiler
, "cannot create compiler\n");
4545 for (i
= 0; i
< 10; i
++) {
4564 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 3, 3, 6, 0, 0);
4565 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
4566 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, (sljit_sw
)&sbuf
);
4567 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
4568 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
4571 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_F64
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S0
), 0);
4572 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4573 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
4575 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_F64
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_F32_SHIFT
, SLJIT_FR5
, 0);
4576 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_F32
, SLJIT_FR4
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
4578 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
), SLJIT_FR4
, 0);
4579 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
4580 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_F32
, SLJIT_FR2
, 0, SLJIT_FR3
, 0);
4582 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
4584 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_f32
), SLJIT_FR3
, 0);
4587 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
4588 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
4589 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_R0
, 0, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), SLJIT_F64_SHIFT
);
4591 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4592 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
4594 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F32
, SLJIT_MEM1(SLJIT_S2
), 3 * sizeof(sljit_sw
), SLJIT_FR5
, 0);
4595 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_FR0
, 0, SLJIT_FR5
, 0);
4596 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 4);
4598 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F32
, SLJIT_MEM2(SLJIT_S2
, SLJIT_R1
), SLJIT_WORD_SHIFT
, SLJIT_FR0
, 0);
4599 sljit_emit_fop1(compiler
, SLJIT_NEG_F64
, SLJIT_FR4
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
));
4601 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F64
, SLJIT_MEM1(SLJIT_R2
), 2 * sizeof(sljit_s32
), SLJIT_FR4
, 0);
4602 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
4603 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F32
, SLJIT_R0
, 0, SLJIT_FR1
, 0);
4605 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_R2
), 3 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4608 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S2
), 0);
4609 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_FR2
, 0, SLJIT_IMM
, -6213);
4611 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
4613 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_f64
), SLJIT_MEM0(), (sljit_sw
)&ibuf
[0]);
4614 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R2
), sizeof(sljit_s32
));
4615 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_FR1
, 0, SLJIT_R0
, 0);
4617 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_f64
), SLJIT_FR1
, 0);
4619 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM0(), (sljit_sw
)(dbuf
+ 9), SLJIT_IMM
, -77);
4621 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_f32
), SLJIT_IMM
, -123);
4622 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 7190);
4623 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_FR3
, 0, SLJIT_R0
, 0);
4625 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 6 * sizeof(sljit_f32
), SLJIT_FR3
, 0);
4626 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 123);
4627 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 123 * sizeof(sljit_s32
));
4628 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_S32
, SLJIT_FR1
, 0, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 2);
4630 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 7 * sizeof(sljit_f32
), SLJIT_FR1
, 0);
4631 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
4632 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 3812);
4634 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_S32
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_F32_SHIFT
, SLJIT_R1
, 0);
4636 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_MEM0(), (sljit_sw
)(sbuf
+ 9), SLJIT_IMM
, -79);
4638 sljit_emit_return_void(compiler
);
4640 code
.code
= sljit_generate_code(compiler
);
4642 sljit_free_compiler(compiler
);
4645 FAILED(dbuf
[3] != 476.25, "test48 case 1 failed\n");
4646 FAILED(dbuf
[4] != 476.25, "test48 case 2 failed\n");
4647 FAILED(dbuf
[5] != 2345.0, "test48 case 3 failed\n");
4648 FAILED(dbuf
[6] != -6213.0, "test48 case 4 failed\n");
4649 FAILED(dbuf
[7] != 312.0, "test48 case 5 failed\n");
4650 FAILED(dbuf
[8] != -9324.0, "test48 case 6 failed\n");
4651 FAILED(dbuf
[9] != -77.0, "test48 case 7 failed\n");
4653 FAILED(sbuf
[2] != 123.5, "test48 case 8 failed\n");
4654 FAILED(sbuf
[3] != 123.5, "test48 case 9 failed\n");
4655 FAILED(sbuf
[4] != 476.25, "test48 case 10 failed\n");
4656 FAILED(sbuf
[5] != -123, "test48 case 11 failed\n");
4657 FAILED(sbuf
[6] != 7190, "test48 case 12 failed\n");
4658 FAILED(sbuf
[7] != 312, "test48 case 13 failed\n");
4659 FAILED(sbuf
[8] != 3812, "test48 case 14 failed\n");
4660 FAILED(sbuf
[9] != -79.0, "test48 case 15 failed\n");
4662 FAILED(wbuf
[1] != -367, "test48 case 16 failed\n");
4663 FAILED(wbuf
[2] != 917, "test48 case 17 failed\n");
4664 FAILED(wbuf
[3] != 476, "test48 case 18 failed\n");
4665 FAILED(wbuf
[4] != -476, "test48 case 19 failed\n");
4667 FAILED(ibuf
[2] != -917, "test48 case 20 failed\n");
4668 FAILED(ibuf
[3] != -1689, "test48 case 21 failed\n");
4670 sljit_free_code(code
.code
, NULL
);
4674 static void test49(void)
4676 /* Test floating point conversions. */
4677 executable_code code
;
4678 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4684 sljit_s32
* dbuf_ptr
= (sljit_s32
*)dbuf
;
4685 sljit_s32
* sbuf_ptr
= (sljit_s32
*)sbuf
;
4688 printf("Run test49\n");
4690 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4692 printf("no fpu available, test49 skipped\n");
4695 sljit_free_compiler(compiler
);
4699 FAILED(!compiler
, "cannot create compiler\n");
4701 for (i
= 0; i
< 9; i
++) {
4702 dbuf_ptr
[i
<< 1] = -1;
4703 dbuf_ptr
[(i
<< 1) + 1] = -1;
4709 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4710 dbuf
[9] = (sljit_f64
)SLJIT_W(0x1122334455);
4717 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 3, 3, 3, 0, 0);
4718 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
4719 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, (sljit_sw
)&sbuf
);
4720 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
4721 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
4724 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_F32
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S1
), 0);
4726 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_F64
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S0
), 0);
4728 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 0);
4730 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F32
, SLJIT_MEM1(SLJIT_S2
), 4 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S1
), 0);
4732 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F64
, SLJIT_MEM1(SLJIT_R2
), 2 * sizeof(sljit_s32
), SLJIT_MEM1(SLJIT_S0
), 0);
4734 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F32
, SLJIT_MEM1(SLJIT_R2
), 4 * sizeof(sljit_s32
), SLJIT_MEM1(SLJIT_S1
), 0);
4736 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S2
), 0);
4738 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S2
), 0);
4740 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_R2
), 0);
4742 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_S32
, SLJIT_MEM1(SLJIT_S1
), 6 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_R2
), 0);
4744 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4745 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f64
));
4747 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), 8 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4748 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f64
));
4749 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F64
, SLJIT_R0
, 0, SLJIT_FR2
, 0);
4750 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4751 sljit_emit_op2(compiler
, SLJIT_AND32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffff);
4753 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R2
), 8 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4754 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x4455667788));
4756 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_f64
), SLJIT_R0
, 0);
4758 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f64
), SLJIT_IMM
, SLJIT_W(0x7766554433));
4761 sljit_emit_return_void(compiler
);
4763 code
.code
= sljit_generate_code(compiler
);
4765 sljit_free_compiler(compiler
);
4769 FAILED(dbuf_ptr
[(1 * 2) + 0] != -1, "test49 case 1 failed\n");
4770 FAILED(dbuf_ptr
[(1 * 2) + 1] != -1, "test49 case 2 failed\n");
4771 FAILED(dbuf
[2] != -879.75, "test49 case 3 failed\n");
4772 FAILED(dbuf_ptr
[(3 * 2) + 0] != -1, "test49 case 4 failed\n");
4773 FAILED(dbuf_ptr
[(3 * 2) + 1] != -1, "test49 case 5 failed\n");
4774 FAILED(dbuf
[4] != 345, "test49 case 6 failed\n");
4775 FAILED(dbuf_ptr
[(5 * 2) + 0] != -1, "test49 case 7 failed\n");
4776 FAILED(dbuf_ptr
[(5 * 2) + 1] != -1, "test49 case 8 failed\n");
4777 FAILED(dbuf
[6] != -249, "test49 case 9 failed\n");
4778 FAILED(dbuf_ptr
[(7 * 2) + 0] != -1, "test49 case 10 failed\n");
4779 FAILED(dbuf_ptr
[(7 * 2) + 1] != -1, "test49 case 11 failed\n");
4781 FAILED(sbuf_ptr
[1] != -1, "test49 case 12 failed\n");
4782 FAILED(sbuf
[2] != 673.75, "test49 case 13 failed\n");
4783 FAILED(sbuf_ptr
[3] != -1, "test49 case 14 failed\n");
4784 FAILED(sbuf
[4] != 345, "test49 case 15 failed\n");
4785 FAILED(sbuf_ptr
[5] != -1, "test49 case 16 failed\n");
4786 FAILED(sbuf
[6] != -249, "test49 case 17 failed\n");
4787 FAILED(sbuf_ptr
[7] != -1, "test49 case 18 failed\n");
4789 FAILED(wbuf
[1] != -1, "test49 case 19 failed\n");
4790 FAILED(wbuf
[2] != 673, "test49 case 20 failed\n");
4791 FAILED(wbuf
[3] != -1, "test49 case 21 failed\n");
4792 FAILED(wbuf
[4] != -879, "test49 case 22 failed\n");
4793 FAILED(wbuf
[5] != -1, "test49 case 23 failed\n");
4795 FAILED(ibuf
[1] != -1, "test49 case 24 failed\n");
4796 FAILED(ibuf
[2] != 673, "test49 case 25 failed\n");
4797 FAILED(ibuf
[3] != -1, "test49 case 26 failed\n");
4798 FAILED(ibuf
[4] != -879, "test49 case 27 failed\n");
4799 FAILED(ibuf
[5] != -1, "test49 case 28 failed\n");
4801 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4802 FAILED(dbuf
[8] != (sljit_f64
)SLJIT_W(0x4455667788), "test49 case 29 failed\n");
4803 FAILED(dbuf
[9] != (sljit_f64
)SLJIT_W(0x66554433), "test49 case 30 failed\n");
4804 FAILED(wbuf
[8] != SLJIT_W(0x1122334455), "test48 case 31 failed\n");
4805 FAILED(ibuf
[8] == 0x4455, "test48 case 32 failed\n");
4808 sljit_free_code(code
.code
, NULL
);
4812 static void test50(void)
4814 /* Test stack and floating point operations. */
4815 executable_code code
;
4816 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4817 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4818 sljit_uw size1
, size2
, size3
;
4824 printf("Run test50\n");
4826 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4828 printf("no fpu available, test50 skipped\n");
4831 sljit_free_compiler(compiler
);
4835 FAILED(!compiler
, "cannot create compiler\n");
4841 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 3, 6, 0, 8 * sizeof(sljit_f32
));
4843 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
4844 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), 0);
4846 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_f32
));
4847 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4848 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
));
4850 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), 2 * sizeof(sljit_f32
));
4851 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 2 * sizeof(sljit_f32
), SLJIT_IMM
, 5934);
4852 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
));
4854 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), 3 * sizeof(sljit_f32
));
4856 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4857 size1
= compiler
->size
;
4859 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f32
));
4860 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4861 size2
= compiler
->size
;
4863 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR5
, 0, SLJIT_FR2
, 0);
4864 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4865 size3
= compiler
->size
;
4868 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f32
), SLJIT_FR5
, 0);
4869 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4870 result
= (compiler
->size
- size3
) == (size3
- size2
) && (size3
- size2
) == (size2
- size1
);
4873 sljit_emit_return_void(compiler
);
4875 code
.code
= sljit_generate_code(compiler
);
4877 sljit_free_compiler(compiler
);
4879 code
.func1((sljit_sw
)&sbuf
);
4881 FAILED(sbuf
[3] != 245.5, "test50 case 1 failed\n");
4882 FAILED(sbuf
[4] != 145.25, "test50 case 2 failed\n");
4883 FAILED(sbuf
[5] != 5934, "test50 case 3 failed\n");
4884 FAILED(sbuf
[6] != 713.75, "test50 case 4 failed\n");
4885 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4886 FAILED(!result
, "test50 case 5 failed\n");
4889 sljit_free_code(code
.code
, NULL
);
4893 static void test51(void)
4895 /* Test all registers provided by the CPU. */
4896 executable_code code
;
4897 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4898 struct sljit_jump
* jump
;
4903 printf("Run test51\n");
4905 FAILED(!compiler
, "cannot create compiler\n");
4909 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0, 0);
4911 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4912 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 32);
4914 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)buf
);
4915 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
4917 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
4918 if (sljit_get_register_index(SLJIT_R(i
)) >= 0) {
4919 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_R0
, 0);
4920 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_R(i
)), 0);
4922 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, buf
[0]);
4925 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 32);
4926 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
4927 if (sljit_get_register_index(SLJIT_R(i
)) >= 0) {
4928 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_R0
, 0);
4929 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_R(i
)), 32);
4931 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, buf
[0]);
4934 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
4935 if (sljit_get_register_index(SLJIT_R(i
)) >= 0) {
4936 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 32);
4937 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM2(SLJIT_R(i
), SLJIT_R0
), 0);
4938 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_R(i
)), 0);
4939 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 8);
4940 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_R(i
)), 2);
4942 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 3 * buf
[0]);
4945 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 32 + sizeof(sljit_sw
), SLJIT_R1
, 0);
4947 sljit_emit_return_void(compiler
);
4949 code
.code
= sljit_generate_code(compiler
);
4951 sljit_free_compiler(compiler
);
4955 FAILED(buf
[1] != (39 * 5 * (SLJIT_NUMBER_OF_REGISTERS
- 2)), "test51 case 1 failed\n");
4957 sljit_free_code(code
.code
, NULL
);
4961 compiler
= sljit_create_compiler(NULL
, NULL
);
4963 FAILED(!compiler
, "cannot create compiler\n");
4965 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), SLJIT_NUMBER_OF_SCRATCH_REGISTERS
, SLJIT_NUMBER_OF_SAVED_REGISTERS
, 0, 0, 0);
4967 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4968 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 17);
4970 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS0(W
));
4971 /* SLJIT_R0 contains the first value. */
4972 for (i
= 1; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4973 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
4975 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
4977 sljit_set_label(jump
, sljit_emit_label(compiler
));
4978 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0, 0);
4979 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
4980 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 35);
4981 sljit_emit_return_void(compiler
);
4983 code
.code
= sljit_generate_code(compiler
);
4985 sljit_free_compiler(compiler
);
4987 FAILED(code
.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS
* 35 + SLJIT_NUMBER_OF_SAVED_REGISTERS
* 17), "test51 case 2 failed\n");
4989 sljit_free_code(code
.code
, NULL
);
4993 compiler
= sljit_create_compiler(NULL
, NULL
);
4995 FAILED(!compiler
, "cannot create compiler\n");
4997 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), SLJIT_NUMBER_OF_SCRATCH_REGISTERS
, SLJIT_NUMBER_OF_SAVED_REGISTERS
, 0, 0, 0);
4999 for (i
= 0; i
< SLJIT_NUMBER_OF_SCRATCH_REGISTERS
; i
++)
5000 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 68);
5001 for (i
= 0; i
< SLJIT_NUMBER_OF_SAVED_REGISTERS
; i
++)
5002 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S(i
), 0, SLJIT_IMM
, 68);
5004 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS0(W
));
5005 /* SLJIT_R0 contains the first value. */
5006 for (i
= 1; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5007 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
5009 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
5011 sljit_set_label(jump
, sljit_emit_label(compiler
));
5012 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0, 0);
5013 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5014 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 43);
5015 sljit_emit_return_void(compiler
);
5017 code
.code
= sljit_generate_code(compiler
);
5019 sljit_free_compiler(compiler
);
5021 FAILED(code
.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS
* 43 + SLJIT_NUMBER_OF_SAVED_REGISTERS
* 68), "test51 case 3 failed\n");
5023 sljit_free_code(code
.code
, NULL
);
5027 static void test52(void)
5029 /* Test all registers provided by the CPU. */
5030 executable_code code
;
5031 struct sljit_compiler
* compiler
;
5032 struct sljit_jump
* jump
;
5037 printf("Run test52\n");
5039 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5041 printf("no fpu available, test52 skipped\n");
5048 compiler
= sljit_create_compiler(NULL
, NULL
);
5049 FAILED(!compiler
, "cannot create compiler\n");
5053 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
, 0);
5055 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5056 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
5058 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS0(VOID
));
5059 /* SLJIT_FR0 contains the first value. */
5060 for (i
= 1; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5061 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_FR(i
), 0);
5062 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5064 sljit_emit_return_void(compiler
);
5066 sljit_set_label(jump
, sljit_emit_label(compiler
));
5067 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 1, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0, 0);
5068 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[1]);
5069 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5070 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_MEM1(SLJIT_R0
), 0);
5071 sljit_emit_return_void(compiler
);
5073 code
.code
= sljit_generate_code(compiler
);
5075 sljit_free_compiler(compiler
);
5077 code
.func1((sljit_sw
)&buf
);
5078 FAILED(buf
[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
* 17.75 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
* 6.25), "test52 case 1 failed\n");
5080 sljit_free_code(code
.code
, NULL
);
5084 compiler
= sljit_create_compiler(NULL
, NULL
);
5085 FAILED(!compiler
, "cannot create compiler\n");
5089 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
, 0);
5091 for (i
= 0; i
< SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
; i
++)
5092 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
5093 for (i
= 0; i
< SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
; i
++)
5094 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FS(i
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
5096 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS0(VOID
));
5097 /* SLJIT_FR0 contains the first value. */
5098 for (i
= 1; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5099 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_FR(i
), 0);
5100 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5102 sljit_emit_return_void(compiler
);
5104 sljit_set_label(jump
, sljit_emit_label(compiler
));
5105 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 1, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0, 0);
5106 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[1]);
5107 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5108 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_MEM1(SLJIT_R0
), 0);
5109 sljit_emit_return_void(compiler
);
5111 code
.code
= sljit_generate_code(compiler
);
5113 sljit_free_compiler(compiler
);
5115 code
.func1((sljit_sw
)&buf
);
5116 FAILED(buf
[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
* -11.25 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
* -32.5), "test52 case 2 failed\n");
5118 sljit_free_code(code
.code
, NULL
);
5122 static void test53(void)
5124 /* Check cdecl calls. */
5125 executable_code code
;
5126 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5130 printf("Run test53\n");
5132 FAILED(!compiler
, "cannot create compiler\n");
5135 sljit_emit_enter(compiler
, SLJIT_ENTER_CDECL
, SLJIT_ARGS3(VOID
, W
, W
, W
), 1, 3, 0, 0, 2 * sizeof(sljit_sw
));
5137 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)buf
);
5138 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
5139 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_S1
, 0);
5140 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_sw
), SLJIT_S2
, 0);
5142 sljit_emit_return_void(compiler
);
5144 code
.code
= sljit_generate_code(compiler
);
5146 sljit_free_compiler(compiler
);
5148 code
.test53_f1(7895, -3812, 4087);
5150 FAILED(buf
[0] != 7895, "test53 case 1 failed\n");
5151 FAILED(buf
[1] != -3812, "test53 case 2 failed\n");
5152 FAILED(buf
[2] != 4087, "test53 case 3 failed\n");
5154 sljit_free_code(code
.code
, NULL
);
5159 static void test54(void)
5162 executable_code code
;
5163 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5164 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
5165 sljit_sw large_num
= SLJIT_W(0x1234567812345678);
5167 sljit_sw large_num
= SLJIT_W(0x12345678);
5175 sljit_s32 s32_value
;
5178 sbuf
[0].s32_value
= 0x7fffffff;
5179 sbuf
[1].value
= 7.5;
5180 sbuf
[2].value
= -14.75;
5183 printf("Run test54\n");
5185 FAILED(!compiler
, "cannot create compiler\n");
5187 for (i
= 0; i
< 19; i
++)
5189 for (i
= 0; i
< 4; i
++)
5192 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 5, 3, 3, 0, 0);
5194 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 17);
5195 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 34);
5196 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, -10);
5197 sljit_emit_cmov(compiler
, SLJIT_SIG_LESS
, SLJIT_R0
, SLJIT_R1
, 0);
5198 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
5199 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, -10);
5200 sljit_emit_cmov(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, SLJIT_R1
, 0);
5201 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
5203 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 24);
5204 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 24);
5205 sljit_emit_cmov(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, SLJIT_IMM
, 66);
5206 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5207 sljit_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R0
, SLJIT_IMM
, 78);
5208 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5209 sljit_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R0
, SLJIT_IMM
, large_num
);
5210 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5212 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
5213 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R3
) == -1 && sljit_get_register_index(SLJIT_R4
) == -1);
5215 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 7);
5216 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -45);
5217 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5218 sljit_emit_cmov(compiler
, SLJIT_OVERFLOW
, SLJIT_R3
, SLJIT_IMM
, 35);
5219 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5220 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, large_num
);
5221 sljit_emit_op2u(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_IMM
, large_num
);
5222 sljit_emit_cmov(compiler
, SLJIT_OVERFLOW
, SLJIT_R3
, SLJIT_IMM
, 35);
5223 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5225 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 71);
5226 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 13);
5227 sljit_emit_op2(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5228 sljit_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R3
, SLJIT_R0
, 0);
5229 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5231 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 12);
5232 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -29);
5233 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5234 sljit_emit_cmov(compiler
, SLJIT_NOT_OVERFLOW
, SLJIT_R0
, SLJIT_R3
, 0);
5235 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5237 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
5238 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -12);
5239 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, 21);
5240 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5241 sljit_emit_cmov(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R3
, SLJIT_R4
, 0);
5242 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5243 sljit_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R3
, SLJIT_R4
, 0);
5244 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5246 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5247 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S2
), 0);
5248 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
5249 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_f32
));
5251 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
5252 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5253 sljit_emit_cmov(compiler
, SLJIT_EQUAL_F32
, SLJIT_R0
, SLJIT_IMM
, -45);
5254 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5255 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_GREATER_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5256 sljit_emit_cmov(compiler
, SLJIT_GREATER_F32
, SLJIT_R0
, SLJIT_IMM
, -45);
5257 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5258 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_GREATER_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5259 sljit_emit_cmov(compiler
, SLJIT_GREATER_EQUAL_F32
, SLJIT_R0
, SLJIT_IMM
, 33);
5260 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5262 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5263 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_LESS_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5264 sljit_emit_cmov(compiler
, SLJIT_LESS_F32
, SLJIT_R0
, SLJIT_IMM
, -70);
5265 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5266 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_LESS_EQUAL_F
, SLJIT_FR2
, 0, SLJIT_FR1
, 0);
5267 sljit_emit_cmov(compiler
, SLJIT_LESS_EQUAL_F32
, SLJIT_R0
, SLJIT_IMM
, -60);
5268 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5269 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_NOT_EQUAL_F
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5270 sljit_emit_cmov(compiler
, SLJIT_NOT_EQUAL_F32
, SLJIT_R0
, SLJIT_IMM
, 31);
5271 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5273 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 53);
5274 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_ORDERED_F
, SLJIT_FR1
, 0, SLJIT_FR0
, 0);
5275 sljit_emit_cmov(compiler
, SLJIT_ORDERED_F32
, SLJIT_R0
, SLJIT_IMM
, 17);
5276 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5277 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_UNORDERED_F
, SLJIT_FR1
, 0, SLJIT_FR0
, 0);
5278 sljit_emit_cmov(compiler
, SLJIT_UNORDERED_F32
, SLJIT_R0
, SLJIT_IMM
, 59);
5279 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5282 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 177);
5283 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 178);
5284 sljit_emit_cmov(compiler
, SLJIT_LESS
, SLJIT_R0
| SLJIT_32
, SLJIT_IMM
, 200);
5285 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_R0
, 0);
5287 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 95);
5288 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R3
, 0, SLJIT_IMM
, 177);
5289 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 95);
5290 sljit_emit_cmov(compiler
, SLJIT_LESS_EQUAL
, SLJIT_R3
| SLJIT_32
, SLJIT_R0
, 0);
5291 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5292 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
), SLJIT_R3
, 0);
5294 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R3
, 0, SLJIT_IMM
, 56);
5295 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R4
, 0, SLJIT_IMM
, -63);
5296 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_SIG_LESS
, SLJIT_R3
, 0, SLJIT_R4
, 0);
5297 sljit_emit_cmov(compiler
, SLJIT_SIG_LESS
, SLJIT_R3
| SLJIT_32
, SLJIT_R4
, 0);
5298 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_s32
), SLJIT_R3
, 0);
5299 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_SIG_GREATER
, SLJIT_R3
, 0, SLJIT_R4
, 0);
5300 sljit_emit_cmov(compiler
, SLJIT_SIG_GREATER
, SLJIT_R3
| SLJIT_32
, SLJIT_R4
, 0);
5301 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_s32
), SLJIT_R3
, 0);
5303 sljit_emit_return_void(compiler
);
5305 code
.code
= sljit_generate_code(compiler
);
5307 sljit_free_compiler(compiler
);
5309 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&ibuf
, (sljit_sw
)&sbuf
);
5311 FAILED(buf
[0] != 17, "test54 case 1 failed\n");
5312 FAILED(buf
[1] != 34, "test54 case 2 failed\n");
5313 FAILED(buf
[2] != 24, "test54 case 3 failed\n");
5314 FAILED(buf
[3] != 78, "test54 case 4 failed\n");
5315 FAILED(buf
[4] != large_num
, "test54 case 5 failed\n");
5316 FAILED(buf
[5] != -45, "test54 case 6 failed\n");
5317 FAILED(buf
[6] != 35, "test54 case 7 failed\n");
5318 FAILED(buf
[7] != 71, "test54 case 8 failed\n");
5319 FAILED(buf
[8] != -29, "test54 case 9 failed\n");
5320 FAILED(buf
[9] != -12, "test54 case 10 failed\n");
5321 FAILED(buf
[10] != 21, "test54 case 11 failed\n");
5323 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5324 FAILED(buf
[11] != 16, "test54 case 12 failed\n");
5325 FAILED(buf
[12] != -45, "test54 case 13 failed\n");
5326 FAILED(buf
[13] != 33, "test54 case 14 failed\n");
5327 FAILED(buf
[14] != 8, "test54 case 15 failed\n");
5328 FAILED(buf
[15] != -60, "test54 case 16 failed\n");
5329 FAILED(buf
[16] != 31, "test54 case 17 failed\n");
5330 FAILED(buf
[17] != 53, "test54 case 18 failed\n");
5331 FAILED(buf
[18] != 59, "test54 case 19 failed\n");
5334 FAILED(ibuf
[0] != 200, "test54 case 12 failed\n");
5335 FAILED(ibuf
[1] != 95, "test54 case 13 failed\n");
5336 FAILED(ibuf
[2] != 56, "test54 case 14 failed\n");
5337 FAILED(ibuf
[3] != -63, "test54 case 15 failed\n");
5339 sljit_free_code(code
.code
, NULL
);
5343 static void test55(void)
5345 /* Check value preservation. */
5346 executable_code code
;
5347 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5352 printf("Run test55\n");
5354 FAILED(!compiler
, "cannot create compiler\n");
5358 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0, sizeof (sljit_sw
));
5360 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 217);
5363 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5364 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 118);
5366 sljit_emit_op0(compiler
, SLJIT_DIVMOD_SW
);
5368 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5370 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5371 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
5372 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_SP
), 0);
5374 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)(buf
+ 0), SLJIT_R0
, 0);
5377 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5378 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 146);
5380 sljit_emit_op0(compiler
, SLJIT_DIV_SW
);
5382 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5384 for (i
= 1; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5385 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
5386 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_SP
), 0);
5388 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)(buf
+ 1), SLJIT_R0
, 0);
5390 sljit_emit_return_void(compiler
);
5392 code
.code
= sljit_generate_code(compiler
);
5394 sljit_free_compiler(compiler
);
5398 FAILED(buf
[0] != (SLJIT_NUMBER_OF_REGISTERS
- 2) * 118 + 217, "test55 case 1 failed\n");
5399 FAILED(buf
[1] != (SLJIT_NUMBER_OF_REGISTERS
- 1) * 146 + 217, "test55 case 2 failed\n");
5401 sljit_free_code(code
.code
, NULL
);
5405 static void test56(void)
5407 /* Check integer substraction with negative immediate. */
5408 executable_code code
;
5409 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5414 printf("Run test56\n");
5416 for (i
= 0; i
< 13; i
++)
5419 FAILED(!compiler
, "cannot create compiler\n");
5421 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 0, 0, 0);
5423 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 90 << 12);
5424 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5425 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
5426 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_SIG_GREATER
);
5427 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5428 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5429 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_LESS
);
5430 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5431 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_SIG_GREATER_EQUAL
);
5432 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5433 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_LESS_EQUAL
);
5434 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5435 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_GREATER
);
5436 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5437 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_SIG_LESS
);
5439 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 90);
5440 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -91);
5441 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5442 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_SIG_GREATER
);
5443 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 90);
5444 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -91);
5445 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_LESS_EQUAL
);
5447 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, -0x7fffffff);
5448 sljit_emit_op2(compiler
, SLJIT_ADD32
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5449 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
5451 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, -0x7fffffff-1);
5452 sljit_emit_op1(compiler
, SLJIT_NEG32
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R0
, 0);
5453 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
5455 sljit_emit_return_void(compiler
);
5457 code
.code
= sljit_generate_code(compiler
);
5459 sljit_free_compiler(compiler
);
5461 code
.func1((sljit_sw
)&buf
);
5463 FAILED(buf
[0] != (181 << 12), "test56 case 1 failed\n");
5464 FAILED(buf
[1] != 1, "test56 case 2 failed\n");
5465 FAILED(buf
[2] != (181 << 12), "test56 case 3 failed\n");
5466 FAILED(buf
[3] != 1, "test56 case 4 failed\n");
5467 FAILED(buf
[4] != 1, "test56 case 5 failed\n");
5468 FAILED(buf
[5] != 1, "test56 case 6 failed\n");
5469 FAILED(buf
[6] != 0, "test56 case 7 failed\n");
5470 FAILED(buf
[7] != 0, "test56 case 8 failed\n");
5471 FAILED(buf
[8] != 181, "test56 case 9 failed\n");
5472 FAILED(buf
[9] != 1, "test56 case 10 failed\n");
5473 FAILED(buf
[10] != 1, "test56 case 11 failed\n");
5474 FAILED(buf
[11] != 1, "test56 case 12 failed\n");
5475 FAILED(buf
[12] != 1, "test56 case 13 failed\n");
5477 sljit_free_code(code
.code
, NULL
);
5481 static void test57(void)
5483 /* Check prefetch instructions. */
5484 executable_code code
;
5485 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5486 struct sljit_label
* labels
[5];
5491 printf("Run test57\n");
5493 FAILED(!compiler
, "cannot create compiler\n");
5495 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 3, 1, 0, 0, 0);
5497 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5498 labels
[0] = sljit_emit_label(compiler
);
5499 /* Should never crash. */
5500 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_L1
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R0
), 2);
5501 labels
[1] = sljit_emit_label(compiler
);
5502 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_L2
, SLJIT_MEM0(), 0);
5503 labels
[2] = sljit_emit_label(compiler
);
5504 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
5505 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_L3
, SLJIT_MEM1(SLJIT_R0
), SLJIT_W(0x1122334455667788));
5507 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_L3
, SLJIT_MEM1(SLJIT_R0
), 0x11223344);
5509 labels
[3] = sljit_emit_label(compiler
);
5510 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_ONCE
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
));
5511 labels
[4] = sljit_emit_label(compiler
);
5513 sljit_emit_return_void(compiler
);
5515 code
.code
= sljit_generate_code(compiler
);
5518 for (i
= 0; i
< 5; i
++)
5519 addr
[i
] = sljit_get_label_addr(labels
[i
]);
5521 sljit_free_compiler(compiler
);
5525 if (sljit_has_cpu_feature(SLJIT_HAS_PREFETCH
)) {
5526 FAILED(addr
[0] == addr
[1], "test57 case 1 failed\n");
5527 FAILED(addr
[1] == addr
[2], "test57 case 2 failed\n");
5528 FAILED(addr
[2] == addr
[3], "test57 case 3 failed\n");
5529 FAILED(addr
[3] == addr
[4], "test57 case 4 failed\n");
5532 FAILED(addr
[0] != addr
[1], "test57 case 1 failed\n");
5533 FAILED(addr
[1] != addr
[2], "test57 case 2 failed\n");
5534 FAILED(addr
[2] != addr
[3], "test57 case 3 failed\n");
5535 FAILED(addr
[3] != addr
[4], "test57 case 4 failed\n");
5538 sljit_free_code(code
.code
, NULL
);
5542 static sljit_f64 SLJIT_FUNC
test58_f1(sljit_f32 a
, sljit_f32 b
, sljit_f64 c
)
5544 return (sljit_f64
)a
+ (sljit_f64
)b
+ c
;
5547 static sljit_f32 SLJIT_FUNC
test58_f2(sljit_sw a
, sljit_f64 b
, sljit_f32 c
)
5549 return (sljit_f32
)((sljit_f64
)a
+ b
+ (sljit_f64
)c
);
5552 static sljit_f64 SLJIT_FUNC
test58_f3(sljit_sw a
, sljit_f32 b
, sljit_sw c
)
5554 return (sljit_f64
)a
+ (sljit_f64
)b
+ (sljit_f64
)c
;
5557 static sljit_f64
test58_f4(sljit_f32 a
, sljit_sw b
)
5559 return (sljit_f64
)a
+ (sljit_f64
)b
;
5562 static sljit_f32
test58_f5(sljit_f32 a
, sljit_f64 b
, sljit_s32 c
)
5564 return (sljit_f32
)((sljit_f64
)a
+ b
+ (sljit_f64
)c
);
5567 static sljit_sw SLJIT_FUNC
test58_f6(sljit_f64 a
, sljit_sw b
)
5569 return (sljit_sw
)(a
+ (sljit_f64
)b
);
5572 static void test58(void)
5574 /* Check function calls with floating point arguments. */
5575 executable_code code
;
5576 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5577 struct sljit_jump
* jump
= NULL
;
5583 printf("Run test58\n");
5585 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5587 printf("no fpu available, test58 skipped\n");
5590 sljit_free_compiler(compiler
);
5611 FAILED(!compiler
, "cannot create compiler\n");
5613 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 3, 3, 4, 0, sizeof(sljit_sw
));
5615 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
5616 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
5617 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
5618 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(F64
, F32
, F32
, F64
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test58_f1
));
5620 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
), SLJIT_FR0
, 0);
5622 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
5623 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
));
5624 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
));
5625 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS3(F64
, F32
, F32
, F64
));
5626 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test58_f1
));
5628 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5630 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test58_f2
));
5631 sljit_get_local_base(compiler
, SLJIT_R1
, 0, -16);
5632 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
5633 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
5634 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
5635 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(F32
, W
, F64
, F32
), SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 0);
5637 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
5639 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -4);
5640 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 9);
5641 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0);
5642 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
5643 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS3(F64
, W
, F32
, W
));
5644 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test58_f3
));
5646 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5648 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
5649 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -6);
5650 jump
= sljit_emit_call(compiler
, SLJIT_CALL_CDECL
, SLJIT_ARGS2(F64
, F32
, W
));
5651 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test58_f4
));
5653 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5655 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test58_f5
));
5656 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
));
5657 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
));
5658 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5659 sljit_emit_icall(compiler
, SLJIT_CALL_CDECL
, SLJIT_ARGS3(F32
, F32
, F64
, 32), SLJIT_MEM1(SLJIT_SP
), 0);
5661 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
5663 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
));
5664 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test58_f6
));
5665 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS2(W
, F64
, W
), SLJIT_R0
, 0);
5667 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), 0, SLJIT_R0
, 0);
5669 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
));
5670 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 319);
5671 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test58_f6
));
5672 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS2(W
, F64
, W
), SLJIT_R1
, 0);
5674 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_sw
), SLJIT_R0
, 0);
5676 sljit_emit_return_void(compiler
);
5678 code
.code
= sljit_generate_code(compiler
);
5680 sljit_free_compiler(compiler
);
5682 code
.func3((sljit_sw
)&dbuf
, (sljit_sw
)&sbuf
, (sljit_sw
)&wbuf
);
5684 FAILED(dbuf
[1] != 8.5, "test58 case 1 failed\n");
5685 FAILED(dbuf
[3] != 0.5, "test58 case 2 failed\n");
5686 FAILED(sbuf
[3] != 17.75, "test58 case 3 failed\n");
5687 FAILED(dbuf
[4] != 11.75, "test58 case 4 failed\n");
5688 FAILED(dbuf
[5] != -9.5, "test58 case 5 failed\n");
5689 FAILED(sbuf
[4] != 12, "test58 case 6 failed\n");
5690 FAILED(wbuf
[0] != SLJIT_FUNC_ADDR(test58_f6
) - 18, "test58 case 7 failed\n");
5691 FAILED(wbuf
[1] != 301, "test58 case 8 failed\n");
5693 sljit_free_code(code
.code
, NULL
);
5697 static sljit_sw SLJIT_FUNC
test59_f1(sljit_sw a
, sljit_s32 b
, sljit_sw c
, sljit_sw d
)
5699 return (sljit_sw
)(a
+ b
+ c
+ d
- SLJIT_FUNC_ADDR(test59_f1
));
5702 static sljit_sw
test59_f2(sljit_sw a
, sljit_s32 b
, sljit_sw c
, sljit_sw d
)
5704 return (sljit_sw
)(a
+ b
+ c
+ d
- SLJIT_FUNC_ADDR(test59_f2
));
5707 static sljit_s32 SLJIT_FUNC
test59_f3(sljit_f64 a
, sljit_f32 b
, sljit_f64 c
, sljit_sw d
)
5709 return (sljit_s32
)(a
+ b
+ c
+ (sljit_f64
)d
);
5712 static sljit_f32 SLJIT_FUNC
test59_f4(sljit_f32 a
, sljit_s32 b
, sljit_f64 c
, sljit_sw d
)
5714 return (sljit_f32
)(a
+ (sljit_f64
)b
+ c
+ (sljit_f64
)d
);
5717 static sljit_f32 SLJIT_FUNC
test59_f5(sljit_f32 a
, sljit_f64 b
, sljit_f32 c
, sljit_f64 d
)
5719 return (sljit_f32
)(a
+ b
+ c
+ (sljit_f64
)d
);
5722 static void test59(void)
5724 /* Check function calls with four arguments. */
5725 executable_code code
;
5726 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5727 struct sljit_jump
* jump
= NULL
;
5733 printf("Run test59\n");
5738 wbuf
[3] = SLJIT_FUNC_ADDR(test59_f1
);
5742 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5753 FAILED(!compiler
, "cannot create compiler\n");
5755 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 4, 3, 4, 0, sizeof(sljit_sw
));
5757 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 33);
5758 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -20);
5759 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f1
));
5760 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -40);
5761 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS4(W
, W
, 32, W
, W
), SLJIT_R2
, 0);
5763 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
5765 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
5766 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -30);
5767 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 50);
5768 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f2
));
5769 sljit_emit_icall(compiler
, SLJIT_CALL_CDECL
, SLJIT_ARGS4(W
, W
, 32, W
, W
), SLJIT_R3
, 0);
5771 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
5773 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f1
));
5774 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -25);
5775 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 100);
5776 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -10);
5777 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS4(W
, W
, 32, W
, W
), SLJIT_R0
, 0);
5779 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5781 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
5782 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 231);
5783 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 3);
5784 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f1
) - 100);
5785 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS4(W
, W
, 32, W
, W
), SLJIT_MEM2(SLJIT_R0
, SLJIT_R2
), SLJIT_WORD_SHIFT
);
5787 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5789 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5790 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
5791 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S2
), 0);
5792 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
));
5793 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -100);
5794 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS4(32, F64
, F32
, F64
, W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f3
));
5795 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
5797 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5799 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
5800 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f64
));
5801 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 36);
5802 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 41);
5803 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS4(F32
, F32
, 32, F64
, W
));
5804 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test59_f4
));
5806 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
5808 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f5
));
5809 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S2
), 0);
5810 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
5811 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
5812 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f64
));
5813 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS4(F32
, F32
, F64
, F32
, F64
), SLJIT_R0
, 0);
5815 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S2
), 3 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
5818 sljit_emit_return_void(compiler
);
5820 code
.code
= sljit_generate_code(compiler
);
5822 sljit_free_compiler(compiler
);
5824 code
.func3((sljit_sw
)&wbuf
, (sljit_sw
)&dbuf
, (sljit_sw
)&sbuf
);
5826 FAILED(wbuf
[0] != -27, "test59 case 1 failed\n");
5827 FAILED(wbuf
[1] != 36, "test59 case 2 failed\n");
5828 FAILED(wbuf
[2] != 65, "test59 case 3 failed\n");
5829 FAILED(wbuf
[4] != (sljit_sw
)wbuf
+ 134, "test59 case 4 failed\n");
5831 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5832 FAILED(wbuf
[5] != -88, "test59 case 5 failed\n");
5833 FAILED(sbuf
[2] != 79.75, "test59 case 6 failed\n");
5834 FAILED(sbuf
[3] != 8.625, "test59 case 7 failed\n");
5837 sljit_free_code(code
.code
, NULL
);
5841 static void test60(void)
5843 /* Test memory accesses with pre/post updates. */
5844 executable_code code
;
5845 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5847 sljit_s32 supported
[10];
5852 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
5853 static sljit_u8 expected
[10] = { 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 };
5854 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
5855 static sljit_u8 expected
[10] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
5856 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32)
5857 static sljit_u8 expected
[10] = { 1, 0, 1, 1, 0, 1, 1, 1, 0, 0 };
5858 #elif (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
5859 static sljit_u8 expected
[10] = { 1, 0, 0, 1, 0, 0, 1, 1, 0, 0 };
5861 static sljit_u8 expected
[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
5865 printf("Run test60\n");
5867 for (i
= 0; i
< 18; i
++)
5879 FAILED(!compiler
, "cannot create compiler\n");
5881 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 4, 3, 4, 0, sizeof(sljit_sw
));
5883 supported
[0] = sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_sw
));
5884 if (supported
[0] == SLJIT_SUCCESS
) {
5885 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
5886 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_sw
));
5887 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
5888 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
5891 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
));
5892 if (supported
[1] == SLJIT_SUCCESS
) {
5893 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s8
));
5894 sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM1(SLJIT_R2
), -2 * (sljit_sw
)sizeof(sljit_s8
));
5895 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5896 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R2
, 0);
5899 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
));
5900 if (supported
[2] == SLJIT_SUCCESS
) {
5901 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s32
));
5902 sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_PRE
, SLJIT_R2
, SLJIT_MEM1(SLJIT_R1
), -2 * (sljit_sw
)sizeof(sljit_s32
));
5903 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R2
, 0);
5904 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5907 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
));
5908 if (supported
[3] == SLJIT_SUCCESS
) {
5909 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -8765);
5910 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, sizeof(sljit_s32
));
5911 sljit_emit_mem(compiler
, SLJIT_MOV32
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R2
), 2 * sizeof(sljit_s32
));
5912 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R2
, 0);
5915 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
));
5916 if (supported
[4] == SLJIT_SUCCESS
) {
5917 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -121);
5918 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_S1
, 0);
5919 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
));
5920 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R2
, 0);
5923 supported
[5] = sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 1);
5924 if (supported
[5] == SLJIT_SUCCESS
) {
5925 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 9 * sizeof(sljit_sw
) - 1);
5926 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -881199);
5927 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 1);
5928 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5931 supported
[6] = sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5932 if (supported
[6] == SLJIT_SUCCESS
) {
5933 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 213);
5934 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -213);
5935 sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_PRE
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5936 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5937 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5940 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);
5941 if (supported
[7] == SLJIT_SUCCESS
) {
5942 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_S2
, 0);
5943 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s32
));
5944 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -7890);
5945 sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5946 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5949 supported
[8] = sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 2);
5950 if (supported
[8] == SLJIT_SUCCESS
) {
5951 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 2 * sizeof(sljit_sw
));
5952 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2 * sizeof(sljit_sw
));
5953 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 2);
5954 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5955 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5958 supported
[9] = sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5959 if (supported
[9] == SLJIT_SUCCESS
) {
5960 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s8
));
5961 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -2 * (sljit_sw
)sizeof(sljit_s8
));
5962 sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5963 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5964 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5967 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
);
5968 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
);
5970 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
5971 /* TODO: at least for ARM (both V5 and V7) the range below needs further fixing */
5972 SLJIT_ASSERT(sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 256) == SLJIT_ERR_UNSUPPORTED
);
5973 SLJIT_ASSERT(sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), -257) == SLJIT_ERR_UNSUPPORTED
);
5976 sljit_emit_return_void(compiler
);
5978 code
.code
= sljit_generate_code(compiler
);
5980 sljit_free_compiler(compiler
);
5982 code
.func3((sljit_sw
)&wbuf
, (sljit_sw
)&bbuf
, (sljit_sw
)&ibuf
);
5984 FAILED(sizeof(expected
) != sizeof(supported
) / sizeof(sljit_s32
), "test60 case 1 failed\n");
5986 for (i
= 0; i
< sizeof(expected
); i
++) {
5988 if (supported
[i
] != SLJIT_SUCCESS
) {
5989 printf("tast60 case %d should be supported\n", i
+ 1);
5993 if (supported
[i
] == SLJIT_SUCCESS
) {
5994 printf("test60 case %d should not be supported\n", i
+ 1);
6000 FAILED(supported
[0] == SLJIT_SUCCESS
&& wbuf
[0] != -887766, "test60 case 2 failed\n");
6001 FAILED(supported
[0] == SLJIT_SUCCESS
&& wbuf
[1] != (sljit_sw
)(wbuf
+ 2), "test60 case 3 failed\n");
6002 FAILED(supported
[1] == SLJIT_SUCCESS
&& wbuf
[3] != -13, "test60 case 4 failed\n");
6003 FAILED(supported
[1] == SLJIT_SUCCESS
&& wbuf
[4] != (sljit_sw
)(bbuf
), "test60 case 5 failed\n");
6004 FAILED(supported
[2] == SLJIT_SUCCESS
&& wbuf
[5] != -5678, "test60 case 6 failed\n");
6005 FAILED(supported
[2] == SLJIT_SUCCESS
&& wbuf
[6] != (sljit_sw
)(ibuf
), "test60 case 7 failed\n");
6006 FAILED(supported
[3] == SLJIT_SUCCESS
&& ibuf
[1] != -8765, "test60 case 8 failed\n");
6007 FAILED(supported
[3] == SLJIT_SUCCESS
&& wbuf
[7] != (sljit_sw
)(ibuf
+ 1), "test60 case 9 failed\n");
6008 FAILED(supported
[4] == SLJIT_SUCCESS
&& bbuf
[0] != -121, "test60 case 10 failed\n");
6009 FAILED(supported
[4] == SLJIT_SUCCESS
&& wbuf
[8] != (sljit_sw
)(bbuf
) - 128 * (sljit_sw
)sizeof(sljit_s8
), "test60 case 11 failed\n");
6010 FAILED(supported
[5] == SLJIT_SUCCESS
&& wbuf
[9] != -881199, "test60 case 12 failed\n");
6011 FAILED(supported
[5] == SLJIT_SUCCESS
&& wbuf
[10] != (sljit_sw
)(wbuf
+ 9), "test60 case 13 failed\n");
6012 FAILED(supported
[6] == SLJIT_SUCCESS
&& wbuf
[11] != -5678, "test60 case 14 failed\n");
6013 FAILED(supported
[6] == SLJIT_SUCCESS
&& wbuf
[12] != (sljit_sw
)(ibuf
), "test60 case 15 failed\n");
6014 FAILED(supported
[7] == SLJIT_SUCCESS
&& ibuf
[2] != -7890, "test60 case 16 failed\n");
6015 FAILED(supported
[7] == SLJIT_SUCCESS
&& wbuf
[13] != (sljit_sw
)(ibuf
+ 2), "test60 case 17 failed\n");
6016 FAILED(supported
[8] == SLJIT_SUCCESS
&& wbuf
[14] != -887766, "test60 case 18 failed\n");
6017 FAILED(supported
[8] == SLJIT_SUCCESS
&& wbuf
[15] != (sljit_sw
)(wbuf
+ 10), "test60 case 19 failed\n");
6018 FAILED(supported
[9] == SLJIT_SUCCESS
&& wbuf
[16] != -13, "test60 case 20 failed\n");
6019 FAILED(supported
[9] == SLJIT_SUCCESS
&& wbuf
[17] != (sljit_sw
)(bbuf
), "test60 case 21 failed\n");
6021 sljit_free_code(code
.code
, NULL
);
6025 static void test61(void)
6027 /* Test float memory accesses with pre/post updates. */
6028 executable_code code
;
6029 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6031 sljit_s32 supported
[6];
6035 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
6036 static sljit_u8 expected
[6] = { 1, 1, 1, 1, 0, 0 };
6037 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
6038 static sljit_u8 expected
[6] = { 1, 0, 1, 0, 1, 1 };
6040 static sljit_u8 expected
[6] = { 0, 0, 0, 0, 0, 0 };
6043 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
6045 printf("no fpu available, test61 skipped\n");
6048 sljit_free_compiler(compiler
);
6053 printf("Run test61\n");
6055 for (i
= 0; i
< 6; i
++)
6068 FAILED(!compiler
, "cannot create compiler\n");
6070 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 4, 3, 4, 0, sizeof(sljit_sw
));
6072 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
));
6073 if (supported
[0] == SLJIT_SUCCESS
) {
6074 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 4 * sizeof(sljit_f64
));
6075 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_PRE
, SLJIT_FR0
, SLJIT_MEM1(SLJIT_R0
), 4 * sizeof(sljit_f64
));
6076 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
), SLJIT_FR0
, 0);
6077 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
6080 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
));
6081 if (supported
[1] == SLJIT_SUCCESS
) {
6082 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 2 * sizeof(sljit_f64
));
6083 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
6084 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_STORE
| SLJIT_MEM_POST
, SLJIT_FR2
, SLJIT_MEM1(SLJIT_R0
), -(sljit_sw
)sizeof(sljit_f64
));
6085 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
6088 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
));
6089 if (supported
[2] == SLJIT_SUCCESS
) {
6090 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 4 * sizeof(sljit_f32
));
6091 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
6092 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
));
6093 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R2
, 0);
6096 supported
[3] = sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_FR1
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_f32
));
6097 if (supported
[3] == SLJIT_SUCCESS
) {
6098 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S2
, 0, SLJIT_IMM
, sizeof(sljit_f32
));
6099 sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_POST
, SLJIT_FR1
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_f32
));
6100 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_f32
), SLJIT_FR1
, 0);
6101 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R1
, 0);
6104 supported
[4] = sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_FR0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 0);
6105 if (supported
[4] == SLJIT_SUCCESS
) {
6106 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 8 * sizeof(sljit_f64
));
6107 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -8 * (sljit_sw
)sizeof(sljit_f64
));
6108 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_PRE
, SLJIT_FR0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 0);
6109 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
6110 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R1
, 0);
6113 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);
6114 if (supported
[5] == SLJIT_SUCCESS
) {
6115 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_S2
, 0);
6116 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3 * sizeof(sljit_f32
));
6117 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
6118 sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_FR2
, SLJIT_MEM2(SLJIT_R2
, SLJIT_R1
), 0);
6119 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R2
, 0);
6122 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
);
6123 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
);
6125 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
6126 /* TODO: at least for ARM (both V5 and V7) the range below needs further fixing */
6127 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
);
6128 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
);
6131 sljit_emit_return_void(compiler
);
6133 code
.code
= sljit_generate_code(compiler
);
6135 sljit_free_compiler(compiler
);
6137 code
.func3((sljit_sw
)&wbuf
, (sljit_sw
)&dbuf
, (sljit_sw
)&sbuf
);
6139 FAILED(sizeof(expected
) != sizeof(supported
) / sizeof(sljit_s32
), "test61 case 1 failed\n");
6141 for (i
= 0; i
< sizeof(expected
); i
++) {
6143 if (supported
[i
] != SLJIT_SUCCESS
) {
6144 printf("tast61 case %d should be supported\n", i
+ 1);
6148 if (supported
[i
] == SLJIT_SUCCESS
) {
6149 printf("test61 case %d should not be supported\n", i
+ 1);
6155 FAILED(supported
[0] == SLJIT_SUCCESS
&& dbuf
[1] != 66.725, "test61 case 2 failed\n");
6156 FAILED(supported
[0] == SLJIT_SUCCESS
&& wbuf
[0] != (sljit_sw
)(dbuf
), "test61 case 3 failed\n");
6157 FAILED(supported
[1] == SLJIT_SUCCESS
&& dbuf
[2] != 66.725, "test61 case 4 failed\n");
6158 FAILED(supported
[1] == SLJIT_SUCCESS
&& wbuf
[1] != (sljit_sw
)(dbuf
+ 1), "test61 case 5 failed\n");
6159 FAILED(supported
[2] == SLJIT_SUCCESS
&& sbuf
[0] != -22.125, "test61 case 6 failed\n");
6160 FAILED(supported
[2] == SLJIT_SUCCESS
&& wbuf
[2] != (sljit_sw
)(sbuf
), "test61 case 7 failed\n");
6161 FAILED(supported
[3] == SLJIT_SUCCESS
&& sbuf
[2] != -22.125, "test61 case 8 failed\n");
6162 FAILED(supported
[3] == SLJIT_SUCCESS
&& wbuf
[3] != (sljit_sw
)(sbuf
+ 2), "test61 case 9 failed\n");
6163 FAILED(supported
[4] == SLJIT_SUCCESS
&& dbuf
[3] != 66.725, "test61 case 10 failed\n");
6164 FAILED(supported
[4] == SLJIT_SUCCESS
&& wbuf
[4] != (sljit_sw
)(dbuf
), "test61 case 11 failed\n");
6165 FAILED(supported
[5] == SLJIT_SUCCESS
&& sbuf
[3] != -22.125, "test61 case 12 failed\n");
6166 FAILED(supported
[5] == SLJIT_SUCCESS
&& wbuf
[5] != (sljit_sw
)(sbuf
+ 3), "test61 case 13 failed\n");
6168 sljit_free_code(code
.code
, NULL
);
6172 static void test62(void)
6174 /* Test fast calls flag preservation. */
6175 executable_code code1
;
6176 executable_code code2
;
6177 struct sljit_compiler
* compiler
;
6180 printf("Run test62\n");
6183 compiler
= sljit_create_compiler(NULL
, NULL
);
6184 FAILED(!compiler
, "cannot create compiler\n");
6185 sljit_set_context(compiler
, 0, SLJIT_ARGS1(W
, W
), 1, 1, 0, 0, 0);
6187 sljit_emit_fast_enter(compiler
, SLJIT_R0
, 0);
6188 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_S0
, 0, SLJIT_IMM
, 42);
6189 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R0
, 0);
6191 code1
.code
= sljit_generate_code(compiler
);
6193 sljit_free_compiler(compiler
);
6196 compiler
= sljit_create_compiler(NULL
, NULL
);
6197 FAILED(!compiler
, "cannot create compiler\n");
6199 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, W
), 1, 1, 0, 0, 0);
6200 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_ADDR(code1
.code
));
6201 sljit_set_current_flags(compiler
, SLJIT_CURRENT_FLAGS_ADD_SUB
| SLJIT_CURRENT_FLAGS_COMPARE
| SLJIT_SET_Z
| SLJIT_SET_LESS
);
6202 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_ZERO
);
6203 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_LESS
);
6204 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
6205 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S0
, 0);
6206 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
6208 code2
.code
= sljit_generate_code(compiler
);
6210 sljit_free_compiler(compiler
);
6212 FAILED(code2
.func1(88) != 0, "test62 case 1 failed\n");
6213 FAILED(code2
.func1(42) != 1, "test62 case 2 failed\n");
6214 FAILED(code2
.func1(0) != 2, "test62 case 3 failed\n");
6216 sljit_free_code(code1
.code
, NULL
);
6217 sljit_free_code(code2
.code
, NULL
);
6221 static void test63(void)
6223 /* Test put label. */
6224 executable_code code
;
6225 struct sljit_label
*label
[2];
6226 struct sljit_put_label
*put_label
[5];
6227 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6230 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
6231 sljit_sw offs
= SLJIT_W(0x123456789012);
6233 sljit_sw offs
= 0x12345678;
6237 printf("Run test63\n");
6239 FAILED(!compiler
, "cannot create compiler\n");
6245 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 2 * sizeof(sljit_sw
));
6247 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_R0
, 0);
6248 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
6250 put_label
[1] = sljit_emit_put_label(compiler
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
));
6251 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
));
6253 label
[0] = sljit_emit_label(compiler
);
6254 sljit_set_put_label(put_label
[0], label
[0]);
6255 sljit_set_put_label(put_label
[1], label
[0]);
6257 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)(buf
+ 2) - offs
);
6258 put_label
[2] = sljit_emit_put_label(compiler
, SLJIT_MEM1(SLJIT_R0
), offs
);
6260 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (offs
+ (sljit_sw
)sizeof(sljit_uw
)) >> 1);
6261 put_label
[3] = sljit_emit_put_label(compiler
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1);
6263 label
[1] = sljit_emit_label(compiler
);
6264 sljit_set_put_label(put_label
[2], label
[1]);
6265 sljit_set_put_label(put_label
[3], label
[1]);
6267 put_label
[4] = sljit_emit_put_label(compiler
, SLJIT_RETURN_REG
, 0);
6268 sljit_set_put_label(put_label
[4], label
[0]);
6269 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
6271 code
.code
= sljit_generate_code(compiler
);
6274 addr
[0] = sljit_get_label_addr(label
[0]);
6275 addr
[1] = sljit_get_label_addr(label
[1]);
6277 sljit_free_compiler(compiler
);
6279 FAILED(code
.func1((sljit_sw
)&buf
) != (sljit_sw
)addr
[0], "test63 case 1 failed\n");
6280 FAILED(buf
[0] != addr
[0], "test63 case 2 failed\n");
6281 FAILED(buf
[1] != addr
[0], "test63 case 3 failed\n");
6282 FAILED(buf
[2] != addr
[1], "test63 case 4 failed\n");
6283 FAILED(buf
[3] != addr
[1], "test63 case 5 failed\n");
6285 sljit_free_code(code
.code
, NULL
);
6289 static void test64(void)
6291 /* Test put label with absolute label addresses */
6292 executable_code code
;
6293 sljit_uw malloc_addr
;
6294 struct sljit_label label
[4];
6295 struct sljit_put_label
*put_label
[2];
6296 struct sljit_compiler
* compiler
;
6298 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
6299 sljit_sw offs1
= SLJIT_W(0x123456781122);
6300 sljit_sw offs2
= SLJIT_W(0x1234567811223344);
6301 #else /* !SLJIT_64BIT_ARCHITECTURE */
6302 sljit_sw offs1
= 0x12345678;
6303 sljit_sw offs2
= (sljit_sw
)0x80000000;
6304 #endif /* SLJIT_64BIT_ARCHITECTURE */
6307 printf("Run test64\n");
6309 /* lock next allocation; see sljit_test_malloc_exec() */
6310 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
6311 malloc_addr
= (sljit_uw
)SLJIT_MALLOC_EXEC(1024, NULL
);
6314 printf("Cannot allocate executable memory\n");
6318 compiler
= sljit_create_compiler(NULL
, (void*)malloc_addr
);
6319 malloc_addr
+= (sljit_uw
)SLJIT_EXEC_OFFSET((void*)malloc_addr
);
6320 #else /* SLJIT_CONFIG_UNSUPPORTED */
6322 compiler
= sljit_create_compiler(NULL
, (void*)malloc_addr
);
6323 #endif /* !SLJIT_CONFIG_UNSUPPORTED */
6325 label
[0].addr
= 0x1234;
6326 label
[0].size
= (sljit_uw
)0x1234 - malloc_addr
;
6328 label
[1].addr
= 0x12345678;
6329 label
[1].size
= (sljit_uw
)0x12345678 - malloc_addr
;
6331 label
[2].addr
= (sljit_uw
)offs1
;
6332 label
[2].size
= (sljit_uw
)offs1
- malloc_addr
;
6334 label
[3].addr
= (sljit_uw
)offs2
;
6335 label
[3].size
= (sljit_uw
)offs2
- malloc_addr
;
6337 FAILED(!compiler
, "cannot create compiler\n");
6344 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 2 * sizeof(sljit_sw
));
6346 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_R0
, 0);
6347 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
6349 put_label
[1] = sljit_emit_put_label(compiler
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
));
6350 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
));
6352 sljit_set_put_label(put_label
[0], &label
[0]);
6353 sljit_set_put_label(put_label
[1], &label
[0]);
6355 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)(buf
+ 2) - offs1
);
6356 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_MEM1(SLJIT_R0
), offs1
);
6358 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (offs1
+ (sljit_sw
)sizeof(sljit_uw
)) >> 1);
6359 put_label
[1] = sljit_emit_put_label(compiler
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1);
6361 sljit_set_put_label(put_label
[0], &label
[1]);
6362 sljit_set_put_label(put_label
[1], &label
[1]);
6364 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_R2
, 0);
6365 sljit_set_put_label(put_label
[0], &label
[2]);
6366 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_uw
), SLJIT_R2
, 0);
6368 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_RETURN_REG
, 0);
6369 sljit_set_put_label(put_label
[0], &label
[3]);
6370 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
6372 code
.code
= sljit_generate_code(compiler
);
6374 sljit_free_compiler(compiler
);
6375 SLJIT_ASSERT(SLJIT_FUNC_UADDR(code
.code
) >= malloc_addr
&& SLJIT_FUNC_UADDR(code
.code
) <= malloc_addr
+ 8);
6377 FAILED(code
.func1((sljit_sw
)&buf
) != (sljit_sw
)label
[3].addr
, "test64 case 1 failed\n");
6378 FAILED(buf
[0] != label
[0].addr
, "test64 case 2 failed\n");
6379 FAILED(buf
[1] != label
[0].addr
, "test64 case 3 failed\n");
6380 FAILED(buf
[2] != label
[1].addr
, "test64 case 4 failed\n");
6381 FAILED(buf
[3] != label
[1].addr
, "test64 case 5 failed\n");
6382 FAILED(buf
[4] != label
[2].addr
, "test64 case 6 failed\n");
6384 sljit_free_code(code
.code
, NULL
);
6389 static void test65(void)
6391 /* Test jump tables. */
6392 executable_code code
;
6393 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6395 /* Normally this table is allocated on the heap. */
6397 struct sljit_label
*labels
[64];
6398 struct sljit_jump
*jump
;
6401 printf("Run test65\n");
6403 FAILED(!compiler
, "cannot create compiler\n");
6405 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(W
, W
, W
), 1, 2, 0, 0, 0);
6407 jump
= sljit_emit_cmp(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_S0
, 0, SLJIT_IMM
, 64);
6408 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)addr
);
6409 sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_MEM2(SLJIT_R0
, SLJIT_S0
), SLJIT_WORD_SHIFT
);
6411 for (i
= 0; i
< 64; i
++) {
6412 labels
[i
] = sljit_emit_label(compiler
);
6413 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
6414 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, i
* 2);
6415 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
6418 sljit_set_label(jump
, sljit_emit_label(compiler
));
6419 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, -1);
6421 code
.code
= sljit_generate_code(compiler
);
6424 for (i
= 0; i
< 64; i
++) {
6425 addr
[i
] = sljit_get_label_addr(labels
[i
]);
6428 sljit_free_compiler(compiler
);
6430 FAILED(code
.func2(64, 0) != -1, "test65 case 1 failed\n");
6432 for (i
= 0; i
< 64; i
++) {
6433 FAILED(code
.func2(i
, i
* 2) != i
* 4, "test65 case 2 failed\n");
6436 sljit_free_code(code
.code
, NULL
);
6440 static void test66(void)
6442 /* Test direct jumps (computed goto). */
6443 executable_code code
;
6444 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6447 struct sljit_label
*labels
[64];
6450 printf("Run test66\n");
6452 FAILED(!compiler
, "cannot create compiler\n");
6454 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(W
, W
, W
), 1, 2, 0, 0, 0);
6455 sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_S0
, 0);
6457 for (i
= 0; i
< 64; i
++) {
6458 labels
[i
] = sljit_emit_label(compiler
);
6459 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
6460 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, i
* 2);
6461 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
6464 code
.code
= sljit_generate_code(compiler
);
6467 for (i
= 0; i
< 64; i
++) {
6468 addr
[i
] = sljit_get_label_addr(labels
[i
]);
6471 sljit_free_compiler(compiler
);
6473 for (i
= 0; i
< 64; i
++) {
6474 FAILED(code
.func2((sljit_sw
)addr
[i
], i
) != i
* 3, "test66 case 1 failed\n");
6477 sljit_free_code(code
.code
, NULL
);
6481 static void test67(void)
6483 /* Test skipping returns from fast calls (return type is fast). */
6484 executable_code code
;
6485 struct sljit_compiler
*compiler
= sljit_create_compiler(NULL
, NULL
);
6486 struct sljit_jump
*call
, *jump
;
6487 struct sljit_label
*label
;
6490 printf("Run test67\n");
6492 FAILED(!compiler
, "cannot create compiler\n");
6494 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), 3, 1, 0, 0, 0);
6496 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
6497 call
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
);
6499 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
6501 /* First function, never returns. */
6502 label
= sljit_emit_label(compiler
);
6503 sljit_set_label(call
, label
);
6504 sljit_emit_fast_enter(compiler
, SLJIT_R1
, 0);
6506 call
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
);
6508 /* Should never return here, marked by a segmentation fault if it does. */
6509 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
6511 /* Second function, skips the first function. */
6512 sljit_set_label(call
, sljit_emit_label(compiler
));
6513 sljit_emit_fast_enter(compiler
, SLJIT_R2
, 0);
6515 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
6517 jump
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
6519 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_R1
, 0);
6520 sljit_set_label(sljit_emit_jump(compiler
, SLJIT_FAST_CALL
), label
);
6521 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
6522 sljit_emit_op_src(compiler
, SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN
, SLJIT_S0
, 0);
6523 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_S0
, 0);
6525 sljit_set_label(jump
, sljit_emit_label(compiler
));
6526 sljit_emit_op_src(compiler
, SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN
, SLJIT_R1
, 0);
6527 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R1
, 0);
6529 code
.code
= sljit_generate_code(compiler
);
6532 sljit_free_compiler(compiler
);
6534 FAILED(code
.func0() != 3, "test67 case 1 failed\n");
6536 sljit_free_code(code
.code
, NULL
);
6540 static void test68(void)
6542 /* Test skipping returns from fast calls (return type is normal). */
6543 executable_code code
;
6544 struct sljit_compiler
*compiler
;
6545 struct sljit_jump
*call
, *jump
;
6546 struct sljit_label
*label
;
6550 printf("Run test68\n");
6552 for (i
= 0; i
< 6; i
++) {
6553 compiler
= sljit_create_compiler(NULL
, NULL
);
6554 FAILED(!compiler
, "cannot create compiler\n");
6556 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), 2 + (i
% 6), (i
% 6), 0, 0, 0);
6558 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
6559 call
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
);
6561 /* Should never return here, marked by a segmentation fault if it does. */
6562 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
6564 /* Recursive fast call. */
6565 label
= sljit_emit_label(compiler
);
6566 sljit_set_label(call
, label
);
6567 sljit_emit_fast_enter(compiler
, SLJIT_R1
, 0);
6569 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
6571 jump
= sljit_emit_cmp(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
6573 sljit_set_label(sljit_emit_jump(compiler
, SLJIT_FAST_CALL
), label
);
6575 sljit_set_label(jump
, sljit_emit_label(compiler
));
6576 sljit_emit_op0(compiler
, SLJIT_SKIP_FRAMES_BEFORE_RETURN
);
6577 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
6579 code
.code
= sljit_generate_code(compiler
);
6582 sljit_free_compiler(compiler
);
6584 if (SLJIT_UNLIKELY(code
.func0() != 4)) {
6585 printf("test68 case %d failed\n", i
+ 1);
6588 sljit_free_code(code
.code
, NULL
);
6594 static void test69(void)
6596 /* Test sljit_set_current_flags. */
6597 executable_code code
;
6598 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6603 printf("Run test69\n");
6605 for (i
= 0; i
< 8; i
++)
6608 FAILED(!compiler
, "cannot create compiler\n");
6610 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 0, 0, 0);
6612 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)1 << ((sizeof (sljit_sw
) * 8) - 2));
6613 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_R0
, 0);
6614 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
6615 sljit_emit_label(compiler
);
6616 sljit_set_current_flags(compiler
, SLJIT_SET_OVERFLOW
| SLJIT_CURRENT_FLAGS_ADD_SUB
);
6617 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_OVERFLOW
);
6619 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
6620 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
6621 sljit_emit_label(compiler
);
6622 sljit_set_current_flags(compiler
, SLJIT_SET_OVERFLOW
| SLJIT_CURRENT_FLAGS_ADD_SUB
);
6623 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_OVERFLOW
);
6625 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_R0
, 0);
6626 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
6627 sljit_emit_label(compiler
);
6628 sljit_set_current_flags(compiler
, SLJIT_SET_OVERFLOW
);
6629 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
6631 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
6632 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R1
, 0);
6633 sljit_emit_label(compiler
);
6634 sljit_set_current_flags(compiler
, SLJIT_SET_OVERFLOW
);
6635 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
6637 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 6);
6638 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 5);
6639 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R1
, 0, SLJIT_R2
, 0);
6640 sljit_emit_label(compiler
);
6641 sljit_set_current_flags(compiler
, SLJIT_SET_GREATER
| SLJIT_CURRENT_FLAGS_ADD_SUB
| SLJIT_CURRENT_FLAGS_COMPARE
);
6642 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_GREATER
);
6644 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R2
, 0);
6645 sljit_emit_label(compiler
);
6646 sljit_set_current_flags(compiler
, SLJIT_SET_Z
| SLJIT_CURRENT_FLAGS_ADD_SUB
| SLJIT_CURRENT_FLAGS_COMPARE
);
6647 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_ZERO
);
6649 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 1 << 31);
6650 sljit_emit_op2u(compiler
, SLJIT_ADD32
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R1
, 0);
6651 sljit_emit_label(compiler
);
6652 sljit_set_current_flags(compiler
, SLJIT_SET_Z
| SLJIT_CURRENT_FLAGS_32
| SLJIT_CURRENT_FLAGS_ADD_SUB
);
6653 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_ZERO
);
6655 sljit_emit_op2u(compiler
, SLJIT_SHL32
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
6656 sljit_emit_label(compiler
);
6657 sljit_set_current_flags(compiler
, SLJIT_SET_Z
| SLJIT_CURRENT_FLAGS_32
);
6658 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_NOT_ZERO
);
6660 sljit_emit_return_void(compiler
);
6662 code
.code
= sljit_generate_code(compiler
);
6664 sljit_free_compiler(compiler
);
6666 code
.func1((sljit_sw
)&buf
);
6668 FAILED(buf
[0] != 1, "test69 case 1 failed\n");
6669 FAILED(buf
[1] != 2, "test69 case 2 failed\n");
6670 FAILED(buf
[2] != 1, "test69 case 3 failed\n");
6671 FAILED(buf
[3] != 2, "test69 case 4 failed\n");
6672 FAILED(buf
[4] != 1, "test69 case 5 failed\n");
6673 FAILED(buf
[5] != 2, "test69 case 6 failed\n");
6674 FAILED(buf
[6] != 1, "test69 case 7 failed\n");
6675 FAILED(buf
[7] != 2, "test69 case 8 failed\n");
6677 sljit_free_code(code
.code
, NULL
);
6681 static void test70(void)
6683 /* Test argument passing to sljit_emit_enter. */
6684 executable_code code
;
6685 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6692 printf("Run test70\n");
6699 FAILED(!compiler
, "cannot create compiler\n");
6701 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, 32, W
, 32, W
), 1, 4, 0, 0, 0);
6702 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
6703 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S1
, 0);
6704 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_S3
, 0);
6705 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
6706 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
6707 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_s32
), SLJIT_S2
, 0);
6708 sljit_emit_return_void(compiler
);
6710 code
.code
= sljit_generate_code(compiler
);
6712 sljit_free_compiler(compiler
);
6714 code
.test70_f1(-1478, 9476, 4928, -6832);
6716 FAILED(wbuf
[0] != 9476, "test70 case 1 failed\n");
6717 FAILED(wbuf
[1] != -6832, "test70 case 2 failed\n");
6718 FAILED(ibuf
[0] != -1478, "test70 case 3 failed\n");
6719 FAILED(ibuf
[1] != 4928, "test70 case 4 failed\n");
6721 sljit_free_code(code
.code
, NULL
);
6723 compiler
= sljit_create_compiler(NULL
, NULL
);
6724 FAILED(!compiler
, "cannot create compiler\n");
6726 sljit_emit_enter(compiler
, SLJIT_ENTER_CDECL
, SLJIT_ARGS4(VOID
, 32, 32, W
, W
), 1, 4, 0, 0, 0);
6727 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
6728 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
6729 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_S1
, 0);
6730 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
6731 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S2
, 0);
6732 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_s32
), SLJIT_S3
, 0);
6733 sljit_emit_return_void(compiler
);
6735 code
.code
= sljit_generate_code(compiler
);
6737 sljit_free_compiler(compiler
);
6739 code
.test70_f2(4721, 7892, -3579, -4830);
6741 FAILED(wbuf
[0] != 4721, "test70 case 5 failed\n");
6742 FAILED(wbuf
[1] != 7892, "test70 case 6 failed\n");
6743 FAILED(ibuf
[0] != -3579, "test70 case 7 failed\n");
6744 FAILED(ibuf
[1] != -4830, "test70 case 8 failed\n");
6746 sljit_free_code(code
.code
, NULL
);
6748 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
6754 compiler
= sljit_create_compiler(NULL
, NULL
);
6755 FAILED(!compiler
, "cannot create compiler\n");
6757 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, 32, F32
, W
, F64
), 2, 2, 2, 0, 0);
6758 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)&wbuf
, SLJIT_S1
, 0);
6759 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&ibuf
, SLJIT_S0
, 0);
6760 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&dbuf
, SLJIT_FR1
, 0);
6761 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM0(), (sljit_sw
)&fbuf
, SLJIT_FR0
, 0);
6762 sljit_emit_return_void(compiler
);
6764 code
.code
= sljit_generate_code(compiler
);
6766 sljit_free_compiler(compiler
);
6768 code
.test70_f3(-6834, 674.5, 2789, -895.25);
6770 FAILED(wbuf
[0] != 2789, "test70 case 9 failed\n");
6771 FAILED(ibuf
[0] != -6834, "test70 case 10 failed\n");
6772 FAILED(dbuf
[0] != -895.25, "test70 case 11 failed\n");
6773 FAILED(fbuf
[0] != 674.5, "test70 case 12 failed\n");
6780 compiler
= sljit_create_compiler(NULL
, NULL
);
6781 FAILED(!compiler
, "cannot create compiler\n");
6783 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F32
, F64
, F32
, 32), 1, 1, 3, 0, 0);
6784 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&ibuf
, SLJIT_S0
, 0);
6785 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&dbuf
, SLJIT_FR1
, 0);
6786 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&fbuf
);
6787 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
6788 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f32
), SLJIT_FR2
, 0);
6789 sljit_emit_return_void(compiler
);
6791 code
.code
= sljit_generate_code(compiler
);
6793 sljit_free_compiler(compiler
);
6795 code
.test70_f4(-4712.5, 5342.25, 2904.25, -4607);
6797 FAILED(ibuf
[0] != -4607, "test70 case 13 failed\n");
6798 FAILED(dbuf
[0] != 5342.25, "test70 case 14 failed\n");
6799 FAILED(fbuf
[0] != -4712.5, "test70 case 15 failed\n");
6800 FAILED(fbuf
[1] != 2904.25, "test70 case 16 failed\n");
6807 compiler
= sljit_create_compiler(NULL
, NULL
);
6808 FAILED(!compiler
, "cannot create compiler\n");
6810 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, F32
, 32, F32
), 1, 1, 3, 0, 0);
6811 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&ibuf
, SLJIT_S0
, 0);
6812 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&dbuf
, SLJIT_FR0
, 0);
6813 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&fbuf
);
6814 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR1
, 0);
6815 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f32
), SLJIT_FR2
, 0);
6817 sljit_emit_return_void(compiler
);
6819 code
.code
= sljit_generate_code(compiler
);
6821 sljit_free_compiler(compiler
);
6823 code
.test70_f5(3578.5, 4619.25, 6859, -1807.75);
6825 FAILED(ibuf
[0] != 6859, "test70 case 17 failed\n");
6826 FAILED(dbuf
[0] != 3578.5, "test70 case 18 failed\n");
6827 FAILED(fbuf
[0] != 4619.25, "test70 case 19 failed\n");
6828 FAILED(fbuf
[1] != -1807.75, "test70 case 20 failed\n");
6835 compiler
= sljit_create_compiler(NULL
, NULL
);
6836 FAILED(!compiler
, "cannot create compiler\n");
6838 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, 32, F32
, F64
), SLJIT_NUMBER_OF_SCRATCH_REGISTERS
+ 2, 1, 3, 0, 33);
6839 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&ibuf
, SLJIT_S0
, 0);
6840 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
6841 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
6842 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
), SLJIT_FR2
, 0);
6843 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM0(), (sljit_sw
)&fbuf
, SLJIT_FR1
, 0);
6844 sljit_emit_return_void(compiler
);
6846 code
.code
= sljit_generate_code(compiler
);
6848 sljit_free_compiler(compiler
);
6850 code
.test70_f6(2740.75, -2651, -7909.25, 3671.5);
6852 FAILED(ibuf
[0] != -2651, "test70 case 21 failed\n");
6853 FAILED(dbuf
[0] != 2740.75, "test70 case 22 failed\n");
6854 FAILED(dbuf
[1] != 3671.5, "test70 case 23 failed\n");
6855 FAILED(fbuf
[0] != -7909.25, "test70 case 24 failed\n");
6862 compiler
= sljit_create_compiler(NULL
, NULL
);
6863 FAILED(!compiler
, "cannot create compiler\n");
6865 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F32
, 32, W
, 32), 1, 3, 1, 0, 1);
6866 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)&wbuf
, SLJIT_S1
, 0);
6867 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
6868 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
6869 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_s32
), SLJIT_S2
, 0);
6870 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM0(), (sljit_sw
)&fbuf
, SLJIT_FR0
, 0);
6871 sljit_emit_return_void(compiler
);
6873 code
.code
= sljit_generate_code(compiler
);
6875 sljit_free_compiler(compiler
);
6877 code
.test70_f7(-5219.25, -4530, 7214, 6741);
6879 FAILED(wbuf
[0] != 7214, "test70 case 25 failed\n");
6880 FAILED(ibuf
[0] != -4530, "test70 case 26 failed\n");
6881 FAILED(ibuf
[1] != 6741, "test70 case 27 failed\n");
6882 FAILED(fbuf
[0] != -5219.25, "test70 case 28 failed\n");
6889 compiler
= sljit_create_compiler(NULL
, NULL
);
6890 FAILED(!compiler
, "cannot create compiler\n");
6892 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, F64
, W
, W
), 1, 5, 2, 0, SLJIT_MAX_LOCAL_SIZE
- 1);
6893 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_S0
, 0);
6894 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_SP
), SLJIT_MAX_LOCAL_SIZE
- 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
6895 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
6896 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
6897 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_S1
, 0);
6898 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
6899 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
6900 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
), SLJIT_FR1
, 0);
6901 sljit_emit_return_void(compiler
);
6903 code
.code
= sljit_generate_code(compiler
);
6905 sljit_free_compiler(compiler
);
6907 code
.test70_f8(-3749.75, 5280.5, 9134, -6506);
6909 FAILED(wbuf
[0] != 9134, "test70 case 29 failed\n");
6910 FAILED(wbuf
[1] != -6506, "test70 case 30 failed\n");
6911 FAILED(dbuf
[0] != -3749.75, "test70 case 31 failed\n");
6912 FAILED(dbuf
[1] != 5280.5, "test70 case 32 failed\n");
6919 compiler
= sljit_create_compiler(NULL
, NULL
);
6920 FAILED(!compiler
, "cannot create compiler\n");
6922 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, F64
, W
, F64
), 1, 1, 3, 0, SLJIT_MAX_LOCAL_SIZE
);
6923 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)&wbuf
, SLJIT_S0
, 0);
6924 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
6925 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
6926 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
), SLJIT_FR1
, 0);
6927 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
6929 sljit_emit_return_void(compiler
);
6931 code
.code
= sljit_generate_code(compiler
);
6933 sljit_free_compiler(compiler
);
6935 code
.test70_f9(-6049.25, 7301.5, 4610, -4312.75);
6937 FAILED(wbuf
[0] != 4610, "test70 case 33 failed\n");
6938 FAILED(dbuf
[0] != -6049.25, "test70 case 34 failed\n");
6939 FAILED(dbuf
[1] != 7301.5, "test70 case 35 failed\n");
6940 FAILED(dbuf
[2] != -4312.75, "test70 case 36 failed\n");
6947 compiler
= sljit_create_compiler(NULL
, NULL
);
6948 FAILED(!compiler
, "cannot create compiler\n");
6950 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, F64
, F64
, 32), 1, 1, 3, 0, 0);
6951 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&ibuf
, SLJIT_S0
, 0);
6952 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
6953 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
6954 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
), SLJIT_FR1
, 0);
6955 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
6957 sljit_emit_return_void(compiler
);
6959 code
.code
= sljit_generate_code(compiler
);
6961 sljit_free_compiler(compiler
);
6963 code
.test70_f10(4810.5, -9148.75, 8601.25, 6703);
6965 FAILED(ibuf
[0] != 6703, "test70 case 37 failed\n");
6966 FAILED(dbuf
[0] != 4810.5, "test70 case 38 failed\n");
6967 FAILED(dbuf
[1] != -9148.75, "test70 case 39 failed\n");
6968 FAILED(dbuf
[2] != 8601.25, "test70 case 40 failed\n");
6974 #if !(defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
6976 static sljit_sw SLJIT_FUNC
test71_f1(sljit_sw a
)
6981 static sljit_sw SLJIT_FUNC
test71_f2(sljit_sw a
, sljit_s32 b
, sljit_s32 c
, sljit_sw d
)
6983 return a
| b
| c
| d
;
6986 static sljit_sw
test71_f3(sljit_sw a
, sljit_s32 b
, sljit_s32 c
, sljit_sw d
)
6988 return a
| b
| c
| d
;
6991 static sljit_sw
test71_f4(sljit_sw a
, sljit_s32 b
, sljit_s32 c
, sljit_sw d
)
6993 SLJIT_UNUSED_ARG(a
);
6997 static sljit_sw
test71_f5(void)
7002 static sljit_sw SLJIT_FUNC
test71_f6(sljit_f64 a
, sljit_f64 b
, sljit_f64 c
, sljit_f64 d
)
7004 if (a
== 1345.5 && b
== -8724.25 && c
== 9034.75 && d
== 6307.5)
7009 static sljit_sw SLJIT_FUNC
test71_f7(sljit_f64 a
, sljit_f64 b
, sljit_f64 c
, sljit_sw d
)
7011 if (a
== 4061.25 && b
== -3291.75 && c
== 8703.5 && d
== 1706)
7016 #endif /* !SLJIT_CONFIG_SPARC */
7018 static void test71(void)
7020 #if !(defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
7021 /* Test tail calls. */
7022 executable_code code
;
7023 struct sljit_compiler
* compiler
;
7024 struct sljit_jump
*jump
;
7026 sljit_sw executable_offset
;
7031 printf("Run test71\n");
7035 compiler
= sljit_create_compiler(NULL
, NULL
);
7036 FAILED(!compiler
, "cannot create compiler\n");
7038 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, W
), 4, 4, 0, 0, 0);
7039 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
7040 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
7041 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0);
7042 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0);
7043 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -1);
7044 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1);
7045 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1);
7046 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, -1);
7047 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS1(W
, W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f1
));
7049 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7051 code
.code
= sljit_generate_code(compiler
);
7053 sljit_free_compiler(compiler
);
7055 FAILED(code
.func1(7987) != 17987, "test71 case 1 failed\n");
7059 compiler
= sljit_create_compiler(NULL
, NULL
);
7060 FAILED(!compiler
, "cannot create compiler\n");
7062 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, W
), 1, 4, 0, 0, 0);
7063 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
7064 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -1);
7065 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1);
7066 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1);
7067 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, -1);
7068 jump
= sljit_emit_call(compiler
, SLJIT_CALL
| SLJIT_REWRITABLE_JUMP
| SLJIT_CALL_RETURN
, SLJIT_ARGS1(W
, W
));
7069 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7071 sljit_set_target(jump
, 0);
7073 code
.code
= sljit_generate_code(compiler
);
7076 executable_offset
= sljit_get_executable_offset(compiler
);
7077 jump_addr
= sljit_get_jump_addr(jump
);
7078 sljit_free_compiler(compiler
);
7080 sljit_set_jump_addr(jump_addr
, SLJIT_FUNC_UADDR(test71_f1
), executable_offset
);
7082 FAILED(code
.func1(3903) != 13903, "test71 case 2 failed\n");
7086 compiler
= sljit_create_compiler(NULL
, NULL
);
7087 FAILED(!compiler
, "cannot create compiler\n");
7089 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), 4, 2, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
7090 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f2
));
7091 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x28000000);
7092 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0x00140000);
7093 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_IMM
, 0x00002800);
7094 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x00000041);
7095 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -1);
7096 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1);
7097 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, W
, 32, 32, W
), SLJIT_MEM1(SLJIT_SP
), 0);
7098 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7100 code
.code
= sljit_generate_code(compiler
);
7102 sljit_free_compiler(compiler
);
7104 FAILED(code
.func0() != 0x28142841, "test71 case 3 failed\n");
7108 compiler
= sljit_create_compiler(NULL
, NULL
);
7109 FAILED(!compiler
, "cannot create compiler\n");
7111 sljit_emit_enter(compiler
, SLJIT_ENTER_CDECL
, SLJIT_ARGS4(W
, W
, 32, 32, W
), 4, 4, 0, 0, 9);
7112 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
7113 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_S1
, 0);
7114 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_S2
, 0);
7115 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_S3
, 0);
7116 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, W
, 32, 32, W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f2
));
7117 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7119 code
.code
= sljit_generate_code(compiler
);
7121 sljit_free_compiler(compiler
);
7123 FAILED(code
.test71_f1(0x650000, 0x13, 0x8400, 0x29000000) != 0x29658413, "test71 case 4 failed\n");
7125 sljit_free_code(code
.code
, NULL
);
7129 compiler
= sljit_create_compiler(NULL
, NULL
);
7130 FAILED(!compiler
, "cannot create compiler\n");
7132 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), 4, 4, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
7133 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f2
));
7134 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x81000000);
7135 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0x00480000);
7136 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_IMM
, 0x00002100);
7137 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x00000014);
7138 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -1);
7139 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1);
7140 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1);
7141 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, W
, 32, 32, W
), SLJIT_S3
, 0);
7142 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7144 code
.code
= sljit_generate_code(compiler
);
7146 sljit_free_compiler(compiler
);
7148 FAILED(code
.func0() != (sljit_sw
)0x81482114, "test71 case 5 failed\n");
7150 sljit_free_code(code
.code
, NULL
);
7154 compiler
= sljit_create_compiler(NULL
, NULL
);
7155 FAILED(!compiler
, "cannot create compiler\n");
7157 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(W
, W
, W
, W
), 4, 4, 0, 0, 0);
7158 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
7159 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_S1
, 0);
7160 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_S2
, 0);
7161 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x48000000);
7162 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -1);
7163 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1);
7164 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1);
7165 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, -1);
7166 sljit_emit_icall(compiler
, SLJIT_CALL_CDECL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, W
, 32, 32, W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f3
));
7167 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7169 code
.code
= sljit_generate_code(compiler
);
7171 sljit_free_compiler(compiler
);
7173 FAILED(code
.func3(0x12, 0x8800, 0x240000) != 0x48248812, "test71 case 6 failed\n");
7175 sljit_free_code(code
.code
, NULL
);
7179 compiler
= sljit_create_compiler(NULL
, NULL
);
7180 FAILED(!compiler
, "cannot create compiler\n");
7182 sljit_emit_enter(compiler
, SLJIT_ENTER_CDECL
, SLJIT_ARGS0(W
), 4, 0, 0, 0, 0);
7183 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f4
));
7184 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0x342);
7185 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_IMM
, 0x451000);
7186 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x21000000);
7187 sljit_emit_icall(compiler
, SLJIT_CALL_CDECL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, W
, 32, 32, W
), SLJIT_R0
, 0);
7188 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7190 code
.code
= sljit_generate_code(compiler
);
7192 sljit_free_compiler(compiler
);
7194 FAILED(code
.func0() != 0x21451342, "test71 case 7 failed\n");
7196 sljit_free_code(code
.code
, NULL
);
7200 compiler
= sljit_create_compiler(NULL
, NULL
);
7201 FAILED(!compiler
, "cannot create compiler\n");
7203 sljit_emit_enter(compiler
, SLJIT_ENTER_CDECL
, SLJIT_ARGS0(W
), 1, 0, 0, 0, 9);
7204 sljit_emit_icall(compiler
, SLJIT_CALL_CDECL
| SLJIT_CALL_RETURN
, SLJIT_ARGS0(W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f5
));
7205 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7207 code
.code
= sljit_generate_code(compiler
);
7209 sljit_free_compiler(compiler
);
7211 FAILED(code
.func0() != 7461932, "test71 case 8 failed\n");
7213 sljit_free_code(code
.code
, NULL
);
7215 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
7221 compiler
= sljit_create_compiler(NULL
, NULL
);
7222 FAILED(!compiler
, "cannot create compiler\n");
7224 sljit_emit_enter(compiler
, SLJIT_ENTER_CDECL
, SLJIT_ARGS2(W
, F64
, F64
), 1, 1, 4, 0, 0);
7225 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
7226 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_R0
), 0);
7227 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
));
7228 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, F64
, F64
, F64
, F64
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f6
));
7229 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7231 code
.code
= sljit_generate_code(compiler
);
7233 sljit_free_compiler(compiler
);
7235 FAILED(code
.test71_f2(1345.5, -8724.25) != 8920567, "test71 case 9 failed\n");
7237 sljit_free_code(code
.code
, NULL
);
7241 wbuf
[0] = SLJIT_FUNC_ADDR(test71_f6
);
7243 compiler
= sljit_create_compiler(NULL
, NULL
);
7244 FAILED(!compiler
, "cannot create compiler\n");
7246 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(W
, F64
, F64
, F64
, F64
), 1, 0, 4, 0, 0);
7247 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, F64
, F64
, F64
, F64
), SLJIT_MEM0(), (sljit_sw
)wbuf
);
7248 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7250 code
.code
= sljit_generate_code(compiler
);
7252 sljit_free_compiler(compiler
);
7254 FAILED(code
.test71_f3(1345.5, -8724.25, 9034.75, 6307.5) != 8920567, "test71 case 10 failed\n");
7256 sljit_free_code(code
.code
, NULL
);
7260 compiler
= sljit_create_compiler(NULL
, NULL
);
7261 FAILED(!compiler
, "cannot create compiler\n");
7263 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(W
, F64
, F64
, F64
), 1, 0, 4, 0, 0);
7264 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1706);
7265 jump
= sljit_emit_call(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, F64
, F64
, F64
, W
));
7266 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7268 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test71_f7
));
7270 code
.code
= sljit_generate_code(compiler
);
7272 sljit_free_compiler(compiler
);
7274 FAILED(code
.test71_f4(4061.25, -3291.75, 8703.5) != 5074526, "test71 case 11 failed\n");
7276 sljit_free_code(code
.code
, NULL
);
7280 compiler
= sljit_create_compiler(NULL
, NULL
);
7281 FAILED(!compiler
, "cannot create compiler\n");
7283 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(W
, F64
, F64
, F64
), SLJIT_NUMBER_OF_SCRATCH_REGISTERS
+ 1, 0, 4, 0, 0);
7284 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1706);
7285 jump
= sljit_emit_call(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, F64
, F64
, F64
, W
));
7286 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7288 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test71_f7
));
7290 code
.code
= sljit_generate_code(compiler
);
7292 sljit_free_compiler(compiler
);
7294 FAILED(code
.test71_f4(4061.25, -3291.75, 8703.5) != 5074526, "test71 case 12 failed\n");
7296 sljit_free_code(code
.code
, NULL
);
7300 compiler
= sljit_create_compiler(NULL
, NULL
);
7301 FAILED(!compiler
, "cannot create compiler\n");
7303 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(W
, F64
, F64
, F64
), SLJIT_NUMBER_OF_SCRATCH_REGISTERS
+ 1, 1, 3, 0, SLJIT_MAX_LOCAL_SIZE
);
7304 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1706);
7305 jump
= sljit_emit_call(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, F64
, F64
, F64
, W
));
7306 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7308 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test71_f7
));
7310 code
.code
= sljit_generate_code(compiler
);
7312 sljit_free_compiler(compiler
);
7314 FAILED(code
.test71_f4(4061.25, -3291.75, 8703.5) != 5074526, "test71 case 13 failed\n");
7316 sljit_free_code(code
.code
, NULL
);
7318 #endif /* !SLJIT_CONFIG_SPARC */
7323 static void test72(void)
7325 /* Test using all fpu registers. */
7326 executable_code code
;
7327 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
7328 sljit_f64 buf
[SLJIT_NUMBER_OF_FLOAT_REGISTERS
];
7330 struct sljit_jump
*jump
;
7334 printf("Run test72\n");
7336 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
7338 printf("no fpu available, test72 skipped\n");
7341 sljit_free_compiler(compiler
);
7346 FAILED(!compiler
, "cannot create compiler\n");
7351 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
7354 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 1, 2, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0, 0);
7355 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
7356 for (i
= 1; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
7357 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_FR0
, 0);
7359 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S1
, 0);
7360 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS1(VOID
, W
));
7362 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
7363 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), i
* (sljit_sw
)sizeof(sljit_f64
), SLJIT_FR(i
), 0);
7364 sljit_emit_return_void(compiler
);
7366 /* Called function. */
7367 sljit_set_label(jump
, sljit_emit_label(compiler
));
7368 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 0, 1, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0, 0);
7370 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
7371 for (i
= 1; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
7372 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_FR0
, 0);
7374 sljit_set_context(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 0, 1, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0, 0);
7375 sljit_emit_return_void(compiler
);
7377 code
.code
= sljit_generate_code(compiler
);
7379 sljit_free_compiler(compiler
);
7381 code
.func2((sljit_sw
)buf
, (sljit_sw
)buf2
);
7383 for (i
= 0; i
< SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
; i
++) {
7384 FAILED(buf
[i
] != -8.25, "test72 case 1 failed\n");
7387 for (i
= SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++) {
7388 FAILED(buf
[i
] != 7.75, "test72 case 2 failed\n");
7391 sljit_free_code(code
.code
, NULL
);
7394 if (SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
>= 3) {
7395 compiler
= sljit_create_compiler(NULL
, NULL
);
7396 FAILED(!compiler
, "cannot create compiler\n");
7401 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
7404 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 1, 2, SLJIT_NUMBER_OF_FLOAT_REGISTERS
- 2, 1, SLJIT_MAX_LOCAL_SIZE
);
7405 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FS0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
7406 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
- 2; i
++)
7407 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_FS0
, 0);
7409 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S1
, 0);
7410 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS1(VOID
, W
));
7412 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
- 2; i
++)
7413 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), i
* (sljit_sw
)sizeof(sljit_f64
), SLJIT_FR(i
), 0);
7414 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), (SLJIT_NUMBER_OF_FLOAT_REGISTERS
- 1) * (sljit_sw
)sizeof(sljit_f64
), SLJIT_FS0
, 0);
7415 sljit_emit_return_void(compiler
);
7417 /* Called function. */
7418 sljit_set_label(jump
, sljit_emit_label(compiler
));
7419 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 0, 1, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0, SLJIT_MAX_LOCAL_SIZE
);
7421 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
7422 for (i
= 1; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
7423 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_FR0
, 0);
7425 sljit_set_context(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 0, 1, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0, SLJIT_MAX_LOCAL_SIZE
);
7426 sljit_emit_return_void(compiler
);
7428 code
.code
= sljit_generate_code(compiler
);
7430 sljit_free_compiler(compiler
);
7432 code
.func2((sljit_sw
)buf
, (sljit_sw
)buf2
);
7434 for (i
= 0; i
< SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
; i
++) {
7435 FAILED(buf
[i
] != 3.75, "test72 case 3 failed\n");
7438 for (i
= SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
- 2; i
++) {
7439 FAILED(buf
[i
] != -6.25, "test72 case 4 failed\n");
7442 FAILED(buf
[SLJIT_NUMBER_OF_FLOAT_REGISTERS
- 2] != 0, "test72 case 5 failed\n");
7443 FAILED(buf
[SLJIT_NUMBER_OF_FLOAT_REGISTERS
- 1] != -6.25, "test72 case 6 failed\n");
7445 sljit_free_code(code
.code
, NULL
);
7450 static void test73(void)
7452 /* Test tail calls. */
7453 executable_code code
;
7454 struct sljit_compiler
* compiler
;
7460 printf("Run test73\n");
7464 compiler
= sljit_create_compiler(NULL
, NULL
);
7465 FAILED(!compiler
, "cannot create compiler\n");
7467 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, 32_R
, W
, W_R
, 32), 3, 2, 0, 0, 0);
7468 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
7469 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0, SLJIT_S0
, 0);
7470 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_sw
), SLJIT_R2
, 0);
7471 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
7472 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R1
), 0, SLJIT_R0
, 0);
7473 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_s32
), SLJIT_S1
, 0);
7474 sljit_emit_return_void(compiler
);
7476 code
.code
= sljit_generate_code(compiler
);
7478 sljit_free_compiler(compiler
);
7480 code
.test73_f1(3467, -6781, 5038, 6310);
7482 FAILED(wbuf
[0] != -6781, "test73 case 1 failed\n");
7483 FAILED(wbuf
[1] != 5038, "test73 case 2 failed\n");
7484 FAILED(ibuf
[0] != 3467, "test73 case 3 failed\n");
7485 FAILED(ibuf
[1] != 6310, "test73 case 4 failed\n");
7486 sljit_free_code(code
.code
, NULL
);
7490 compiler
= sljit_create_compiler(NULL
, NULL
);
7491 FAILED(!compiler
, "cannot create compiler\n");
7493 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, 32, W_R
, W
, 32_R
), 4, 2, 0, 0, 8192);
7494 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
7495 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_R1
, 0);
7496 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_S1
, 0);
7497 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
7498 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
7499 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_s32
), SLJIT_R3
, 0);
7500 sljit_emit_return_void(compiler
);
7502 code
.code
= sljit_generate_code(compiler
);
7504 sljit_free_compiler(compiler
);
7506 code
.test73_f1(-9723, 5208, 4761, 5084);
7508 FAILED(wbuf
[0] != 5208, "test73 case 5 failed\n");
7509 FAILED(wbuf
[1] != 4761, "test73 case 6 failed\n");
7510 FAILED(ibuf
[0] != -9723, "test73 case 7 failed\n");
7511 FAILED(ibuf
[1] != 5084, "test73 case 8 failed\n");
7512 sljit_free_code(code
.code
, NULL
);
7516 compiler
= sljit_create_compiler(NULL
, NULL
);
7517 FAILED(!compiler
, "cannot create compiler\n");
7519 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, 32_R
, W_R
, W_R
, 32_R
), 4, 1, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
7520 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
7521 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
7522 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R2
, 0);
7523 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
7524 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
7525 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_s32
), SLJIT_R3
, 0);
7526 sljit_emit_return_void(compiler
);
7528 code
.code
= sljit_generate_code(compiler
);
7530 sljit_free_compiler(compiler
);
7532 code
.test73_f1(5934, 6043, -8572, -3861);
7534 FAILED(wbuf
[0] != 6043, "test73 case 9 failed\n");
7535 FAILED(wbuf
[1] != -8572, "test73 case 10 failed\n");
7536 FAILED(ibuf
[0] != 5934, "test73 case 11 failed\n");
7537 FAILED(ibuf
[1] != -3861, "test73 case 12 failed\n");
7538 sljit_free_code(code
.code
, NULL
);
7542 compiler
= sljit_create_compiler(NULL
, NULL
);
7543 FAILED(!compiler
, "cannot create compiler\n");
7545 sljit_emit_enter(compiler
, SLJIT_ENTER_CDECL
, SLJIT_ARGS4(VOID
, W_R
, W_R
, 32_R
, 32_R
), 4, 1, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
7546 sljit_set_context(compiler
, SLJIT_ENTER_CDECL
, SLJIT_ARGS4(VOID
, W_R
, W_R
, 32_R
, 32_R
), 4, 1, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
7547 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
7548 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
7549 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R1
, 0);
7550 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
7551 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R2
, 0);
7552 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_s32
), SLJIT_R3
, 0);
7553 sljit_emit_return_void(compiler
);
7555 code
.code
= sljit_generate_code(compiler
);
7557 sljit_free_compiler(compiler
);
7559 code
.test73_f2(6732, -5916, 2740, -3621);
7561 FAILED(wbuf
[0] != 6732, "test73 case 13 failed\n");
7562 FAILED(wbuf
[1] != -5916, "test73 case 14 failed\n");
7563 FAILED(ibuf
[0] != 2740, "test73 case 15 failed\n");
7564 FAILED(ibuf
[1] != -3621, "test73 case 16 failed\n");
7565 sljit_free_code(code
.code
, NULL
);
7567 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
7570 compiler
= sljit_create_compiler(NULL
, NULL
);
7571 FAILED(!compiler
, "cannot create compiler\n");
7573 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, F64
, F64
, W_R
), 1, 0, 3, 0, SLJIT_MAX_LOCAL_SIZE
);
7574 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)&wbuf
, SLJIT_R0
, 0);
7575 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
7576 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
7577 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
), SLJIT_FR1
, 0);
7578 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
7580 sljit_emit_return_void(compiler
);
7582 code
.code
= sljit_generate_code(compiler
);
7584 sljit_free_compiler(compiler
);
7586 code
.test73_f3(7390.25, -8045.5, 1390.75, 8201);
7588 FAILED(wbuf
[0] != 8201, "test73 case 17 failed\n");
7589 FAILED(dbuf
[0] != 7390.25, "test73 case 18 failed\n");
7590 FAILED(dbuf
[1] != -8045.5, "test73 case 19 failed\n");
7591 FAILED(dbuf
[2] != 1390.75, "test73 case 20 failed\n");
7595 compiler
= sljit_create_compiler(NULL
, NULL
);
7596 FAILED(!compiler
, "cannot create compiler\n");
7598 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, F64
, W
, W_R
), 2, 1, 2, 0, SLJIT_MAX_LOCAL_SIZE
);
7599 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
7600 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
7601 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_R1
, 0);
7602 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
7603 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
7604 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
), SLJIT_FR1
, 0);
7606 sljit_emit_return_void(compiler
);
7608 code
.code
= sljit_generate_code(compiler
);
7610 sljit_free_compiler(compiler
);
7612 code
.test73_f4(4892.75, -3702.5, 4731, 8530);
7614 FAILED(wbuf
[0] != 4731, "test73 case 21 failed\n");
7615 FAILED(wbuf
[1] != 8530, "test73 case 22 failed\n");
7616 FAILED(dbuf
[0] != 4892.75, "test73 case 23 failed\n");
7617 FAILED(dbuf
[1] != -3702.5, "test73 case 24 failed\n");
7623 int sljit_test(int argc
, char* argv
[])
7625 sljit_s32 has_arg
= (argc
>= 2 && argv
[1][0] == '-' && argv
[1][2] == '\0');
7626 verbose
= has_arg
&& argv
[1][1] == 'v';
7627 silent
= has_arg
&& argv
[1][1] == 's';
7629 if (!verbose
&& !silent
)
7630 printf("Pass -v to enable verbose, -s to disable this hint.\n\n");
7632 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
7633 test_exec_allocator();
7709 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
7710 sljit_free_unused_memory_exec();
7713 # define TEST_COUNT 73
7715 printf("SLJIT tests: ");
7716 if (successful_tests
== TEST_COUNT
)
7717 printf("all tests are " COLOR_GREEN
"PASSED" COLOR_DEFAULT
" ");
7719 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
);
7720 printf("on " COLOR_ARCH
"%s" COLOR_DEFAULT
"%s\n", sljit_get_platform_name(), sljit_has_cpu_feature(SLJIT_HAS_FPU
) ? " (with fpu)" : " (without fpu)");
7722 return TEST_COUNT
- successful_tests
;
7728 #pragma warning(pop)