|
Line 0
a/Source/JavaScriptCore/wasm/WasmJITCompiler.cpp_sec1
|
|
|
1 |
/* |
| 2 |
* Copyright (C) 2015 Apple Inc. All rights reserved. |
| 3 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without |
| 5 |
* modification, are permitted provided that the following conditions |
| 6 |
* are met: |
| 7 |
* 1. Redistributions of source code must retain the above copyright |
| 8 |
* notice, this list of conditions and the following disclaimer. |
| 9 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 10 |
* notice, this list of conditions and the following disclaimer in the |
| 11 |
* documentation and/or other materials provided with the distribution. |
| 12 |
* |
| 13 |
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 |
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 |
*/ |
| 25 |
|
| 26 |
/* |
| 27 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 28 |
you may not use this file except in compliance with the License. |
| 29 |
You may obtain a copy of the License at |
| 30 |
|
| 31 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 32 |
|
| 33 |
Unless required by applicable law or agreed to in writing, software |
| 34 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 35 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 36 |
See the License for the specific language governing permissions and |
| 37 |
limitations under the License. |
| 38 |
*/ |
| 39 |
|
| 40 |
#include "config.h" |
| 41 |
#include "WasmJITCompiler.h" |
| 42 |
|
| 43 |
#include "JITCode.h" |
| 44 |
#include "JSCJSValueInlines.h" |
| 45 |
#include "LinkBuffer.h" |
| 46 |
#include "MaxFrameExtentForSlowPathCall.h" |
| 47 |
#include "Register.h" |
| 48 |
|
| 49 |
namespace JSC { |
| 50 |
|
| 51 |
namespace Wasm { |
| 52 |
|
| 53 |
class JumpScope { |
| 54 |
public: |
| 55 |
JumpScope(MacroAssembler* macroAssembler) |
| 56 |
: m_macroAssembler(macroAssembler) |
| 57 |
, m_linked(false) |
| 58 |
{ |
| 59 |
} |
| 60 |
|
| 61 |
JumpScope(MacroAssembler* macroAssembler, const MacroAssembler::Label& label) |
| 62 |
: m_macroAssembler(macroAssembler) |
| 63 |
, m_linked(true) |
| 64 |
, m_label(label) |
| 65 |
{ |
| 66 |
} |
| 67 |
|
| 68 |
void jump() |
| 69 |
{ |
| 70 |
if (m_linked) |
| 71 |
m_macroAssembler->jump(m_label); |
| 72 |
else |
| 73 |
m_jumpList.append(m_macroAssembler->jump()); |
| 74 |
} |
| 75 |
|
| 76 |
void link() |
| 77 |
{ |
| 78 |
ASSERT(!m_linked); |
| 79 |
m_jumpList.link(m_macroAssembler); |
| 80 |
} |
| 81 |
|
| 82 |
private: |
| 83 |
MacroAssembler* m_macroAssembler; |
| 84 |
bool m_linked; |
| 85 |
MacroAssembler::Label m_label; |
| 86 |
MacroAssembler::JumpList m_jumpList; |
| 87 |
}; |
| 88 |
|
| 89 |
RefPtr<JITCode> JITCompiler::compileFunction(VM& vm, size_t functionIndex) |
| 90 |
{ |
| 91 |
emitFunctionPrologue(); |
| 92 |
// FIXME: need to do this! |
| 93 |
// emitPutImmediateToCallFrameHeader(m_codeBlock, JSStack::CodeBlock); |
| 94 |
|
| 95 |
const Signature& signature = m_module->m_signatures[m_module->m_funcSignatures[functionIndex]]; |
| 96 |
m_currentReturnType = signature.returnType; |
| 97 |
parseArguments(signature); |
| 98 |
|
| 99 |
// FIXME: Calculate the actual height. (Be careful about calls.) |
| 100 |
m_stackHeight = WTF::roundUpToMultipleOf(stackAlignmentRegisters(), signature.arguments.size() + 8) * sizeof(Register); |
| 101 |
allocateSpaceOnStack(); |
| 102 |
|
| 103 |
parseVars(); |
| 104 |
parseStmtList(); |
| 105 |
|
| 106 |
LinkBuffer patchBuffer(vm, *this, 0, JITCompilationMustSucceed); |
| 107 |
|
| 108 |
MacroAssemblerCodePtr withArityCheck; |
| 109 |
CodeRef result = FINALIZE_CODE(patchBuffer, ("Baseline JIT code for WebAssembly")); |
| 110 |
return adoptRef(new DirectJITCode(result, withArityCheck, JITCode::BaselineJIT)); |
| 111 |
} |
| 112 |
|
| 113 |
void JITCompiler::allocateSpaceOnStack() |
| 114 |
{ |
| 115 |
addPtr(TrustedImm32(-m_stackHeight), stackPointerRegister); |
| 116 |
} |
| 117 |
|
| 118 |
void JITCompiler::deallocateSpaceOnStack() |
| 119 |
{ |
| 120 |
addPtr(TrustedImm32(m_stackHeight), stackPointerRegister); |
| 121 |
} |
| 122 |
|
| 123 |
void JITCompiler::parseArguments(const Signature& signature) |
| 124 |
{ |
| 125 |
size_t argumentCount = signature.arguments.size(); |
| 126 |
for (uint32_t argIndex = 0; argIndex < argumentCount; ++argIndex) { |
| 127 |
Type type = signature.arguments[argIndex]; |
| 128 |
m_currentLocalTypes.append(type); |
| 129 |
switch (type) { |
| 130 |
case Type::I32: |
| 131 |
load32(Address(GPRInfo::callFrameRegister, (argIndex + 1 + CallFrame::thisArgumentOffset()) * sizeof(Register)), GPRInfo::regT0); |
| 132 |
store32(GPRInfo::regT0, stackAddress(argIndex)); |
| 133 |
break; |
| 134 |
case Type::F32: |
| 135 |
RELEASE_ASSERT_NOT_REACHED(); |
| 136 |
case Type::F64: |
| 137 |
load64(Address(GPRInfo::callFrameRegister, (argIndex + 1 + CallFrame::thisArgumentOffset()) * sizeof(Register)), GPRInfo::regT0); |
| 138 |
unboxDoubleWithoutAssertions(GPRInfo::regT0, FPRInfo::fpRegT0); |
| 139 |
storeDouble(FPRInfo::fpRegT0, stackAddress(argIndex)); |
| 140 |
break; |
| 141 |
default: |
| 142 |
RELEASE_ASSERT_NOT_REACHED(); |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
void JITCompiler::parseVars() |
| 148 |
{ |
| 149 |
uint32_t numberOfI32Vars = 0; |
| 150 |
uint32_t numberOfF32Vars = 0; |
| 151 |
uint32_t numberOfF64Vars = 0; |
| 152 |
|
| 153 |
VarTypes varTypes; |
| 154 |
VarTypesWithImm varTypesWithImm; |
| 155 |
uint8_t imm; |
| 156 |
if (m_module->m_reader.code(&varTypes, &varTypesWithImm, &imm)) { |
| 157 |
if (varTypes & VarTypes::I32) |
| 158 |
numberOfI32Vars = m_module->m_reader.immU32(); |
| 159 |
if (varTypes & VarTypes::F32) |
| 160 |
numberOfF32Vars = m_module->m_reader.immU32(); |
| 161 |
if (varTypes & VarTypes::F64) |
| 162 |
numberOfF64Vars = m_module->m_reader.immU32(); |
| 163 |
} else |
| 164 |
numberOfI32Vars = imm; |
| 165 |
|
| 166 |
uint32_t numberOfVars = numberOfI32Vars + numberOfF32Vars + numberOfF64Vars; |
| 167 |
if (numberOfVars > 0) { |
| 168 |
uint32_t localIndex = m_currentLocalTypes.size(); |
| 169 |
for (uint32_t i = 0; i < numberOfI32Vars; ++i) { |
| 170 |
m_currentLocalTypes.append(Type::I32); |
| 171 |
store32(TrustedImm32(0), stackAddress(localIndex++)); |
| 172 |
} |
| 173 |
for (uint32_t i = 0; i < numberOfF32Vars; ++i) { |
| 174 |
m_currentLocalTypes.append(Type::F32); |
| 175 |
store32(TrustedImm32(0), stackAddress(localIndex++)); |
| 176 |
} |
| 177 |
for (uint32_t i = 0; i < numberOfF64Vars; ++i) { |
| 178 |
m_currentLocalTypes.append(Type::F64); |
| 179 |
store64(TrustedImm64(0), stackAddress(localIndex++)); |
| 180 |
} |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
void JITCompiler::parseStmt() |
| 185 |
{ |
| 186 |
Stmt stmt; |
| 187 |
StmtWithImm stmtWithImm; |
| 188 |
uint8_t imm; |
| 189 |
if (m_module->m_reader.code(&stmt, &stmtWithImm, &imm)) { |
| 190 |
switch (stmt) { |
| 191 |
case Stmt::SetLoc: |
| 192 |
parseSetLocal(0); |
| 193 |
break; |
| 194 |
case Stmt::SetGlo: |
| 195 |
case Stmt::I32Store8: |
| 196 |
case Stmt::I32StoreOff8: |
| 197 |
case Stmt::I32Store16: |
| 198 |
case Stmt::I32StoreOff16: |
| 199 |
case Stmt::I32Store32: |
| 200 |
case Stmt::I32StoreOff32: |
| 201 |
case Stmt::F32Store: |
| 202 |
case Stmt::F32StoreOff: |
| 203 |
case Stmt::F64Store: |
| 204 |
case Stmt::F64StoreOff: |
| 205 |
case Stmt::CallInt: |
| 206 |
case Stmt::CallInd: |
| 207 |
RELEASE_ASSERT_NOT_REACHED(); |
| 208 |
case Stmt::CallImp: |
| 209 |
parseCallImport(ReturnType::Void, 0); // FIXME: Is it really Void? |
| 210 |
break; |
| 211 |
case Stmt::Ret: |
| 212 |
parseReturnStmt(); |
| 213 |
return; |
| 214 |
case Stmt::Block: |
| 215 |
parseBlockStmt(); |
| 216 |
return; |
| 217 |
case Stmt::IfThen: |
| 218 |
parseIfStmt(); |
| 219 |
return; |
| 220 |
case Stmt::IfElse: |
| 221 |
parseIfElseStmt(); |
| 222 |
return; |
| 223 |
case Stmt::While: |
| 224 |
parseWhileStmt(); |
| 225 |
return; |
| 226 |
case Stmt::Do: |
| 227 |
parseDoStmt(); |
| 228 |
return; |
| 229 |
case Stmt::Label: |
| 230 |
parseLabelStmt(); |
| 231 |
return; |
| 232 |
case Stmt::Break: |
| 233 |
parseBreakStmt(); |
| 234 |
return; |
| 235 |
case Stmt::BreakLabel: |
| 236 |
parseBreakLabelStmt(); |
| 237 |
return; |
| 238 |
case Stmt::Continue: |
| 239 |
parseContinueStmt(); |
| 240 |
break; |
| 241 |
case Stmt::ContinueLabel: |
| 242 |
parseContinueLabelStmt(); |
| 243 |
return; |
| 244 |
case Stmt::Switch: |
| 245 |
parseSwitchStmt(); |
| 246 |
break; |
| 247 |
default: |
| 248 |
RELEASE_ASSERT_NOT_REACHED(); |
| 249 |
} |
| 250 |
} else { |
| 251 |
switch (stmtWithImm) { |
| 252 |
case StmtWithImm::SetLoc: |
| 253 |
parseSetLocal(imm, 0); |
| 254 |
break; |
| 255 |
case StmtWithImm::SetGlo: |
| 256 |
default: |
| 257 |
RELEASE_ASSERT_NOT_REACHED(); |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
void JITCompiler::parseGetLocal(int dst) |
| 263 |
{ |
| 264 |
uint32_t imm = m_module->m_reader.immU32(); |
| 265 |
switch (m_currentLocalTypes[imm]) { |
| 266 |
case Type::I32: |
| 267 |
case Type::F32: |
| 268 |
load32(stackAddress(imm), GPRInfo::regT0); |
| 269 |
store32(GPRInfo::regT0, temporaryAddress(dst)); |
| 270 |
break; |
| 271 |
case Type::F64: |
| 272 |
load64(stackAddress(imm), GPRInfo::regT0); |
| 273 |
store64(GPRInfo::regT0, temporaryAddress(dst)); |
| 274 |
break; |
| 275 |
default: |
| 276 |
RELEASE_ASSERT_NOT_REACHED(); |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
void JITCompiler::parseSetLocal(uint32_t imm, int dst) |
| 281 |
{ |
| 282 |
Type type = m_currentLocalTypes[imm]; |
| 283 |
parseExpr(ReturnType(type), dst); |
| 284 |
switch (type) { |
| 285 |
case Type::I32: |
| 286 |
case Type::F32: |
| 287 |
load32(temporaryAddress(dst), GPRInfo::regT0); |
| 288 |
store32(GPRInfo::regT0, stackAddress(imm)); |
| 289 |
break; |
| 290 |
case Type::F64: |
| 291 |
load64(temporaryAddress(dst), GPRInfo::regT0); |
| 292 |
store64(GPRInfo::regT0, stackAddress(imm)); |
| 293 |
break; |
| 294 |
default: |
| 295 |
RELEASE_ASSERT_NOT_REACHED(); |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
void JITCompiler::parseSetLocal(int dst) |
| 300 |
{ |
| 301 |
parseSetLocal(m_module->m_reader.immU32(), dst); |
| 302 |
} |
| 303 |
|
| 304 |
void JITCompiler::parseReturnStmt() |
| 305 |
{ |
| 306 |
switch (m_currentReturnType) { |
| 307 |
case ReturnType::I32: |
| 308 |
parseExpr(ReturnType::I32, 0); |
| 309 |
load32(temporaryAddress(0), GPRInfo::returnValueGPR); |
| 310 |
or64(GPRInfo::tagTypeNumberRegister, GPRInfo::returnValueGPR); |
| 311 |
break; |
| 312 |
case ReturnType::F32: |
| 313 |
parseExpr(ReturnType::F32, 0); |
| 314 |
loadDouble(temporaryAddress(0), FPRInfo::fpRegT0); // FIXME: This loads 64 bits! |
| 315 |
convertFloatToDouble(FPRInfo::fpRegT0, FPRInfo::fpRegT0); |
| 316 |
boxDouble(FPRInfo::fpRegT0, GPRInfo::returnValueGPR); |
| 317 |
break; |
| 318 |
case ReturnType::F64: |
| 319 |
parseExpr(ReturnType::F64, 0); |
| 320 |
loadDouble(temporaryAddress(0), FPRInfo::fpRegT0); |
| 321 |
boxDouble(FPRInfo::fpRegT0, GPRInfo::returnValueGPR); |
| 322 |
break; |
| 323 |
case ReturnType::Void: |
| 324 |
break; |
| 325 |
} |
| 326 |
|
| 327 |
deallocateSpaceOnStack(); |
| 328 |
emitFunctionEpilogue(); |
| 329 |
ret(); |
| 330 |
} |
| 331 |
|
| 332 |
void JITCompiler::parseStmtList() |
| 333 |
{ |
| 334 |
uint32_t numberOfStmts = m_module->m_reader.immU32(); |
| 335 |
for (uint32_t i = 0; i < numberOfStmts; ++i) |
| 336 |
parseStmt(); |
| 337 |
} |
| 338 |
|
| 339 |
void JITCompiler::parseBlockStmt() |
| 340 |
{ |
| 341 |
parseStmtList(); |
| 342 |
} |
| 343 |
|
| 344 |
void JITCompiler::parseIfStmt() |
| 345 |
{ |
| 346 |
parseExpr(ReturnType::I32, 0); |
| 347 |
load32(temporaryAddress(0), GPRInfo::regT0); |
| 348 |
Jump end = branchTest32(Zero, GPRInfo::regT0); |
| 349 |
parseStmt(); |
| 350 |
end.link(this); |
| 351 |
} |
| 352 |
|
| 353 |
void JITCompiler::parseIfElseStmt() |
| 354 |
{ |
| 355 |
parseExpr(ReturnType::I32, 0); |
| 356 |
load32(temporaryAddress(0), GPRInfo::regT0); |
| 357 |
Jump els = branchTest32(Zero, GPRInfo::regT0); |
| 358 |
parseStmt(); |
| 359 |
Jump end = jump(); |
| 360 |
els.link(this); |
| 361 |
parseStmt(); |
| 362 |
end.link(this); |
| 363 |
} |
| 364 |
|
| 365 |
void JITCompiler::parseWhileStmt() |
| 366 |
{ |
| 367 |
JumpScope continueJumpScope(this, label()); |
| 368 |
pushContinueJumpScope(&continueJumpScope); |
| 369 |
|
| 370 |
JumpList breakJumpList; |
| 371 |
pushBreakJumpList(&breakJumpList); |
| 372 |
|
| 373 |
parseExpr(ReturnType::I32, 0); |
| 374 |
load32(temporaryAddress(0), GPRInfo::regT0); |
| 375 |
Jump end = branchTest32(Zero, GPRInfo::regT0); |
| 376 |
parseStmt(); |
| 377 |
continueJumpScope.jump(); |
| 378 |
end.link(this); |
| 379 |
breakJumpList.link(this); |
| 380 |
|
| 381 |
popBreakJumpList(); |
| 382 |
|
| 383 |
popContinueJumpScope(); |
| 384 |
} |
| 385 |
|
| 386 |
void JITCompiler::parseDoStmt() |
| 387 |
{ |
| 388 |
JumpScope continueJumpScope(this); |
| 389 |
pushContinueJumpScope(&continueJumpScope); |
| 390 |
|
| 391 |
JumpList breakJumpList; |
| 392 |
pushBreakJumpList(&breakJumpList); |
| 393 |
|
| 394 |
Label start = label(); |
| 395 |
parseStmt(); |
| 396 |
continueJumpScope.link(); |
| 397 |
parseExpr(ReturnType::I32, 0); |
| 398 |
load32(temporaryAddress(0), GPRInfo::regT0); |
| 399 |
Jump jumpToStart = branchTest32(NonZero, GPRInfo::regT0); |
| 400 |
jumpToStart.linkTo(start, this); |
| 401 |
breakJumpList.link(this); |
| 402 |
|
| 403 |
popBreakJumpList(); |
| 404 |
|
| 405 |
popContinueJumpScope(); |
| 406 |
} |
| 407 |
|
| 408 |
void JITCompiler::parseLabelStmt() |
| 409 |
{ |
| 410 |
Label continueLabel = label(); |
| 411 |
JumpList breakJumpList; |
| 412 |
pushContinueLabelLabel(&continueLabel); |
| 413 |
pushBreakLabelJumpList(&breakJumpList); |
| 414 |
parseStmt(); |
| 415 |
breakJumpList.link(this); |
| 416 |
popBreakLabelJumpList(); |
| 417 |
popContinueLabelLabel(); |
| 418 |
} |
| 419 |
|
| 420 |
void JITCompiler::parseBreakStmt() |
| 421 |
{ |
| 422 |
topBreakJumpList()->append(jump()); |
| 423 |
} |
| 424 |
|
| 425 |
void JITCompiler::parseBreakLabelStmt() |
| 426 |
{ |
| 427 |
uint32_t index = m_module->m_reader.immU32(); |
| 428 |
breakLabelJumpList(index)->append(jump()); |
| 429 |
} |
| 430 |
|
| 431 |
void JITCompiler::parseContinueStmt() |
| 432 |
{ |
| 433 |
topContinueJumpScope()->jump(); |
| 434 |
} |
| 435 |
|
| 436 |
void JITCompiler::parseContinueLabelStmt() |
| 437 |
{ |
| 438 |
uint32_t index = m_module->m_reader.immU32(); |
| 439 |
jump(*continueLabelLabel(index)); |
| 440 |
} |
| 441 |
|
| 442 |
void JITCompiler::parseSwitchStmt() |
| 443 |
{ |
| 444 |
JumpList breakJumpList; |
| 445 |
pushBreakJumpList(&breakJumpList); |
| 446 |
|
| 447 |
uint32_t numberOfCases = m_module->m_reader.immU32(); |
| 448 |
parseExpr(ReturnType::I32, 0); |
| 449 |
load32(temporaryAddress(0), GPRInfo::regT0); |
| 450 |
|
| 451 |
Jump table = jump(); |
| 452 |
|
| 453 |
Vector<Label> labels; |
| 454 |
Vector<int32_t> imms; |
| 455 |
Label defaultLabel; |
| 456 |
bool hasDefault = false; |
| 457 |
|
| 458 |
for (uint32_t i = 0; i < numberOfCases; ++i) { |
| 459 |
switch (m_module->m_reader.switchCase()) { |
| 460 |
case SwitchCase::Case0: |
| 461 |
labels.append(label()); |
| 462 |
imms.append(m_module->m_reader.immS32()); |
| 463 |
break; |
| 464 |
case SwitchCase::Case1: |
| 465 |
labels.append(label()); |
| 466 |
imms.append(m_module->m_reader.immS32()); |
| 467 |
parseStmt(); |
| 468 |
break; |
| 469 |
case SwitchCase::CaseN: |
| 470 |
labels.append(label()); |
| 471 |
imms.append(m_module->m_reader.immS32()); |
| 472 |
parseStmtList(); |
| 473 |
break; |
| 474 |
case SwitchCase::Default0: |
| 475 |
defaultLabel = label(); |
| 476 |
hasDefault = true; |
| 477 |
break; |
| 478 |
case SwitchCase::Default1: |
| 479 |
defaultLabel = label(); |
| 480 |
hasDefault = true; |
| 481 |
parseStmt(); |
| 482 |
break; |
| 483 |
case SwitchCase::DefaultN: |
| 484 |
defaultLabel = label(); |
| 485 |
hasDefault = true; |
| 486 |
parseStmtList(); |
| 487 |
break; |
| 488 |
default: |
| 489 |
RELEASE_ASSERT_NOT_REACHED(); |
| 490 |
} |
| 491 |
} |
| 492 |
|
| 493 |
Jump end = jump(); |
| 494 |
table.link(this); |
| 495 |
|
| 496 |
for (size_t i = 0; i < labels.size(); ++i) { |
| 497 |
Jump jmp = branch32(Equal, GPRInfo::regT0, TrustedImm32(imms[i])); |
| 498 |
jmp.linkTo(labels[i], this); |
| 499 |
} |
| 500 |
if (hasDefault) |
| 501 |
jump(defaultLabel); |
| 502 |
|
| 503 |
end.link(this); |
| 504 |
|
| 505 |
breakJumpList.link(this); |
| 506 |
popBreakJumpList(); |
| 507 |
} |
| 508 |
|
| 509 |
void JITCompiler::parseExpr(ReturnType returnType, int dst) |
| 510 |
{ |
| 511 |
switch (returnType) { |
| 512 |
case ReturnType::I32: |
| 513 |
parseExprI32(dst); |
| 514 |
break; |
| 515 |
case ReturnType::F64: |
| 516 |
parseExprF64(dst); |
| 517 |
break; |
| 518 |
default: |
| 519 |
RELEASE_ASSERT_NOT_REACHED(); |
| 520 |
} |
| 521 |
} |
| 522 |
|
| 523 |
void JITCompiler::parseExprI32(int dst) |
| 524 |
{ |
| 525 |
I32 i32; |
| 526 |
I32WithImm i32WithImm; |
| 527 |
uint8_t imm; |
| 528 |
|
| 529 |
if (m_module->m_reader.code(&i32, &i32WithImm, &imm)) { |
| 530 |
switch (i32) { |
| 531 |
case I32::LitImm: |
| 532 |
store32(TrustedImm32(m_module->m_reader.immU32()), temporaryAddress(dst)); |
| 533 |
break; |
| 534 |
case I32::LitPool: |
| 535 |
case I32::GetLoc: |
| 536 |
parseGetLocal(dst); |
| 537 |
break; |
| 538 |
case I32::GetGlo: |
| 539 |
RELEASE_ASSERT_NOT_REACHED(); |
| 540 |
case I32::SetLoc: |
| 541 |
parseSetLocal(dst); |
| 542 |
break; |
| 543 |
case I32::SetGlo: |
| 544 |
case I32::SLoad8: |
| 545 |
case I32::SLoadOff8: |
| 546 |
case I32::ULoad8: |
| 547 |
case I32::ULoadOff8: |
| 548 |
case I32::SLoad16: |
| 549 |
case I32::SLoadOff16: |
| 550 |
case I32::ULoad16: |
| 551 |
case I32::ULoadOff16: |
| 552 |
case I32::Load32: |
| 553 |
case I32::LoadOff32: |
| 554 |
case I32::Store8: |
| 555 |
case I32::StoreOff8: |
| 556 |
case I32::Store16: |
| 557 |
case I32::StoreOff16: |
| 558 |
case I32::Store32: |
| 559 |
case I32::StoreOff32: |
| 560 |
RELEASE_ASSERT_NOT_REACHED(); |
| 561 |
case I32::CallInt: |
| 562 |
parseCallInternal(ReturnType::I32, dst); |
| 563 |
break; |
| 564 |
case I32::CallInd: |
| 565 |
RELEASE_ASSERT_NOT_REACHED(); |
| 566 |
case I32::CallImp: |
| 567 |
parseCallImport(ReturnType::I32, dst); |
| 568 |
break; |
| 569 |
case I32::Cond: |
| 570 |
parseCond(ReturnType::I32, dst); |
| 571 |
break; |
| 572 |
case I32::Comma: |
| 573 |
parseComma(ReturnType::I32, dst); |
| 574 |
break; |
| 575 |
case I32::FromF32: |
| 576 |
RELEASE_ASSERT_NOT_REACHED(); |
| 577 |
case I32::FromF64: |
| 578 |
parseExprF64(dst); |
| 579 |
loadDouble(temporaryAddress(dst), FPRInfo::fpRegT0); |
| 580 |
truncateDoubleToInt32(FPRInfo::fpRegT0, GPRInfo::regT0); |
| 581 |
store32(GPRInfo::regT0, temporaryAddress(dst)); |
| 582 |
break; |
| 583 |
case I32::Neg: |
| 584 |
parseUnaryOp(static_cast<uint8_t>(i32), ReturnType::I32, dst); |
| 585 |
break; |
| 586 |
case I32::Add: |
| 587 |
case I32::Sub: |
| 588 |
case I32::Mul: |
| 589 |
parseBinaryOp(static_cast<uint8_t>(i32), ReturnType::I32, dst); |
| 590 |
break; |
| 591 |
case I32::SDiv: |
| 592 |
case I32::UDiv: |
| 593 |
RELEASE_ASSERT_NOT_REACHED(); |
| 594 |
case I32::SMod: |
| 595 |
parseBinaryOp(static_cast<uint8_t>(i32), ReturnType::I32, dst); |
| 596 |
break; |
| 597 |
case I32::UMod: |
| 598 |
RELEASE_ASSERT_NOT_REACHED(); |
| 599 |
case I32::BitNot: |
| 600 |
parseUnaryOp(static_cast<uint8_t>(i32), ReturnType::I32, dst); |
| 601 |
break; |
| 602 |
case I32::BitOr: |
| 603 |
case I32::BitAnd: |
| 604 |
case I32::BitXor: |
| 605 |
parseBinaryOp(static_cast<uint8_t>(i32), ReturnType::I32, dst); |
| 606 |
break; |
| 607 |
case I32::Lsh: |
| 608 |
case I32::ArithRsh: |
| 609 |
case I32::LogicRsh: |
| 610 |
case I32::Clz: |
| 611 |
case I32::LogicNot: |
| 612 |
RELEASE_ASSERT_NOT_REACHED(); |
| 613 |
case I32::EqI32: |
| 614 |
parseRelationalOpI32(Equal, dst); |
| 615 |
break; |
| 616 |
case I32::EqF32: |
| 617 |
RELEASE_ASSERT_NOT_REACHED(); |
| 618 |
case I32::EqF64: |
| 619 |
parseRelationalOpF64(DoubleEqual, dst); |
| 620 |
break; |
| 621 |
case I32::NEqI32: |
| 622 |
parseRelationalOpI32(NotEqual, dst); |
| 623 |
break; |
| 624 |
case I32::NEqF32: |
| 625 |
RELEASE_ASSERT_NOT_REACHED(); |
| 626 |
case I32::NEqF64: |
| 627 |
parseRelationalOpF64(DoubleNotEqual, dst); |
| 628 |
break; |
| 629 |
case I32::SLeThI32: |
| 630 |
parseRelationalOpI32(LessThan, dst); |
| 631 |
break; |
| 632 |
case I32::ULeThI32: |
| 633 |
parseRelationalOpI32(Below, dst); |
| 634 |
break; |
| 635 |
case I32::LeThF32: |
| 636 |
RELEASE_ASSERT_NOT_REACHED(); |
| 637 |
case I32::LeThF64: |
| 638 |
parseRelationalOpF64(DoubleLessThan, dst); |
| 639 |
break; |
| 640 |
case I32::SLeEqI32: |
| 641 |
parseRelationalOpI32(LessThanOrEqual, dst); |
| 642 |
break; |
| 643 |
case I32::ULeEqI32: |
| 644 |
parseRelationalOpI32(BelowOrEqual, dst); |
| 645 |
break; |
| 646 |
case I32::LeEqF32: |
| 647 |
RELEASE_ASSERT_NOT_REACHED(); |
| 648 |
case I32::LeEqF64: |
| 649 |
parseRelationalOpF64(DoubleLessThanOrEqual, dst); |
| 650 |
break; |
| 651 |
case I32::SGrThI32: |
| 652 |
parseRelationalOpI32(GreaterThan, dst); |
| 653 |
break; |
| 654 |
case I32::UGrThI32: |
| 655 |
parseRelationalOpI32(Above, dst); |
| 656 |
break; |
| 657 |
case I32::GrThF32: |
| 658 |
RELEASE_ASSERT_NOT_REACHED(); |
| 659 |
case I32::GrThF64: |
| 660 |
parseRelationalOpF64(DoubleGreaterThan, dst); |
| 661 |
break; |
| 662 |
case I32::SGrEqI32: |
| 663 |
parseRelationalOpI32(GreaterThanOrEqual, dst); |
| 664 |
break; |
| 665 |
case I32::UGrEqI32: |
| 666 |
parseRelationalOpI32(AboveOrEqual, dst); |
| 667 |
break; |
| 668 |
case I32::GrEqF32: |
| 669 |
RELEASE_ASSERT_NOT_REACHED(); |
| 670 |
case I32::GrEqF64: |
| 671 |
parseRelationalOpF64(DoubleGreaterThanOrEqual, dst); |
| 672 |
break; |
| 673 |
case I32::SMin: |
| 674 |
case I32::UMin: |
| 675 |
case I32::SMax: |
| 676 |
case I32::UMax: |
| 677 |
case I32::Abs: |
| 678 |
default: |
| 679 |
RELEASE_ASSERT_NOT_REACHED(); |
| 680 |
} |
| 681 |
} else { |
| 682 |
switch (i32WithImm) { |
| 683 |
case I32WithImm::LitImm: |
| 684 |
store32(TrustedImm32(imm), temporaryAddress(dst)); |
| 685 |
break; |
| 686 |
case I32WithImm::LitPool: |
| 687 |
store32(TrustedImm32(m_module->m_constantI32s[imm]), temporaryAddress(dst)); |
| 688 |
break; |
| 689 |
case I32WithImm::GetLoc: |
| 690 |
load32(stackAddress(imm), GPRInfo::regT0); |
| 691 |
store32(GPRInfo::regT0, temporaryAddress(dst)); |
| 692 |
break; |
| 693 |
default: |
| 694 |
RELEASE_ASSERT_NOT_REACHED(); |
| 695 |
} |
| 696 |
} |
| 697 |
} |
| 698 |
|
| 699 |
void JITCompiler::parseExprF64(int dst) |
| 700 |
{ |
| 701 |
F64 f64; |
| 702 |
F64WithImm f64WithImm; |
| 703 |
uint8_t imm; |
| 704 |
|
| 705 |
if (m_module->m_reader.code(&f64, &f64WithImm, &imm)) { |
| 706 |
switch (f64) { |
| 707 |
case F64::LitImm: |
| 708 |
store64(TrustedImm64(reinterpretDoubleToInt64(m_module->m_reader.fixedWidth<double>())), temporaryAddress(dst)); |
| 709 |
break; |
| 710 |
case F64::Neg: |
| 711 |
parseUnaryOp(static_cast<uint8_t>(f64), ReturnType::F64, dst); |
| 712 |
break; |
| 713 |
case F64::Add: |
| 714 |
case F64::Sub: |
| 715 |
case F64::Mul: |
| 716 |
case F64::Div: |
| 717 |
parseBinaryOp(static_cast<uint8_t>(f64), ReturnType::F64, dst); |
| 718 |
break; |
| 719 |
case F64::Sqrt: |
| 720 |
parseUnaryOp(static_cast<uint8_t>(f64), ReturnType::F64, dst); |
| 721 |
break; |
| 722 |
case F64::CallInt: |
| 723 |
parseCallInternal(ReturnType::F64, dst); |
| 724 |
break; |
| 725 |
case F64::CallImp: |
| 726 |
parseCallImport(ReturnType::F64, dst); |
| 727 |
break; |
| 728 |
default: |
| 729 |
RELEASE_ASSERT_NOT_REACHED(); |
| 730 |
} |
| 731 |
} else { |
| 732 |
switch (f64WithImm) { |
| 733 |
case F64WithImm::LitPool: |
| 734 |
store64(TrustedImm64(reinterpretDoubleToInt64(m_module->m_constantF64s[imm])), temporaryAddress(dst)); |
| 735 |
break; |
| 736 |
case F64WithImm::GetLoc: |
| 737 |
// FIXME: loadDouble/storeDouble? |
| 738 |
load64(stackAddress(imm), GPRInfo::regT0); |
| 739 |
store64(GPRInfo::regT0, temporaryAddress(dst)); |
| 740 |
break; |
| 741 |
default: |
| 742 |
RELEASE_ASSERT_NOT_REACHED(); |
| 743 |
} |
| 744 |
} |
| 745 |
} |
| 746 |
|
| 747 |
static EncodedJSValue getInternalFunction(ExecState*, Module* module, uint32_t functionIndex) |
| 748 |
{ |
| 749 |
// TODO: Use these two lines? |
| 750 |
// VM* vm = exec->vm(); |
| 751 |
// NativeCallFrameTracer tracer(vm, exec); |
| 752 |
|
| 753 |
return JSValue::encode(module->internalFunction(functionIndex)); |
| 754 |
} |
| 755 |
|
| 756 |
void JITCompiler::parseCallInternal(ReturnType returnType, int dst) |
| 757 |
{ |
| 758 |
uint32_t functionIndex = m_module->m_reader.immU32(); |
| 759 |
const Signature& signature = m_module->m_signatures[m_module->m_funcSignatures[functionIndex]]; |
| 760 |
const Vector<Type>& arguments = signature.arguments; |
| 761 |
size_t argumentCount = arguments.size(); |
| 762 |
// FIXME: returnType is redundant with signature.returnType |
| 763 |
|
| 764 |
parseCallArguments(arguments, dst); |
| 765 |
|
| 766 |
store32(TrustedImm32(argumentCount + 1), Address(stackPointerRegister, JSStack::ArgumentCount * static_cast<int>(sizeof(Register)) + PayloadOffset - sizeof(CallerFrameAndPC))); |
| 767 |
|
| 768 |
if (maxFrameExtentForSlowPathCall) |
| 769 |
addPtr(TrustedImm32(-maxFrameExtentForSlowPathCall), stackPointerRegister); |
| 770 |
setupArgumentsWithExecState(TrustedImmPtr(m_module), TrustedImm32(functionIndex)); |
| 771 |
move(TrustedImmPtr(bitwise_cast<void*>(getInternalFunction)), GPRInfo::nonArgGPR0); |
| 772 |
call(GPRInfo::nonArgGPR0); |
| 773 |
if (maxFrameExtentForSlowPathCall) |
| 774 |
addPtr(TrustedImm32(maxFrameExtentForSlowPathCall), stackPointerRegister); |
| 775 |
|
| 776 |
move(GPRInfo::returnValueGPR, GPRInfo::regT0); // regT0 holds callee. |
| 777 |
store64(GPRInfo::regT0, Address(stackPointerRegister, JSStack::Callee * static_cast<int>(sizeof(Register)) - sizeof(CallerFrameAndPC))); |
| 778 |
|
| 779 |
callFunctionSlowCase(returnType, dst); |
| 780 |
} |
| 781 |
|
| 782 |
static EncodedJSValue getImportedFunction(ExecState* exec, Module* module, uint32_t funcImportIndex) |
| 783 |
{ |
| 784 |
// TODO: Use these two lines? |
| 785 |
// VM* vm = exec->vm(); |
| 786 |
// NativeCallFrameTracer tracer(vm, exec); |
| 787 |
|
| 788 |
const String& functionImportName = module->functionImportName(funcImportIndex); |
| 789 |
|
| 790 |
JSGlobalObject* globalObject = exec->lexicalGlobalObject(); |
| 791 |
Identifier identifier = Identifier::fromString(&exec->vm(), functionImportName); |
| 792 |
PropertySlot slot(globalObject); |
| 793 |
|
| 794 |
if (!globalObject->getPropertySlot(exec, identifier, slot)) { |
| 795 |
// TODO: do something! |
| 796 |
fprintf(stderr, "Can't find a function named \"%s\".\n", functionImportName.utf8().data()); |
| 797 |
abort(); |
| 798 |
} |
| 799 |
|
| 800 |
JSValue value = slot.getValue(exec, identifier); |
| 801 |
if (!value.isFunction()) { |
| 802 |
fprintf(stderr, "\"%s\" is not a function.\n", functionImportName.utf8().data()); |
| 803 |
abort(); |
| 804 |
} |
| 805 |
|
| 806 |
return JSValue::encode(value); |
| 807 |
} |
| 808 |
|
| 809 |
void JITCompiler::parseCallImport(ReturnType returnType, int dst) |
| 810 |
{ |
| 811 |
uint32_t funcImportSignatureIndex = m_module->m_reader.immU32(); |
| 812 |
const Module::FuncImportSignature& funcImportSignature = m_module->m_funcImportSignatures[funcImportSignatureIndex]; |
| 813 |
const Signature& signature = m_module->m_signatures[funcImportSignature.signatureIndex]; |
| 814 |
const Vector<Type>& arguments = signature.arguments; |
| 815 |
size_t argumentCount = arguments.size(); |
| 816 |
// FIXME: returnType is redundant with signature.returnType |
| 817 |
|
| 818 |
parseCallArguments(arguments, dst); |
| 819 |
|
| 820 |
store32(TrustedImm32(argumentCount + 1), Address(stackPointerRegister, JSStack::ArgumentCount * static_cast<int>(sizeof(Register)) + PayloadOffset - sizeof(CallerFrameAndPC))); |
| 821 |
|
| 822 |
if (maxFrameExtentForSlowPathCall) |
| 823 |
addPtr(TrustedImm32(-maxFrameExtentForSlowPathCall), stackPointerRegister); |
| 824 |
setupArgumentsWithExecState(TrustedImmPtr(m_module), TrustedImm32(funcImportSignature.funcImportIndex)); |
| 825 |
move(TrustedImmPtr(bitwise_cast<void*>(getImportedFunction)), GPRInfo::nonArgGPR0); |
| 826 |
call(GPRInfo::nonArgGPR0); |
| 827 |
if (maxFrameExtentForSlowPathCall) |
| 828 |
addPtr(TrustedImm32(maxFrameExtentForSlowPathCall), stackPointerRegister); |
| 829 |
|
| 830 |
move(GPRInfo::returnValueGPR, GPRInfo::regT0); // regT0 holds callee. |
| 831 |
store64(GPRInfo::regT0, Address(stackPointerRegister, JSStack::Callee * static_cast<int>(sizeof(Register)) - sizeof(CallerFrameAndPC))); |
| 832 |
|
| 833 |
callFunctionSlowCase(returnType, dst); |
| 834 |
} |
| 835 |
|
| 836 |
void JITCompiler::callFunctionSlowCase(ReturnType returnType, int dst) |
| 837 |
{ |
| 838 |
ThunkGenerator generator = linkThunkGeneratorFor(CodeForCall, RegisterPreservationNotRequired); |
| 839 |
|
| 840 |
move(TrustedImmPtr(nullptr), GPRInfo::regT2); // TODO: use CallLinkInfo |
| 841 |
|
| 842 |
CodePtr ptr = m_vm->getCTIStub(generator).code(); |
| 843 |
|
| 844 |
move(TrustedImmPtr(ptr.executableAddress()), GPRInfo::nonArgGPR0); |
| 845 |
|
| 846 |
call(GPRInfo::nonArgGPR0); |
| 847 |
|
| 848 |
addPtr(TrustedImm32(-m_stackHeight), GPRInfo::callFrameRegister, stackPointerRegister); // FIXME: hacky |
| 849 |
|
| 850 |
// FIXME: Can we really use returnValueGPR? |
| 851 |
switch (returnType) { |
| 852 |
case ReturnType::I32: |
| 853 |
store32(GPRInfo::returnValueGPR, temporaryAddress(dst)); |
| 854 |
break; |
| 855 |
case ReturnType::F64: |
| 856 |
unboxDoubleWithoutAssertions(GPRInfo::returnValueGPR, FPRInfo::fpRegT0); |
| 857 |
storeDouble(FPRInfo::fpRegT0, temporaryAddress(dst)); |
| 858 |
break; |
| 859 |
case ReturnType::Void: |
| 860 |
break; // TODO: sure? |
| 861 |
default: |
| 862 |
ASSERT_NOT_REACHED(); |
| 863 |
} |
| 864 |
} |
| 865 |
|
| 866 |
void JITCompiler::parseCallArguments(const Vector<Type>& arguments, int dst) |
| 867 |
{ |
| 868 |
size_t argumentCount = arguments.size(); |
| 869 |
size_t offset = WTF::roundUpToMultipleOf(stackAlignmentRegisters(), dst + argumentCount + m_currentLocalTypes.size()) - m_currentLocalTypes.size(); // FIXME: better name |
| 870 |
|
| 871 |
for (size_t i = 0; i < argumentCount; ++i) { |
| 872 |
switch (arguments[i]) { |
| 873 |
case Type::I32: |
| 874 |
parseExpr(ReturnType::I32, offset); |
| 875 |
load32(temporaryAddress(offset), GPRInfo::regT0); |
| 876 |
or64(GPRInfo::tagTypeNumberRegister, GPRInfo::regT0); |
| 877 |
store64(GPRInfo::regT0, temporaryAddress(offset - i - 1)); |
| 878 |
break; |
| 879 |
case Type::F64: |
| 880 |
parseExpr(ReturnType::F64, offset); |
| 881 |
loadDouble(temporaryAddress(offset), FPRInfo::fpRegT0); |
| 882 |
boxDouble(FPRInfo::fpRegT0, GPRInfo::regT0); |
| 883 |
store64(GPRInfo::regT0, temporaryAddress(offset - i - 1)); |
| 884 |
break; |
| 885 |
default: |
| 886 |
ASSERT_NOT_REACHED(); |
| 887 |
} |
| 888 |
} |
| 889 |
|
| 890 |
addPtr(TrustedImm32(-(offset + m_currentLocalTypes.size() + 3) * 8 - 8), GPRInfo::callFrameRegister, stackPointerRegister); // FIXME: hacky |
| 891 |
} |
| 892 |
|
| 893 |
void JITCompiler::parseUnaryOp(uint8_t op, ReturnType returnType, int dst) |
| 894 |
{ |
| 895 |
parseExpr(returnType, dst); |
| 896 |
switch (returnType) { |
| 897 |
case ReturnType::I32: |
| 898 |
load32(temporaryAddress(dst), GPRInfo::regT0); |
| 899 |
switch (static_cast<I32>(op)) { |
| 900 |
case I32::Neg: |
| 901 |
neg32(GPRInfo::regT0); |
| 902 |
break; |
| 903 |
case I32::BitNot: |
| 904 |
xor32(TrustedImm32(-1), GPRInfo::regT0); |
| 905 |
break; |
| 906 |
default: |
| 907 |
ASSERT_NOT_REACHED(); |
| 908 |
} |
| 909 |
store32(GPRInfo::regT0, temporaryAddress(dst)); |
| 910 |
break; |
| 911 |
case ReturnType::F64: |
| 912 |
loadDouble(temporaryAddress(dst), FPRInfo::fpRegT0); |
| 913 |
switch (static_cast<F64>(op)) { |
| 914 |
case F64::Neg: |
| 915 |
negateDouble(FPRInfo::fpRegT0, FPRInfo::fpRegT1); |
| 916 |
break; |
| 917 |
case F64::Sqrt: |
| 918 |
sqrtDouble(FPRInfo::fpRegT0, FPRInfo::fpRegT1); |
| 919 |
break; |
| 920 |
default: |
| 921 |
ASSERT_NOT_REACHED(); |
| 922 |
} |
| 923 |
storeDouble(FPRInfo::fpRegT1, temporaryAddress(dst)); |
| 924 |
break; |
| 925 |
default: |
| 926 |
RELEASE_ASSERT_NOT_REACHED(); |
| 927 |
} |
| 928 |
} |
| 929 |
|
| 930 |
void JITCompiler::parseBinaryOp(uint8_t op, ReturnType returnType, int dst) |
| 931 |
{ |
| 932 |
parseExpr(returnType, dst); |
| 933 |
parseExpr(returnType, dst + 1); |
| 934 |
switch (returnType) { |
| 935 |
case ReturnType::I32: |
| 936 |
load32(temporaryAddress(dst), GPRInfo::regT0); |
| 937 |
load32(temporaryAddress(dst + 1), GPRInfo::regT1); |
| 938 |
switch (static_cast<I32>(op)) { |
| 939 |
case I32::Add: |
| 940 |
add32(GPRInfo::regT1, GPRInfo::regT0); |
| 941 |
break; |
| 942 |
case I32::Sub: |
| 943 |
sub32(GPRInfo::regT1, GPRInfo::regT0); |
| 944 |
break; |
| 945 |
case I32::Mul: |
| 946 |
mul32(GPRInfo::regT1, GPRInfo::regT0); |
| 947 |
break; |
| 948 |
case I32::SMod: |
| 949 |
move(GPRInfo::regT1, GPRInfo::regT2); |
| 950 |
m_assembler.cdq(); |
| 951 |
m_assembler.idivl_r(GPRInfo::regT2); |
| 952 |
move(GPRInfo::regT1, GPRInfo::regT0); |
| 953 |
break; |
| 954 |
case I32::BitOr: |
| 955 |
or32(GPRInfo::regT1, GPRInfo::regT0); |
| 956 |
break; |
| 957 |
case I32::BitAnd: |
| 958 |
and32(GPRInfo::regT1, GPRInfo::regT0); |
| 959 |
break; |
| 960 |
case I32::BitXor: |
| 961 |
xor32(GPRInfo::regT1, GPRInfo::regT0); |
| 962 |
break; |
| 963 |
default: |
| 964 |
ASSERT_NOT_REACHED(); |
| 965 |
} |
| 966 |
store32(GPRInfo::regT0, temporaryAddress(dst)); |
| 967 |
break; |
| 968 |
case ReturnType::F64: |
| 969 |
loadDouble(temporaryAddress(dst), FPRInfo::fpRegT0); |
| 970 |
loadDouble(temporaryAddress(dst + 1), FPRInfo::fpRegT1); |
| 971 |
switch (static_cast<F64>(op)) { |
| 972 |
case F64::Add: |
| 973 |
addDouble(FPRInfo::fpRegT1, FPRInfo::fpRegT0); |
| 974 |
break; |
| 975 |
case F64::Sub: |
| 976 |
subDouble(FPRInfo::fpRegT1, FPRInfo::fpRegT0); |
| 977 |
break; |
| 978 |
case F64::Mul: |
| 979 |
mulDouble(FPRInfo::fpRegT1, FPRInfo::fpRegT0); |
| 980 |
break; |
| 981 |
case F64::Div: |
| 982 |
divDouble(FPRInfo::fpRegT1, FPRInfo::fpRegT0); |
| 983 |
break; |
| 984 |
default: |
| 985 |
ASSERT_NOT_REACHED(); |
| 986 |
} |
| 987 |
storeDouble(FPRInfo::fpRegT0, temporaryAddress(dst)); |
| 988 |
break; |
| 989 |
default: |
| 990 |
RELEASE_ASSERT_NOT_REACHED(); |
| 991 |
} |
| 992 |
} |
| 993 |
|
| 994 |
void JITCompiler::parseRelationalOpI32(RelationalCondition condition, int dst) |
| 995 |
{ |
| 996 |
parseExpr(ReturnType::I32, dst); |
| 997 |
parseExpr(ReturnType::I32, dst + 1); |
| 998 |
load32(temporaryAddress(dst), GPRInfo::regT0); |
| 999 |
load32(temporaryAddress(dst + 1), GPRInfo::regT1); |
| 1000 |
compare32(condition, GPRInfo::regT0, GPRInfo::regT1, GPRInfo::regT0); |
| 1001 |
store32(GPRInfo::regT0, temporaryAddress(dst)); |
| 1002 |
} |
| 1003 |
|
| 1004 |
void JITCompiler::parseRelationalOpF64(DoubleCondition condition, int dst) |
| 1005 |
{ |
| 1006 |
parseExpr(ReturnType::F64, dst); |
| 1007 |
parseExpr(ReturnType::F64, dst + 1); |
| 1008 |
loadDouble(temporaryAddress(dst), FPRInfo::fpRegT0); |
| 1009 |
loadDouble(temporaryAddress(dst + 1), FPRInfo::fpRegT1); |
| 1010 |
Jump trueCase = branchDouble(condition, FPRInfo::fpRegT0, FPRInfo::fpRegT1); |
| 1011 |
store32(TrustedImm32(0), temporaryAddress(dst)); |
| 1012 |
Jump end = jump(); |
| 1013 |
trueCase.link(this); |
| 1014 |
store32(TrustedImm32(1), temporaryAddress(dst)); |
| 1015 |
end.link(this); |
| 1016 |
} |
| 1017 |
|
| 1018 |
void JITCompiler::parseComma(ReturnType returnType, int dst) |
| 1019 |
{ |
| 1020 |
parseExpr(m_module->m_reader.rtype(), dst); |
| 1021 |
parseExpr(returnType, dst); |
| 1022 |
} |
| 1023 |
|
| 1024 |
void JITCompiler::parseCond(ReturnType returnType, int dst) |
| 1025 |
{ |
| 1026 |
parseExpr(ReturnType::I32, dst); |
| 1027 |
load32(temporaryAddress(dst), GPRInfo::regT0); |
| 1028 |
Jump els = branchTest32(Zero, GPRInfo::regT0); |
| 1029 |
parseExpr(returnType, dst); |
| 1030 |
Jump end = jump(); |
| 1031 |
els.link(this); |
| 1032 |
parseExpr(returnType, dst); |
| 1033 |
end.link(this); |
| 1034 |
} |
| 1035 |
|
| 1036 |
} } // namespace JSC::Wasm |