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