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_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_IMM
, 0, SLJIT_S1
, 0);
333 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM0(), (sljit_sw
)&buf
[0], SLJIT_IMM
, 0, SLJIT_MEM0(), (sljit_sw
)&buf
[1]);
334 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 299);
335 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_IMM
, 0, SLJIT_R1
, 0);
336 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 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
);
565 printf("Run test8\n");
567 FAILED(!compiler
, "cannot create compiler\n");
569 for (i
= 1; i
< 21; i
++)
572 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 2, 0, 0, 0);
573 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 20);
574 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 10);
575 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_IMM
, 6, SLJIT_IMM
, 5);
577 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_NOT_EQUAL
);
579 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_EQUAL
);
580 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 3000);
581 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_GREATER
);
582 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 3000);
584 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_S1
, 0);
585 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_LESS
);
587 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R2
, 0);
588 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, -15);
589 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_SIG_GREATER
);
591 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R2
, 0);
592 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -(sljit_sw
)(~(sljit_uw
)0 >> 1) - 1);
593 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0);
594 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
595 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_IMM
, 0, SLJIT_R0
, 0);
597 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_OVERFLOW
);
598 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
599 sljit_emit_op1(compiler
, SLJIT_NOT
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R0
, 0);
601 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_ZERO
);
602 sljit_emit_op1(compiler
, SLJIT_NOT
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R1
, 0);
604 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_ZERO
);
605 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_IMM
, 0xffff, SLJIT_R0
, 0);
606 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);
616 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, SLJIT_NOT_ZERO
);
617 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -(sljit_sw
)(~(sljit_uw
)0 >> 1) - 1);
618 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
619 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0);
621 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 11, SLJIT_OVERFLOW
);
622 sljit_emit_op2u(compiler
, SLJIT_ADD
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0);
624 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 12, SLJIT_OVERFLOW
);
625 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 9);
626 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 0, SLJIT_R0
, 0);
628 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 13, SLJIT_LESS
);
630 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 14, SLJIT_ZERO
);
631 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
632 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 0, SLJIT_R0
, 0);
634 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 15, SLJIT_LESS
);
636 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 16, SLJIT_ZERO
);
637 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -9);
638 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 0, SLJIT_R0
, 0);
640 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 17, SLJIT_SIG_LESS
);
641 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -9);
642 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 0, SLJIT_R0
, 0);
644 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 18, SLJIT_SIG_GREATER
);
645 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
646 sljit_emit_op2(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
648 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 19, SLJIT_ZERO
);
650 sljit_emit_op2u(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
651 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 20, SLJIT_ZERO
);
652 sljit_emit_op2(compiler
, SLJIT_XOR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
654 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 21, SLJIT_ZERO
);
656 sljit_emit_return_void(compiler
);
658 code
.code
= sljit_generate_code(compiler
);
660 sljit_free_compiler(compiler
);
662 code
.func1((sljit_sw
)&buf
);
663 FAILED(buf
[1] != 1, "test8 case 1 failed\n");
664 FAILED(buf
[2] != 0, "test8 case 2 failed\n");
665 FAILED(buf
[3] != 0, "test8 case 3 failed\n");
666 FAILED(buf
[4] != 1, "test8 case 4 failed\n");
667 FAILED(buf
[5] != 1, "test8 case 5 failed\n");
668 FAILED(buf
[6] != 1, "test8 case 6 failed\n");
669 FAILED(buf
[7] != 1, "test8 case 7 failed\n");
670 FAILED(buf
[8] != 0, "test8 case 8 failed\n");
671 FAILED(buf
[9] != 1, "test8 case 9 failed\n");
672 FAILED(buf
[10] != 0, "test8 case 10 failed\n");
673 FAILED(buf
[11] != 1, "test8 case 11 failed\n");
674 FAILED(buf
[12] != 0, "test8 case 12 failed\n");
675 FAILED(buf
[13] != 1, "test8 case 13 failed\n");
676 FAILED(buf
[14] != 0, "test8 case 14 failed\n");
677 FAILED(buf
[15] != 0, "test8 case 15 failed\n");
678 FAILED(buf
[16] != 1, "test8 case 16 failed\n");
679 FAILED(buf
[17] != 0, "test8 case 17 failed\n");
680 FAILED(buf
[18] != 1, "test8 case 18 failed\n");
681 FAILED(buf
[19] != 1, "test8 case 19 failed\n");
682 FAILED(buf
[20] != 0, "test8 case 20 failed\n");
683 FAILED(buf
[21] != 1, "test8 case 21 failed\n");
685 sljit_free_code(code
.code
, NULL
);
689 static void test9(void)
692 executable_code code
;
693 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
695 #ifdef SLJIT_PREF_SHIFT_REG
696 sljit_s32 shift_reg
= SLJIT_PREF_SHIFT_REG
;
698 sljit_s32 shift_reg
= SLJIT_R2
;
701 SLJIT_ASSERT(shift_reg
>= SLJIT_R2
&& shift_reg
<= SLJIT_R3
);
704 printf("Run test9\n");
706 FAILED(!compiler
, "cannot create compiler\n");
721 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 4, 2, 0, 0, 0);
722 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xf);
723 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 3);
724 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
725 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
726 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
727 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R1
, 0, SLJIT_IMM
, 1);
728 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -64);
729 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 2);
730 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, shift_reg
, 0);
732 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0xff);
733 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
734 sljit_emit_op2(compiler
, SLJIT_SHL
, shift_reg
, 0, shift_reg
, 0, SLJIT_R0
, 0);
735 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, shift_reg
, 0);
736 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0xff);
737 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
738 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);
739 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, shift_reg
, 0, SLJIT_R0
, 0);
741 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, 0xf);
742 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
743 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_S1
, 0, SLJIT_S1
, 0, SLJIT_R0
, 0);
744 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_S1
, 0);
745 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_R0
, 0);
746 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_R0
, 0);
747 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0xf00);
748 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
749 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R1
, 0, SLJIT_R2
, 0, SLJIT_R0
, 0);
750 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_R1
, 0);
752 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)buf
);
753 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 9);
754 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
);
756 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 4);
757 sljit_emit_op2(compiler
, SLJIT_SHL
, shift_reg
, 0, SLJIT_IMM
, 2, shift_reg
, 0);
758 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 10, shift_reg
, 0);
760 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xa9);
761 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
762 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x7d00);
763 sljit_emit_op2(compiler
, SLJIT_LSHR32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 32);
764 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
765 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
767 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
768 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xe30000);
769 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
770 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffc0);
772 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffe0);
774 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
775 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x25000000);
776 sljit_emit_op2(compiler
, SLJIT_SHL32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xfffe1);
777 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
778 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
780 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 11, SLJIT_R1
, 0, SLJIT_R0
, 0);
782 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0);
783 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x5c);
784 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R1
, 0, SLJIT_R0
, 0, shift_reg
, 0);
785 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0xf600);
786 sljit_emit_op2(compiler
, SLJIT_LSHR32
, SLJIT_R0
, 0, SLJIT_R0
, 0, shift_reg
, 0);
787 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
788 /* Alternative form of uint32 type cast. */
789 sljit_emit_op2(compiler
, SLJIT_AND
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffffffff);
791 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
792 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x630000);
793 sljit_emit_op2(compiler
, SLJIT_ASHR
, SLJIT_R0
, 0, SLJIT_R0
, 0, shift_reg
, 0);
794 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 12, SLJIT_R1
, 0, SLJIT_R0
, 0);
796 sljit_emit_return_void(compiler
);
798 code
.code
= sljit_generate_code(compiler
);
800 sljit_free_compiler(compiler
);
802 code
.func1((sljit_sw
)&buf
);
803 FAILED(buf
[0] != 0x3c, "test9 case 1 failed\n");
804 FAILED(buf
[1] != 0xf0, "test9 case 2 failed\n");
805 FAILED(buf
[2] != -16, "test9 case 3 failed\n");
806 FAILED(buf
[3] != 0xff0, "test9 case 4 failed\n");
807 FAILED(buf
[4] != 4, "test9 case 5 failed\n");
808 FAILED(buf
[5] != 0xff00, "test9 case 6 failed\n");
809 FAILED(buf
[6] != 0x3c, "test9 case 7 failed\n");
810 FAILED(buf
[7] != 0xf0, "test9 case 8 failed\n");
811 FAILED(buf
[8] != 0xf0, "test9 case 9 failed\n");
812 FAILED(buf
[9] != 0x18, "test9 case 10 failed\n");
813 FAILED(buf
[10] != 32, "test9 case 11 failed\n");
814 FAILED(buf
[11] != 0x4ae37da9, "test9 case 12 failed\n");
815 FAILED(buf
[12] != 0x63f65c, "test9 case 13 failed\n");
817 sljit_free_code(code
.code
, NULL
);
821 static void test10(void)
823 /* Test multiplications. */
824 executable_code code
;
825 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
829 printf("Run test10\n");
831 FAILED(!compiler
, "cannot create compiler\n");
840 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 0);
841 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
842 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
843 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
844 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 7);
845 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 8);
846 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
847 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_IMM
, -3, SLJIT_IMM
, -4);
848 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0);
849 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -2);
850 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);
851 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
) / 2);
852 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[3]);
853 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);
854 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 9);
855 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R0
, 0);
856 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_R0
, 0);
857 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
858 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3);
859 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x123456789));
860 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_R0
, 0);
862 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 11, SLJIT_IMM
, 10);
863 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
865 code
.code
= sljit_generate_code(compiler
);
867 sljit_free_compiler(compiler
);
869 FAILED(code
.func1((sljit_sw
)&buf
) != 110, "test10 case 1 failed\n");
870 FAILED(buf
[0] != 15, "test10 case 2 failed\n");
871 FAILED(buf
[1] != 56, "test10 case 3 failed\n");
872 FAILED(buf
[2] != 12, "test10 case 4 failed\n");
873 FAILED(buf
[3] != -12, "test10 case 5 failed\n");
874 FAILED(buf
[4] != 100, "test10 case 6 failed\n");
875 FAILED(buf
[5] != 81, "test10 case 7 failed\n");
876 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
877 FAILED(buf
[6] != SLJIT_W(0x123456789) * 3, "test10 case 8 failed\n");
880 sljit_free_code(code
.code
, NULL
);
884 static void test11(void)
886 /* Test rewritable constants. */
887 executable_code code
;
888 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
889 struct sljit_const
* const1
;
890 struct sljit_const
* const2
;
891 struct sljit_const
* const3
;
892 struct sljit_const
* const4
;
894 sljit_sw executable_offset
;
895 sljit_uw const1_addr
;
896 sljit_uw const2_addr
;
897 sljit_uw const3_addr
;
898 sljit_uw const4_addr
;
899 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
900 sljit_sw word_value1
= (sljit_sw
)SLJIT_W(0xaaaaaaaaaaaaaaaa);
901 sljit_sw word_value2
= (sljit_sw
)SLJIT_W(0xfee1deadfbadf00d);
903 sljit_sw word_value1
= (sljit_sw
)0xaaaaaaaal
;
904 sljit_sw word_value2
= (sljit_sw
)0xfbadf00dl
;
909 printf("Run test11\n");
911 FAILED(!compiler
, "cannot create compiler\n");
916 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 0);
918 SLJIT_ASSERT(!sljit_alloc_memory(compiler
, 0));
919 SLJIT_ASSERT(!sljit_alloc_memory(compiler
, 16 * sizeof(sljit_sw
) + 1));
921 const1
= sljit_emit_const(compiler
, SLJIT_MEM0(), (sljit_sw
)&buf
[0], -0x81b9);
923 value
= sljit_alloc_memory(compiler
, 16 * sizeof(sljit_sw
));
926 SLJIT_ASSERT(!((sljit_sw
)value
& ((sljit_sw
)sizeof(sljit_sw
) - 1)));
927 memset(value
, 255, 16 * sizeof(sljit_sw
));
930 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
931 const2
= sljit_emit_const(compiler
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), SLJIT_WORD_SHIFT
- 1, -65535);
932 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);
933 const3
= sljit_emit_const(compiler
, SLJIT_MEM1(SLJIT_R0
), 0, word_value1
);
935 value
= sljit_alloc_memory(compiler
, 17);
938 SLJIT_ASSERT(!((sljit_sw
)value
& ((sljit_sw
)sizeof(sljit_sw
) - 1)));
939 memset(value
, 255, 16);
942 const4
= sljit_emit_const(compiler
, SLJIT_RETURN_REG
, 0, (sljit_sw
)0xf7afcdb7);
944 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
946 code
.code
= sljit_generate_code(compiler
);
948 executable_offset
= sljit_get_executable_offset(compiler
);
949 const1_addr
= sljit_get_const_addr(const1
);
950 const2_addr
= sljit_get_const_addr(const2
);
951 const3_addr
= sljit_get_const_addr(const3
);
952 const4_addr
= sljit_get_const_addr(const4
);
953 sljit_free_compiler(compiler
);
955 FAILED(code
.func1((sljit_sw
)&buf
) != (sljit_sw
)0xf7afcdb7, "test11 case 1 failed\n");
956 FAILED(buf
[0] != -0x81b9, "test11 case 2 failed\n");
957 FAILED(buf
[1] != -65535, "test11 case 3 failed\n");
958 FAILED(buf
[2] != word_value1
, "test11 case 4 failed\n");
960 sljit_set_const(const1_addr
, -1, executable_offset
);
961 sljit_set_const(const2_addr
, word_value2
, executable_offset
);
962 sljit_set_const(const3_addr
, (sljit_sw
)0xbab0fea1, executable_offset
);
963 sljit_set_const(const4_addr
, -60089, executable_offset
);
965 FAILED(code
.func1((sljit_sw
)&buf
) != -60089, "test11 case 5 failed\n");
966 FAILED(buf
[0] != -1, "test11 case 6 failed\n");
967 FAILED(buf
[1] != word_value2
, "test11 case 7 failed\n");
968 FAILED(buf
[2] != (sljit_sw
)0xbab0fea1, "test11 case 8 failed\n");
970 sljit_free_code(code
.code
, NULL
);
974 static void test12(void)
976 /* Test rewriteable jumps. */
977 executable_code code
;
978 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
979 struct sljit_label
*label1
;
980 struct sljit_label
*label2
;
981 struct sljit_label
*label3
;
982 struct sljit_jump
*jump1
;
983 struct sljit_jump
*jump2
;
984 struct sljit_jump
*jump3
;
985 sljit_sw executable_offset
;
988 sljit_uw label1_addr
;
989 sljit_uw label2_addr
;
993 printf("Run test12\n");
995 FAILED(!compiler
, "cannot create compiler\n");
998 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, W
), 3, 2, 0, 0, 0);
999 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_S1
, 0, SLJIT_IMM
, 10);
1000 jump1
= sljit_emit_jump(compiler
, SLJIT_REWRITABLE_JUMP
| SLJIT_SIG_GREATER
);
1001 /* Default handler. */
1002 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 5);
1003 jump2
= sljit_emit_jump(compiler
, SLJIT_JUMP
);
1005 value
= sljit_alloc_memory(compiler
, 15);
1008 SLJIT_ASSERT(!((sljit_sw
)value
& ((sljit_sw
)sizeof(sljit_sw
) - 1)));
1009 memset(value
, 255, 15);
1013 label1
= sljit_emit_label(compiler
);
1014 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
1015 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 6);
1016 jump3
= sljit_emit_jump(compiler
, SLJIT_JUMP
);
1018 label2
= sljit_emit_label(compiler
);
1019 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
1020 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 7);
1022 label3
= sljit_emit_label(compiler
);
1023 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
1024 sljit_set_label(jump2
, label3
);
1025 sljit_set_label(jump3
, label3
);
1026 /* By default, set to handler 1. */
1027 sljit_set_label(jump1
, label1
);
1028 sljit_emit_return_void(compiler
);
1030 value
= sljit_alloc_memory(compiler
, 8);
1033 SLJIT_ASSERT(!((sljit_sw
)value
& ((sljit_sw
)sizeof(sljit_sw
) - 1)));
1034 memset(value
, 255, 8);
1037 code
.code
= sljit_generate_code(compiler
);
1039 executable_offset
= sljit_get_executable_offset(compiler
);
1040 jump1_addr
= sljit_get_jump_addr(jump1
);
1041 label1_addr
= sljit_get_label_addr(label1
);
1042 label2_addr
= sljit_get_label_addr(label2
);
1043 sljit_free_compiler(compiler
);
1045 code
.func2((sljit_sw
)&buf
, 4);
1046 FAILED(buf
[0] != 5, "test12 case 1 failed\n");
1048 code
.func2((sljit_sw
)&buf
, 11);
1049 FAILED(buf
[0] != 6, "test12 case 2 failed\n");
1051 sljit_set_jump_addr(jump1_addr
, label2_addr
, executable_offset
);
1052 code
.func2((sljit_sw
)&buf
, 12);
1053 FAILED(buf
[0] != 7, "test12 case 3 failed\n");
1055 sljit_set_jump_addr(jump1_addr
, label1_addr
, executable_offset
);
1056 code
.func2((sljit_sw
)&buf
, 13);
1057 FAILED(buf
[0] != 6, "test12 case 4 failed\n");
1059 sljit_free_code(code
.code
, NULL
);
1063 static void test13(void)
1065 /* Test fpu monadic functions. */
1066 executable_code code
;
1067 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1072 printf("Run test13\n");
1074 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
1076 printf("no fpu available, test13 skipped\n");
1079 sljit_free_compiler(compiler
);
1083 FAILED(!compiler
, "cannot create compiler\n");
1099 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 3, 2, 6, 0, 0);
1100 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&buf
[2], SLJIT_MEM0(), (sljit_sw
)&buf
[1]);
1101 sljit_emit_fop1(compiler
, SLJIT_ABS_F64
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1102 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
1103 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2 * sizeof(sljit_f64
));
1104 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 0);
1105 sljit_emit_fop1(compiler
, SLJIT_NEG_F64
, SLJIT_FR2
, 0, SLJIT_FR0
, 0);
1106 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_FR2
, 0);
1107 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&buf
[4], SLJIT_FR3
, 0);
1108 sljit_emit_fop1(compiler
, SLJIT_ABS_F64
, SLJIT_FR4
, 0, SLJIT_FR1
, 0);
1109 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f64
), SLJIT_FR4
, 0);
1110 sljit_emit_fop1(compiler
, SLJIT_NEG_F64
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
), SLJIT_FR4
, 0);
1112 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
1113 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_F_GREATER
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1114 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_F_GREATER
);
1115 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_F_GREATER
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
), SLJIT_FR5
, 0);
1116 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
), SLJIT_F_GREATER
);
1117 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_FR5
, 0);
1118 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_F_EQUAL
, SLJIT_FR1
, 0, SLJIT_FR1
, 0);
1119 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
), SLJIT_F_EQUAL
);
1120 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_F_LESS
, SLJIT_FR1
, 0, SLJIT_FR1
, 0);
1121 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
), SLJIT_F_LESS
);
1122 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_F_EQUAL
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1123 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_F_EQUAL
);
1124 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_F_NOT_EQUAL
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1125 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_F_NOT_EQUAL
);
1127 sljit_emit_return_void(compiler
);
1129 code
.code
= sljit_generate_code(compiler
);
1131 sljit_free_compiler(compiler
);
1133 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&buf2
);
1134 FAILED(buf
[2] != -4.5, "test13 case 1 failed\n");
1135 FAILED(buf
[3] != 4.5, "test13 case 2 failed\n");
1136 FAILED(buf
[4] != -7.75, "test13 case 3 failed\n");
1137 FAILED(buf
[5] != 4.5, "test13 case 4 failed\n");
1138 FAILED(buf
[6] != -4.5, "test13 case 5 failed\n");
1140 FAILED(buf2
[0] != 1, "test13 case 6 failed\n");
1141 FAILED(buf2
[1] != 0, "test13 case 7 failed\n");
1142 FAILED(buf2
[2] != 1, "test13 case 8 failed\n");
1143 FAILED(buf2
[3] != 0, "test13 case 9 failed\n");
1144 FAILED(buf2
[4] != 0, "test13 case 10 failed\n");
1145 FAILED(buf2
[5] != 1, "test13 case 11 failed\n");
1147 sljit_free_code(code
.code
, NULL
);
1151 static void test14(void)
1153 /* Test fpu diadic functions. */
1154 executable_code code
;
1155 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1159 printf("Run test14\n");
1161 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
1163 printf("no fpu available, test14 skipped\n");
1166 sljit_free_compiler(compiler
);
1185 FAILED(!compiler
, "cannot create compiler\n");
1186 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 6, 0, 0);
1189 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_f64
));
1190 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
1191 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2);
1192 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);
1193 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_FR1
, 0);
1194 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR1
, 0, SLJIT_FR0
, 0, SLJIT_FR1
, 0);
1195 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 4, SLJIT_FR0
, 0);
1196 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 5, SLJIT_FR1
, 0);
1199 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
1200 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2);
1201 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 2);
1202 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
);
1203 sljit_emit_fop2(compiler
, SLJIT_SUB_F64
, SLJIT_FR2
, 0, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2);
1204 sljit_emit_fop2(compiler
, SLJIT_SUB_F64
, SLJIT_FR3
, 0, SLJIT_FR2
, 0, SLJIT_FR3
, 0);
1205 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 7, SLJIT_FR2
, 0);
1206 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 8, SLJIT_FR3
, 0);
1209 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
1210 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);
1211 sljit_emit_fop2(compiler
, SLJIT_MUL_F64
, SLJIT_FR1
, 0, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
1212 sljit_emit_fop2(compiler
, SLJIT_MUL_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 2, SLJIT_FR2
, 0);
1213 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 10, SLJIT_FR1
, 0);
1214 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 11, SLJIT_FR5
, 0);
1217 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 12);
1218 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 13);
1219 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR4
, 0, SLJIT_FR5
, 0);
1220 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);
1221 sljit_emit_fop2(compiler
, SLJIT_DIV_F64
, SLJIT_FR5
, 0, SLJIT_FR5
, 0, SLJIT_FR1
, 0);
1222 sljit_emit_fop2(compiler
, SLJIT_DIV_F64
, SLJIT_FR4
, 0, SLJIT_FR1
, 0, SLJIT_FR4
, 0);
1223 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 13, SLJIT_FR5
, 0);
1224 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
) * 14, SLJIT_FR4
, 0);
1226 sljit_emit_return_void(compiler
);
1228 code
.code
= sljit_generate_code(compiler
);
1230 sljit_free_compiler(compiler
);
1232 code
.func1((sljit_sw
)&buf
);
1233 FAILED(buf
[3] != 10.75, "test14 case 1 failed\n");
1234 FAILED(buf
[4] != 5.25, "test14 case 2 failed\n");
1235 FAILED(buf
[5] != 7.0, "test14 case 3 failed\n");
1236 FAILED(buf
[6] != 0.0, "test14 case 4 failed\n");
1237 FAILED(buf
[7] != 5.5, "test14 case 5 failed\n");
1238 FAILED(buf
[8] != 3.75, "test14 case 6 failed\n");
1239 FAILED(buf
[9] != 24.5, "test14 case 7 failed\n");
1240 FAILED(buf
[10] != 38.5, "test14 case 8 failed\n");
1241 FAILED(buf
[11] != 9.625, "test14 case 9 failed\n");
1242 FAILED(buf
[12] != 2.0, "test14 case 10 failed\n");
1243 FAILED(buf
[13] != 2.0, "test14 case 11 failed\n");
1244 FAILED(buf
[14] != 0.5, "test14 case 12 failed\n");
1246 sljit_free_code(code
.code
, NULL
);
1250 static sljit_sw SLJIT_FUNC
func(sljit_sw a
, sljit_sw b
, sljit_sw c
)
1252 return a
+ b
+ c
+ 5;
1255 static void test15(void)
1257 /* Test function call. */
1258 executable_code code
;
1259 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1260 struct sljit_jump
* jump
= NULL
;
1264 printf("Run test15\n");
1266 FAILED(!compiler
, "cannot create compiler\n");
1273 buf
[6] = SLJIT_FUNC_ADDR(func
);
1275 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 4, 1, 0, 0, 0);
1277 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
1278 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 7);
1279 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -3);
1280 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(func
));
1281 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_RETURN_REG
, 0);
1283 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -5);
1284 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -10);
1285 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2);
1286 jump
= sljit_emit_call(compiler
, SLJIT_CALL
| SLJIT_REWRITABLE_JUMP
, SLJIT_ARGS3(W
, W
, W
, W
));
1287 sljit_set_target(jump
, (sljit_uw
)-1);
1288 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1290 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(func
));
1291 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 40);
1292 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -3);
1293 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_R0
, 0);
1294 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1296 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -60);
1297 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(func
));
1298 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -30);
1299 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_R1
, 0);
1300 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1302 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 10);
1303 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 16);
1304 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(func
));
1305 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_R2
, 0);
1306 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1308 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 100);
1309 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 110);
1310 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 120);
1311 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(func
));
1312 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_R3
, 0);
1313 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1315 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -10);
1316 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -16);
1317 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 6);
1318 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(W
, W
, W
, W
), SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
));
1319 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_RETURN_REG
, 0);
1321 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1323 code
.code
= sljit_generate_code(compiler
);
1325 sljit_set_jump_addr(sljit_get_jump_addr(jump
), SLJIT_FUNC_UADDR(func
), sljit_get_executable_offset(compiler
));
1326 sljit_free_compiler(compiler
);
1328 FAILED(code
.func1((sljit_sw
)&buf
) != -15, "test15 case 1 failed\n");
1329 FAILED(buf
[0] != 14, "test15 case 2 failed\n");
1330 FAILED(buf
[1] != -8, "test15 case 3 failed\n");
1331 FAILED(buf
[2] != SLJIT_FUNC_ADDR(func
) + 42, "test15 case 4 failed\n");
1332 FAILED(buf
[3] != SLJIT_FUNC_ADDR(func
) - 85, "test15 case 5 failed\n");
1333 FAILED(buf
[4] != SLJIT_FUNC_ADDR(func
) + 31, "test15 case 6 failed\n");
1334 FAILED(buf
[5] != 335, "test15 case 7 failed\n");
1335 FAILED(buf
[6] != -15, "test15 case 8 failed\n");
1337 sljit_free_code(code
.code
, NULL
);
1341 static void test16(void)
1343 /* Ackermann benchmark. */
1344 executable_code code
;
1345 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1346 struct sljit_label
*entry
;
1347 struct sljit_label
*label
;
1348 struct sljit_jump
*jump
;
1349 struct sljit_jump
*jump1
;
1350 struct sljit_jump
*jump2
;
1353 printf("Run test16\n");
1355 FAILED(!compiler
, "cannot create compiler\n");
1357 entry
= sljit_emit_label(compiler
);
1358 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(W
, W
, W
), 3, 2, 0, 0, 0);
1360 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_S0
, 0, SLJIT_IMM
, 0);
1361 jump1
= sljit_emit_jump(compiler
, SLJIT_EQUAL
);
1363 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_S1
, 0, SLJIT_IMM
, 0);
1364 jump2
= sljit_emit_jump(compiler
, SLJIT_EQUAL
);
1367 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
1368 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 1);
1369 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS2(W
, W
, W
));
1370 sljit_set_label(jump
, entry
);
1372 /* Returns with Ack(x-1, Ack(x,y-1)). */
1373 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_RETURN_REG
, 0);
1374 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
1375 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS2(W
, W
, W
));
1376 sljit_set_label(jump
, entry
);
1377 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1379 /* Returns with y+1. */
1380 label
= sljit_emit_label(compiler
);
1381 sljit_set_label(jump1
, label
);
1382 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 1, SLJIT_S1
, 0);
1383 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1385 /* Returns with Ack(x-1,1) */
1386 label
= sljit_emit_label(compiler
);
1387 sljit_set_label(jump2
, label
);
1388 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
1389 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
1390 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS2(W
, W
, W
));
1391 sljit_set_label(jump
, entry
);
1392 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1394 code
.code
= sljit_generate_code(compiler
);
1396 sljit_free_compiler(compiler
);
1398 FAILED(code
.func2(3, 3) != 61, "test16 case 1 failed\n");
1399 /* For benchmarking. */
1400 /* FAILED(code.func2(3, 11) != 16381, "test16 case 1 failed\n"); */
1402 sljit_free_code(code
.code
, NULL
);
1406 static void test17(void)
1408 /* Test arm constant pool. */
1409 executable_code code
;
1410 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1415 printf("Run test17\n");
1417 FAILED(!compiler
, "cannot create compiler\n");
1419 for (i
= 0; i
< 5; i
++)
1422 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 0, 0, 0);
1423 for (i
= 0; i
<= 0xfff; i
++) {
1424 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x81818000 | i
);
1425 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x81818000 | i
);
1426 if ((i
& 0x3ff) == 0)
1427 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), (i
>> 10) * (sljit_sw
)sizeof(sljit_sw
), SLJIT_R0
, 0);
1429 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1430 sljit_emit_return_void(compiler
);
1432 code
.code
= sljit_generate_code(compiler
);
1434 sljit_free_compiler(compiler
);
1436 code
.func1((sljit_sw
)&buf
);
1437 FAILED((sljit_uw
)buf
[0] != 0x81818000, "test17 case 1 failed\n");
1438 FAILED((sljit_uw
)buf
[1] != 0x81818400, "test17 case 2 failed\n");
1439 FAILED((sljit_uw
)buf
[2] != 0x81818800, "test17 case 3 failed\n");
1440 FAILED((sljit_uw
)buf
[3] != 0x81818c00, "test17 case 4 failed\n");
1441 FAILED((sljit_uw
)buf
[4] != 0x81818fff, "test17 case 5 failed\n");
1443 sljit_free_code(code
.code
, NULL
);
1447 static void test18(void)
1450 executable_code code
;
1451 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1455 printf("Run test18\n");
1457 FAILED(!compiler
, "cannot create compiler\n");
1468 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1469 buf
[10] = SLJIT_W(1) << 32;
1474 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 2, 0, 0, 0);
1476 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1477 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, SLJIT_W(0x1122334455667788));
1478 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x1122334455667788));
1480 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(1000000000000));
1481 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(1000000000000));
1482 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_IMM
, SLJIT_W(5000000000000), SLJIT_R0
, 0);
1484 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x1108080808));
1485 sljit_emit_op2(compiler
, SLJIT_ADD32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x1120202020));
1487 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1108080808));
1488 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1120202020));
1489 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_ZERO
);
1490 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_S1
, 0);
1491 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
1492 sljit_emit_op2u(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1120202020));
1493 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_ZERO
);
1495 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1108080808));
1496 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x2208080808));
1497 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_LESS
);
1498 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
1499 sljit_emit_op2u(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x1104040404));
1500 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_NOT_ZERO
);
1502 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
1503 sljit_emit_op2(compiler
, SLJIT_SHL32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_IMM
, SLJIT_W(0xffff0000), SLJIT_R0
, 0);
1505 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);
1507 /* 32 bit operations. */
1509 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0x11223344);
1510 sljit_emit_op2(compiler
, SLJIT_ADD32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 0x44332211);
1514 sljit_emit_return_void(compiler
);
1516 code
.code
= sljit_generate_code(compiler
);
1518 sljit_free_compiler(compiler
);
1520 code
.func1((sljit_sw
)&buf
);
1521 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1522 FAILED(buf
[0] != SLJIT_W(0x1122334455667788), "test18 case 1 failed\n");
1523 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1524 FAILED(buf
[1] != 0x55667788, "test18 case 2 failed\n");
1526 FAILED(buf
[1] != SLJIT_W(0x5566778800000000), "test18 case 2 failed\n");
1528 FAILED(buf
[2] != SLJIT_W(2000000000000), "test18 case 3 failed\n");
1529 FAILED(buf
[3] != SLJIT_W(4000000000000), "test18 case 4 failed\n");
1530 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1531 FAILED(buf
[4] != 0x28282828, "test18 case 5 failed\n");
1533 FAILED(buf
[4] != SLJIT_W(0x2828282800000000), "test18 case 5 failed\n");
1535 FAILED(buf
[5] != 0, "test18 case 6 failed\n");
1536 FAILED(buf
[6] != 1, "test18 case 7 failed\n");
1537 FAILED(buf
[7] != 1, "test18 case 8 failed\n");
1538 FAILED(buf
[8] != 0, "test18 case 9 failed\n");
1539 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1540 FAILED(buf
[9] != (sljit_sw
)0xfff00000, "test18 case 10 failed\n");
1541 FAILED(buf
[10] != (sljit_sw
)0xffffffff, "test18 case 11 failed\n");
1543 FAILED(buf
[9] != (sljit_sw
)SLJIT_W(0xfff0000000000000), "test18 case 10 failed\n");
1544 FAILED(buf
[10] != (sljit_sw
)SLJIT_W(0xffffffff00000000), "test18 case 11 failed\n");
1547 FAILED(buf
[0] != 0x11223344, "test18 case 1 failed\n");
1548 FAILED(buf
[1] != 0x44332211, "test18 case 2 failed\n");
1551 sljit_free_code(code
.code
, NULL
);
1555 static void test19(void)
1557 /* Test arm partial instruction caching. */
1558 executable_code code
;
1559 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1563 printf("Run test19\n");
1565 FAILED(!compiler
, "cannot create compiler\n");
1575 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 0, 0, 0);
1576 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
1577 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM0(), (sljit_sw
)&buf
[2], SLJIT_MEM0(), (sljit_sw
)&buf
[1], SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
1578 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
1579 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1580 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]);
1581 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_MEM0(), (sljit_sw
)&buf
[0], SLJIT_IMM
, 2);
1582 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
));
1583 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_IMM
, 10);
1584 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 7);
1585 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]);
1587 sljit_emit_return_void(compiler
);
1589 code
.code
= sljit_generate_code(compiler
);
1591 sljit_free_compiler(compiler
);
1593 code
.func1((sljit_sw
)&buf
);
1594 FAILED(buf
[0] != 10, "test19 case 1 failed\n");
1595 FAILED(buf
[1] != 4, "test19 case 2 failed\n");
1596 FAILED(buf
[2] != 14, "test19 case 3 failed\n");
1597 FAILED(buf
[3] != 14, "test19 case 4 failed\n");
1598 FAILED(buf
[4] != 8, "test19 case 5 failed\n");
1599 FAILED(buf
[5] != 6, "test19 case 6 failed\n");
1600 FAILED(buf
[6] != 12, "test19 case 7 failed\n");
1601 FAILED(buf
[7] != 10, "test19 case 8 failed\n");
1603 sljit_free_code(code
.code
, NULL
);
1607 static void test20(void)
1610 executable_code code
;
1611 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1612 struct sljit_jump
* jump
;
1613 struct sljit_label
* label
;
1615 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1616 sljit_sw offset_value
= SLJIT_W(0x1234567812345678);
1618 sljit_sw offset_value
= SLJIT_W(0x12345678);
1622 printf("Run test20\n");
1624 FAILED(!compiler
, "cannot create compiler\n");
1632 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 5, 5, 0, 0, 4 * sizeof(sljit_sw
));
1633 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
), SLJIT_MEM1(SLJIT_S0
), 0);
1634 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
));
1635 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -1);
1636 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, -1);
1637 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, -1);
1638 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_IMM
, -1);
1639 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
));
1640 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);
1641 sljit_get_local_base(compiler
, SLJIT_R0
, 0, -offset_value
);
1642 sljit_get_local_base(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, -0x1234);
1643 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
1644 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
));
1645 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_uw
));
1646 /* Dummy last instructions. */
1647 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 23);
1648 sljit_emit_label(compiler
);
1650 code
.code
= sljit_generate_code(compiler
);
1652 sljit_free_compiler(compiler
);
1654 FAILED(code
.func1((sljit_sw
)&buf
) != -12345, "test20 case 1 failed\n")
1656 FAILED(buf
[2] != 60, "test20 case 2 failed\n");
1657 FAILED(buf
[3] != 17, "test20 case 3 failed\n");
1658 FAILED(buf
[4] != 7, "test20 case 4 failed\n");
1660 sljit_free_code(code
.code
, NULL
);
1662 compiler
= sljit_create_compiler(NULL
, NULL
);
1663 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(W
, W
, W
, W
), 3, 3, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
1665 sljit_get_local_base(compiler
, SLJIT_R0
, 0, SLJIT_MAX_LOCAL_SIZE
- sizeof(sljit_sw
));
1666 sljit_get_local_base(compiler
, SLJIT_R1
, 0, -(sljit_sw
)sizeof(sljit_sw
));
1667 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -1);
1668 label
= sljit_emit_label(compiler
);
1669 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
1670 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0, SLJIT_R2
, 0);
1671 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R0
, 0);
1672 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_EQUAL
);
1673 sljit_set_label(jump
, label
);
1675 /* Saved registers should keep their value. */
1676 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_S1
, 0);
1677 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_S2
, 0);
1678 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
1680 code
.code
= sljit_generate_code(compiler
);
1682 sljit_free_compiler(compiler
);
1684 FAILED(code
.func3(1234, 5678, 9012) != 15924, "test20 case 5 failed\n");
1686 sljit_free_code(code
.code
, NULL
);
1690 static void test21(void)
1692 /* Test set context. The parts of the jit code can be separated in the memory. */
1693 executable_code code1
;
1694 executable_code code2
;
1695 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1696 struct sljit_jump
* jump
= NULL
;
1698 sljit_sw executable_offset
;
1702 printf("Run test21\n");
1704 FAILED(!compiler
, "cannot create compiler\n");
1710 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 2, 0, 0, 2 * sizeof(sljit_sw
));
1712 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 10);
1713 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_SP
), 0);
1715 jump
= sljit_emit_jump(compiler
, SLJIT_JUMP
| SLJIT_REWRITABLE_JUMP
);
1716 sljit_set_target(jump
, 0);
1718 code1
.code
= sljit_generate_code(compiler
);
1721 executable_offset
= sljit_get_executable_offset(compiler
);
1722 addr
= sljit_get_jump_addr(jump
);
1724 sljit_free_compiler(compiler
);
1726 compiler
= sljit_create_compiler(NULL
, NULL
);
1727 FAILED(!compiler
, "cannot create compiler\n");
1729 /* Other part of the jit code. */
1730 sljit_set_context(compiler
, 0, 1, 3, 2, 0, 0, 2 * sizeof(sljit_sw
));
1732 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
1733 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);
1734 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 3, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_MEM1(SLJIT_SP
), 0);
1735 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_sw
));
1737 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
1739 code2
.code
= sljit_generate_code(compiler
);
1741 sljit_free_compiler(compiler
);
1743 sljit_set_jump_addr(addr
, SLJIT_FUNC_UADDR(code2
.code
), executable_offset
);
1745 FAILED(code1
.func1((sljit_sw
)&buf
) != 19, "test21 case 1 failed\n");
1746 FAILED(buf
[2] != -16, "test21 case 2 failed\n");
1747 FAILED(buf
[3] != 100, "test21 case 3 failed\n");
1749 sljit_free_code(code1
.code
, NULL
);
1750 sljit_free_code(code2
.code
, NULL
);
1754 static void test22(void)
1756 /* Test simple byte and half-int data transfers. */
1757 executable_code code
;
1758 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1764 printf("Run test22\n");
1766 FAILED(!compiler
, "cannot create compiler\n");
1786 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 3, 3, 0, 0, 0);
1788 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, -13);
1789 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s16
), SLJIT_IMM
, 0x1234);
1790 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_s16
));
1791 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
1792 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s16
));
1793 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s16
), SLJIT_MEM1(SLJIT_S1
), -(sljit_sw
)sizeof(sljit_s16
));
1794 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xff0000 + 8000);
1795 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 2);
1796 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R1
), 1, SLJIT_R0
, 0);
1797 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0x1234 - 3 * sizeof(sljit_s16
));
1798 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R2
), 0x1234, SLJIT_IMM
, -9317);
1799 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0x1234 + 4 * sizeof(sljit_s16
));
1800 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R2
), -0x1234, SLJIT_IMM
, -9317);
1801 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0x12348 - 5 * sizeof(sljit_s16
));
1802 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R2
), 0x12348, SLJIT_IMM
, -8888);
1803 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 0x12348 + 6 * sizeof(sljit_s16
));
1804 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R2
), -0x12348, SLJIT_IMM
, -8888);
1806 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM1(SLJIT_S2
), 0, SLJIT_IMM
, -45);
1807 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_s8
), SLJIT_IMM
, 0x12);
1808 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4 * sizeof(sljit_s8
));
1809 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_s8
));
1810 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_S1
, 0, SLJIT_R1
, 0);
1811 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_S1
, 0, SLJIT_S1
, 0);
1812 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R2
, 0, SLJIT_S1
, 0);
1813 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R2
, 0);
1814 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S2
), 3 * sizeof(sljit_s8
), SLJIT_S1
, 0);
1815 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM2(SLJIT_S2
, SLJIT_R0
), 0, SLJIT_R0
, 0);
1816 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
1817 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
1818 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1819 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
1820 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
1821 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1823 sljit_emit_return_void(compiler
);
1825 code
.code
= sljit_generate_code(compiler
);
1827 sljit_free_compiler(compiler
);
1829 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&sbuf
, (sljit_sw
)&bbuf
);
1830 FAILED(buf
[0] != -9, "test22 case 1 failed\n");
1831 FAILED(buf
[1] != -56, "test22 case 2 failed\n");
1832 FAILED(buf
[2] != 0, "test22 case 3 failed\n");
1833 FAILED(buf
[3] != 0, "test22 case 4 failed\n");
1835 FAILED(sbuf
[0] != -13, "test22 case 5 failed\n");
1836 FAILED(sbuf
[1] != 0x1234, "test22 case 6 failed\n");
1837 FAILED(sbuf
[3] != 0x1234, "test22 case 7 failed\n");
1838 FAILED(sbuf
[4] != 8000, "test22 case 8 failed\n");
1839 FAILED(sbuf
[5] != -9317, "test22 case 9 failed\n");
1840 FAILED(sbuf
[6] != -9317, "test22 case 10 failed\n");
1841 FAILED(sbuf
[7] != -8888, "test22 case 11 failed\n");
1842 FAILED(sbuf
[8] != -8888, "test22 case 12 failed\n");
1844 FAILED(bbuf
[0] != -45, "test22 case 13 failed\n");
1845 FAILED(bbuf
[1] != 0x12, "test22 case 14 failed\n");
1846 FAILED(bbuf
[3] != -56, "test22 case 15 failed\n");
1847 FAILED(bbuf
[4] != 4, "test22 case 16 failed\n");
1849 sljit_free_code(code
.code
, NULL
);
1853 static void test23(void)
1855 /* Test 32 bit / 64 bit signed / unsigned int transfer and conversion.
1856 This test has do real things on 64 bit systems, but works on 32 bit systems as well. */
1857 executable_code code
;
1858 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1863 sljit_u8 asbytes
[4];
1865 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1866 sljit_sw garbage
= SLJIT_W(0x1234567812345678);
1868 sljit_sw garbage
= 0x12345678;
1872 printf("Run test23\n");
1874 FAILED(!compiler
, "cannot create compiler\n");
1891 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(W
, P
, P
), 3, 3, 0, 0, 0);
1892 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, 34567);
1893 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
1894 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), 0, SLJIT_IMM
, -7654);
1895 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, garbage
);
1896 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_s32
));
1897 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
1898 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, garbage
);
1899 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_s32
));
1900 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
1901 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, garbage
);
1902 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_s32
));
1903 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
1904 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1905 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x0f00f00);
1906 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x7777);
1907 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0x7777 + 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
1908 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x7777);
1909 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), -0x7777 + 4 * (sljit_sw
)sizeof(sljit_sw
), SLJIT_R0
, 0);
1910 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 5 * sizeof(sljit_sw
));
1911 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 1);
1912 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R1
), 0, SLJIT_IMM
, 16);
1913 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
1914 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1, SLJIT_IMM
, 64, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1);
1915 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)&buf
[7], SLJIT_IMM
, 0x123456);
1916 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&buf
[6], SLJIT_MEM0(), (sljit_sw
)&buf
[7]);
1917 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 5 * sizeof(sljit_sw
));
1918 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 2 * sizeof(sljit_sw
), SLJIT_R1
, 0);
1919 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 7 * sizeof(sljit_sw
));
1920 sljit_emit_op2(compiler
, SLJIT_LSHR
, SLJIT_R2
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 1);
1921 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_MEM2(SLJIT_R2
, SLJIT_R2
), 0);
1922 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[8] - 0x12340);
1923 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0x12340, SLJIT_R2
, 0);
1924 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_R0
), 0x12340, SLJIT_MEM1(SLJIT_R2
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 6);
1925 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_s32
), SLJIT_IMM
, 0x12345678);
1926 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x2bd700 | 243);
1927 sljit_emit_return(compiler
, SLJIT_MOV_S8
, SLJIT_R1
, 0);
1929 code
.code
= sljit_generate_code(compiler
);
1931 sljit_free_compiler(compiler
);
1933 FAILED(code
.func2((sljit_sw
)&buf
, (sljit_sw
)&ibuf
) != -13, "test23 case 1 failed\n");
1934 FAILED(buf
[0] != -5791, "test23 case 2 failed\n");
1935 FAILED(buf
[1] != 43579, "test23 case 3 failed\n");
1936 FAILED(buf
[2] != 658923, "test23 case 4 failed\n");
1937 FAILED(buf
[3] != 0x0f00f00, "test23 case 5 failed\n");
1938 FAILED(buf
[4] != 0x0f00f00, "test23 case 6 failed\n");
1939 FAILED(buf
[5] != 80, "test23 case 7 failed\n");
1940 FAILED(buf
[6] != 0x123456, "test23 case 8 failed\n");
1941 FAILED(buf
[7] != (sljit_sw
)&buf
[5], "test23 case 9 failed\n");
1942 FAILED(buf
[8] != (sljit_sw
)&buf
[5] + 6, "test23 case 10 failed\n");
1944 FAILED(ibuf
[0] != 34567, "test23 case 11 failed\n");
1945 FAILED(ibuf
[1] != -7654, "test23 case 12 failed\n");
1947 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1948 FAILED(u
.asbytes
[0] != 0x78, "test23 case 13 failed\n");
1949 FAILED(u
.asbytes
[1] != 0x56, "test23 case 14 failed\n");
1950 FAILED(u
.asbytes
[2] != 0x34, "test23 case 15 failed\n");
1951 FAILED(u
.asbytes
[3] != 0x12, "test23 case 16 failed\n");
1953 FAILED(u
.asbytes
[0] != 0x12, "test23 case 13 failed\n");
1954 FAILED(u
.asbytes
[1] != 0x34, "test23 case 14 failed\n");
1955 FAILED(u
.asbytes
[2] != 0x56, "test23 case 15 failed\n");
1956 FAILED(u
.asbytes
[3] != 0x78, "test23 case 16 failed\n");
1959 sljit_free_code(code
.code
, NULL
);
1963 static void test24(void)
1965 /* Some complicated addressing modes. */
1966 executable_code code
;
1967 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
1973 printf("Run test24\n");
1975 FAILED(!compiler
, "cannot create compiler\n");
2001 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 3, 3, 0, 0, 0);
2003 /* Nothing should be updated. */
2004 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM0(), (sljit_sw
)&sbuf
[1], SLJIT_MEM0(), (sljit_sw
)&sbuf
[0]);
2005 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM0(), (sljit_sw
)&bbuf
[1], SLJIT_MEM0(), (sljit_sw
)&bbuf
[0]);
2006 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
2007 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), 1, SLJIT_MEM0(), (sljit_sw
)&sbuf
[3]);
2008 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[0]);
2009 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
2010 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2);
2011 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);
2012 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_s8
));
2013 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&bbuf
[1], SLJIT_MEM1(SLJIT_R0
), (sljit_sw
)&bbuf
[2]);
2015 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, sizeof(sljit_s16
));
2016 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_MEM1(SLJIT_R1
), (sljit_sw
)&sbuf
[3], SLJIT_R1
, 0);
2018 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
2019 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
);
2020 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
2021 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_S0
, 0);
2022 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
);
2024 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 9 * sizeof(sljit_sw
));
2025 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 4 * sizeof(sljit_sw
));
2026 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -(4 << SLJIT_WORD_SHIFT
));
2027 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R2
), 0, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
2029 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
- 0x7fff8000 + 6 * (sljit_sw
)sizeof(sljit_sw
));
2030 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 952467);
2031 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0x7fff8000, SLJIT_R1
, 0);
2032 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0x7fff8000 + sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_R0
), 0x7fff8000);
2034 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
+ 0x7fff7fff + 6 * (sljit_sw
)sizeof(sljit_sw
));
2035 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);
2036 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
- 0x7fff7ffe + 3 * (sljit_sw
)sizeof(sljit_s8
));
2037 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM1(SLJIT_R0
), 0x7fff7fff, SLJIT_MEM1(SLJIT_R0
), 0x7fff7ffe);
2038 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
+ 0x7fff7fff + 5 * (sljit_sw
)sizeof(sljit_s8
));
2039 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_MEM1(SLJIT_R0
), -0x7fff7fff, SLJIT_MEM1(SLJIT_R0
), -0x7fff8000);
2040 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2041 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
- SLJIT_W(0x123456123456));
2042 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&bbuf
- SLJIT_W(0x123456123456));
2043 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));
2046 sljit_emit_return_void(compiler
);
2048 code
.code
= sljit_generate_code(compiler
);
2050 sljit_free_compiler(compiler
);
2052 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&sbuf
, (sljit_sw
)&bbuf
);
2053 FAILED(buf
[2] != 176366, "test24 case 1 failed\n");
2054 FAILED(buf
[3] != 64, "test24 case 2 failed\n");
2055 FAILED(buf
[4] != -100, "test24 case 3 failed\n");
2056 FAILED(buf
[5] != 100567, "test24 case 4 failed\n");
2057 FAILED(buf
[6] != 952467, "test24 case 5 failed\n");
2058 FAILED(buf
[7] != 952467, "test24 case 6 failed\n");
2059 FAILED(buf
[8] != 952467 * 2, "test24 case 7 failed\n");
2061 FAILED(sbuf
[1] != 30000, "test24 case 8 failed\n");
2062 FAILED(sbuf
[2] != -12345, "test24 case 9 failed\n");
2063 FAILED(sbuf
[4] != sizeof(sljit_s16
), "test24 case 10 failed\n");
2065 FAILED(bbuf
[1] != -128, "test24 case 11 failed\n");
2066 FAILED(bbuf
[2] != 99, "test24 case 12 failed\n");
2067 FAILED(bbuf
[4] != 99, "test24 case 13 failed\n");
2068 FAILED(bbuf
[5] != 99, "test24 case 14 failed\n");
2069 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2070 FAILED(bbuf
[6] != -128, "test24 case 15 failed\n");
2073 sljit_free_code(code
.code
, NULL
);
2077 static void test25(void)
2079 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2081 executable_code code
;
2082 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2086 printf("Run test25\n");
2088 FAILED(!compiler
, "cannot create compiler\n");
2104 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 0, 0, 0);
2106 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0);
2107 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 1 * sizeof(sljit_sw
), SLJIT_IMM
, 0x7fff);
2108 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_IMM
, -0x8000);
2109 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 0x7fffffff);
2110 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(-0x80000000));
2111 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x1234567887654321));
2112 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0xff80000000));
2113 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x3ff0000000));
2114 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_IMM
, (sljit_sw
)SLJIT_W(0xfffffff800100000));
2115 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_IMM
, (sljit_sw
)SLJIT_W(0xfffffff80010f000));
2116 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00000008001));
2117 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00080010000));
2118 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00080018001));
2119 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_IMM
, SLJIT_W(0x07fff00ffff00000));
2121 sljit_emit_return_void(compiler
);
2123 code
.code
= sljit_generate_code(compiler
);
2125 sljit_free_compiler(compiler
);
2127 code
.func1((sljit_sw
)&buf
);
2128 FAILED(buf
[0] != 0, "test25 case 1 failed\n");
2129 FAILED(buf
[1] != 0x7fff, "test25 case 2 failed\n");
2130 FAILED(buf
[2] != -0x8000, "test25 case 3 failed\n");
2131 FAILED(buf
[3] != 0x7fffffff, "test25 case 4 failed\n");
2132 FAILED(buf
[4] != SLJIT_W(-0x80000000), "test25 case 5 failed\n");
2133 FAILED(buf
[5] != SLJIT_W(0x1234567887654321), "test25 case 6 failed\n");
2134 FAILED(buf
[6] != SLJIT_W(0xff80000000), "test25 case 7 failed\n");
2135 FAILED(buf
[7] != SLJIT_W(0x3ff0000000), "test25 case 8 failed\n");
2136 FAILED((sljit_uw
)buf
[8] != SLJIT_W(0xfffffff800100000), "test25 case 9 failed\n");
2137 FAILED((sljit_uw
)buf
[9] != SLJIT_W(0xfffffff80010f000), "test25 case 10 failed\n");
2138 FAILED(buf
[10] != SLJIT_W(0x07fff00000008001), "test25 case 11 failed\n");
2139 FAILED(buf
[11] != SLJIT_W(0x07fff00080010000), "test25 case 12 failed\n");
2140 FAILED(buf
[12] != SLJIT_W(0x07fff00080018001), "test25 case 13 failed\n");
2141 FAILED(buf
[13] != SLJIT_W(0x07fff00ffff00000), "test25 case 14 failed\n");
2143 sljit_free_code(code
.code
, NULL
);
2148 static void test26(void)
2150 /* Aligned access without aligned offsets. */
2151 executable_code code
;
2152 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2158 printf("Run test26\n");
2160 FAILED(!compiler
, "cannot create compiler\n");
2177 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 3, 3, 0, 0, 0);
2179 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 3);
2180 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 1);
2181 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), -3);
2182 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
) - 1, SLJIT_R0
, 0);
2183 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), -1);
2184 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) - 3, SLJIT_R0
, 0);
2186 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 100);
2187 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);
2188 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 100);
2189 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);
2191 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
2192 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 3);
2193 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f64
) - 3, SLJIT_MEM1(SLJIT_S2
), -3);
2194 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);
2195 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 2);
2196 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sizeof(sljit_f64
) * 3 - 4) >> 1);
2197 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 1);
2198 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);
2201 sljit_emit_return_void(compiler
);
2203 code
.code
= sljit_generate_code(compiler
);
2205 sljit_free_compiler(compiler
);
2207 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&ibuf
, (sljit_sw
)&dbuf
);
2209 FAILED(buf
[1] != -689, "test26 case 1 failed\n");
2210 FAILED(buf
[2] != -16, "test26 case 2 failed\n");
2211 FAILED(ibuf
[1] != -2789, "test26 case 3 failed\n");
2212 FAILED(ibuf
[2] != -18, "test26 case 4 failed\n");
2214 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
2215 FAILED(dbuf
[1] != 5.75, "test26 case 5 failed\n");
2216 FAILED(dbuf
[2] != 11.5, "test26 case 6 failed\n");
2217 FAILED(dbuf
[3] != -2.875, "test26 case 7 failed\n");
2220 sljit_free_code(code
.code
, NULL
);
2224 static void test27(void)
2226 #define SET_NEXT_BYTE(type) \
2227 cond_set(compiler, SLJIT_R2, 0, type); \
2228 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R2, 0); \
2229 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2230 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2233 #define RESULT(i) (3 - i)
2236 /* Playing with conditional flags. */
2237 executable_code code
;
2238 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2241 #ifdef SLJIT_PREF_SHIFT_REG
2242 sljit_s32 shift_reg
= SLJIT_PREF_SHIFT_REG
;
2244 sljit_s32 shift_reg
= SLJIT_R2
;
2247 SLJIT_ASSERT(shift_reg
>= SLJIT_R2
&& shift_reg
<= SLJIT_R3
);
2250 printf("Run test27\n");
2252 for (i
= 0; i
< sizeof(buf
); ++i
)
2255 FAILED(!compiler
, "cannot create compiler\n");
2257 /* 3 arguments passed, 3 arguments used. */
2258 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 4, 3, 0, 0, 0);
2260 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
2262 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1001);
2263 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 20);
2264 /* 0x100100000 on 64 bit machines, 0x100000 on 32 bit machines. */
2265 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x800000);
2266 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2267 sljit_emit_op0(compiler
, SLJIT_ENDBR
); /* ENDBR should keep the flags. */
2268 sljit_emit_op0(compiler
, SLJIT_NOP
); /* Nop should keep the flags. */
2269 SET_NEXT_BYTE(SLJIT_GREATER
);
2270 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2271 SET_NEXT_BYTE(SLJIT_LESS
);
2272 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2273 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
2274 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2275 sljit_emit_op0(compiler
, SLJIT_ENDBR
); /* ENDBR should keep the flags. */
2276 sljit_emit_op0(compiler
, SLJIT_NOP
); /* Nop should keep the flags. */
2277 SET_NEXT_BYTE(SLJIT_GREATER
);
2278 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2279 SET_NEXT_BYTE(SLJIT_LESS
);
2281 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1000);
2282 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 20);
2283 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0x10);
2284 /* 0x100000010 on 64 bit machines, 0x10 on 32 bit machines. */
2285 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2286 SET_NEXT_BYTE(SLJIT_GREATER
);
2287 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2288 SET_NEXT_BYTE(SLJIT_LESS
);
2289 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2290 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2291 SET_NEXT_BYTE(SLJIT_GREATER
);
2292 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 0x80);
2293 SET_NEXT_BYTE(SLJIT_LESS
);
2295 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2296 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2297 /* 0xff..ff on all machines. */
2298 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2299 SET_NEXT_BYTE(SLJIT_LESS_EQUAL
);
2300 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2301 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL
);
2302 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R2
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -1);
2303 SET_NEXT_BYTE(SLJIT_SIG_GREATER
);
2304 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -1);
2305 SET_NEXT_BYTE(SLJIT_SIG_LESS
);
2306 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
2307 SET_NEXT_BYTE(SLJIT_EQUAL
);
2308 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
2309 SET_NEXT_BYTE(SLJIT_NOT_EQUAL
);
2310 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2311 SET_NEXT_BYTE(SLJIT_OVERFLOW
);
2312 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2313 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW
);
2314 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2315 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL
);
2316 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -2);
2317 SET_NEXT_BYTE(SLJIT_LESS_EQUAL
);
2318 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)((sljit_uw
)1 << ((8 * sizeof(sljit_uw
)) - 1)));
2319 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2320 SET_NEXT_BYTE(SLJIT_SIG_LESS
);
2321 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -1);
2322 SET_NEXT_BYTE(SLJIT_SIG_GREATER
);
2323 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2324 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -2);
2325 SET_NEXT_BYTE(SLJIT_SIG_GREATER_EQUAL
);
2326 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 2);
2327 SET_NEXT_BYTE(SLJIT_SIG_GREATER
);
2329 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x80000000);
2330 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 16);
2331 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 16);
2332 /* 0x80..0 on 64 bit machines, 0 on 32 bit machines. */
2333 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)0xffffffff);
2334 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2335 SET_NEXT_BYTE(SLJIT_OVERFLOW
);
2336 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2337 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW
);
2338 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2339 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
2340 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2341 SET_NEXT_BYTE(SLJIT_OVERFLOW
);
2342 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2343 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW
);
2345 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2346 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2347 sljit_emit_op2u(compiler
, SLJIT_SUBC
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2348 sljit_emit_op2(compiler
, SLJIT_SUBC
, SLJIT_R0
, 0, SLJIT_IMM
, 6, SLJIT_R0
, 0);
2349 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_R0
, 0);
2350 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
2352 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
2353 sljit_emit_op2u(compiler
, SLJIT_ADD
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2354 sljit_emit_op2u(compiler
, SLJIT_ADDC
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2355 sljit_emit_op2(compiler
, SLJIT_ADDC
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 9);
2356 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_R0
, 0);
2357 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
2359 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2360 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, (8 * sizeof(sljit_sw
)) - 1);
2361 sljit_emit_op2u(compiler
, SLJIT_ADD
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2362 SET_NEXT_BYTE(SLJIT_EQUAL
);
2363 sljit_emit_op2u(compiler
, SLJIT_ADD
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2364 SET_NEXT_BYTE(SLJIT_EQUAL
);
2366 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2367 sljit_emit_op2(compiler
, SLJIT_ASHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2368 SET_NEXT_BYTE(SLJIT_EQUAL
);
2369 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2370 sljit_emit_op2(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffffc0);
2371 SET_NEXT_BYTE(SLJIT_NOT_EQUAL
);
2372 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0);
2373 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2374 sljit_emit_op2(compiler
, SLJIT_ASHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, shift_reg
, 0);
2375 SET_NEXT_BYTE(SLJIT_EQUAL
);
2376 sljit_emit_op1(compiler
, SLJIT_MOV
, shift_reg
, 0, SLJIT_IMM
, 0);
2377 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2378 sljit_emit_op2(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R0
, 0, shift_reg
, 0);
2379 SET_NEXT_BYTE(SLJIT_NOT_EQUAL
);
2381 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
2382 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2383 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0);
2384 sljit_emit_op2(compiler
, SLJIT_SUBC
| SLJIT_SET_CARRY
, SLJIT_R2
, 0, SLJIT_IMM
, 1, SLJIT_R0
, 0);
2385 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_R2
, 0);
2386 sljit_emit_op2u(compiler
, SLJIT_SUBC
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2387 sljit_emit_op2(compiler
, SLJIT_SUBC
, SLJIT_R2
, 0, SLJIT_IMM
, 1, SLJIT_R0
, 0);
2388 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 2, SLJIT_R2
, 0);
2389 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 2);
2391 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -34);
2392 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1234);
2393 SET_NEXT_BYTE(SLJIT_LESS
);
2394 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1234);
2395 SET_NEXT_BYTE(SLJIT_SIG_LESS
);
2396 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2397 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x12300000000) - 43);
2399 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, -43);
2401 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -96);
2402 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2403 SET_NEXT_BYTE(SLJIT_LESS
);
2404 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2405 SET_NEXT_BYTE(SLJIT_SIG_GREATER
);
2407 sljit_emit_return_void(compiler
);
2409 code
.code
= sljit_generate_code(compiler
);
2411 sljit_free_compiler(compiler
);
2413 code
.func1((sljit_sw
)&buf
);
2415 FAILED(buf
[0] != RESULT(1), "test27 case 1 failed\n");
2416 FAILED(buf
[1] != RESULT(2), "test27 case 2 failed\n");
2417 FAILED(buf
[2] != 2, "test27 case 3 failed\n");
2418 FAILED(buf
[3] != 1, "test27 case 4 failed\n");
2419 FAILED(buf
[4] != RESULT(1), "test27 case 5 failed\n");
2420 FAILED(buf
[5] != RESULT(2), "test27 case 6 failed\n");
2421 FAILED(buf
[6] != 2, "test27 case 7 failed\n");
2422 FAILED(buf
[7] != 1, "test27 case 8 failed\n");
2424 FAILED(buf
[8] != 2, "test27 case 9 failed\n");
2425 FAILED(buf
[9] != 1, "test27 case 10 failed\n");
2426 FAILED(buf
[10] != 2, "test27 case 11 failed\n");
2427 FAILED(buf
[11] != 1, "test27 case 12 failed\n");
2428 FAILED(buf
[12] != 1, "test27 case 13 failed\n");
2429 FAILED(buf
[13] != 2, "test27 case 14 failed\n");
2430 FAILED(buf
[14] != 2, "test27 case 15 failed\n");
2431 FAILED(buf
[15] != 1, "test27 case 16 failed\n");
2432 FAILED(buf
[16] != 1, "test27 case 17 failed\n");
2433 FAILED(buf
[17] != 2, "test27 case 18 failed\n");
2434 FAILED(buf
[18] != 1, "test27 case 19 failed\n");
2435 FAILED(buf
[19] != 1, "test27 case 20 failed\n");
2436 FAILED(buf
[20] != 1, "test27 case 21 failed\n");
2437 FAILED(buf
[21] != 2, "test27 case 22 failed\n");
2439 FAILED(buf
[22] != RESULT(1), "test27 case 23 failed\n");
2440 FAILED(buf
[23] != RESULT(2), "test27 case 24 failed\n");
2441 FAILED(buf
[24] != 2, "test27 case 25 failed\n");
2442 FAILED(buf
[25] != 1, "test27 case 26 failed\n");
2444 FAILED(buf
[26] != 5, "test27 case 27 failed\n");
2445 FAILED(buf
[27] != 9, "test27 case 28 failed\n");
2447 FAILED(buf
[28] != 2, "test27 case 29 failed\n");
2448 FAILED(buf
[29] != 1, "test27 case 30 failed\n");
2450 FAILED(buf
[30] != 1, "test27 case 31 failed\n");
2451 FAILED(buf
[31] != 1, "test27 case 32 failed\n");
2452 FAILED(buf
[32] != 1, "test27 case 33 failed\n");
2453 FAILED(buf
[33] != 1, "test27 case 34 failed\n");
2455 FAILED(buf
[34] != 1, "test27 case 35 failed\n");
2456 FAILED(buf
[35] != 0, "test27 case 36 failed\n");
2458 FAILED(buf
[36] != 2, "test27 case 37 failed\n");
2459 FAILED(buf
[37] != 1, "test27 case 38 failed\n");
2460 FAILED(buf
[38] != 2, "test27 case 39 failed\n");
2461 FAILED(buf
[39] != 1, "test27 case 40 failed\n");
2462 FAILED(buf
[40] != 10, "test27 case 41 failed\n");
2464 sljit_free_code(code
.code
, NULL
);
2466 #undef SET_NEXT_BYTE
2470 static void test28(void)
2473 executable_code code
;
2474 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2475 struct sljit_const
* const1
= NULL
;
2476 struct sljit_label
* label
= NULL
;
2477 sljit_uw label_addr
= 0;
2481 printf("Run test28\n");
2483 FAILED(!compiler
, "cannot create compiler\n");
2491 FAILED(!compiler
, "cannot create compiler\n");
2492 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 5, 5, 0, 0, 0);
2493 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -234);
2494 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
));
2495 sljit_emit_op2(compiler
, SLJIT_MUL
, SLJIT_S3
, 0, SLJIT_R3
, 0, SLJIT_R4
, 0);
2496 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_S3
, 0);
2497 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_S3
, 0, SLJIT_IMM
, 0);
2498 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_NOT_ZERO
);
2499 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_S3
, 0);
2500 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
));
2501 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S4
, 0, SLJIT_S4
, 0, SLJIT_R4
, 0);
2502 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_S4
, 0);
2504 const1
= sljit_emit_const(compiler
, SLJIT_S3
, 0, 0);
2505 sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_S3
, 0);
2506 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S3
, 0, SLJIT_S3
, 0, SLJIT_IMM
, 100);
2507 label
= sljit_emit_label(compiler
);
2508 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
2509 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_S3
, 0);
2511 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R4
, 0);
2513 code
.code
= sljit_generate_code(compiler
);
2516 label_addr
= sljit_get_label_addr(label
);
2517 sljit_set_const(sljit_get_const_addr(const1
), (sljit_sw
)label_addr
, sljit_get_executable_offset(compiler
));
2519 sljit_free_compiler(compiler
);
2521 FAILED(code
.func1((sljit_sw
)&buf
) != 8, "test28 case 1 failed\n");
2522 FAILED(buf
[1] != -1872, "test28 case 2 failed\n");
2523 FAILED(buf
[2] != 1, "test28 case 3 failed\n");
2524 FAILED(buf
[3] != 2, "test28 case 4 failed\n");
2525 FAILED(buf
[4] != (sljit_sw
)label_addr
, "test28 case 5 failed\n");
2527 sljit_free_code(code
.code
, NULL
);
2531 static void test29(void)
2533 /* Test signed/unsigned bytes and halfs. */
2534 executable_code code
;
2535 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2540 printf("Run test29\n");
2542 for (i
= 0; i
< 25; i
++)
2545 FAILED(!compiler
, "cannot create compiler\n");
2546 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 5, 5, 0, 0, 0);
2548 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_IMM
, -187);
2549 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
2550 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_IMM
, -605);
2551 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_R0
, 0);
2552 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R0
, 0, SLJIT_IMM
, -56);
2553 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2554 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R4
, 0, SLJIT_IMM
, 0xcde5);
2555 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2557 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_IMM
, -45896);
2558 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2559 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_IMM
, -1472797);
2560 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2561 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R0
, 0, SLJIT_IMM
, -12890);
2562 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2563 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R4
, 0, SLJIT_IMM
, 0x9cb0a6);
2564 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2566 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2567 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-3580429715));
2568 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2569 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-100722768662));
2570 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2571 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-1457052677972));
2572 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2573 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R4
, 0, SLJIT_IMM
, SLJIT_W(0xcef97a70b5));
2574 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2577 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -187);
2578 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2579 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2580 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -605);
2581 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_S2
, 0);
2582 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2583 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -56);
2584 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R0
, 0, SLJIT_R2
, 0);
2585 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2586 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0xcde5);
2587 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R4
, 0, SLJIT_R3
, 0);
2588 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2590 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -45896);
2591 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2592 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2593 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1472797);
2594 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_S2
, 0);
2595 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2596 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -12890);
2597 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R0
, 0, SLJIT_R2
, 0);
2598 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2599 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x9cb0a6);
2600 sljit_emit_op1(compiler
, SLJIT_MOV_U16
, SLJIT_R4
, 0, SLJIT_R3
, 0);
2601 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 19 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2603 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2604 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(-3580429715));
2605 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R1
, 0);
2606 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2607 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, SLJIT_W(-100722768662));
2608 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_S2
, 0);
2609 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 21 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2610 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, SLJIT_W(-1457052677972));
2611 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R2
, 0);
2612 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_uw
), SLJIT_R0
, 0);
2613 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_W(0xcef97a70b5));
2614 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R4
, 0, SLJIT_R3
, 0);
2615 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 23 * sizeof(sljit_uw
), SLJIT_R4
, 0);
2618 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, 0x9faa5);
2619 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_S2
, 0, SLJIT_S2
, 0);
2620 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 24 * sizeof(sljit_uw
), SLJIT_S2
, 0);
2622 sljit_emit_return_void(compiler
);
2624 code
.code
= sljit_generate_code(compiler
);
2626 sljit_free_compiler(compiler
);
2628 code
.func1((sljit_sw
)&buf
);
2629 FAILED(buf
[0] != 69, "test29 case 1 failed\n");
2630 FAILED(buf
[1] != -93, "test29 case 2 failed\n");
2631 FAILED(buf
[2] != 200, "test29 case 3 failed\n");
2632 FAILED(buf
[3] != 0xe5, "test29 case 4 failed\n");
2633 FAILED(buf
[4] != 19640, "test29 case 5 failed\n");
2634 FAILED(buf
[5] != -31005, "test29 case 6 failed\n");
2635 FAILED(buf
[6] != 52646, "test29 case 7 failed\n");
2636 FAILED(buf
[7] != 0xb0a6, "test29 case 8 failed\n");
2638 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2639 FAILED(buf
[8] != SLJIT_W(714537581), "test29 case 9 failed\n");
2640 FAILED(buf
[9] != SLJIT_W(-1938520854), "test29 case 10 failed\n");
2641 FAILED(buf
[10] != SLJIT_W(3236202668), "test29 case 11 failed\n");
2642 FAILED(buf
[11] != SLJIT_W(0xf97a70b5), "test29 case 12 failed\n");
2645 FAILED(buf
[12] != 69, "test29 case 13 failed\n");
2646 FAILED(buf
[13] != -93, "test29 case 14 failed\n");
2647 FAILED(buf
[14] != 200, "test29 case 15 failed\n");
2648 FAILED(buf
[15] != 0xe5, "test29 case 16 failed\n");
2649 FAILED(buf
[16] != 19640, "test29 case 17 failed\n");
2650 FAILED(buf
[17] != -31005, "test29 case 18 failed\n");
2651 FAILED(buf
[18] != 52646, "test29 case 19 failed\n");
2652 FAILED(buf
[19] != 0xb0a6, "test29 case 20 failed\n");
2654 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2655 FAILED(buf
[20] != SLJIT_W(714537581), "test29 case 21 failed\n");
2656 FAILED(buf
[21] != SLJIT_W(-1938520854), "test29 case 22 failed\n");
2657 FAILED(buf
[22] != SLJIT_W(3236202668), "test29 case 23 failed\n");
2658 FAILED(buf
[23] != SLJIT_W(0xf97a70b5), "test29 case 24 failed\n");
2661 FAILED(buf
[24] != -91, "test29 case 25 failed\n");
2663 sljit_free_code(code
.code
, NULL
);
2667 static void test30(void)
2669 /* Test unused results. */
2670 executable_code code
;
2671 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2675 printf("Run test30\n");
2677 FAILED(!compiler
, "cannot create compiler\n");
2679 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 5, 5, 0, 0, 0);
2681 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
2682 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2683 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 1);
2684 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 1);
2685 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, 1);
2686 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2687 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S1
, 0, SLJIT_IMM
, SLJIT_W(-0x123ffffffff));
2689 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S1
, 0, SLJIT_IMM
, 1);
2691 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, 1);
2692 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, 1);
2693 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_IMM
, 1);
2695 /* Some calculations with unused results. */
2696 sljit_emit_op2u(compiler
, SLJIT_ADD
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
2697 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_GREATER_EQUAL
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
2698 sljit_emit_op2u(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_S0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
2699 sljit_emit_op2u(compiler
, SLJIT_SHL
| SLJIT_SET_Z
, SLJIT_S3
, 0, SLJIT_R2
, 0);
2700 sljit_emit_op2u(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 5);
2701 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_IMM
, 0xff);
2703 /* Testing that any change happens. */
2704 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2705 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R2
, 0);
2706 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R3
, 0);
2707 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R4
, 0);
2708 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_S1
, 0, SLJIT_S1
, 0);
2709 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S1
, 0);
2710 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S2
, 0);
2711 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S3
, 0);
2712 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0, SLJIT_S4
, 0);
2714 sljit_emit_return_void(compiler
);
2716 code
.code
= sljit_generate_code(compiler
);
2718 sljit_free_compiler(compiler
);
2720 code
.func1((sljit_sw
)&buf
);
2721 FAILED(buf
[0] != 9, "test30 case 1 failed\n");
2723 sljit_free_code(code
.code
, NULL
);
2727 static void test31(void)
2729 /* Integer mul and set flags. */
2730 executable_code code
;
2731 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2734 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2735 sljit_sw big_word
= SLJIT_W(0x7fffffff00000000);
2736 sljit_sw big_word2
= SLJIT_W(0x7fffffff00000012);
2738 sljit_sw big_word
= 0x7fffffff;
2739 sljit_sw big_word2
= 0x00000012;
2743 printf("Run test31\n");
2745 for (i
= 0; i
< 12; i
++)
2748 FAILED(!compiler
, "cannot create compiler\n");
2750 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 5, 0, 0, 0);
2751 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
2752 sljit_emit_op2u(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_IMM
, -45);
2753 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_NOT_OVERFLOW
);
2754 sljit_emit_op2u(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_IMM
, -45);
2755 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_OVERFLOW
);
2757 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, big_word
);
2758 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, -2);
2759 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 33); /* Should not change flags. */
2760 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0); /* Should not change flags. */
2761 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
2762 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, -2);
2763 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_NOT_OVERFLOW
);
2765 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S3
, 0, SLJIT_IMM
, 0x3f6b0);
2766 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_S4
, 0, SLJIT_IMM
, 0x2a783);
2767 sljit_emit_op2(compiler
, SLJIT_MUL32
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_S3
, 0, SLJIT_S4
, 0);
2768 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
2769 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R1
, 0);
2771 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, big_word2
);
2772 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_R1
, 0);
2773 sljit_emit_op2(compiler
, SLJIT_MUL32
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 23);
2774 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
2776 sljit_emit_op2u(compiler
, SLJIT_MUL32
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_IMM
, -23);
2777 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_NOT_OVERFLOW
);
2778 sljit_emit_op2u(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_IMM
, -23);
2779 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_NOT_OVERFLOW
);
2781 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 67);
2782 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, -23);
2783 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R1
, 0);
2785 sljit_emit_return_void(compiler
);
2787 code
.code
= sljit_generate_code(compiler
);
2789 sljit_free_compiler(compiler
);
2791 code
.func1((sljit_sw
)&buf
);
2793 FAILED(buf
[0] != 1, "test31 case 1 failed\n");
2794 FAILED(buf
[1] != 2, "test31 case 2 failed\n");
2795 /* Qemu issues for 64 bit muls. */
2796 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2797 FAILED(buf
[2] != 1, "test31 case 3 failed\n");
2798 FAILED(buf
[3] != 2, "test31 case 4 failed\n");
2800 FAILED(buf
[4] != 1, "test31 case 5 failed\n");
2801 FAILED((buf
[5] & (sljit_sw
)0xffffffff) != (sljit_sw
)0x85540c10, "test31 case 6 failed\n");
2802 FAILED(buf
[6] != 2, "test31 case 7 failed\n");
2803 FAILED(buf
[7] != 1, "test31 case 8 failed\n");
2804 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2805 FAILED(buf
[8] != 1, "test31 case 9 failed\n");
2807 FAILED(buf
[9] != -1541, "test31 case 10 failed\n");
2809 sljit_free_code(code
.code
, NULL
);
2813 static void test32(void)
2815 /* Floating point set flags. */
2816 executable_code code
;
2817 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2830 printf("Run test32\n");
2832 for (i
= 0; i
< 16; i
++)
2836 dbuf
[0].u
.value1
= 0x7fffffff;
2837 dbuf
[0].u
.value2
= 0x7fffffff;
2838 dbuf
[1].u
.value1
= 0x7fffffff;
2839 dbuf
[1].u
.value2
= 0x7fffffff;
2840 dbuf
[2].value
= -13.0;
2841 dbuf
[3].value
= 27.0;
2843 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
2845 printf("no fpu available, test32 skipped\n");
2848 sljit_free_compiler(compiler
);
2852 FAILED(!compiler
, "cannot create compiler\n");
2853 SLJIT_ASSERT(sizeof(sljit_f64
) == 8 && sizeof(sljit_s32
) == 4 && sizeof(dbuf
[0]) == 8);
2855 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 1, 2, 4, 0, 0);
2857 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
2858 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
2859 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f64
));
2860 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_UNORDERED
);
2861 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_ORDERED
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
2862 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_ORDERED
);
2864 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
));
2865 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2866 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_UNORDERED
);
2867 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_ORDERED
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2868 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_ORDERED
);
2869 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_F_LESS
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2870 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_F_LESS
);
2871 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_F_GREATER_EQUAL
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2872 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_F_GREATER_EQUAL
);
2873 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_F_GREATER
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2874 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_F_GREATER
);
2875 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_F_LESS_EQUAL
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2876 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_F_LESS_EQUAL
);
2877 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_F_EQUAL
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2878 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_F_EQUAL
);
2879 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_F_NOT_EQUAL
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
2880 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_F_NOT_EQUAL
);
2882 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR3
, 0, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
));
2883 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
));
2884 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_UNORDERED
);
2885 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_F_EQUAL
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
));
2886 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_F_EQUAL
);
2888 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_ORDERED
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
), SLJIT_FR0
, 0);
2889 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_ORDERED
);
2891 sljit_emit_fop1(compiler
, SLJIT_CMP_F64
| SLJIT_SET_UNORDERED
, SLJIT_FR3
, 0, SLJIT_FR2
, 0);
2892 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
2893 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_UNORDERED
);
2895 sljit_emit_return_void(compiler
);
2897 code
.code
= sljit_generate_code(compiler
);
2899 sljit_free_compiler(compiler
);
2901 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&dbuf
);
2903 FAILED(buf
[0] != 1, "test32 case 1 failed\n");
2904 FAILED(buf
[1] != 2, "test32 case 2 failed\n");
2905 FAILED(buf
[2] != 2, "test32 case 3 failed\n");
2906 FAILED(buf
[3] != 1, "test32 case 4 failed\n");
2907 FAILED(buf
[4] != 1, "test32 case 5 failed\n");
2908 FAILED(buf
[5] != 2, "test32 case 6 failed\n");
2909 FAILED(buf
[6] != 2, "test32 case 7 failed\n");
2910 FAILED(buf
[7] != 1, "test32 case 8 failed\n");
2911 FAILED(buf
[8] != 2, "test32 case 9 failed\n");
2912 FAILED(buf
[9] != 1, "test32 case 10 failed\n");
2913 FAILED(buf
[10] != 2, "test32 case 11 failed\n");
2914 FAILED(buf
[11] != 1, "test32 case 12 failed\n");
2915 FAILED(buf
[12] != 2, "test32 case 13 failed\n");
2916 FAILED(buf
[13] != 1, "test32 case 14 failed\n");
2918 sljit_free_code(code
.code
, NULL
);
2922 static void test33(void)
2924 /* Test setting multiple flags. */
2925 executable_code code
;
2926 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
2927 struct sljit_jump
* jump
;
2931 printf("Run test33\n");
2944 FAILED(!compiler
, "cannot create compiler\n");
2946 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 3, 0, 0, 0);
2948 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 20);
2949 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 10);
2950 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2951 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_ZERO
);
2952 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -10);
2953 jump
= sljit_emit_jump(compiler
, SLJIT_LESS
);
2954 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_IMM
, 11);
2955 sljit_set_label(jump
, sljit_emit_label(compiler
));
2957 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_SIG_GREATER
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2958 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_SIG_GREATER
);
2959 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 45);
2960 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_EQUAL
);
2961 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_IMM
, 55);
2962 sljit_set_label(jump
, sljit_emit_label(compiler
));
2964 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2965 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)SLJIT_W(0x8000000000000000));
2967 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)SLJIT_W(0x80000000));
2969 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
2970 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2971 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, 33);
2972 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_OVERFLOW
);
2973 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_ZERO
);
2974 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, 13);
2975 sljit_set_label(jump
, sljit_emit_label(compiler
));
2977 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x80000000);
2978 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R0
, 0);
2979 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2980 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
2981 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_NOT_ZERO
);
2982 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, 78);
2983 jump
= sljit_emit_jump(compiler
, SLJIT_OVERFLOW
);
2984 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_IMM
, 48);
2985 sljit_set_label(jump
, sljit_emit_label(compiler
));
2987 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2988 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)SLJIT_W(0x8000000000000000));
2990 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)SLJIT_W(0x80000000));
2992 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_R0
, 0);
2993 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_Z
| SLJIT_SET_OVERFLOW
, SLJIT_R2
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
2994 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_IMM
, 30);
2995 jump
= sljit_emit_jump(compiler
, SLJIT_NOT_OVERFLOW
);
2996 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_IMM
, 50);
2997 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_ZERO
);
2998 sljit_set_label(jump
, sljit_emit_label(compiler
));
3000 sljit_emit_return_void(compiler
);
3002 code
.code
= sljit_generate_code(compiler
);
3004 sljit_free_compiler(compiler
);
3006 code
.func1((sljit_sw
)&buf
);
3008 FAILED(buf
[0] != 0, "test33 case 1 failed\n");
3009 FAILED(buf
[1] != 11, "test33 case 2 failed\n");
3010 FAILED(buf
[2] != 1, "test33 case 3 failed\n");
3011 FAILED(buf
[3] != 45, "test33 case 4 failed\n");
3012 FAILED(buf
[4] != 13, "test33 case 5 failed\n");
3013 FAILED(buf
[5] != 0, "test33 case 6 failed\n");
3014 FAILED(buf
[6] != 0, "test33 case 7 failed\n");
3015 FAILED(buf
[7] != 48, "test33 case 8 failed\n");
3016 FAILED(buf
[8] != 50, "test33 case 9 failed\n");
3017 FAILED(buf
[9] != 1, "test33 case 10 failed\n");
3019 sljit_free_code(code
.code
, NULL
);
3023 static void test34(void)
3025 /* Test fast calls. */
3026 executable_code codeA
;
3027 executable_code codeB
;
3028 executable_code codeC
;
3029 executable_code codeD
;
3030 executable_code codeE
;
3031 executable_code codeF
;
3032 struct sljit_compiler
* compiler
;
3033 struct sljit_jump
*jump
;
3034 struct sljit_label
* label
;
3039 printf("Run test34\n");
3045 compiler
= sljit_create_compiler(NULL
, NULL
);
3046 FAILED(!compiler
, "cannot create compiler\n");
3047 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3049 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3050 sljit_emit_fast_enter(compiler
, SLJIT_R1
, 0);
3051 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 4);
3052 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R1
, 0);
3054 codeA
.code
= sljit_generate_code(compiler
);
3056 sljit_free_compiler(compiler
);
3059 compiler
= sljit_create_compiler(NULL
, NULL
);
3060 FAILED(!compiler
, "cannot create compiler\n");
3061 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3063 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3064 sljit_emit_fast_enter(compiler
, SLJIT_R4
, 0);
3065 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 6);
3066 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(codeA
.code
));
3067 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_R1
, 0);
3068 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R4
, 0);
3070 codeB
.code
= sljit_generate_code(compiler
);
3072 sljit_free_compiler(compiler
);
3075 compiler
= sljit_create_compiler(NULL
, NULL
);
3076 FAILED(!compiler
, "cannot create compiler\n");
3077 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3079 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3080 sljit_emit_fast_enter(compiler
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_p
));
3081 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3082 jump
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
| SLJIT_REWRITABLE_JUMP
);
3083 sljit_set_target(jump
, SLJIT_FUNC_UADDR(codeB
.code
));
3084 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_p
));
3086 codeC
.code
= sljit_generate_code(compiler
);
3088 sljit_free_compiler(compiler
);
3091 compiler
= sljit_create_compiler(NULL
, NULL
);
3092 FAILED(!compiler
, "cannot create compiler\n");
3093 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3095 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3096 sljit_emit_fast_enter(compiler
, SLJIT_MEM1(SLJIT_SP
), 0);
3097 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 10);
3098 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_ADDR(codeC
.code
));
3099 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_MEM1(SLJIT_SP
), 0);
3101 codeD
.code
= sljit_generate_code(compiler
);
3103 sljit_free_compiler(compiler
);
3106 compiler
= sljit_create_compiler(NULL
, NULL
);
3107 FAILED(!compiler
, "cannot create compiler\n");
3108 sljit_set_context(compiler
, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3110 sljit_emit_fast_enter(compiler
, SLJIT_MEM1(SLJIT_S0
), 0);
3111 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 12);
3112 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_p
), SLJIT_IMM
, SLJIT_FUNC_ADDR(codeD
.code
));
3113 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_p
));
3114 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_MEM1(SLJIT_S0
), 0);
3116 codeE
.code
= sljit_generate_code(compiler
);
3118 sljit_free_compiler(compiler
);
3121 compiler
= sljit_create_compiler(NULL
, NULL
);
3122 FAILED(!compiler
, "cannot create compiler\n");
3124 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 5, 5, 0, 0, 2 * sizeof(sljit_p
));
3125 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3126 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_ADDR(codeE
.code
));
3127 label
= sljit_emit_label(compiler
);
3128 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
3130 codeF
.code
= sljit_generate_code(compiler
);
3132 addr
= sljit_get_label_addr(label
);
3133 sljit_free_compiler(compiler
);
3135 FAILED(codeF
.func1((sljit_sw
)&buf
) != 40, "test34 case 1 failed\n");
3136 FAILED(buf
[0] != addr
- SLJIT_RETURN_ADDRESS_OFFSET
, "test34 case 2 failed\n");
3138 sljit_free_code(codeA
.code
, NULL
);
3139 sljit_free_code(codeB
.code
, NULL
);
3140 sljit_free_code(codeC
.code
, NULL
);
3141 sljit_free_code(codeD
.code
, NULL
);
3142 sljit_free_code(codeE
.code
, NULL
);
3143 sljit_free_code(codeF
.code
, NULL
);
3147 static void test35(void)
3149 /* More complicated tests for fast calls. */
3150 executable_code codeA
;
3151 executable_code codeB
;
3152 executable_code codeC
;
3153 struct sljit_compiler
* compiler
;
3154 struct sljit_jump
*jump
= NULL
;
3155 struct sljit_label
* label
;
3156 sljit_sw executable_offset
;
3157 sljit_uw return_addr
;
3158 sljit_uw jump_addr
= 0;
3162 printf("Run test35\n");
3167 compiler
= sljit_create_compiler(NULL
, NULL
);
3168 FAILED(!compiler
, "cannot create compiler\n");
3169 sljit_set_context(compiler
, 0, 0, 2, 2, 0, 0, 0);
3171 sljit_emit_fast_enter(compiler
, SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
3172 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3174 jump
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
| SLJIT_REWRITABLE_JUMP
);
3175 sljit_set_target(jump
, 0);
3177 label
= sljit_emit_label(compiler
);
3178 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_MEM0(), (sljit_sw
)&buf
[0]);
3180 codeA
.code
= sljit_generate_code(compiler
);
3182 executable_offset
= sljit_get_executable_offset(compiler
);
3183 jump_addr
= sljit_get_jump_addr(jump
);
3184 sljit_free_compiler(compiler
);
3187 compiler
= sljit_create_compiler(NULL
, NULL
);
3188 FAILED(!compiler
, "cannot create compiler\n");
3189 sljit_set_context(compiler
, 0, 0, 2, 2, 0, 0, 0);
3191 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3192 sljit_emit_fast_enter(compiler
, SLJIT_R1
, 0);
3193 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 7);
3194 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R1
, 0);
3196 codeB
.code
= sljit_generate_code(compiler
);
3198 sljit_free_compiler(compiler
);
3200 sljit_set_jump_addr(jump_addr
, SLJIT_FUNC_UADDR(codeB
.code
), executable_offset
);
3203 compiler
= sljit_create_compiler(NULL
, NULL
);
3204 FAILED(!compiler
, "cannot create compiler\n");
3206 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), 2, 2, 0, 0, 0);
3207 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3208 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_ADDR(codeA
.code
));
3209 label
= sljit_emit_label(compiler
);
3210 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
3212 codeC
.code
= sljit_generate_code(compiler
);
3214 return_addr
= sljit_get_label_addr(label
);
3215 sljit_free_compiler(compiler
);
3217 FAILED(codeC
.func0() != 12, "test35 case 1 failed\n");
3218 FAILED(buf
[0] != return_addr
- SLJIT_RETURN_ADDRESS_OFFSET
, "test35 case 2 failed\n");
3220 sljit_free_code(codeA
.code
, NULL
);
3221 sljit_free_code(codeB
.code
, NULL
);
3222 sljit_free_code(codeC
.code
, NULL
);
3226 static void cmp_test(struct sljit_compiler
*compiler
, sljit_s32 type
, sljit_s32 src1
, sljit_sw src1w
, sljit_s32 src2
, sljit_sw src2w
)
3228 /* 2 = true, 1 = false */
3229 struct sljit_jump
* jump
;
3230 struct sljit_label
* label
;
3232 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_IMM
, 2);
3233 jump
= sljit_emit_cmp(compiler
, type
, src1
, src1w
, src2
, src2w
);
3234 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 1, SLJIT_IMM
, 1);
3235 label
= sljit_emit_label(compiler
);
3236 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
3237 sljit_set_label(jump
, label
);
3238 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
3241 #define TEST_CASES (7 + 10 + 12 + 11 + 4)
3242 static void test36(void)
3244 /* Compare instruction. */
3245 executable_code code
;
3246 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3248 sljit_s8 buf
[TEST_CASES
];
3249 sljit_s8 compare_buf
[TEST_CASES
] = {
3250 1, 1, 2, 2, 1, 2, 2,
3251 1, 1, 2, 2, 2, 1, 2, 2, 1, 1,
3252 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2,
3253 2, 1, 2, 1, 1, 1, 2, 1, 2, 1, 2,
3260 printf("Run test36\n");
3262 FAILED(!compiler
, "cannot create compiler\n");
3263 for (i
= 0; i
< TEST_CASES
; ++i
)
3270 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 3, 2, 0, 0, 0);
3271 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
3273 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 13);
3274 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 15);
3275 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_IMM
, 9, SLJIT_R0
, 0);
3276 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3277 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
3278 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_IMM
, -13);
3279 cmp_test(compiler
, SLJIT_NOT_EQUAL
, SLJIT_IMM
, 0, SLJIT_R0
, 0);
3280 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3281 cmp_test(compiler
, SLJIT_NOT_EQUAL
| SLJIT_REWRITABLE_JUMP
, SLJIT_IMM
, 0, SLJIT_R0
, 0);
3282 cmp_test(compiler
, SLJIT_EQUAL
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
);
3283 cmp_test(compiler
, SLJIT_EQUAL
| SLJIT_REWRITABLE_JUMP
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3285 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, 0);
3286 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -8);
3287 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3288 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3289 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3290 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_REWRITABLE_JUMP
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3291 cmp_test(compiler
, SLJIT_SIG_GREATER_EQUAL
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3292 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
));
3293 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_IMM
, 0, SLJIT_R1
, 0);
3294 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
));
3295 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
));
3296 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_REWRITABLE_JUMP
, SLJIT_IMM
, 0, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
));
3298 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3299 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3300 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
));
3301 cmp_test(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3302 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, -10);
3303 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
3304 cmp_test(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_IMM
, 8, SLJIT_R1
, 0);
3305 cmp_test(compiler
, SLJIT_GREATER_EQUAL
| SLJIT_REWRITABLE_JUMP
, SLJIT_IMM
, 8, SLJIT_R1
, 0);
3306 cmp_test(compiler
, SLJIT_GREATER
, SLJIT_IMM
, 8, SLJIT_R1
, 0);
3307 cmp_test(compiler
, SLJIT_LESS_EQUAL
, SLJIT_IMM
, 7, SLJIT_R0
, 0);
3308 cmp_test(compiler
, SLJIT_GREATER
, SLJIT_IMM
, 1, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
));
3309 cmp_test(compiler
, SLJIT_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3310 cmp_test(compiler
, SLJIT_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3311 cmp_test(compiler
, SLJIT_GREATER
| SLJIT_REWRITABLE_JUMP
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3313 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -3);
3314 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3315 cmp_test(compiler
, SLJIT_SIG_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3316 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
3317 cmp_test(compiler
, SLJIT_SIG_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3318 cmp_test(compiler
, SLJIT_SIG_LESS
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, -1);
3319 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_REWRITABLE_JUMP
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_IMM
, -1);
3320 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3321 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3322 cmp_test(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_IMM
, -4, SLJIT_R0
, 0);
3323 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_IMM
, -1, SLJIT_R1
, 0);
3324 cmp_test(compiler
, SLJIT_SIG_GREATER
| SLJIT_REWRITABLE_JUMP
, SLJIT_R1
, 0, SLJIT_IMM
, -1);
3326 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3327 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xf00000004));
3328 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_R0
, 0);
3329 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
3330 cmp_test(compiler
, SLJIT_LESS
| SLJIT_32
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
3331 cmp_test(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3332 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xff0000004));
3333 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_R0
, 0);
3334 cmp_test(compiler
, SLJIT_SIG_GREATER
| SLJIT_32
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
3335 cmp_test(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3337 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
3338 cmp_test(compiler
, SLJIT_LESS
| SLJIT_32
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3339 cmp_test(compiler
, SLJIT_GREATER
| SLJIT_32
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3340 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0xf0000004);
3341 cmp_test(compiler
, SLJIT_SIG_GREATER
| SLJIT_32
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3342 cmp_test(compiler
, SLJIT_SIG_LESS
| SLJIT_32
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
3345 sljit_emit_return_void(compiler
);
3347 code
.code
= sljit_generate_code(compiler
);
3349 sljit_free_compiler(compiler
);
3351 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&data
);
3353 for (i
= 0; i
< TEST_CASES
; ++i
)
3354 if (SLJIT_UNLIKELY(buf
[i
] != compare_buf
[i
])) {
3355 printf("test36 case %d failed\n", i
+ 1);
3359 sljit_free_code(code
.code
, NULL
);
3364 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3365 #define BITN(n) (SLJIT_W(1) << (63 - (n)))
3368 #define BITN(n) (1 << (31 - ((n) & 0x1f)))
3369 #define RESN(n) ((n) & 0x1f)
3372 static void test37(void)
3374 /* Test count leading zeroes. */
3375 executable_code code
;
3376 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3382 printf("Run test37\n");
3384 FAILED(!compiler
, "cannot create compiler\n");
3386 for (i
= 0; i
< 9; i
++)
3392 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 1, 3, 0, 0, 0);
3393 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, BITN(27));
3394 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
3395 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, BITN(47));
3396 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_R0
, 0, SLJIT_S2
, 0);
3397 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
3398 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
));
3399 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
3400 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3401 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3402 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3403 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_R0
, 0);
3404 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
3405 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
));
3406 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3407 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, BITN(58));
3408 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3409 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
3410 sljit_emit_op1(compiler
, SLJIT_CLZ
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3411 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3412 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xff08a00000));
3414 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x08a00000);
3416 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
), SLJIT_R0
, 0);
3417 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3418 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3419 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3420 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xffc8a00000));
3422 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0xc8a00000);
3424 sljit_emit_op1(compiler
, SLJIT_CLZ32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
3425 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3427 sljit_emit_return_void(compiler
);
3429 code
.code
= sljit_generate_code(compiler
);
3431 sljit_free_compiler(compiler
);
3433 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&ibuf
);
3434 FAILED(buf
[0] != RESN(27), "test37 case 1 failed\n");
3435 FAILED(buf
[1] != RESN(47), "test37 case 2 failed\n");
3436 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3437 FAILED(buf
[2] != 64, "test37 case 3 failed\n");
3439 FAILED(buf
[2] != 32, "test37 case 3 failed\n");
3441 FAILED(buf
[3] != 0, "test37 case 4 failed\n");
3442 FAILED(ibuf
[0] != 32, "test37 case 5 failed\n");
3443 FAILED(buf
[4] != RESN(13), "test37 case 6 failed\n");
3444 FAILED(buf
[5] != RESN(58), "test37 case 7 failed\n");
3445 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3446 FAILED(buf
[6] != 64, "test37 case 8 failed\n");
3448 FAILED(buf
[6] != 32, "test37 case 8 failed\n");
3450 FAILED(ibuf
[1] != 4, "test37 case 9 failed\n");
3452 FAILED((buf
[7] & (sljit_sw
)0xffffffff) != 4, "test37 case 10 failed\n");
3453 FAILED((buf
[8] & (sljit_sw
)0xffffffff) != 0, "test37 case 11 failed\n");
3455 sljit_free_code(code
.code
, NULL
);
3461 static void test38(void)
3463 #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)
3464 /* Test stack utility. */
3465 executable_code code
;
3466 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3467 struct sljit_jump
* alloc1_fail
;
3468 struct sljit_jump
* alloc2_fail
;
3469 struct sljit_jump
* alloc3_fail
;
3470 struct sljit_jump
* sanity1_fail
;
3471 struct sljit_jump
* sanity2_fail
;
3472 struct sljit_jump
* sanity3_fail
;
3473 struct sljit_jump
* sanity4_fail
;
3474 struct sljit_jump
* jump
;
3475 struct sljit_label
* label
;
3478 printf("Run test38\n");
3480 FAILED(!compiler
, "cannot create compiler\n");
3482 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), 3, 1, 0, 0, 0);
3484 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8192);
3485 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 65536);
3486 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0);
3487 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(P
, W
, W
, P
), SLJIT_IMM
, SLJIT_FUNC_ADDR(sljit_allocate_stack
));
3488 alloc1_fail
= sljit_emit_cmp(compiler
, SLJIT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0);
3489 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_RETURN_REG
, 0);
3491 /* Write 8k data. */
3492 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3493 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8192);
3494 label
= sljit_emit_label(compiler
);
3495 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_IMM
, -1);
3496 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
3497 jump
= sljit_emit_cmp(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3498 sljit_set_label(jump
, label
);
3501 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
3502 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, end
), SLJIT_IMM
, 65536);
3503 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS2(P
, P
, P
), SLJIT_IMM
, SLJIT_FUNC_ADDR(sljit_stack_resize
));
3504 alloc2_fail
= sljit_emit_cmp(compiler
, SLJIT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0);
3505 sanity1_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3507 /* Write 64k data. */
3508 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3509 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 65536);
3510 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, min_start
));
3511 sanity2_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, 0, SLJIT_R2
, 0);
3512 label
= sljit_emit_label(compiler
);
3513 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_IMM
, -1);
3514 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
3515 jump
= sljit_emit_cmp(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3516 sljit_set_label(jump
, label
);
3519 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
3520 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, end
), SLJIT_IMM
, 32768);
3521 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS2(P
, P
, P
), SLJIT_IMM
, SLJIT_FUNC_ADDR(sljit_stack_resize
));
3522 alloc3_fail
= sljit_emit_cmp(compiler
, SLJIT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 0);
3523 sanity3_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_RETURN_REG
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3525 /* Write 32k data. */
3526 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, start
));
3527 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_S0
), SLJIT_OFFSETOF(struct sljit_stack
, end
));
3528 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R2
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 32768);
3529 sanity4_fail
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, 0, SLJIT_R2
, 0);
3530 label
= sljit_emit_label(compiler
);
3531 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_IMM
, -1);
3532 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_sw
));
3533 jump
= sljit_emit_cmp(compiler
, SLJIT_LESS
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3534 sljit_set_label(jump
, label
);
3536 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
3537 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3538 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS2(VOID
, P
, P
), SLJIT_IMM
, SLJIT_FUNC_ADDR(sljit_free_stack
));
3540 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, 4567);
3542 label
= sljit_emit_label(compiler
);
3543 sljit_set_label(alloc1_fail
, label
);
3544 sljit_set_label(alloc2_fail
, label
);
3545 sljit_set_label(alloc3_fail
, label
);
3546 sljit_set_label(sanity1_fail
, label
);
3547 sljit_set_label(sanity2_fail
, label
);
3548 sljit_set_label(sanity3_fail
, label
);
3549 sljit_set_label(sanity4_fail
, label
);
3550 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, 0);
3552 code
.code
= sljit_generate_code(compiler
);
3554 sljit_free_compiler(compiler
);
3556 /* Just survive this. */
3557 FAILED(code
.func0() != 4567, "test38 case 1 failed\n");
3559 sljit_free_code(code
.code
, NULL
);
3564 static void test39(void)
3566 /* Test error handling. */
3567 executable_code code
;
3568 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3569 struct sljit_jump
* jump
;
3572 printf("Run test39\n");
3574 FAILED(!compiler
, "cannot create compiler\n");
3576 /* Such assignment should never happen in a regular program. */
3577 compiler
->error
= -3967;
3579 SLJIT_ASSERT(sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, W
, W
), 5, 5, 6, 0, 32) == -3967);
3580 SLJIT_ASSERT(sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R1
, 0) == -3967);
3581 SLJIT_ASSERT(sljit_emit_op0(compiler
, SLJIT_NOP
) == -3967);
3582 SLJIT_ASSERT(sljit_emit_op0(compiler
, SLJIT_ENDBR
) == -3967);
3583 SLJIT_ASSERT(sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1) == -3967);
3584 SLJIT_ASSERT(sljit_emit_op2(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R0
), 64, SLJIT_MEM1(SLJIT_S0
), -64) == -3967);
3585 SLJIT_ASSERT(sljit_emit_fop1(compiler
, SLJIT_ABS_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_R1
), 0) == -3967);
3586 SLJIT_ASSERT(sljit_emit_fop2(compiler
, SLJIT_DIV_F64
, SLJIT_FR2
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_S0
), 0, SLJIT_FR2
, 0) == -3967);
3587 SLJIT_ASSERT(!sljit_emit_label(compiler
));
3588 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS4(W
, 32, P
, F32
, F64
));
3589 SLJIT_ASSERT(!jump
);
3590 sljit_set_label(jump
, (struct sljit_label
*)0x123450);
3591 sljit_set_target(jump
, 0x123450);
3592 jump
= sljit_emit_cmp(compiler
, SLJIT_SIG_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3593 SLJIT_ASSERT(!jump
);
3594 SLJIT_ASSERT(sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_MEM1(SLJIT_R0
), 8) == -3967);
3595 SLJIT_ASSERT(sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_OVERFLOW
) == -3967);
3596 SLJIT_ASSERT(!sljit_emit_const(compiler
, SLJIT_R0
, 0, 99));
3598 SLJIT_ASSERT(!compiler
->labels
&& !compiler
->jumps
&& !compiler
->consts
);
3599 SLJIT_ASSERT(!compiler
->last_label
&& !compiler
->last_jump
&& !compiler
->last_const
);
3600 SLJIT_ASSERT(!compiler
->buf
->next
&& !compiler
->buf
->used_size
);
3601 SLJIT_ASSERT(!compiler
->abuf
->next
&& !compiler
->abuf
->used_size
);
3603 sljit_set_compiler_memory_error(compiler
);
3604 FAILED(sljit_get_compiler_error(compiler
) != -3967, "test39 case 1 failed\n");
3606 code
.code
= sljit_generate_code(compiler
);
3607 FAILED(sljit_get_compiler_error(compiler
) != -3967, "test39 case 2 failed\n");
3608 FAILED(!!code
.code
, "test39 case 3 failed\n");
3609 sljit_free_compiler(compiler
);
3611 compiler
= sljit_create_compiler(NULL
, NULL
);
3612 FAILED(!compiler
, "cannot create compiler\n");
3614 FAILED(sljit_get_compiler_error(compiler
) != SLJIT_SUCCESS
, "test39 case 4 failed\n");
3615 sljit_set_compiler_memory_error(compiler
);
3616 FAILED(sljit_get_compiler_error(compiler
) != SLJIT_ERR_ALLOC_FAILED
, "test39 case 5 failed\n");
3617 sljit_free_compiler(compiler
);
3622 static void test40(void)
3624 /* Test emit_op_flags. */
3625 executable_code code
;
3626 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3630 printf("Run test40\n");
3632 FAILED(!compiler
, "cannot create compiler\n");
3644 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 4, 0, 0, sizeof(sljit_sw
));
3646 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -5);
3647 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_IMM
, -6, SLJIT_R0
, 0);
3648 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x123456);
3649 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_R1
, 0, SLJIT_SIG_LESS
);
3650 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
3652 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -13);
3653 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_IMM
, -13, SLJIT_R0
, 0);
3654 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 0);
3655 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_EQUAL
);
3656 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_NOT_EQUAL
);
3657 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);
3658 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_IMM
, -13, SLJIT_R0
, 0);
3659 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
3660 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_EQUAL
);
3661 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 2, SLJIT_EQUAL
);
3663 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -13);
3664 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3);
3665 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
3666 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R1
), SLJIT_WORD_SHIFT
, SLJIT_SIG_LESS
);
3668 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -8);
3669 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 33);
3670 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3671 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, 0);
3672 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_GREATER
);
3673 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_S1
, 0, SLJIT_EQUAL
);
3674 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_R1
, 0);
3675 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, 0x88);
3676 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_S3
, 0, SLJIT_NOT_EQUAL
);
3677 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 4, SLJIT_S1
, 0);
3678 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 5, SLJIT_S3
, 0);
3680 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x84);
3681 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_IMM
, 0x180, SLJIT_R0
, 0);
3682 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 6, SLJIT_EQUAL
);
3683 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 7, SLJIT_EQUAL
);
3685 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3686 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3687 sljit_emit_op_flags(compiler
, SLJIT_OR
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_NOT_EQUAL
);
3688 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 8, SLJIT_NOT_EQUAL
);
3690 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x123456);
3691 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
3692 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_GREATER
);
3693 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
) * 9, SLJIT_R0
, 0);
3695 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 0xbaddead);
3696 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0);
3698 code
.code
= sljit_generate_code(compiler
);
3700 sljit_free_compiler(compiler
);
3702 FAILED(code
.func1((sljit_sw
)&buf
) != 0xbaddead, "test40 case 1 failed\n");
3703 FAILED(buf
[0] != 0x123457, "test40 case 2 failed\n");
3704 FAILED(buf
[1] != 1, "test40 case 3 failed\n");
3705 FAILED(buf
[2] != 0, "test40 case 4 failed\n");
3706 FAILED(buf
[3] != -7, "test40 case 5 failed\n");
3707 FAILED(buf
[4] != 0, "test40 case 6 failed\n");
3708 FAILED(buf
[5] != 0x89, "test40 case 7 failed\n");
3709 FAILED(buf
[6] != 0, "test40 case 8 failed\n");
3710 FAILED(buf
[7] != 1, "test40 case 9 failed\n");
3711 FAILED(buf
[8] != 1, "test40 case 10 failed\n");
3712 FAILED(buf
[9] != 0x123457, "test40 case 11 failed\n");
3714 sljit_free_code(code
.code
, NULL
);
3718 static void test41(void)
3720 /* Test inline assembly. */
3721 executable_code code
;
3722 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3725 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3727 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3735 printf("Run test41\n");
3737 #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3738 SLJIT_ASSERT(sljit_has_cpu_feature(SLJIT_HAS_VIRTUAL_REGISTERS
) == 0);
3741 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
3742 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3743 if (SLJIT_R(i
) >= SLJIT_R3
&& SLJIT_R(i
) <= SLJIT_R8
) {
3744 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i
)) == -1);
3748 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i
)) >= 0 && sljit_get_register_index(SLJIT_R(i
)) < 64);
3751 FAILED(!compiler
, "cannot create compiler\n");
3752 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(W
, W
, W
), 3, 3, 0, 0, 0);
3754 /* Returns with the sum of SLJIT_S0 and SLJIT_S1. */
3755 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3756 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3759 inst
[2] = (sljit_u8
)(0x04 | ((sljit_get_register_index(SLJIT_RETURN_REG
) & 0x7) << 3));
3760 inst
[3] = (sljit_u8
)((sljit_get_register_index(SLJIT_S0
) & 0x7)
3761 | ((sljit_get_register_index(SLJIT_S1
) & 0x7) << 3));
3762 sljit_emit_op_custom(compiler
, inst
, 4);
3763 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3764 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3765 inst
[0] = 0x48; /* REX_W */
3767 reg
= sljit_get_register_index(SLJIT_RETURN_REG
);
3768 inst
[2] = (sljit_u8
)(0x04 | ((reg
& 0x7) << 3));
3770 inst
[0] |= 0x04; /* REX_R */
3771 reg
= sljit_get_register_index(SLJIT_S0
);
3772 inst
[3] = (sljit_u8
)(reg
& 0x7);
3774 inst
[0] |= 0x01; /* REX_B */
3775 reg
= sljit_get_register_index(SLJIT_S1
);
3776 inst
[3] = (sljit_u8
)(inst
[3] | ((reg
& 0x7) << 3));
3778 inst
[0] |= 0x02; /* REX_X */
3779 sljit_emit_op_custom(compiler
, inst
, 4);
3780 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
3781 /* add rd, rn, rm */
3782 inst
= 0xe0800000 | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 12)
3783 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 16)
3784 | (sljit_u32
)sljit_get_register_index(SLJIT_S1
);
3785 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3786 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
3787 /* add rd, rn, rm */
3788 inst
= 0xeb000000 | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 8)
3789 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 16)
3790 | (sljit_u32
)sljit_get_register_index(SLJIT_S1
);
3791 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3792 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3793 /* add rd, rn, rm */
3794 inst
= 0x8b000000 | (sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
)
3795 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 5)
3796 | ((sljit_u32
)sljit_get_register_index(SLJIT_S1
) << 16);
3797 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3798 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3799 /* add rD, rA, rB */
3800 inst
= (31 << 26) | (266 << 1) | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 21)
3801 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 16)
3802 | ((sljit_u32
)sljit_get_register_index(SLJIT_S1
) << 11);
3803 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3804 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
3805 /* addu rd, rs, rt */
3806 inst
= 33 | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 11)
3807 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 21)
3808 | ((sljit_u32
)sljit_get_register_index(SLJIT_S1
) << 16);
3809 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3810 #elif (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
3811 /* daddu rd, rs, rt */
3812 inst
= 45 | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 11)
3813 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 21)
3814 | ((sljit_u32
)sljit_get_register_index(SLJIT_S1
) << 16);
3815 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3816 #elif (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV)
3817 /* add rd, rs1, rs2 */
3818 inst
= 0x33 | (0 << 12) | (0 << 25) | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 7)
3819 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 15)
3820 | ((sljit_u32
)sljit_get_register_index(SLJIT_S1
) << 20);
3821 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3822 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3823 /* add rd, rs1, rs2 */
3824 inst
= (0x2u
<< 30) | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 25)
3825 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 14)
3826 | (sljit_u32
)sljit_get_register_index(SLJIT_S1
);
3827 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3828 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
3829 /* agrk rd, rs1, rs2 */
3830 inst
= (0xb9e8u
<< 16)
3831 | ((sljit_u32
)sljit_get_register_index(SLJIT_RETURN_REG
) << 4)
3832 | ((sljit_u32
)sljit_get_register_index(SLJIT_S0
) << 12)
3833 | (sljit_u32
)sljit_get_register_index(SLJIT_S1
);
3834 sljit_emit_op_custom(compiler
, &inst
, sizeof(inst
));
3837 sljit_emit_op_custom(compiler
, &inst
, 0);
3840 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
3842 code
.code
= sljit_generate_code(compiler
);
3844 sljit_free_compiler(compiler
);
3846 FAILED(code
.func2(32, -11) != 21, "test41 case 1 failed\n");
3847 FAILED(code
.func2(1000, 234) != 1234, "test41 case 2 failed\n");
3848 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3849 FAILED(code
.func2(SLJIT_W(0x20f0a04090c06070), SLJIT_W(0x020f0a04090c0607)) != SLJIT_W(0x22ffaa4499cc6677), "test41 case 3 failed\n");
3852 sljit_free_code(code
.code
, NULL
);
3854 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
3859 compiler
= sljit_create_compiler(NULL
, NULL
);
3860 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 0, 1, 2, 0, 0);
3861 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
3862 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
3863 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3868 inst
[3] = (sljit_u8
)(0xc0 | (sljit_get_float_register_index(SLJIT_FR0
) << 3)
3869 | sljit_get_float_register_index(SLJIT_FR1
));
3870 sljit_emit_op_custom(compiler
, inst
, 4);
3871 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3873 if (sljit_get_float_register_index(SLJIT_FR0
) > 7 || sljit_get_float_register_index(SLJIT_FR1
) > 7) {
3875 if (sljit_get_float_register_index(SLJIT_FR0
) > 7)
3876 inst
[0] |= 0x04; /* REX_R */
3877 if (sljit_get_float_register_index(SLJIT_FR1
) > 7)
3878 inst
[0] |= 0x01; /* REX_B */
3882 inst
[4] = (sljit_u8
)(0xc0 | ((sljit_get_float_register_index(SLJIT_FR0
) & 0x7) << 3)
3883 | (sljit_get_float_register_index(SLJIT_FR1
) & 0x7));
3884 sljit_emit_op_custom(compiler
, inst
, 5);
3890 inst
[3] = (sljit_u8
)(0xc0 | (sljit_get_float_register_index(SLJIT_FR0
) << 3)
3891 | sljit_get_float_register_index(SLJIT_FR1
));
3892 sljit_emit_op_custom(compiler
, inst
, 4);
3894 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
3895 /* vadd.f64 dd, dn, dm */
3896 inst
= 0xee300b00 | (((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) >> 1) << 12)
3897 | (((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) >> 1) << 16)
3898 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
) >> 1);
3899 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3900 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3901 /* fadd rd, rn, rm */
3902 inst
= 0x1e602800 | (sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
)
3903 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 5)
3904 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
) << 16);
3905 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3906 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3907 /* fadd frD, frA, frB */
3908 inst
= (63u << 26) | (21u << 1) | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 21)
3909 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 16)
3910 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
) << 11);
3911 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3912 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
3913 /* add.d fd, fs, ft */
3914 inst
= (17u << 26) | (17u << 21) | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 6)
3915 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 11)
3916 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
) << 16);
3917 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3918 #elif (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV)
3919 /* fadd.d rd, rs1, rs2 */
3920 inst
= (0x1u
<< 25) | (0x7u
<< 12) | (0x53u
)
3921 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 7)
3922 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 15)
3923 | (sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
) << 20;
3924 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3925 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3926 /* faddd rd, rs1, rs2 */
3927 inst
= (0x2u
<< 30) | (0x34u
<< 19) | (0x42u
<< 5)
3928 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 25)
3929 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 14)
3930 | (sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
);
3931 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3932 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
3935 | ((sljit_u32
)sljit_get_float_register_index(SLJIT_FR0
) << 4)
3936 | (sljit_u32
)sljit_get_float_register_index(SLJIT_FR1
);
3937 sljit_emit_op_custom(compiler
, &inst
, sizeof(sljit_u32
));
3939 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
3940 sljit_emit_return_void(compiler
);
3942 code
.code
= sljit_generate_code(compiler
);
3944 sljit_free_compiler(compiler
);
3946 code
.func1((sljit_sw
)&buf
);
3947 FAILED(buf
[2] != 11.25, "test41 case 4 failed\n");
3949 sljit_free_code(code
.code
, NULL
);
3955 static void test42(void)
3957 /* Test long multiply and division. */
3958 executable_code code
;
3959 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
3961 sljit_sw buf
[7 + 4 + 8 + 8];
3964 printf("Run test42\n");
3966 FAILED(!compiler
, "cannot create compiler\n");
3967 for (i
= 0; i
< 7 + 4 + 8 + 8; i
++)
3970 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 5, 5, 0, 0, 0);
3972 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -0x1fb308a);
3973 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0xf50c873);
3974 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, 0x8a0475b);
3975 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, 0x9dc849b);
3976 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -0x7c69a35);
3977 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, 0x5a4d0c4);
3978 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S4
, 0, SLJIT_IMM
, 0x9a3b06d);
3980 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3981 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3982 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3983 sljit_emit_op0(compiler
, SLJIT_LMUL_UW
);
3984 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3985 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3987 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3988 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3989 sljit_emit_op0(compiler
, SLJIT_LMUL_SW
);
3990 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3991 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3993 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
3994 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
3995 sljit_emit_op0(compiler
, SLJIT_DIVMOD_UW
);
3996 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
3997 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R1
, 0);
3999 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x5dc4f897b8cd67f5));
4000 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3f8b5c026cb088df));
4001 sljit_emit_op0(compiler
, SLJIT_DIVMOD_SW
);
4002 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4003 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4005 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x5cf783d3cf0a74b0));
4006 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3d5df42d03a28fc7));
4007 sljit_emit_op0(compiler
, SLJIT_DIVMOD_U32
);
4008 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4009 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
4010 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4011 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4013 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x371df5197ba26a28));
4014 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x46c78a5cfd6a420c));
4015 sljit_emit_op0(compiler
, SLJIT_DIVMOD_S32
);
4016 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4017 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
4018 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4019 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4021 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)SLJIT_W(0xc456f048c28a611b));
4022 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x3d4af2c543));
4023 sljit_emit_op0(compiler
, SLJIT_DIV_UW
);
4024 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 19 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4025 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4027 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(-0x720fa4b74c329b14));
4028 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0xa64ae42b7d6));
4029 sljit_emit_op0(compiler
, SLJIT_DIV_SW
);
4030 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 21 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4031 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4033 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x4af51c027b34));
4034 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(0x9ba4ff2906b14));
4035 sljit_emit_op0(compiler
, SLJIT_DIV_U32
);
4036 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4037 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
4038 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 23 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4039 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 24 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4041 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0xc40b58a3f20d));
4042 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_W(-0xa63c923));
4043 sljit_emit_op0(compiler
, SLJIT_DIV_S32
);
4044 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4045 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
4046 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 25 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4047 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 26 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4050 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
4051 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
4052 sljit_emit_op0(compiler
, SLJIT_LMUL_UW
);
4053 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4054 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4056 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
4057 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
4058 sljit_emit_op0(compiler
, SLJIT_LMUL_SW
);
4059 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4060 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4062 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
4063 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
4064 sljit_emit_op0(compiler
, SLJIT_DIVMOD_UW
);
4065 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4066 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4068 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58cd67f5);
4069 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x3cb088df);
4070 sljit_emit_op0(compiler
, SLJIT_DIVMOD_SW
);
4071 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4072 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4074 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0xcf0a74b0);
4075 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0x03a28fc7);
4076 sljit_emit_op0(compiler
, SLJIT_DIVMOD_U32
);
4077 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4078 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4080 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x7ba26a28);
4081 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)0xfd6a420c);
4082 sljit_emit_op0(compiler
, SLJIT_DIVMOD_S32
);
4083 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4084 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4086 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x9d4b7036);
4087 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0xb86d0);
4088 sljit_emit_op0(compiler
, SLJIT_DIV_UW
);
4089 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 19 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4090 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4092 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -0x58b0692c);
4093 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0xd357);
4094 sljit_emit_op0(compiler
, SLJIT_DIV_SW
);
4095 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 21 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4096 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4098 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1c027b34);
4099 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)0xf2906b14);
4100 sljit_emit_op0(compiler
, SLJIT_DIV_U32
);
4101 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4102 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
4103 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 23 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4104 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 24 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4106 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0x58a3f20d);
4107 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -0xa63c923);
4108 sljit_emit_op0(compiler
, SLJIT_DIV_S32
);
4109 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4110 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R1
, 0, SLJIT_R1
, 0);
4111 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 25 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4112 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 26 * sizeof(sljit_sw
), SLJIT_R1
, 0);
4115 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R2
, 0);
4116 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R3
, 0);
4117 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R4
, 0);
4118 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_S1
, 0);
4119 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_S2
, 0);
4120 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_S3
, 0);
4121 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_S4
, 0);
4123 sljit_emit_return_void(compiler
);
4125 code
.code
= sljit_generate_code(compiler
);
4127 sljit_free_compiler(compiler
);
4129 code
.func1((sljit_sw
)&buf
);
4131 FAILED(buf
[0] != -0x1fb308a, "test42 case 1 failed\n");
4132 FAILED(buf
[1] != 0xf50c873, "test42 case 2 failed\n");
4133 FAILED(buf
[2] != 0x8a0475b, "test42 case 3 failed\n");
4134 FAILED(buf
[3] != 0x9dc849b, "test42 case 4 failed\n");
4135 FAILED(buf
[4] != -0x7c69a35, "test42 case 5 failed\n");
4136 FAILED(buf
[5] != 0x5a4d0c4, "test42 case 6 failed\n");
4137 FAILED(buf
[6] != 0x9a3b06d, "test42 case 7 failed\n");
4139 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4140 FAILED(buf
[7] != SLJIT_W(-4388959407985636971), "test42 case 8 failed\n");
4141 FAILED(buf
[8] != SLJIT_W(2901680654366567099), "test42 case 9 failed\n");
4142 FAILED(buf
[9] != SLJIT_W(-4388959407985636971), "test42 case 10 failed\n");
4143 FAILED(buf
[10] != SLJIT_W(-1677173957268872740), "test42 case 11 failed\n");
4144 FAILED(buf
[11] != SLJIT_W(2), "test42 case 12 failed\n");
4145 FAILED(buf
[12] != SLJIT_W(2532236178951865933), "test42 case 13 failed\n");
4146 FAILED(buf
[13] != SLJIT_W(-1), "test42 case 14 failed\n");
4147 FAILED(buf
[14] != SLJIT_W(-2177944059851366166), "test42 case 15 failed\n");
4149 FAILED(buf
[7] != -1587000939, "test42 case 8 failed\n");
4150 FAILED(buf
[8] != 665003983, "test42 case 9 failed\n");
4151 FAILED(buf
[9] != -1587000939, "test42 case 10 failed\n");
4152 FAILED(buf
[10] != -353198352, "test42 case 11 failed\n");
4153 FAILED(buf
[11] != 2, "test42 case 12 failed\n");
4154 FAILED(buf
[12] != 768706125, "test42 case 13 failed\n");
4155 FAILED(buf
[13] != -1, "test42 case 14 failed\n");
4156 FAILED(buf
[14] != -471654166, "test42 case 15 failed\n");
4159 FAILED(buf
[15] != 56, "test42 case 16 failed\n");
4160 FAILED(buf
[16] != 58392872, "test42 case 17 failed\n");
4161 FAILED(buf
[17] != -47, "test42 case 18 failed\n");
4162 FAILED(buf
[18] != 35949148, "test42 case 19 failed\n");
4164 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4165 FAILED(buf
[19] != SLJIT_W(0x3340bfc), "test42 case 20 failed\n");
4166 FAILED(buf
[20] != SLJIT_W(0x3d4af2c543), "test42 case 21 failed\n");
4167 FAILED(buf
[21] != SLJIT_W(-0xaf978), "test42 case 22 failed\n");
4168 FAILED(buf
[22] != SLJIT_W(0xa64ae42b7d6), "test42 case 23 failed\n");
4170 FAILED(buf
[19] != SLJIT_W(0xda5), "test42 case 20 failed\n");
4171 FAILED(buf
[20] != SLJIT_W(0xb86d0), "test42 case 21 failed\n");
4172 FAILED(buf
[21] != SLJIT_W(-0x6b6e), "test42 case 22 failed\n");
4173 FAILED(buf
[22] != SLJIT_W(0xd357), "test42 case 23 failed\n");
4176 FAILED(buf
[23] != 0x0, "test42 case 24 failed\n");
4177 FAILED(buf
[24] != (sljit_sw
)0xf2906b14, "test42 case 25 failed\n");
4178 FAILED(buf
[25] != -0x8, "test42 case 26 failed\n");
4179 FAILED(buf
[26] != -0xa63c923, "test42 case 27 failed\n");
4181 sljit_free_code(code
.code
, NULL
);
4185 static void test43(void)
4187 /* Test floating point compare. */
4188 executable_code code
;
4189 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4190 struct sljit_jump
* jump
;
4201 printf("Run test43\n");
4203 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4205 printf("no fpu available, test43 skipped\n");
4208 sljit_free_compiler(compiler
);
4212 FAILED(!compiler
, "cannot create compiler\n");
4214 dbuf
[0].value
= 12.125;
4216 dbuf
[1].u
.value1
= 0x7fffffff;
4217 dbuf
[1].u
.value2
= 0x7fffffff;
4218 dbuf
[2].value
= -13.5;
4219 dbuf
[3].value
= 12.125;
4221 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 1, 1, 3, 0, 0);
4222 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
4223 /* dbuf[0] < dbuf[2] -> -2 */
4224 jump
= sljit_emit_fcmp(compiler
, SLJIT_F_GREATER_EQUAL
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), SLJIT_F64_SHIFT
);
4225 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, -2);
4227 sljit_set_label(jump
, sljit_emit_label(compiler
));
4228 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4229 /* dbuf[0] and dbuf[1] is not NaN -> 5 */
4230 jump
= sljit_emit_fcmp(compiler
, SLJIT_UNORDERED
, SLJIT_MEM0(), (sljit_sw
)&dbuf
[1], SLJIT_FR1
, 0);
4231 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, 5);
4233 sljit_set_label(jump
, sljit_emit_label(compiler
));
4234 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
));
4235 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, 11);
4236 /* dbuf[0] == dbuf[3] -> 11 */
4237 jump
= sljit_emit_fcmp(compiler
, SLJIT_F_EQUAL
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_FR2
, 0);
4240 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0, SLJIT_IMM
, -17);
4241 sljit_set_label(jump
, sljit_emit_label(compiler
));
4242 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
4244 code
.code
= sljit_generate_code(compiler
);
4246 sljit_free_compiler(compiler
);
4248 FAILED(code
.func1((sljit_sw
)&dbuf
) != 11, "test43 case 1 failed\n");
4250 FAILED(code
.func1((sljit_sw
)&dbuf
) != -17, "test43 case 2 failed\n");
4252 FAILED(code
.func1((sljit_sw
)&dbuf
) != 5, "test43 case 3 failed\n");
4254 FAILED(code
.func1((sljit_sw
)&dbuf
) != -2, "test43 case 4 failed\n");
4256 sljit_free_code(code
.code
, NULL
);
4260 static void test44(void)
4263 executable_code code
;
4264 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4268 printf("Run test44\n");
4270 FAILED(!compiler
, "cannot create compiler\n");
4277 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(P
, P
), 3, 2, 0, 0, 0);
4279 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4280 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_p
), SLJIT_R0
, 0);
4281 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_p
));
4282 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 2);
4283 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R1
), SLJIT_POINTER_SHIFT
, SLJIT_R0
, 0);
4284 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, sizeof(sljit_p
));
4285 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3 << SLJIT_POINTER_SHIFT
);
4286 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_S0
, 0);
4287 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM2(SLJIT_R2
, SLJIT_R1
), 0, SLJIT_R0
, 0);
4288 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 2 * sizeof(sljit_p
));
4289 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 1 << SLJIT_POINTER_SHIFT
);
4290 sljit_emit_op1(compiler
, SLJIT_MOV_P
, SLJIT_MEM2(SLJIT_R2
, SLJIT_R1
), 2, SLJIT_R0
, 0);
4292 sljit_emit_return(compiler
, SLJIT_MOV_P
, SLJIT_R0
, 0);
4294 code
.code
= sljit_generate_code(compiler
);
4296 sljit_free_compiler(compiler
);
4298 FAILED(code
.func1((sljit_sw
)&buf
) != (sljit_sw
)(buf
+ 2), "test44 case 1 failed\n");
4299 FAILED(buf
[1] != buf
+ 2, "test44 case 2 failed\n");
4300 FAILED(buf
[2] != buf
+ 3, "test44 case 3 failed\n");
4301 FAILED(buf
[3] != buf
+ 4, "test44 case 4 failed\n");
4302 FAILED(buf
[4] != buf
+ 2, "test44 case 5 failed\n");
4304 sljit_free_code(code
.code
, NULL
);
4308 static void test45(void)
4310 /* Test single precision floating point. */
4312 executable_code code
;
4313 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4316 struct sljit_jump
* jump
;
4319 printf("Run test45\n");
4321 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4323 printf("no fpu available, test45 skipped\n");
4326 sljit_free_compiler(compiler
);
4330 FAILED(!compiler
, "cannot create compiler\n");
4352 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 3, 2, 6, 0, 0);
4354 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4355 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4356 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
4357 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_FR1
, 0, SLJIT_FR5
, 0);
4358 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f32
), SLJIT_FR1
, 0);
4359 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f32
), SLJIT_FR5
, 0);
4360 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_FR4
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4361 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f32
), SLJIT_FR4
, 0);
4363 sljit_emit_fop2(compiler
, SLJIT_ADD_F32
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4364 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
4365 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);
4366 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4367 sljit_emit_fop2(compiler
, SLJIT_MUL_F32
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_f32
), SLJIT_FR0
, 0, SLJIT_FR0
, 0);
4368 sljit_emit_fop2(compiler
, SLJIT_DIV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
4369 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f32
), SLJIT_FR2
, 0);
4370 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x3d0ac);
4371 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_R0
), 0x3d0ac);
4372 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 0x3d0ac + sizeof(sljit_f32
));
4373 sljit_emit_fop1(compiler
, SLJIT_ABS_F32
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_R0
), -0x3d0ac);
4375 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4376 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4377 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_F_EQUAL
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4378 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_F_EQUAL
);
4379 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_F_LESS
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4380 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_sw
), SLJIT_F_LESS
);
4381 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_F_EQUAL
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
4382 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_sw
), SLJIT_F_EQUAL
);
4383 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_F_GREATER_EQUAL
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
4384 cond_set(compiler
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
), SLJIT_F_GREATER_EQUAL
);
4386 jump
= sljit_emit_fcmp(compiler
, SLJIT_F_LESS_EQUAL
| SLJIT_32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4387 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_IMM
, 7);
4388 sljit_set_label(jump
, sljit_emit_label(compiler
));
4390 jump
= sljit_emit_fcmp(compiler
, SLJIT_F_GREATER
| SLJIT_32
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_FR2
, 0);
4391 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_IMM
, 6);
4392 sljit_set_label(jump
, sljit_emit_label(compiler
));
4394 sljit_emit_return_void(compiler
);
4396 code
.code
= sljit_generate_code(compiler
);
4398 sljit_free_compiler(compiler
);
4400 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&buf2
);
4401 FAILED(buf
[2] != -5.5, "test45 case 1 failed\n");
4402 FAILED(buf
[3] != 7.25, "test45 case 2 failed\n");
4403 FAILED(buf
[4] != 7.25, "test45 case 3 failed\n");
4404 FAILED(buf
[5] != -5.5, "test45 case 4 failed\n");
4405 FAILED(buf
[6] != -1.75, "test45 case 5 failed\n");
4406 FAILED(buf
[7] != 16.0, "test45 case 6 failed\n");
4407 FAILED(buf
[8] != 30.25, "test45 case 7 failed\n");
4408 FAILED(buf
[9] != 3, "test45 case 8 failed\n");
4409 FAILED(buf
[10] != -5.5, "test45 case 9 failed\n");
4410 FAILED(buf
[11] != 7.25, "test45 case 10 failed\n");
4411 FAILED(buf2
[0] != 1, "test45 case 11 failed\n");
4412 FAILED(buf2
[1] != 2, "test45 case 12 failed\n");
4413 FAILED(buf2
[2] != 2, "test45 case 13 failed\n");
4414 FAILED(buf2
[3] != 1, "test45 case 14 failed\n");
4415 FAILED(buf2
[4] != 7, "test45 case 15 failed\n");
4416 FAILED(buf2
[5] != -1, "test45 case 16 failed\n");
4418 sljit_free_code(code
.code
, NULL
);
4422 static void test46(void)
4424 /* Test sljit_emit_op_flags with 32 bit operations. */
4426 executable_code code
;
4427 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4433 printf("Run test46\n");
4435 for (i
= 0; i
< 24; ++i
)
4438 for (i
= 0; i
< 6; ++i
)
4442 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 3, 3, 0, 0, 0);
4444 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4445 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_R2
, 0, SLJIT_IMM
, 13);
4446 sljit_emit_op_flags(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&buf
, SLJIT_LESS
);
4447 sljit_emit_op_flags(compiler
, SLJIT_AND32
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_s32
), SLJIT_NOT_ZERO
);
4449 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4450 sljit_emit_op_flags(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_s32
), SLJIT_EQUAL
);
4451 sljit_emit_op_flags(compiler
, SLJIT_AND32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_s32
), SLJIT_NOT_EQUAL
);
4452 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1235);
4453 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 0x1235);
4454 sljit_emit_op_flags(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_ZERO
);
4455 sljit_emit_op_flags(compiler
, SLJIT_AND32
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_s32
), SLJIT_ZERO
);
4456 sljit_emit_op1(compiler
, SLJIT_MOV_U32
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4458 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4459 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 12);
4460 sljit_emit_op_flags(compiler
, SLJIT_MOV32
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 2, SLJIT_EQUAL
);
4461 sljit_emit_op_flags(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_EQUAL
);
4462 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4463 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
4464 sljit_emit_op_flags(compiler
, SLJIT_AND32
| SLJIT_SET_Z
, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), 2, SLJIT_EQUAL
);
4465 sljit_emit_op_flags(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_s32
), SLJIT_NOT_EQUAL
);
4467 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4468 sljit_emit_op_flags(compiler
, SLJIT_XOR32
| SLJIT_SET_Z
, SLJIT_MEM1(SLJIT_S0
), 20 * sizeof(sljit_s32
), SLJIT_ZERO
);
4469 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 39);
4470 sljit_emit_op_flags(compiler
, SLJIT_XOR32
, SLJIT_R0
, 0, SLJIT_NOT_ZERO
);
4471 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 22 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4473 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R2
, 0, SLJIT_IMM
, -7);
4474 sljit_emit_op_flags(compiler
, SLJIT_AND
, SLJIT_MEM0(), (sljit_sw
)&buf2
, SLJIT_GREATER
);
4475 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R2
, 0, SLJIT_IMM
, 5);
4476 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
4477 sljit_emit_op_flags(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_SIG_LESS
);
4478 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
4479 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_R2
, 0, SLJIT_IMM
, 5);
4480 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_LESS
);
4481 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_NOT_EQUAL
);
4482 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R2
, 0, SLJIT_IMM
, 5);
4483 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_sw
), SLJIT_S2
, 0);
4484 sljit_emit_op_flags(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_WORD_SHIFT
, SLJIT_SIG_LESS
);
4485 sljit_emit_op_flags(compiler
, SLJIT_OR
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_sw
), SLJIT_ZERO
);
4486 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R2
, 0, SLJIT_IMM
, 0);
4487 sljit_emit_op_flags(compiler
, SLJIT_XOR
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_sw
), SLJIT_GREATER
);
4489 sljit_emit_return_void(compiler
);
4491 code
.code
= sljit_generate_code(compiler
);
4493 sljit_free_compiler(compiler
);
4495 code
.func2((sljit_sw
)&buf
, (sljit_sw
)&buf2
);
4496 FAILED(buf
[0] != 0, "test46 case 1 failed\n");
4497 FAILED(buf
[1] != -17, "test46 case 2 failed\n");
4498 FAILED(buf
[2] != 1, "test46 case 3 failed\n");
4499 FAILED(buf
[3] != -17, "test46 case 4 failed\n");
4500 FAILED(buf
[4] != 1, "test46 case 5 failed\n");
4501 FAILED(buf
[5] != -17, "test46 case 6 failed\n");
4502 FAILED(buf
[6] != 1, "test46 case 7 failed\n");
4503 FAILED(buf
[7] != -17, "test46 case 8 failed\n");
4504 FAILED(buf
[8] != 0, "test46 case 9 failed\n");
4505 FAILED(buf
[9] != -17, "test46 case 10 failed\n");
4506 FAILED(buf
[10] != 1, "test46 case 11 failed\n");
4507 FAILED(buf
[11] != -17, "test46 case 12 failed\n");
4508 FAILED(buf
[12] != 1, "test46 case 13 failed\n");
4509 FAILED(buf
[13] != -17, "test46 case 14 failed\n");
4510 FAILED(buf
[14] != 1, "test46 case 15 failed\n");
4511 FAILED(buf
[15] != -17, "test46 case 16 failed\n");
4512 FAILED(buf
[16] != 0, "test46 case 17 failed\n");
4513 FAILED(buf
[17] != -17, "test46 case 18 failed\n");
4514 FAILED(buf
[18] != 0, "test46 case 19 failed\n");
4515 FAILED(buf
[19] != -17, "test46 case 20 failed\n");
4516 FAILED(buf
[20] != -18, "test46 case 21 failed\n");
4517 FAILED(buf
[21] != -17, "test46 case 22 failed\n");
4518 FAILED(buf
[22] != 38, "test46 case 23 failed\n");
4519 FAILED(buf
[23] != -17, "test46 case 24 failed\n");
4521 FAILED(buf2
[0] != 0, "test46 case 25 failed\n");
4522 FAILED(buf2
[1] != 1, "test46 case 26 failed\n");
4523 FAILED(buf2
[2] != 0, "test46 case 27 failed\n");
4524 FAILED(buf2
[3] != 1, "test46 case 28 failed\n");
4525 FAILED(buf2
[4] != -123, "test46 case 29 failed\n");
4526 FAILED(buf2
[5] != -14, "test46 case 30 failed\n");
4528 sljit_free_code(code
.code
, NULL
);
4532 static void test47(void)
4534 /* Test jump optimizations. */
4535 executable_code code
;
4536 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4540 printf("Run test47\n");
4542 FAILED(!compiler
, "cannot create compiler\n");
4547 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 0);
4548 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x3a5c6f);
4549 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
4550 sljit_set_target(sljit_emit_jump(compiler
, SLJIT_LESS
), 0x11223344);
4551 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
4552 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0xd37c10);
4553 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4554 sljit_set_target(sljit_emit_jump(compiler
, SLJIT_LESS
), SLJIT_W(0x112233445566));
4556 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
4557 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x59b48e);
4558 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4559 sljit_set_target(sljit_emit_jump(compiler
, SLJIT_LESS
), SLJIT_W(0x1122334455667788));
4561 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4562 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
4564 code
.code
= sljit_generate_code(compiler
);
4566 sljit_free_compiler(compiler
);
4568 FAILED(code
.func1((sljit_sw
)&buf
) != 0x59b48e, "test47 case 1 failed\n");
4569 FAILED(buf
[0] != 0x3a5c6f, "test47 case 2 failed\n");
4570 FAILED(buf
[1] != 0xd37c10, "test47 case 3 failed\n");
4571 FAILED(buf
[2] != 0x59b48e, "test47 case 4 failed\n");
4573 sljit_free_code(code
.code
, NULL
);
4577 static void test48(void)
4579 /* Test floating point conversions. */
4580 executable_code code
;
4581 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4589 printf("Run test48\n");
4591 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4593 printf("no fpu available, test48 skipped\n");
4596 sljit_free_compiler(compiler
);
4600 FAILED(!compiler
, "cannot create compiler\n");
4601 for (i
= 0; i
< 10; i
++) {
4620 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 3, 3, 6, 0, 0);
4621 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
4622 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, (sljit_sw
)&sbuf
);
4623 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
4624 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
4627 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_F64
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S0
), 0);
4628 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
4629 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 3);
4631 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_F64
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_F32_SHIFT
, SLJIT_FR5
, 0);
4632 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_F32
, SLJIT_FR4
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
4634 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
), SLJIT_FR4
, 0);
4635 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
4636 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_F32
, SLJIT_FR2
, 0, SLJIT_FR3
, 0);
4638 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
4640 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_f32
), SLJIT_FR3
, 0);
4643 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
4644 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
4645 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_R0
, 0, SLJIT_MEM2(SLJIT_S0
, SLJIT_R0
), SLJIT_F64_SHIFT
);
4647 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4648 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR5
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
4650 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F32
, SLJIT_MEM1(SLJIT_S2
), 3 * sizeof(sljit_sw
), SLJIT_FR5
, 0);
4651 sljit_emit_fop1(compiler
, SLJIT_NEG_F32
, SLJIT_FR0
, 0, SLJIT_FR5
, 0);
4652 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 4);
4654 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F32
, SLJIT_MEM2(SLJIT_S2
, SLJIT_R1
), SLJIT_WORD_SHIFT
, SLJIT_FR0
, 0);
4655 sljit_emit_fop1(compiler
, SLJIT_NEG_F64
, SLJIT_FR4
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
));
4657 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F64
, SLJIT_MEM1(SLJIT_R2
), 2 * sizeof(sljit_s32
), SLJIT_FR4
, 0);
4658 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
4659 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F32
, SLJIT_R0
, 0, SLJIT_FR1
, 0);
4661 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_MEM1(SLJIT_R2
), 3 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4664 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S2
), 0);
4665 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_FR2
, 0, SLJIT_IMM
, -6213);
4667 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
4669 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_f64
), SLJIT_MEM0(), (sljit_sw
)&ibuf
[0]);
4670 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R2
), sizeof(sljit_s32
));
4671 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_FR1
, 0, SLJIT_R0
, 0);
4673 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_f64
), SLJIT_FR1
, 0);
4675 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM0(), (sljit_sw
)(dbuf
+ 9), SLJIT_IMM
, -77);
4677 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_MEM1(SLJIT_S1
), 5 * sizeof(sljit_f32
), SLJIT_IMM
, -123);
4678 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 7190);
4679 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_FR3
, 0, SLJIT_R0
, 0);
4681 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 6 * sizeof(sljit_f32
), SLJIT_FR3
, 0);
4682 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 123);
4683 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_R2
, 0, SLJIT_IMM
, 123 * sizeof(sljit_s32
));
4684 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_S32
, SLJIT_FR1
, 0, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 2);
4686 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 7 * sizeof(sljit_f32
), SLJIT_FR1
, 0);
4687 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
4688 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 3812);
4690 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_S32
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), SLJIT_F32_SHIFT
, SLJIT_R1
, 0);
4692 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_MEM0(), (sljit_sw
)(sbuf
+ 9), SLJIT_IMM
, -79);
4694 sljit_emit_return_void(compiler
);
4696 code
.code
= sljit_generate_code(compiler
);
4698 sljit_free_compiler(compiler
);
4701 FAILED(dbuf
[3] != 476.25, "test48 case 1 failed\n");
4702 FAILED(dbuf
[4] != 476.25, "test48 case 2 failed\n");
4703 FAILED(dbuf
[5] != 2345.0, "test48 case 3 failed\n");
4704 FAILED(dbuf
[6] != -6213.0, "test48 case 4 failed\n");
4705 FAILED(dbuf
[7] != 312.0, "test48 case 5 failed\n");
4706 FAILED(dbuf
[8] != -9324.0, "test48 case 6 failed\n");
4707 FAILED(dbuf
[9] != -77.0, "test48 case 7 failed\n");
4709 FAILED(sbuf
[2] != 123.5, "test48 case 8 failed\n");
4710 FAILED(sbuf
[3] != 123.5, "test48 case 9 failed\n");
4711 FAILED(sbuf
[4] != 476.25, "test48 case 10 failed\n");
4712 FAILED(sbuf
[5] != -123, "test48 case 11 failed\n");
4713 FAILED(sbuf
[6] != 7190, "test48 case 12 failed\n");
4714 FAILED(sbuf
[7] != 312, "test48 case 13 failed\n");
4715 FAILED(sbuf
[8] != 3812, "test48 case 14 failed\n");
4716 FAILED(sbuf
[9] != -79.0, "test48 case 15 failed\n");
4718 FAILED(wbuf
[1] != -367, "test48 case 16 failed\n");
4719 FAILED(wbuf
[2] != 917, "test48 case 17 failed\n");
4720 FAILED(wbuf
[3] != 476, "test48 case 18 failed\n");
4721 FAILED(wbuf
[4] != -476, "test48 case 19 failed\n");
4723 FAILED(ibuf
[2] != -917, "test48 case 20 failed\n");
4724 FAILED(ibuf
[3] != -1689, "test48 case 21 failed\n");
4726 sljit_free_code(code
.code
, NULL
);
4730 static void test49(void)
4732 /* Test floating point conversions. */
4733 executable_code code
;
4734 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4740 sljit_s32
* dbuf_ptr
= (sljit_s32
*)dbuf
;
4741 sljit_s32
* sbuf_ptr
= (sljit_s32
*)sbuf
;
4744 printf("Run test49\n");
4746 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4748 printf("no fpu available, test49 skipped\n");
4751 sljit_free_compiler(compiler
);
4755 FAILED(!compiler
, "cannot create compiler\n");
4757 for (i
= 0; i
< 9; i
++) {
4758 dbuf_ptr
[i
<< 1] = -1;
4759 dbuf_ptr
[(i
<< 1) + 1] = -1;
4765 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4766 dbuf
[9] = (sljit_f64
)SLJIT_W(0x1122334455);
4773 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 3, 3, 3, 0, 0);
4774 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
4775 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, (sljit_sw
)&sbuf
);
4776 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
4777 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
4780 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_F32
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S1
), 0);
4782 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_F64
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S0
), 0);
4784 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S0
), 0);
4786 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F32
, SLJIT_MEM1(SLJIT_S2
), 4 * sizeof(sljit_sw
), SLJIT_MEM1(SLJIT_S1
), 0);
4788 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F64
, SLJIT_MEM1(SLJIT_R2
), 2 * sizeof(sljit_s32
), SLJIT_MEM1(SLJIT_S0
), 0);
4790 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F32
, SLJIT_MEM1(SLJIT_R2
), 4 * sizeof(sljit_s32
), SLJIT_MEM1(SLJIT_S1
), 0);
4792 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_S2
), 0);
4794 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_SW
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S2
), 0);
4796 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
), SLJIT_MEM1(SLJIT_R2
), 0);
4798 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_S32
, SLJIT_MEM1(SLJIT_S1
), 6 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_R2
), 0);
4800 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4801 sljit_emit_fop1(compiler
, SLJIT_CONV_SW_FROM_F64
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f64
));
4803 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), 8 * sizeof(sljit_sw
), SLJIT_R0
, 0);
4804 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f64
));
4805 sljit_emit_fop1(compiler
, SLJIT_CONV_S32_FROM_F64
, SLJIT_R0
, 0, SLJIT_FR2
, 0);
4806 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
4807 sljit_emit_op2(compiler
, SLJIT_AND32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0xffff);
4809 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R2
), 8 * sizeof(sljit_s32
), SLJIT_R0
, 0);
4810 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_W(0x4455667788));
4812 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_SW
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_f64
), SLJIT_R0
, 0);
4814 sljit_emit_fop1(compiler
, SLJIT_CONV_F64_FROM_S32
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_f64
), SLJIT_IMM
, SLJIT_W(0x7766554433));
4817 sljit_emit_return_void(compiler
);
4819 code
.code
= sljit_generate_code(compiler
);
4821 sljit_free_compiler(compiler
);
4825 FAILED(dbuf_ptr
[(1 * 2) + 0] != -1, "test49 case 1 failed\n");
4826 FAILED(dbuf_ptr
[(1 * 2) + 1] != -1, "test49 case 2 failed\n");
4827 FAILED(dbuf
[2] != -879.75, "test49 case 3 failed\n");
4828 FAILED(dbuf_ptr
[(3 * 2) + 0] != -1, "test49 case 4 failed\n");
4829 FAILED(dbuf_ptr
[(3 * 2) + 1] != -1, "test49 case 5 failed\n");
4830 FAILED(dbuf
[4] != 345, "test49 case 6 failed\n");
4831 FAILED(dbuf_ptr
[(5 * 2) + 0] != -1, "test49 case 7 failed\n");
4832 FAILED(dbuf_ptr
[(5 * 2) + 1] != -1, "test49 case 8 failed\n");
4833 FAILED(dbuf
[6] != -249, "test49 case 9 failed\n");
4834 FAILED(dbuf_ptr
[(7 * 2) + 0] != -1, "test49 case 10 failed\n");
4835 FAILED(dbuf_ptr
[(7 * 2) + 1] != -1, "test49 case 11 failed\n");
4837 FAILED(sbuf_ptr
[1] != -1, "test49 case 12 failed\n");
4838 FAILED(sbuf
[2] != 673.75, "test49 case 13 failed\n");
4839 FAILED(sbuf_ptr
[3] != -1, "test49 case 14 failed\n");
4840 FAILED(sbuf
[4] != 345, "test49 case 15 failed\n");
4841 FAILED(sbuf_ptr
[5] != -1, "test49 case 16 failed\n");
4842 FAILED(sbuf
[6] != -249, "test49 case 17 failed\n");
4843 FAILED(sbuf_ptr
[7] != -1, "test49 case 18 failed\n");
4845 FAILED(wbuf
[1] != -1, "test49 case 19 failed\n");
4846 FAILED(wbuf
[2] != 673, "test49 case 20 failed\n");
4847 FAILED(wbuf
[3] != -1, "test49 case 21 failed\n");
4848 FAILED(wbuf
[4] != -879, "test49 case 22 failed\n");
4849 FAILED(wbuf
[5] != -1, "test49 case 23 failed\n");
4851 FAILED(ibuf
[1] != -1, "test49 case 24 failed\n");
4852 FAILED(ibuf
[2] != 673, "test49 case 25 failed\n");
4853 FAILED(ibuf
[3] != -1, "test49 case 26 failed\n");
4854 FAILED(ibuf
[4] != -879, "test49 case 27 failed\n");
4855 FAILED(ibuf
[5] != -1, "test49 case 28 failed\n");
4857 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4858 FAILED(dbuf
[8] != (sljit_f64
)SLJIT_W(0x4455667788), "test49 case 29 failed\n");
4859 FAILED(dbuf
[9] != (sljit_f64
)SLJIT_W(0x66554433), "test49 case 30 failed\n");
4860 FAILED(wbuf
[8] != SLJIT_W(0x1122334455), "test48 case 31 failed\n");
4861 FAILED(ibuf
[8] == 0x4455, "test48 case 32 failed\n");
4864 sljit_free_code(code
.code
, NULL
);
4868 static void test50(void)
4870 /* Test stack and floating point operations. */
4871 executable_code code
;
4872 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4873 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4874 sljit_uw size1
, size2
, size3
;
4880 printf("Run test50\n");
4882 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
4884 printf("no fpu available, test50 skipped\n");
4887 sljit_free_compiler(compiler
);
4891 FAILED(!compiler
, "cannot create compiler\n");
4897 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 3, 6, 0, 8 * sizeof(sljit_f32
));
4899 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
4900 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), 0);
4902 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_f32
));
4903 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f32
));
4904 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
));
4906 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), 2 * sizeof(sljit_f32
));
4907 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_SP
), 2 * sizeof(sljit_f32
), SLJIT_IMM
, 5934);
4908 sljit_emit_fop1(compiler
, SLJIT_CONV_F32_FROM_S32
, SLJIT_MEM1(SLJIT_SP
), 3 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), 2 * sizeof(sljit_f32
));
4910 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f32
), SLJIT_MEM1(SLJIT_SP
), 3 * sizeof(sljit_f32
));
4912 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4913 size1
= compiler
->size
;
4915 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f32
));
4916 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4917 size2
= compiler
->size
;
4919 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR5
, 0, SLJIT_FR2
, 0);
4920 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4921 size3
= compiler
->size
;
4924 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f32
), SLJIT_FR5
, 0);
4925 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4926 result
= (compiler
->size
- size3
) == (size3
- size2
) && (size3
- size2
) == (size2
- size1
);
4929 sljit_emit_return_void(compiler
);
4931 code
.code
= sljit_generate_code(compiler
);
4933 sljit_free_compiler(compiler
);
4935 code
.func1((sljit_sw
)&sbuf
);
4937 FAILED(sbuf
[3] != 245.5, "test50 case 1 failed\n");
4938 FAILED(sbuf
[4] != 145.25, "test50 case 2 failed\n");
4939 FAILED(sbuf
[5] != 5934, "test50 case 3 failed\n");
4940 FAILED(sbuf
[6] != 713.75, "test50 case 4 failed\n");
4941 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4942 FAILED(!result
, "test50 case 5 failed\n");
4945 sljit_free_code(code
.code
, NULL
);
4949 static void test51(void)
4951 /* Test all registers provided by the CPU. */
4952 executable_code code
;
4953 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
4954 struct sljit_jump
* jump
;
4959 printf("Run test51\n");
4961 FAILED(!compiler
, "cannot create compiler\n");
4965 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), SLJIT_NUMBER_OF_REGISTERS
, 0, 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
, 32);
4970 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)buf
);
4971 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
4973 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
4974 if (sljit_get_register_index(SLJIT_R(i
)) >= 0) {
4975 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_R0
, 0);
4976 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_R(i
)), 0);
4978 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, buf
[0]);
4981 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 32);
4982 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
4983 if (sljit_get_register_index(SLJIT_R(i
)) >= 0) {
4984 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_R0
, 0);
4985 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM1(SLJIT_R(i
)), 32);
4987 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, buf
[0]);
4990 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
4991 if (sljit_get_register_index(SLJIT_R(i
)) >= 0) {
4992 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 32);
4993 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM2(SLJIT_R(i
), SLJIT_R0
), 0);
4994 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_R(i
)), 0);
4995 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 8);
4996 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_MEM2(SLJIT_R0
, SLJIT_R(i
)), 2);
4998 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_IMM
, 3 * buf
[0]);
5001 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 32 + sizeof(sljit_sw
), SLJIT_R1
, 0);
5003 sljit_emit_return_void(compiler
);
5005 code
.code
= sljit_generate_code(compiler
);
5007 sljit_free_compiler(compiler
);
5011 FAILED(buf
[1] != (39 * 5 * (SLJIT_NUMBER_OF_REGISTERS
- 2)), "test51 case 1 failed\n");
5013 sljit_free_code(code
.code
, NULL
);
5017 compiler
= sljit_create_compiler(NULL
, NULL
);
5019 FAILED(!compiler
, "cannot create compiler\n");
5021 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), SLJIT_NUMBER_OF_SCRATCH_REGISTERS
, SLJIT_NUMBER_OF_SAVED_REGISTERS
, 0, 0, 0);
5023 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5024 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 17);
5026 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS0(W
));
5027 /* SLJIT_R0 contains the first value. */
5028 for (i
= 1; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5029 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
5031 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
5033 sljit_set_label(jump
, sljit_emit_label(compiler
));
5034 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0, 0);
5035 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5036 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 35);
5037 sljit_emit_return_void(compiler
);
5039 code
.code
= sljit_generate_code(compiler
);
5041 sljit_free_compiler(compiler
);
5043 FAILED(code
.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS
* 35 + SLJIT_NUMBER_OF_SAVED_REGISTERS
* 17), "test51 case 2 failed\n");
5045 sljit_free_code(code
.code
, NULL
);
5049 compiler
= sljit_create_compiler(NULL
, NULL
);
5051 FAILED(!compiler
, "cannot create compiler\n");
5053 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), SLJIT_NUMBER_OF_SCRATCH_REGISTERS
, SLJIT_NUMBER_OF_SAVED_REGISTERS
, 0, 0, 0);
5055 for (i
= 0; i
< SLJIT_NUMBER_OF_SCRATCH_REGISTERS
; i
++)
5056 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 68);
5057 for (i
= 0; i
< SLJIT_NUMBER_OF_SAVED_REGISTERS
; i
++)
5058 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S(i
), 0, SLJIT_IMM
, 68);
5060 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS0(W
));
5061 /* SLJIT_R0 contains the first value. */
5062 for (i
= 1; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5063 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
5065 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
5067 sljit_set_label(jump
, sljit_emit_label(compiler
));
5068 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0, 0);
5069 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5070 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 43);
5071 sljit_emit_return_void(compiler
);
5073 code
.code
= sljit_generate_code(compiler
);
5075 sljit_free_compiler(compiler
);
5077 FAILED(code
.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS
* 43 + SLJIT_NUMBER_OF_SAVED_REGISTERS
* 68), "test51 case 3 failed\n");
5079 sljit_free_code(code
.code
, NULL
);
5083 static void test52(void)
5085 /* Test all registers provided by the CPU. */
5086 executable_code code
;
5087 struct sljit_compiler
* compiler
;
5088 struct sljit_jump
* jump
;
5093 printf("Run test52\n");
5095 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5097 printf("no fpu available, test52 skipped\n");
5104 compiler
= sljit_create_compiler(NULL
, NULL
);
5105 FAILED(!compiler
, "cannot create compiler\n");
5109 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
, 0);
5111 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5112 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
5114 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS0(VOID
));
5115 /* SLJIT_FR0 contains the first value. */
5116 for (i
= 1; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5117 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_FR(i
), 0);
5118 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5120 sljit_emit_return_void(compiler
);
5122 sljit_set_label(jump
, sljit_emit_label(compiler
));
5123 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 1, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0, 0);
5124 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[1]);
5125 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5126 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_MEM1(SLJIT_R0
), 0);
5127 sljit_emit_return_void(compiler
);
5129 code
.code
= sljit_generate_code(compiler
);
5131 sljit_free_compiler(compiler
);
5133 code
.func1((sljit_sw
)&buf
);
5134 FAILED(buf
[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
* 17.75 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
* 6.25), "test52 case 1 failed\n");
5136 sljit_free_code(code
.code
, NULL
);
5140 compiler
= sljit_create_compiler(NULL
, NULL
);
5141 FAILED(!compiler
, "cannot create compiler\n");
5145 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
, 0);
5147 for (i
= 0; i
< SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
; i
++)
5148 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
5149 for (i
= 0; i
< SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
; i
++)
5150 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FS(i
), 0, SLJIT_MEM1(SLJIT_S0
), 0);
5152 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS0(VOID
));
5153 /* SLJIT_FR0 contains the first value. */
5154 for (i
= 1; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5155 sljit_emit_fop2(compiler
, SLJIT_ADD_F64
, SLJIT_FR0
, 0, SLJIT_FR0
, 0, SLJIT_FR(i
), 0);
5156 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5158 sljit_emit_return_void(compiler
);
5160 sljit_set_label(jump
, sljit_emit_label(compiler
));
5161 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 1, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0, 0);
5162 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
[1]);
5163 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
5164 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_MEM1(SLJIT_R0
), 0);
5165 sljit_emit_return_void(compiler
);
5167 code
.code
= sljit_generate_code(compiler
);
5169 sljit_free_compiler(compiler
);
5171 code
.func1((sljit_sw
)&buf
);
5172 FAILED(buf
[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
* -11.25 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
* -32.5), "test52 case 2 failed\n");
5174 sljit_free_code(code
.code
, NULL
);
5178 static void test53(void)
5180 /* Check cdecl calls. */
5181 executable_code code
;
5182 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5186 printf("Run test53\n");
5188 FAILED(!compiler
, "cannot create compiler\n");
5191 sljit_emit_enter(compiler
, SLJIT_ENTER_CDECL
, SLJIT_ARGS3(VOID
, W
, W
, W
), 1, 3, 0, 0, 2 * sizeof(sljit_sw
));
5193 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)buf
);
5194 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
5195 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_S1
, 0);
5196 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_sw
), SLJIT_S2
, 0);
5198 sljit_emit_return_void(compiler
);
5200 code
.code
= sljit_generate_code(compiler
);
5202 sljit_free_compiler(compiler
);
5204 code
.test53_f1(7895, -3812, 4087);
5206 FAILED(buf
[0] != 7895, "test53 case 1 failed\n");
5207 FAILED(buf
[1] != -3812, "test53 case 2 failed\n");
5208 FAILED(buf
[2] != 4087, "test53 case 3 failed\n");
5210 sljit_free_code(code
.code
, NULL
);
5215 static void test54(void)
5218 executable_code code
;
5219 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5220 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
5221 sljit_sw large_num
= SLJIT_W(0x1234567812345678);
5223 sljit_sw large_num
= SLJIT_W(0x12345678);
5231 sljit_s32 s32_value
;
5234 sbuf
[0].s32_value
= 0x7fffffff;
5235 sbuf
[1].value
= 7.5;
5236 sbuf
[2].value
= -14.75;
5239 printf("Run test54\n");
5241 FAILED(!compiler
, "cannot create compiler\n");
5243 for (i
= 0; i
< 19; i
++)
5245 for (i
= 0; i
< 4; i
++)
5248 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 5, 3, 3, 0, 0);
5250 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 17);
5251 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 34);
5252 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, -10);
5253 sljit_emit_cmov(compiler
, SLJIT_SIG_LESS
, SLJIT_R0
, SLJIT_R1
, 0);
5254 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
5255 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_IMM
, -10);
5256 sljit_emit_cmov(compiler
, SLJIT_SIG_GREATER
, SLJIT_R0
, SLJIT_R1
, 0);
5257 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
5259 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 24);
5260 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 24);
5261 sljit_emit_cmov(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, SLJIT_IMM
, 66);
5262 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5263 sljit_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R0
, SLJIT_IMM
, 78);
5264 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5265 sljit_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R0
, SLJIT_IMM
, large_num
);
5266 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5268 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
5269 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R3
) == -1 && sljit_get_register_index(SLJIT_R4
) == -1);
5271 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 7);
5272 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -45);
5273 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5274 sljit_emit_cmov(compiler
, SLJIT_OVERFLOW
, SLJIT_R3
, SLJIT_IMM
, 35);
5275 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5276 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, large_num
);
5277 sljit_emit_op2u(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_IMM
, large_num
);
5278 sljit_emit_cmov(compiler
, SLJIT_OVERFLOW
, SLJIT_R3
, SLJIT_IMM
, 35);
5279 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5281 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 71);
5282 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 13);
5283 sljit_emit_op2(compiler
, SLJIT_LSHR
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5284 sljit_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R3
, SLJIT_R0
, 0);
5285 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5287 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 12);
5288 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -29);
5289 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5290 sljit_emit_cmov(compiler
, SLJIT_NOT_OVERFLOW
, SLJIT_R0
, SLJIT_R3
, 0);
5291 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5293 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
5294 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -12);
5295 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R4
, 0, SLJIT_IMM
, 21);
5296 sljit_emit_op2u(compiler
, SLJIT_AND
| SLJIT_SET_Z
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5297 sljit_emit_cmov(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R3
, SLJIT_R4
, 0);
5298 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5299 sljit_emit_cmov(compiler
, SLJIT_EQUAL
, SLJIT_R3
, SLJIT_R4
, 0);
5300 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R3
, 0);
5302 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5303 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S2
), 0);
5304 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
5305 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_f32
));
5307 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
5308 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_F_EQUAL
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5309 sljit_emit_cmov(compiler
, SLJIT_F_EQUAL
, SLJIT_R0
, SLJIT_IMM
, -45);
5310 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5311 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_F_GREATER
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5312 sljit_emit_cmov(compiler
, SLJIT_F_GREATER
, SLJIT_R0
, SLJIT_IMM
, -45);
5313 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5314 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_F_GREATER_EQUAL
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5315 sljit_emit_cmov(compiler
, SLJIT_F_GREATER_EQUAL
, SLJIT_R0
, SLJIT_IMM
, 33);
5316 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5318 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5319 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_F_LESS
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5320 sljit_emit_cmov(compiler
, SLJIT_F_LESS
, SLJIT_R0
, SLJIT_IMM
, -70);
5321 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5322 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_F_LESS_EQUAL
, SLJIT_FR2
, 0, SLJIT_FR1
, 0);
5323 sljit_emit_cmov(compiler
, SLJIT_F_LESS_EQUAL
, SLJIT_R0
, SLJIT_IMM
, -60);
5324 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5325 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_F_NOT_EQUAL
, SLJIT_FR1
, 0, SLJIT_FR2
, 0);
5326 sljit_emit_cmov(compiler
, SLJIT_F_NOT_EQUAL
, SLJIT_R0
, SLJIT_IMM
, 31);
5327 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5329 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 53);
5330 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_ORDERED
, SLJIT_FR1
, 0, SLJIT_FR0
, 0);
5331 sljit_emit_cmov(compiler
, SLJIT_ORDERED
, SLJIT_R0
, SLJIT_IMM
, 17);
5332 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5333 sljit_emit_fop1(compiler
, SLJIT_CMP_F32
| SLJIT_SET_UNORDERED
, SLJIT_FR1
, 0, SLJIT_FR0
, 0);
5334 sljit_emit_cmov(compiler
, SLJIT_UNORDERED
, SLJIT_R0
, SLJIT_IMM
, 59);
5335 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 18 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5338 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 177);
5339 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS
, SLJIT_R0
, 0, SLJIT_IMM
, 178);
5340 sljit_emit_cmov(compiler
, SLJIT_LESS
, SLJIT_R0
| SLJIT_32
, SLJIT_IMM
, 200);
5341 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), 0, SLJIT_R0
, 0);
5343 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 95);
5344 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R3
, 0, SLJIT_IMM
, 177);
5345 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 95);
5346 sljit_emit_cmov(compiler
, SLJIT_LESS_EQUAL
, SLJIT_R3
| SLJIT_32
, SLJIT_R0
, 0);
5347 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5348 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s32
), SLJIT_R3
, 0);
5350 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R3
, 0, SLJIT_IMM
, 56);
5351 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R4
, 0, SLJIT_IMM
, -63);
5352 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_SIG_LESS
, SLJIT_R3
, 0, SLJIT_R4
, 0);
5353 sljit_emit_cmov(compiler
, SLJIT_SIG_LESS
, SLJIT_R3
| SLJIT_32
, SLJIT_R4
, 0);
5354 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_s32
), SLJIT_R3
, 0);
5355 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_SIG_GREATER
, SLJIT_R3
, 0, SLJIT_R4
, 0);
5356 sljit_emit_cmov(compiler
, SLJIT_SIG_GREATER
, SLJIT_R3
| SLJIT_32
, SLJIT_R4
, 0);
5357 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_s32
), SLJIT_R3
, 0);
5359 sljit_emit_return_void(compiler
);
5361 code
.code
= sljit_generate_code(compiler
);
5363 sljit_free_compiler(compiler
);
5365 code
.func3((sljit_sw
)&buf
, (sljit_sw
)&ibuf
, (sljit_sw
)&sbuf
);
5367 FAILED(buf
[0] != 17, "test54 case 1 failed\n");
5368 FAILED(buf
[1] != 34, "test54 case 2 failed\n");
5369 FAILED(buf
[2] != 24, "test54 case 3 failed\n");
5370 FAILED(buf
[3] != 78, "test54 case 4 failed\n");
5371 FAILED(buf
[4] != large_num
, "test54 case 5 failed\n");
5372 FAILED(buf
[5] != -45, "test54 case 6 failed\n");
5373 FAILED(buf
[6] != 35, "test54 case 7 failed\n");
5374 FAILED(buf
[7] != 71, "test54 case 8 failed\n");
5375 FAILED(buf
[8] != -29, "test54 case 9 failed\n");
5376 FAILED(buf
[9] != -12, "test54 case 10 failed\n");
5377 FAILED(buf
[10] != 21, "test54 case 11 failed\n");
5379 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5380 FAILED(buf
[11] != 16, "test54 case 12 failed\n");
5381 FAILED(buf
[12] != -45, "test54 case 13 failed\n");
5382 FAILED(buf
[13] != 33, "test54 case 14 failed\n");
5383 FAILED(buf
[14] != 8, "test54 case 15 failed\n");
5384 FAILED(buf
[15] != -60, "test54 case 16 failed\n");
5385 FAILED(buf
[16] != 31, "test54 case 17 failed\n");
5386 FAILED(buf
[17] != 53, "test54 case 18 failed\n");
5387 FAILED(buf
[18] != 59, "test54 case 19 failed\n");
5390 FAILED(ibuf
[0] != 200, "test54 case 12 failed\n");
5391 FAILED(ibuf
[1] != 95, "test54 case 13 failed\n");
5392 FAILED(ibuf
[2] != 56, "test54 case 14 failed\n");
5393 FAILED(ibuf
[3] != -63, "test54 case 15 failed\n");
5395 sljit_free_code(code
.code
, NULL
);
5399 static void test55(void)
5401 /* Check value preservation. */
5402 executable_code code
;
5403 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5408 printf("Run test55\n");
5410 FAILED(!compiler
, "cannot create compiler\n");
5414 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0, sizeof (sljit_sw
));
5416 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, 217);
5419 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5420 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 118);
5422 sljit_emit_op0(compiler
, SLJIT_DIVMOD_SW
);
5424 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5426 for (i
= 2; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5427 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
5428 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_SP
), 0);
5430 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)(buf
+ 0), SLJIT_R0
, 0);
5433 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5434 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, 146);
5436 sljit_emit_op0(compiler
, SLJIT_DIV_SW
);
5438 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5440 for (i
= 1; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++)
5441 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R(i
), 0);
5442 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_SP
), 0);
5444 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)(buf
+ 1), SLJIT_R0
, 0);
5446 sljit_emit_return_void(compiler
);
5448 code
.code
= sljit_generate_code(compiler
);
5450 sljit_free_compiler(compiler
);
5454 FAILED(buf
[0] != (SLJIT_NUMBER_OF_REGISTERS
- 2) * 118 + 217, "test55 case 1 failed\n");
5455 FAILED(buf
[1] != (SLJIT_NUMBER_OF_REGISTERS
- 1) * 146 + 217, "test55 case 2 failed\n");
5457 sljit_free_code(code
.code
, NULL
);
5461 static void test56(void)
5463 /* Check integer substraction with negative immediate. */
5464 executable_code code
;
5465 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5470 printf("Run test56\n");
5472 for (i
= 0; i
< 13; i
++)
5475 FAILED(!compiler
, "cannot create compiler\n");
5477 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 0, 0, 0);
5479 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 90 << 12);
5480 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5481 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
5482 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_SIG_GREATER
);
5483 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5484 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5485 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_LESS
);
5486 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5487 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_SIG_GREATER_EQUAL
);
5488 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5489 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_LESS_EQUAL
);
5490 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5491 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_GREATER
);
5492 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_LESS
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5493 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_SIG_LESS
);
5495 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 90);
5496 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_SIG_GREATER
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -91);
5497 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5498 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_SIG_GREATER
);
5499 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 90);
5500 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_LESS_EQUAL
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -91);
5501 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_LESS_EQUAL
);
5503 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, -0x7fffffff);
5504 sljit_emit_op2(compiler
, SLJIT_ADD32
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -(91 << 12));
5505 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
5507 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, -0x7fffffff-1);
5508 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_OVERFLOW
, SLJIT_R0
, 0, SLJIT_IMM
, 0, SLJIT_R0
, 0);
5509 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
5511 sljit_emit_return_void(compiler
);
5513 code
.code
= sljit_generate_code(compiler
);
5515 sljit_free_compiler(compiler
);
5517 code
.func1((sljit_sw
)&buf
);
5519 FAILED(buf
[0] != (181 << 12), "test56 case 1 failed\n");
5520 FAILED(buf
[1] != 1, "test56 case 2 failed\n");
5521 FAILED(buf
[2] != (181 << 12), "test56 case 3 failed\n");
5522 FAILED(buf
[3] != 1, "test56 case 4 failed\n");
5523 FAILED(buf
[4] != 1, "test56 case 5 failed\n");
5524 FAILED(buf
[5] != 1, "test56 case 6 failed\n");
5525 FAILED(buf
[6] != 0, "test56 case 7 failed\n");
5526 FAILED(buf
[7] != 0, "test56 case 8 failed\n");
5527 FAILED(buf
[8] != 181, "test56 case 9 failed\n");
5528 FAILED(buf
[9] != 1, "test56 case 10 failed\n");
5529 FAILED(buf
[10] != 1, "test56 case 11 failed\n");
5530 FAILED(buf
[11] != 1, "test56 case 12 failed\n");
5531 FAILED(buf
[12] != 1, "test56 case 13 failed\n");
5533 sljit_free_code(code
.code
, NULL
);
5537 static void test57(void)
5539 /* Check prefetch instructions. */
5540 executable_code code
;
5541 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5542 struct sljit_label
* labels
[5];
5547 printf("Run test57\n");
5549 FAILED(!compiler
, "cannot create compiler\n");
5551 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 3, 1, 0, 0, 0);
5553 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
5554 labels
[0] = sljit_emit_label(compiler
);
5555 /* Should never crash. */
5556 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_L1
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R0
), 2);
5557 labels
[1] = sljit_emit_label(compiler
);
5558 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_L2
, SLJIT_MEM0(), 0);
5559 labels
[2] = sljit_emit_label(compiler
);
5560 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
5561 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_L3
, SLJIT_MEM1(SLJIT_R0
), SLJIT_W(0x1122334455667788));
5563 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_L3
, SLJIT_MEM1(SLJIT_R0
), 0x11223344);
5565 labels
[3] = sljit_emit_label(compiler
);
5566 sljit_emit_op_src(compiler
, SLJIT_PREFETCH_ONCE
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
));
5567 labels
[4] = sljit_emit_label(compiler
);
5569 sljit_emit_return_void(compiler
);
5571 code
.code
= sljit_generate_code(compiler
);
5574 for (i
= 0; i
< 5; i
++)
5575 addr
[i
] = sljit_get_label_addr(labels
[i
]);
5577 sljit_free_compiler(compiler
);
5581 if (sljit_has_cpu_feature(SLJIT_HAS_PREFETCH
)) {
5582 FAILED(addr
[0] == addr
[1], "test57 case 1 failed\n");
5583 FAILED(addr
[1] == addr
[2], "test57 case 2 failed\n");
5584 FAILED(addr
[2] == addr
[3], "test57 case 3 failed\n");
5585 FAILED(addr
[3] == addr
[4], "test57 case 4 failed\n");
5588 FAILED(addr
[0] != addr
[1], "test57 case 1 failed\n");
5589 FAILED(addr
[1] != addr
[2], "test57 case 2 failed\n");
5590 FAILED(addr
[2] != addr
[3], "test57 case 3 failed\n");
5591 FAILED(addr
[3] != addr
[4], "test57 case 4 failed\n");
5594 sljit_free_code(code
.code
, NULL
);
5598 static sljit_f64 SLJIT_FUNC
test58_f1(sljit_f32 a
, sljit_f32 b
, sljit_f64 c
)
5600 return (sljit_f64
)a
+ (sljit_f64
)b
+ c
;
5603 static sljit_f32 SLJIT_FUNC
test58_f2(sljit_sw a
, sljit_f64 b
, sljit_f32 c
)
5605 return (sljit_f32
)((sljit_f64
)a
+ b
+ (sljit_f64
)c
);
5608 static sljit_f64 SLJIT_FUNC
test58_f3(sljit_sw a
, sljit_f32 b
, sljit_sw c
)
5610 return (sljit_f64
)a
+ (sljit_f64
)b
+ (sljit_f64
)c
;
5613 static sljit_f64
test58_f4(sljit_f32 a
, sljit_sw b
)
5615 return (sljit_f64
)a
+ (sljit_f64
)b
;
5618 static sljit_f32
test58_f5(sljit_f32 a
, sljit_f64 b
, sljit_s32 c
)
5620 return (sljit_f32
)((sljit_f64
)a
+ b
+ (sljit_f64
)c
);
5623 static sljit_sw SLJIT_FUNC
test58_f6(sljit_f64 a
, sljit_sw b
)
5625 return (sljit_sw
)(a
+ (sljit_f64
)b
);
5628 static void test58(void)
5630 /* Check function calls with floating point arguments. */
5631 executable_code code
;
5632 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5633 struct sljit_jump
* jump
= NULL
;
5639 printf("Run test58\n");
5641 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5643 printf("no fpu available, test58 skipped\n");
5646 sljit_free_compiler(compiler
);
5667 FAILED(!compiler
, "cannot create compiler\n");
5669 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 3, 3, 4, 0, sizeof(sljit_sw
));
5671 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
5672 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
5673 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
5674 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(F64
, F32
, F32
, F64
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test58_f1
));
5676 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
), SLJIT_FR0
, 0);
5678 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
5679 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
));
5680 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
));
5681 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS3(F64
, F32
, F32
, F64
));
5682 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test58_f1
));
5684 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5686 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test58_f2
));
5687 sljit_get_local_base(compiler
, SLJIT_R1
, 0, -16);
5688 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
5689 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
5690 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
5691 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS3(F32
, W
, F64
, F32
), SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 0);
5693 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
5695 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -4);
5696 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 9);
5697 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0);
5698 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
5699 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS3(F64
, W
, F32
, W
));
5700 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test58_f3
));
5702 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5704 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
));
5705 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -6);
5706 jump
= sljit_emit_call(compiler
, SLJIT_CALL_CDECL
, SLJIT_ARGS2(F64
, F32
, W
));
5707 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test58_f4
));
5709 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
5711 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test58_f5
));
5712 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
));
5713 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
));
5714 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8);
5715 sljit_emit_icall(compiler
, SLJIT_CALL_CDECL
, SLJIT_ARGS3(F32
, F32
, F64
, 32), SLJIT_MEM1(SLJIT_SP
), 0);
5717 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 4 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
5719 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
));
5720 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test58_f6
));
5721 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS2(W
, F64
, W
), SLJIT_R0
, 0);
5723 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), 0, SLJIT_R0
, 0);
5725 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_f64
));
5726 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 319);
5727 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test58_f6
));
5728 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS2(W
, F64
, W
), SLJIT_R1
, 0);
5730 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_sw
), SLJIT_R0
, 0);
5732 sljit_emit_return_void(compiler
);
5734 code
.code
= sljit_generate_code(compiler
);
5736 sljit_free_compiler(compiler
);
5738 code
.func3((sljit_sw
)&dbuf
, (sljit_sw
)&sbuf
, (sljit_sw
)&wbuf
);
5740 FAILED(dbuf
[1] != 8.5, "test58 case 1 failed\n");
5741 FAILED(dbuf
[3] != 0.5, "test58 case 2 failed\n");
5742 FAILED(sbuf
[3] != 17.75, "test58 case 3 failed\n");
5743 FAILED(dbuf
[4] != 11.75, "test58 case 4 failed\n");
5744 FAILED(dbuf
[5] != -9.5, "test58 case 5 failed\n");
5745 FAILED(sbuf
[4] != 12, "test58 case 6 failed\n");
5746 FAILED(wbuf
[0] != SLJIT_FUNC_ADDR(test58_f6
) - 18, "test58 case 7 failed\n");
5747 FAILED(wbuf
[1] != 301, "test58 case 8 failed\n");
5749 sljit_free_code(code
.code
, NULL
);
5753 static sljit_sw SLJIT_FUNC
test59_f1(sljit_sw a
, sljit_s32 b
, sljit_sw c
, sljit_sw d
)
5755 return (sljit_sw
)(a
+ b
+ c
+ d
- SLJIT_FUNC_ADDR(test59_f1
));
5758 static sljit_sw
test59_f2(sljit_sw a
, sljit_s32 b
, sljit_sw c
, sljit_sw d
)
5760 return (sljit_sw
)(a
+ b
+ c
+ d
- SLJIT_FUNC_ADDR(test59_f2
));
5763 static sljit_s32 SLJIT_FUNC
test59_f3(sljit_f64 a
, sljit_f32 b
, sljit_f64 c
, sljit_sw d
)
5765 return (sljit_s32
)(a
+ b
+ c
+ (sljit_f64
)d
);
5768 static sljit_f32 SLJIT_FUNC
test59_f4(sljit_f32 a
, sljit_s32 b
, sljit_f64 c
, sljit_sw d
)
5770 return (sljit_f32
)(a
+ (sljit_f64
)b
+ c
+ (sljit_f64
)d
);
5773 static sljit_f32 SLJIT_FUNC
test59_f5(sljit_f32 a
, sljit_f64 b
, sljit_f32 c
, sljit_f64 d
)
5775 return (sljit_f32
)(a
+ b
+ c
+ (sljit_f64
)d
);
5778 static void test59(void)
5780 /* Check function calls with four arguments. */
5781 executable_code code
;
5782 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5783 struct sljit_jump
* jump
= NULL
;
5789 printf("Run test59\n");
5794 wbuf
[3] = SLJIT_FUNC_ADDR(test59_f1
);
5798 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5809 FAILED(!compiler
, "cannot create compiler\n");
5811 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 4, 3, 4, 0, sizeof(sljit_sw
));
5813 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 33);
5814 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -20);
5815 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f1
));
5816 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -40);
5817 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS4(W
, W
, 32, W
, W
), SLJIT_R2
, 0);
5819 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
5821 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 16);
5822 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -30);
5823 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 50);
5824 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f2
));
5825 sljit_emit_icall(compiler
, SLJIT_CALL_CDECL
, SLJIT_ARGS4(W
, W
, 32, W
, W
), SLJIT_R3
, 0);
5827 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
5829 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f1
));
5830 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -25);
5831 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 100);
5832 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -10);
5833 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS4(W
, W
, 32, W
, W
), SLJIT_R0
, 0);
5835 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5837 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
5838 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 231);
5839 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 3);
5840 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f1
) - 100);
5841 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS4(W
, W
, 32, W
, W
), SLJIT_MEM2(SLJIT_R0
, SLJIT_R2
), SLJIT_WORD_SHIFT
);
5843 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5845 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5846 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
5847 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S2
), 0);
5848 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
));
5849 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -100);
5850 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS4(32, F64
, F32
, F64
, W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f3
));
5851 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_R0
, 0);
5853 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5855 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
5856 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f64
));
5857 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 36);
5858 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 41);
5859 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS4(F32
, F32
, 32, F64
, W
));
5860 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test59_f4
));
5862 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
5864 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test59_f5
));
5865 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S2
), 0);
5866 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
5867 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
5868 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f64
));
5869 sljit_emit_icall(compiler
, SLJIT_CALL
, SLJIT_ARGS4(F32
, F32
, F64
, F32
, F64
), SLJIT_R0
, 0);
5871 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S2
), 3 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
5874 sljit_emit_return_void(compiler
);
5876 code
.code
= sljit_generate_code(compiler
);
5878 sljit_free_compiler(compiler
);
5880 code
.func3((sljit_sw
)&wbuf
, (sljit_sw
)&dbuf
, (sljit_sw
)&sbuf
);
5882 FAILED(wbuf
[0] != -27, "test59 case 1 failed\n");
5883 FAILED(wbuf
[1] != 36, "test59 case 2 failed\n");
5884 FAILED(wbuf
[2] != 65, "test59 case 3 failed\n");
5885 FAILED(wbuf
[4] != (sljit_sw
)wbuf
+ 134, "test59 case 4 failed\n");
5887 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
5888 FAILED(wbuf
[5] != -88, "test59 case 5 failed\n");
5889 FAILED(sbuf
[2] != 79.75, "test59 case 6 failed\n");
5890 FAILED(sbuf
[3] != 8.625, "test59 case 7 failed\n");
5893 sljit_free_code(code
.code
, NULL
);
5897 static void test60(void)
5899 /* Test memory accesses with pre/post updates. */
5900 executable_code code
;
5901 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
5903 sljit_s32 supported
[10];
5908 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
5909 static sljit_u8 expected
[10] = { 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 };
5910 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
5911 static sljit_u8 expected
[10] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
5912 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32)
5913 static sljit_u8 expected
[10] = { 1, 0, 1, 1, 0, 1, 1, 1, 0, 0 };
5914 #elif (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
5915 static sljit_u8 expected
[10] = { 1, 0, 0, 1, 0, 0, 1, 1, 0, 0 };
5917 static sljit_u8 expected
[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
5921 printf("Run test60\n");
5923 for (i
= 0; i
< 18; i
++)
5935 FAILED(!compiler
, "cannot create compiler\n");
5937 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 4, 3, 4, 0, sizeof(sljit_sw
));
5939 supported
[0] = sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_sw
));
5940 if (supported
[0] == SLJIT_SUCCESS
) {
5941 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
5942 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_sw
));
5943 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
5944 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
5947 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
));
5948 if (supported
[1] == SLJIT_SUCCESS
) {
5949 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s8
));
5950 sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM1(SLJIT_R2
), -2 * (sljit_sw
)sizeof(sljit_s8
));
5951 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5952 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R2
, 0);
5955 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
));
5956 if (supported
[2] == SLJIT_SUCCESS
) {
5957 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s32
));
5958 sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_PRE
, SLJIT_R2
, SLJIT_MEM1(SLJIT_R1
), -2 * (sljit_sw
)sizeof(sljit_s32
));
5959 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R2
, 0);
5960 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5963 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
));
5964 if (supported
[3] == SLJIT_SUCCESS
) {
5965 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, -8765);
5966 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, sizeof(sljit_s32
));
5967 sljit_emit_mem(compiler
, SLJIT_MOV32
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R2
), 2 * sizeof(sljit_s32
));
5968 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R2
, 0);
5971 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
));
5972 if (supported
[4] == SLJIT_SUCCESS
) {
5973 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -121);
5974 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_S1
, 0);
5975 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
));
5976 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R2
, 0);
5979 supported
[5] = sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 1);
5980 if (supported
[5] == SLJIT_SUCCESS
) {
5981 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 9 * sizeof(sljit_sw
) - 1);
5982 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -881199);
5983 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 1);
5984 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5987 supported
[6] = sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5988 if (supported
[6] == SLJIT_SUCCESS
) {
5989 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 213);
5990 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -213);
5991 sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_PRE
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
5992 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R0
, 0);
5993 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R1
, 0);
5996 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);
5997 if (supported
[7] == SLJIT_SUCCESS
) {
5998 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_S2
, 0);
5999 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s32
));
6000 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -7890);
6001 sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
6002 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R1
, 0);
6005 supported
[8] = sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 2);
6006 if (supported
[8] == SLJIT_SUCCESS
) {
6007 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 2 * sizeof(sljit_sw
));
6008 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2 * sizeof(sljit_sw
));
6009 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 2);
6010 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R0
, 0);
6011 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 15 * sizeof(sljit_sw
), SLJIT_R1
, 0);
6014 supported
[9] = sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
6015 if (supported
[9] == SLJIT_SUCCESS
) {
6016 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 2 * sizeof(sljit_s8
));
6017 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -2 * (sljit_sw
)sizeof(sljit_s8
));
6018 sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_POST
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R2
), 0);
6019 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 16 * sizeof(sljit_sw
), SLJIT_R0
, 0);
6020 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 17 * sizeof(sljit_sw
), SLJIT_R1
, 0);
6023 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
);
6024 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
);
6026 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
6027 /* TODO: at least for ARM (both V5 and V7) the range below needs further fixing */
6028 SLJIT_ASSERT(sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), 256) == SLJIT_ERR_UNSUPPORTED
);
6029 SLJIT_ASSERT(sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_R1
, SLJIT_MEM1(SLJIT_R0
), -257) == SLJIT_ERR_UNSUPPORTED
);
6032 sljit_emit_return_void(compiler
);
6034 code
.code
= sljit_generate_code(compiler
);
6036 sljit_free_compiler(compiler
);
6038 code
.func3((sljit_sw
)&wbuf
, (sljit_sw
)&bbuf
, (sljit_sw
)&ibuf
);
6040 FAILED(sizeof(expected
) != sizeof(supported
) / sizeof(sljit_s32
), "test60 case 1 failed\n");
6042 for (i
= 0; i
< sizeof(expected
); i
++) {
6044 if (supported
[i
] != SLJIT_SUCCESS
) {
6045 printf("tast60 case %d should be supported\n", i
+ 1);
6049 if (supported
[i
] == SLJIT_SUCCESS
) {
6050 printf("test60 case %d should not be supported\n", i
+ 1);
6056 FAILED(supported
[0] == SLJIT_SUCCESS
&& wbuf
[0] != -887766, "test60 case 2 failed\n");
6057 FAILED(supported
[0] == SLJIT_SUCCESS
&& wbuf
[1] != (sljit_sw
)(wbuf
+ 2), "test60 case 3 failed\n");
6058 FAILED(supported
[1] == SLJIT_SUCCESS
&& wbuf
[3] != -13, "test60 case 4 failed\n");
6059 FAILED(supported
[1] == SLJIT_SUCCESS
&& wbuf
[4] != (sljit_sw
)(bbuf
), "test60 case 5 failed\n");
6060 FAILED(supported
[2] == SLJIT_SUCCESS
&& wbuf
[5] != -5678, "test60 case 6 failed\n");
6061 FAILED(supported
[2] == SLJIT_SUCCESS
&& wbuf
[6] != (sljit_sw
)(ibuf
), "test60 case 7 failed\n");
6062 FAILED(supported
[3] == SLJIT_SUCCESS
&& ibuf
[1] != -8765, "test60 case 8 failed\n");
6063 FAILED(supported
[3] == SLJIT_SUCCESS
&& wbuf
[7] != (sljit_sw
)(ibuf
+ 1), "test60 case 9 failed\n");
6064 FAILED(supported
[4] == SLJIT_SUCCESS
&& bbuf
[0] != -121, "test60 case 10 failed\n");
6065 FAILED(supported
[4] == SLJIT_SUCCESS
&& wbuf
[8] != (sljit_sw
)(bbuf
) - 128 * (sljit_sw
)sizeof(sljit_s8
), "test60 case 11 failed\n");
6066 FAILED(supported
[5] == SLJIT_SUCCESS
&& wbuf
[9] != -881199, "test60 case 12 failed\n");
6067 FAILED(supported
[5] == SLJIT_SUCCESS
&& wbuf
[10] != (sljit_sw
)(wbuf
+ 9), "test60 case 13 failed\n");
6068 FAILED(supported
[6] == SLJIT_SUCCESS
&& wbuf
[11] != -5678, "test60 case 14 failed\n");
6069 FAILED(supported
[6] == SLJIT_SUCCESS
&& wbuf
[12] != (sljit_sw
)(ibuf
), "test60 case 15 failed\n");
6070 FAILED(supported
[7] == SLJIT_SUCCESS
&& ibuf
[2] != -7890, "test60 case 16 failed\n");
6071 FAILED(supported
[7] == SLJIT_SUCCESS
&& wbuf
[13] != (sljit_sw
)(ibuf
+ 2), "test60 case 17 failed\n");
6072 FAILED(supported
[8] == SLJIT_SUCCESS
&& wbuf
[14] != -887766, "test60 case 18 failed\n");
6073 FAILED(supported
[8] == SLJIT_SUCCESS
&& wbuf
[15] != (sljit_sw
)(wbuf
+ 10), "test60 case 19 failed\n");
6074 FAILED(supported
[9] == SLJIT_SUCCESS
&& wbuf
[16] != -13, "test60 case 20 failed\n");
6075 FAILED(supported
[9] == SLJIT_SUCCESS
&& wbuf
[17] != (sljit_sw
)(bbuf
), "test60 case 21 failed\n");
6077 sljit_free_code(code
.code
, NULL
);
6081 static void test61(void)
6083 /* Test float memory accesses with pre/post updates. */
6084 executable_code code
;
6085 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6087 sljit_s32 supported
[6];
6091 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
6092 static sljit_u8 expected
[6] = { 1, 1, 1, 1, 0, 0 };
6093 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
6094 static sljit_u8 expected
[6] = { 1, 0, 1, 0, 1, 1 };
6096 static sljit_u8 expected
[6] = { 0, 0, 0, 0, 0, 0 };
6099 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
6101 printf("no fpu available, test61 skipped\n");
6104 sljit_free_compiler(compiler
);
6109 printf("Run test61\n");
6111 for (i
= 0; i
< 6; i
++)
6124 FAILED(!compiler
, "cannot create compiler\n");
6126 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 4, 3, 4, 0, sizeof(sljit_sw
));
6128 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
));
6129 if (supported
[0] == SLJIT_SUCCESS
) {
6130 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 4 * sizeof(sljit_f64
));
6131 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_PRE
, SLJIT_FR0
, SLJIT_MEM1(SLJIT_R0
), 4 * sizeof(sljit_f64
));
6132 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
), SLJIT_FR0
, 0);
6133 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
6136 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
));
6137 if (supported
[1] == SLJIT_SUCCESS
) {
6138 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 2 * sizeof(sljit_f64
));
6139 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
6140 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_STORE
| SLJIT_MEM_POST
, SLJIT_FR2
, SLJIT_MEM1(SLJIT_R0
), -(sljit_sw
)sizeof(sljit_f64
));
6141 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
6144 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
));
6145 if (supported
[2] == SLJIT_SUCCESS
) {
6146 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R2
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 4 * sizeof(sljit_f32
));
6147 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
6148 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
));
6149 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R2
, 0);
6152 supported
[3] = sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_SUPP
| SLJIT_MEM_POST
, SLJIT_FR1
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_f32
));
6153 if (supported
[3] == SLJIT_SUCCESS
) {
6154 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S2
, 0, SLJIT_IMM
, sizeof(sljit_f32
));
6155 sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_POST
, SLJIT_FR1
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_f32
));
6156 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_f32
), SLJIT_FR1
, 0);
6157 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R1
, 0);
6160 supported
[4] = sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_SUPP
| SLJIT_MEM_PRE
, SLJIT_FR0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 0);
6161 if (supported
[4] == SLJIT_SUCCESS
) {
6162 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 8 * sizeof(sljit_f64
));
6163 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -8 * (sljit_sw
)sizeof(sljit_f64
));
6164 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_PRE
, SLJIT_FR0
, SLJIT_MEM2(SLJIT_R1
, SLJIT_R0
), 0);
6165 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S1
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
6166 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R1
, 0);
6169 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);
6170 if (supported
[5] == SLJIT_SUCCESS
) {
6171 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_S2
, 0);
6172 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 3 * sizeof(sljit_f32
));
6173 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
6174 sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_STORE
| SLJIT_MEM_PRE
, SLJIT_FR2
, SLJIT_MEM2(SLJIT_R2
, SLJIT_R1
), 0);
6175 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R2
, 0);
6178 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
);
6179 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
);
6181 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
6182 /* TODO: at least for ARM (both V5 and V7) the range below needs further fixing */
6183 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
);
6184 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
);
6187 sljit_emit_return_void(compiler
);
6189 code
.code
= sljit_generate_code(compiler
);
6191 sljit_free_compiler(compiler
);
6193 code
.func3((sljit_sw
)&wbuf
, (sljit_sw
)&dbuf
, (sljit_sw
)&sbuf
);
6195 FAILED(sizeof(expected
) != sizeof(supported
) / sizeof(sljit_s32
), "test61 case 1 failed\n");
6197 for (i
= 0; i
< sizeof(expected
); i
++) {
6199 if (supported
[i
] != SLJIT_SUCCESS
) {
6200 printf("tast61 case %d should be supported\n", i
+ 1);
6204 if (supported
[i
] == SLJIT_SUCCESS
) {
6205 printf("test61 case %d should not be supported\n", i
+ 1);
6211 FAILED(supported
[0] == SLJIT_SUCCESS
&& dbuf
[1] != 66.725, "test61 case 2 failed\n");
6212 FAILED(supported
[0] == SLJIT_SUCCESS
&& wbuf
[0] != (sljit_sw
)(dbuf
), "test61 case 3 failed\n");
6213 FAILED(supported
[1] == SLJIT_SUCCESS
&& dbuf
[2] != 66.725, "test61 case 4 failed\n");
6214 FAILED(supported
[1] == SLJIT_SUCCESS
&& wbuf
[1] != (sljit_sw
)(dbuf
+ 1), "test61 case 5 failed\n");
6215 FAILED(supported
[2] == SLJIT_SUCCESS
&& sbuf
[0] != -22.125, "test61 case 6 failed\n");
6216 FAILED(supported
[2] == SLJIT_SUCCESS
&& wbuf
[2] != (sljit_sw
)(sbuf
), "test61 case 7 failed\n");
6217 FAILED(supported
[3] == SLJIT_SUCCESS
&& sbuf
[2] != -22.125, "test61 case 8 failed\n");
6218 FAILED(supported
[3] == SLJIT_SUCCESS
&& wbuf
[3] != (sljit_sw
)(sbuf
+ 2), "test61 case 9 failed\n");
6219 FAILED(supported
[4] == SLJIT_SUCCESS
&& dbuf
[3] != 66.725, "test61 case 10 failed\n");
6220 FAILED(supported
[4] == SLJIT_SUCCESS
&& wbuf
[4] != (sljit_sw
)(dbuf
), "test61 case 11 failed\n");
6221 FAILED(supported
[5] == SLJIT_SUCCESS
&& sbuf
[3] != -22.125, "test61 case 12 failed\n");
6222 FAILED(supported
[5] == SLJIT_SUCCESS
&& wbuf
[5] != (sljit_sw
)(sbuf
+ 3), "test61 case 13 failed\n");
6224 sljit_free_code(code
.code
, NULL
);
6228 static void test62(void)
6230 /* Test fast calls flag preservation. */
6231 executable_code code1
;
6232 executable_code code2
;
6233 struct sljit_compiler
* compiler
;
6236 printf("Run test62\n");
6239 compiler
= sljit_create_compiler(NULL
, NULL
);
6240 FAILED(!compiler
, "cannot create compiler\n");
6241 sljit_set_context(compiler
, 0, SLJIT_ARGS1(W
, W
), 1, 1, 0, 0, 0);
6243 sljit_emit_fast_enter(compiler
, SLJIT_R0
, 0);
6244 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
| SLJIT_SET_LESS
, SLJIT_S0
, 0, SLJIT_IMM
, 42);
6245 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R0
, 0);
6247 code1
.code
= sljit_generate_code(compiler
);
6249 sljit_free_compiler(compiler
);
6252 compiler
= sljit_create_compiler(NULL
, NULL
);
6253 FAILED(!compiler
, "cannot create compiler\n");
6255 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, W
), 1, 1, 0, 0, 0);
6256 sljit_emit_ijump(compiler
, SLJIT_FAST_CALL
, SLJIT_IMM
, SLJIT_FUNC_ADDR(code1
.code
));
6257 sljit_set_current_flags(compiler
, SLJIT_CURRENT_FLAGS_SUB
| SLJIT_CURRENT_FLAGS_COMPARE
| SLJIT_SET_Z
| SLJIT_SET_LESS
);
6258 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_ZERO
);
6259 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_LESS
);
6260 sljit_emit_op2(compiler
, SLJIT_SHL
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, 1);
6261 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_S0
, 0);
6262 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
6264 code2
.code
= sljit_generate_code(compiler
);
6266 sljit_free_compiler(compiler
);
6268 FAILED(code2
.func1(88) != 0, "test62 case 1 failed\n");
6269 FAILED(code2
.func1(42) != 1, "test62 case 2 failed\n");
6270 FAILED(code2
.func1(0) != 2, "test62 case 3 failed\n");
6272 sljit_free_code(code1
.code
, NULL
);
6273 sljit_free_code(code2
.code
, NULL
);
6277 static void test63(void)
6279 /* Test put label. */
6280 executable_code code
;
6281 struct sljit_label
*label
[2];
6282 struct sljit_put_label
*put_label
[5];
6283 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6286 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
6287 sljit_sw offs
= SLJIT_W(0x123456789012);
6289 sljit_sw offs
= 0x12345678;
6293 printf("Run test63\n");
6295 FAILED(!compiler
, "cannot create compiler\n");
6301 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 2 * sizeof(sljit_sw
));
6303 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_R0
, 0);
6304 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
6306 put_label
[1] = sljit_emit_put_label(compiler
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
));
6307 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
));
6309 label
[0] = sljit_emit_label(compiler
);
6310 sljit_set_put_label(put_label
[0], label
[0]);
6311 sljit_set_put_label(put_label
[1], label
[0]);
6313 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)(buf
+ 2) - offs
);
6314 put_label
[2] = sljit_emit_put_label(compiler
, SLJIT_MEM1(SLJIT_R0
), offs
);
6316 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (offs
+ (sljit_sw
)sizeof(sljit_uw
)) >> 1);
6317 put_label
[3] = sljit_emit_put_label(compiler
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1);
6319 label
[1] = sljit_emit_label(compiler
);
6320 sljit_set_put_label(put_label
[2], label
[1]);
6321 sljit_set_put_label(put_label
[3], label
[1]);
6323 put_label
[4] = sljit_emit_put_label(compiler
, SLJIT_RETURN_REG
, 0);
6324 sljit_set_put_label(put_label
[4], label
[0]);
6325 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
6327 code
.code
= sljit_generate_code(compiler
);
6330 addr
[0] = sljit_get_label_addr(label
[0]);
6331 addr
[1] = sljit_get_label_addr(label
[1]);
6333 sljit_free_compiler(compiler
);
6335 FAILED(code
.func1((sljit_sw
)&buf
) != (sljit_sw
)addr
[0], "test63 case 1 failed\n");
6336 FAILED(buf
[0] != addr
[0], "test63 case 2 failed\n");
6337 FAILED(buf
[1] != addr
[0], "test63 case 3 failed\n");
6338 FAILED(buf
[2] != addr
[1], "test63 case 4 failed\n");
6339 FAILED(buf
[3] != addr
[1], "test63 case 5 failed\n");
6341 sljit_free_code(code
.code
, NULL
);
6345 static void test64(void)
6347 /* Test put label with absolute label addresses */
6348 executable_code code
;
6349 sljit_uw malloc_addr
;
6350 struct sljit_label label
[6];
6351 struct sljit_put_label
*put_label
[2];
6352 struct sljit_compiler
* compiler
;
6355 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
6356 /* Must be even because it is also used for addressing. */
6357 sljit_sw offs1
= SLJIT_W(0x1234567812l
);
6358 sljit_sw offs2
= SLJIT_W(0x123456781122l
);
6359 sljit_sw offs3
= SLJIT_W(0x7fffffff7ffl
);
6360 sljit_sw offs4
= SLJIT_W(0x1234567811223344l
);
6361 #else /* !SLJIT_64BIT_ARCHITECTURE */
6362 sljit_sw offs1
= (sljit_sw
)0x80000000;
6363 sljit_sw offs2
= (sljit_sw
)0xe0000000;
6364 sljit_sw offs3
= (sljit_sw
)0x87654321;
6365 sljit_sw offs4
= (sljit_sw
)0xffffffff;
6366 #endif /* SLJIT_64BIT_ARCHITECTURE */
6369 printf("Run test64\n");
6371 /* lock next allocation; see sljit_test_malloc_exec() */
6372 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
6373 malloc_addr
= (sljit_uw
)SLJIT_MALLOC_EXEC(1024, NULL
);
6376 printf("Cannot allocate executable memory\n");
6380 compiler
= sljit_create_compiler(NULL
, (void*)malloc_addr
);
6381 malloc_addr
+= (sljit_uw
)SLJIT_EXEC_OFFSET((void*)malloc_addr
);
6382 #else /* SLJIT_CONFIG_UNSUPPORTED */
6384 compiler
= sljit_create_compiler(NULL
, (void*)malloc_addr
);
6385 #endif /* !SLJIT_CONFIG_UNSUPPORTED */
6387 label
[0].addr
= 0x1234;
6388 label
[0].size
= (sljit_uw
)0x1234 - malloc_addr
;
6390 label
[1].addr
= 0x12345678;
6391 label
[1].size
= (sljit_uw
)0x12345678 - malloc_addr
;
6393 label
[2].addr
= (sljit_uw
)offs1
;
6394 label
[2].size
= (sljit_uw
)offs1
- malloc_addr
;
6396 label
[3].addr
= (sljit_uw
)offs2
;
6397 label
[3].size
= (sljit_uw
)offs2
- malloc_addr
;
6399 label
[4].addr
= (sljit_uw
)offs3
;
6400 label
[4].size
= (sljit_uw
)offs3
- malloc_addr
;
6402 label
[5].addr
= (sljit_uw
)offs4
;
6403 label
[5].size
= (sljit_uw
)offs4
- malloc_addr
;
6405 FAILED(!compiler
, "cannot create compiler\n");
6407 for (i
= 0; i
< 6; i
++)
6410 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, P
), 3, 1, 0, 0, 2 * sizeof(sljit_sw
));
6412 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_R0
, 0);
6413 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
6415 put_label
[1] = sljit_emit_put_label(compiler
, SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
));
6416 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_uw
), SLJIT_MEM1(SLJIT_SP
), sizeof(sljit_uw
));
6418 sljit_set_put_label(put_label
[0], &label
[0]);
6419 sljit_set_put_label(put_label
[1], &label
[0]);
6421 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)(buf
+ 2) - offs1
);
6422 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_MEM1(SLJIT_R0
), offs1
);
6424 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (offs1
+ (sljit_sw
)sizeof(sljit_uw
)) >> 1);
6425 put_label
[1] = sljit_emit_put_label(compiler
, SLJIT_MEM2(SLJIT_R0
, SLJIT_R1
), 1);
6427 sljit_set_put_label(put_label
[0], &label
[1]);
6428 sljit_set_put_label(put_label
[1], &label
[1]);
6430 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_R1
, 0);
6431 sljit_set_put_label(put_label
[0], &label
[2]);
6432 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_uw
), SLJIT_R1
, 0);
6434 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_R2
, 0);
6435 sljit_set_put_label(put_label
[0], &label
[3]);
6436 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_uw
), SLJIT_R2
, 0);
6438 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_R1
, 0);
6439 sljit_set_put_label(put_label
[0], &label
[4]);
6440 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_uw
), SLJIT_R1
, 0);
6442 put_label
[0] = sljit_emit_put_label(compiler
, SLJIT_RETURN_REG
, 0);
6443 sljit_set_put_label(put_label
[0], &label
[5]);
6444 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
6446 code
.code
= sljit_generate_code(compiler
);
6448 sljit_free_compiler(compiler
);
6449 SLJIT_ASSERT(SLJIT_FUNC_UADDR(code
.code
) >= malloc_addr
&& SLJIT_FUNC_UADDR(code
.code
) <= malloc_addr
+ 8);
6451 FAILED(code
.func1((sljit_sw
)&buf
) != (sljit_sw
)label
[5].addr
, "test64 case 1 failed\n");
6452 FAILED(buf
[0] != label
[0].addr
, "test64 case 2 failed\n");
6453 FAILED(buf
[1] != label
[0].addr
, "test64 case 3 failed\n");
6454 FAILED(buf
[2] != label
[1].addr
, "test64 case 4 failed\n");
6455 FAILED(buf
[3] != label
[1].addr
, "test64 case 5 failed\n");
6456 FAILED(buf
[4] != label
[2].addr
, "test64 case 6 failed\n");
6457 FAILED(buf
[5] != label
[3].addr
, "test64 case 7 failed\n");
6458 FAILED(buf
[6] != label
[4].addr
, "test64 case 8 failed\n");
6460 sljit_free_code(code
.code
, NULL
);
6465 static void test65(void)
6467 /* Test jump tables. */
6468 executable_code code
;
6469 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6471 /* Normally this table is allocated on the heap. */
6473 struct sljit_label
*labels
[64];
6474 struct sljit_jump
*jump
;
6477 printf("Run test65\n");
6479 FAILED(!compiler
, "cannot create compiler\n");
6481 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(W
, W
, W
), 1, 2, 0, 0, 0);
6483 jump
= sljit_emit_cmp(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_S0
, 0, SLJIT_IMM
, 64);
6484 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)addr
);
6485 sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_MEM2(SLJIT_R0
, SLJIT_S0
), SLJIT_WORD_SHIFT
);
6487 for (i
= 0; i
< 64; i
++) {
6488 labels
[i
] = sljit_emit_label(compiler
);
6489 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
6490 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, i
* 2);
6491 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
6494 sljit_set_label(jump
, sljit_emit_label(compiler
));
6495 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_IMM
, -1);
6497 code
.code
= sljit_generate_code(compiler
);
6500 for (i
= 0; i
< 64; i
++) {
6501 addr
[i
] = sljit_get_label_addr(labels
[i
]);
6504 sljit_free_compiler(compiler
);
6506 FAILED(code
.func2(64, 0) != -1, "test65 case 1 failed\n");
6508 for (i
= 0; i
< 64; i
++) {
6509 FAILED(code
.func2(i
, i
* 2) != i
* 4, "test65 case 2 failed\n");
6512 sljit_free_code(code
.code
, NULL
);
6516 static void test66(void)
6518 /* Test direct jumps (computed goto). */
6519 executable_code code
;
6520 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6523 struct sljit_label
*labels
[64];
6526 printf("Run test66\n");
6528 FAILED(!compiler
, "cannot create compiler\n");
6530 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(W
, W
, W
), 1, 2, 0, 0, 0);
6531 sljit_emit_ijump(compiler
, SLJIT_JUMP
, SLJIT_S0
, 0);
6533 for (i
= 0; i
< 64; i
++) {
6534 labels
[i
] = sljit_emit_label(compiler
);
6535 sljit_emit_op0(compiler
, SLJIT_ENDBR
);
6536 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, i
* 2);
6537 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_RETURN_REG
, 0);
6540 code
.code
= sljit_generate_code(compiler
);
6543 for (i
= 0; i
< 64; i
++) {
6544 addr
[i
] = sljit_get_label_addr(labels
[i
]);
6547 sljit_free_compiler(compiler
);
6549 for (i
= 0; i
< 64; i
++) {
6550 FAILED(code
.func2((sljit_sw
)addr
[i
], i
) != i
* 3, "test66 case 1 failed\n");
6553 sljit_free_code(code
.code
, NULL
);
6557 static void test67(void)
6559 /* Test skipping returns from fast calls (return type is fast). */
6560 executable_code code
;
6561 struct sljit_compiler
*compiler
= sljit_create_compiler(NULL
, NULL
);
6562 struct sljit_jump
*call
, *jump
;
6563 struct sljit_label
*label
;
6566 printf("Run test67\n");
6568 FAILED(!compiler
, "cannot create compiler\n");
6570 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), 3, 1, 0, 0, 0);
6572 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
6573 call
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
);
6575 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
6577 /* First function, never returns. */
6578 label
= sljit_emit_label(compiler
);
6579 sljit_set_label(call
, label
);
6580 sljit_emit_fast_enter(compiler
, SLJIT_R1
, 0);
6582 call
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
);
6584 /* Should never return here, marked by a segmentation fault if it does. */
6585 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
6587 /* Second function, skips the first function. */
6588 sljit_set_label(call
, sljit_emit_label(compiler
));
6589 sljit_emit_fast_enter(compiler
, SLJIT_R2
, 0);
6591 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
6593 jump
= sljit_emit_cmp(compiler
, SLJIT_NOT_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
6595 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_R1
, 0);
6596 sljit_set_label(sljit_emit_jump(compiler
, SLJIT_FAST_CALL
), label
);
6597 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
6598 sljit_emit_op_src(compiler
, SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN
, SLJIT_S0
, 0);
6599 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_S0
, 0);
6601 sljit_set_label(jump
, sljit_emit_label(compiler
));
6602 sljit_emit_op_src(compiler
, SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN
, SLJIT_R1
, 0);
6603 sljit_emit_op_src(compiler
, SLJIT_FAST_RETURN
, SLJIT_R1
, 0);
6605 code
.code
= sljit_generate_code(compiler
);
6608 sljit_free_compiler(compiler
);
6610 FAILED(code
.func0() != 3, "test67 case 1 failed\n");
6612 sljit_free_code(code
.code
, NULL
);
6616 static void test68(void)
6618 /* Test skipping returns from fast calls (return type is normal). */
6619 executable_code code
;
6620 struct sljit_compiler
*compiler
;
6621 struct sljit_jump
*call
, *jump
;
6622 struct sljit_label
*label
;
6626 printf("Run test68\n");
6628 for (i
= 0; i
< 6; i
++) {
6629 compiler
= sljit_create_compiler(NULL
, NULL
);
6630 FAILED(!compiler
, "cannot create compiler\n");
6632 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), 2 + (i
% 6), (i
% 6), 0, 0, 0);
6634 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
6635 call
= sljit_emit_jump(compiler
, SLJIT_FAST_CALL
);
6637 /* Should never return here, marked by a segmentation fault if it does. */
6638 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
6640 /* Recursive fast call. */
6641 label
= sljit_emit_label(compiler
);
6642 sljit_set_label(call
, label
);
6643 sljit_emit_fast_enter(compiler
, SLJIT_R1
, 0);
6645 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
6647 jump
= sljit_emit_cmp(compiler
, SLJIT_GREATER_EQUAL
, SLJIT_R0
, 0, SLJIT_IMM
, 4);
6649 sljit_set_label(sljit_emit_jump(compiler
, SLJIT_FAST_CALL
), label
);
6651 sljit_set_label(jump
, sljit_emit_label(compiler
));
6652 sljit_emit_op0(compiler
, SLJIT_SKIP_FRAMES_BEFORE_RETURN
);
6653 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
6655 code
.code
= sljit_generate_code(compiler
);
6658 sljit_free_compiler(compiler
);
6660 if (SLJIT_UNLIKELY(code
.func0() != 4)) {
6661 printf("test68 case %d failed\n", i
+ 1);
6664 sljit_free_code(code
.code
, NULL
);
6670 static void test69(void)
6672 /* Test sljit_set_current_flags. */
6673 executable_code code
;
6674 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6679 printf("Run test69\n");
6681 for (i
= 0; i
< 8; i
++)
6684 FAILED(!compiler
, "cannot create compiler\n");
6686 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 3, 1, 0, 0, 0);
6688 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)1 << ((sizeof (sljit_sw
) * 8) - 2));
6689 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_R0
, 0);
6690 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
6691 sljit_emit_label(compiler
);
6692 sljit_set_current_flags(compiler
, SLJIT_SET_OVERFLOW
| SLJIT_CURRENT_FLAGS_ADD
);
6693 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_OVERFLOW
);
6695 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
6696 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
6697 sljit_emit_label(compiler
);
6698 sljit_set_current_flags(compiler
, SLJIT_SET_OVERFLOW
| SLJIT_CURRENT_FLAGS_ADD
);
6699 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_OVERFLOW
);
6701 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_R0
, 0);
6702 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
6703 sljit_emit_label(compiler
);
6704 sljit_set_current_flags(compiler
, SLJIT_SET_OVERFLOW
);
6705 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
6707 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 5);
6708 sljit_emit_op2(compiler
, SLJIT_MUL
| SLJIT_SET_OVERFLOW
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R1
, 0);
6709 sljit_emit_label(compiler
);
6710 sljit_set_current_flags(compiler
, SLJIT_SET_OVERFLOW
);
6711 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_OVERFLOW
);
6713 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 6);
6714 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 5);
6715 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_GREATER
, SLJIT_R1
, 0, SLJIT_R2
, 0);
6716 sljit_emit_label(compiler
);
6717 sljit_set_current_flags(compiler
, SLJIT_SET_GREATER
| SLJIT_CURRENT_FLAGS_SUB
| SLJIT_CURRENT_FLAGS_COMPARE
);
6718 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_GREATER
);
6720 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R2
, 0);
6721 sljit_emit_label(compiler
);
6722 sljit_set_current_flags(compiler
, SLJIT_SET_Z
| SLJIT_CURRENT_FLAGS_SUB
| SLJIT_CURRENT_FLAGS_COMPARE
);
6723 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_ZERO
);
6725 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)(1u << 31));
6726 sljit_emit_op2u(compiler
, SLJIT_ADD32
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_R1
, 0);
6727 sljit_emit_label(compiler
);
6728 sljit_set_current_flags(compiler
, SLJIT_SET_Z
| SLJIT_CURRENT_FLAGS_32
| SLJIT_CURRENT_FLAGS_ADD
);
6729 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_ZERO
);
6731 sljit_emit_op2u(compiler
, SLJIT_SHL32
| SLJIT_SET_Z
, SLJIT_R1
, 0, SLJIT_IMM
, 1);
6732 sljit_emit_label(compiler
);
6733 sljit_set_current_flags(compiler
, SLJIT_SET_Z
| SLJIT_CURRENT_FLAGS_32
);
6734 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_NOT_ZERO
);
6736 sljit_emit_return_void(compiler
);
6738 code
.code
= sljit_generate_code(compiler
);
6740 sljit_free_compiler(compiler
);
6742 code
.func1((sljit_sw
)&buf
);
6744 FAILED(buf
[0] != 1, "test69 case 1 failed\n");
6745 FAILED(buf
[1] != 2, "test69 case 2 failed\n");
6746 FAILED(buf
[2] != 1, "test69 case 3 failed\n");
6747 FAILED(buf
[3] != 2, "test69 case 4 failed\n");
6748 FAILED(buf
[4] != 1, "test69 case 5 failed\n");
6749 FAILED(buf
[5] != 2, "test69 case 6 failed\n");
6750 FAILED(buf
[6] != 1, "test69 case 7 failed\n");
6751 FAILED(buf
[7] != 2, "test69 case 8 failed\n");
6753 sljit_free_code(code
.code
, NULL
);
6757 static void test70(void)
6759 /* Test argument passing to sljit_emit_enter. */
6760 executable_code code
;
6761 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
6768 printf("Run test70\n");
6775 FAILED(!compiler
, "cannot create compiler\n");
6777 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, 32, W
, 32, W
), 1, 4, 0, 0, 0);
6778 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
6779 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S1
, 0);
6780 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_S3
, 0);
6781 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
6782 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
6783 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_s32
), SLJIT_S2
, 0);
6784 sljit_emit_return_void(compiler
);
6786 code
.code
= sljit_generate_code(compiler
);
6788 sljit_free_compiler(compiler
);
6790 code
.test70_f1(-1478, 9476, 4928, -6832);
6792 FAILED(wbuf
[0] != 9476, "test70 case 1 failed\n");
6793 FAILED(wbuf
[1] != -6832, "test70 case 2 failed\n");
6794 FAILED(ibuf
[0] != -1478, "test70 case 3 failed\n");
6795 FAILED(ibuf
[1] != 4928, "test70 case 4 failed\n");
6797 sljit_free_code(code
.code
, NULL
);
6799 compiler
= sljit_create_compiler(NULL
, NULL
);
6800 FAILED(!compiler
, "cannot create compiler\n");
6802 sljit_emit_enter(compiler
, SLJIT_ENTER_CDECL
, SLJIT_ARGS4(VOID
, 32, 32, W
, W
), 1, 4, 0, 0, 0);
6803 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
6804 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
6805 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_S1
, 0);
6806 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
6807 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S2
, 0);
6808 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_s32
), SLJIT_S3
, 0);
6809 sljit_emit_return_void(compiler
);
6811 code
.code
= sljit_generate_code(compiler
);
6813 sljit_free_compiler(compiler
);
6815 code
.test70_f2(4721, 7892, -3579, -4830);
6817 FAILED(wbuf
[0] != 4721, "test70 case 5 failed\n");
6818 FAILED(wbuf
[1] != 7892, "test70 case 6 failed\n");
6819 FAILED(ibuf
[0] != -3579, "test70 case 7 failed\n");
6820 FAILED(ibuf
[1] != -4830, "test70 case 8 failed\n");
6822 sljit_free_code(code
.code
, NULL
);
6824 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
6830 compiler
= sljit_create_compiler(NULL
, NULL
);
6831 FAILED(!compiler
, "cannot create compiler\n");
6833 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, 32, F32
, W
, F64
), 2, 2, 2, 0, 0);
6834 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)&wbuf
, SLJIT_S1
, 0);
6835 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&ibuf
, SLJIT_S0
, 0);
6836 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&dbuf
, SLJIT_FR1
, 0);
6837 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM0(), (sljit_sw
)&fbuf
, SLJIT_FR0
, 0);
6838 sljit_emit_return_void(compiler
);
6840 code
.code
= sljit_generate_code(compiler
);
6842 sljit_free_compiler(compiler
);
6844 code
.test70_f3(-6834, 674.5, 2789, -895.25);
6846 FAILED(wbuf
[0] != 2789, "test70 case 9 failed\n");
6847 FAILED(ibuf
[0] != -6834, "test70 case 10 failed\n");
6848 FAILED(dbuf
[0] != -895.25, "test70 case 11 failed\n");
6849 FAILED(fbuf
[0] != 674.5, "test70 case 12 failed\n");
6856 compiler
= sljit_create_compiler(NULL
, NULL
);
6857 FAILED(!compiler
, "cannot create compiler\n");
6859 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F32
, F64
, F32
, 32), 1, 1, 3, 0, 0);
6860 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&ibuf
, SLJIT_S0
, 0);
6861 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&dbuf
, SLJIT_FR1
, 0);
6862 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&fbuf
);
6863 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
6864 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f32
), SLJIT_FR2
, 0);
6865 sljit_emit_return_void(compiler
);
6867 code
.code
= sljit_generate_code(compiler
);
6869 sljit_free_compiler(compiler
);
6871 code
.test70_f4(-4712.5, 5342.25, 2904.25, -4607);
6873 FAILED(ibuf
[0] != -4607, "test70 case 13 failed\n");
6874 FAILED(dbuf
[0] != 5342.25, "test70 case 14 failed\n");
6875 FAILED(fbuf
[0] != -4712.5, "test70 case 15 failed\n");
6876 FAILED(fbuf
[1] != 2904.25, "test70 case 16 failed\n");
6883 compiler
= sljit_create_compiler(NULL
, NULL
);
6884 FAILED(!compiler
, "cannot create compiler\n");
6886 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, F32
, 32, F32
), 1, 1, 3, 0, 0);
6887 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&ibuf
, SLJIT_S0
, 0);
6888 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM0(), (sljit_sw
)&dbuf
, SLJIT_FR0
, 0);
6889 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&fbuf
);
6890 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR1
, 0);
6891 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f32
), SLJIT_FR2
, 0);
6893 sljit_emit_return_void(compiler
);
6895 code
.code
= sljit_generate_code(compiler
);
6897 sljit_free_compiler(compiler
);
6899 code
.test70_f5(3578.5, 4619.25, 6859, -1807.75);
6901 FAILED(ibuf
[0] != 6859, "test70 case 17 failed\n");
6902 FAILED(dbuf
[0] != 3578.5, "test70 case 18 failed\n");
6903 FAILED(fbuf
[0] != 4619.25, "test70 case 19 failed\n");
6904 FAILED(fbuf
[1] != -1807.75, "test70 case 20 failed\n");
6911 compiler
= sljit_create_compiler(NULL
, NULL
);
6912 FAILED(!compiler
, "cannot create compiler\n");
6914 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, 32, F32
, F64
), SLJIT_NUMBER_OF_SCRATCH_REGISTERS
+ 2, 1, 3, 0, 33);
6915 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&ibuf
, SLJIT_S0
, 0);
6916 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
6917 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
6918 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
), SLJIT_FR2
, 0);
6919 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM0(), (sljit_sw
)&fbuf
, SLJIT_FR1
, 0);
6920 sljit_emit_return_void(compiler
);
6922 code
.code
= sljit_generate_code(compiler
);
6924 sljit_free_compiler(compiler
);
6926 code
.test70_f6(2740.75, -2651, -7909.25, 3671.5);
6928 FAILED(ibuf
[0] != -2651, "test70 case 21 failed\n");
6929 FAILED(dbuf
[0] != 2740.75, "test70 case 22 failed\n");
6930 FAILED(dbuf
[1] != 3671.5, "test70 case 23 failed\n");
6931 FAILED(fbuf
[0] != -7909.25, "test70 case 24 failed\n");
6938 compiler
= sljit_create_compiler(NULL
, NULL
);
6939 FAILED(!compiler
, "cannot create compiler\n");
6941 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F32
, 32, W
, 32), 1, 3, 1, 0, 1);
6942 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)&wbuf
, SLJIT_S1
, 0);
6943 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
6944 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
6945 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_s32
), SLJIT_S2
, 0);
6946 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM0(), (sljit_sw
)&fbuf
, SLJIT_FR0
, 0);
6947 sljit_emit_return_void(compiler
);
6949 code
.code
= sljit_generate_code(compiler
);
6951 sljit_free_compiler(compiler
);
6953 code
.test70_f7(-5219.25, -4530, 7214, 6741);
6955 FAILED(wbuf
[0] != 7214, "test70 case 25 failed\n");
6956 FAILED(ibuf
[0] != -4530, "test70 case 26 failed\n");
6957 FAILED(ibuf
[1] != 6741, "test70 case 27 failed\n");
6958 FAILED(fbuf
[0] != -5219.25, "test70 case 28 failed\n");
6965 compiler
= sljit_create_compiler(NULL
, NULL
);
6966 FAILED(!compiler
, "cannot create compiler\n");
6968 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, F64
, W
, W
), 1, 5, 2, 0, SLJIT_MAX_LOCAL_SIZE
- 1);
6969 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_S0
, 0);
6970 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_SP
), SLJIT_MAX_LOCAL_SIZE
- 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
6971 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
6972 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
6973 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_S1
, 0);
6974 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
6975 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
6976 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
), SLJIT_FR1
, 0);
6977 sljit_emit_return_void(compiler
);
6979 code
.code
= sljit_generate_code(compiler
);
6981 sljit_free_compiler(compiler
);
6983 code
.test70_f8(-3749.75, 5280.5, 9134, -6506);
6985 FAILED(wbuf
[0] != 9134, "test70 case 29 failed\n");
6986 FAILED(wbuf
[1] != -6506, "test70 case 30 failed\n");
6987 FAILED(dbuf
[0] != -3749.75, "test70 case 31 failed\n");
6988 FAILED(dbuf
[1] != 5280.5, "test70 case 32 failed\n");
6995 compiler
= sljit_create_compiler(NULL
, NULL
);
6996 FAILED(!compiler
, "cannot create compiler\n");
6998 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, F64
, W
, F64
), 1, 1, 3, 0, SLJIT_MAX_LOCAL_SIZE
);
6999 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)&wbuf
, SLJIT_S0
, 0);
7000 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
7001 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
7002 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
), SLJIT_FR1
, 0);
7003 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
7005 sljit_emit_return_void(compiler
);
7007 code
.code
= sljit_generate_code(compiler
);
7009 sljit_free_compiler(compiler
);
7011 code
.test70_f9(-6049.25, 7301.5, 4610, -4312.75);
7013 FAILED(wbuf
[0] != 4610, "test70 case 33 failed\n");
7014 FAILED(dbuf
[0] != -6049.25, "test70 case 34 failed\n");
7015 FAILED(dbuf
[1] != 7301.5, "test70 case 35 failed\n");
7016 FAILED(dbuf
[2] != -4312.75, "test70 case 36 failed\n");
7023 compiler
= sljit_create_compiler(NULL
, NULL
);
7024 FAILED(!compiler
, "cannot create compiler\n");
7026 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, F64
, F64
, 32), 1, 1, 3, 0, 0);
7027 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM0(), (sljit_sw
)&ibuf
, SLJIT_S0
, 0);
7028 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
7029 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
7030 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
), SLJIT_FR1
, 0);
7031 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
7033 sljit_emit_return_void(compiler
);
7035 code
.code
= sljit_generate_code(compiler
);
7037 sljit_free_compiler(compiler
);
7039 code
.test70_f10(4810.5, -9148.75, 8601.25, 6703);
7041 FAILED(ibuf
[0] != 6703, "test70 case 37 failed\n");
7042 FAILED(dbuf
[0] != 4810.5, "test70 case 38 failed\n");
7043 FAILED(dbuf
[1] != -9148.75, "test70 case 39 failed\n");
7044 FAILED(dbuf
[2] != 8601.25, "test70 case 40 failed\n");
7050 #if !(defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
7052 static sljit_sw SLJIT_FUNC
test71_f1(sljit_sw a
)
7057 static sljit_sw SLJIT_FUNC
test71_f2(sljit_sw a
, sljit_s32 b
, sljit_s32 c
, sljit_sw d
)
7059 return a
| b
| c
| d
;
7062 static sljit_sw
test71_f3(sljit_sw a
, sljit_s32 b
, sljit_s32 c
, sljit_sw d
)
7064 return a
| b
| c
| d
;
7067 static sljit_sw
test71_f4(sljit_sw a
, sljit_s32 b
, sljit_s32 c
, sljit_sw d
)
7069 SLJIT_UNUSED_ARG(a
);
7073 static sljit_sw
test71_f5(void)
7078 static sljit_sw SLJIT_FUNC
test71_f6(sljit_f64 a
, sljit_f64 b
, sljit_f64 c
, sljit_f64 d
)
7080 if (a
== 1345.5 && b
== -8724.25 && c
== 9034.75 && d
== 6307.5)
7085 static sljit_sw SLJIT_FUNC
test71_f7(sljit_f64 a
, sljit_f64 b
, sljit_f64 c
, sljit_sw d
)
7087 if (a
== 4061.25 && b
== -3291.75 && c
== 8703.5 && d
== 1706)
7092 #endif /* !SLJIT_CONFIG_SPARC */
7094 static void test71(void)
7096 #if !(defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
7097 /* Test tail calls. */
7098 executable_code code
;
7099 struct sljit_compiler
* compiler
;
7100 struct sljit_jump
*jump
;
7102 sljit_sw executable_offset
;
7107 printf("Run test71\n");
7111 compiler
= sljit_create_compiler(NULL
, NULL
);
7112 FAILED(!compiler
, "cannot create compiler\n");
7114 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, W
), 4, 4, 0, 0, 0);
7115 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
7116 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0);
7117 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0);
7118 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0);
7119 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -1);
7120 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1);
7121 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1);
7122 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, -1);
7123 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS1(W
, W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f1
));
7125 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7127 code
.code
= sljit_generate_code(compiler
);
7129 sljit_free_compiler(compiler
);
7131 FAILED(code
.func1(7987) != 17987, "test71 case 1 failed\n");
7135 compiler
= sljit_create_compiler(NULL
, NULL
);
7136 FAILED(!compiler
, "cannot create compiler\n");
7138 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(W
, W
), 1, 4, 0, 0, 0);
7139 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
7140 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -1);
7141 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1);
7142 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1);
7143 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, -1);
7144 jump
= sljit_emit_call(compiler
, SLJIT_CALL
| SLJIT_REWRITABLE_JUMP
| SLJIT_CALL_RETURN
, SLJIT_ARGS1(W
, W
));
7145 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7147 sljit_set_target(jump
, 0);
7149 code
.code
= sljit_generate_code(compiler
);
7152 executable_offset
= sljit_get_executable_offset(compiler
);
7153 jump_addr
= sljit_get_jump_addr(jump
);
7154 sljit_free_compiler(compiler
);
7156 sljit_set_jump_addr(jump_addr
, SLJIT_FUNC_UADDR(test71_f1
), executable_offset
);
7158 FAILED(code
.func1(3903) != 13903, "test71 case 2 failed\n");
7162 compiler
= sljit_create_compiler(NULL
, NULL
);
7163 FAILED(!compiler
, "cannot create compiler\n");
7165 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), 4, 2, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
7166 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_SP
), 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f2
));
7167 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x28000000);
7168 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0x00140000);
7169 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_IMM
, 0x00002800);
7170 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x00000041);
7171 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -1);
7172 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1);
7173 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, W
, 32, 32, W
), SLJIT_MEM1(SLJIT_SP
), 0);
7174 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7176 code
.code
= sljit_generate_code(compiler
);
7178 sljit_free_compiler(compiler
);
7180 FAILED(code
.func0() != 0x28142841, "test71 case 3 failed\n");
7184 compiler
= sljit_create_compiler(NULL
, NULL
);
7185 FAILED(!compiler
, "cannot create compiler\n");
7187 sljit_emit_enter(compiler
, SLJIT_ENTER_CDECL
, SLJIT_ARGS4(W
, W
, 32, 32, W
), 4, 4, 0, 0, 9);
7188 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
7189 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_S1
, 0);
7190 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_S2
, 0);
7191 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_S3
, 0);
7192 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, W
, 32, 32, W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f2
));
7193 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7195 code
.code
= sljit_generate_code(compiler
);
7197 sljit_free_compiler(compiler
);
7199 FAILED(code
.test71_f1(0x650000, 0x13, 0x8400, 0x29000000) != 0x29658413, "test71 case 4 failed\n");
7201 sljit_free_code(code
.code
, NULL
);
7205 compiler
= sljit_create_compiler(NULL
, NULL
);
7206 FAILED(!compiler
, "cannot create compiler\n");
7208 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), 4, 4, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
7209 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f2
));
7210 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)0x81000000);
7211 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0x00480000);
7212 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_IMM
, 0x00002100);
7213 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x00000014);
7214 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -1);
7215 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1);
7216 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1);
7217 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, W
, 32, 32, W
), SLJIT_S3
, 0);
7218 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7220 code
.code
= sljit_generate_code(compiler
);
7222 sljit_free_compiler(compiler
);
7224 FAILED(code
.func0() != (sljit_sw
)0x81482114, "test71 case 5 failed\n");
7226 sljit_free_code(code
.code
, NULL
);
7230 compiler
= sljit_create_compiler(NULL
, NULL
);
7231 FAILED(!compiler
, "cannot create compiler\n");
7233 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(W
, W
, W
, W
), 4, 4, 0, 0, 0);
7234 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S0
, 0);
7235 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_S1
, 0);
7236 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_S2
, 0);
7237 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x48000000);
7238 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -1);
7239 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1);
7240 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1);
7241 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S3
, 0, SLJIT_IMM
, -1);
7242 sljit_emit_icall(compiler
, SLJIT_CALL_CDECL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, W
, 32, 32, W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f3
));
7243 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7245 code
.code
= sljit_generate_code(compiler
);
7247 sljit_free_compiler(compiler
);
7249 FAILED(code
.func3(0x12, 0x8800, 0x240000) != 0x48248812, "test71 case 6 failed\n");
7251 sljit_free_code(code
.code
, NULL
);
7255 compiler
= sljit_create_compiler(NULL
, NULL
);
7256 FAILED(!compiler
, "cannot create compiler\n");
7258 sljit_emit_enter(compiler
, SLJIT_ENTER_CDECL
, SLJIT_ARGS0(W
), 4, 0, 0, 0, 0);
7259 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f4
));
7260 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R1
, 0, SLJIT_IMM
, 0x342);
7261 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R2
, 0, SLJIT_IMM
, 0x451000);
7262 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x21000000);
7263 sljit_emit_icall(compiler
, SLJIT_CALL_CDECL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, W
, 32, 32, W
), SLJIT_R0
, 0);
7264 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7266 code
.code
= sljit_generate_code(compiler
);
7268 sljit_free_compiler(compiler
);
7270 FAILED(code
.func0() != 0x21451342, "test71 case 7 failed\n");
7272 sljit_free_code(code
.code
, NULL
);
7276 compiler
= sljit_create_compiler(NULL
, NULL
);
7277 FAILED(!compiler
, "cannot create compiler\n");
7279 sljit_emit_enter(compiler
, SLJIT_ENTER_CDECL
, SLJIT_ARGS0(W
), 1, 0, 0, 0, 9);
7280 sljit_emit_icall(compiler
, SLJIT_CALL_CDECL
| SLJIT_CALL_RETURN
, SLJIT_ARGS0(W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f5
));
7281 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7283 code
.code
= sljit_generate_code(compiler
);
7285 sljit_free_compiler(compiler
);
7287 FAILED(code
.func0() != 7461932, "test71 case 8 failed\n");
7289 sljit_free_code(code
.code
, NULL
);
7291 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
7297 compiler
= sljit_create_compiler(NULL
, NULL
);
7298 FAILED(!compiler
, "cannot create compiler\n");
7300 sljit_emit_enter(compiler
, SLJIT_ENTER_CDECL
, SLJIT_ARGS2(W
, F64
, F64
), 1, 1, 4, 0, 0);
7301 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
7302 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_R0
), 0);
7303 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
));
7304 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, F64
, F64
, F64
, F64
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f6
));
7305 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7307 code
.code
= sljit_generate_code(compiler
);
7309 sljit_free_compiler(compiler
);
7311 FAILED(code
.test71_f2(1345.5, -8724.25) != 8920567, "test71 case 9 failed\n");
7313 sljit_free_code(code
.code
, NULL
);
7317 wbuf
[0] = SLJIT_FUNC_ADDR(test71_f6
);
7319 compiler
= sljit_create_compiler(NULL
, NULL
);
7320 FAILED(!compiler
, "cannot create compiler\n");
7322 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(W
, F64
, F64
, F64
, F64
), 1, 0, 4, 0, 0);
7323 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, F64
, F64
, F64
, F64
), SLJIT_MEM0(), (sljit_sw
)wbuf
);
7324 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7326 code
.code
= sljit_generate_code(compiler
);
7328 sljit_free_compiler(compiler
);
7330 FAILED(code
.test71_f3(1345.5, -8724.25, 9034.75, 6307.5) != 8920567, "test71 case 10 failed\n");
7332 sljit_free_code(code
.code
, NULL
);
7336 compiler
= sljit_create_compiler(NULL
, NULL
);
7337 FAILED(!compiler
, "cannot create compiler\n");
7339 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(W
, F64
, F64
, F64
), 1, 0, 4, 0, 0);
7340 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1706);
7341 jump
= sljit_emit_call(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, F64
, F64
, F64
, W
));
7342 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7344 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test71_f7
));
7346 code
.code
= sljit_generate_code(compiler
);
7348 sljit_free_compiler(compiler
);
7350 FAILED(code
.test71_f4(4061.25, -3291.75, 8703.5) != 5074526, "test71 case 11 failed\n");
7352 sljit_free_code(code
.code
, NULL
);
7356 compiler
= sljit_create_compiler(NULL
, NULL
);
7357 FAILED(!compiler
, "cannot create compiler\n");
7359 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(W
, F64
, F64
, F64
), SLJIT_NUMBER_OF_SCRATCH_REGISTERS
+ 1, 0, 4, 0, 0);
7360 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1706);
7361 jump
= sljit_emit_call(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, F64
, F64
, F64
, W
));
7362 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7364 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test71_f7
));
7366 code
.code
= sljit_generate_code(compiler
);
7368 sljit_free_compiler(compiler
);
7370 FAILED(code
.test71_f4(4061.25, -3291.75, 8703.5) != 5074526, "test71 case 12 failed\n");
7372 sljit_free_code(code
.code
, NULL
);
7376 compiler
= sljit_create_compiler(NULL
, NULL
);
7377 FAILED(!compiler
, "cannot create compiler\n");
7379 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(W
, F64
, F64
, F64
), SLJIT_NUMBER_OF_SCRATCH_REGISTERS
+ 1, 1, 3, 0, SLJIT_MAX_LOCAL_SIZE
);
7380 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1706);
7381 jump
= sljit_emit_call(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, F64
, F64
, F64
, W
));
7382 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
7384 sljit_set_target(jump
, SLJIT_FUNC_UADDR(test71_f7
));
7386 code
.code
= sljit_generate_code(compiler
);
7388 sljit_free_compiler(compiler
);
7390 FAILED(code
.test71_f4(4061.25, -3291.75, 8703.5) != 5074526, "test71 case 13 failed\n");
7392 sljit_free_code(code
.code
, NULL
);
7394 #endif /* !SLJIT_CONFIG_SPARC */
7399 static void test72(void)
7401 /* Test using all fpu registers. */
7402 executable_code code
;
7403 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
7404 sljit_f64 buf
[SLJIT_NUMBER_OF_FLOAT_REGISTERS
];
7406 struct sljit_jump
*jump
;
7410 printf("Run test72\n");
7412 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
7414 printf("no fpu available, test72 skipped\n");
7417 sljit_free_compiler(compiler
);
7422 FAILED(!compiler
, "cannot create compiler\n");
7427 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
7430 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 1, 2, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0, 0);
7431 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
7432 for (i
= 1; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
7433 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_FR0
, 0);
7435 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S1
, 0);
7436 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS1(VOID
, W
));
7438 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
7439 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), i
* (sljit_sw
)sizeof(sljit_f64
), SLJIT_FR(i
), 0);
7440 sljit_emit_return_void(compiler
);
7442 /* Called function. */
7443 sljit_set_label(jump
, sljit_emit_label(compiler
));
7444 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 0, 1, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0, 0);
7446 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
7447 for (i
= 1; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
7448 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_FR0
, 0);
7450 sljit_set_context(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 0, 1, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0, 0);
7451 sljit_emit_return_void(compiler
);
7453 code
.code
= sljit_generate_code(compiler
);
7455 sljit_free_compiler(compiler
);
7457 code
.func2((sljit_sw
)buf
, (sljit_sw
)buf2
);
7459 for (i
= 0; i
< SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
; i
++) {
7460 FAILED(buf
[i
] != -8.25, "test72 case 1 failed\n");
7463 for (i
= SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++) {
7464 FAILED(buf
[i
] != 7.75, "test72 case 2 failed\n");
7467 sljit_free_code(code
.code
, NULL
);
7470 if (SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS
>= 3) {
7471 compiler
= sljit_create_compiler(NULL
, NULL
);
7472 FAILED(!compiler
, "cannot create compiler\n");
7477 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
7480 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 1, 2, SLJIT_NUMBER_OF_FLOAT_REGISTERS
- 2, 1, SLJIT_MAX_LOCAL_SIZE
);
7481 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FS0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
7482 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
- 2; i
++)
7483 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_FS0
, 0);
7485 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_S1
, 0);
7486 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS1(VOID
, W
));
7488 for (i
= 0; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
- 2; i
++)
7489 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), i
* (sljit_sw
)sizeof(sljit_f64
), SLJIT_FR(i
), 0);
7490 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);
7491 sljit_emit_return_void(compiler
);
7493 /* Called function. */
7494 sljit_set_label(jump
, sljit_emit_label(compiler
));
7495 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 0, 1, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0, SLJIT_MAX_LOCAL_SIZE
);
7497 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
));
7498 for (i
= 1; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
; i
++)
7499 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR(i
), 0, SLJIT_FR0
, 0);
7501 sljit_set_context(compiler
, 0, SLJIT_ARGS1(VOID
, P
), 0, 1, SLJIT_NUMBER_OF_FLOAT_REGISTERS
, 0, SLJIT_MAX_LOCAL_SIZE
);
7502 sljit_emit_return_void(compiler
);
7504 code
.code
= sljit_generate_code(compiler
);
7506 sljit_free_compiler(compiler
);
7508 code
.func2((sljit_sw
)buf
, (sljit_sw
)buf2
);
7510 for (i
= 0; i
< SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
; i
++) {
7511 FAILED(buf
[i
] != 3.75, "test72 case 3 failed\n");
7514 for (i
= SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS
; i
< SLJIT_NUMBER_OF_FLOAT_REGISTERS
- 2; i
++) {
7515 FAILED(buf
[i
] != -6.25, "test72 case 4 failed\n");
7518 FAILED(buf
[SLJIT_NUMBER_OF_FLOAT_REGISTERS
- 2] != 0, "test72 case 5 failed\n");
7519 FAILED(buf
[SLJIT_NUMBER_OF_FLOAT_REGISTERS
- 1] != -6.25, "test72 case 6 failed\n");
7521 sljit_free_code(code
.code
, NULL
);
7526 static void test73(void)
7528 /* Test tail calls. */
7529 executable_code code
;
7530 struct sljit_compiler
* compiler
;
7536 printf("Run test73\n");
7540 compiler
= sljit_create_compiler(NULL
, NULL
);
7541 FAILED(!compiler
, "cannot create compiler\n");
7543 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, 32_R
, W
, W_R
, 32), 3, 2, 0, 0, 0);
7544 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
7545 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0, SLJIT_S0
, 0);
7546 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_sw
), SLJIT_R2
, 0);
7547 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
7548 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R1
), 0, SLJIT_R0
, 0);
7549 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_s32
), SLJIT_S1
, 0);
7550 sljit_emit_return_void(compiler
);
7552 code
.code
= sljit_generate_code(compiler
);
7554 sljit_free_compiler(compiler
);
7556 code
.test73_f1(3467, -6781, 5038, 6310);
7558 FAILED(wbuf
[0] != -6781, "test73 case 1 failed\n");
7559 FAILED(wbuf
[1] != 5038, "test73 case 2 failed\n");
7560 FAILED(ibuf
[0] != 3467, "test73 case 3 failed\n");
7561 FAILED(ibuf
[1] != 6310, "test73 case 4 failed\n");
7562 sljit_free_code(code
.code
, NULL
);
7566 compiler
= sljit_create_compiler(NULL
, NULL
);
7567 FAILED(!compiler
, "cannot create compiler\n");
7569 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, 32, W_R
, W
, 32_R
), 4, 2, 0, 0, 8192);
7570 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
7571 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_R1
, 0);
7572 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_S1
, 0);
7573 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
7574 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
7575 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_s32
), SLJIT_R3
, 0);
7576 sljit_emit_return_void(compiler
);
7578 code
.code
= sljit_generate_code(compiler
);
7580 sljit_free_compiler(compiler
);
7582 code
.test73_f1(-9723, 5208, 4761, 5084);
7584 FAILED(wbuf
[0] != 5208, "test73 case 5 failed\n");
7585 FAILED(wbuf
[1] != 4761, "test73 case 6 failed\n");
7586 FAILED(ibuf
[0] != -9723, "test73 case 7 failed\n");
7587 FAILED(ibuf
[1] != 5084, "test73 case 8 failed\n");
7588 sljit_free_code(code
.code
, NULL
);
7592 compiler
= sljit_create_compiler(NULL
, NULL
);
7593 FAILED(!compiler
, "cannot create compiler\n");
7595 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, 32_R
, W_R
, W_R
, 32_R
), 4, 1, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
7596 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
7597 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
7598 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R2
, 0);
7599 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
7600 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
7601 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_s32
), SLJIT_R3
, 0);
7602 sljit_emit_return_void(compiler
);
7604 code
.code
= sljit_generate_code(compiler
);
7606 sljit_free_compiler(compiler
);
7608 code
.test73_f1(5934, 6043, -8572, -3861);
7610 FAILED(wbuf
[0] != 6043, "test73 case 9 failed\n");
7611 FAILED(wbuf
[1] != -8572, "test73 case 10 failed\n");
7612 FAILED(ibuf
[0] != 5934, "test73 case 11 failed\n");
7613 FAILED(ibuf
[1] != -3861, "test73 case 12 failed\n");
7614 sljit_free_code(code
.code
, NULL
);
7618 compiler
= sljit_create_compiler(NULL
, NULL
);
7619 FAILED(!compiler
, "cannot create compiler\n");
7621 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
);
7622 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
);
7623 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
7624 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
7625 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R1
, 0);
7626 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, (sljit_sw
)&ibuf
);
7627 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R2
, 0);
7628 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_s32
), SLJIT_R3
, 0);
7629 sljit_emit_return_void(compiler
);
7631 code
.code
= sljit_generate_code(compiler
);
7633 sljit_free_compiler(compiler
);
7635 code
.test73_f2(6732, -5916, 2740, -3621);
7637 FAILED(wbuf
[0] != 6732, "test73 case 13 failed\n");
7638 FAILED(wbuf
[1] != -5916, "test73 case 14 failed\n");
7639 FAILED(ibuf
[0] != 2740, "test73 case 15 failed\n");
7640 FAILED(ibuf
[1] != -3621, "test73 case 16 failed\n");
7641 sljit_free_code(code
.code
, NULL
);
7643 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
7646 compiler
= sljit_create_compiler(NULL
, NULL
);
7647 FAILED(!compiler
, "cannot create compiler\n");
7649 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, F64
, F64
, W_R
), 1, 0, 3, 0, SLJIT_MAX_LOCAL_SIZE
);
7650 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)&wbuf
, SLJIT_R0
, 0);
7651 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
7652 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
7653 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
), SLJIT_FR1
, 0);
7654 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_f64
), SLJIT_FR2
, 0);
7656 sljit_emit_return_void(compiler
);
7658 code
.code
= sljit_generate_code(compiler
);
7660 sljit_free_compiler(compiler
);
7662 code
.test73_f3(7390.25, -8045.5, 1390.75, 8201);
7664 FAILED(wbuf
[0] != 8201, "test73 case 17 failed\n");
7665 FAILED(dbuf
[0] != 7390.25, "test73 case 18 failed\n");
7666 FAILED(dbuf
[1] != -8045.5, "test73 case 19 failed\n");
7667 FAILED(dbuf
[2] != 1390.75, "test73 case 20 failed\n");
7671 compiler
= sljit_create_compiler(NULL
, NULL
);
7672 FAILED(!compiler
, "cannot create compiler\n");
7674 sljit_emit_enter(compiler
, 0, SLJIT_ARGS4(VOID
, F64
, F64
, W
, W_R
), 2, 1, 2, 0, SLJIT_MAX_LOCAL_SIZE
);
7675 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&wbuf
);
7676 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
7677 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_R1
, 0);
7678 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
7679 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR0
, 0);
7680 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
), SLJIT_FR1
, 0);
7682 sljit_emit_return_void(compiler
);
7684 code
.code
= sljit_generate_code(compiler
);
7686 sljit_free_compiler(compiler
);
7688 code
.test73_f4(4892.75, -3702.5, 4731, 8530);
7690 FAILED(wbuf
[0] != 4731, "test73 case 21 failed\n");
7691 FAILED(wbuf
[1] != 8530, "test73 case 22 failed\n");
7692 FAILED(dbuf
[0] != 4892.75, "test73 case 23 failed\n");
7693 FAILED(dbuf
[1] != -3702.5, "test73 case 24 failed\n");
7699 static void test74(void)
7701 /* Test carry flag. */
7702 executable_code code
;
7703 struct sljit_compiler
* compiler
;
7708 printf("Run test74\n");
7710 for (i
= 0; i
< 15; i
++)
7713 compiler
= sljit_create_compiler(NULL
, NULL
);
7714 FAILED(!compiler
, "cannot create compiler\n");
7716 sljit_emit_enter(compiler
, 0, SLJIT_ARGS1(VOID
, W
), 3, 2, 0, 0, 0);
7718 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
7719 sljit_emit_op2u(compiler
, SLJIT_ADD
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
7720 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_CARRY
);
7722 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R1
, 0);
7723 cond_set(compiler
, SLJIT_R1
, 0, SLJIT_CARRY
);
7725 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R1
, 0);
7727 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2);
7728 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -1);
7729 sljit_set_current_flags(compiler
, SLJIT_SET_CARRY
| SLJIT_CURRENT_FLAGS_ADD
);
7731 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_NOT_CARRY
);
7733 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
7734 sljit_emit_op2(compiler
, SLJIT_SHL32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 31);
7735 sljit_emit_op2u(compiler
, SLJIT_ADD32
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0);
7736 cond_set(compiler
, SLJIT_R1
, 0, SLJIT_CARRY
);
7738 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R1
, 0);
7740 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
7741 sljit_emit_op2(compiler
, SLJIT_ADD32
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 5);
7742 cond_set(compiler
, SLJIT_R1
, 0, SLJIT_CARRY
);
7744 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R1
, 0);
7746 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
7747 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
7748 cond_set(compiler
, SLJIT_R1
, 0, SLJIT_CARRY
);
7750 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R1
, 0);
7752 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
7753 sljit_emit_op2u(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
7754 cond_set(compiler
, SLJIT_R1
, 0, SLJIT_NOT_CARRY
);
7756 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R1
, 0);
7758 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
7759 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
7761 cond_set(compiler
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_CARRY
);
7763 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
7764 sljit_emit_op2u(compiler
, SLJIT_SUB32
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
7765 sljit_set_current_flags(compiler
, SLJIT_SET_CARRY
| SLJIT_CURRENT_FLAGS_32
| SLJIT_CURRENT_FLAGS_SUB
);
7766 cond_set(compiler
, SLJIT_R1
, 0, SLJIT_NOT_CARRY
);
7768 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R1
, 0);
7770 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
7771 sljit_emit_op2(compiler
, SLJIT_SHL32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 31);
7772 sljit_emit_op2(compiler
, SLJIT_SUB32
, SLJIT_R1
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
7773 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_CARRY
, SLJIT_R1
, 0, SLJIT_R1
, 0, SLJIT_R0
, 0);
7774 cond_set(compiler
, SLJIT_R1
, 0, SLJIT_NOT_CARRY
);
7776 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R1
, 0);
7778 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -1);
7779 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, -2);
7780 cond_set(compiler
, SLJIT_R1
, 0, SLJIT_NOT_CARRY
);
7782 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R1
, 0);
7784 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
7785 sljit_emit_op2(compiler
, SLJIT_ADD
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
7786 sljit_emit_op2(compiler
, SLJIT_ADDC
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R0
, 0);
7787 cond_set(compiler
, SLJIT_R1
, 0, SLJIT_CARRY
);
7789 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
), SLJIT_R1
, 0);
7791 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 1);
7792 sljit_emit_op2(compiler
, SLJIT_SHL32
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 31);
7793 sljit_emit_op2(compiler
, SLJIT_ADD32
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
7794 sljit_emit_op2(compiler
, SLJIT_ADDC32
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R0
, 0);
7795 cond_set(compiler
, SLJIT_R1
, 0, SLJIT_CARRY
);
7797 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
), SLJIT_R1
, 0);
7799 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
7800 sljit_emit_op2(compiler
, SLJIT_SUB
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 0);
7801 sljit_emit_op2(compiler
, SLJIT_SUBC
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
7802 cond_set(compiler
, SLJIT_R1
, 0, SLJIT_CARRY
);
7804 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 13 * sizeof(sljit_sw
), SLJIT_R1
, 0);
7806 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
7807 sljit_emit_op2(compiler
, SLJIT_SUB32
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
7808 sljit_emit_op2(compiler
, SLJIT_SUBC32
| SLJIT_SET_CARRY
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 1);
7809 cond_set(compiler
, SLJIT_R1
, 0, SLJIT_NOT_CARRY
);
7811 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 14 * sizeof(sljit_sw
), SLJIT_R1
, 0);
7813 sljit_emit_return_void(compiler
);
7815 code
.code
= sljit_generate_code(compiler
);
7817 sljit_free_compiler(compiler
);
7819 code
.func1((sljit_sw
)&wbuf
);
7821 FAILED(wbuf
[0] != 1, "test74 case 1 failed\n");
7822 FAILED(wbuf
[1] != 1, "test74 case 2 failed\n");
7823 FAILED(wbuf
[2] != 2, "test74 case 3 failed\n");
7824 FAILED(wbuf
[3] != 1, "test74 case 4 failed\n");
7825 FAILED(wbuf
[4] != 2, "test74 case 5 failed\n");
7826 FAILED(wbuf
[5] != 1, "test74 case 6 failed\n");
7827 FAILED(wbuf
[6] != 1, "test74 case 7 failed\n");
7828 FAILED(wbuf
[7] != 1, "test74 case 8 failed\n");
7829 FAILED(wbuf
[8] != 2, "test74 case 9 failed\n");
7830 FAILED(wbuf
[9] != 2, "test74 case 10 failed\n");
7831 FAILED(wbuf
[10] != 1, "test74 case 11 failed\n");
7832 FAILED(wbuf
[11] != 2, "test74 case 12 failed\n");
7833 FAILED(wbuf
[12] != 1, "test74 case 13 failed\n");
7834 FAILED(wbuf
[13] != 1, "test74 case 14 failed\n");
7835 FAILED(wbuf
[14] != 1, "test74 case 15 failed\n");
7840 static void test75_set(struct sljit_compiler
*compiler
, sljit_s32 compare
, sljit_s32 type
, sljit_s32 left_fr
, sljit_s32 right_fr
)
7842 /* Testing both sljit_emit_op_flags and sljit_emit_jump. */
7843 struct sljit_jump
* jump1
;
7844 struct sljit_jump
* jump2
;
7845 sljit_s32 is_ordered
;
7847 if (sljit_cmp_info(type
)) {
7848 sljit_emit_fop1(compiler
, compare
| SLJIT_SET(type
), left_fr
, 0, right_fr
, 0);
7849 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, type
);
7850 jump1
= sljit_emit_jump(compiler
, type
);
7851 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_IMM
, 2);
7852 sljit_set_label(jump1
, sljit_emit_label(compiler
));
7854 if (type
< SLJIT_UNORDERED_OR_EQUAL
) {
7855 is_ordered
= (type
& 0x1) ^ 0x1;
7856 type
+= SLJIT_UNORDERED_OR_EQUAL
- SLJIT_ORDERED_EQUAL
;
7858 is_ordered
= type
& 0x1;
7859 type
-= SLJIT_UNORDERED_OR_EQUAL
- SLJIT_ORDERED_EQUAL
;
7861 SLJIT_ASSERT(sljit_cmp_info(type
) && sljit_cmp_info(SLJIT_UNORDERED
) && sljit_cmp_info(SLJIT_ORDERED
));
7863 sljit_emit_fop1(compiler
, compare
| SLJIT_SET(type
), left_fr
, 0, right_fr
, 0);
7864 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, type
);
7865 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0);
7868 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_ORDERED
);
7870 jump1
= sljit_emit_jump(compiler
, SLJIT_UNORDERED
);
7871 jump2
= sljit_emit_jump(compiler
, type
);
7872 sljit_set_label(jump1
, sljit_emit_label(compiler
));
7873 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2);
7874 sljit_set_label(jump2
, sljit_emit_label(compiler
));
7876 sljit_emit_op2(compiler
, SLJIT_AND
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
7878 sljit_emit_op_flags(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_UNORDERED
);
7880 jump1
= sljit_emit_jump(compiler
, SLJIT_UNORDERED
);
7881 jump2
= sljit_emit_jump(compiler
, type
);
7882 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2);
7883 sljit_set_label(jump1
, sljit_emit_label(compiler
));
7884 sljit_set_label(jump2
, sljit_emit_label(compiler
));
7886 sljit_emit_op2(compiler
, SLJIT_OR
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R1
, 0);
7889 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_R0
, 0, SLJIT_R2
, 0);
7892 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_S0
), 0, SLJIT_R0
, 0);
7893 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_S0
, 0, SLJIT_S0
, 0, SLJIT_IMM
, sizeof(sljit_s8
));
7896 static void test75(void)
7898 /* Test floating point comparison. */
7899 executable_code code
;
7900 struct sljit_compiler
* compiler
;
7917 dbuf
[0].u
.value1
= 0x7fffffff;
7918 dbuf
[0].u
.value2
= 0x7fffffff;
7919 dbuf
[1].value
= -13.0;
7920 dbuf
[2].value
= 27.0;
7922 sbuf
[0].value1
= 0x7fffffff;
7923 sbuf
[1].value
= -13.0;
7924 sbuf
[2].value
= 27.0;
7927 printf("Run test75\n");
7929 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
7931 printf("no fpu available, test75 skipped\n");
7936 for (i
= 0; i
< 96; i
++)
7939 compiler
= sljit_create_compiler(NULL
, NULL
);
7940 FAILED(!compiler
, "cannot create compiler\n");
7942 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 3, 3, 6, 0, 0);
7945 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
7946 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
7947 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
));
7948 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f64
));
7949 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR4
, 0, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f64
));
7952 /* bbuf[0] and bbuf[48] */
7953 test75_set(compiler
, i
, SLJIT_ORDERED_EQUAL
, SLJIT_FR2
, SLJIT_FR3
);
7954 /* bbuf[1] and bbuf[49] */
7955 test75_set(compiler
, i
, SLJIT_ORDERED_EQUAL
, SLJIT_FR2
, SLJIT_FR4
);
7956 /* bbuf[2] and bbuf[50] */
7957 test75_set(compiler
, i
, SLJIT_ORDERED_EQUAL
, SLJIT_FR0
, SLJIT_FR1
);
7958 /* bbuf[3] and bbuf[51] */
7959 test75_set(compiler
, i
, SLJIT_ORDERED_EQUAL
, SLJIT_FR0
, SLJIT_FR2
);
7961 /* bbuf[4] and bbuf[52] */
7962 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_NOT_EQUAL
, SLJIT_FR2
, SLJIT_FR3
);
7963 /* bbuf[5] and bbuf[53] */
7964 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_NOT_EQUAL
, SLJIT_FR2
, SLJIT_FR4
);
7965 /* bbuf[6] and bbuf[54] */
7966 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_NOT_EQUAL
, SLJIT_FR0
, SLJIT_FR1
);
7967 /* bbuf[7] and bbuf[55] */
7968 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_NOT_EQUAL
, SLJIT_FR0
, SLJIT_FR2
);
7970 /* bbuf[8] and bbuf[56] */
7971 test75_set(compiler
, i
, SLJIT_ORDERED_LESS
, SLJIT_FR2
, SLJIT_FR3
);
7972 /* bbuf[9] and bbuf[57] */
7973 test75_set(compiler
, i
, SLJIT_ORDERED_LESS
, SLJIT_FR2
, SLJIT_FR4
);
7974 /* bbuf[10] and bbuf[58] */
7975 test75_set(compiler
, i
, SLJIT_ORDERED_LESS
, SLJIT_FR0
, SLJIT_FR1
);
7976 /* bbuf[11] and bbuf[59] */
7977 test75_set(compiler
, i
, SLJIT_ORDERED_LESS
, SLJIT_FR0
, SLJIT_FR2
);
7979 /* bbuf[12] and bbuf[60] */
7980 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_GREATER_EQUAL
, SLJIT_FR2
, SLJIT_FR4
);
7981 /* bbuf[13] and bbuf[61] */
7982 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_GREATER_EQUAL
, SLJIT_FR4
, SLJIT_FR2
);
7983 /* bbuf[14] and bbuf[62] */
7984 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_GREATER_EQUAL
, SLJIT_FR0
, SLJIT_FR1
);
7985 /* bbuf[15] and bbuf[63] */
7986 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_GREATER_EQUAL
, SLJIT_FR0
, SLJIT_FR2
);
7988 /* bbuf[16] and bbuf[64] */
7989 test75_set(compiler
, i
, SLJIT_ORDERED_GREATER
, SLJIT_FR2
, SLJIT_FR4
);
7990 /* bbuf[17] and bbuf[65] */
7991 test75_set(compiler
, i
, SLJIT_ORDERED_GREATER
, SLJIT_FR4
, SLJIT_FR2
);
7992 /* bbuf[18] and bbuf[66] */
7993 test75_set(compiler
, i
, SLJIT_ORDERED_GREATER
, SLJIT_FR0
, SLJIT_FR1
);
7994 /* bbuf[19] and bbuf[67] */
7995 test75_set(compiler
, i
, SLJIT_ORDERED_GREATER
, SLJIT_FR0
, SLJIT_FR2
);
7997 /* bbuf[20] and bbuf[68] */
7998 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_LESS_EQUAL
, SLJIT_FR2
, SLJIT_FR4
);
7999 /* bbuf[21] and bbuf[69] */
8000 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_LESS_EQUAL
, SLJIT_FR4
, SLJIT_FR2
);
8001 /* bbuf[22] and bbuf[70] */
8002 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_LESS_EQUAL
, SLJIT_FR0
, SLJIT_FR1
);
8003 /* bbuf[23] and bbuf[71] */
8004 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_LESS_EQUAL
, SLJIT_FR0
, SLJIT_FR2
);
8006 /* bbuf[24] and bbuf[72] */
8007 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_EQUAL
, SLJIT_FR2
, SLJIT_FR4
);
8008 /* bbuf[25] and bbuf[73] */
8009 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_EQUAL
, SLJIT_FR2
, SLJIT_FR3
);
8010 /* bbuf[26] and bbuf[74] */
8011 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_EQUAL
, SLJIT_FR0
, SLJIT_FR1
);
8012 /* bbuf[27] and bbuf[75] */
8013 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_EQUAL
, SLJIT_FR0
, SLJIT_FR2
);
8015 /* bbuf[28] and bbuf[76] */
8016 test75_set(compiler
, i
, SLJIT_ORDERED_NOT_EQUAL
, SLJIT_FR2
, SLJIT_FR3
);
8017 /* bbuf[29] and bbuf[77] */
8018 test75_set(compiler
, i
, SLJIT_ORDERED_NOT_EQUAL
, SLJIT_FR2
, SLJIT_FR4
);
8019 /* bbuf[30] and bbuf[78] */
8020 test75_set(compiler
, i
, SLJIT_ORDERED_NOT_EQUAL
, SLJIT_FR0
, SLJIT_FR1
);
8021 /* bbuf[31] and bbuf[79] */
8022 test75_set(compiler
, i
, SLJIT_ORDERED_NOT_EQUAL
, SLJIT_FR0
, SLJIT_FR2
);
8024 /* bbuf[32] and bbuf[80] */
8025 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_LESS
, SLJIT_FR2
, SLJIT_FR4
);
8026 /* bbuf[33] and bbuf[81] */
8027 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_LESS
, SLJIT_FR2
, SLJIT_FR3
);
8028 /* bbuf[34] and bbuf[82] */
8029 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_LESS
, SLJIT_FR0
, SLJIT_FR1
);
8030 /* bbuf[35] and bbuf[83] */
8031 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_LESS
, SLJIT_FR0
, SLJIT_FR2
);
8033 /* bbuf[36] and bbuf[84] */
8034 test75_set(compiler
, i
, SLJIT_ORDERED_GREATER_EQUAL
, SLJIT_FR2
, SLJIT_FR4
);
8035 /* bbuf[37] and bbuf[85] */
8036 test75_set(compiler
, i
, SLJIT_ORDERED_GREATER_EQUAL
, SLJIT_FR4
, SLJIT_FR2
);
8037 /* bbuf[38] and bbuf[86] */
8038 test75_set(compiler
, i
, SLJIT_ORDERED_GREATER_EQUAL
, SLJIT_FR0
, SLJIT_FR1
);
8039 /* bbuf[39] and bbuf[87] */
8040 test75_set(compiler
, i
, SLJIT_ORDERED_GREATER_EQUAL
, SLJIT_FR0
, SLJIT_FR2
);
8042 /* bbuf[40] and bbuf[88] */
8043 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_GREATER
, SLJIT_FR2
, SLJIT_FR4
);
8044 /* bbuf[41] and bbuf[89] */
8045 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_GREATER
, SLJIT_FR4
, SLJIT_FR2
);
8046 /* bbuf[42] and bbuf[90] */
8047 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_GREATER
, SLJIT_FR0
, SLJIT_FR1
);
8048 /* bbuf[43] and bbuf[91] */
8049 test75_set(compiler
, i
, SLJIT_UNORDERED_OR_GREATER
, SLJIT_FR0
, SLJIT_FR2
);
8051 /* bbuf[44] and bbuf[92] */
8052 test75_set(compiler
, i
, SLJIT_ORDERED_LESS_EQUAL
, SLJIT_FR2
, SLJIT_FR3
);
8053 /* bbuf[45] and bbuf[93] */
8054 test75_set(compiler
, i
, SLJIT_ORDERED_LESS_EQUAL
, SLJIT_FR4
, SLJIT_FR2
);
8055 /* bbuf[46] and bbuf[94] */
8056 test75_set(compiler
, i
, SLJIT_ORDERED_LESS_EQUAL
, SLJIT_FR0
, SLJIT_FR1
);
8057 /* bbuf[47] and bbuf[95] */
8058 test75_set(compiler
, i
, SLJIT_ORDERED_LESS_EQUAL
, SLJIT_FR0
, SLJIT_FR2
);
8060 if (i
== SLJIT_CMP_F32
)
8064 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S2
), 0);
8065 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_S2
), 0);
8066 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
8067 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR3
, 0, SLJIT_MEM1(SLJIT_S2
), sizeof(sljit_f32
));
8068 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR4
, 0, SLJIT_MEM1(SLJIT_S2
), 2 * sizeof(sljit_f32
));
8071 sljit_emit_return_void(compiler
);
8073 code
.code
= sljit_generate_code(compiler
);
8075 sljit_free_compiler(compiler
);
8077 code
.func3((sljit_sw
)&bbuf
, (sljit_sw
)&dbuf
, (sljit_sw
)&sbuf
);
8080 FAILED(bbuf
[0] != 1, "test75 case 1 failed\n");
8081 FAILED(bbuf
[1] != 2, "test75 case 2 failed\n");
8082 FAILED(bbuf
[2] != 2, "test75 case 3 failed\n");
8083 FAILED(bbuf
[3] != 2, "test75 case 4 failed\n");
8085 FAILED(bbuf
[4] != 2, "test75 case 5 failed\n");
8086 FAILED(bbuf
[5] != 1, "test75 case 6 failed\n");
8087 FAILED(bbuf
[6] != 1, "test75 case 7 failed\n");
8088 FAILED(bbuf
[7] != 1, "test75 case 8 failed\n");
8090 FAILED(bbuf
[8] != 2, "test75 case 9 failed\n");
8091 FAILED(bbuf
[9] != 1, "test75 case 10 failed\n");
8092 FAILED(bbuf
[10] != 2, "test75 case 11 failed\n");
8093 FAILED(bbuf
[11] != 2, "test75 case 12 failed\n");
8095 FAILED(bbuf
[12] != 2, "test75 case 13 failed\n");
8096 FAILED(bbuf
[13] != 1, "test75 case 14 failed\n");
8097 FAILED(bbuf
[14] != 1, "test75 case 15 failed\n");
8098 FAILED(bbuf
[15] != 1, "test75 case 16 failed\n");
8100 FAILED(bbuf
[16] != 2, "test75 case 17 failed\n");
8101 FAILED(bbuf
[17] != 1, "test75 case 18 failed\n");
8102 FAILED(bbuf
[18] != 2, "test75 case 19 failed\n");
8103 FAILED(bbuf
[19] != 2, "test75 case 20 failed\n");
8105 FAILED(bbuf
[20] != 1, "test75 case 21 failed\n");
8106 FAILED(bbuf
[21] != 2, "test75 case 22 failed\n");
8107 FAILED(bbuf
[22] != 1, "test75 case 23 failed\n");
8108 FAILED(bbuf
[23] != 1, "test75 case 24 failed\n");
8110 FAILED(bbuf
[24] != 2, "test75 case 25 failed\n");
8111 FAILED(bbuf
[25] != 1, "test75 case 26 failed\n");
8112 FAILED(bbuf
[26] != 1, "test75 case 27 failed\n");
8113 FAILED(bbuf
[27] != 1, "test75 case 28 failed\n");
8115 FAILED(bbuf
[28] != 2, "test75 case 29 failed\n");
8116 FAILED(bbuf
[29] != 1, "test75 case 30 failed\n");
8117 FAILED(bbuf
[30] != 2, "test75 case 31 failed\n");
8118 FAILED(bbuf
[31] != 2, "test75 case 32 failed\n");
8120 FAILED(bbuf
[32] != 1, "test75 case 33 failed\n");
8121 FAILED(bbuf
[33] != 2, "test75 case 34 failed\n");
8122 FAILED(bbuf
[34] != 1, "test75 case 35 failed\n");
8123 FAILED(bbuf
[35] != 1, "test75 case 36 failed\n");
8125 FAILED(bbuf
[36] != 2, "test75 case 37 failed\n");
8126 FAILED(bbuf
[37] != 1, "test75 case 38 failed\n");
8127 FAILED(bbuf
[38] != 2, "test75 case 39 failed\n");
8128 FAILED(bbuf
[39] != 2, "test75 case 40 failed\n");
8130 FAILED(bbuf
[40] != 2, "test75 case 41 failed\n");
8131 FAILED(bbuf
[41] != 1, "test75 case 42 failed\n");
8132 FAILED(bbuf
[42] != 1, "test75 case 43 failed\n");
8133 FAILED(bbuf
[43] != 1, "test75 case 44 failed\n");
8135 FAILED(bbuf
[44] != 1, "test75 case 45 failed\n");
8136 FAILED(bbuf
[45] != 2, "test75 case 46 failed\n");
8137 FAILED(bbuf
[46] != 2, "test75 case 47 failed\n");
8138 FAILED(bbuf
[47] != 2, "test75 case 48 failed\n");
8141 FAILED(bbuf
[48] != 1, "test75 case 49 failed\n");
8142 FAILED(bbuf
[49] != 2, "test75 case 50 failed\n");
8143 FAILED(bbuf
[50] != 2, "test75 case 51 failed\n");
8144 FAILED(bbuf
[51] != 2, "test75 case 52 failed\n");
8146 FAILED(bbuf
[52] != 2, "test75 case 53 failed\n");
8147 FAILED(bbuf
[53] != 1, "test75 case 54 failed\n");
8148 FAILED(bbuf
[54] != 1, "test75 case 55 failed\n");
8149 FAILED(bbuf
[55] != 1, "test75 case 56 failed\n");
8151 FAILED(bbuf
[56] != 2, "test75 case 57 failed\n");
8152 FAILED(bbuf
[57] != 1, "test75 case 58 failed\n");
8153 FAILED(bbuf
[58] != 2, "test75 case 59 failed\n");
8154 FAILED(bbuf
[59] != 2, "test75 case 60 failed\n");
8156 FAILED(bbuf
[60] != 2, "test75 case 61 failed\n");
8157 FAILED(bbuf
[61] != 1, "test75 case 62 failed\n");
8158 FAILED(bbuf
[62] != 1, "test75 case 63 failed\n");
8159 FAILED(bbuf
[63] != 1, "test75 case 64 failed\n");
8161 FAILED(bbuf
[64] != 2, "test75 case 65 failed\n");
8162 FAILED(bbuf
[65] != 1, "test75 case 66 failed\n");
8163 FAILED(bbuf
[66] != 2, "test75 case 67 failed\n");
8164 FAILED(bbuf
[67] != 2, "test75 case 68 failed\n");
8166 FAILED(bbuf
[68] != 1, "test75 case 69 failed\n");
8167 FAILED(bbuf
[69] != 2, "test75 case 70 failed\n");
8168 FAILED(bbuf
[70] != 1, "test75 case 71 failed\n");
8169 FAILED(bbuf
[71] != 1, "test75 case 72 failed\n");
8171 FAILED(bbuf
[72] != 2, "test75 case 73 failed\n");
8172 FAILED(bbuf
[73] != 1, "test75 case 74 failed\n");
8173 FAILED(bbuf
[74] != 1, "test75 case 75 failed\n");
8174 FAILED(bbuf
[75] != 1, "test75 case 76 failed\n");
8176 FAILED(bbuf
[76] != 2, "test75 case 77 failed\n");
8177 FAILED(bbuf
[77] != 1, "test75 case 78 failed\n");
8178 FAILED(bbuf
[78] != 2, "test75 case 79 failed\n");
8179 FAILED(bbuf
[79] != 2, "test75 case 80 failed\n");
8181 FAILED(bbuf
[80] != 1, "test75 case 81 failed\n");
8182 FAILED(bbuf
[81] != 2, "test75 case 82 failed\n");
8183 FAILED(bbuf
[82] != 1, "test75 case 83 failed\n");
8184 FAILED(bbuf
[83] != 1, "test75 case 84 failed\n");
8186 FAILED(bbuf
[84] != 2, "test75 case 85 failed\n");
8187 FAILED(bbuf
[85] != 1, "test75 case 86 failed\n");
8188 FAILED(bbuf
[86] != 2, "test75 case 87 failed\n");
8189 FAILED(bbuf
[87] != 2, "test75 case 88 failed\n");
8191 FAILED(bbuf
[88] != 2, "test75 case 89 failed\n");
8192 FAILED(bbuf
[89] != 1, "test75 case 90 failed\n");
8193 FAILED(bbuf
[90] != 1, "test75 case 91 failed\n");
8194 FAILED(bbuf
[91] != 1, "test75 case 92 failed\n");
8196 FAILED(bbuf
[92] != 1, "test75 case 93 failed\n");
8197 FAILED(bbuf
[93] != 2, "test75 case 94 failed\n");
8198 FAILED(bbuf
[94] != 2, "test75 case 95 failed\n");
8199 FAILED(bbuf
[95] != 2, "test75 case 96 failed\n");
8204 static void test76(void)
8206 #if !(defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
8207 /* Test keep saved registers. */
8208 executable_code code
;
8209 struct sljit_compiler
* compiler
;
8210 struct sljit_jump
* jump
;
8216 printf("Run test76\n");
8219 for (i
= 0; i
< 9; i
++)
8222 compiler
= sljit_create_compiler(NULL
, NULL
);
8223 FAILED(!compiler
, "cannot create compiler\n");
8225 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 4, 2, 0, 0, 0);
8227 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 7945);
8228 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -9267);
8229 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 4309);
8230 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -8321);
8232 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 6803);
8233 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -5497);
8235 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS4(W
, W
, W
, W
, W
));
8237 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
);
8238 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0, SLJIT_R0
, 0);
8239 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_sw
), SLJIT_S0
, 0);
8240 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 2 * sizeof(sljit_sw
), SLJIT_S1
, 0);
8241 sljit_emit_return_void(compiler
);
8243 sljit_set_label(jump
, sljit_emit_label(compiler
));
8244 sljit_emit_enter(compiler
, SLJIT_ENTER_KEEP_S0_S1
, SLJIT_ARGS4(W
, W
, W
, W
, W
), 1, 6, 0, 0, 32);
8246 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
);
8247 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 3 * sizeof(sljit_sw
), SLJIT_S0
, 0);
8248 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 4 * sizeof(sljit_sw
), SLJIT_S1
, 0);
8249 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 5 * sizeof(sljit_sw
), SLJIT_S2
, 0);
8250 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 6 * sizeof(sljit_sw
), SLJIT_S3
, 0);
8251 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 7 * sizeof(sljit_sw
), SLJIT_S4
, 0);
8252 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 8 * sizeof(sljit_sw
), SLJIT_S5
, 0);
8254 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 6028);
8255 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 4982);
8256 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1289);
8258 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
8260 code
.code
= sljit_generate_code(compiler
);
8262 sljit_free_compiler(compiler
);
8264 code
.func1((sljit_sw
)&buf
);
8266 FAILED(buf
[0] != 6028, "test76 case 1 failed\n");
8267 FAILED(buf
[1] != 4982, "test76 case 2 failed\n");
8268 FAILED(buf
[2] != -1289, "test76 case 3 failed\n");
8269 FAILED(buf
[3] != 6803, "test76 case 4 failed\n");
8270 FAILED(buf
[4] != -5497, "test76 case 5 failed\n");
8271 FAILED(buf
[5] != 7945, "test76 case 6 failed\n");
8272 FAILED(buf
[6] != -9267, "test76 case 7 failed\n");
8273 FAILED(buf
[7] != 4309, "test76 case 8 failed\n");
8274 FAILED(buf
[8] != -8321, "test76 case 9 failed\n");
8278 for (i
= 0; i
< 9; i
++)
8281 compiler
= sljit_create_compiler(NULL
, NULL
);
8282 FAILED(!compiler
, "cannot create compiler\n");
8284 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 4, 1, 0, 0, 0);
8286 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -2608);
8287 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 4751);
8288 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 5740);
8289 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, -9704);
8291 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -8749);
8293 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS4(W
, W
, W
, W
, W
));
8295 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
);
8296 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0, SLJIT_R0
, 0);
8297 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_sw
), SLJIT_S0
, 0);
8298 sljit_emit_return_void(compiler
);
8300 sljit_set_label(jump
, sljit_emit_label(compiler
));
8301 sljit_emit_enter(compiler
, SLJIT_ENTER_KEEP_S0
, SLJIT_ARGS4(W
, W_R
, W
, W_R
, W
), 3, 3, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
8302 sljit_set_context(compiler
, SLJIT_ENTER_KEEP_S0
, SLJIT_ARGS4(W
, W_R
, W
, W_R
, W
), 3, 3, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
8304 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
);
8305 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 2 * sizeof(sljit_sw
), SLJIT_S0
, 0);
8306 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
8307 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 4 * sizeof(sljit_sw
), SLJIT_S1
, 0);
8308 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 5 * sizeof(sljit_sw
), SLJIT_R2
, 0);
8309 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 6 * sizeof(sljit_sw
), SLJIT_S2
, 0);
8311 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, -7351);
8312 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 3628);
8314 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
8316 code
.code
= sljit_generate_code(compiler
);
8318 sljit_free_compiler(compiler
);
8320 code
.func1((sljit_sw
)&buf
);
8322 FAILED(buf
[0] != -7351, "test76 case 10 failed\n");
8323 FAILED(buf
[1] != 3628, "test76 case 11 failed\n");
8324 FAILED(buf
[2] != -8749, "test76 case 12 failed\n");
8325 FAILED(buf
[3] != -2608, "test76 case 13 failed\n");
8326 FAILED(buf
[4] != 4751, "test76 case 14 failed\n");
8327 FAILED(buf
[5] != 5740, "test76 case 15 failed\n");
8328 FAILED(buf
[6] != -9704, "test76 case 16 failed\n");
8329 FAILED(buf
[7] != -1, "test76 case 17 failed\n");
8333 for (i
= 0; i
< 9; i
++)
8336 compiler
= sljit_create_compiler(NULL
, NULL
);
8337 FAILED(!compiler
, "cannot create compiler\n");
8339 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 4, 1, 0, 0, 0);
8341 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8653);
8342 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 7245);
8343 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, -3610);
8344 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 4591);
8346 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -2865);
8348 jump
= sljit_emit_call(compiler
, SLJIT_CALL_CDECL
, SLJIT_ARGS4(VOID
, W
, W
, W
, W
));
8350 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM0(), (sljit_sw
)&buf
, SLJIT_S0
, 0);
8351 sljit_emit_return_void(compiler
);
8353 sljit_set_label(jump
, sljit_emit_label(compiler
));
8354 sljit_emit_enter(compiler
, SLJIT_ENTER_CDECL
| SLJIT_ENTER_KEEP_S0
, SLJIT_ARGS4(W
, W_R
, W
, W
, W_R
), 4, 3, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
8356 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
);
8357 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_sw
), SLJIT_S0
, 0);
8358 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
8359 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 3 * sizeof(sljit_sw
), SLJIT_S1
, 0);
8360 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 4 * sizeof(sljit_sw
), SLJIT_S2
, 0);
8361 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 5 * sizeof(sljit_sw
), SLJIT_R3
, 0);
8363 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 5789);
8365 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
8367 code
.code
= sljit_generate_code(compiler
);
8369 sljit_free_compiler(compiler
);
8371 code
.func1((sljit_sw
)&buf
);
8373 FAILED(buf
[0] != 5789, "test76 case 18 failed\n");
8374 FAILED(buf
[1] != -2865, "test76 case 19 failed\n");
8375 FAILED(buf
[2] != 8653, "test76 case 20 failed\n");
8376 FAILED(buf
[3] != 7245, "test76 case 21 failed\n");
8377 FAILED(buf
[4] != -3610, "test76 case 22 failed\n");
8378 FAILED(buf
[5] != 4591, "test76 case 23 failed\n");
8379 FAILED(buf
[6] != -1, "test76 case 24 failed\n");
8383 for (i
= 0; i
< 9; i
++)
8386 compiler
= sljit_create_compiler(NULL
, NULL
);
8387 FAILED(!compiler
, "cannot create compiler\n");
8389 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 2, 3, 0, 0, 0);
8391 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 6071);
8392 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -3817);
8393 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, 9250);
8395 jump
= sljit_emit_call(compiler
, SLJIT_CALL_CDECL
, SLJIT_ARGS0(W
));
8397 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
);
8398 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0, SLJIT_R0
, 0);
8399 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_sw
), SLJIT_S0
, 0);
8400 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 2 * sizeof(sljit_sw
), SLJIT_S1
, 0);
8401 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 3 * sizeof(sljit_sw
), SLJIT_S2
, 0);
8402 sljit_emit_return_void(compiler
);
8404 sljit_set_label(jump
, sljit_emit_label(compiler
));
8405 sljit_emit_enter(compiler
, SLJIT_ENTER_CDECL
| SLJIT_ENTER_KEEP_S0_S1
, SLJIT_ARGS0(W
), 4, 3, 0, 0, SLJIT_MAX_LOCAL_SIZE
);
8407 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
);
8408 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 4 * sizeof(sljit_sw
), SLJIT_S0
, 0);
8409 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 5 * sizeof(sljit_sw
), SLJIT_S1
, 0);
8411 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0x15000000);
8412 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 0x93);
8413 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 0x280000);
8414 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R3
, 0, SLJIT_IMM
, 0x4600);
8416 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 4892);
8417 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -7513);
8418 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1);
8420 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, W
, 32, 32, W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f2
));
8421 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
8423 code
.code
= sljit_generate_code(compiler
);
8425 sljit_free_compiler(compiler
);
8427 code
.func1((sljit_sw
)&buf
);
8429 FAILED(buf
[0] != 0x15284693, "test76 case 25 failed\n");
8430 FAILED(buf
[1] != 4892, "test76 case 26 failed\n");
8431 FAILED(buf
[2] != -7513, "test76 case 27 failed\n");
8432 FAILED(buf
[3] != 9250, "test76 case 28 failed\n");
8433 FAILED(buf
[4] != 6071, "test76 case 29 failed\n");
8434 FAILED(buf
[5] != -3817, "test76 case 30 failed\n");
8435 FAILED(buf
[6] != -1, "test76 case 31 failed\n");
8437 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
8440 for (i
= 0; i
< 9; i
++)
8447 compiler
= sljit_create_compiler(NULL
, NULL
);
8448 FAILED(!compiler
, "cannot create compiler\n");
8450 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 2, 3, 3, 0, 0);
8452 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
8453 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_R1
), 0);
8454 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_f64
));
8455 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_R1
), 2 * sizeof(sljit_f64
));
8457 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1706);
8458 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, -8956);
8459 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, 4381);
8460 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -5314);
8462 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS4(W
, F64
, F64
, F64
, W
));
8464 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
);
8465 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0, SLJIT_R0
, 0);
8466 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_sw
), SLJIT_S0
, 0);
8467 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 2 * sizeof(sljit_sw
), SLJIT_S1
, 0);
8468 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 3 * sizeof(sljit_sw
), SLJIT_S2
, 0);
8469 sljit_emit_return_void(compiler
);
8471 sljit_set_label(jump
, sljit_emit_label(compiler
));
8472 sljit_emit_enter(compiler
, SLJIT_ENTER_KEEP_S0
, SLJIT_ARGS4(W
, F64
, F64
, F64
, W
), 1, 3, 3, 0, SLJIT_MAX_LOCAL_SIZE
);
8474 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
);
8475 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 4 * sizeof(sljit_sw
), SLJIT_S0
, 0);
8476 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 5 * sizeof(sljit_sw
), SLJIT_S1
, 0);
8478 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
8479 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_FR2
, 0);
8480 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
), SLJIT_FR0
, 0);
8481 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_f64
), SLJIT_FR1
, 0);
8483 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 2784);
8484 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 1503);
8485 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1);
8486 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1);
8488 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R0
, 0);
8490 code
.code
= sljit_generate_code(compiler
);
8492 sljit_free_compiler(compiler
);
8494 code
.func1((sljit_sw
)&buf
);
8496 FAILED(buf
[0] != 2784, "test76 case 32 failed\n");
8497 FAILED(buf
[1] != 1503, "test76 case 33 failed\n");
8498 FAILED(buf
[2] != 4381, "test76 case 34 failed\n");
8499 FAILED(buf
[3] != -5314, "test76 case 35 failed\n");
8500 FAILED(buf
[4] != -8956, "test76 case 36 failed\n");
8501 FAILED(buf
[5] != 1706, "test76 case 37 failed\n");
8502 FAILED(buf
[6] != -1, "test76 case 38 failed\n");
8503 FAILED(dbuf
[0] != 8703.5, "test76 case 39 failed\n");
8504 FAILED(dbuf
[1] != 4061.25, "test76 case 40 failed\n");
8505 FAILED(dbuf
[2] != -3291.75, "test76 case 41 failed\n");
8509 for (i
= 0; i
< 9; i
++)
8514 compiler
= sljit_create_compiler(NULL
, NULL
);
8515 FAILED(!compiler
, "cannot create compiler\n");
8517 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 3, 3, 1, 0, 0);
8519 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM0(), (sljit_sw
)&dbuf
);
8521 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 8793);
8522 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, -4027);
8523 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R2
, 0, SLJIT_IMM
, 2910);
8524 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 4619);
8525 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -1502);
8526 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, 5316);
8528 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS4(VOID
, F64
, W
, W
, W
));
8530 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
);
8531 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 0, SLJIT_S0
, 0);
8532 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_sw
), SLJIT_S1
, 0);
8533 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_sw
), SLJIT_S2
, 0);
8534 sljit_emit_return_void(compiler
);
8536 sljit_set_label(jump
, sljit_emit_label(compiler
));
8537 sljit_emit_enter(compiler
, SLJIT_ENTER_KEEP_S0_S1
, SLJIT_ARGS4(VOID
, F64
, W
, W
, W
), 1, 5, 3, 0, SLJIT_MAX_LOCAL_SIZE
);
8539 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
);
8540 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 3 * sizeof(sljit_sw
), SLJIT_S0
, 0);
8541 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 4 * sizeof(sljit_sw
), SLJIT_S1
, 0);
8542 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 5 * sizeof(sljit_sw
), SLJIT_S2
, 0);
8543 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 6 * sizeof(sljit_sw
), SLJIT_S3
, 0);
8544 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 7 * sizeof(sljit_sw
), SLJIT_S4
, 0);
8546 sljit_emit_fop1(compiler
, SLJIT_NEG_F64
, SLJIT_MEM0(), (sljit_sw
)&dbuf
, SLJIT_FR0
, 0);
8548 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 7839);
8549 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -9215);
8550 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1);
8552 sljit_emit_return_void(compiler
);
8554 code
.code
= sljit_generate_code(compiler
);
8556 sljit_free_compiler(compiler
);
8558 code
.func1((sljit_sw
)&buf
);
8560 FAILED(buf
[0] != 7839, "test76 case 42 failed\n");
8561 FAILED(buf
[1] != -9215, "test76 case 43 failed\n");
8562 FAILED(buf
[2] != 5316, "test76 case 44 failed\n");
8563 FAILED(buf
[3] != 4619, "test76 case 45 failed\n");
8564 FAILED(buf
[4] != -1502, "test76 case 46 failed\n");
8565 FAILED(buf
[5] != 8793, "test76 case 47 failed\n");
8566 FAILED(buf
[6] != -4027, "test76 case 48 failed\n");
8567 FAILED(buf
[7] != 2910, "test76 case 49 failed\n");
8568 FAILED(buf
[8] != -1, "test76 case 50 failed\n");
8569 FAILED(dbuf
[0] != -4061.25, "test76 case 51 failed\n");
8573 for (i
= 0; i
< 9; i
++)
8580 compiler
= sljit_create_compiler(NULL
, NULL
);
8581 FAILED(!compiler
, "cannot create compiler\n");
8583 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(VOID
), 2, 3, 0, 0, 0);
8585 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 7869);
8586 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -5406);
8587 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, 4951);
8589 jump
= sljit_emit_call(compiler
, SLJIT_CALL
, SLJIT_ARGS0(W
));
8591 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, (sljit_sw
)&buf
);
8592 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 0, SLJIT_R0
, 0);
8593 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), sizeof(sljit_sw
), SLJIT_S0
, 0);
8594 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 2 * sizeof(sljit_sw
), SLJIT_S1
, 0);
8595 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), 3 * sizeof(sljit_sw
), SLJIT_S2
, 0);
8596 sljit_emit_return_void(compiler
);
8598 sljit_set_label(jump
, sljit_emit_label(compiler
));
8599 sljit_emit_enter(compiler
, SLJIT_ENTER_KEEP_S0_S1
, SLJIT_ARGS0(W
), 1, 3, 3, 0, SLJIT_MAX_LOCAL_SIZE
);
8601 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&buf
);
8602 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 4 * sizeof(sljit_sw
), SLJIT_S0
, 0);
8603 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R0
), 5 * sizeof(sljit_sw
), SLJIT_S1
, 0);
8605 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)&dbuf
);
8606 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_R0
), 0);
8607 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR1
, 0, SLJIT_MEM1(SLJIT_R0
), sizeof(sljit_f64
));
8608 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR2
, 0, SLJIT_MEM1(SLJIT_R0
), 2 * sizeof(sljit_f64
));
8610 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 1706);
8612 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S0
, 0, SLJIT_IMM
, 4713);
8613 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S1
, 0, SLJIT_IMM
, -2078);
8614 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_S2
, 0, SLJIT_IMM
, -1);
8616 sljit_emit_icall(compiler
, SLJIT_CALL
| SLJIT_CALL_RETURN
, SLJIT_ARGS4(W
, F64
, F64
, F64
, W
), SLJIT_IMM
, SLJIT_FUNC_ADDR(test71_f7
));
8617 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM0(), 0);
8619 code
.code
= sljit_generate_code(compiler
);
8621 sljit_free_compiler(compiler
);
8623 code
.func1((sljit_sw
)&buf
);
8625 FAILED(buf
[0] != 5074526, "test76 case 52 failed\n");
8626 FAILED(buf
[1] != 4713, "test76 case 53 failed\n");
8627 FAILED(buf
[2] != -2078, "test76 case 54 failed\n");
8628 FAILED(buf
[3] != 4951, "test76 case 55 failed\n");
8629 FAILED(buf
[4] != 7869, "test76 case 56 failed\n");
8630 FAILED(buf
[5] != -5406, "test76 case 57 failed\n");
8631 FAILED(buf
[6] != -1, "test76 case 58 failed\n");
8633 #endif /* !SLJIT_CONFIG_SPARC */
8638 static void copy_u8(void *dst
, sljit_sw offset
, const void *src
, sljit_uw length
)
8640 sljit_u8
*dst_p
= (sljit_u8
*)dst
+ offset
;
8641 const sljit_u8
*src_p
= (sljit_u8
*)src
;
8643 while (length
-- != 0)
8644 *dst_p
++ = *src_p
++;
8647 static int cmp_u8(const void *src1
, sljit_sw offset
, const void *src2
, sljit_uw length
)
8649 const sljit_u8
*src1_p
= (sljit_u8
*)src1
+ offset
;
8650 const sljit_u8
*src2_p
= (sljit_u8
*)src2
;
8652 while (--length
!= 0) {
8653 if (*src1_p
!= *src2_p
)
8661 static void test77(void)
8663 /* Test unaligned accesses. */
8664 executable_code code
;
8665 struct sljit_compiler
* compiler
;
8672 sljit_s8 bbuf_start
[40 + 8 /* for alignment */];
8673 sljit_s8
*bbuf
= (sljit_s8
*)(((sljit_uw
)bbuf_start
+ 7) & ~(sljit_uw
)7);
8675 SLJIT_ASSERT(((sljit_uw
)bbuf
& 0x7) == 0);
8678 printf("Run test77\n");
8680 for (i
= 0; i
< 13; i
++)
8683 for (i
= 0; i
< 40; i
++)
8689 copy_u8(bbuf
, 3, hbuf
, sizeof(sljit_s16
));
8690 copy_u8(bbuf
, 5, ibuf
, sizeof(sljit_s32
));
8691 copy_u8(bbuf
, 9, wbuf
, sizeof(sljit_sw
));
8692 copy_u8(bbuf
, 18, ibuf
, sizeof(sljit_s32
));
8693 copy_u8(bbuf
, 22, wbuf
, sizeof(sljit_sw
));
8694 copy_u8(bbuf
, 32, wbuf
, sizeof(sljit_sw
));
8701 compiler
= sljit_create_compiler(NULL
, NULL
);
8702 FAILED(!compiler
, "cannot create compiler\n");
8704 sljit_emit_enter(compiler
, 0, SLJIT_ARGS2(VOID
, P
, P
), 2, 2, 0, 0, 0);
8706 sljit_emit_mem(compiler
, SLJIT_MOV_S8
| SLJIT_MEM_UNALIGNED
, SLJIT_R0
, SLJIT_MEM0(), (sljit_sw
)bbuf
);
8708 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_sw
), SLJIT_R0
, 0);
8710 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 0);
8711 sljit_emit_mem(compiler
, SLJIT_MOV_U8
| SLJIT_MEM_UNALIGNED
, SLJIT_R0
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R0
), 0);
8713 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_sw
), SLJIT_R0
, 0);
8715 sljit_emit_op1(compiler
, SLJIT_MOV_S8
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
8717 sljit_emit_mem(compiler
, SLJIT_MOV_U8
| SLJIT_MEM_STORE
| SLJIT_MEM_UNALIGNED
, SLJIT_R0
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_s8
));
8719 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 100000);
8720 sljit_emit_mem(compiler
, SLJIT_MOV_S16
| SLJIT_MEM_UNALIGNED
, SLJIT_R0
, SLJIT_MEM1(SLJIT_R1
), 100000 + 3);
8722 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_sw
), SLJIT_R0
, 0);
8724 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 1000);
8725 sljit_emit_mem(compiler
, SLJIT_MOV_U16
| SLJIT_MEM_UNALIGNED
, SLJIT_R0
, SLJIT_MEM1(SLJIT_R1
), -1000 + 3);
8727 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_sw
), SLJIT_R0
, 0);
8729 sljit_emit_op1(compiler
, SLJIT_MOV_S16
, SLJIT_R0
, 0, SLJIT_MEM0(), (sljit_sw
)&hbuf
);
8731 sljit_emit_mem(compiler
, SLJIT_MOV_S16
| SLJIT_MEM_STORE
| SLJIT_MEM_UNALIGNED
, SLJIT_R0
, SLJIT_MEM1(SLJIT_S1
), 3);
8733 sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_UNALIGNED
, SLJIT_R0
, SLJIT_MEM1(SLJIT_S1
), 5);
8735 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 5 * sizeof(sljit_sw
), SLJIT_R0
, 0);
8737 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 5);
8738 sljit_emit_mem(compiler
, SLJIT_MOV_U32
| SLJIT_MEM_UNALIGNED
, SLJIT_R0
, SLJIT_MEM2(SLJIT_R0
, SLJIT_S1
), 0);
8740 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 6 * sizeof(sljit_sw
), SLJIT_R0
, 0);
8742 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 100000);
8743 sljit_emit_op1(compiler
, SLJIT_MOV32
, SLJIT_R0
, 0, SLJIT_MEM0(), (sljit_sw
)&ibuf
);
8745 sljit_emit_mem(compiler
, SLJIT_MOV32
| SLJIT_MEM_STORE
| SLJIT_MEM_UNALIGNED
, SLJIT_R0
, SLJIT_MEM1(SLJIT_R1
), 100000 + 5);
8747 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 100000);
8748 #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED)
8749 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_R1
), -100000 + 9);
8750 #else /* !SLJIT_UNALIGNED */
8751 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_UNALIGNED
, SLJIT_R0
, SLJIT_MEM1(SLJIT_R1
), -100000 + 9);
8752 #endif /* SLJIT_UNALIGNED */
8754 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 7 * sizeof(sljit_sw
), SLJIT_R0
, 0);
8756 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
8758 #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED)
8759 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_R1
), -100000 + 9, SLJIT_R0
, 0);
8760 #else /* !SLJIT_UNALIGNED */
8761 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_STORE
| SLJIT_MEM_UNALIGNED
, SLJIT_R0
, SLJIT_MEM1(SLJIT_R1
), -100000 + 9);
8762 #endif /* SLJIT_UNALIGNED */
8764 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R1
, 0, SLJIT_IMM
, 18 >> 1);
8765 sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_UNALIGNED
| SLJIT_MEM_ALIGNED_16
, SLJIT_R0
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R1
), 1);
8767 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 8 * sizeof(sljit_sw
), SLJIT_R0
, 0);
8769 sljit_emit_op1(compiler
, SLJIT_MOV_S32
, SLJIT_R0
, 0, SLJIT_MEM0(), (sljit_sw
)&ibuf
);
8771 sljit_emit_mem(compiler
, SLJIT_MOV_S32
| SLJIT_MEM_STORE
| SLJIT_MEM_UNALIGNED
| SLJIT_MEM_ALIGNED_16
, SLJIT_R0
, SLJIT_MEM2(SLJIT_S1
, SLJIT_R1
), 1);
8773 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_UNALIGNED
| SLJIT_MEM_ALIGNED_16
, SLJIT_R0
, SLJIT_MEM0(), (sljit_sw
)bbuf
+ 22);
8775 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 9 * sizeof(sljit_sw
), SLJIT_R0
, 0);
8777 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
8779 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_STORE
| SLJIT_MEM_UNALIGNED
| SLJIT_MEM_ALIGNED_16
, SLJIT_R0
, SLJIT_MEM0(), (sljit_sw
)bbuf
+ 22);
8781 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 128);
8782 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_UNALIGNED
| SLJIT_MEM_ALIGNED_32
, SLJIT_R0
, SLJIT_MEM1(SLJIT_R0
), -128 + 32);
8784 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_MEM1(SLJIT_S0
), 10 * sizeof(sljit_sw
), SLJIT_R0
, 0);
8786 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R1
, 0, SLJIT_S1
, 0, SLJIT_IMM
, 128);
8787 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
8789 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_STORE
| SLJIT_MEM_UNALIGNED
| SLJIT_MEM_ALIGNED_32
, SLJIT_R0
, SLJIT_MEM1(SLJIT_R1
), -128 + 32);
8791 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_UNALIGNED
, SLJIT_R0
, SLJIT_MEM1(SLJIT_S0
), 0);
8793 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_STORE
| SLJIT_MEM_UNALIGNED
, SLJIT_R0
, SLJIT_MEM1(SLJIT_S0
), 11 * sizeof(sljit_sw
));
8795 sljit_emit_mem(compiler
, SLJIT_MOV
| SLJIT_MEM_STORE
| SLJIT_MEM_UNALIGNED
, SLJIT_S0
, SLJIT_MEM1(SLJIT_S0
), 12 * sizeof(sljit_sw
));
8797 sljit_emit_return_void(compiler
);
8799 code
.code
= sljit_generate_code(compiler
);
8801 sljit_free_compiler(compiler
);
8803 code
.func2((sljit_sw
)&wbuf
, (sljit_sw
)bbuf
);
8805 FAILED(wbuf
[1] != -73, "test77 case 1 failed\n");
8806 FAILED(wbuf
[2] != (sljit_u8
)-73, "test77 case 2 failed\n");
8807 FAILED(bbuf
[1] != -73, "test77 case 3 failed\n");
8808 FAILED(wbuf
[3] != -28531, "test77 case 4 failed\n");
8809 FAILED(wbuf
[4] != (sljit_u16
)-28531, "test77 case 5 failed\n");
8810 FAILED(cmp_u8(bbuf
, 3, hbuf
, sizeof(sljit_s16
)) != 1, "test77 case 6 failed\n");
8811 FAILED(wbuf
[5] != -38512, "test77 case 7 failed\n");
8812 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
8813 FAILED(wbuf
[6] != (sljit_u32
)-38512, "test77 case 8 failed\n");
8815 FAILED(wbuf
[6] != -38512, "test77 case 8 failed\n");
8817 FAILED(cmp_u8(bbuf
, 5, ibuf
, sizeof(sljit_s32
)) != 1, "test77 case 9 failed\n");
8818 FAILED(wbuf
[7] != -46870, "test77 case 10 failed\n");
8819 FAILED(cmp_u8(bbuf
, 9, wbuf
, sizeof(sljit_sw
)) != 1, "test77 case 11 failed\n");
8820 FAILED(wbuf
[8] != -38512, "test77 case 12 failed\n");
8821 FAILED(cmp_u8(bbuf
, 18, ibuf
, sizeof(sljit_s32
)) != 1, "test77 case 13 failed\n");
8822 FAILED(wbuf
[9] != -46870, "test77 case 14 failed\n");
8823 FAILED(cmp_u8(bbuf
, 22, wbuf
, sizeof(sljit_sw
)) != 1, "test77 case 15 failed\n");
8824 FAILED(wbuf
[10] != -46870, "test77 case 16 failed\n");
8825 FAILED(cmp_u8(bbuf
, 32, wbuf
, sizeof(sljit_sw
)) != 1, "test77 case 17 failed\n");
8826 FAILED(wbuf
[11] != -62945, "test77 case 18 failed\n");
8827 FAILED(wbuf
[12] != (sljit_sw
)&wbuf
, "test77 case 19 failed\n");
8829 sljit_free_code(code
.code
, NULL
);
8831 if (sljit_has_cpu_feature(SLJIT_HAS_FPU
)) {
8832 for (i
= 0; i
< 40; i
++)
8835 for (i
= 0; i
< 5; i
++)
8840 copy_u8(bbuf
, 1, sbuf
, sizeof(sljit_f32
));
8841 copy_u8(bbuf
, 5, dbuf
, sizeof(sljit_f64
));
8842 copy_u8(bbuf
, 14, sbuf
, sizeof(sljit_f32
));
8843 copy_u8(bbuf
, 18, dbuf
, sizeof(sljit_f64
));
8844 copy_u8(bbuf
, 28, dbuf
, sizeof(sljit_f64
));
8849 compiler
= sljit_create_compiler(NULL
, NULL
);
8850 FAILED(!compiler
, "cannot create compiler\n");
8852 sljit_emit_enter(compiler
, 0, SLJIT_ARGS3(VOID
, P
, P
, P
), 1, 3, 1, 0, 0);
8854 sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_UNALIGNED
, SLJIT_FR0
, SLJIT_MEM0(), (sljit_sw
)bbuf
+ 1);
8856 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), sizeof(sljit_f32
), SLJIT_FR0
, 0);
8858 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
8860 sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_STORE
| SLJIT_MEM_UNALIGNED
, SLJIT_FR0
, SLJIT_MEM0(), (sljit_sw
)bbuf
+ 1);
8862 sljit_emit_op2(compiler
, SLJIT_SUB
, SLJIT_R0
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 100000);
8863 #if (defined SLJIT_FPU_UNALIGNED && SLJIT_FPU_UNALIGNED)
8864 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_R0
), 100000 + 5);
8865 #else /* !SLJIT_FPU_UNALIGNED */
8866 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_UNALIGNED
, SLJIT_FR0
, SLJIT_MEM1(SLJIT_R0
), 100000 + 5);
8867 #endif /* SLJIT_FPU_UNALIGNED */
8869 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), sizeof(sljit_f64
), SLJIT_FR0
, 0);
8871 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
8873 #if (defined SLJIT_FPU_UNALIGNED && SLJIT_FPU_UNALIGNED)
8874 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_R0
), 100000 + 5, SLJIT_FR0
, 0);
8875 #else /* !SLJIT_FPU_UNALIGNED */
8876 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_STORE
| SLJIT_MEM_UNALIGNED
, SLJIT_FR0
, SLJIT_MEM1(SLJIT_R0
), 100000 + 5);
8877 #endif /* SLJIT_FPU_UNALIGNED */
8879 sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_UNALIGNED
| SLJIT_MEM_ALIGNED_16
, SLJIT_FR0
, SLJIT_MEM1(SLJIT_S2
), 14);
8881 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_MEM1(SLJIT_S1
), 2 * sizeof(sljit_f32
), SLJIT_FR0
, 0);
8883 sljit_emit_fop1(compiler
, SLJIT_MOV_F32
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S1
), 0);
8885 sljit_emit_fmem(compiler
, SLJIT_MOV_F32
| SLJIT_MEM_STORE
| SLJIT_MEM_UNALIGNED
| SLJIT_MEM_ALIGNED_16
, SLJIT_FR0
, SLJIT_MEM1(SLJIT_S2
), 14);
8887 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, 18 >> 1);
8888 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_UNALIGNED
| SLJIT_MEM_ALIGNED_16
, SLJIT_FR0
, SLJIT_MEM2(SLJIT_S2
, SLJIT_R0
), 1);
8890 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 2 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
8892 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
8894 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_STORE
| SLJIT_MEM_UNALIGNED
| SLJIT_MEM_ALIGNED_16
, SLJIT_FR0
, SLJIT_MEM2(SLJIT_S2
, SLJIT_R0
), 1);
8896 sljit_emit_op2(compiler
, SLJIT_ADD
, SLJIT_R0
, 0, SLJIT_S2
, 0, SLJIT_IMM
, 128);
8897 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_UNALIGNED
| SLJIT_MEM_ALIGNED_32
, SLJIT_FR0
, SLJIT_MEM1(SLJIT_R0
), -128 + 28);
8899 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_MEM1(SLJIT_S0
), 3 * sizeof(sljit_f64
), SLJIT_FR0
, 0);
8901 sljit_emit_fop1(compiler
, SLJIT_MOV_F64
, SLJIT_FR0
, 0, SLJIT_MEM1(SLJIT_S0
), 0);
8903 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_STORE
| SLJIT_MEM_UNALIGNED
| SLJIT_MEM_ALIGNED_32
, SLJIT_FR0
, SLJIT_MEM1(SLJIT_R0
), -128 + 28);
8905 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_UNALIGNED
| SLJIT_MEM_ALIGNED_32
, SLJIT_FR0
, SLJIT_MEM1(SLJIT_S0
), 0);
8907 sljit_emit_fmem(compiler
, SLJIT_MOV_F64
| SLJIT_MEM_STORE
| SLJIT_MEM_UNALIGNED
| SLJIT_MEM_ALIGNED_32
, SLJIT_FR0
, SLJIT_MEM1(SLJIT_S0
), 4 * sizeof(sljit_f64
));
8909 sljit_emit_return_void(compiler
);
8911 code
.code
= sljit_generate_code(compiler
);
8913 sljit_free_compiler(compiler
);
8915 code
.func3((sljit_sw
)&dbuf
, (sljit_sw
)&sbuf
, (sljit_sw
)bbuf
);
8917 FAILED(sbuf
[1] != -8812.25, "test77 case 20 failed\n");
8918 FAILED(cmp_u8(bbuf
, 1, sbuf
, sizeof(sljit_f32
)) != 1, "test77 case 21 failed\n");
8919 FAILED(dbuf
[1] != 6897.75, "test77 case 22 failed\n");
8920 FAILED(cmp_u8(bbuf
, 5, dbuf
, sizeof(sljit_f64
)) != 1, "test77 case 23 failed\n");
8921 FAILED(sbuf
[2] != -8812.25, "test77 case 24 failed\n");
8922 FAILED(cmp_u8(bbuf
, 14, sbuf
, sizeof(sljit_f32
)) != 1, "test77 case 25 failed\n");
8923 FAILED(dbuf
[2] != 6897.75, "test77 case 26 failed\n");
8924 FAILED(cmp_u8(bbuf
, 18, dbuf
, sizeof(sljit_f64
)) != 1, "test77 case 27 failed\n");
8925 FAILED(dbuf
[3] != 6897.75, "test77 case 28 failed\n");
8926 FAILED(cmp_u8(bbuf
, 28, dbuf
, sizeof(sljit_f64
)) != 1, "test77 case 29 failed\n");
8927 FAILED(dbuf
[4] != -18046.5, "test77 case 30 failed\n");
8929 sljit_free_code(code
.code
, NULL
);
8935 static void test78(void)
8937 /* Test addressing modes. */
8938 executable_code code
;
8939 struct sljit_compiler
* compiler
= sljit_create_compiler(NULL
, NULL
);
8940 sljit_u8 buf
[3 + SLJIT_NUMBER_OF_REGISTERS
* 3];
8941 sljit_u8
*buf_start
;
8942 sljit_uw addr
= (sljit_uw
)&buf
;
8945 addr
= addr
+ 3 - (addr
% 3);
8946 buf_start
= (sljit_u8
*)addr
;
8948 SLJIT_ASSERT((addr
% 3) == 0);
8950 for (i
= 0; i
< (sljit_s32
)sizeof(buf
); i
++)
8954 printf("Run test78\n");
8956 FAILED(!compiler
, "cannot create compiler\n");
8958 sljit_emit_enter(compiler
, 0, SLJIT_ARGS0(W
), SLJIT_NUMBER_OF_REGISTERS
, 0, 0, 0, 0);
8961 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++, addr
++) {
8962 if (sljit_get_register_index(SLJIT_R(i
)) == -1)
8965 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, (sljit_sw
)addr
);
8966 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM2(SLJIT_R(i
), SLJIT_R(i
)), 1, SLJIT_IMM
, 88 + i
);
8969 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R0
, 0, SLJIT_IMM
, (sljit_sw
)(addr
* 2 + 1));
8970 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM2(SLJIT_R(i
), SLJIT_R0
), 0, SLJIT_IMM
, 147 + i
);
8973 sljit_emit_op1(compiler
, SLJIT_MOV
, SLJIT_R(i
), 0, SLJIT_IMM
, (sljit_sw
)(addr
* 3 + 2));
8974 sljit_emit_op1(compiler
, SLJIT_MOV_U8
, SLJIT_MEM1(SLJIT_R(i
)), 0, SLJIT_IMM
, 191 + i
);
8977 sljit_emit_return(compiler
, SLJIT_MOV
, SLJIT_R2
, 0);
8979 code
.code
= sljit_generate_code(compiler
);
8981 sljit_free_compiler(compiler
);
8985 for (i
= 0; i
< SLJIT_NUMBER_OF_REGISTERS
; i
++) {
8986 if (sljit_get_register_index(SLJIT_R(i
)) == -1)
8989 FAILED(buf_start
[i
* 3] != 88 + i
, "test78 case 1 failed\n");
8991 FAILED(buf_start
[i
* 3 + 1] != 147 + i
, "test78 case 2 failed\n");
8993 FAILED(buf_start
[i
* 3 + 2] != 191 + i
, "test78 case 3 failed\n");
8996 sljit_free_code(code
.code
, NULL
);
9001 int sljit_test(int argc
, char* argv
[])
9003 sljit_s32 has_arg
= (argc
>= 2 && argv
[1][0] == '-' && argv
[1][2] == '\0');
9004 verbose
= has_arg
&& argv
[1][1] == 'v';
9005 silent
= has_arg
&& argv
[1][1] == 's';
9007 if (!verbose
&& !silent
)
9008 printf("Pass -v to enable verbose, -s to disable this hint.\n\n");
9010 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
9011 test_exec_allocator();
9092 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
9093 sljit_free_unused_memory_exec();
9096 # define TEST_COUNT 78
9098 printf("SLJIT tests: ");
9099 if (successful_tests
== TEST_COUNT
)
9100 printf("all tests are " COLOR_GREEN
"PASSED" COLOR_DEFAULT
" ");
9102 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
);
9103 printf("on " COLOR_ARCH
"%s" COLOR_DEFAULT
"%s\n", sljit_get_platform_name(), sljit_has_cpu_feature(SLJIT_HAS_FPU
) ? " (with fpu)" : " (without fpu)");
9105 return TEST_COUNT
- successful_tests
;
9111 #pragma warning(pop)