| 86 |
return code_ptr; |
return code_ptr; |
| 87 |
} |
} |
| 88 |
|
|
| 89 |
SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_enter(struct sljit_compiler *compiler, int args, int temporaries, int generals, int local_size) |
SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_enter(struct sljit_compiler *compiler, int args, int temporaries, int saveds, int local_size) |
| 90 |
{ |
{ |
| 91 |
int size, pushed_size; |
int size, pushed_size; |
| 92 |
sljit_ub *buf; |
sljit_ub *buf; |
| 93 |
|
|
| 94 |
CHECK_ERROR(); |
CHECK_ERROR(); |
| 95 |
check_sljit_emit_enter(compiler, args, temporaries, generals, local_size); |
check_sljit_emit_enter(compiler, args, temporaries, saveds, local_size); |
| 96 |
|
|
| 97 |
compiler->temporaries = temporaries; |
compiler->temporaries = temporaries; |
| 98 |
compiler->generals = generals; |
compiler->saveds = saveds; |
| 99 |
compiler->flags_saved = 0; |
compiler->flags_saved = 0; |
| 100 |
|
#if (defined SLJIT_DEBUG && SLJIT_DEBUG) |
| 101 |
|
compiler->logical_local_size = local_size; |
| 102 |
|
#endif |
| 103 |
|
|
| 104 |
size = generals; |
size = saveds; |
| 105 |
/* Including the return address saved by the call instruction. */ |
/* Including the return address saved by the call instruction. */ |
| 106 |
pushed_size = (generals + 1) * sizeof(sljit_w); |
pushed_size = (saveds + 1) * sizeof(sljit_w); |
| 107 |
#ifndef _WIN64 |
#ifndef _WIN64 |
| 108 |
if (generals >= 2) |
if (saveds >= 2) |
| 109 |
size += generals - 1; |
size += saveds - 1; |
| 110 |
#else |
#else |
| 111 |
/* Saving the virtual stack pointer. */ |
if (saveds >= 4) |
| 112 |
compiler->has_locals = local_size > 0; |
size += saveds - 3; |
|
if (local_size > 0) { |
|
|
size += 2; |
|
|
pushed_size += sizeof(sljit_w); |
|
|
} |
|
|
if (generals >= 4) |
|
|
size += generals - 3; |
|
| 113 |
if (temporaries >= 5) { |
if (temporaries >= 5) { |
| 114 |
size += (5 - 4) * 2; |
size += (5 - 4) * 2; |
| 115 |
pushed_size += sizeof(sljit_w); |
pushed_size += sizeof(sljit_w); |
| 121 |
FAIL_IF(!buf); |
FAIL_IF(!buf); |
| 122 |
|
|
| 123 |
INC_SIZE(size); |
INC_SIZE(size); |
| 124 |
if (generals >= 5) { |
if (saveds >= 5) { |
| 125 |
SLJIT_COMPILE_ASSERT(reg_map[SLJIT_GENERAL_EREG2] >= 8, general_ereg2_is_hireg); |
SLJIT_COMPILE_ASSERT(reg_map[SLJIT_SAVED_EREG2] >= 8, saved_ereg2_is_hireg); |
| 126 |
*buf++ = REX_B; |
*buf++ = REX_B; |
| 127 |
PUSH_REG(reg_lmap[SLJIT_GENERAL_EREG2]); |
PUSH_REG(reg_lmap[SLJIT_SAVED_EREG2]); |
| 128 |
} |
} |
| 129 |
if (generals >= 4) { |
if (saveds >= 4) { |
| 130 |
SLJIT_COMPILE_ASSERT(reg_map[SLJIT_GENERAL_EREG1] >= 8, general_ereg1_is_hireg); |
SLJIT_COMPILE_ASSERT(reg_map[SLJIT_SAVED_EREG1] >= 8, saved_ereg1_is_hireg); |
| 131 |
*buf++ = REX_B; |
*buf++ = REX_B; |
| 132 |
PUSH_REG(reg_lmap[SLJIT_GENERAL_EREG1]); |
PUSH_REG(reg_lmap[SLJIT_SAVED_EREG1]); |
| 133 |
} |
} |
| 134 |
if (generals >= 3) { |
if (saveds >= 3) { |
| 135 |
#ifndef _WIN64 |
#ifndef _WIN64 |
| 136 |
SLJIT_COMPILE_ASSERT(reg_map[SLJIT_GENERAL_REG3] >= 8, general_reg3_is_hireg); |
SLJIT_COMPILE_ASSERT(reg_map[SLJIT_SAVED_REG3] >= 8, saved_reg3_is_hireg); |
| 137 |
*buf++ = REX_B; |
*buf++ = REX_B; |
| 138 |
#else |
#else |
| 139 |
SLJIT_COMPILE_ASSERT(reg_map[SLJIT_GENERAL_REG3] < 8, general_reg3_is_loreg); |
SLJIT_COMPILE_ASSERT(reg_map[SLJIT_SAVED_REG3] < 8, saved_reg3_is_loreg); |
| 140 |
#endif |
#endif |
| 141 |
PUSH_REG(reg_lmap[SLJIT_GENERAL_REG3]); |
PUSH_REG(reg_lmap[SLJIT_SAVED_REG3]); |
| 142 |
} |
} |
| 143 |
if (generals >= 2) { |
if (saveds >= 2) { |
| 144 |
#ifndef _WIN64 |
#ifndef _WIN64 |
| 145 |
SLJIT_COMPILE_ASSERT(reg_map[SLJIT_GENERAL_REG2] >= 8, general_reg2_is_hireg); |
SLJIT_COMPILE_ASSERT(reg_map[SLJIT_SAVED_REG2] >= 8, saved_reg2_is_hireg); |
| 146 |
*buf++ = REX_B; |
*buf++ = REX_B; |
| 147 |
#else |
#else |
| 148 |
SLJIT_COMPILE_ASSERT(reg_map[SLJIT_GENERAL_REG2] < 8, general_reg2_is_loreg); |
SLJIT_COMPILE_ASSERT(reg_map[SLJIT_SAVED_REG2] < 8, saved_reg2_is_loreg); |
| 149 |
#endif |
#endif |
| 150 |
PUSH_REG(reg_lmap[SLJIT_GENERAL_REG2]); |
PUSH_REG(reg_lmap[SLJIT_SAVED_REG2]); |
| 151 |
} |
} |
| 152 |
if (generals >= 1) { |
if (saveds >= 1) { |
| 153 |
SLJIT_COMPILE_ASSERT(reg_map[SLJIT_GENERAL_REG1] < 8, general_reg1_is_loreg); |
SLJIT_COMPILE_ASSERT(reg_map[SLJIT_SAVED_REG1] < 8, saved_reg1_is_loreg); |
| 154 |
PUSH_REG(reg_lmap[SLJIT_GENERAL_REG1]); |
PUSH_REG(reg_lmap[SLJIT_SAVED_REG1]); |
| 155 |
} |
} |
| 156 |
#ifdef _WIN64 |
#ifdef _WIN64 |
| 157 |
if (temporaries >= 5) { |
if (temporaries >= 5) { |
| 159 |
*buf++ = REX_B; |
*buf++ = REX_B; |
| 160 |
PUSH_REG(reg_lmap[SLJIT_TEMPORARY_EREG2]); |
PUSH_REG(reg_lmap[SLJIT_TEMPORARY_EREG2]); |
| 161 |
} |
} |
|
if (local_size > 0) { |
|
|
SLJIT_COMPILE_ASSERT(reg_map[SLJIT_LOCALS_REG] >= 8, locals_reg_is_hireg); |
|
|
*buf++ = REX_B; |
|
|
PUSH_REG(reg_lmap[SLJIT_LOCALS_REG]); |
|
|
} |
|
| 162 |
#endif |
#endif |
| 163 |
|
|
| 164 |
#ifndef _WIN64 |
#ifndef _WIN64 |
| 165 |
if (args > 0) { |
if (args > 0) { |
| 166 |
*buf++ = REX_W; |
*buf++ = REX_W; |
| 167 |
*buf++ = 0x8b; |
*buf++ = 0x8b; |
| 168 |
*buf++ = 0xc0 | (reg_map[SLJIT_GENERAL_REG1] << 3) | 0x7; |
*buf++ = 0xc0 | (reg_map[SLJIT_SAVED_REG1] << 3) | 0x7; |
| 169 |
} |
} |
| 170 |
if (args > 1) { |
if (args > 1) { |
| 171 |
*buf++ = REX_W | REX_R; |
*buf++ = REX_W | REX_R; |
| 172 |
*buf++ = 0x8b; |
*buf++ = 0x8b; |
| 173 |
*buf++ = 0xc0 | (reg_lmap[SLJIT_GENERAL_REG2] << 3) | 0x6; |
*buf++ = 0xc0 | (reg_lmap[SLJIT_SAVED_REG2] << 3) | 0x6; |
| 174 |
} |
} |
| 175 |
if (args > 2) { |
if (args > 2) { |
| 176 |
*buf++ = REX_W | REX_R; |
*buf++ = REX_W | REX_R; |
| 177 |
*buf++ = 0x8b; |
*buf++ = 0x8b; |
| 178 |
*buf++ = 0xc0 | (reg_lmap[SLJIT_GENERAL_REG3] << 3) | 0x2; |
*buf++ = 0xc0 | (reg_lmap[SLJIT_SAVED_REG3] << 3) | 0x2; |
| 179 |
} |
} |
| 180 |
#else |
#else |
| 181 |
if (args > 0) { |
if (args > 0) { |
| 182 |
*buf++ = REX_W; |
*buf++ = REX_W; |
| 183 |
*buf++ = 0x8b; |
*buf++ = 0x8b; |
| 184 |
*buf++ = 0xc0 | (reg_map[SLJIT_GENERAL_REG1] << 3) | 0x1; |
*buf++ = 0xc0 | (reg_map[SLJIT_SAVED_REG1] << 3) | 0x1; |
| 185 |
} |
} |
| 186 |
if (args > 1) { |
if (args > 1) { |
| 187 |
*buf++ = REX_W; |
*buf++ = REX_W; |
| 188 |
*buf++ = 0x8b; |
*buf++ = 0x8b; |
| 189 |
*buf++ = 0xc0 | (reg_map[SLJIT_GENERAL_REG2] << 3) | 0x2; |
*buf++ = 0xc0 | (reg_map[SLJIT_SAVED_REG2] << 3) | 0x2; |
| 190 |
} |
} |
| 191 |
if (args > 2) { |
if (args > 2) { |
| 192 |
*buf++ = REX_W | REX_B; |
*buf++ = REX_W | REX_B; |
| 193 |
*buf++ = 0x8b; |
*buf++ = 0x8b; |
| 194 |
*buf++ = 0xc0 | (reg_map[SLJIT_GENERAL_REG3] << 3) | 0x0; |
*buf++ = 0xc0 | (reg_map[SLJIT_SAVED_REG3] << 3) | 0x0; |
| 195 |
} |
} |
| 196 |
#endif |
#endif |
| 197 |
} |
} |
| 198 |
|
|
| 199 |
local_size = ((local_size + pushed_size + 16 - 1) & ~(16 - 1)) - pushed_size; |
local_size = ((local_size + FIXED_LOCALS_OFFSET + pushed_size + 16 - 1) & ~(16 - 1)) - pushed_size; |
|
#ifdef _WIN64 |
|
|
local_size += 4 * sizeof(sljit_w); |
|
| 200 |
compiler->local_size = local_size; |
compiler->local_size = local_size; |
| 201 |
|
#ifdef _WIN64 |
| 202 |
if (local_size > 1024) { |
if (local_size > 1024) { |
| 203 |
/* Allocate the stack for the function itself. */ |
/* Allocate stack for the callback, which grows the stack. */ |
| 204 |
buf = (sljit_ub*)ensure_buf(compiler, 1 + 4); |
buf = (sljit_ub*)ensure_buf(compiler, 1 + 4); |
| 205 |
FAIL_IF(!buf); |
FAIL_IF(!buf); |
| 206 |
INC_SIZE(4); |
INC_SIZE(4); |
| 217 |
local_size -= 4 * sizeof(sljit_w); |
local_size -= 4 * sizeof(sljit_w); |
| 218 |
} |
} |
| 219 |
FAIL_IF(emit_load_imm64(compiler, SLJIT_TEMPORARY_REG1, local_size)); |
FAIL_IF(emit_load_imm64(compiler, SLJIT_TEMPORARY_REG1, local_size)); |
| 220 |
FAIL_IF(sljit_emit_ijump(compiler, SLJIT_CALL1, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_touch_stack))); |
FAIL_IF(sljit_emit_ijump(compiler, SLJIT_CALL1, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_grow_stack))); |
| 221 |
} |
} |
|
#else |
|
|
compiler->local_size = local_size; |
|
|
if (local_size > 0) { |
|
| 222 |
#endif |
#endif |
| 223 |
/* In case of Win64, local_size is always > 4 * sizeof(sljit_w) */ |
SLJIT_ASSERT(local_size > 0); |
| 224 |
if (local_size <= 127) { |
if (local_size <= 127) { |
| 225 |
buf = (sljit_ub*)ensure_buf(compiler, 1 + 4); |
buf = (sljit_ub*)ensure_buf(compiler, 1 + 4); |
| 226 |
FAIL_IF(!buf); |
FAIL_IF(!buf); |
| 227 |
INC_SIZE(4); |
INC_SIZE(4); |
| 228 |
*buf++ = REX_W; |
*buf++ = REX_W; |
| 229 |
*buf++ = 0x83; |
*buf++ = 0x83; |
| 230 |
*buf++ = 0xc0 | (5 << 3) | 4; |
*buf++ = 0xc0 | (5 << 3) | 4; |
| 231 |
*buf++ = local_size; |
*buf++ = local_size; |
|
} |
|
|
else { |
|
|
buf = (sljit_ub*)ensure_buf(compiler, 1 + 7); |
|
|
FAIL_IF(!buf); |
|
|
INC_SIZE(7); |
|
|
*buf++ = REX_W; |
|
|
*buf++ = 0x81; |
|
|
*buf++ = 0xc0 | (5 << 3) | 4; |
|
|
*(sljit_hw*)buf = local_size; |
|
|
buf += sizeof(sljit_hw); |
|
|
} |
|
|
#ifndef _WIN64 |
|
| 232 |
} |
} |
| 233 |
#endif |
else { |
| 234 |
|
buf = (sljit_ub*)ensure_buf(compiler, 1 + 7); |
|
#ifdef _WIN64 |
|
|
if (compiler->has_locals) { |
|
|
buf = (sljit_ub*)ensure_buf(compiler, 1 + 5); |
|
| 235 |
FAIL_IF(!buf); |
FAIL_IF(!buf); |
| 236 |
INC_SIZE(5); |
INC_SIZE(7); |
| 237 |
*buf++ = REX_W | REX_R; |
*buf++ = REX_W; |
| 238 |
*buf++ = 0x8d; |
*buf++ = 0x81; |
| 239 |
*buf++ = 0x40 | (reg_lmap[SLJIT_LOCALS_REG] << 3) | 0x4; |
*buf++ = 0xc0 | (5 << 3) | 4; |
| 240 |
*buf++ = 0x24; |
*(sljit_hw*)buf = local_size; |
| 241 |
*buf = 4 * sizeof(sljit_w); |
buf += sizeof(sljit_hw); |
| 242 |
} |
} |
|
#endif |
|
| 243 |
|
|
|
/* Mov arguments to general registers. */ |
|
| 244 |
return SLJIT_SUCCESS; |
return SLJIT_SUCCESS; |
| 245 |
} |
} |
| 246 |
|
|
| 247 |
SLJIT_API_FUNC_ATTRIBUTE void sljit_set_context(struct sljit_compiler *compiler, int args, int temporaries, int generals, int local_size) |
SLJIT_API_FUNC_ATTRIBUTE void sljit_set_context(struct sljit_compiler *compiler, int args, int temporaries, int saveds, int local_size) |
| 248 |
{ |
{ |
| 249 |
int pushed_size; |
int pushed_size; |
| 250 |
|
|
| 251 |
CHECK_ERROR_VOID(); |
CHECK_ERROR_VOID(); |
| 252 |
check_sljit_set_context(compiler, args, temporaries, generals, local_size); |
check_sljit_set_context(compiler, args, temporaries, saveds, local_size); |
| 253 |
|
|
| 254 |
compiler->temporaries = temporaries; |
compiler->temporaries = temporaries; |
| 255 |
compiler->generals = generals; |
compiler->saveds = saveds; |
| 256 |
|
#if (defined SLJIT_DEBUG && SLJIT_DEBUG) |
| 257 |
|
compiler->logical_local_size = local_size; |
| 258 |
|
#endif |
| 259 |
|
|
| 260 |
/* Including the return address saved by the call instruction. */ |
/* Including the return address saved by the call instruction. */ |
| 261 |
pushed_size = (generals + 1) * sizeof(sljit_w); |
pushed_size = (saveds + 1) * sizeof(sljit_w); |
| 262 |
#ifdef _WIN64 |
#ifdef _WIN64 |
|
compiler->has_locals = local_size > 0; |
|
|
if (local_size > 0) |
|
|
pushed_size += sizeof(sljit_w); |
|
| 263 |
if (temporaries >= 5) |
if (temporaries >= 5) |
| 264 |
pushed_size += sizeof(sljit_w); |
pushed_size += sizeof(sljit_w); |
| 265 |
#endif |
#endif |
| 266 |
compiler->local_size = ((local_size + pushed_size + 16 - 1) & ~(16 - 1)) - pushed_size; |
compiler->local_size = ((local_size + FIXED_LOCALS_OFFSET + pushed_size + 16 - 1) & ~(16 - 1)) - pushed_size; |
|
#ifdef _WIN64 |
|
|
compiler->local_size += 4 * sizeof(sljit_w); |
|
|
#endif |
|
| 267 |
} |
} |
| 268 |
|
|
| 269 |
SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int src, sljit_w srcw) |
SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int op, int src, sljit_w srcw) |
| 270 |
{ |
{ |
| 271 |
int size; |
int size; |
| 272 |
sljit_ub *buf; |
sljit_ub *buf; |
| 273 |
|
|
| 274 |
CHECK_ERROR(); |
CHECK_ERROR(); |
| 275 |
check_sljit_emit_return(compiler, src, srcw); |
check_sljit_emit_return(compiler, op, src, srcw); |
| 276 |
|
ADJUST_LOCAL_OFFSET(src, srcw); |
| 277 |
|
|
| 278 |
compiler->flags_saved = 0; |
compiler->flags_saved = 0; |
| 279 |
|
FAIL_IF(emit_mov_before_return(compiler, op, src, srcw)); |
| 280 |
|
|
| 281 |
if (src != SLJIT_UNUSED && src != SLJIT_RETURN_REG) { |
SLJIT_ASSERT(compiler->local_size > 0); |
| 282 |
compiler->mode32 = 0; |
if (compiler->local_size <= 127) { |
| 283 |
FAIL_IF(emit_mov(compiler, SLJIT_RETURN_REG, 0, src, srcw)); |
buf = (sljit_ub*)ensure_buf(compiler, 1 + 4); |
| 284 |
|
FAIL_IF(!buf); |
| 285 |
|
INC_SIZE(4); |
| 286 |
|
*buf++ = REX_W; |
| 287 |
|
*buf++ = 0x83; |
| 288 |
|
*buf++ = 0xc0 | (0 << 3) | 4; |
| 289 |
|
*buf = compiler->local_size; |
| 290 |
} |
} |
| 291 |
|
else { |
| 292 |
if (compiler->local_size > 0) { |
buf = (sljit_ub*)ensure_buf(compiler, 1 + 7); |
| 293 |
if (compiler->local_size <= 127) { |
FAIL_IF(!buf); |
| 294 |
buf = (sljit_ub*)ensure_buf(compiler, 1 + 4); |
INC_SIZE(7); |
| 295 |
FAIL_IF(!buf); |
*buf++ = REX_W; |
| 296 |
INC_SIZE(4); |
*buf++ = 0x81; |
| 297 |
*buf++ = REX_W; |
*buf++ = 0xc0 | (0 << 3) | 4; |
| 298 |
*buf++ = 0x83; |
*(sljit_hw*)buf = compiler->local_size; |
|
*buf++ = 0xc0 | (0 << 3) | 4; |
|
|
*buf = compiler->local_size; |
|
|
} |
|
|
else { |
|
|
buf = (sljit_ub*)ensure_buf(compiler, 1 + 7); |
|
|
FAIL_IF(!buf); |
|
|
INC_SIZE(7); |
|
|
*buf++ = REX_W; |
|
|
*buf++ = 0x81; |
|
|
*buf++ = 0xc0 | (0 << 3) | 4; |
|
|
*(sljit_hw*)buf = compiler->local_size; |
|
|
} |
|
| 299 |
} |
} |
| 300 |
|
|
| 301 |
size = 1 + compiler->generals; |
size = 1 + compiler->saveds; |
| 302 |
#ifndef _WIN64 |
#ifndef _WIN64 |
| 303 |
if (compiler->generals >= 2) |
if (compiler->saveds >= 2) |
| 304 |
size += compiler->generals - 1; |
size += compiler->saveds - 1; |
| 305 |
#else |
#else |
| 306 |
if (compiler->has_locals) |
if (compiler->saveds >= 4) |
| 307 |
size += 2; |
size += compiler->saveds - 3; |
|
if (compiler->generals >= 4) |
|
|
size += compiler->generals - 3; |
|
| 308 |
if (compiler->temporaries >= 5) |
if (compiler->temporaries >= 5) |
| 309 |
size += (5 - 4) * 2; |
size += (5 - 4) * 2; |
| 310 |
#endif |
#endif |
| 314 |
INC_SIZE(size); |
INC_SIZE(size); |
| 315 |
|
|
| 316 |
#ifdef _WIN64 |
#ifdef _WIN64 |
|
if (compiler->has_locals) { |
|
|
*buf++ = REX_B; |
|
|
POP_REG(reg_lmap[SLJIT_LOCALS_REG]); |
|
|
} |
|
| 317 |
if (compiler->temporaries >= 5) { |
if (compiler->temporaries >= 5) { |
| 318 |
*buf++ = REX_B; |
*buf++ = REX_B; |
| 319 |
POP_REG(reg_lmap[SLJIT_TEMPORARY_EREG2]); |
POP_REG(reg_lmap[SLJIT_TEMPORARY_EREG2]); |
| 320 |
} |
} |
| 321 |
#endif |
#endif |
| 322 |
if (compiler->generals >= 1) |
if (compiler->saveds >= 1) |
| 323 |
POP_REG(reg_map[SLJIT_GENERAL_REG1]); |
POP_REG(reg_map[SLJIT_SAVED_REG1]); |
| 324 |
if (compiler->generals >= 2) { |
if (compiler->saveds >= 2) { |
| 325 |
#ifndef _WIN64 |
#ifndef _WIN64 |
| 326 |
*buf++ = REX_B; |
*buf++ = REX_B; |
| 327 |
#endif |
#endif |
| 328 |
POP_REG(reg_lmap[SLJIT_GENERAL_REG2]); |
POP_REG(reg_lmap[SLJIT_SAVED_REG2]); |
| 329 |
} |
} |
| 330 |
if (compiler->generals >= 3) { |
if (compiler->saveds >= 3) { |
| 331 |
#ifndef _WIN64 |
#ifndef _WIN64 |
| 332 |
*buf++ = REX_B; |
*buf++ = REX_B; |
| 333 |
#endif |
#endif |
| 334 |
POP_REG(reg_lmap[SLJIT_GENERAL_REG3]); |
POP_REG(reg_lmap[SLJIT_SAVED_REG3]); |
| 335 |
} |
} |
| 336 |
if (compiler->generals >= 4) { |
if (compiler->saveds >= 4) { |
| 337 |
*buf++ = REX_B; |
*buf++ = REX_B; |
| 338 |
POP_REG(reg_lmap[SLJIT_GENERAL_EREG1]); |
POP_REG(reg_lmap[SLJIT_SAVED_EREG1]); |
| 339 |
} |
} |
| 340 |
if (compiler->generals >= 5) { |
if (compiler->saveds >= 5) { |
| 341 |
*buf++ = REX_B; |
*buf++ = REX_B; |
| 342 |
POP_REG(reg_lmap[SLJIT_GENERAL_EREG2]); |
POP_REG(reg_lmap[SLJIT_SAVED_EREG2]); |
| 343 |
} |
} |
| 344 |
|
|
| 345 |
RET(); |
RET(); |
| 439 |
} |
} |
| 440 |
} |
} |
| 441 |
|
|
| 442 |
#ifndef _WIN64 |
if ((b & 0xf) == SLJIT_LOCALS_REG && !(b & 0xf0)) |
|
if ((b & 0xf) == SLJIT_LOCALS_REG && (b & 0xf0) == 0) |
|
| 443 |
b |= SLJIT_LOCALS_REG << 4; |
b |= SLJIT_LOCALS_REG << 4; |
|
#endif |
|
| 444 |
|
|
| 445 |
if ((b & 0xf0) != SLJIT_UNUSED) { |
if ((b & 0xf0) != SLJIT_UNUSED) { |
| 446 |
inst_size += 1; /* SIB byte. */ |
inst_size += 1; /* SIB byte. */ |
| 542 |
*buf_ptr++ |= 0xc0 + reg_lmap[b]; |
*buf_ptr++ |= 0xc0 + reg_lmap[b]; |
| 543 |
#endif |
#endif |
| 544 |
else if ((b & 0x0f) != SLJIT_UNUSED) { |
else if ((b & 0x0f) != SLJIT_UNUSED) { |
|
#ifdef _WIN64 |
|
|
SLJIT_ASSERT((b & 0xf0) != (SLJIT_LOCALS_REG << 4)); |
|
|
#endif |
|
| 545 |
if ((b & 0xf0) == SLJIT_UNUSED || (b & 0xf0) == (SLJIT_LOCALS_REG << 4)) { |
if ((b & 0xf0) == SLJIT_UNUSED || (b & 0xf0) == (SLJIT_LOCALS_REG << 4)) { |
| 546 |
if (immb != 0) { |
if (immb != 0) { |
| 547 |
if (immb <= 127 && immb >= -128) |
if (immb <= 127 && immb >= -128) |
| 630 |
return SLJIT_SUCCESS; |
return SLJIT_SUCCESS; |
| 631 |
} |
} |
| 632 |
|
|
| 633 |
SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_fast_enter(struct sljit_compiler *compiler, int dst, sljit_w dstw, int args, int temporaries, int generals, int local_size) |
SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_fast_enter(struct sljit_compiler *compiler, int dst, sljit_w dstw) |
| 634 |
{ |
{ |
| 635 |
sljit_ub *buf; |
sljit_ub *buf; |
| 636 |
|
|
| 637 |
CHECK_ERROR(); |
CHECK_ERROR(); |
| 638 |
check_sljit_emit_fast_enter(compiler, dst, dstw, args, temporaries, generals, local_size); |
check_sljit_emit_fast_enter(compiler, dst, dstw); |
| 639 |
|
ADJUST_LOCAL_OFFSET(dst, dstw); |
|
compiler->temporaries = temporaries; |
|
|
compiler->generals = generals; |
|
|
compiler->local_size = (local_size + sizeof(sljit_uw) - 1) & ~(sizeof(sljit_uw) - 1); |
|
|
#ifdef _WIN64 |
|
|
compiler->local_size += 4 * sizeof(sljit_w); |
|
|
#endif |
|
| 640 |
|
|
| 641 |
/* For UNUSED dst. Uncommon, but possible. */ |
/* For UNUSED dst. Uncommon, but possible. */ |
| 642 |
if (dst == SLJIT_UNUSED) |
if (dst == SLJIT_UNUSED) |
| 660 |
} |
} |
| 661 |
} |
} |
| 662 |
else if (dst & SLJIT_MEM) { |
else if (dst & SLJIT_MEM) { |
|
#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) |
|
| 663 |
/* REX_W is not necessary (src is not immediate). */ |
/* REX_W is not necessary (src is not immediate). */ |
| 664 |
compiler->mode32 = 1; |
compiler->mode32 = 1; |
|
#endif |
|
| 665 |
buf = emit_x86_instruction(compiler, 1, 0, 0, dst, dstw); |
buf = emit_x86_instruction(compiler, 1, 0, 0, dst, dstw); |
| 666 |
FAIL_IF(!buf); |
FAIL_IF(!buf); |
| 667 |
*buf++ = 0x8f; |
*buf++ = 0x8f; |
| 675 |
|
|
| 676 |
CHECK_ERROR(); |
CHECK_ERROR(); |
| 677 |
check_sljit_emit_fast_return(compiler, src, srcw); |
check_sljit_emit_fast_return(compiler, src, srcw); |
| 678 |
|
ADJUST_LOCAL_OFFSET(src, srcw); |
|
CHECK_EXTRA_REGS(src, srcw, (void)0); |
|
| 679 |
|
|
| 680 |
if ((src & SLJIT_IMM) && NOT_HALFWORD(srcw)) { |
if ((src & SLJIT_IMM) && NOT_HALFWORD(srcw)) { |
| 681 |
FAIL_IF(emit_load_imm64(compiler, TMP_REGISTER, srcw)); |
FAIL_IF(emit_load_imm64(compiler, TMP_REGISTER, srcw)); |
| 700 |
} |
} |
| 701 |
} |
} |
| 702 |
else if (src & SLJIT_MEM) { |
else if (src & SLJIT_MEM) { |
|
#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) |
|
| 703 |
/* REX_W is not necessary (src is not immediate). */ |
/* REX_W is not necessary (src is not immediate). */ |
| 704 |
compiler->mode32 = 1; |
compiler->mode32 = 1; |
|
#endif |
|
| 705 |
buf = emit_x86_instruction(compiler, 1, 0, 0, src, srcw); |
buf = emit_x86_instruction(compiler, 1, 0, 0, src, srcw); |
| 706 |
FAIL_IF(!buf); |
FAIL_IF(!buf); |
| 707 |
*buf++ = 0xff; |
*buf++ = 0xff; |
| 745 |
return SLJIT_SUCCESS; /* Empty instruction. */ |
return SLJIT_SUCCESS; /* Empty instruction. */ |
| 746 |
|
|
| 747 |
if (src & SLJIT_IMM) { |
if (src & SLJIT_IMM) { |
| 748 |
if (dst >= SLJIT_TEMPORARY_REG1 && dst <= SLJIT_NO_REGISTERS) |
if (dst >= SLJIT_TEMPORARY_REG1 && dst <= SLJIT_NO_REGISTERS) { |
| 749 |
|
if (sign || ((sljit_uw)srcw <= 0x7fffffff)) { |
| 750 |
|
code = emit_x86_instruction(compiler, 1, SLJIT_IMM, (sljit_w)(sljit_i)srcw, dst, dstw); |
| 751 |
|
FAIL_IF(!code); |
| 752 |
|
*code = 0xc7; |
| 753 |
|
return SLJIT_SUCCESS; |
| 754 |
|
} |
| 755 |
return emit_load_imm64(compiler, dst, srcw); |
return emit_load_imm64(compiler, dst, srcw); |
| 756 |
|
} |
| 757 |
compiler->mode32 = 1; |
compiler->mode32 = 1; |
| 758 |
code = emit_x86_instruction(compiler, 1, SLJIT_IMM, (sljit_w)(int)srcw, dst, dstw); |
code = emit_x86_instruction(compiler, 1, SLJIT_IMM, (sljit_w)(sljit_i)srcw, dst, dstw); |
| 759 |
FAIL_IF(!code); |
FAIL_IF(!code); |
| 760 |
*code = 0xc7; |
*code = 0xc7; |
| 761 |
compiler->mode32 = 0; |
compiler->mode32 = 0; |
| 762 |
return SLJIT_SUCCESS; |
return SLJIT_SUCCESS; |
| 763 |
} |
} |
| 764 |
|
|
| 765 |
dst_r = (dst >= SLJIT_TEMPORARY_REG1 && dst <= SLJIT_GENERAL_REG3) ? dst : TMP_REGISTER; |
dst_r = (dst >= SLJIT_TEMPORARY_REG1 && dst <= SLJIT_SAVED_REG3) ? dst : TMP_REGISTER; |
| 766 |
|
|
| 767 |
if ((dst & SLJIT_MEM) && (src >= SLJIT_TEMPORARY_REG1 && src <= SLJIT_GENERAL_REG3)) |
if ((dst & SLJIT_MEM) && (src >= SLJIT_TEMPORARY_REG1 && src <= SLJIT_SAVED_REG3)) |
| 768 |
dst_r = src; |
dst_r = src; |
| 769 |
else { |
else { |
| 770 |
if (sign) { |
if (sign) { |
| 771 |
code = emit_x86_instruction(compiler, 1, dst_r, 0, src, srcw); |
code = emit_x86_instruction(compiler, 1, dst_r, 0, src, srcw); |
| 772 |
FAIL_IF(!code); |
FAIL_IF(!code); |
| 773 |
*code++ = 0x63; |
*code++ = 0x63; |
|
} else if (dst_r == src) { |
|
|
compiler->mode32 = 0; |
|
|
code = emit_x86_instruction(compiler, 1 | EX86_SHIFT_INS, SLJIT_IMM, 32, dst, 0); |
|
|
FAIL_IF(!code); |
|
|
*code |= 0x4 << 3; |
|
|
code = emit_x86_instruction(compiler, 1 | EX86_SHIFT_INS, SLJIT_IMM, 32, dst, 0); |
|
|
FAIL_IF(!code); |
|
|
*code |= 0x7 << 3; |
|
| 774 |
} else { |
} else { |
|
/* xor reg, reg. */ |
|
|
code = emit_x86_instruction(compiler, 1, dst_r, 0, dst_r, 0); |
|
|
FAIL_IF(!code); |
|
|
*code++ = 0x33; |
|
| 775 |
compiler->mode32 = 1; |
compiler->mode32 = 1; |
| 776 |
code = emit_x86_instruction(compiler, 1, dst_r, 0, src, srcw); |
FAIL_IF(emit_mov(compiler, dst_r, 0, src, srcw)); |
|
FAIL_IF(!code); |
|
|
*code++ = 0x8b; |
|
| 777 |
compiler->mode32 = 0; |
compiler->mode32 = 0; |
| 778 |
} |
} |
| 779 |
} |
} |