xref: /netbsd-src/sys/external/bsd/sljit/dist/test_src/sljitTest.c (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1 /*
2  *    Stack-less Just-In-Time compiler
3  *
4  *    Copyright 2009-2010 Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without modification, are
7  * permitted provided that the following conditions are met:
8  *
9  *   1. Redistributions of source code must retain the above copyright notice, this list of
10  *      conditions and the following disclaimer.
11  *
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.
15  *
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.
25  */
26 
27 #include "sljitLir.h"
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 
33 union executable_code {
34 	void* code;
35 	sljit_w (SLJIT_CALL *func0)(void);
36 	sljit_w (SLJIT_CALL *func1)(sljit_w a);
37 	sljit_w (SLJIT_CALL *func2)(sljit_w a, sljit_w b);
38 	sljit_w (SLJIT_CALL *func3)(sljit_w a, sljit_w b, sljit_w c);
39 };
40 typedef union executable_code executable_code;
41 
42 static int successful_tests = 0;
43 
44 #define FAILED(cond, text) \
45 	if (SLJIT_UNLIKELY(cond)) { \
46 		printf(text); \
47 		return; \
48 	}
49 
50 #define CHECK(compiler) \
51 	if (sljit_get_compiler_error(compiler) != SLJIT_ERR_COMPILED) { \
52 		printf("Compiler error: %d\n", sljit_get_compiler_error(compiler)); \
53 		sljit_free_compiler(compiler); \
54 		return; \
55 	}
56 
57 static void cond_set(struct sljit_compiler *compiler, int dst, sljit_w dstw, int type)
58 {
59 	/* Testing both sljit_emit_cond_value and sljit_emit_jump. */
60 	struct sljit_jump* jump;
61 	struct sljit_label* label;
62 
63 	sljit_emit_cond_value(compiler, SLJIT_MOV, dst, dstw, type);
64 	jump = sljit_emit_jump(compiler, type);
65 	sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_KEEP_FLAGS, dst, dstw, dst, dstw, SLJIT_IMM, 2);
66 	label = sljit_emit_label(compiler);
67 	sljit_set_label(jump, label);
68 }
69 
70 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
71 
72 #define MALLOC_EXEC(result, size) \
73 	result = SLJIT_MALLOC_EXEC(size); \
74 	if (!result) { \
75 		printf("Cannot allocate executable memory\n"); \
76 		return; \
77 	} \
78 	memset(result, 255, size);
79 
80 static void test_exec_allocator(void)
81 {
82 	/* This is not an sljit test. */
83 	void *ptr1;
84 	void *ptr2;
85 	void *ptr3;
86 
87 	MALLOC_EXEC(ptr1, 32);
88 	MALLOC_EXEC(ptr2, 512);
89 	MALLOC_EXEC(ptr3, 512);
90 	SLJIT_FREE_EXEC(ptr2);
91 	SLJIT_FREE_EXEC(ptr3);
92 	SLJIT_FREE_EXEC(ptr1);
93 	MALLOC_EXEC(ptr1, 262104);
94 	MALLOC_EXEC(ptr2, 32000);
95 	SLJIT_FREE_EXEC(ptr1);
96 	MALLOC_EXEC(ptr1, 262104);
97 	SLJIT_FREE_EXEC(ptr1);
98 	SLJIT_FREE_EXEC(ptr2);
99 	MALLOC_EXEC(ptr1, 512);
100 	MALLOC_EXEC(ptr2, 512);
101 	MALLOC_EXEC(ptr3, 512);
102 	SLJIT_FREE_EXEC(ptr2);
103 	MALLOC_EXEC(ptr2, 512);
104 	SLJIT_FREE_EXEC(ptr3);
105 	SLJIT_FREE_EXEC(ptr1);
106 	SLJIT_FREE_EXEC(ptr2);
107 #if (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK)
108 	/* Just call the global locks. */
109 	sljit_grab_lock();
110 	sljit_release_lock();
111 #endif
112 	printf("Executable allocator: ok\n");
113 }
114 
115 #undef MALLOC_EXEC
116 
117 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
118 
119 static void test1(void)
120 {
121 	/* Enter and return from an sljit function. */
122 	executable_code code;
123 	struct sljit_compiler* compiler = sljit_create_compiler();
124 
125 	FAILED(!compiler, "cannot create compiler\n");
126 
127 	/* 3 arguments passed, 3 arguments used. */
128 	sljit_emit_enter(compiler, 3, 3, 3, 0);
129 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_SAVED_REG2, 0);
130 
131 	SLJIT_ASSERT(sljit_get_generated_code_size(compiler) == 0);
132 	code.code = sljit_generate_code(compiler);
133 	CHECK(compiler);
134 	SLJIT_ASSERT(compiler->error == SLJIT_ERR_COMPILED);
135 	SLJIT_ASSERT(sljit_get_generated_code_size(compiler) > 0);
136 	sljit_free_compiler(compiler);
137 
138 	FAILED(code.func3(3, -21, 86) != -21, "test1 case 1 failed\n");
139 	FAILED(code.func3(4789, 47890, 997) != 47890, "test1 case 2 failed\n");
140 	sljit_free_code(code.code);
141 	printf("test1 ok\n");
142 	successful_tests++;
143 }
144 
145 static void test2(void)
146 {
147 	/* Test mov. */
148 	executable_code code;
149 	struct sljit_compiler* compiler = sljit_create_compiler();
150 	sljit_w buf[6];
151 	static sljit_w data[2] = { 0, -9876 };
152 
153 	FAILED(!compiler, "cannot create compiler\n");
154 
155 	buf[0] = 5678;
156 	buf[1] = 0;
157 	buf[2] = 0;
158 	buf[3] = 0;
159 	buf[4] = 0;
160 	buf[5] = 0;
161 	sljit_emit_enter(compiler, 1, 3, 2, 0);
162 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_UNUSED, 0, SLJIT_MEM0(), (sljit_w)&buf);
163 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 9999);
164 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG1, 0);
165 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
166 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, sizeof(sljit_w));
167 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_TEMPORARY_REG2), 0);
168 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 2);
169 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SAVED_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_TEMPORARY_REG2), 0);
170 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 3);
171 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SAVED_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM0(), (sljit_w)&buf);
172 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, sizeof(sljit_w));
173 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), (sljit_w)&data);
174 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 4 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
175 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, (sljit_w)&buf - 0x12345678);
176 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), 0x12345678);
177 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 5 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
178 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0);
179 
180 	code.code = sljit_generate_code(compiler);
181 	CHECK(compiler);
182 	sljit_free_compiler(compiler);
183 
184 	FAILED(code.func1((sljit_w)&buf) != 9999, "test2 case 1 failed\n");
185 	FAILED(buf[1] != 9999, "test2 case 2 failed\n");
186 	FAILED(buf[2] != 9999, "test2 case 3 failed\n");
187 	FAILED(buf[3] != 5678, "test2 case 4 failed\n");
188 	FAILED(buf[4] != -9876, "test2 case 5 failed\n");
189 	FAILED(buf[5] != 5678, "test2 case 6 failed\n");
190 	sljit_free_code(code.code);
191 	printf("test2 ok\n");
192 	successful_tests++;
193 }
194 
195 static void test3(void)
196 {
197 	/* Test not. */
198 	executable_code code;
199 	struct sljit_compiler* compiler = sljit_create_compiler();
200 	sljit_w buf[5];
201 
202 	FAILED(!compiler, "cannot create compiler\n");
203 	buf[0] = 1234;
204 	buf[1] = 0;
205 	buf[2] = 9876;
206 	buf[3] = 0;
207 	buf[4] = 0x12345678;
208 
209 	sljit_emit_enter(compiler, 1, 3, 1, 0);
210 	sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_UNUSED, 0, SLJIT_MEM0(), (sljit_w)&buf);
211 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
212 	sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM0(), (sljit_w)&buf[1], SLJIT_MEM0(), (sljit_w)&buf[1]);
213 	sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
214 	sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 3, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 2);
215 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, (sljit_w)&buf[4] - 0xff0000 - 0x20);
216 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, (sljit_w)&buf[4] - 0xff0000);
217 	sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), 0xff0000 + 0x20, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), 0xff0000);
218 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
219 
220 	code.code = sljit_generate_code(compiler);
221 	CHECK(compiler);
222 	sljit_free_compiler(compiler);
223 
224 	FAILED(code.func1((sljit_w)&buf) != ~1234, "test3 case 1 failed\n");
225 	FAILED(buf[1] != ~1234, "test3 case 2 failed\n");
226 	FAILED(buf[3] != ~9876, "test3 case 3 failed\n");
227 	FAILED(buf[4] != ~0x12345678, "test3 case 4 failed\n");
228 
229 	sljit_free_code(code.code);
230 	printf("test3 ok\n");
231 	successful_tests++;
232 }
233 
234 static void test4(void)
235 {
236 	/* Test neg. */
237 	executable_code code;
238 	struct sljit_compiler* compiler = sljit_create_compiler();
239 	sljit_w buf[4];
240 
241 	FAILED(!compiler, "cannot create compiler\n");
242 	buf[0] = 0;
243 	buf[1] = 1234;
244 	buf[2] = 0;
245 	buf[3] = 0;
246 
247 	sljit_emit_enter(compiler, 2, 3, 2, 0);
248 	sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
249 	sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 2, SLJIT_SAVED_REG2, 0);
250 	sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM0(), (sljit_w)&buf[0], SLJIT_MEM0(), (sljit_w)&buf[1]);
251 	sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_RETURN_REG, 0, SLJIT_SAVED_REG2, 0);
252 	sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 3, SLJIT_IMM, 299);
253 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
254 
255 	code.code = sljit_generate_code(compiler);
256 	CHECK(compiler);
257 	sljit_free_compiler(compiler);
258 
259 	FAILED(code.func2((sljit_w)&buf, 4567) != -4567, "test4 case 1 failed\n");
260 	FAILED(buf[0] != -1234, "test4 case 2 failed\n");
261 	FAILED(buf[2] != -4567, "test4 case 3 failed\n");
262 	FAILED(buf[3] != -299, "test4 case 4 failed\n");
263 
264 	sljit_free_code(code.code);
265 	printf("test4 ok\n");
266 	successful_tests++;
267 }
268 
269 static void test5(void)
270 {
271 	/* Test add. */
272 	executable_code code;
273 	struct sljit_compiler* compiler = sljit_create_compiler();
274 	sljit_w buf[9];
275 
276 	FAILED(!compiler, "cannot create compiler\n");
277 	buf[0] = 100;
278 	buf[1] = 200;
279 	buf[2] = 300;
280 	buf[3] = 0;
281 	buf[4] = 0;
282 	buf[5] = 0;
283 	buf[6] = 0;
284 	buf[7] = 0;
285 	buf[8] = 313;
286 
287 	sljit_emit_enter(compiler, 1, 3, 2, 0);
288 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_UNUSED, 0, SLJIT_IMM, 16, SLJIT_IMM, 16);
289 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_UNUSED, 0, SLJIT_IMM, 255, SLJIT_IMM, 255);
290 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_UNUSED, 0, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0);
291 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, sizeof(sljit_w));
292 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 50);
293 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG1), 1, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG1), 1, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG1), 0);
294 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, sizeof(sljit_w) + 2);
295 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 50);
296 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
297 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0);
298 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 4, SLJIT_TEMPORARY_REG1, 0);
299 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 50, SLJIT_TEMPORARY_REG2, 0);
300 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_w), SLJIT_IMM, 50, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_w));
301 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0);
302 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_w));
303 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_w), SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_w), SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_w));
304 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_w), SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0);
305 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0x1e7d39f2);
306 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0x23de7c06);
307 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_w), SLJIT_IMM, 0x3d72e452, SLJIT_TEMPORARY_REG2, 0);
308 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_w), SLJIT_IMM, -43, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_w));
309 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1000, SLJIT_TEMPORARY_REG1, 0);
310 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1430);
311 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -99, SLJIT_TEMPORARY_REG1, 0);
312 
313 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0);
314 
315 	code.code = sljit_generate_code(compiler);
316 	CHECK(compiler);
317 	sljit_free_compiler(compiler);
318 
319 	FAILED(code.func1((sljit_w)&buf) != 2437 + 2 * sizeof(sljit_w), "test5 case 1 failed\n");
320 	FAILED(buf[0] != 202 + 2 * sizeof(sljit_w), "test5 case 2 failed\n");
321 	FAILED(buf[2] != 500, "test5 case 3 failed\n");
322 	FAILED(buf[3] != 400, "test5 case 4 failed\n");
323 	FAILED(buf[4] != 200, "test5 case 5 failed\n");
324 	FAILED(buf[5] != 250, "test5 case 6 failed\n");
325 	FAILED(buf[6] != 0x425bb5f8, "test5 case 7 failed\n");
326 	FAILED(buf[7] != 0x5bf01e44, "test5 case 8 failed\n");
327 	FAILED(buf[8] != 270, "test5 case 9 failed\n");
328 
329 	sljit_free_code(code.code);
330 	printf("test5 ok\n");
331 	successful_tests++;
332 }
333 
334 static void test6(void)
335 {
336 	/* Test addc, sub, subc. */
337 	executable_code code;
338 	struct sljit_compiler* compiler = sljit_create_compiler();
339 	sljit_w buf[10];
340 
341 	FAILED(!compiler, "cannot create compiler\n");
342 	buf[0] = 0;
343 	buf[1] = 0;
344 	buf[2] = 0;
345 	buf[3] = 0;
346 	buf[4] = 0;
347 	buf[5] = 0;
348 	buf[6] = 0;
349 	buf[7] = 0;
350 	buf[8] = 0;
351 	buf[9] = 0;
352 
353 	sljit_emit_enter(compiler, 1, 3, 1, 0);
354 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -1);
355 	sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_C, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -1);
356 	sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 0, SLJIT_IMM, 0);
357 	sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_C, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0);
358 	sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_IMM, 4);
359 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 100);
360 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 2, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 50);
361 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_C, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 6000);
362 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 3, SLJIT_IMM, 10);
363 	sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 3, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 3, SLJIT_IMM, 5);
364 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 100);
365 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 2);
366 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 4, SLJIT_TEMPORARY_REG1, 0);
367 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 5000);
368 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 4, SLJIT_TEMPORARY_REG1, 0);
369 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
370 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 5, SLJIT_TEMPORARY_REG2, 0);
371 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 5000);
372 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 6000, SLJIT_TEMPORARY_REG1, 0);
373 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 6, SLJIT_TEMPORARY_REG1, 0);
374 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 100);
375 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 32768);
376 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 7, SLJIT_TEMPORARY_REG2, 0);
377 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -32767);
378 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 8, SLJIT_TEMPORARY_REG2, 0);
379 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x52cd3bf4);
380 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 9, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x3da297c6);
381 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 10);
382 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_C, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 5);
383 	sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 2);
384 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, -2220);
385 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
386 
387 	code.code = sljit_generate_code(compiler);
388 	CHECK(compiler);
389 	sljit_free_compiler(compiler);
390 
391 	FAILED(code.func1((sljit_w)&buf) != 2223, "test6 case 1 failed\n");
392 	FAILED(buf[0] != 1, "test6 case 2 failed\n");
393 	FAILED(buf[1] != 5, "test6 case 3 failed\n");
394 	FAILED(buf[2] != 50, "test6 case 4 failed\n");
395 	FAILED(buf[3] != 4, "test6 case 5 failed\n");
396 	FAILED(buf[4] != 50, "test6 case 6 failed\n");
397 	FAILED(buf[5] != 50, "test6 case 7 failed\n");
398 	FAILED(buf[6] != 1000, "test6 case 8 failed\n");
399 	FAILED(buf[7] != 100 - 32768, "test6 case 9 failed\n");
400 	FAILED(buf[8] != 100 + 32767, "test6 case 10 failed\n");
401 	FAILED(buf[9] != 0x152aa42e, "test6 case 11 failed\n");
402 
403 	sljit_free_code(code.code);
404 	printf("test6 ok\n");
405 	successful_tests++;
406 }
407 
408 static void test7(void)
409 {
410 	/* Test logical operators. */
411 	executable_code code;
412 	struct sljit_compiler* compiler = sljit_create_compiler();
413 	sljit_w buf[8];
414 
415 	FAILED(!compiler, "cannot create compiler\n");
416 	buf[0] = 0xff80;
417 	buf[1] = 0x0f808080;
418 	buf[2] = 0;
419 	buf[3] = 0xaaaaaa;
420 	buf[4] = 0;
421 	buf[5] = 0x4040;
422 	buf[6] = 0;
423 	buf[7] = 0xc43a7f95;
424 
425 	sljit_emit_enter(compiler, 1, 3, 1, 0);
426 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xf0C000);
427 	sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 2, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x308f);
428 	sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w));
429 	sljit_emit_op2(compiler, SLJIT_AND, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 3, SLJIT_IMM, 0xf0f0f0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 3);
430 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xC0F0);
431 	sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 5);
432 	sljit_emit_op2(compiler, SLJIT_OR, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xff0000);
433 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 4, SLJIT_TEMPORARY_REG1, 0);
434 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 0xC0F0);
435 	sljit_emit_op2(compiler, SLJIT_AND, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 5);
436 	sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 5, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 0xff0000);
437 	sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_IMM, 0xFFFFFF, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w));
438 	sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 6, SLJIT_IMM, 0xa56c82c0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 6);
439 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 7);
440 	sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 7, SLJIT_IMM, 0xff00ff00, SLJIT_TEMPORARY_REG1, 0);
441 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xff00ff00);
442 	sljit_emit_op2(compiler, SLJIT_OR, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x0f);
443 	sljit_emit_op2(compiler, SLJIT_AND, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0x888888, SLJIT_TEMPORARY_REG2, 0);
444 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
445 
446 	code.code = sljit_generate_code(compiler);
447 	CHECK(compiler);
448 	sljit_free_compiler(compiler);
449 
450 	FAILED(code.func1((sljit_w)&buf) != 0x8808, "test7 case 1 failed\n");
451 	FAILED(buf[0] != 0x0F807F00, "test7 case 2 failed\n");
452 	FAILED(buf[1] != 0x0F7F7F7F, "test7 case 3 failed\n");
453 	FAILED(buf[2] != 0x00F0F08F, "test7 case 4 failed\n");
454 	FAILED(buf[3] != 0x00A0A0A0, "test7 case 5 failed\n");
455 	FAILED(buf[4] != 0x00FF80B0, "test7 case 6 failed\n");
456 	FAILED(buf[5] != 0x00FF4040, "test7 case 7 failed\n");
457 	FAILED(buf[6] != 0xa56c82c0, "test7 case 8 failed\n");
458 	FAILED(buf[7] != 0x3b3a8095, "test7 case 9 failed\n");
459 
460 	sljit_free_code(code.code);
461 	printf("test7 ok\n");
462 	successful_tests++;
463 }
464 
465 static void test8(void)
466 {
467 	/* Test flags (neg, cmp, test). */
468 	executable_code code;
469 	struct sljit_compiler* compiler = sljit_create_compiler();
470 	sljit_w buf[20];
471 
472 	FAILED(!compiler, "cannot create compiler\n");
473 	buf[0] = 100;
474 	buf[1] = 3;
475 	buf[2] = 3;
476 	buf[3] = 3;
477 	buf[4] = 3;
478 	buf[5] = 3;
479 	buf[6] = 3;
480 	buf[7] = 3;
481 	buf[8] = 3;
482 	buf[9] = 3;
483 
484 	sljit_emit_enter(compiler, 1, 3, 2, 0);
485 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 20);
486 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 10);
487 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_IMM, 6, SLJIT_IMM, 5);
488 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_C_NOT_EQUAL);
489 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 2, SLJIT_C_EQUAL);
490 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 3000);
491 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_SAVED_REG2, 0, SLJIT_C_GREATER);
492 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 3, SLJIT_SAVED_REG2, 0);
493 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_C_LESS);
494 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 4, SLJIT_TEMPORARY_REG3, 0);
495 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -15);
496 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_C_SIG_GREATER);
497 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 5, SLJIT_TEMPORARY_REG3, 0);
498 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
499 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0);
500 	sljit_emit_op1(compiler, SLJIT_NEG | SLJIT_SET_E | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_IMM, (sljit_w)1 << ((sizeof(sljit_w) << 3) - 1));
501 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 6, SLJIT_C_OVERFLOW);
502 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -1);
503 	sljit_emit_op1(compiler, SLJIT_NOT | SLJIT_SET_E, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0);
504 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 7, SLJIT_C_ZERO);
505 	sljit_emit_op1(compiler, SLJIT_NOT | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG2, 0);
506 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 8, SLJIT_C_ZERO);
507 	sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_IMM, 0xffff, SLJIT_TEMPORARY_REG1, 0);
508 	sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xffff);
509 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 9, SLJIT_C_NOT_ZERO);
510 	sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_IMM, 0xffff, SLJIT_TEMPORARY_REG2, 0);
511 	sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0xffff);
512 	sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG2, 0);
513 	sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
514 	sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
515 	sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 0x1);
516 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 10, SLJIT_C_NOT_ZERO);
517 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
518 
519 	code.code = sljit_generate_code(compiler);
520 	CHECK(compiler);
521 	sljit_free_compiler(compiler);
522 
523 	code.func1((sljit_w)&buf);
524 	FAILED(buf[1] != 1, "test8 case 1 failed\n");
525 	FAILED(buf[2] != 0, "test8 case 2 failed\n");
526 	FAILED(buf[3] != 0, "test8 case 3 failed\n");
527 	FAILED(buf[4] != 1, "test8 case 4 failed\n");
528 	FAILED(buf[5] != 1, "test8 case 5 failed\n");
529 	FAILED(buf[6] != 1, "test8 case 6 failed\n");
530 	FAILED(buf[7] != 1, "test8 case 7 failed\n");
531 	FAILED(buf[8] != 0, "test8 case 8 failed\n");
532 	FAILED(buf[9] != 1, "test8 case 9 failed\n");
533 	FAILED(buf[10] != 0, "test8 case 10 failed\n");
534 
535 	sljit_free_code(code.code);
536 	printf("test8 ok\n");
537 	successful_tests++;
538 }
539 
540 static void test9(void)
541 {
542 	/* Test shift. */
543 	executable_code code;
544 	struct sljit_compiler* compiler = sljit_create_compiler();
545 	sljit_w buf[13];
546 
547 	FAILED(!compiler, "cannot create compiler\n");
548 	buf[0] = 0;
549 	buf[1] = 0;
550 	buf[2] = 0;
551 	buf[3] = 0;
552 	buf[4] = 1 << 10;
553 	buf[5] = 0;
554 	buf[6] = 0;
555 	buf[7] = 0;
556 	buf[8] = 0;
557 	buf[9] = 3;
558 	buf[10] = 0;
559 	buf[11] = 0;
560 	buf[12] = 0;
561 
562 	sljit_emit_enter(compiler, 1, 3, 2, 0);
563 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xf);
564 	sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 3);
565 	sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1);
566 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0);
567 	sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 2);
568 	sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1);
569 	sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);
570 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -64);
571 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 2);
572 	sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 2, SLJIT_TEMPORARY_REG1, 0, SLJIT_PREF_SHIFT_REG, 0);
573 
574 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 0xff);
575 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 4);
576 	sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_PREF_SHIFT_REG, 0, SLJIT_PREF_SHIFT_REG, 0, SLJIT_TEMPORARY_REG1, 0);
577 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 3, SLJIT_PREF_SHIFT_REG, 0);
578 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 0xff);
579 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 8);
580 	sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 4, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 4, SLJIT_TEMPORARY_REG1, 0);
581 	sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 5, SLJIT_PREF_SHIFT_REG, 0, SLJIT_TEMPORARY_REG1, 0);
582 
583 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 0xf);
584 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 2);
585 	sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_TEMPORARY_REG1, 0);
586 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 6, SLJIT_SAVED_REG2, 0);
587 	sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_REG2, 0, SLJIT_TEMPORARY_REG1, 0);
588 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 7, SLJIT_TEMPORARY_REG1, 0);
589 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 0xf00);
590 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 4);
591 	sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG1, 0);
592 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 8, SLJIT_TEMPORARY_REG2, 0);
593 
594 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, (sljit_w)buf);
595 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 9);
596 	sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM2(SLJIT_TEMPORARY_REG1, SLJIT_TEMPORARY_REG2), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_TEMPORARY_REG1, SLJIT_TEMPORARY_REG2), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_TEMPORARY_REG1, SLJIT_TEMPORARY_REG2), SLJIT_WORD_SHIFT);
597 
598 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 4);
599 	sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 2, SLJIT_PREF_SHIFT_REG, 0);
600 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 10, SLJIT_PREF_SHIFT_REG, 0);
601 
602 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xa9);
603 	sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
604 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x7d00);
605 	sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_INT_OP, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 32);
606 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
607 	sljit_emit_op2(compiler, SLJIT_AND, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xffffffff);
608 #endif
609 	sljit_emit_op2(compiler, SLJIT_OR, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0);
610 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xe30000);
611 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
612 	sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xffc0);
613 #else
614 	sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xffe0);
615 #endif
616 	sljit_emit_op2(compiler, SLJIT_OR, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0);
617 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x25000000);
618 	sljit_emit_op2(compiler, SLJIT_SHL | SLJIT_INT_OP, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xfffe1);
619 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
620 	sljit_emit_op2(compiler, SLJIT_AND, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xffffffff);
621 #endif
622 	sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 11, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0);
623 
624 	SLJIT_ASSERT(SLJIT_TEMPORARY_REG3 == SLJIT_PREF_SHIFT_REG);
625 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 0);
626 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x5c);
627 	sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_PREF_SHIFT_REG, 0);
628 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xf600);
629 	sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_INT_OP, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_PREF_SHIFT_REG, 0);
630 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
631 	sljit_emit_op2(compiler, SLJIT_AND, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xffffffff);
632 #endif
633 	sljit_emit_op2(compiler, SLJIT_OR, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0);
634 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x630000);
635 	sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_PREF_SHIFT_REG, 0);
636 	sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 12, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0);
637 
638 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
639 
640 	code.code = sljit_generate_code(compiler);
641 	CHECK(compiler);
642 	sljit_free_compiler(compiler);
643 
644 	code.func1((sljit_w)&buf);
645 	FAILED(buf[0] != 0x3c, "test9 case 1 failed\n");
646 	FAILED(buf[1] != 0xf0, "test9 case 2 failed\n");
647 	FAILED(buf[2] != -16, "test9 case 3 failed\n");
648 	FAILED(buf[3] != 0xff0, "test9 case 4 failed\n");
649 	FAILED(buf[4] != 4, "test9 case 5 failed\n");
650 	FAILED(buf[5] != 0xff00, "test9 case 6 failed\n");
651 	FAILED(buf[6] != 0x3c, "test9 case 7 failed\n");
652 	FAILED(buf[7] != 0xf0, "test9 case 8 failed\n");
653 	FAILED(buf[8] != 0xf0, "test9 case 9 failed\n");
654 	FAILED(buf[9] != 0x18, "test9 case 10 failed\n");
655 	FAILED(buf[10] != 32, "test9 case 11 failed\n");
656 	FAILED(buf[11] != 0x4ae37da9, "test9 case 12 failed\n");
657 	FAILED(buf[12] != 0x63f65c, "test9 case 13 failed\n");
658 
659 	sljit_free_code(code.code);
660 	printf("test9 ok\n");
661 	successful_tests++;
662 }
663 
664 static void test10(void)
665 {
666 	/* Test multiplications. */
667 	executable_code code;
668 	struct sljit_compiler* compiler = sljit_create_compiler();
669 	sljit_w buf[6];
670 
671 	FAILED(!compiler, "cannot create compiler\n");
672 	buf[0] = 3;
673 	buf[1] = 0;
674 	buf[2] = 0;
675 	buf[3] = 6;
676 	buf[4] = -10;
677 	buf[5] = 0;
678 
679 	sljit_emit_enter(compiler, 1, 3, 1, 0);
680 
681 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 5);
682 	sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0);
683 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0);
684 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 7);
685 	sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 8);
686 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
687 	sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -3, SLJIT_IMM, -4);
688 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 2, SLJIT_TEMPORARY_REG1, 0);
689 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -2);
690 	sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 3, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 3, SLJIT_TEMPORARY_REG1, 0);
691 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, sizeof(sljit_w) / 2);
692 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, (sljit_w)&buf[3]);
693 	sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM2(SLJIT_TEMPORARY_REG2, SLJIT_TEMPORARY_REG1), 1, SLJIT_MEM2(SLJIT_TEMPORARY_REG2, SLJIT_TEMPORARY_REG1), 1, SLJIT_MEM2(SLJIT_TEMPORARY_REG2, SLJIT_TEMPORARY_REG1), 1);
694 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 9);
695 	sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0);
696 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 5, SLJIT_TEMPORARY_REG1, 0);
697 	sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 11, SLJIT_IMM, 10);
698 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
699 
700 	code.code = sljit_generate_code(compiler);
701 	CHECK(compiler);
702 	sljit_free_compiler(compiler);
703 
704 	FAILED(code.func1((sljit_w)&buf) != 110, "test10 case 1 failed\n");
705 	FAILED(buf[0] != 15, "test10 case 2 failed\n");
706 	FAILED(buf[1] != 56, "test10 case 3 failed\n");
707 	FAILED(buf[2] != 12, "test10 case 4 failed\n");
708 	FAILED(buf[3] != -12, "test10 case 5 failed\n");
709 	FAILED(buf[4] != 100, "test10 case 6 failed\n");
710 	FAILED(buf[5] != 81, "test10 case 7 failed\n");
711 
712 	sljit_free_code(code.code);
713 	printf("test10 ok\n");
714 	successful_tests++;
715 }
716 
717 static void test11(void)
718 {
719 	/* Test rewritable constants. */
720 	executable_code code;
721 	struct sljit_compiler* compiler = sljit_create_compiler();
722 	struct sljit_const* const1;
723 	struct sljit_const* const2;
724 	struct sljit_const* const3;
725 	struct sljit_const* const4;
726 	void* value;
727 	sljit_uw const1_addr;
728 	sljit_uw const2_addr;
729 	sljit_uw const3_addr;
730 	sljit_uw const4_addr;
731 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
732 	sljit_w word_value1 = SLJIT_W(0xaaaaaaaaaaaaaaaa);
733 	sljit_w word_value2 = SLJIT_W(0xfee1deadfbadf00d);
734 #else
735 	sljit_w word_value1 = 0xaaaaaaaal;
736 	sljit_w word_value2 = 0xfbadf00dl;
737 #endif
738 	sljit_w buf[3];
739 
740 	FAILED(!compiler, "cannot create compiler\n");
741 	buf[0] = 0;
742 	buf[1] = 0;
743 	buf[2] = 0;
744 
745 	sljit_emit_enter(compiler, 1, 3, 1, 0);
746 
747 	const1 = sljit_emit_const(compiler, SLJIT_MEM0(), (sljit_w)&buf[0], -0x81b9);
748 	SLJIT_ASSERT(!sljit_alloc_memory(compiler, 0));
749 	SLJIT_ASSERT(!sljit_alloc_memory(compiler, 16 * sizeof(sljit_w) + 1));
750 	value = sljit_alloc_memory(compiler, 16 * sizeof(sljit_w));
751 	SLJIT_ASSERT(!((sljit_w)value & (sizeof(sljit_w) - 1)));
752 	memset(value, 255, 16 * sizeof(sljit_w));
753 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 2);
754 	const2 = sljit_emit_const(compiler, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG1), SLJIT_WORD_SHIFT - 1, -65535);
755 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, (sljit_w)&buf[0] + 2 * sizeof(sljit_w) - 2);
756 	const3 = sljit_emit_const(compiler, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), 0, word_value1);
757 	value = sljit_alloc_memory(compiler, 17);
758 	SLJIT_ASSERT(!((sljit_w)value & (sizeof(sljit_w) - 1)));
759 	memset(value, 255, 16);
760 	const4 = sljit_emit_const(compiler, SLJIT_RETURN_REG, 0, 0xf7afcdb7);
761 
762 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
763 
764 	code.code = sljit_generate_code(compiler);
765 	CHECK(compiler);
766 	const1_addr = sljit_get_const_addr(const1);
767 	const2_addr = sljit_get_const_addr(const2);
768 	const3_addr = sljit_get_const_addr(const3);
769 	const4_addr = sljit_get_const_addr(const4);
770 	sljit_free_compiler(compiler);
771 
772 	FAILED(code.func1((sljit_w)&buf) != 0xf7afcdb7, "test11 case 1 failed\n");
773 	FAILED(buf[0] != -0x81b9, "test11 case 2 failed\n");
774 	FAILED(buf[1] != -65535, "test11 case 3 failed\n");
775 	FAILED(buf[2] != word_value1, "test11 case 4 failed\n");
776 
777 	sljit_set_const(const1_addr, -1);
778 	sljit_set_const(const2_addr, word_value2);
779 	sljit_set_const(const3_addr, 0xbab0fea1);
780 	sljit_set_const(const4_addr, -60089);
781 
782 	FAILED(code.func1((sljit_w)&buf) != -60089, "test11 case 5 failed\n");
783 	FAILED(buf[0] != -1, "test11 case 6 failed\n");
784 	FAILED(buf[1] != word_value2, "test11 case 7 failed\n");
785 	FAILED(buf[2] != 0xbab0fea1, "test11 case 8 failed\n");
786 
787 	sljit_free_code(code.code);
788 	printf("test11 ok\n");
789 	successful_tests++;
790 }
791 
792 static void test12(void)
793 {
794 	/* Test rewriteable jumps. */
795 	executable_code code;
796 	struct sljit_compiler* compiler = sljit_create_compiler();
797 	struct sljit_label *label1;
798 	struct sljit_label *label2;
799 	struct sljit_label *label3;
800 	struct sljit_jump *jump1;
801 	struct sljit_jump *jump2;
802 	struct sljit_jump *jump3;
803 	void* value;
804 	sljit_uw jump1_addr;
805 	sljit_uw label1_addr;
806 	sljit_uw label2_addr;
807 	sljit_w buf[1];
808 
809 	FAILED(!compiler, "cannot create compiler\n");
810 	buf[0] = 0;
811 
812 	sljit_emit_enter(compiler, 2, 3, 2, 0);
813 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 10);
814 	jump1 = sljit_emit_jump(compiler, SLJIT_REWRITABLE_JUMP | SLJIT_C_SIG_GREATER);
815 	/* Default handler. */
816 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 5);
817 	jump2 = sljit_emit_jump(compiler, SLJIT_JUMP);
818 	value = sljit_alloc_memory(compiler, 15);
819 	SLJIT_ASSERT(!((sljit_w)value & (sizeof(sljit_w) - 1)));
820 	memset(value, 255, 15);
821 	/* Handler 1. */
822 	label1 = sljit_emit_label(compiler);
823 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 6);
824 	jump3 = sljit_emit_jump(compiler, SLJIT_JUMP);
825 	/* Handler 2. */
826 	label2 = sljit_emit_label(compiler);
827 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 7);
828 	/* Exit. */
829 	label3 = sljit_emit_label(compiler);
830 	sljit_set_label(jump2, label3);
831 	sljit_set_label(jump3, label3);
832 	/* By default, set to handler 1. */
833 	sljit_set_label(jump1, label1);
834 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
835 
836 	value = sljit_alloc_memory(compiler, 8);
837 	SLJIT_ASSERT(!((sljit_w)value & (sizeof(sljit_w) - 1)));
838 	memset(value, 255, 8);
839 
840 	code.code = sljit_generate_code(compiler);
841 	CHECK(compiler);
842 	jump1_addr = sljit_get_jump_addr(jump1);
843 	label1_addr = sljit_get_label_addr(label1);
844 	label2_addr = sljit_get_label_addr(label2);
845 	sljit_free_compiler(compiler);
846 
847 	code.func2((sljit_w)&buf, 4);
848 	FAILED(buf[0] != 5, "test12 case 1 failed\n");
849 
850 	code.func2((sljit_w)&buf, 11);
851 	FAILED(buf[0] != 6, "test12 case 2 failed\n");
852 
853 	sljit_set_jump_addr(jump1_addr, label2_addr);
854 	code.func2((sljit_w)&buf, 12);
855 	FAILED(buf[0] != 7, "test12 case 3 failed\n");
856 
857 	sljit_set_jump_addr(jump1_addr, label1_addr);
858 	code.func2((sljit_w)&buf, 13);
859 	FAILED(buf[0] != 6, "test12 case 4 failed\n");
860 
861 	sljit_free_code(code.code);
862 	printf("test12 ok\n");
863 	successful_tests++;
864 }
865 
866 static void test13(void)
867 {
868 	/* Test fpu monadic functions. */
869 	executable_code code;
870 	struct sljit_compiler* compiler = sljit_create_compiler();
871 	double buf[7];
872 	sljit_w buf2[6];
873 
874 	if (!sljit_is_fpu_available()) {
875 		printf("no fpu available, test13 skipped\n");
876 		successful_tests++;
877 		if (compiler)
878 			sljit_free_compiler(compiler);
879 		return;
880 	}
881 
882 	FAILED(!compiler, "cannot create compiler\n");
883 	buf[0] = 7.75;
884 	buf[1] = -4.5;
885 	buf[2] = 0.0;
886 	buf[3] = 0.0;
887 	buf[4] = 0.0;
888 	buf[5] = 0.0;
889 	buf[6] = 0.0;
890 
891 	buf2[0] = 10;
892 	buf2[1] = 10;
893 	buf2[2] = 10;
894 	buf2[3] = 10;
895 	buf2[4] = 10;
896 	buf2[5] = 10;
897 
898 	sljit_emit_enter(compiler, 2, 3, 2, 0);
899 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_MEM0(), (sljit_w)&buf[2], SLJIT_MEM0(), (sljit_w)&buf[1]);
900 	sljit_emit_fop1(compiler, SLJIT_FABS, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(double), SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double));
901 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_FLOAT_REG1, 0, SLJIT_MEM0(), (sljit_w)&buf[0]);
902 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 2 * sizeof(double));
903 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_FLOAT_REG2, 0, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG1), 0);
904 	sljit_emit_fop1(compiler, SLJIT_FNEG, SLJIT_FLOAT_REG3, 0, SLJIT_FLOAT_REG1, 0);
905 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_FLOAT_REG4, 0, SLJIT_FLOAT_REG3, 0);
906 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_MEM0(), (sljit_w)&buf[4], SLJIT_FLOAT_REG4, 0);
907 	sljit_emit_fop1(compiler, SLJIT_FABS, SLJIT_FLOAT_REG3, 0, SLJIT_FLOAT_REG2, 0);
908 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(double), SLJIT_FLOAT_REG3, 0);
909 	sljit_emit_fop1(compiler, SLJIT_FNEG, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(double), SLJIT_FLOAT_REG3, 0);
910 
911 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
912 	sljit_emit_fop1(compiler, SLJIT_FCMP | SLJIT_SET_S, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double));
913 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 0, SLJIT_C_FLOAT_GREATER);
914 	sljit_emit_fop1(compiler, SLJIT_FCMP | SLJIT_SET_S, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double), SLJIT_FLOAT_REG2, 0);
915 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_w), SLJIT_C_FLOAT_GREATER);
916 	sljit_emit_fop1(compiler, SLJIT_FCMP | SLJIT_SET_E | SLJIT_SET_S, SLJIT_FLOAT_REG2, 0, SLJIT_FLOAT_REG2, 0);
917 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 2 * sizeof(sljit_w), SLJIT_C_FLOAT_EQUAL);
918 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 3 * sizeof(sljit_w), SLJIT_C_FLOAT_LESS);
919 	sljit_emit_fop1(compiler, SLJIT_FCMP | SLJIT_SET_E, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double));
920 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 4 * sizeof(sljit_w), SLJIT_C_FLOAT_EQUAL);
921 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 5 * sizeof(sljit_w), SLJIT_C_FLOAT_NOT_EQUAL);
922 
923 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
924 
925 	code.code = sljit_generate_code(compiler);
926 	CHECK(compiler);
927 	sljit_free_compiler(compiler);
928 
929 	code.func2((sljit_w)&buf, (sljit_w)&buf2);
930 	FAILED(buf[2] != -4.5, "test13 case 1 failed\n");
931 	FAILED(buf[3] != 4.5, "test13 case 2 failed\n");
932 	FAILED(buf[4] != -7.75, "test13 case 3 failed\n");
933 	FAILED(buf[5] != 4.5, "test13 case 4 failed\n");
934 	FAILED(buf[6] != -4.5, "test13 case 5 failed\n");
935 
936 	FAILED(buf2[0] != 1, "test13 case 6 failed\n");
937 	FAILED(buf2[1] != 0, "test13 case 7 failed\n");
938 	FAILED(buf2[2] != 1, "test13 case 8 failed\n");
939 	FAILED(buf2[3] != 0, "test13 case 9 failed\n");
940 	FAILED(buf2[4] != 0, "test13 case 10 failed\n");
941 	FAILED(buf2[5] != 1, "test13 case 11 failed\n");
942 
943 	sljit_free_code(code.code);
944 	printf("test13 ok\n");
945 	successful_tests++;
946 }
947 
948 static void test14(void)
949 {
950 	/* Test fpu diadic functions. */
951 	executable_code code;
952 	struct sljit_compiler* compiler = sljit_create_compiler();
953 	double buf[15];
954 
955 	if (!sljit_is_fpu_available()) {
956 		printf("no fpu available, test14 skipped\n");
957 		successful_tests++;
958 		if (compiler)
959 			sljit_free_compiler(compiler);
960 		return;
961 	}
962 	buf[0] = 7.25;
963 	buf[1] = 3.5;
964 	buf[2] = 1.75;
965 	buf[3] = 0.0;
966 	buf[4] = 0.0;
967 	buf[5] = 0.0;
968 	buf[6] = 0.0;
969 	buf[7] = 0.0;
970 	buf[8] = 0.0;
971 	buf[9] = 0.0;
972 	buf[10] = 0.0;
973 	buf[11] = 0.0;
974 	buf[12] = 8.0;
975 	buf[13] = 4.0;
976 	buf[14] = 0.0;
977 
978 	FAILED(!compiler, "cannot create compiler\n");
979 	sljit_emit_enter(compiler, 1, 3, 1, 0);
980 
981 	/* ADD */
982 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, sizeof(double));
983 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_FLOAT_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double));
984 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 2);
985 	sljit_emit_fop2(compiler, SLJIT_FADD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 3, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
986 	sljit_emit_fop2(compiler, SLJIT_FADD, SLJIT_FLOAT_REG1, 0, SLJIT_FLOAT_REG1, 0, SLJIT_FLOAT_REG2, 0);
987 	sljit_emit_fop2(compiler, SLJIT_FADD, SLJIT_FLOAT_REG2, 0, SLJIT_FLOAT_REG1, 0, SLJIT_FLOAT_REG2, 0);
988 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 4, SLJIT_FLOAT_REG1, 0);
989 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 5, SLJIT_FLOAT_REG2, 0);
990 
991 	/* SUB */
992 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_FLOAT_REG3, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
993 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_FLOAT_REG4, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 2);
994 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 2);
995 	sljit_emit_fop2(compiler, SLJIT_FSUB, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 6, SLJIT_FLOAT_REG4, 0, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG2), SLJIT_FLOAT_SHIFT);
996 	sljit_emit_fop2(compiler, SLJIT_FSUB, SLJIT_FLOAT_REG3, 0, SLJIT_FLOAT_REG3, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 2);
997 	sljit_emit_fop2(compiler, SLJIT_FSUB, SLJIT_FLOAT_REG4, 0, SLJIT_FLOAT_REG3, 0, SLJIT_FLOAT_REG4, 0);
998 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 7, SLJIT_FLOAT_REG3, 0);
999 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 8, SLJIT_FLOAT_REG4, 0);
1000 
1001 	/* MUL */
1002 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);
1003 	sljit_emit_fop2(compiler, SLJIT_FMUL, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 9, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG2), SLJIT_FLOAT_SHIFT, SLJIT_FLOAT_REG2, 0);
1004 	sljit_emit_fop2(compiler, SLJIT_FMUL, SLJIT_FLOAT_REG2, 0, SLJIT_FLOAT_REG2, 0, SLJIT_FLOAT_REG3, 0);
1005 	sljit_emit_fop2(compiler, SLJIT_FMUL, SLJIT_FLOAT_REG3, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 2, SLJIT_FLOAT_REG3, 0);
1006 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 10, SLJIT_FLOAT_REG2, 0);
1007 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 11, SLJIT_FLOAT_REG3, 0);
1008 
1009 	/* DIV */
1010 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_FLOAT_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 12);
1011 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 13);
1012 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_FLOAT_REG3, 0, SLJIT_FLOAT_REG1, 0);
1013 	sljit_emit_fop2(compiler, SLJIT_FDIV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 12, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 12, SLJIT_FLOAT_REG2, 0);
1014 	sljit_emit_fop2(compiler, SLJIT_FDIV, SLJIT_FLOAT_REG1, 0, SLJIT_FLOAT_REG1, 0, SLJIT_FLOAT_REG2, 0);
1015 	sljit_emit_fop2(compiler, SLJIT_FDIV, SLJIT_FLOAT_REG3, 0, SLJIT_FLOAT_REG2, 0, SLJIT_FLOAT_REG3, 0);
1016 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 13, SLJIT_FLOAT_REG1, 0);
1017 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(double) * 14, SLJIT_FLOAT_REG3, 0);
1018 
1019 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1020 
1021 	code.code = sljit_generate_code(compiler);
1022 	CHECK(compiler);
1023 	sljit_free_compiler(compiler);
1024 
1025 	code.func1((sljit_w)&buf);
1026 	FAILED(buf[3] != 10.75, "test14 case 1 failed\n");
1027 	FAILED(buf[4] != 5.25, "test14 case 2 failed\n");
1028 	FAILED(buf[5] != 7.0, "test14 case 3 failed\n");
1029 	FAILED(buf[6] != 0.0, "test14 case 4 failed\n");
1030 	FAILED(buf[7] != 5.5, "test14 case 5 failed\n");
1031 	FAILED(buf[8] != 3.75, "test14 case 6 failed\n");
1032 	FAILED(buf[9] != 24.5, "test14 case 7 failed\n");
1033 	FAILED(buf[10] != 38.5, "test14 case 8 failed\n");
1034 	FAILED(buf[11] != 9.625, "test14 case 9 failed\n");
1035 	FAILED(buf[12] != 2.0, "test14 case 10 failed\n");
1036 	FAILED(buf[13] != 2.0, "test14 case 11 failed\n");
1037 	FAILED(buf[14] != 0.5, "test14 case 11 failed\n");
1038 
1039 	sljit_free_code(code.code);
1040 	printf("test14 ok\n");
1041 	successful_tests++;
1042 }
1043 
1044 static sljit_w SLJIT_CALL func(sljit_w a, sljit_w b, sljit_w c)
1045 {
1046 	return a + b + c + 5;
1047 }
1048 
1049 static void test15(void)
1050 {
1051 	/* Test function call. */
1052 	executable_code code;
1053 	struct sljit_compiler* compiler = sljit_create_compiler();
1054 	struct sljit_jump* jump;
1055 	sljit_w buf[7];
1056 
1057 	FAILED(!compiler, "cannot create compiler\n");
1058 	buf[0] = 0;
1059 	buf[1] = 0;
1060 	buf[2] = 0;
1061 	buf[3] = 0;
1062 	buf[4] = 0;
1063 	buf[5] = 0;
1064 	buf[6] = SLJIT_FUNC_OFFSET(func);
1065 
1066 	sljit_emit_enter(compiler, 1, 4, 1, 0);
1067 
1068 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 5);
1069 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 7);
1070 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, -3);
1071 	sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1072 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_RETURN_REG, 0);
1073 
1074 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -5);
1075 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, -10);
1076 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2);
1077 	jump = sljit_emit_jump(compiler, SLJIT_CALL3 | SLJIT_REWRITABLE_JUMP);
1078 	sljit_set_target(jump, (sljit_w)-1);
1079 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_RETURN_REG, 0);
1080 
1081 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1082 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 40);
1083 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, -3);
1084 	sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_TEMPORARY_REG1, 0);
1085 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_w), SLJIT_RETURN_REG, 0);
1086 
1087 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -60);
1088 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1089 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, -30);
1090 	sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_TEMPORARY_REG2, 0);
1091 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_w), SLJIT_RETURN_REG, 0);
1092 
1093 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 10);
1094 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 16);
1095 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1096 	sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_TEMPORARY_REG3, 0);
1097 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_w), SLJIT_RETURN_REG, 0);
1098 
1099 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 100);
1100 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 110);
1101 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 120);
1102 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG1, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1103 	sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_TEMPORARY_EREG1, 0);
1104 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_w), SLJIT_RETURN_REG, 0);
1105 
1106 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -10);
1107 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, -16);
1108 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 6);
1109 	sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_w));
1110 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_w), SLJIT_RETURN_REG, 0);
1111 
1112 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1113 
1114 	code.code = sljit_generate_code(compiler);
1115 	CHECK(compiler);
1116 	sljit_set_jump_addr(sljit_get_jump_addr(jump), SLJIT_FUNC_OFFSET(func));
1117 	sljit_free_compiler(compiler);
1118 
1119 	FAILED(code.func1((sljit_w)&buf) != -15, "test15 case 1 failed\n");
1120 	FAILED(buf[0] != 14, "test15 case 2 failed\n");
1121 	FAILED(buf[1] != -8, "test15 case 3 failed\n");
1122 	FAILED(buf[2] != SLJIT_FUNC_OFFSET(func) + 42, "test15 case 4 failed\n");
1123 	FAILED(buf[3] != SLJIT_FUNC_OFFSET(func) - 85, "test15 case 5 failed\n");
1124 	FAILED(buf[4] != SLJIT_FUNC_OFFSET(func) + 31, "test15 case 6 failed\n");
1125 	FAILED(buf[5] != 335, "test15 case 7 failed\n");
1126 	FAILED(buf[6] != -15, "test15 case 8 failed\n");
1127 
1128 	sljit_free_code(code.code);
1129 	printf("test15 ok\n");
1130 	successful_tests++;
1131 }
1132 
1133 static void test16(void)
1134 {
1135 	/* Ackermann benchmark. */
1136 	executable_code code;
1137 	struct sljit_compiler* compiler = sljit_create_compiler();
1138 	struct sljit_label *entry;
1139 	struct sljit_label *label;
1140 	struct sljit_jump *jump;
1141 	struct sljit_jump *jump1;
1142 	struct sljit_jump *jump2;
1143 
1144 	FAILED(!compiler, "cannot create compiler\n");
1145 
1146 	entry = sljit_emit_label(compiler);
1147 	sljit_emit_enter(compiler, 2, 3, 2, 0);
1148 	/* If x == 0. */
1149 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 0);
1150 	jump1 = sljit_emit_jump(compiler, SLJIT_C_EQUAL);
1151 	/* If y == 0. */
1152 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 0);
1153 	jump2 = sljit_emit_jump(compiler, SLJIT_C_EQUAL);
1154 
1155 	/* Ack(x,y-1). */
1156 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_REG1, 0);
1157 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);
1158 	jump = sljit_emit_jump(compiler, SLJIT_CALL2);
1159 	sljit_set_label(jump, entry);
1160 
1161 	/* Returns with Ack(x-1, Ack(x,y-1)). */
1162 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_RETURN_REG, 0);
1163 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 1);
1164 	jump = sljit_emit_jump(compiler, SLJIT_CALL2);
1165 	sljit_set_label(jump, entry);
1166 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1167 
1168 	/* Returns with y+1. */
1169 	label = sljit_emit_label(compiler);
1170 	sljit_set_label(jump1, label);
1171 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1, SLJIT_SAVED_REG2, 0);
1172 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1173 
1174 	/* Returns with Ack(x-1,1) */
1175 	label = sljit_emit_label(compiler);
1176 	sljit_set_label(jump2, label);
1177 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 1);
1178 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);
1179 	jump = sljit_emit_jump(compiler, SLJIT_CALL2);
1180 	sljit_set_label(jump, entry);
1181 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1182 
1183 	code.code = sljit_generate_code(compiler);
1184 	CHECK(compiler);
1185 	sljit_free_compiler(compiler);
1186 
1187 	FAILED(code.func2(3, 3) != 61, "test16 case 1 failed\n");
1188 	/* For benchmarking. */
1189 	/* FAILED(code.func2(3, 11) != 16381, "test16 case 1 failed\n"); */
1190 
1191 	sljit_free_code(code.code);
1192 	printf("test16 ok\n");
1193 	successful_tests++;
1194 }
1195 
1196 static void test17(void)
1197 {
1198 	/* Test arm constant pool. */
1199 	executable_code code;
1200 	struct sljit_compiler* compiler = sljit_create_compiler();
1201 	int i;
1202 	sljit_w buf[5];
1203 
1204 	FAILED(!compiler, "cannot create compiler\n");
1205 	buf[0] = 0;
1206 	buf[1] = 0;
1207 	buf[2] = 0;
1208 	buf[3] = 0;
1209 	buf[4] = 0;
1210 
1211 	sljit_emit_enter(compiler, 1, 3, 1, 0);
1212 	for (i = 0; i <= 0xfff; i++) {
1213 		sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x81818000 | i);
1214 		sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x81818000 | i);
1215 		if ((i & 0x3ff) == 0)
1216 			sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), (i >> 10) * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
1217 	}
1218 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
1219 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1220 
1221 	code.code = sljit_generate_code(compiler);
1222 	CHECK(compiler);
1223 	sljit_free_compiler(compiler);
1224 
1225 	code.func1((sljit_w)&buf);
1226 	FAILED((sljit_uw)buf[0] != 0x81818000, "test17 case 1 failed\n");
1227 	FAILED((sljit_uw)buf[1] != 0x81818400, "test17 case 2 failed\n");
1228 	FAILED((sljit_uw)buf[2] != 0x81818800, "test17 case 3 failed\n");
1229 	FAILED((sljit_uw)buf[3] != 0x81818c00, "test17 case 4 failed\n");
1230 	FAILED((sljit_uw)buf[4] != 0x81818fff, "test17 case 5 failed\n");
1231 
1232 	sljit_free_code(code.code);
1233 	printf("test17 ok\n");
1234 	successful_tests++;
1235 }
1236 
1237 static void test18(void)
1238 {
1239 	/* Test 64 bit. */
1240 	executable_code code;
1241 	struct sljit_compiler* compiler = sljit_create_compiler();
1242 	sljit_w buf[11];
1243 
1244 	FAILED(!compiler, "cannot create compiler\n");
1245 	buf[0] = 0;
1246 	buf[1] = 0;
1247 	buf[2] = 0;
1248 	buf[3] = 0;
1249 	buf[4] = 0;
1250 	buf[5] = 100;
1251 	buf[6] = 100;
1252 	buf[7] = 100;
1253 	buf[8] = 100;
1254 	buf[9] = 0;
1255 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1256 	buf[10] = SLJIT_W(1) << 32;
1257 #else
1258 	buf[10] = 1;
1259 #endif
1260 
1261 	sljit_emit_enter(compiler, 1, 3, 2, 0);
1262 
1263 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1264 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, SLJIT_W(0x1122334455667788));
1265 	sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_IMM, SLJIT_W(0x1122334455667788));
1266 
1267 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(1000000000000));
1268 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 2, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(1000000000000));
1269 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 3, SLJIT_IMM, SLJIT_W(5000000000000), SLJIT_TEMPORARY_REG1, 0);
1270 
1271 	sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1272 	sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_INT_OP, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 4, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1273 
1274 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1275 	sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1276 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_SAVED_REG2, 0, SLJIT_C_ZERO);
1277 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 5, SLJIT_SAVED_REG2, 0);
1278 	sljit_emit_op2(compiler, SLJIT_AND | SLJIT_INT_OP | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1279 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 6, SLJIT_C_ZERO);
1280 
1281 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1282 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(0x2208080808));
1283 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 7, SLJIT_C_LESS);
1284 	sljit_emit_op2(compiler, SLJIT_AND | SLJIT_INT_OP | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(0x1104040404));
1285 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 8, SLJIT_C_NOT_ZERO);
1286 
1287 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 4);
1288 	sljit_emit_op2(compiler, SLJIT_SHL | SLJIT_INT_OP, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 9, SLJIT_IMM, SLJIT_W(0xffff0000), SLJIT_TEMPORARY_REG1, 0);
1289 
1290 	sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_INT_OP, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 10, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 10, SLJIT_IMM, -1);
1291 #else
1292 	/* 32 bit operations. */
1293 
1294 	sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 0x11223344);
1295 	sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_INT_OP, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_IMM, 0x44332211);
1296 
1297 #endif
1298 
1299 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1300 
1301 	code.code = sljit_generate_code(compiler);
1302 	CHECK(compiler);
1303 	sljit_free_compiler(compiler);
1304 
1305 	code.func1((sljit_w)&buf);
1306 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1307 	FAILED(buf[0] != SLJIT_W(0x1122334455667788), "test18 case 1 failed\n");
1308 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1309 	FAILED(buf[1] != 0x55667788, "test18 case 2 failed\n");
1310 #else
1311 	FAILED(buf[1] != SLJIT_W(0x5566778800000000), "test18 case 2 failed\n");
1312 #endif
1313 	FAILED(buf[2] != SLJIT_W(2000000000000), "test18 case 3 failed\n");
1314 	FAILED(buf[3] != SLJIT_W(4000000000000), "test18 case 4 failed\n");
1315 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1316 	FAILED(buf[4] != 0x28282828, "test18 case 5 failed\n");
1317 #else
1318 	FAILED(buf[4] != SLJIT_W(0x2828282800000000), "test18 case 5 failed\n");
1319 #endif
1320 	FAILED(buf[5] != 0, "test18 case 6 failed\n");
1321 	FAILED(buf[6] != 1, "test18 case 7 failed\n");
1322 	FAILED(buf[7] != 1, "test18 case 8 failed\n");
1323 	FAILED(buf[8] != 0, "test18 case 9 failed\n");
1324 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1325 	FAILED(buf[9] != 0xfff00000, "test18 case 10 failed\n");
1326 	FAILED(buf[10] != 0xffffffff, "test18 case 11 failed\n");
1327 #else
1328 	FAILED(buf[9] != SLJIT_W(0xfff0000000000000), "test18 case 10 failed\n");
1329 	FAILED(buf[10] != SLJIT_W(0xffffffff00000000), "test18 case 11 failed\n");
1330 #endif
1331 #else
1332 	FAILED(buf[0] != 0x11223344, "test18 case 1 failed\n");
1333 	FAILED(buf[1] != 0x44332211, "test18 case 2 failed\n");
1334 #endif
1335 
1336 	sljit_free_code(code.code);
1337 	printf("test18 ok\n");
1338 	successful_tests++;
1339 }
1340 
1341 static void test19(void)
1342 {
1343 	/* Test arm partial instruction caching. */
1344 	executable_code code;
1345 	struct sljit_compiler* compiler = sljit_create_compiler();
1346 	sljit_w buf[10];
1347 
1348 	FAILED(!compiler, "cannot create compiler\n");
1349 	buf[0] = 6;
1350 	buf[1] = 4;
1351 	buf[2] = 0;
1352 	buf[3] = 0;
1353 	buf[4] = 0;
1354 	buf[5] = 0;
1355 	buf[6] = 2;
1356 	buf[7] = 0;
1357 
1358 	sljit_emit_enter(compiler, 1, 3, 1, 0);
1359 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w));
1360 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1361 	SLJIT_ASSERT(compiler->cache_arg == 0);
1362 #endif
1363 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM0(), (sljit_w)&buf[2], SLJIT_MEM0(), (sljit_w)&buf[1], SLJIT_MEM0(), (sljit_w)&buf[0]);
1364 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1365 	SLJIT_ASSERT(compiler->cache_arg > 0);
1366 #endif
1367 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
1368 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, sizeof(sljit_w));
1369 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 3, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), (sljit_w)&buf[0], SLJIT_MEM1(SLJIT_TEMPORARY_REG2), (sljit_w)&buf[0]);
1370 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1371 	SLJIT_ASSERT(compiler->cache_arg > 0);
1372 #endif
1373 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 4, SLJIT_MEM0(), (sljit_w)&buf[0], SLJIT_IMM, 2);
1374 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1375 	SLJIT_ASSERT(compiler->cache_arg > 0);
1376 #endif
1377 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 5, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 2, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), (sljit_w)&buf[0] + 4 * sizeof(sljit_w));
1378 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1379 	SLJIT_ASSERT(compiler->cache_arg > 0);
1380 #endif
1381 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 7, SLJIT_IMM, 10);
1382 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 7);
1383 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), (sljit_w)&buf[5], SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), (sljit_w)&buf[5]);
1384 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1385 	SLJIT_ASSERT(compiler->cache_arg > 0);
1386 #endif
1387 
1388 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1389 
1390 	code.code = sljit_generate_code(compiler);
1391 	CHECK(compiler);
1392 	sljit_free_compiler(compiler);
1393 
1394 	code.func1((sljit_w)&buf);
1395 	FAILED(buf[0] != 10, "test19 case 1 failed\n");
1396 	FAILED(buf[1] != 4, "test19 case 2 failed\n");
1397 	FAILED(buf[2] != 14, "test19 case 3 failed\n");
1398 	FAILED(buf[3] != 14, "test19 case 4 failed\n");
1399 	FAILED(buf[4] != 8, "test19 case 5 failed\n");
1400 	FAILED(buf[5] != 6, "test19 case 6 failed\n");
1401 	FAILED(buf[6] != 12, "test19 case 7 failed\n");
1402 	FAILED(buf[7] != 10, "test19 case 8 failed\n");
1403 
1404 	sljit_free_code(code.code);
1405 	printf("test19 ok\n");
1406 	successful_tests++;
1407 }
1408 
1409 static void test20(void)
1410 {
1411 	/* Test stack. */
1412 	executable_code code;
1413 	struct sljit_compiler* compiler = sljit_create_compiler();
1414 	struct sljit_jump* jump;
1415 	struct sljit_label* label;
1416 	sljit_w buf[6];
1417 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1418 	sljit_w offset_value = SLJIT_W(0x1234567812345678);
1419 #else
1420 	sljit_w offset_value = SLJIT_W(0x12345678);
1421 #endif
1422 
1423 	FAILED(!compiler, "cannot create compiler\n");
1424 	buf[0] = 5;
1425 	buf[1] = 12;
1426 	buf[2] = 0;
1427 	buf[3] = 0;
1428 	buf[4] = 111;
1429 	buf[5] = -12345;
1430 
1431 	sljit_emit_enter(compiler, 1, 5, 5, 4 * sizeof(sljit_w));
1432 
1433 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
1434 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw));
1435 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG1, 0, SLJIT_IMM, -1);
1436 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG2, 0, SLJIT_IMM, -1);
1437 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG1, 0, SLJIT_IMM, -1);
1438 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG2, 0, SLJIT_IMM, -1);
1439 	sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_uw), SLJIT_MEM1(SLJIT_LOCALS_REG), 0, SLJIT_MEM1(SLJIT_LOCALS_REG), sizeof(sljit_uw));
1440 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_uw), SLJIT_MEM1(SLJIT_LOCALS_REG), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_LOCALS_REG), 0);
1441 	sljit_get_local_base(compiler, SLJIT_TEMPORARY_REG1, 0, -offset_value);
1442 	sljit_get_local_base(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, -0x1234);
1443 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
1444 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_uw), SLJIT_MEM1(SLJIT_TEMPORARY_REG1), offset_value, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), 0x1234 + sizeof(sljit_w));
1445 
1446 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_uw));
1447 	/* Dummy last instructions. */
1448 	sljit_emit_const(compiler, SLJIT_TEMPORARY_REG1, 0, -9);
1449 	sljit_emit_label(compiler);
1450 
1451 	code.code = sljit_generate_code(compiler);
1452 	CHECK(compiler);
1453 	sljit_free_compiler(compiler);
1454 
1455 	FAILED(code.func1((sljit_w)&buf) != -12345, "test20 case 1 failed\n")
1456 
1457 	FAILED(buf[2] != 60, "test20 case 2 failed\n");
1458 	FAILED(buf[3] != 17, "test20 case 3 failed\n");
1459 	FAILED(buf[4] != 7, "test20 case 4 failed\n");
1460 	sljit_free_code(code.code);
1461 
1462 	compiler = sljit_create_compiler();
1463 	sljit_emit_enter(compiler, 0, 3, 0, SLJIT_MAX_LOCAL_SIZE);
1464 
1465 	sljit_get_local_base(compiler, SLJIT_TEMPORARY_REG1, 0, SLJIT_MAX_LOCAL_SIZE - sizeof(sljit_w));
1466 	sljit_get_local_base(compiler, SLJIT_TEMPORARY_REG2, 0, -(sljit_w)sizeof(sljit_w));
1467 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, -1);
1468 	label = sljit_emit_label(compiler);
1469 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG3, 0);
1470 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0);
1471 	jump = sljit_emit_jump(compiler, SLJIT_C_NOT_EQUAL);
1472 	sljit_set_label(jump, label);
1473 
1474 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1475 
1476 	code.code = sljit_generate_code(compiler);
1477 	CHECK(compiler);
1478 	sljit_free_compiler(compiler);
1479 
1480 	/* Just survive this code. */
1481 	code.func0();
1482 
1483 	sljit_free_code(code.code);
1484 	printf("test20 ok\n");
1485 	successful_tests++;
1486 }
1487 
1488 static void test21(void)
1489 {
1490 	/* Test fake enter. The parts of the jit code can be separated in the memory. */
1491 	executable_code code1;
1492 	executable_code code2;
1493 	struct sljit_compiler* compiler = sljit_create_compiler();
1494 	struct sljit_jump* jump;
1495 	sljit_uw addr;
1496 	sljit_w buf[4];
1497 
1498 	FAILED(!compiler, "cannot create compiler\n");
1499 	buf[0] = 9;
1500 	buf[1] = -6;
1501 	buf[2] = 0;
1502 	buf[3] = 0;
1503 
1504 	sljit_emit_enter(compiler, 1, 3, 2, 2 * sizeof(sljit_w));
1505 
1506 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), 0, SLJIT_IMM, 10);
1507 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_LOCALS_REG), sizeof(sljit_w), SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_LOCALS_REG), 0);
1508 	jump = sljit_emit_jump(compiler, SLJIT_JUMP | SLJIT_REWRITABLE_JUMP);
1509 	sljit_set_target(jump, 0);
1510 
1511 	code1.code = sljit_generate_code(compiler);
1512 	CHECK(compiler);
1513 	addr = sljit_get_jump_addr(jump);
1514 	sljit_free_compiler(compiler);
1515 
1516 	compiler = sljit_create_compiler();
1517 	FAILED(!compiler, "cannot create compiler\n");
1518 
1519 	/* Other part of the jit code. */
1520 	sljit_set_context(compiler, 1, 3, 2, 2 * sizeof(sljit_w));
1521 
1522 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 2, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_MEM1(SLJIT_LOCALS_REG), 0);
1523 	sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 3, SLJIT_MEM1(SLJIT_LOCALS_REG), 0, SLJIT_MEM1(SLJIT_LOCALS_REG), 0);
1524 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), sizeof(sljit_w));
1525 
1526 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1527 
1528 	code2.code = sljit_generate_code(compiler);
1529 	CHECK(compiler);
1530 	sljit_free_compiler(compiler);
1531 
1532 	sljit_set_jump_addr(addr, SLJIT_FUNC_OFFSET(code2.code));
1533 
1534 	FAILED(code1.func1((sljit_w)&buf) != 19, "test21 case 1 failed\n");
1535 	FAILED(buf[2] != -16, "test21 case 2 failed\n");
1536 	FAILED(buf[3] != 100, "test21 case 3 failed\n");
1537 
1538 	sljit_free_code(code1.code);
1539 	sljit_free_code(code2.code);
1540 	printf("test21 ok\n");
1541 	successful_tests++;
1542 }
1543 
1544 static void test22(void)
1545 {
1546 	/* Test simple byte and half-int data transfers. */
1547 	executable_code code;
1548 	struct sljit_compiler* compiler = sljit_create_compiler();
1549 	sljit_w buf[9];
1550 	short sbuf[7];
1551 	signed char bbuf[5];
1552 
1553 	FAILED(!compiler, "cannot create compiler\n");
1554 	buf[0] = 5;
1555 	buf[1] = 0;
1556 	buf[2] = 0;
1557 	buf[3] = 0;
1558 	buf[4] = 0;
1559 	buf[5] = 0;
1560 	buf[6] = 0;
1561 	buf[7] = 0;
1562 	buf[8] = 0;
1563 
1564 	sbuf[0] = 0;
1565 	sbuf[1] = 0;
1566 	sbuf[2] = -9;
1567 	sbuf[3] = 0;
1568 	sbuf[4] = 0;
1569 	sbuf[5] = 0;
1570 	sbuf[6] = 0;
1571 
1572 	bbuf[0] = 0;
1573 	bbuf[1] = 0;
1574 	bbuf[2] = -56;
1575 	bbuf[3] = 0;
1576 	bbuf[4] = 0;
1577 
1578 	sljit_emit_enter(compiler, 3, 3, 3, 0);
1579 
1580 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_w));
1581 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_SAVED_REG1, 0);
1582 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_IMM, -13);
1583 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), sizeof(sljit_w));
1584 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG3, 0);
1585 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_MEM1(SLJIT_TEMPORARY_REG1), sizeof(sljit_w));
1586 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1);
1587 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM2(SLJIT_TEMPORARY_REG2, SLJIT_TEMPORARY_REG1), SLJIT_WORD_SHIFT, SLJIT_TEMPORARY_REG2, 0);
1588 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, sizeof(sljit_w));
1589 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_TEMPORARY_REG2, SLJIT_TEMPORARY_REG1), 0, SLJIT_TEMPORARY_REG2, 0);
1590 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 2);
1591 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM2(SLJIT_TEMPORARY_REG2, SLJIT_TEMPORARY_REG1), SLJIT_WORD_SHIFT, SLJIT_TEMPORARY_REG2, 0);
1592 
1593 	sljit_emit_op1(compiler, SLJIT_MOV_SH, SLJIT_MEM1(SLJIT_SAVED_REG2), 0, SLJIT_IMM, -13);
1594 	sljit_emit_op1(compiler, SLJIT_MOVU_UH, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(short), SLJIT_IMM, 0x1234);
1595 	sljit_emit_op1(compiler, SLJIT_MOVU_SH, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(short));
1596 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
1597 	sljit_emit_op1(compiler, SLJIT_MOV_UH, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(short), SLJIT_MEM1(SLJIT_SAVED_REG2), -(int)sizeof(short));
1598 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xff0000 + 8000);
1599 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 2);
1600 	sljit_emit_op1(compiler, SLJIT_MOV_SH, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_TEMPORARY_REG2), 1, SLJIT_TEMPORARY_REG1, 0);
1601 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 3);
1602 	sljit_emit_op1(compiler, SLJIT_MOVU_SH, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_TEMPORARY_REG2), 1, SLJIT_TEMPORARY_REG1, 0);
1603 	sljit_emit_op1(compiler, SLJIT_MOV_SH, SLJIT_MEM1(SLJIT_SAVED_REG2), 0, SLJIT_IMM, -9317);
1604 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 5 * sizeof(short));
1605 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -5);
1606 	sljit_emit_op1(compiler, SLJIT_MOV_UH, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM2(SLJIT_TEMPORARY_REG2, SLJIT_TEMPORARY_REG1), 1);
1607 	sljit_emit_op1(compiler, SLJIT_MOV_UH, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(short), SLJIT_TEMPORARY_REG2, 0);
1608 
1609 	sljit_emit_op1(compiler, SLJIT_MOV_SB, SLJIT_MEM1(SLJIT_SAVED_REG3), 0, SLJIT_IMM, -45);
1610 	sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_SAVED_REG3), sizeof(char), SLJIT_IMM, 0x12);
1611 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 2 * sizeof(char));
1612 	sljit_emit_op1(compiler, SLJIT_MOVU_SB, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG3), sizeof(char));
1613 	sljit_emit_op1(compiler, SLJIT_MOV_SB, SLJIT_SAVED_REG2, 0, SLJIT_TEMPORARY_REG2, 0);
1614 	sljit_emit_op1(compiler, SLJIT_MOV_UB, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0);
1615 	sljit_emit_op1(compiler, SLJIT_MOV_SB, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG2, 0);
1616 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_w), SLJIT_TEMPORARY_REG3, 0);
1617 	sljit_emit_op1(compiler, SLJIT_MOV_UB, SLJIT_MEM1(SLJIT_SAVED_REG3), sizeof(char), SLJIT_SAVED_REG2, 0);
1618 	sljit_emit_op1(compiler, SLJIT_MOV_UB, SLJIT_MEM2(SLJIT_SAVED_REG3, SLJIT_TEMPORARY_REG1), 0, SLJIT_TEMPORARY_REG1, 0);
1619 
1620 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1621 
1622 	code.code = sljit_generate_code(compiler);
1623 	CHECK(compiler);
1624 	sljit_free_compiler(compiler);
1625 
1626 	code.func3((sljit_w)&buf, (sljit_w)&sbuf, (sljit_w)&bbuf);
1627 	FAILED(buf[1] != -13, "test22 case 1 failed\n");
1628 	FAILED(buf[2] != 5, "test22 case 2 failed\n");
1629 	FAILED(buf[3] != -13, "test22 case 3 failed\n");
1630 	FAILED(buf[4] != (sljit_w)&buf[3], "test22 case 4 failed\n");
1631 	FAILED(buf[5] != (sljit_w)&buf[4], "test22 case 5 failed\n");
1632 	FAILED(buf[6] != (sljit_w)&buf[4], "test22 case 6 failed\n");
1633 	FAILED(buf[7] != -9, "test22 case 7 failed\n");
1634 	FAILED(buf[8] != -56, "test22 case 8 failed\n");
1635 
1636 	FAILED(sbuf[0] != -13, "test22 case 9 failed\n");
1637 	FAILED(sbuf[1] != 0x1234, "test22 case 10 failed\n");
1638 	FAILED(sbuf[3] != 0x1234, "test22 case 11 failed\n");
1639 	FAILED(sbuf[4] != 8000, "test22 case 12 failed\n");
1640 	FAILED(sbuf[5] != -9317, "test22 case 13 failed\n");
1641 	FAILED(sbuf[6] != -9317, "test22 case 14 failed\n");
1642 
1643 	FAILED(bbuf[0] != -45, "test22 case 15 failed\n");
1644 	FAILED(bbuf[1] != 0x12, "test22 case 16 failed\n");
1645 	FAILED(bbuf[3] != -56, "test22 case 17 failed\n");
1646 	FAILED(bbuf[4] != 2, "test22 case 18 failed\n");
1647 
1648 	sljit_free_code(code.code);
1649 	printf("test22 ok\n");
1650 	successful_tests++;
1651 }
1652 
1653 static void test23(void)
1654 {
1655 	/* Test 32 bit / 64 bit signed / unsigned int transfer and conversion.
1656 	   This test has do real things on 64 bit systems, but works on 32 bit systems as well. */
1657 	executable_code code;
1658 	struct sljit_compiler* compiler = sljit_create_compiler();
1659 	sljit_w buf[9];
1660 	int ibuf[5];
1661 	union {
1662 		int asint;
1663 		sljit_ub asbytes[4];
1664 	} u;
1665 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1666 	sljit_w garbage = SLJIT_W(0x1234567812345678);
1667 #else
1668 	sljit_w garbage = 0x12345678;
1669 #endif
1670 
1671 	FAILED(!compiler, "cannot create compiler\n");
1672 	buf[0] = 0;
1673 	buf[1] = 0;
1674 	buf[2] = 0;
1675 	buf[3] = 0;
1676 	buf[4] = 0;
1677 	buf[5] = 0;
1678 	buf[6] = 0;
1679 	buf[7] = 0;
1680 	buf[8] = 0;
1681 
1682 	ibuf[0] = 0;
1683 	ibuf[1] = 0;
1684 	ibuf[2] = -5791;
1685 	ibuf[3] = 43579;
1686 	ibuf[4] = 658923;
1687 
1688 	sljit_emit_enter(compiler, 2, 3, 3, 0);
1689 	sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_MEM1(SLJIT_SAVED_REG2), 0, SLJIT_IMM, 34567);
1690 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1);
1691 	sljit_emit_op1(compiler, SLJIT_MOVU_SI, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_TEMPORARY_REG1), 2, SLJIT_IMM, -7654);
1692 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, garbage);
1693 	sljit_emit_op1(compiler, SLJIT_MOVU_SI, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(int));
1694 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0);
1695 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, garbage);
1696 	sljit_emit_op1(compiler, SLJIT_MOVU_UI, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(int));
1697 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
1698 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, garbage);
1699 	sljit_emit_op1(compiler, SLJIT_MOV_SI, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(int));
1700 	sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0);
1701 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
1702 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x0f00f00);
1703 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 0x7777);
1704 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), 0x7777 + 2 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
1705 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 0x7777);
1706 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), -0x7777 + (int)sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
1707 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 16 - sizeof(sljit_w));
1708 	sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);
1709 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 16);
1710 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM2(SLJIT_TEMPORARY_REG1, SLJIT_TEMPORARY_REG2), 1, SLJIT_TEMPORARY_REG1, 0);
1711 	sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), 0, SLJIT_IMM, 64, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), 0);
1712 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
1713 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), (sljit_w)&buf[6], SLJIT_MEM0(), (sljit_w)&buf[6]);
1714 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), 0, SLJIT_IMM, 0x123456);
1715 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_w), SLJIT_SAVED_REG1, 0);
1716 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, sizeof(sljit_w));
1717 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 100000 * sizeof(sljit_w));
1718 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), 100001 * sizeof(sljit_w), SLJIT_SAVED_REG1, 0);
1719 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, sizeof(sljit_w));
1720 	sljit_emit_op1(compiler, SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(int), SLJIT_IMM, 0x12345678);
1721 
1722 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0x2bd700 | 243);
1723 	sljit_emit_return(compiler, SLJIT_MOV_SB, SLJIT_TEMPORARY_REG2, 0);
1724 
1725 	code.code = sljit_generate_code(compiler);
1726 	CHECK(compiler);
1727 	sljit_free_compiler(compiler);
1728 
1729 	FAILED(code.func2((sljit_w)&buf, (sljit_w)&ibuf) != -13, "test23 case 1 failed\n");
1730 	FAILED(buf[0] != -5791, "test23 case 2 failed\n");
1731 	FAILED(buf[1] != 43579, "test23 case 3 failed\n");
1732 	FAILED(buf[2] != 658923, "test23 case 4 failed\n");
1733 	FAILED(buf[3] != 0x0f00f00, "test23 case 5 failed\n");
1734 	FAILED(buf[4] != 0x0f00f00, "test23 case 6 failed\n");
1735 	FAILED(buf[5] != 80, "test23 case 7 failed\n");
1736 	FAILED(buf[6] != 0x123456, "test23 case 8 failed\n");
1737 	FAILED(buf[7] != (sljit_w)&buf[5], "test23 case 9 failed\n");
1738 	FAILED(buf[8] != (sljit_w)&buf[8] - 100000 * sizeof(sljit_w), "test23 case 10 failed\n");
1739 
1740 	FAILED(ibuf[0] != 34567, "test23 case 11 failed\n");
1741 	FAILED(ibuf[1] != -7654, "test23 case 12 failed\n");
1742 	u.asint = ibuf[4];
1743 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1744 	FAILED(u.asbytes[0] != 0x78, "test23 case 13 failed\n");
1745 	FAILED(u.asbytes[1] != 0x56, "test23 case 14 failed\n");
1746 	FAILED(u.asbytes[2] != 0x34, "test23 case 15 failed\n");
1747 	FAILED(u.asbytes[3] != 0x12, "test23 case 16 failed\n");
1748 #else
1749 	FAILED(u.asbytes[0] != 0x12, "test23 case 13 failed\n");
1750 	FAILED(u.asbytes[1] != 0x34, "test23 case 14 failed\n");
1751 	FAILED(u.asbytes[2] != 0x56, "test23 case 15 failed\n");
1752 	FAILED(u.asbytes[3] != 0x78, "test23 case 16 failed\n");
1753 #endif
1754 
1755 	sljit_free_code(code.code);
1756 	printf("test23 ok\n");
1757 	successful_tests++;
1758 }
1759 
1760 static void test24(void)
1761 {
1762 	/* Some complicated addressing modes. */
1763 	executable_code code;
1764 	struct sljit_compiler* compiler = sljit_create_compiler();
1765 	sljit_w buf[6];
1766 	short sbuf[5];
1767 	sljit_b bbuf[4];
1768 
1769 	FAILED(!compiler, "cannot create compiler\n");
1770 
1771 	buf[0] = 100567;
1772 	buf[1] = 75799;
1773 	buf[2] = 0;
1774 	buf[3] = -8;
1775 	buf[4] = -50;
1776 	buf[5] = 0;
1777 
1778 	sbuf[0] = 30000;
1779 	sbuf[1] = 0;
1780 	sbuf[2] = 0;
1781 	sbuf[3] = -12345;
1782 	sbuf[4] = 0;
1783 
1784 	bbuf[0] = -128;
1785 	bbuf[1] = 0;
1786 	bbuf[2] = 0;
1787 	bbuf[3] = 99;
1788 
1789 	sljit_emit_enter(compiler, 3, 3, 3, 0);
1790 
1791 	/* Nothing should be updated. */
1792 	sljit_emit_op1(compiler, SLJIT_MOVU_SH, SLJIT_MEM0(), (sljit_w)&sbuf[1], SLJIT_MEM0(), (sljit_w)&sbuf[0]);
1793 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1794 	SLJIT_ASSERT(compiler->cache_arg > 0);
1795 #endif
1796 	sljit_emit_op1(compiler, SLJIT_MOVU_SB, SLJIT_MEM0(), (sljit_w)&bbuf[1], SLJIT_MEM0(), (sljit_w)&bbuf[0]);
1797 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1798 	SLJIT_ASSERT(compiler->cache_arg > 0);
1799 #endif
1800 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 2);
1801 	sljit_emit_op1(compiler, SLJIT_MOV_UH, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_TEMPORARY_REG1), 1, SLJIT_MEM0(), (sljit_w)&sbuf[3]);
1802 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1803 	SLJIT_ASSERT(compiler->cache_arg > 0);
1804 #endif
1805 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, (sljit_w)&buf[0]);
1806 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, sizeof(sljit_w));
1807 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2);
1808 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM2(SLJIT_TEMPORARY_REG1, SLJIT_TEMPORARY_REG3), SLJIT_WORD_SHIFT, SLJIT_MEM0(), (sljit_w)&buf[0], SLJIT_MEM2(SLJIT_TEMPORARY_REG2, SLJIT_TEMPORARY_REG1), 0);
1809 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1810 	SLJIT_ASSERT(compiler->cache_arg > 0);
1811 #endif
1812 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, sizeof(signed char));
1813 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, sizeof(signed char));
1814 	sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), (sljit_w)&bbuf[1], SLJIT_MEM1(SLJIT_TEMPORARY_REG2), (sljit_w)&bbuf[0]);
1815 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1816 	SLJIT_ASSERT(compiler->cache_arg > 0);
1817 #endif
1818 	sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), 2 * sizeof(signed char));
1819 
1820 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, sizeof(short));
1821 	sljit_emit_op1(compiler, SLJIT_MOV_SH, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), (sljit_w)&sbuf[3], SLJIT_TEMPORARY_REG2, 0);
1822 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1823 	SLJIT_ASSERT(compiler->cache_arg == 0);
1824 #endif
1825 
1826 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 3);
1827 	sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG1), SLJIT_WORD_SHIFT);
1828 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1829 	SLJIT_ASSERT(compiler->cache_arg > 0);
1830 #endif
1831 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 4);
1832 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_SAVED_REG1, 0);
1833 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_TEMPORARY_REG2, SLJIT_TEMPORARY_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG1), SLJIT_WORD_SHIFT);
1834 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1835 	SLJIT_ASSERT(compiler->cache_arg > 0);
1836 #endif
1837 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_REG1, 0);
1838 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_w));
1839 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 4);
1840 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM2(SLJIT_TEMPORARY_REG2, SLJIT_TEMPORARY_REG3), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_TEMPORARY_REG1, SLJIT_TEMPORARY_REG3), SLJIT_WORD_SHIFT);
1841 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1842 	SLJIT_ASSERT(compiler->cache_arg > 0);
1843 #endif
1844 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_w), SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
1845 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_w), SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0);
1846 
1847 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1848 
1849 	code.code = sljit_generate_code(compiler);
1850 	CHECK(compiler);
1851 	sljit_free_compiler(compiler);
1852 
1853 	code.func3((sljit_w)&buf, (sljit_w)&sbuf, (sljit_w)&bbuf);
1854 	FAILED(buf[2] != 176366, "test24 case 1 failed\n");
1855 	FAILED(buf[3] != 64, "test24 case 2 failed\n");
1856 	FAILED(buf[4] != -100, "test24 case 3 failed\n");
1857 	FAILED(buf[5] != -100 + (sljit_w)&buf[5] + (sljit_w)&buf[4], "test24 case 4 failed\n");
1858 
1859 	FAILED(sbuf[1] != 30000, "test24 case 5 failed\n");
1860 	FAILED(sbuf[2] != -12345, "test24 case 6 failed\n");
1861 	FAILED(sbuf[4] != sizeof(short), "test24 case 7 failed\n");
1862 
1863 	FAILED(bbuf[1] != -128, "test24 case 8 failed\n");
1864 	FAILED(bbuf[2] != 99, "test24 case 9 failed\n");
1865 
1866 	sljit_free_code(code.code);
1867 	printf("test24 ok\n");
1868 	successful_tests++;
1869 }
1870 
1871 static void test25(void)
1872 {
1873 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1874 	/* 64 bit loads. */
1875 	executable_code code;
1876 	struct sljit_compiler* compiler = sljit_create_compiler();
1877 	sljit_w buf[14];
1878 
1879 	FAILED(!compiler, "cannot create compiler\n");
1880 	buf[0] = 7;
1881 	buf[1] = 0;
1882 	buf[2] = 0;
1883 	buf[3] = 0;
1884 	buf[4] = 0;
1885 	buf[5] = 0;
1886 	buf[6] = 0;
1887 	buf[7] = 0;
1888 	buf[8] = 0;
1889 	buf[9] = 0;
1890 	buf[10] = 0;
1891 	buf[11] = 0;
1892 	buf[12] = 0;
1893 	buf[13] = 0;
1894 
1895 	sljit_emit_enter(compiler, 1, 3, 1, 0);
1896 
1897 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 0);
1898 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 1 * sizeof(sljit_w), SLJIT_IMM, 0x7fff);
1899 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_w), SLJIT_IMM, -0x8000);
1900 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_w), SLJIT_IMM, 0x7fffffff);
1901 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_w), SLJIT_IMM, SLJIT_W(-0x80000000));
1902 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_w), SLJIT_IMM, SLJIT_W(0x1234567887654321));
1903 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_w), SLJIT_IMM, SLJIT_W(0xff80000000));
1904 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_w), SLJIT_IMM, SLJIT_W(0x3ff0000000));
1905 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_w), SLJIT_IMM, SLJIT_W(0xfffffff800100000));
1906 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 9 * sizeof(sljit_w), SLJIT_IMM, SLJIT_W(0xfffffff80010f000));
1907 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 10 * sizeof(sljit_w), SLJIT_IMM, SLJIT_W(0x07fff00000008001));
1908 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 11 * sizeof(sljit_w), SLJIT_IMM, SLJIT_W(0x07fff00080010000));
1909 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 12 * sizeof(sljit_w), SLJIT_IMM, SLJIT_W(0x07fff00080018001));
1910 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 13 * sizeof(sljit_w), SLJIT_IMM, SLJIT_W(0x07fff00ffff00000));
1911 
1912 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1913 
1914 	code.code = sljit_generate_code(compiler);
1915 	CHECK(compiler);
1916 	sljit_free_compiler(compiler);
1917 
1918 	code.func1((sljit_w)&buf);
1919 	FAILED(buf[0] != 0, "test25 case 1 failed\n");
1920 	FAILED(buf[1] != 0x7fff, "test25 case 2 failed\n");
1921 	FAILED(buf[2] != -0x8000, "test25 case 3 failed\n");
1922 	FAILED(buf[3] != 0x7fffffff, "test25 case 4 failed\n");
1923 	FAILED(buf[4] != SLJIT_W(-0x80000000), "test25 case 5 failed\n");
1924 	FAILED(buf[5] != SLJIT_W(0x1234567887654321), "test25 case 6 failed\n");
1925 	FAILED(buf[6] != SLJIT_W(0xff80000000), "test25 case 7 failed\n");
1926 	FAILED(buf[7] != SLJIT_W(0x3ff0000000), "test25 case 8 failed\n");
1927 	FAILED((sljit_uw)buf[8] != SLJIT_W(0xfffffff800100000), "test25 case 9 failed\n");
1928 	FAILED((sljit_uw)buf[9] != SLJIT_W(0xfffffff80010f000), "test25 case 10 failed\n");
1929 	FAILED(buf[10] != SLJIT_W(0x07fff00000008001), "test25 case 11 failed\n");
1930 	FAILED(buf[11] != SLJIT_W(0x07fff00080010000), "test25 case 12 failed\n");
1931 	FAILED(buf[12] != SLJIT_W(0x07fff00080018001), "test25 case 13 failed\n");
1932 	FAILED(buf[13] != SLJIT_W(0x07fff00ffff00000), "test25 case 14 failed\n");
1933 
1934 	sljit_free_code(code.code);
1935 #endif
1936 	printf("test25 ok\n");
1937 	successful_tests++;
1938 }
1939 
1940 static void test26(void)
1941 {
1942 	/* Aligned access without aligned offsets. */
1943 	executable_code code;
1944 	struct sljit_compiler* compiler = sljit_create_compiler();
1945 	sljit_w buf[4];
1946 	int ibuf[4];
1947 	double dbuf[4];
1948 
1949 	FAILED(!compiler, "cannot create compiler\n");
1950 
1951 	buf[0] = -2789;
1952 	buf[1] = 0;
1953 	buf[2] = 4;
1954 	buf[3] = -4;
1955 
1956 	ibuf[0] = -689;
1957 	ibuf[1] = 0;
1958 	ibuf[2] = -6;
1959 	ibuf[3] = 3;
1960 
1961 	dbuf[0] = 5.75;
1962 	dbuf[1] = 0.0;
1963 	dbuf[2] = 0.0;
1964 	dbuf[3] = -4.0;
1965 
1966 	sljit_emit_enter(compiler, 3, 3, 3, 0);
1967 
1968 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 3);
1969 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);
1970 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), -3);
1971 	sljit_emit_op1(compiler, SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(int) - 1, SLJIT_TEMPORARY_REG1, 0);
1972 	sljit_emit_op1(compiler, SLJIT_MOV_SI, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), -1);
1973 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) - 3, SLJIT_TEMPORARY_REG1, 0);
1974 
1975 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 100);
1976 	sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), sizeof(sljit_w) * 2 - 103, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 2 - 3, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 3 - 3);
1977 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 100);
1978 	sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_INT_OP, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), sizeof(int) * 2 - 101, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(int) * 2 - 1, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(int) * 3 - 1);
1979 
1980 	if (sljit_is_fpu_available()) {
1981 		sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SAVED_REG3, 0, SLJIT_SAVED_REG3, 0, SLJIT_IMM, 3);
1982 		sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_MEM1(SLJIT_SAVED_REG3), sizeof(double) - 3, SLJIT_MEM1(SLJIT_SAVED_REG3), -3);
1983 		sljit_emit_fop2(compiler, SLJIT_FADD, SLJIT_MEM1(SLJIT_SAVED_REG3), sizeof(double) * 2 - 3, SLJIT_MEM1(SLJIT_SAVED_REG3), -3, SLJIT_MEM1(SLJIT_SAVED_REG3), sizeof(double) - 3);
1984 		sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_REG3, 0, SLJIT_IMM, 2);
1985 		sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, (sizeof(double) * 3 - 4) >> 1);
1986 		sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG3, 0, SLJIT_IMM, 1);
1987 		sljit_emit_fop2(compiler, SLJIT_FDIV, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), sizeof(double) * 3 - 5, SLJIT_MEM1(SLJIT_SAVED_REG3), sizeof(double) * 2 - 3, SLJIT_MEM2(SLJIT_TEMPORARY_REG3, SLJIT_TEMPORARY_REG2), 1);
1988 	}
1989 
1990 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1991 
1992 	code.code = sljit_generate_code(compiler);
1993 	CHECK(compiler);
1994 	sljit_free_compiler(compiler);
1995 
1996 	code.func3((sljit_w)&buf, (sljit_w)&ibuf, (sljit_w)&dbuf);
1997 
1998 	FAILED(buf[1] != -689, "test26 case 1 failed\n");
1999 	FAILED(buf[2] != -16, "test26 case 2 failed\n");
2000 	FAILED(ibuf[1] != -2789, "test26 case 3 failed\n");
2001 	FAILED(ibuf[2] != -18, "test26 case 4 failed\n");
2002 
2003 	if (sljit_is_fpu_available()) {
2004 		FAILED(dbuf[1] != 5.75, "test26 case 5 failed\n");
2005 		FAILED(dbuf[2] != 11.5, "test26 case 6 failed\n");
2006 		FAILED(dbuf[3] != -2.875, "test26 case 7 failed\n");
2007 	}
2008 
2009 	sljit_free_code(code.code);
2010 	printf("test26 ok\n");
2011 	successful_tests++;
2012 }
2013 
2014 static void test27(void)
2015 {
2016 #define SET_NEXT_BYTE(type) \
2017 		cond_set(compiler, SLJIT_TEMPORARY_REG3, 0, type); \
2018 		sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_SAVED_REG1), 1, SLJIT_TEMPORARY_REG3, 0);
2019 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2020 #define RESULT(i) i
2021 #else
2022 #define RESULT(i) (3 - i)
2023 #endif
2024 
2025 	/* Playing with conditional flags. */
2026 	executable_code code;
2027 	struct sljit_compiler* compiler = sljit_create_compiler();
2028 	sljit_b buf[37];
2029 	int i;
2030 
2031 	for (i = 0; i < 37; ++i)
2032 		buf[i] = 10;
2033 
2034 	FAILED(!compiler, "cannot create compiler\n");
2035 
2036 	/* 3 arguments passed, 3 arguments used. */
2037 	sljit_emit_enter(compiler, 1, 3, 3, 0);
2038 
2039 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 1);
2040 
2041 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x1001);
2042 	sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 20);
2043 	/* 0x100100000 on 64 bit machines, 0x100000 on 32 bit machines. */
2044 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0x800000);
2045 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
2046 	sljit_emit_op0(compiler, SLJIT_NOP); /* Nop should keep the flags. */
2047 	SET_NEXT_BYTE(SLJIT_C_GREATER);
2048 	SET_NEXT_BYTE(SLJIT_C_LESS);
2049 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_INT_OP | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
2050 	sljit_emit_op0(compiler, SLJIT_NOP); /* Nop should keep the flags. */
2051 	SET_NEXT_BYTE(SLJIT_C_GREATER);
2052 	SET_NEXT_BYTE(SLJIT_C_LESS);
2053 
2054 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x1000);
2055 	sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 20);
2056 	sljit_emit_op2(compiler, SLJIT_OR, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x10);
2057 	/* 0x100000010 on 64 bit machines, 0x10 on 32 bit machines. */
2058 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x80);
2059 	SET_NEXT_BYTE(SLJIT_C_GREATER);
2060 	SET_NEXT_BYTE(SLJIT_C_LESS);
2061 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_INT_OP | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x80);
2062 	SET_NEXT_BYTE(SLJIT_C_GREATER);
2063 	SET_NEXT_BYTE(SLJIT_C_LESS);
2064 
2065 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
2066 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1);
2067 	/* 0xff..ff on all machines. */
2068 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_U, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1);
2069 	SET_NEXT_BYTE(SLJIT_C_LESS_EQUAL);
2070 	SET_NEXT_BYTE(SLJIT_C_GREATER_EQUAL);
2071 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_S, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, -1);
2072 	SET_NEXT_BYTE(SLJIT_C_SIG_GREATER);
2073 	SET_NEXT_BYTE(SLJIT_C_SIG_LESS);
2074 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0);
2075 	SET_NEXT_BYTE(SLJIT_C_EQUAL);
2076 	SET_NEXT_BYTE(SLJIT_C_NOT_EQUAL);
2077 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_O | SLJIT_SET_U, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, -2);
2078 	SET_NEXT_BYTE(SLJIT_C_OVERFLOW);
2079 	SET_NEXT_BYTE(SLJIT_C_NOT_OVERFLOW);
2080 	SET_NEXT_BYTE(SLJIT_C_GREATER_EQUAL);
2081 	SET_NEXT_BYTE(SLJIT_C_LESS_EQUAL);
2082 
2083 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x80000000);
2084 	sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 16);
2085 	sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 16);
2086 	/* 0x80..0 on 64 bit machines, 0 on 32 bit machines. */
2087 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0xffffffff);
2088 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
2089 	SET_NEXT_BYTE(SLJIT_C_OVERFLOW);
2090 	SET_NEXT_BYTE(SLJIT_C_NOT_OVERFLOW);
2091 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_INT_OP | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
2092 	SET_NEXT_BYTE(SLJIT_C_OVERFLOW);
2093 	SET_NEXT_BYTE(SLJIT_C_NOT_OVERFLOW);
2094 
2095 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
2096 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_C, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1);
2097 	sljit_emit_op2(compiler, SLJIT_SUBC | SLJIT_SET_C, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
2098 	sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 6, SLJIT_TEMPORARY_REG1, 0);
2099 	sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_SAVED_REG1), 1, SLJIT_TEMPORARY_REG1, 0);
2100 
2101 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -1);
2102 	sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_C, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1);
2103 	sljit_emit_op2(compiler, SLJIT_ADDC | SLJIT_SET_C, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1);
2104 	sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 9);
2105 	sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_SAVED_REG1), 1, SLJIT_TEMPORARY_REG1, 0);
2106 
2107 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1);
2108 	sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, (8 * sizeof(sljit_w)) - 1);
2109 	sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
2110 	SET_NEXT_BYTE(SLJIT_C_EQUAL);
2111 	sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0);
2112 	SET_NEXT_BYTE(SLJIT_C_EQUAL);
2113 
2114 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
2115 	sljit_emit_op2(compiler, SLJIT_ASHR | SLJIT_SET_E, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
2116 	SET_NEXT_BYTE(SLJIT_C_EQUAL);
2117 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1);
2118 	sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_E, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xffffc0);
2119 	SET_NEXT_BYTE(SLJIT_C_NOT_EQUAL);
2120 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 0);
2121 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
2122 	sljit_emit_op2(compiler, SLJIT_ASHR | SLJIT_SET_E, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_PREF_SHIFT_REG, 0);
2123 	SET_NEXT_BYTE(SLJIT_C_EQUAL);
2124 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_PREF_SHIFT_REG, 0, SLJIT_IMM, 0);
2125 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1);
2126 	sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_E, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_PREF_SHIFT_REG, 0);
2127 	SET_NEXT_BYTE(SLJIT_C_NOT_EQUAL);
2128 
2129 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
2130 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);
2131 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_C, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0);
2132 	sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1, SLJIT_TEMPORARY_REG1, 0);
2133 	sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_SAVED_REG1), 1, SLJIT_TEMPORARY_REG3, 0);
2134 	sljit_emit_op2(compiler, SLJIT_SUBC | SLJIT_SET_C, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
2135 	sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1, SLJIT_TEMPORARY_REG1, 0);
2136 	sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_SAVED_REG1), 1, SLJIT_TEMPORARY_REG3, 0);
2137 
2138 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -34);
2139 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_S | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x1234);
2140 	SET_NEXT_BYTE(SLJIT_C_LESS);
2141 	SET_NEXT_BYTE(SLJIT_C_SIG_LESS);
2142 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2143 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(0x12300000000) - 43);
2144 #else
2145 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -43);
2146 #endif
2147 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, -96);
2148 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_INT_OP | SLJIT_SET_S | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
2149 	SET_NEXT_BYTE(SLJIT_C_LESS);
2150 	SET_NEXT_BYTE(SLJIT_C_SIG_GREATER);
2151 
2152 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2153 
2154 	code.code = sljit_generate_code(compiler);
2155 	CHECK(compiler);
2156 	sljit_free_compiler(compiler);
2157 
2158 	code.func1((sljit_w)&buf);
2159 	sljit_free_code(code.code);
2160 
2161 	FAILED(buf[0] != RESULT(1), "test27 case 1 failed\n");
2162 	FAILED(buf[1] != RESULT(2), "test27 case 2 failed\n");
2163 	FAILED(buf[2] != 2, "test27 case 3 failed\n");
2164 	FAILED(buf[3] != 1, "test27 case 4 failed\n");
2165 	FAILED(buf[4] != RESULT(1), "test27 case 5 failed\n");
2166 	FAILED(buf[5] != RESULT(2), "test27 case 6 failed\n");
2167 	FAILED(buf[6] != 2, "test27 case 7 failed\n");
2168 	FAILED(buf[7] != 1, "test27 case 8 failed\n");
2169 
2170 	FAILED(buf[8] != 2, "test27 case 9 failed\n");
2171 	FAILED(buf[9] != 1, "test27 case 10 failed\n");
2172 	FAILED(buf[10] != 2, "test27 case 11 failed\n");
2173 	FAILED(buf[11] != 1, "test27 case 12 failed\n");
2174 	FAILED(buf[12] != 1, "test27 case 13 failed\n");
2175 	FAILED(buf[13] != 2, "test27 case 14 failed\n");
2176 	FAILED(buf[14] != 2, "test27 case 15 failed\n");
2177 	FAILED(buf[15] != 1, "test27 case 16 failed\n");
2178 	FAILED(buf[16] != 1, "test27 case 17 failed\n");
2179 	FAILED(buf[17] != 2, "test27 case 18 failed\n");
2180 
2181 	FAILED(buf[18] != RESULT(1), "test27 case 19 failed\n");
2182 	FAILED(buf[19] != RESULT(2), "test27 case 20 failed\n");
2183 	FAILED(buf[20] != 2, "test27 case 21 failed\n");
2184 	FAILED(buf[21] != 1, "test27 case 22 failed\n");
2185 
2186 	FAILED(buf[22] != 5, "test27 case 23 failed\n");
2187 	FAILED(buf[23] != 9, "test27 case 24 failed\n");
2188 
2189 	FAILED(buf[24] != 2, "test27 case 25 failed\n");
2190 	FAILED(buf[25] != 1, "test27 case 26 failed\n");
2191 
2192 	FAILED(buf[26] != 1, "test27 case 27 failed\n");
2193 	FAILED(buf[27] != 1, "test27 case 28 failed\n");
2194 	FAILED(buf[28] != 1, "test27 case 29 failed\n");
2195 	FAILED(buf[29] != 1, "test27 case 30 failed\n");
2196 
2197 	FAILED(buf[30] != 1, "test27 case 31 failed\n");
2198 	FAILED(buf[31] != 0, "test27 case 32 failed\n");
2199 
2200 	FAILED(buf[32] != 2, "test27 case 33 failed\n");
2201 	FAILED(buf[33] != 1, "test27 case 34 failed\n");
2202 	FAILED(buf[34] != 2, "test27 case 35 failed\n");
2203 	FAILED(buf[35] != 1, "test27 case 36 failed\n");
2204 	FAILED(buf[36] != 10, "test27 case 37 failed\n");
2205 	printf("test27 ok\n");
2206 	successful_tests++;
2207 #undef SET_NEXT_BYTE
2208 #undef RESULT
2209 }
2210 
2211 static void test28(void)
2212 {
2213 	/* Test mov. */
2214 	executable_code code;
2215 	struct sljit_compiler* compiler = sljit_create_compiler();
2216 	struct sljit_const* const1;
2217 	struct sljit_label* label;
2218 	sljit_uw label_addr;
2219 	sljit_w buf[5];
2220 
2221 	FAILED(!compiler, "cannot create compiler\n");
2222 
2223 	buf[0] = -36;
2224 	buf[1] = 8;
2225 	buf[2] = 0;
2226 	buf[3] = 10;
2227 	buf[4] = 0;
2228 
2229 	FAILED(!compiler, "cannot create compiler\n");
2230 	sljit_emit_enter(compiler, 1, 5, 5, 0);
2231 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG1, 0, SLJIT_IMM, -234);
2232 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w));
2233 	sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_SAVED_EREG1, 0, SLJIT_TEMPORARY_EREG1, 0, SLJIT_TEMPORARY_EREG2, 0);
2234 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_SAVED_EREG1, 0);
2235 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SAVED_EREG1, 0, SLJIT_IMM, 0);
2236 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_SAVED_EREG1, 0, SLJIT_C_NOT_ZERO);
2237 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_w), SLJIT_SAVED_EREG1, 0);
2238 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_w));
2239 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SAVED_EREG2, 0, SLJIT_SAVED_EREG2, 0, SLJIT_TEMPORARY_EREG2, 0);
2240 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_w), SLJIT_SAVED_EREG2, 0);
2241 	const1 = sljit_emit_const(compiler, SLJIT_SAVED_EREG1, 0, 0);
2242 	sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_SAVED_EREG1, 0);
2243 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SAVED_EREG1, 0, SLJIT_SAVED_EREG1, 0, SLJIT_IMM, 100);
2244 	label = sljit_emit_label(compiler);
2245 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_w), SLJIT_SAVED_EREG1, 0);
2246 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG2, 0);
2247 
2248 	code.code = sljit_generate_code(compiler);
2249 	CHECK(compiler);
2250 	label_addr = sljit_get_label_addr(label);
2251 	sljit_set_const(sljit_get_const_addr(const1), label_addr);
2252 	sljit_free_compiler(compiler);
2253 
2254 	FAILED(code.func1((sljit_w)&buf) != 8, "test28 case 1 failed\n");
2255 	FAILED(buf[1] != -1872, "test28 case 2 failed\n");
2256 	FAILED(buf[2] != 1, "test28 case 3 failed\n");
2257 	FAILED(buf[3] != 2, "test28 case 4 failed\n");
2258 	FAILED(buf[4] != label_addr, "test28 case 5 failed\n");
2259 
2260 	sljit_free_code(code.code);
2261 	printf("test28 ok\n");
2262 	successful_tests++;
2263 }
2264 
2265 static void test29(void)
2266 {
2267 	/* Test signed/unsigned bytes and halfs. */
2268 	executable_code code;
2269 	struct sljit_compiler* compiler = sljit_create_compiler();
2270 
2271 	sljit_w buf[25];
2272 	buf[0] = 0;
2273 	buf[1] = 0;
2274 	buf[2] = 0;
2275 	buf[3] = 0;
2276 	buf[4] = 0;
2277 	buf[5] = 0;
2278 	buf[6] = 0;
2279 	buf[7] = 0;
2280 	buf[8] = 0;
2281 	buf[9] = 0;
2282 	buf[10] = 0;
2283 	buf[11] = 0;
2284 	buf[12] = 0;
2285 	buf[13] = 0;
2286 	buf[14] = 0;
2287 	buf[15] = 0;
2288 	buf[16] = 0;
2289 	buf[17] = 0;
2290 	buf[18] = 0;
2291 	buf[19] = 0;
2292 	buf[20] = 0;
2293 	buf[21] = 0;
2294 	buf[22] = 0;
2295 	buf[23] = 0;
2296 	buf[24] = 0;
2297 
2298 	FAILED(!compiler, "cannot create compiler\n");
2299 	sljit_emit_enter(compiler, 1, 5, 5, 0);
2300 
2301 	sljit_emit_op1(compiler, SLJIT_MOV_SB, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -187);
2302 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0);
2303 	sljit_emit_op1(compiler, SLJIT_MOVU_SB, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -605);
2304 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_REG1, 0);
2305 	sljit_emit_op1(compiler, SLJIT_MOV_UB, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -56);
2306 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_REG1, 0);
2307 	sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_TEMPORARY_EREG2, 0, SLJIT_IMM, 0xcde5);
2308 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_EREG2, 0);
2309 
2310 	sljit_emit_op1(compiler, SLJIT_MOV_SH, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -45896);
2311 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_REG1, 0);
2312 	sljit_emit_op1(compiler, SLJIT_MOVU_SH, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -1472797);
2313 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_REG1, 0);
2314 	sljit_emit_op1(compiler, SLJIT_MOV_UH, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -12890);
2315 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_REG1, 0);
2316 	sljit_emit_op1(compiler, SLJIT_MOVU_UH, SLJIT_TEMPORARY_EREG2, 0, SLJIT_IMM, 0x9cb0a6);
2317 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_EREG2, 0);
2318 
2319 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2320 	sljit_emit_op1(compiler, SLJIT_MOV_SI, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(-3580429715));
2321 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_REG1, 0);
2322 	sljit_emit_op1(compiler, SLJIT_MOVU_SI, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(-100722768662));
2323 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_REG1, 0);
2324 	sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(-1457052677972));
2325 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_REG1, 0);
2326 	sljit_emit_op1(compiler, SLJIT_MOVU_UI, SLJIT_TEMPORARY_EREG2, 0, SLJIT_IMM, SLJIT_W(0xcef97a70b5));
2327 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_EREG2, 0);
2328 #else
2329 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 4 * sizeof(sljit_uw));
2330 #endif
2331 
2332 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, -187);
2333 	sljit_emit_op1(compiler, SLJIT_MOV_SB, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
2334 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_REG1, 0);
2335 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_IMM, -605);
2336 	sljit_emit_op1(compiler, SLJIT_MOVU_SB, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_REG3, 0);
2337 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_REG1, 0);
2338 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, -56);
2339 	sljit_emit_op1(compiler, SLJIT_MOV_UB, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG3, 0);
2340 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_REG1, 0);
2341 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG1, 0, SLJIT_IMM, 0xcde5);
2342 	sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_TEMPORARY_EREG2, 0, SLJIT_TEMPORARY_EREG1, 0);
2343 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_EREG2, 0);
2344 
2345 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, -45896);
2346 	sljit_emit_op1(compiler, SLJIT_MOV_SH, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
2347 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_REG1, 0);
2348 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_IMM, -1472797);
2349 	sljit_emit_op1(compiler, SLJIT_MOVU_SH, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_REG3, 0);
2350 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_REG1, 0);
2351 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, -12890);
2352 	sljit_emit_op1(compiler, SLJIT_MOV_UH, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG3, 0);
2353 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_REG1, 0);
2354 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG1, 0, SLJIT_IMM, 0x9cb0a6);
2355 	sljit_emit_op1(compiler, SLJIT_MOVU_UH, SLJIT_TEMPORARY_EREG2, 0, SLJIT_TEMPORARY_EREG1, 0);
2356 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_EREG2, 0);
2357 
2358 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2359 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, SLJIT_W(-3580429715));
2360 	sljit_emit_op1(compiler, SLJIT_MOV_SI, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
2361 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_REG1, 0);
2362 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_IMM, SLJIT_W(-100722768662));
2363 	sljit_emit_op1(compiler, SLJIT_MOVU_SI, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_REG3, 0);
2364 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_REG1, 0);
2365 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, SLJIT_W(-1457052677972));
2366 	sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG3, 0);
2367 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_REG1, 0);
2368 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG1, 0, SLJIT_IMM, SLJIT_W(0xcef97a70b5));
2369 	sljit_emit_op1(compiler, SLJIT_MOVU_UI, SLJIT_TEMPORARY_EREG2, 0, SLJIT_TEMPORARY_EREG1, 0);
2370 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_TEMPORARY_EREG2, 0);
2371 #else
2372 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 4 * sizeof(sljit_uw));
2373 #endif
2374 
2375 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_IMM, 0x9faa5);
2376 	sljit_emit_op1(compiler, SLJIT_MOV_SB, SLJIT_SAVED_REG3, 0, SLJIT_SAVED_REG3, 0);
2377 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_uw), SLJIT_SAVED_REG3, 0);
2378 
2379 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2380 
2381 	code.code = sljit_generate_code(compiler);
2382 	CHECK(compiler);
2383 	sljit_free_compiler(compiler);
2384 
2385 	code.func1((sljit_w)&buf);
2386 	FAILED(buf[0] != 69, "test29 case 1 failed\n");
2387 	FAILED(buf[1] != -93, "test29 case 2 failed\n");
2388 	FAILED(buf[2] != 200, "test29 case 3 failed\n");
2389 	FAILED(buf[3] != 0xe5, "test29 case 4 failed\n");
2390 	FAILED(buf[4] != 19640, "test29 case 5 failed\n");
2391 	FAILED(buf[5] != -31005, "test29 case 6 failed\n");
2392 	FAILED(buf[6] != 52646, "test29 case 7 failed\n");
2393 	FAILED(buf[7] != 0xb0a6, "test29 case 8 failed\n");
2394 
2395 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2396 	FAILED(buf[8] != SLJIT_W(714537581), "test29 case 9 failed\n");
2397 	FAILED(buf[9] != SLJIT_W(-1938520854), "test29 case 10 failed\n");
2398 	FAILED(buf[10] != SLJIT_W(3236202668), "test29 case 11 failed\n");
2399 	FAILED(buf[11] != SLJIT_W(0xf97a70b5), "test29 case 12 failed\n");
2400 #endif
2401 
2402 	FAILED(buf[12] != 69, "test29 case 13 failed\n");
2403 	FAILED(buf[13] != -93, "test29 case 14 failed\n");
2404 	FAILED(buf[14] != 200, "test29 case 15 failed\n");
2405 	FAILED(buf[15] != 0xe5, "test29 case 16 failed\n");
2406 	FAILED(buf[16] != 19640, "test29 case 17 failed\n");
2407 	FAILED(buf[17] != -31005, "test29 case 18 failed\n");
2408 	FAILED(buf[18] != 52646, "test29 case 19 failed\n");
2409 	FAILED(buf[19] != 0xb0a6, "test29 case 20 failed\n");
2410 
2411 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2412 	FAILED(buf[20] != SLJIT_W(714537581), "test29 case 21 failed\n");
2413 	FAILED(buf[21] != SLJIT_W(-1938520854), "test29 case 22 failed\n");
2414 	FAILED(buf[22] != SLJIT_W(3236202668), "test29 case 23 failed\n");
2415 	FAILED(buf[23] != SLJIT_W(0xf97a70b5), "test29 case 24 failed\n");
2416 #endif
2417 
2418 	FAILED(buf[24] != -91, "test29 case 25 failed\n");
2419 
2420 	sljit_free_code(code.code);
2421 	printf("test29 ok\n");
2422 	successful_tests++;
2423 }
2424 
2425 static void test30(void)
2426 {
2427 	/* Test unused results. */
2428 	executable_code code;
2429 	struct sljit_compiler* compiler = sljit_create_compiler();
2430 
2431 	sljit_w buf[1];
2432 	buf[0] = 0;
2433 
2434 	FAILED(!compiler, "cannot create compiler\n");
2435 	sljit_emit_enter(compiler, 1, 5, 5, 0);
2436 
2437 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1);
2438 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);
2439 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);
2440 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG1, 0, SLJIT_IMM, 1);
2441 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG2, 0, SLJIT_IMM, 1);
2442 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);
2443 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_IMM, 1);
2444 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG1, 0, SLJIT_IMM, 1);
2445 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG2, 0, SLJIT_IMM, 1);
2446 
2447 	/* Some calculations with unused results. */
2448 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG3, 0);
2449 	sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG2, 0);
2450 	sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
2451 	sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
2452 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_INT_OP | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
2453 	sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_UNUSED, 0, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
2454 	sljit_emit_op2(compiler, SLJIT_SHL | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SAVED_EREG1, 0, SLJIT_TEMPORARY_REG3, 0);
2455 	sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 5);
2456 	sljit_emit_op2(compiler, SLJIT_AND, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 0xff);
2457 	sljit_emit_op1(compiler, SLJIT_NOT | SLJIT_INT_OP | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_SAVED_REG2, 0);
2458 
2459 	/* Testing that any change happens. */
2460 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
2461 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG3, 0);
2462 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_EREG1, 0);
2463 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_EREG2, 0);
2464 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_REG2, 0);
2465 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_REG3, 0);
2466 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_EREG1, 0);
2467 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_EREG2, 0);
2468 
2469 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2470 
2471 	code.code = sljit_generate_code(compiler);
2472 	CHECK(compiler);
2473 	sljit_free_compiler(compiler);
2474 
2475 	code.func1((sljit_w)&buf);
2476 	FAILED(buf[0] != 9, "test30 case 1 failed\n");
2477 	sljit_free_code(code.code);
2478 	printf("test30 ok\n");
2479 	successful_tests++;
2480 }
2481 
2482 static void test31(void)
2483 {
2484 	/* Integer mul and set flags. */
2485 	executable_code code;
2486 	struct sljit_compiler* compiler = sljit_create_compiler();
2487 
2488 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2489 	sljit_w big_word = SLJIT_W(0x7fffffff00000000);
2490 	sljit_w big_word2 = SLJIT_W(0x7fffffff00000012);
2491 #else
2492 	sljit_w big_word = 0x7fffffff;
2493 	sljit_w big_word2 = 0x00000012;
2494 #endif
2495 
2496 	sljit_w buf[12];
2497 	buf[0] = 3;
2498 	buf[1] = 3;
2499 	buf[2] = 3;
2500 	buf[3] = 3;
2501 	buf[4] = 3;
2502 	buf[5] = 3;
2503 	buf[6] = 3;
2504 	buf[7] = 3;
2505 	buf[8] = 3;
2506 	buf[9] = 3;
2507 	buf[10] = 3;
2508 	buf[11] = 3;
2509 
2510 	FAILED(!compiler, "cannot create compiler\n");
2511 
2512 	sljit_emit_enter(compiler, 1, 3, 5, 0);
2513 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0);
2514 	sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, -45);
2515 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_C_MUL_NOT_OVERFLOW);
2516 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_C_MUL_OVERFLOW);
2517 
2518 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_IMM, big_word);
2519 	sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_O, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG3, 0, SLJIT_IMM, -2);
2520 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 33); /* Should not change flags. */
2521 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0); /* Should not change flags. */
2522 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_w), SLJIT_C_MUL_OVERFLOW);
2523 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_w), SLJIT_C_MUL_NOT_OVERFLOW);
2524 
2525 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG1, 0, SLJIT_IMM, 0x3f6b0);
2526 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG2, 0, SLJIT_IMM, 0x2a783);
2527 	sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_INT_OP | SLJIT_SET_O, SLJIT_TEMPORARY_REG2, 0, SLJIT_SAVED_EREG1, 0, SLJIT_SAVED_EREG2, 0);
2528 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_w), SLJIT_C_MUL_OVERFLOW);
2529 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0);
2530 
2531 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, big_word2);
2532 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG2, 0);
2533 	sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_INT_OP | SLJIT_SET_O, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 23);
2534 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_w), SLJIT_C_MUL_OVERFLOW);
2535 
2536 	sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_INT_OP | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, -23);
2537 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_w), SLJIT_C_MUL_NOT_OVERFLOW);
2538 	sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_O, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, -23);
2539 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_w), SLJIT_C_MUL_NOT_OVERFLOW);
2540 
2541 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 67);
2542 	sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_O, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, -23);
2543 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 9 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0);
2544 
2545 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2546 
2547 	code.code = sljit_generate_code(compiler);
2548 	CHECK(compiler);
2549 	sljit_free_compiler(compiler);
2550 
2551 	code.func1((sljit_w)&buf);
2552 
2553 	FAILED(buf[0] != 1, "test31 case 1 failed\n");
2554 	FAILED(buf[1] != 2, "test31 case 2 failed\n");
2555 /* Qemu issues for 64 bit muls. */
2556 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2557 	FAILED(buf[2] != 1, "test31 case 3 failed\n");
2558 	FAILED(buf[3] != 2, "test31 case 4 failed\n");
2559 #endif
2560 	FAILED(buf[4] != 1, "test31 case 5 failed\n");
2561 	FAILED((buf[5] & 0xffffffff) != 0x85540c10, "test31 case 6 failed\n");
2562 	FAILED(buf[6] != 2, "test31 case 7 failed\n");
2563 	FAILED(buf[7] != 1, "test31 case 8 failed\n");
2564 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2565 	FAILED(buf[8] != 1, "test31 case 9 failed\n");
2566 #endif
2567 	FAILED(buf[9] != -1541, "test31 case 10 failed\n");
2568 	sljit_free_code(code.code);
2569 	printf("test31 ok\n");
2570 	successful_tests++;
2571 }
2572 
2573 static void test32(void)
2574 {
2575 	/* Floating point set flags. */
2576 	executable_code code;
2577 	struct sljit_compiler* compiler = sljit_create_compiler();
2578 
2579 	sljit_w buf[16];
2580 	union {
2581 		double value;
2582 		struct {
2583 			int value1;
2584 			int value2;
2585 		} u;
2586 	} dbuf[4];
2587 
2588 	buf[0] = 5;
2589 	buf[1] = 5;
2590 	buf[2] = 5;
2591 	buf[3] = 5;
2592 	buf[4] = 5;
2593 	buf[5] = 5;
2594 	buf[6] = 5;
2595 	buf[7] = 5;
2596 	buf[8] = 5;
2597 	buf[9] = 5;
2598 	buf[10] = 5;
2599 	buf[11] = 5;
2600 	buf[12] = 5;
2601 	buf[13] = 5;
2602 	buf[14] = 5;
2603 	buf[15] = 5;
2604 
2605 	/* Two NaNs */
2606 	dbuf[0].u.value1 = 0x7fffffff;
2607 	dbuf[0].u.value2 = 0x7fffffff;
2608 	dbuf[1].u.value1 = 0x7fffffff;
2609 	dbuf[1].u.value2 = 0x7fffffff;
2610 	dbuf[2].value = -13.0;
2611 	dbuf[3].value = 27.0;
2612 
2613 	if (!sljit_is_fpu_available()) {
2614 		printf("no fpu available, test32 skipped\n");
2615 		successful_tests++;
2616 		if (compiler)
2617 			sljit_free_compiler(compiler);
2618 		return;
2619 	}
2620 
2621 	FAILED(!compiler, "cannot create compiler\n");
2622 	SLJIT_ASSERT(sizeof(double) == 8 && sizeof(int) == 4 && sizeof(dbuf[0]) == 8);
2623 
2624 	sljit_emit_enter(compiler, 2, 1, 2, 0);
2625 
2626 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_FLOAT_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 0);
2627 	sljit_emit_fop1(compiler, SLJIT_FCMP | SLJIT_SET_E, SLJIT_MEM1(SLJIT_SAVED_REG2), 3 * sizeof(double), SLJIT_FLOAT_REG1, 0);
2628 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 2 * sizeof(double));
2629 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_C_FLOAT_UNORDERED);
2630 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_C_FLOAT_ORDERED);
2631 
2632 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_FLOAT_REG3, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 3 * sizeof(double));
2633 	sljit_emit_fop1(compiler, SLJIT_FCMP | SLJIT_SET_E | SLJIT_SET_S, SLJIT_FLOAT_REG2, 0, SLJIT_FLOAT_REG3, 0);
2634 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_w), SLJIT_C_FLOAT_UNORDERED);
2635 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_w), SLJIT_C_FLOAT_ORDERED);
2636 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_w), SLJIT_C_FLOAT_LESS);
2637 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_w), SLJIT_C_FLOAT_GREATER_EQUAL);
2638 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_w), SLJIT_C_FLOAT_GREATER);
2639 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_w), SLJIT_C_FLOAT_LESS_EQUAL);
2640 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_w), SLJIT_C_FLOAT_EQUAL);
2641 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 9 * sizeof(sljit_w), SLJIT_C_FLOAT_NOT_EQUAL);
2642 
2643 	sljit_emit_fop1(compiler, SLJIT_FCMP | SLJIT_SET_E, SLJIT_FLOAT_REG3, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 3 * sizeof(double));
2644 	sljit_emit_fop2(compiler, SLJIT_FADD, SLJIT_FLOAT_REG4, 0, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(double));
2645 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 10 * sizeof(sljit_w), SLJIT_C_FLOAT_UNORDERED);
2646 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 11 * sizeof(sljit_w), SLJIT_C_FLOAT_EQUAL);
2647 
2648 	sljit_emit_fop1(compiler, SLJIT_FCMP | SLJIT_SET_S, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(double), SLJIT_FLOAT_REG1, 0);
2649 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 12 * sizeof(sljit_w), SLJIT_C_FLOAT_ORDERED);
2650 
2651 	sljit_emit_fop1(compiler, SLJIT_FCMP | SLJIT_SET_S, SLJIT_FLOAT_REG4, 0, SLJIT_FLOAT_REG3, 0);
2652 	sljit_emit_op1(compiler, SLJIT_MOV_UB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 0);
2653 	cond_set(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 13 * sizeof(sljit_w), SLJIT_C_FLOAT_UNORDERED);
2654 
2655 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2656 
2657 	code.code = sljit_generate_code(compiler);
2658 	CHECK(compiler);
2659 	sljit_free_compiler(compiler);
2660 
2661 	code.func2((sljit_w)&buf, (sljit_w)&dbuf);
2662 
2663 	FAILED(buf[0] != 1, "test32 case 1 failed\n");
2664 	FAILED(buf[1] != 2, "test32 case 2 failed\n");
2665 	FAILED(buf[2] != 2, "test32 case 3 failed\n");
2666 	FAILED(buf[3] != 1, "test32 case 4 failed\n");
2667 	FAILED(buf[4] != 1, "test32 case 5 failed\n");
2668 	FAILED(buf[5] != 2, "test32 case 6 failed\n");
2669 	FAILED(buf[6] != 2, "test32 case 7 failed\n");
2670 	FAILED(buf[7] != 1, "test32 case 8 failed\n");
2671 	FAILED(buf[8] != 2, "test32 case 9 failed\n");
2672 	FAILED(buf[9] != 1, "test32 case 10 failed\n");
2673 	FAILED(buf[10] != 2, "test32 case 11 failed\n");
2674 	FAILED(buf[11] != 1, "test32 case 12 failed\n");
2675 	FAILED(buf[12] != 2, "test32 case 13 failed\n");
2676 	FAILED(buf[13] != 1, "test32 case 14 failed\n");
2677 
2678 	sljit_free_code(code.code);
2679 	printf("test32 ok\n");
2680 	successful_tests++;
2681 }
2682 
2683 static void test33(void)
2684 {
2685 	/* Test keep flags. */
2686 	executable_code code;
2687 	struct sljit_compiler* compiler = sljit_create_compiler();
2688 
2689 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2690 	sljit_w big_word = SLJIT_W(0x8000000000000003);
2691 #else
2692 	sljit_w big_word = 0x80000003;
2693 #endif
2694 
2695 	sljit_w buf[12];
2696 	buf[0] = 3;
2697 	buf[1] = 3;
2698 	buf[2] = 3;
2699 	buf[3] = 3;
2700 	buf[4] = 3;
2701 	buf[5] = 3;
2702 	buf[6] = 3;
2703 	buf[7] = 3;
2704 	buf[8] = 3;
2705 	buf[9] = 3;
2706 	buf[10] = 3;
2707 	buf[11] = 3;
2708 
2709 	FAILED(!compiler, "cannot create compiler\n");
2710 
2711 	sljit_emit_enter(compiler, 1, 3, 3, 0);
2712 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, big_word);
2713 	sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_E | SLJIT_SET_C, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, big_word);
2714 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG2, 0);
2715 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 8);
2716 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_KEEP_FLAGS, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 8);
2717 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_C_NOT_ZERO);
2718 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
2719 	sljit_emit_op2(compiler, SLJIT_ADDC | SLJIT_KEEP_FLAGS, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
2720 	sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 7);
2721 
2722 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 8);
2723 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 8);
2724 	sljit_emit_op2(compiler, SLJIT_SHL | SLJIT_KEEP_FLAGS, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_w), SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_w), SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w));
2725 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_w), SLJIT_C_EQUAL);
2726 
2727 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_w), SLJIT_IMM, 0x124);
2728 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 2);
2729 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1);
2730 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_KEEP_FLAGS, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0);
2731 	sljit_emit_cond_value(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_w), SLJIT_C_NOT_EQUAL);
2732 
2733 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2734 
2735 	code.code = sljit_generate_code(compiler);
2736 	CHECK(compiler);
2737 	sljit_free_compiler(compiler);
2738 
2739 	code.func1((sljit_w)&buf);
2740 
2741 	FAILED(buf[0] != 6, "test33 case 1 failed\n");
2742 	FAILED(buf[1] != 1, "test33 case 2 failed\n");
2743 	FAILED(buf[2] != 8, "test33 case 3 failed\n");
2744 	FAILED(buf[3] != 16, "test33 case 4 failed\n");
2745 	FAILED(buf[4] != 1, "test33 case 5 failed\n");
2746 	FAILED(buf[5] != 0x125, "test33 case 6 failed\n");
2747 
2748 	sljit_free_code(code.code);
2749 	printf("test33 ok\n");
2750 	successful_tests++;
2751 }
2752 
2753 static void test34(void)
2754 {
2755 	/* Test fast calls. */
2756 	executable_code codeA;
2757 	executable_code codeB;
2758 	executable_code codeC;
2759 	executable_code codeD;
2760 	executable_code codeE;
2761 	executable_code codeF;
2762 	struct sljit_compiler* compiler;
2763 	struct sljit_jump *jump;
2764 	struct sljit_label* label;
2765 	sljit_uw addr;
2766 
2767 	sljit_w buf[2];
2768 	buf[0] = 0;
2769 	buf[1] = 0;
2770 
2771 	/* A */
2772 	compiler = sljit_create_compiler();
2773 	FAILED(!compiler, "cannot create compiler\n");
2774 	sljit_set_context(compiler, 1, 5, 5, 2 * sizeof(sljit_w));
2775 
2776 	sljit_emit_fast_enter(compiler, SLJIT_TEMPORARY_REG2, 0);
2777 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 4);
2778 	sljit_emit_fast_return(compiler, SLJIT_TEMPORARY_REG2, 0);
2779 
2780 	codeA.code = sljit_generate_code(compiler);
2781 	CHECK(compiler);
2782 	sljit_free_compiler(compiler);
2783 
2784 	/* B */
2785 	compiler = sljit_create_compiler();
2786 	FAILED(!compiler, "cannot create compiler\n");
2787 	sljit_set_context(compiler, 1, 5, 5, 2 * sizeof(sljit_w));
2788 
2789 	sljit_emit_fast_enter(compiler, SLJIT_TEMPORARY_EREG2, 0);
2790 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 6);
2791 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeA.code));
2792 	sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_TEMPORARY_REG2, 0);
2793 	sljit_emit_fast_return(compiler, SLJIT_TEMPORARY_EREG2, 0);
2794 
2795 	codeB.code = sljit_generate_code(compiler);
2796 	CHECK(compiler);
2797 	sljit_free_compiler(compiler);
2798 
2799 	/* C */
2800 	compiler = sljit_create_compiler();
2801 	FAILED(!compiler, "cannot create compiler\n");
2802 	sljit_set_context(compiler, 1, 5, 5, 2 * sizeof(sljit_w));
2803 
2804 	sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), sizeof(sljit_w));
2805 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 8);
2806 	jump = sljit_emit_jump(compiler, SLJIT_REWRITABLE_JUMP | SLJIT_FAST_CALL);
2807 	sljit_set_target(jump, SLJIT_FUNC_OFFSET(codeB.code));
2808 	sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), sizeof(sljit_w));
2809 
2810 	codeC.code = sljit_generate_code(compiler);
2811 	CHECK(compiler);
2812 	sljit_free_compiler(compiler);
2813 
2814 	/* D */
2815 	compiler = sljit_create_compiler();
2816 	FAILED(!compiler, "cannot create compiler\n");
2817 	sljit_set_context(compiler, 1, 5, 5, 2 * sizeof(sljit_w));
2818 
2819 	sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), 0);
2820 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 10);
2821 	sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeC.code));
2822 	sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), 0);
2823 
2824 	codeD.code = sljit_generate_code(compiler);
2825 	CHECK(compiler);
2826 	sljit_free_compiler(compiler);
2827 
2828 	/* E */
2829 	compiler = sljit_create_compiler();
2830 	FAILED(!compiler, "cannot create compiler\n");
2831 	sljit_set_context(compiler, 1, 5, 5, 2 * sizeof(sljit_w));
2832 
2833 	sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
2834 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 12);
2835 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_IMM, SLJIT_FUNC_OFFSET(codeD.code));
2836 	sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w));
2837 	sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
2838 
2839 	codeE.code = sljit_generate_code(compiler);
2840 	CHECK(compiler);
2841 	sljit_free_compiler(compiler);
2842 
2843 	/* F */
2844 	compiler = sljit_create_compiler();
2845 	FAILED(!compiler, "cannot create compiler\n");
2846 
2847 	sljit_emit_enter(compiler, 1, 5, 5, 2 * sizeof(sljit_w));
2848 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
2849 	sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeE.code));
2850 	label = sljit_emit_label(compiler);
2851 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0);
2852 
2853 	codeF.code = sljit_generate_code(compiler);
2854 	CHECK(compiler);
2855 	addr = sljit_get_label_addr(label);
2856 	sljit_free_compiler(compiler);
2857 
2858 	FAILED(codeF.func1((sljit_w)&buf) != 40, "test34 case 1 failed\n");
2859 	FAILED(buf[0] != addr - SLJIT_RETURN_ADDRESS_OFFSET, "test34 case 2 failed\n");
2860 
2861 	sljit_free_code(codeA.code);
2862 	sljit_free_code(codeB.code);
2863 	sljit_free_code(codeC.code);
2864 	sljit_free_code(codeD.code);
2865 	sljit_free_code(codeE.code);
2866 	sljit_free_code(codeF.code);
2867 
2868 	printf("test34 ok\n");
2869 	successful_tests++;
2870 }
2871 
2872 static void test35(void)
2873 {
2874 	/* More complicated tests for fast calls. */
2875 	executable_code codeA;
2876 	executable_code codeB;
2877 	executable_code codeC;
2878 	struct sljit_compiler* compiler;
2879 	struct sljit_jump *jump;
2880 	struct sljit_label* label;
2881 	sljit_uw return_addr, jump_addr;
2882 
2883 	sljit_w buf[1];
2884 	buf[0] = 0;
2885 
2886 	/* A */
2887 	compiler = sljit_create_compiler();
2888 	FAILED(!compiler, "cannot create compiler\n");
2889 	sljit_set_context(compiler, 0, 2, 2, 0);
2890 
2891 	sljit_emit_fast_enter(compiler, SLJIT_MEM0(), (sljit_w)&buf[0]);
2892 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 5);
2893 	jump = sljit_emit_jump(compiler, SLJIT_REWRITABLE_JUMP | SLJIT_FAST_CALL);
2894 	sljit_set_target(jump, 0);
2895 	label = sljit_emit_label(compiler);
2896 	sljit_emit_fast_return(compiler, SLJIT_MEM0(), (sljit_w)&buf[0]);
2897 
2898 	codeA.code = sljit_generate_code(compiler);
2899 	CHECK(compiler);
2900 	return_addr = sljit_get_label_addr(label) - SLJIT_RETURN_ADDRESS_OFFSET;
2901 	jump_addr = sljit_get_jump_addr(jump);
2902 	sljit_free_compiler(compiler);
2903 
2904 	/* B */
2905 	compiler = sljit_create_compiler();
2906 	FAILED(!compiler, "cannot create compiler\n");
2907 	sljit_set_context(compiler, 0, 2, 2, 0);
2908 
2909 	sljit_emit_fast_enter(compiler, SLJIT_UNUSED, 0);
2910 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 7);
2911 	sljit_emit_fast_return(compiler, SLJIT_IMM, return_addr);
2912 
2913 	codeB.code = sljit_generate_code(compiler);
2914 	CHECK(compiler);
2915 	sljit_free_compiler(compiler);
2916 	sljit_set_jump_addr(jump_addr, SLJIT_FUNC_OFFSET(codeB.code));
2917 
2918 	/* C */
2919 	compiler = sljit_create_compiler();
2920 	FAILED(!compiler, "cannot create compiler\n");
2921 
2922 	sljit_emit_enter(compiler, 0, 2, 2, 0);
2923 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
2924 	sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeA.code));
2925 	label = sljit_emit_label(compiler);
2926 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0);
2927 
2928 	codeC.code = sljit_generate_code(compiler);
2929 	CHECK(compiler);
2930 	return_addr = sljit_get_label_addr(label);
2931 	sljit_free_compiler(compiler);
2932 
2933 	FAILED(codeC.func0() != 12, "test35 case 1 failed\n");
2934 	FAILED(buf[0] != return_addr - SLJIT_RETURN_ADDRESS_OFFSET, "test35 case 2 failed\n");
2935 
2936 	sljit_free_code(codeA.code);
2937 	sljit_free_code(codeB.code);
2938 	sljit_free_code(codeC.code);
2939 
2940 	printf("test35 ok\n");
2941 	successful_tests++;
2942 }
2943 
2944 static int cmp_test(struct sljit_compiler *compiler, int type, int src1, sljit_w src1w, int src2, sljit_w src2w)
2945 {
2946 	/* 2 = true, 1 = false */
2947 	struct sljit_jump* jump;
2948 	struct sljit_label* label;
2949 
2950 	if (sljit_emit_op1(compiler, SLJIT_MOVU_UB, SLJIT_MEM1(SLJIT_SAVED_REG1), 1, SLJIT_IMM, 2))
2951 		return compiler->error;
2952 	jump = sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w);
2953 	if (!jump)
2954 		return compiler->error;
2955 	if (sljit_emit_op1(compiler, SLJIT_MOV_UB, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_IMM, 1))
2956 		return compiler->error;
2957 	label = sljit_emit_label(compiler);
2958 	if (!label)
2959 		return compiler->error;
2960 	sljit_set_label(jump, label);
2961 	return SLJIT_SUCCESS;
2962 }
2963 
2964 #define TEST_CASES	(7 + 10 + 12 + 11 + 4)
2965 static void test36(void)
2966 {
2967 	/* Compare instruction. */
2968 	executable_code code;
2969 	struct sljit_compiler* compiler = sljit_create_compiler();
2970 
2971 	sljit_b buf[TEST_CASES];
2972 	sljit_b compare_buf[TEST_CASES] = {
2973 		1, 1, 2, 2, 1, 2, 2,
2974 		1, 1, 2, 2, 2, 1, 2, 2, 1, 1,
2975 		2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2,
2976 		2, 1, 2, 1, 1, 1, 2, 1, 2, 1, 2,
2977 		2, 1, 1, 2
2978 	};
2979 	sljit_w data[4];
2980 	int i;
2981 
2982 	FAILED(!compiler, "cannot create compiler\n");
2983 	for (i = 0; i < TEST_CASES; ++i)
2984 		buf[i] = 100;
2985 	data[0] = 32;
2986 	data[1] = -9;
2987 	data[2] = 43;
2988 	data[3] = -13;
2989 
2990 	sljit_emit_enter(compiler, 2, 3, 2, 0);
2991 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 1);
2992 
2993 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 13);
2994 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 15);
2995 	cmp_test(compiler, SLJIT_C_EQUAL, SLJIT_IMM, 9, SLJIT_TEMPORARY_REG1, 0);
2996 	cmp_test(compiler, SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
2997 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 3);
2998 	cmp_test(compiler, SLJIT_C_EQUAL, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_TEMPORARY_REG1), SLJIT_WORD_SHIFT, SLJIT_IMM, -13);
2999 	cmp_test(compiler, SLJIT_C_NOT_EQUAL, SLJIT_IMM, 0, SLJIT_TEMPORARY_REG1, 0);
3000 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
3001 	cmp_test(compiler, SLJIT_C_NOT_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 0, SLJIT_TEMPORARY_REG1, 0);
3002 	cmp_test(compiler, SLJIT_C_EQUAL, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_TEMPORARY_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_TEMPORARY_REG1), SLJIT_WORD_SHIFT);
3003 	cmp_test(compiler, SLJIT_C_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
3004 
3005 	cmp_test(compiler, SLJIT_C_SIG_LESS, SLJIT_MEM1(SLJIT_SAVED_REG2), 0, SLJIT_IMM, 0);
3006 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -8);
3007 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0);
3008 	cmp_test(compiler, SLJIT_C_SIG_GREATER, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
3009 	cmp_test(compiler, SLJIT_C_SIG_LESS_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
3010 	cmp_test(compiler, SLJIT_C_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
3011 	cmp_test(compiler, SLJIT_C_SIG_GREATER_EQUAL, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0);
3012 	cmp_test(compiler, SLJIT_C_SIG_GREATER, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 2 * sizeof(sljit_w));
3013 	cmp_test(compiler, SLJIT_C_SIG_LESS_EQUAL, SLJIT_IMM, 0, SLJIT_TEMPORARY_REG2, 0);
3014 	cmp_test(compiler, SLJIT_C_SIG_LESS, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 2 * sizeof(sljit_w));
3015 	cmp_test(compiler, SLJIT_C_SIG_LESS, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 3 * sizeof(sljit_w));
3016 	cmp_test(compiler, SLJIT_C_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), 3 * sizeof(sljit_w));
3017 
3018 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 8);
3019 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0);
3020 	cmp_test(compiler, SLJIT_C_LESS, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_w));
3021 	cmp_test(compiler, SLJIT_C_GREATER_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 8);
3022 	cmp_test(compiler, SLJIT_C_LESS, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -10);
3023 	cmp_test(compiler, SLJIT_C_LESS, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 8);
3024 	cmp_test(compiler, SLJIT_C_GREATER_EQUAL, SLJIT_IMM, 8, SLJIT_TEMPORARY_REG2, 0);
3025 	cmp_test(compiler, SLJIT_C_GREATER_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 8, SLJIT_TEMPORARY_REG2, 0);
3026 	cmp_test(compiler, SLJIT_C_GREATER, SLJIT_IMM, 8, SLJIT_TEMPORARY_REG2, 0);
3027 	cmp_test(compiler, SLJIT_C_LESS_EQUAL, SLJIT_IMM, 7, SLJIT_TEMPORARY_REG1, 0);
3028 	cmp_test(compiler, SLJIT_C_GREATER, SLJIT_IMM, 1, SLJIT_MEM1(SLJIT_SAVED_REG2), 3 * sizeof(sljit_w));
3029 	cmp_test(compiler, SLJIT_C_LESS_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
3030 	cmp_test(compiler, SLJIT_C_GREATER, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
3031 	cmp_test(compiler, SLJIT_C_GREATER | SLJIT_REWRITABLE_JUMP, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
3032 
3033 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -3);
3034 	cmp_test(compiler, SLJIT_C_SIG_LESS, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
3035 	cmp_test(compiler, SLJIT_C_SIG_GREATER_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
3036 	cmp_test(compiler, SLJIT_C_SIG_LESS, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -1);
3037 	cmp_test(compiler, SLJIT_C_SIG_GREATER_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1);
3038 	cmp_test(compiler, SLJIT_C_SIG_LESS, SLJIT_MEM1(SLJIT_SAVED_REG2), 0, SLJIT_IMM, -1);
3039 	cmp_test(compiler, SLJIT_C_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_MEM1(SLJIT_SAVED_REG2), 0, SLJIT_IMM, -1);
3040 	cmp_test(compiler, SLJIT_C_SIG_LESS_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
3041 	cmp_test(compiler, SLJIT_C_SIG_GREATER, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
3042 	cmp_test(compiler, SLJIT_C_SIG_LESS_EQUAL, SLJIT_IMM, -4, SLJIT_TEMPORARY_REG1, 0);
3043 	cmp_test(compiler, SLJIT_C_SIG_GREATER, SLJIT_IMM, -1, SLJIT_TEMPORARY_REG2, 0);
3044 	cmp_test(compiler, SLJIT_C_SIG_GREATER | SLJIT_REWRITABLE_JUMP, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, -1);
3045 
3046 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3047 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(0xf00000004));
3048 	cmp_test(compiler, SLJIT_C_LESS | SLJIT_INT_OP, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 5);
3049 	cmp_test(compiler, SLJIT_C_LESS, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 5);
3050 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(0xff0000004));
3051 	cmp_test(compiler, SLJIT_C_SIG_GREATER | SLJIT_INT_OP, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 5);
3052 	cmp_test(compiler, SLJIT_C_SIG_GREATER, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 5);
3053 #else
3054 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 4);
3055 	cmp_test(compiler, SLJIT_C_LESS | SLJIT_INT_OP, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 5);
3056 	cmp_test(compiler, SLJIT_C_GREATER | SLJIT_INT_OP, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 5);
3057 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xf0000004);
3058 	cmp_test(compiler, SLJIT_C_SIG_GREATER | SLJIT_INT_OP, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 5);
3059 	cmp_test(compiler, SLJIT_C_SIG_LESS | SLJIT_INT_OP, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 5);
3060 #endif
3061 
3062 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3063 
3064 	code.code = sljit_generate_code(compiler);
3065 	CHECK(compiler);
3066 	sljit_free_compiler(compiler);
3067 
3068 	code.func2((sljit_w)&buf, (sljit_w)&data);
3069 
3070 	for (i = 0; i < TEST_CASES; ++i)
3071 		if (SLJIT_UNLIKELY(buf[i] != compare_buf[i])) {
3072 			printf("test36 case %d failed\n", i + 1);
3073 			return;
3074 		}
3075 	sljit_free_code(code.code);
3076 
3077 	printf("test36 ok\n");
3078 	successful_tests++;
3079 }
3080 #undef TEST_CASES
3081 
3082 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3083 #define BITN(n) (SLJIT_W(1) << (63 - (n)))
3084 #define RESN(n) (n)
3085 #else
3086 #define BITN(n) (1 << (31 - ((n) & 0x1f)))
3087 #define RESN(n) ((n) & 0x1f)
3088 #endif
3089 
3090 static void test37(void)
3091 {
3092 	/* Test count leading zeroes. */
3093 	executable_code code;
3094 	struct sljit_compiler* compiler = sljit_create_compiler();
3095 	sljit_w buf[15];
3096 	int ibuf[2];
3097 	int i;
3098 
3099 	FAILED(!compiler, "cannot create compiler\n");
3100 
3101 	for (i = 0; i < 15; i++)
3102 		buf[i] = -1;
3103 	buf[3] = 0;
3104 	buf[7] = BITN(13);
3105 	ibuf[0] = -1;
3106 	ibuf[1] = -1;
3107 	sljit_emit_enter(compiler, 2, 1, 2, 0);
3108 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, BITN(27));
3109 	sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0);
3110 	sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_SET_E, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, BITN(47));
3111 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3112 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_w), SLJIT_C_ZERO);
3113 	sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_w), SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_w));
3114 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -1);
3115 	sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_SET_E, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0);
3116 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_w), SLJIT_C_ZERO);
3117 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3118 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
3119 	sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_INT_OP, SLJIT_MEM1(SLJIT_SAVED_REG2), 0, SLJIT_TEMPORARY_REG1, 0);
3120 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -1);
3121 	sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0);
3122 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_w), SLJIT_C_ZERO);
3123 	sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_KEEP_FLAGS, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_w));
3124 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3125 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_w), SLJIT_C_NOT_ZERO);
3126 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, BITN(58));
3127 	sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_SAVED_REG1), 9 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3128 	sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 10 * sizeof(sljit_w));
3129 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 10 * sizeof(sljit_w), SLJIT_C_NOT_ZERO);
3130 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0);
3131 	sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_SAVED_REG1), 11 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3132 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3133 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(0xff08a00000));
3134 #else
3135 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x08a00000);
3136 #endif
3137 	sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_INT_OP, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(int), SLJIT_TEMPORARY_REG1, 0);
3138 	sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_INT_OP, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0);
3139 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 12 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3140 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3141 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(0xffc8a00000));
3142 #else
3143 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xc8a00000);
3144 #endif
3145 	sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_SET_E | SLJIT_INT_OP, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0);
3146 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 13 * sizeof(sljit_w), SLJIT_C_ZERO);
3147 	sljit_emit_op1(compiler, SLJIT_CLZ | SLJIT_SET_E | SLJIT_INT_OP, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0);
3148 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 14 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3149 
3150 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3151 
3152 	code.code = sljit_generate_code(compiler);
3153 	CHECK(compiler);
3154 	sljit_free_compiler(compiler);
3155 
3156 	code.func2((sljit_w)&buf, (sljit_w)&ibuf);
3157 	FAILED(buf[0] != RESN(27), "test37 case 1 failed\n");
3158 	FAILED(buf[1] != RESN(47), "test37 case 2 failed\n");
3159 	FAILED(buf[2] != 0, "test37 case 3 failed\n");
3160 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3161 	FAILED(buf[3] != 64, "test37 case 4 failed\n");
3162 #else
3163 	FAILED(buf[3] != 32, "test37 case 4 failed\n");
3164 #endif
3165 	FAILED(buf[4] != 1, "test37 case 5 failed\n");
3166 	FAILED(buf[5] != 0, "test37 case 6 failed\n");
3167 	FAILED(ibuf[0] != 32, "test37 case 7 failed\n");
3168 	FAILED(buf[6] != 1, "test37 case 8 failed\n");
3169 	FAILED(buf[7] != RESN(13), "test37 case 9 failed\n");
3170 #if !(defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3171 	FAILED(buf[8] != 0, "test37 case 10 failed\n");
3172 #endif
3173 	FAILED(buf[9] != RESN(58), "test37 case 11 failed\n");
3174 	FAILED(buf[10] != 0, "test37 case 12 failed\n");
3175 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3176 	FAILED(buf[11] != 64, "test37 case 13 failed\n");
3177 #else
3178 	FAILED(buf[11] != 32, "test37 case 13 failed\n");
3179 #endif
3180 	FAILED(ibuf[1] != 4, "test37 case 14 failed\n");
3181 	FAILED(buf[12] != 4, "test37 case 15 failed\n");
3182 	FAILED(buf[13] != 1, "test37 case 16 failed\n");
3183 	FAILED(buf[14] != 0, "test37 case 17 failed\n");
3184 
3185 	sljit_free_code(code.code);
3186 	printf("test37 ok\n");
3187 	successful_tests++;
3188 }
3189 #undef BITN
3190 #undef RESN
3191 
3192 static void test38(void)
3193 {
3194 #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)
3195 	/* Test stack utility. */
3196 	executable_code code;
3197 	struct sljit_compiler* compiler = sljit_create_compiler();
3198 	struct sljit_jump* alloc_fail;
3199 	struct sljit_jump* alloc2_fail;
3200 	struct sljit_jump* alloc3_fail;
3201 	struct sljit_jump* jump;
3202 	struct sljit_label* label;
3203 
3204 	FAILED(!compiler, "cannot create compiler\n");
3205 
3206 	sljit_emit_enter(compiler, 0, 2, 1, 0);
3207 
3208 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 8192);
3209 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 65536);
3210 	sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_allocate_stack));
3211 	alloc_fail = sljit_emit_cmp(compiler, SLJIT_C_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3212 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_RETURN_REG, 0);
3213 
3214 	/* Write 8k data. */
3215 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(struct sljit_stack, base), SLJIT_IMM, sizeof(sljit_w));
3216 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 8192);
3217 	label = sljit_emit_label(compiler);
3218 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), sizeof(sljit_w), SLJIT_IMM, -1);
3219 	jump = sljit_emit_cmp(compiler, SLJIT_C_LESS, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
3220 	sljit_set_label(jump, label);
3221 
3222 	/* Grow stack. */
3223 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_REG1, 0);
3224 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(struct sljit_stack, base), SLJIT_IMM, 65536);
3225 	sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_stack_resize));
3226 	alloc2_fail = sljit_emit_cmp(compiler, SLJIT_C_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3227 
3228 	/* Write 64k data. */
3229 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(struct sljit_stack, base), SLJIT_IMM, sizeof(sljit_w));
3230 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 65536);
3231 	label = sljit_emit_label(compiler);
3232 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), sizeof(sljit_w), SLJIT_IMM, -1);
3233 	jump = sljit_emit_cmp(compiler, SLJIT_C_LESS, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
3234 	sljit_set_label(jump, label);
3235 
3236 	/* Shrink stack. */
3237 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_REG1, 0);
3238 	sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(struct sljit_stack, base), SLJIT_IMM, 32768);
3239 	sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_stack_resize));
3240 	alloc3_fail = sljit_emit_cmp(compiler, SLJIT_C_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3241 
3242 	/* Write 32k data. */
3243 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(struct sljit_stack, base), SLJIT_IMM, sizeof(sljit_w));
3244 	sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(struct sljit_stack, limit), SLJIT_IMM, sizeof(sljit_w));
3245 	label = sljit_emit_label(compiler);
3246 	sljit_emit_op1(compiler, SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), sizeof(sljit_w), SLJIT_IMM, -1);
3247 	jump = sljit_emit_cmp(compiler, SLJIT_C_LESS, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
3248 	sljit_set_label(jump, label);
3249 
3250 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_SAVED_REG1, 0);
3251 	sljit_emit_ijump(compiler, SLJIT_CALL1, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_free_stack));
3252 
3253 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
3254 	label = sljit_emit_label(compiler);
3255 	sljit_set_label(alloc_fail, label);
3256 	sljit_set_label(alloc2_fail, label);
3257 	sljit_set_label(alloc3_fail, label);
3258 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3259 
3260 	code.code = sljit_generate_code(compiler);
3261 	CHECK(compiler);
3262 	sljit_free_compiler(compiler);
3263 
3264 	/* Just survive this. */
3265 	FAILED(code.func0() != 1, "test38 case 1 failed\n");
3266 	sljit_free_code(code.code);
3267 #endif
3268 	printf("test38 ok\n");
3269 	successful_tests++;
3270 }
3271 
3272 static void test39(void)
3273 {
3274 	/* Test error handling. */
3275 	executable_code code;
3276 	struct sljit_compiler* compiler = sljit_create_compiler();
3277 	struct sljit_jump* jump;
3278 
3279 	FAILED(!compiler, "cannot create compiler\n");
3280 
3281 	/* Such assignment should never happen in a regular program. */
3282 	compiler->error = -3967;
3283 
3284 	SLJIT_ASSERT(sljit_emit_enter(compiler, 2, 5, 5, 32) == -3967);
3285 	SLJIT_ASSERT(sljit_emit_return(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0) == -3967);
3286 	SLJIT_ASSERT(sljit_emit_op0(compiler, SLJIT_NOP) == -3967);
3287 	SLJIT_ASSERT(sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM2(SLJIT_TEMPORARY_REG1, SLJIT_TEMPORARY_REG2), 1) == -3967);
3288 	SLJIT_ASSERT(sljit_emit_op2(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), 64, SLJIT_MEM1(SLJIT_SAVED_REG1), -64) == -3967);
3289 	SLJIT_ASSERT(sljit_emit_fop1(compiler, SLJIT_FABS, SLJIT_FLOAT_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), 0) == -3967);
3290 	SLJIT_ASSERT(sljit_emit_fop2(compiler, SLJIT_FDIV, SLJIT_FLOAT_REG3, 0, SLJIT_MEM2(SLJIT_TEMPORARY_REG1, SLJIT_SAVED_REG1), 0, SLJIT_FLOAT_REG3, 0) == -3967);
3291 	SLJIT_ASSERT(!sljit_emit_label(compiler));
3292 	jump = sljit_emit_jump(compiler, SLJIT_CALL3);
3293 	SLJIT_ASSERT(!jump);
3294 	sljit_set_label(jump, (struct sljit_label*)0x123450);
3295 	sljit_set_target(jump, 0x123450);
3296 	jump = sljit_emit_cmp(compiler, SLJIT_C_SIG_LESS_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
3297 	SLJIT_ASSERT(!jump);
3298 	SLJIT_ASSERT(sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), 8) == -3967);
3299 	SLJIT_ASSERT(sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_C_MUL_OVERFLOW) == -3967);
3300 	SLJIT_ASSERT(!sljit_emit_const(compiler, SLJIT_TEMPORARY_REG1, 0, 99));
3301 
3302 	SLJIT_ASSERT(!compiler->labels && !compiler->jumps && !compiler->consts);
3303 	SLJIT_ASSERT(!compiler->last_label && !compiler->last_jump && !compiler->last_const);
3304 	SLJIT_ASSERT(!compiler->buf->next && !compiler->buf->used_size);
3305 	SLJIT_ASSERT(!compiler->abuf->next && !compiler->abuf->used_size);
3306 
3307 	code.code = sljit_generate_code(compiler);
3308 	SLJIT_ASSERT(!code.code && sljit_get_compiler_error(compiler) == -3967);
3309 	sljit_free_compiler(compiler);
3310 
3311 	printf("test39 ok\n");
3312 	successful_tests++;
3313 }
3314 
3315 static void test40(void)
3316 {
3317 	/* Test emit_cond_value. */
3318 	executable_code code;
3319 	struct sljit_compiler* compiler = sljit_create_compiler();
3320 	sljit_w buf[9];
3321 
3322 	FAILED(!compiler, "cannot create compiler\n");
3323 	buf[0] = -100;
3324 	buf[1] = -100;
3325 	buf[2] = -100;
3326 	buf[3] = -8;
3327 	buf[4] = -100;
3328 	buf[5] = -100;
3329 	buf[6] = 0;
3330 	buf[7] = 0;
3331 	buf[8] = -100;
3332 
3333 	sljit_emit_enter(compiler, 1, 3, 4, sizeof(sljit_w));
3334 
3335 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -5);
3336 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_IMM, -6, SLJIT_TEMPORARY_REG1, 0);
3337 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0x123456);
3338 	sljit_emit_cond_value(compiler, SLJIT_OR, SLJIT_TEMPORARY_REG2, 0, SLJIT_C_SIG_LESS);
3339 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG2, 0);
3340 
3341 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -13);
3342 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_IMM, -13, SLJIT_TEMPORARY_REG1, 0);
3343 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), 0, SLJIT_IMM, 0);
3344 	sljit_emit_cond_value(compiler, SLJIT_OR | SLJIT_KEEP_FLAGS, SLJIT_MEM1(SLJIT_LOCALS_REG), 0, SLJIT_C_EQUAL);
3345 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_C_EQUAL);
3346 	sljit_emit_op2(compiler, SLJIT_OR | SLJIT_KEEP_FLAGS, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_MEM1(SLJIT_LOCALS_REG), 0);
3347 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0);
3348 	sljit_emit_cond_value(compiler, SLJIT_OR | SLJIT_SET_E, SLJIT_TEMPORARY_REG2, 0, SLJIT_C_EQUAL);
3349 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 2, SLJIT_C_EQUAL);
3350 
3351 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -13);
3352 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 3);
3353 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_S, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
3354 	sljit_emit_cond_value(compiler, SLJIT_OR, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG2), SLJIT_WORD_SHIFT, SLJIT_C_SIG_LESS);
3355 
3356 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -8);
3357 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 33);
3358 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG2, 0);
3359 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 0);
3360 	sljit_emit_cond_value(compiler, SLJIT_OR | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
3361 	sljit_emit_cond_value(compiler, SLJIT_OR | SLJIT_KEEP_FLAGS, SLJIT_SAVED_REG2, 0, SLJIT_C_EQUAL);
3362 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG1, 0, SLJIT_IMM, 0x88);
3363 	sljit_emit_cond_value(compiler, SLJIT_OR | SLJIT_KEEP_FLAGS, SLJIT_SAVED_EREG1, 0, SLJIT_C_NOT_EQUAL);
3364 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 4, SLJIT_SAVED_REG2, 0);
3365 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 5, SLJIT_SAVED_EREG1, 0);
3366 
3367 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x84);
3368 	sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_IMM, 0x180, SLJIT_TEMPORARY_REG1, 0);
3369 	sljit_emit_cond_value(compiler, SLJIT_OR | SLJIT_SET_E, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 6, SLJIT_C_EQUAL);
3370 	sljit_emit_cond_value(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 7, SLJIT_C_EQUAL);
3371 
3372 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1);
3373 	sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 1);
3374 	sljit_emit_cond_value(compiler, SLJIT_OR | SLJIT_SET_E, SLJIT_TEMPORARY_REG1, 0, SLJIT_C_NOT_EQUAL);
3375 	sljit_emit_cond_value(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 8, SLJIT_C_NOT_EQUAL);
3376 
3377 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), 0, SLJIT_IMM, 0xbaddead);
3378 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), 0);
3379 
3380 	code.code = sljit_generate_code(compiler);
3381 	CHECK(compiler);
3382 	sljit_free_compiler(compiler);
3383 
3384 	FAILED(code.func1((sljit_w)&buf) != 0xbaddead, "test40 case 1 failed\n");
3385 	FAILED(buf[0] != 0x123457, "test40 case 2 failed\n");
3386 	FAILED(buf[1] != 1, "test40 case 3 failed\n");
3387 	FAILED(buf[2] != 0, "test40 case 4 failed\n");
3388 	FAILED(buf[3] != -7, "test40 case 5 failed\n");
3389 	FAILED(buf[4] != 0, "test40 case 6 failed\n");
3390 	FAILED(buf[5] != 0x89, "test40 case 7 failed\n");
3391 	FAILED(buf[6] != 0, "test40 case 8 failed\n");
3392 	FAILED(buf[7] != 1, "test40 case 9 failed\n");
3393 	FAILED(buf[8] != 1, "test40 case 10 failed\n");
3394 
3395 	printf("test40 ok\n");
3396 	successful_tests++;
3397 }
3398 
3399 static void test41(void)
3400 {
3401 	/* Test inline assembly. */
3402 	executable_code code;
3403 	struct sljit_compiler* compiler = sljit_create_compiler();
3404 	int i;
3405 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3406 	sljit_ub inst[16];
3407 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3408 	sljit_ub inst[16];
3409 	int reg;
3410 #else
3411 	sljit_ui inst;
3412 #endif
3413 
3414 	for (i = 1; i <= SLJIT_NO_REGISTERS; i++) {
3415 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3416 		if (i == SLJIT_TEMPORARY_EREG1 || i == SLJIT_TEMPORARY_EREG2
3417 				|| i == SLJIT_SAVED_EREG1 || i == SLJIT_SAVED_EREG2) {
3418 			SLJIT_ASSERT(sljit_get_register_index(i) == -1);
3419 			continue;
3420 		}
3421 #endif
3422 		SLJIT_ASSERT(sljit_get_register_index(i) >= 0 && sljit_get_register_index(i) < 32);
3423 	}
3424 
3425 	FAILED(!compiler, "cannot create compiler\n");
3426 	sljit_emit_enter(compiler, 2, 3, 3, 0);
3427 
3428 	/* Returns with the sum of SLJIT_SAVED_REG1 and SLJIT_SAVED_REG2. */
3429 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3430 	/* lea SLJIT_RETURN_REG, [SLJIT_SAVED_REG1, SLJIT_SAVED_REG2] */
3431 	inst[0] = 0x48;
3432 	inst[1] = 0x8d;
3433 	inst[2] = 0x04 | ((sljit_get_register_index(SLJIT_RETURN_REG) & 0x7) << 3);
3434 	inst[3] = (sljit_get_register_index(SLJIT_SAVED_REG1) & 0x7)
3435 		| ((sljit_get_register_index(SLJIT_SAVED_REG2) & 0x7) << 3);
3436 	sljit_emit_op_custom(compiler, inst, 4);
3437 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3438 	/* lea SLJIT_RETURN_REG, [SLJIT_SAVED_REG1, SLJIT_SAVED_REG2] */
3439 	inst[0] = 0x48; /* REX_W */
3440 	inst[1] = 0x8d;
3441 	inst[2] = 0x04;
3442 	reg = sljit_get_register_index(SLJIT_RETURN_REG);
3443 	inst[2] |= ((reg & 0x7) << 3);
3444 	if (reg > 7)
3445 		inst[0] |= 0x04; /* REX_R */
3446 	reg = sljit_get_register_index(SLJIT_SAVED_REG1);
3447 	inst[3] = reg & 0x7;
3448 	if (reg > 7)
3449 		inst[0] |= 0x01; /* REX_B */
3450 	reg = sljit_get_register_index(SLJIT_SAVED_REG2);
3451 	inst[3] |= (reg & 0x7) << 3;
3452 	if (reg > 7)
3453 		inst[0] |= 0x02; /* REX_X */
3454 	sljit_emit_op_custom(compiler, inst, 4);
3455 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
3456 	/* add rd, rn, rm */
3457 	inst = 0xe0800000 | (sljit_get_register_index(SLJIT_RETURN_REG) << 12)
3458 		| (sljit_get_register_index(SLJIT_SAVED_REG1) << 16)
3459 		| sljit_get_register_index(SLJIT_SAVED_REG2);
3460 	sljit_emit_op_custom(compiler, &inst, sizeof(sljit_ui));
3461 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
3462 	/* add rd, rn, rm */
3463 	inst = 0xeb000000 | (sljit_get_register_index(SLJIT_RETURN_REG) << 8)
3464 		| (sljit_get_register_index(SLJIT_SAVED_REG1) << 16)
3465 		| sljit_get_register_index(SLJIT_SAVED_REG2);
3466 	sljit_emit_op_custom(compiler, &inst, sizeof(sljit_ui));
3467 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
3468 	/* add rD, rA, rB */
3469 	inst = (31 << 26) | (266 << 1) | (sljit_get_register_index(SLJIT_RETURN_REG) << 21)
3470 		| (sljit_get_register_index(SLJIT_SAVED_REG1) << 16)
3471 		| (sljit_get_register_index(SLJIT_SAVED_REG2) << 11);
3472 	sljit_emit_op_custom(compiler, &inst, sizeof(sljit_ui));
3473 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
3474 	/* addu rd, rs, rt */
3475 	inst = 33 | (sljit_get_register_index(SLJIT_RETURN_REG) << 11)
3476 		| (sljit_get_register_index(SLJIT_SAVED_REG1) << 21)
3477 		| (sljit_get_register_index(SLJIT_SAVED_REG2) << 16);
3478 	sljit_emit_op_custom(compiler, &inst, sizeof(sljit_ui));
3479 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3480 	/* add rd, rs1, rs2 */
3481 	inst = (0x2 << 30) | (sljit_get_register_index(SLJIT_RETURN_REG) << 25)
3482 		| (sljit_get_register_index(SLJIT_SAVED_REG1) << 14)
3483 		| sljit_get_register_index(SLJIT_SAVED_REG2);
3484 	sljit_emit_op_custom(compiler, &inst, sizeof(sljit_ui));
3485 #else
3486 	inst = 0;
3487 	sljit_emit_op_custom(compiler, &inst, 0);
3488 #endif
3489 
3490 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
3491 
3492 	code.code = sljit_generate_code(compiler);
3493 	CHECK(compiler);
3494 	sljit_free_compiler(compiler);
3495 
3496 	FAILED(code.func2(32, -11) != 21, "test41 case 1 failed\n");
3497 	FAILED(code.func2(1000, 234) != 1234, "test41 case 2 failed\n");
3498 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3499 	FAILED(code.func2(SLJIT_W(0x20f0a04090c06070), SLJIT_W(0x020f0a04090c0607)) != SLJIT_W(0x22ffaa4499cc6677), "test41 case 3 failed\n");
3500 #endif
3501 
3502 	printf("test41 ok\n");
3503 	successful_tests++;
3504 }
3505 
3506 static void test42(void)
3507 {
3508 	/* Test long multiply and division. */
3509 	executable_code code;
3510 	struct sljit_compiler* compiler = sljit_create_compiler();
3511 	int i;
3512 	sljit_w buf[7 + 8 + 4];
3513 
3514 	FAILED(!compiler, "cannot create compiler\n");
3515 	for (i = 0; i < 7 + 8; i++)
3516 		buf[i] = -1;
3517 
3518 	sljit_emit_enter(compiler, 1, 5, 5, 0);
3519 
3520 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, -0x1fb308a);
3521 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG1, 0, SLJIT_IMM, 0xf50c873);
3522 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_EREG2, 0, SLJIT_IMM, 0x8a0475b);
3523 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 0x9dc849b);
3524 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_IMM, -0x7c69a35);
3525 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG1, 0, SLJIT_IMM, 0x5a4d0c4);
3526 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_EREG2, 0, SLJIT_IMM, 0x9a3b06d);
3527 
3528 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3529 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3530 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3531 	sljit_emit_op0(compiler, SLJIT_UMUL);
3532 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3533 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0);
3534 
3535 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3536 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3537 	sljit_emit_op0(compiler, SLJIT_SMUL);
3538 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 9 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3539 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 10 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0);
3540 
3541 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3542 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3543 	sljit_emit_op0(compiler, SLJIT_UDIV);
3544 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 11 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3545 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 12 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0);
3546 
3547 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3548 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3549 	sljit_emit_op0(compiler, SLJIT_SDIV);
3550 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 13 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3551 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 14 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0);
3552 
3553 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(0x5cf783d3cf0a74b0));
3554 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, SLJIT_W(0x3d5df42d03a28fc7));
3555 	sljit_emit_op0(compiler, SLJIT_UDIV | SLJIT_INT_OP);
3556 	sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0);
3557 	sljit_emit_op1(compiler, SLJIT_MOV_UI, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0);
3558 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 15 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3559 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 16 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0);
3560 
3561 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, SLJIT_W(0x371df5197ba26a28));
3562 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, SLJIT_W(0x46c78a5cfd6a420c));
3563 	sljit_emit_op0(compiler, SLJIT_SDIV | SLJIT_INT_OP);
3564 	sljit_emit_op1(compiler, SLJIT_MOV_SI, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0);
3565 	sljit_emit_op1(compiler, SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0);
3566 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 17 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3567 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 18 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0);
3568 
3569 #else
3570 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -0x58cd67f5);
3571 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0x3cb088df);
3572 	sljit_emit_op0(compiler, SLJIT_UMUL);
3573 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 7 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3574 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 8 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0);
3575 
3576 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -0x58cd67f5);
3577 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0x3cb088df);
3578 	sljit_emit_op0(compiler, SLJIT_SMUL);
3579 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 9 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3580 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 10 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0);
3581 
3582 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -0x58cd67f5);
3583 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0x3cb088df);
3584 	sljit_emit_op0(compiler, SLJIT_UDIV);
3585 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 11 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3586 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 12 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0);
3587 
3588 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, -0x58cd67f5);
3589 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0x3cb088df);
3590 	sljit_emit_op0(compiler, SLJIT_SDIV);
3591 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 13 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3592 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 14 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0);
3593 
3594 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0xcf0a74b0);
3595 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0x03a28fc7);
3596 	sljit_emit_op0(compiler, SLJIT_UDIV | SLJIT_INT_OP);
3597 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 15 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3598 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 16 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0);
3599 
3600 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0x7ba26a28);
3601 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, (sljit_w)0xfd6a420c);
3602 	sljit_emit_op0(compiler, SLJIT_SDIV | SLJIT_INT_OP);
3603 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 17 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
3604 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 18 * sizeof(sljit_w), SLJIT_TEMPORARY_REG2, 0);
3605 #endif
3606 
3607 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG3, 0);
3608 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_TEMPORARY_EREG1, 0);
3609 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 2 * sizeof(sljit_w), SLJIT_TEMPORARY_EREG2, 0);
3610 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(sljit_w), SLJIT_SAVED_REG2, 0);
3611 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 4 * sizeof(sljit_w), SLJIT_SAVED_REG3, 0);
3612 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 5 * sizeof(sljit_w), SLJIT_SAVED_EREG1, 0);
3613 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), 6 * sizeof(sljit_w), SLJIT_SAVED_EREG2, 0);
3614 
3615 	sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3616 
3617 	code.code = sljit_generate_code(compiler);
3618 	CHECK(compiler);
3619 	sljit_free_compiler(compiler);
3620 
3621 	code.func1((sljit_w)&buf);
3622 
3623 	FAILED(buf[0] != -0x1fb308a, "test42 case 1 failed\n");
3624 	FAILED(buf[1] != 0xf50c873, "test42 case 2 failed\n");
3625 	FAILED(buf[2] != 0x8a0475b, "test42 case 3 failed\n");
3626 	FAILED(buf[3] != 0x9dc849b, "test42 case 4 failed\n");
3627 	FAILED(buf[4] != -0x7c69a35, "test42 case 5 failed\n");
3628 	FAILED(buf[5] != 0x5a4d0c4, "test42 case 6 failed\n");
3629 	FAILED(buf[6] != 0x9a3b06d, "test42 case 7 failed\n");
3630 
3631 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3632 	FAILED(buf[7] != SLJIT_W(-4388959407985636971), "test42 case 8 failed\n");
3633 	FAILED(buf[8] != SLJIT_W(2901680654366567099), "test42 case 9 failed\n");
3634 	FAILED(buf[9] != SLJIT_W(-4388959407985636971), "test42 case 10 failed\n");
3635 	FAILED(buf[10] != SLJIT_W(-1677173957268872740), "test42 case 11 failed\n");
3636 	FAILED(buf[11] != SLJIT_W(2), "test42 case 12 failed\n");
3637 	FAILED(buf[12] != SLJIT_W(2532236178951865933), "test42 case 13 failed\n");
3638 	FAILED(buf[13] != SLJIT_W(-1), "test42 case 14 failed\n");
3639 	FAILED(buf[14] != SLJIT_W(-2177944059851366166), "test42 case 15 failed\n");
3640 #else
3641 	FAILED(buf[7] != -1587000939, "test42 case 8 failed\n");
3642 	FAILED(buf[8] != 665003983, "test42 case 9 failed\n");
3643 	FAILED(buf[9] != -1587000939, "test42 case 10 failed\n");
3644 	FAILED(buf[10] != -353198352, "test42 case 11 failed\n");
3645 	FAILED(buf[11] != 2, "test42 case 12 failed\n");
3646 	FAILED(buf[12] != 768706125, "test42 case 13 failed\n");
3647 	FAILED(buf[13] != -1, "test42 case 14 failed\n");
3648 	FAILED(buf[14] != -471654166, "test42 case 15 failed\n");
3649 #endif
3650 
3651 	FAILED(buf[15] != SLJIT_W(56), "test42 case 16 failed\n");
3652 	FAILED(buf[16] != SLJIT_W(58392872), "test42 case 17 failed\n");
3653 	FAILED(buf[17] != SLJIT_W(-47), "test42 case 18 failed\n");
3654 	FAILED(buf[18] != SLJIT_W(35949148), "test42 case 19 failed\n");
3655 	printf("test42 ok\n");
3656 	successful_tests++;
3657 }
3658 
3659 static void test43(void)
3660 {
3661 	/* Test floating point compare. */
3662 	executable_code code;
3663 	struct sljit_compiler* compiler = sljit_create_compiler();
3664 	struct sljit_jump* jump;
3665 
3666 	union {
3667 		double value;
3668 		struct {
3669 			int value1;
3670 			int value2;
3671 		} u;
3672 	} dbuf[4];
3673 
3674 	if (!sljit_is_fpu_available()) {
3675 		printf("no fpu available, test43 skipped\n");
3676 		successful_tests++;
3677 		if (compiler)
3678 			sljit_free_compiler(compiler);
3679 		return;
3680 	}
3681 
3682 	FAILED(!compiler, "cannot create compiler\n");
3683 
3684 	dbuf[0].value = 12.125;
3685 	/* a NaN */
3686 	dbuf[1].u.value1 = 0x7fffffff;
3687 	dbuf[1].u.value2 = 0x7fffffff;
3688 	dbuf[2].value = -13.5;
3689 	dbuf[3].value = 12.125;
3690 
3691 	sljit_emit_enter(compiler, 1, 1, 1, 0);
3692 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 2);
3693 	/* dbuf[0] < dbuf[2] -> -2 */
3694 	jump = sljit_emit_fcmp(compiler, SLJIT_C_FLOAT_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG1), SLJIT_FLOAT_SHIFT);
3695 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, -2);
3696 
3697 	sljit_set_label(jump, sljit_emit_label(compiler));
3698 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_FLOAT_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
3699 	/* dbuf[0] and dbuf[1] is not NaN -> 5 */
3700 	jump = sljit_emit_fcmp(compiler, SLJIT_C_FLOAT_UNORDERED, SLJIT_MEM0(), (sljit_w)&dbuf[1], SLJIT_FLOAT_REG2, 0);
3701 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 5);
3702 
3703 	sljit_set_label(jump, sljit_emit_label(compiler));
3704 	sljit_emit_fop1(compiler, SLJIT_FMOV, SLJIT_FLOAT_REG3, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 3 * sizeof(double));
3705 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 11);
3706 	/* dbuf[0] == dbuf[3] -> 11 */
3707 	jump = sljit_emit_fcmp(compiler, SLJIT_C_FLOAT_EQUAL, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_FLOAT_REG3, 0);
3708 
3709 	/* else -> -17 */
3710 	sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, -17);
3711 	sljit_set_label(jump, sljit_emit_label(compiler));
3712 	sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
3713 
3714 	code.code = sljit_generate_code(compiler);
3715 	CHECK(compiler);
3716 	sljit_free_compiler(compiler);
3717 
3718 	FAILED(code.func1((sljit_w)&dbuf) != 11, "test43 case 1 failed\n");
3719 	dbuf[3].value = 12;
3720 	FAILED(code.func1((sljit_w)&dbuf) != -17, "test43 case 2 failed\n");
3721 	dbuf[1].value = 0;
3722 	FAILED(code.func1((sljit_w)&dbuf) != 5, "test43 case 3 failed\n");
3723 	dbuf[2].value = 20;
3724 	FAILED(code.func1((sljit_w)&dbuf) != -2, "test43 case 4 failed\n");
3725 
3726 	printf("test43 ok\n");
3727 	successful_tests++;
3728 }
3729 
3730 void sljit_test(void);
3731 void sljit_test(void)
3732 {
3733 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
3734 	test_exec_allocator();
3735 #endif
3736 	test1();
3737 	test2();
3738 	test3();
3739 	test4();
3740 	test5();
3741 	test6();
3742 	test7();
3743 	test8();
3744 	test9();
3745 	test10();
3746 	test11();
3747 	test12();
3748 	test13();
3749 	test14();
3750 	test15();
3751 	test16();
3752 	test17();
3753 	test18();
3754 	test19();
3755 	test20();
3756 	test21();
3757 	test22();
3758 	test23();
3759 	test24();
3760 	test25();
3761 	test26();
3762 	test27();
3763 	test28();
3764 	test29();
3765 	test30();
3766 	test31();
3767 	test32();
3768 	test33();
3769 	test34();
3770 	test35();
3771 	test36();
3772 	test37();
3773 	test38();
3774 	test39();
3775 	test40();
3776 	test41();
3777 	test42();
3778 	test43();
3779 	printf("On %s%s: ", sljit_get_platform_name(), sljit_is_fpu_available() ? " (+fpu)" : "");
3780 	if (successful_tests == 43)
3781 		printf("All tests are passed!\n");
3782 	else
3783 		printf("Successful test ratio: %d%%.\n", successful_tests * 100 / 43);
3784 }
3785