Skip to content

Commit a34917b

Browse files
Michael StarzingerCommit Bot
authored andcommitted
[asm.js] Port {InstantiateAsmJs} builtin to CSA.
R=jgruber@chromium.org Change-Id: If4b439ac7465cd984600816ff619d66f04cf174b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1917156 Reviewed-by: Jakob Gruber <jgruber@chromium.org> Commit-Queue: Michael Starzinger <mstarzinger@chromium.org> Cr-Commit-Position: refs/heads/master@{#65028}
1 parent 52e07ff commit a34917b

11 files changed

Lines changed: 29 additions & 584 deletions

File tree

src/builtins/arm/builtins-arm.cc

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,77 +1398,6 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
13981398
Generate_InterpreterEnterBytecode(masm);
13991399
}
14001400

1401-
void Builtins::Generate_InstantiateAsmJs(MacroAssembler* masm) {
1402-
// ----------- S t a t e -------------
1403-
// -- r0 : argument count (preserved for callee)
1404-
// -- r1 : new target (preserved for callee)
1405-
// -- r3 : target function (preserved for callee)
1406-
// -----------------------------------
1407-
Label failed;
1408-
{
1409-
FrameScope scope(masm, StackFrame::INTERNAL);
1410-
// Preserve argument count for later compare.
1411-
__ Move(r4, r0);
1412-
// Push the number of arguments to the callee.
1413-
__ SmiTag(r0);
1414-
__ push(r0);
1415-
// Push a copy of the target function and the new target.
1416-
__ push(r1);
1417-
__ push(r3);
1418-
1419-
// The function.
1420-
__ push(r1);
1421-
// Copy arguments from caller (stdlib, foreign, heap).
1422-
Label args_done;
1423-
for (int j = 0; j < 4; ++j) {
1424-
Label over;
1425-
if (j < 3) {
1426-
__ cmp(r4, Operand(j));
1427-
__ b(ne, &over);
1428-
}
1429-
for (int i = j - 1; i >= 0; --i) {
1430-
__ ldr(r4, MemOperand(fp, StandardFrameConstants::kCallerSPOffset +
1431-
i * kPointerSize));
1432-
__ push(r4);
1433-
}
1434-
for (int i = 0; i < 3 - j; ++i) {
1435-
__ PushRoot(RootIndex::kUndefinedValue);
1436-
}
1437-
if (j < 3) {
1438-
__ jmp(&args_done);
1439-
__ bind(&over);
1440-
}
1441-
}
1442-
__ bind(&args_done);
1443-
1444-
// Call runtime, on success unwind frame, and parent frame.
1445-
__ CallRuntime(Runtime::kInstantiateAsmJs, 4);
1446-
// A smi 0 is returned on failure, an object on success.
1447-
__ JumpIfSmi(r0, &failed);
1448-
1449-
__ Drop(2);
1450-
__ pop(r4);
1451-
__ SmiUntag(r4);
1452-
scope.GenerateLeaveFrame();
1453-
1454-
__ add(r4, r4, Operand(1));
1455-
__ Drop(r4);
1456-
__ Ret();
1457-
1458-
__ bind(&failed);
1459-
// Restore target function and new target.
1460-
__ pop(r3);
1461-
__ pop(r1);
1462-
__ pop(r0);
1463-
__ SmiUntag(r0);
1464-
}
1465-
// On failure, tail call back to regular js by re-calling the function
1466-
// which has be reset to the compile lazy builtin.
1467-
static_assert(kJavaScriptCallCodeStartRegister == r2, "ABI mismatch");
1468-
__ ldr(r2, FieldMemOperand(r1, JSFunction::kCodeOffset));
1469-
__ JumpCodeObject(r2);
1470-
}
1471-
14721401
namespace {
14731402
void Generate_ContinueToBuiltinHelper(MacroAssembler* masm,
14741403
bool java_script_builtin,

src/builtins/arm64/builtins-arm64.cc

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,96 +1560,6 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
15601560
Generate_InterpreterEnterBytecode(masm);
15611561
}
15621562

1563-
void Builtins::Generate_InstantiateAsmJs(MacroAssembler* masm) {
1564-
// ----------- S t a t e -------------
1565-
// -- x0 : argument count (preserved for callee)
1566-
// -- x1 : new target (preserved for callee)
1567-
// -- x3 : target function (preserved for callee)
1568-
// -----------------------------------
1569-
Register argc = x0;
1570-
Register new_target = x1;
1571-
Register target = x3;
1572-
1573-
Label failed;
1574-
{
1575-
FrameScope scope(masm, StackFrame::INTERNAL);
1576-
1577-
// Push argument count, a copy of the target function and the new target,
1578-
// together with some padding to maintain 16-byte alignment.
1579-
__ SmiTag(argc);
1580-
__ Push(argc, new_target, target, padreg);
1581-
1582-
// Push another copy of new target as a parameter to the runtime call and
1583-
// copy the rest of the arguments from caller (stdlib, foreign, heap).
1584-
Label args_done;
1585-
Register undef = x10;
1586-
Register scratch1 = x12;
1587-
Register scratch2 = x13;
1588-
Register scratch3 = x14;
1589-
__ LoadRoot(undef, RootIndex::kUndefinedValue);
1590-
1591-
Label at_least_one_arg;
1592-
Label three_args;
1593-
DCHECK_EQ(0, Smi::zero().ptr());
1594-
__ Cbnz(argc, &at_least_one_arg);
1595-
1596-
// No arguments.
1597-
__ Push(new_target, undef, undef, undef);
1598-
__ B(&args_done);
1599-
1600-
__ Bind(&at_least_one_arg);
1601-
// Load two arguments, though we may only use one (for the one arg case).
1602-
__ Ldp(scratch2, scratch1,
1603-
MemOperand(fp, StandardFrameConstants::kCallerSPOffset));
1604-
1605-
// Set flags for determining the value of smi-tagged argc.
1606-
// lt => 1, eq => 2, gt => 3.
1607-
__ CmpTagged(argc, Smi::FromInt(2));
1608-
__ B(gt, &three_args);
1609-
1610-
// One or two arguments.
1611-
// If there is one argument (flags are lt), scratch2 contains that argument,
1612-
// and scratch1 must be undefined.
1613-
__ CmovX(scratch1, scratch2, lt);
1614-
__ CmovX(scratch2, undef, lt);
1615-
__ Push(new_target, scratch1, scratch2, undef);
1616-
__ B(&args_done);
1617-
1618-
// Three arguments.
1619-
__ Bind(&three_args);
1620-
__ Ldr(scratch3, MemOperand(fp, StandardFrameConstants::kCallerSPOffset +
1621-
2 * kSystemPointerSize));
1622-
__ Push(new_target, scratch3, scratch1, scratch2);
1623-
1624-
__ Bind(&args_done);
1625-
1626-
// Call runtime, on success unwind frame, and parent frame.
1627-
__ CallRuntime(Runtime::kInstantiateAsmJs, 4);
1628-
1629-
// A smi 0 is returned on failure, an object on success.
1630-
__ JumpIfSmi(x0, &failed);
1631-
1632-
// Peek the argument count from the stack, untagging at the same time.
1633-
__ SmiUntag(x4, MemOperand(sp, 3 * kSystemPointerSize));
1634-
__ Drop(4);
1635-
scope.GenerateLeaveFrame();
1636-
1637-
// Drop arguments and receiver.
1638-
__ DropArguments(x4, TurboAssembler::kCountExcludesReceiver);
1639-
__ Ret();
1640-
1641-
__ Bind(&failed);
1642-
// Restore target function and new target.
1643-
__ Pop(padreg, target, new_target, argc);
1644-
__ SmiUntag(argc);
1645-
}
1646-
// On failure, tail call back to regular js by re-calling the function
1647-
// which has be reset to the compile lazy builtin.
1648-
__ LoadTaggedPointerField(
1649-
x4, FieldMemOperand(new_target, JSFunction::kCodeOffset));
1650-
__ JumpCodeObject(x4);
1651-
}
1652-
16531563
namespace {
16541564
void Generate_ContinueToBuiltinHelper(MacroAssembler* masm,
16551565
bool java_script_builtin,

src/builtins/builtins-definitions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ namespace internal {
132132
/* Code life-cycle */ \
133133
TFC(CompileLazy, JSTrampoline) \
134134
TFC(CompileLazyDeoptimizedCode, JSTrampoline) \
135-
ASM(InstantiateAsmJs, Dummy) \
135+
TFC(InstantiateAsmJs, JSTrampoline) \
136136
ASM(NotifyDeoptimized, Dummy) \
137137
\
138138
/* Trampolines called when returning from a deoptimization that expects */ \

src/builtins/builtins-internal-gen.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,5 +1133,33 @@ TF_BUILTIN(SetPropertyInLiteral, CodeStubAssembler) {
11331133
key, value);
11341134
}
11351135

1136+
TF_BUILTIN(InstantiateAsmJs, CodeStubAssembler) {
1137+
Label tailcall_to_function(this);
1138+
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
1139+
TNode<Object> new_target = CAST(Parameter(Descriptor::kNewTarget));
1140+
TNode<Int32T> arg_count =
1141+
UncheckedCast<Int32T>(Parameter(Descriptor::kActualArgumentsCount));
1142+
TNode<JSFunction> function = CAST(Parameter(Descriptor::kTarget));
1143+
1144+
// Retrieve arguments from caller (stdlib, foreign, heap).
1145+
CodeStubArguments args(this, arg_count);
1146+
TNode<Object> stdlib = args.GetOptionalArgumentValue(0);
1147+
TNode<Object> foreign = args.GetOptionalArgumentValue(1);
1148+
TNode<Object> heap = args.GetOptionalArgumentValue(2);
1149+
1150+
// Call runtime, on success just pass the result to the caller and pop all
1151+
// arguments. A smi 0 is returned on failure, an object on success.
1152+
TNode<Object> maybe_result_or_smi_zero = CallRuntime(
1153+
Runtime::kInstantiateAsmJs, context, function, stdlib, foreign, heap);
1154+
GotoIf(TaggedIsSmi(maybe_result_or_smi_zero), &tailcall_to_function);
1155+
args.PopAndReturn(maybe_result_or_smi_zero);
1156+
1157+
BIND(&tailcall_to_function);
1158+
// On failure, tail call back to regular JavaScript by re-calling the given
1159+
// function which has been reset to the compile lazy builtin.
1160+
TNode<Code> code = CAST(LoadObjectField(function, JSFunction::kCodeOffset));
1161+
TailCallJSCode(code, context, function, new_target, arg_count);
1162+
}
1163+
11361164
} // namespace internal
11371165
} // namespace v8

src/builtins/ia32/builtins-ia32.cc

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,78 +1447,6 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
14471447
Generate_InterpreterEnterBytecode(masm);
14481448
}
14491449

1450-
void Builtins::Generate_InstantiateAsmJs(MacroAssembler* masm) {
1451-
// ----------- S t a t e -------------
1452-
// -- eax : argument count (preserved for callee)
1453-
// -- edx : new target (preserved for callee)
1454-
// -- edi : target function (preserved for callee)
1455-
// -----------------------------------
1456-
Label failed;
1457-
{
1458-
FrameScope scope(masm, StackFrame::INTERNAL);
1459-
// Preserve argument count for later compare.
1460-
__ mov(ecx, eax);
1461-
// Push the number of arguments to the callee.
1462-
__ SmiTag(eax);
1463-
__ push(eax);
1464-
// Push a copy of the target function and the new target.
1465-
__ push(edi);
1466-
__ push(edx);
1467-
1468-
// The function.
1469-
__ push(edi);
1470-
// Copy arguments from caller (stdlib, foreign, heap).
1471-
Label args_done;
1472-
for (int j = 0; j < 4; ++j) {
1473-
Label over;
1474-
if (j < 3) {
1475-
__ cmp(ecx, Immediate(j));
1476-
__ j(not_equal, &over, Label::kNear);
1477-
}
1478-
for (int i = j - 1; i >= 0; --i) {
1479-
__ Push(Operand(ebp, StandardFrameConstants::kCallerSPOffset +
1480-
i * kSystemPointerSize));
1481-
}
1482-
for (int i = 0; i < 3 - j; ++i) {
1483-
__ PushRoot(RootIndex::kUndefinedValue);
1484-
}
1485-
if (j < 3) {
1486-
__ jmp(&args_done, Label::kNear);
1487-
__ bind(&over);
1488-
}
1489-
}
1490-
__ bind(&args_done);
1491-
1492-
// Call runtime, on success unwind frame, and parent frame.
1493-
__ CallRuntime(Runtime::kInstantiateAsmJs, 4);
1494-
// A smi 0 is returned on failure, an object on success.
1495-
__ JumpIfSmi(eax, &failed, Label::kNear);
1496-
1497-
__ Drop(2);
1498-
__ Pop(ecx);
1499-
__ SmiUntag(ecx);
1500-
scope.GenerateLeaveFrame();
1501-
1502-
__ PopReturnAddressTo(edx);
1503-
__ inc(ecx);
1504-
__ lea(esp, Operand(esp, ecx, times_system_pointer_size, 0));
1505-
__ PushReturnAddressFrom(edx);
1506-
__ ret(0);
1507-
1508-
__ bind(&failed);
1509-
// Restore target function and new target.
1510-
__ pop(edx);
1511-
__ pop(edi);
1512-
__ pop(eax);
1513-
__ SmiUntag(eax);
1514-
}
1515-
// On failure, tail call back to regular js by re-calling the function
1516-
// which has be reset to the compile lazy builtin.
1517-
static_assert(kJavaScriptCallCodeStartRegister == ecx, "ABI mismatch");
1518-
__ mov(ecx, FieldOperand(edi, JSFunction::kCodeOffset));
1519-
__ JumpCodeObject(ecx);
1520-
}
1521-
15221450
namespace {
15231451
void Generate_ContinueToBuiltinHelper(MacroAssembler* masm,
15241452
bool java_script_builtin,

src/builtins/mips/builtins-mips.cc

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,71 +1372,6 @@ void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
13721372
Generate_InterpreterEnterBytecode(masm);
13731373
}
13741374

1375-
void Builtins::Generate_InstantiateAsmJs(MacroAssembler* masm) {
1376-
// ----------- S t a t e -------------
1377-
// -- a0 : argument count (preserved for callee)
1378-
// -- a1 : new target (preserved for callee)
1379-
// -- a3 : target function (preserved for callee)
1380-
// -----------------------------------
1381-
Label failed;
1382-
{
1383-
FrameScope scope(masm, StackFrame::INTERNAL);
1384-
// Preserve argument count for later compare.
1385-
__ Move(t4, a0);
1386-
// Push a copy of the target function and the new target.
1387-
// Push function as parameter to the runtime call.
1388-
__ SmiTag(a0);
1389-
__ Push(a0, a1, a3, a1);
1390-
1391-
// Copy arguments from caller (stdlib, foreign, heap).
1392-
Label args_done;
1393-
for (int j = 0; j < 4; ++j) {
1394-
Label over;
1395-
if (j < 3) {
1396-
__ Branch(&over, ne, t4, Operand(j));
1397-
}
1398-
for (int i = j - 1; i >= 0; --i) {
1399-
__ lw(t4, MemOperand(fp, StandardFrameConstants::kCallerSPOffset +
1400-
i * kPointerSize));
1401-
__ push(t4);
1402-
}
1403-
for (int i = 0; i < 3 - j; ++i) {
1404-
__ PushRoot(RootIndex::kUndefinedValue);
1405-
}
1406-
if (j < 3) {
1407-
__ jmp(&args_done);
1408-
__ bind(&over);
1409-
}
1410-
}
1411-
__ bind(&args_done);
1412-
1413-
// Call runtime, on success unwind frame, and parent frame.
1414-
__ CallRuntime(Runtime::kInstantiateAsmJs, 4);
1415-
// A smi 0 is returned on failure, an object on success.
1416-
__ JumpIfSmi(v0, &failed);
1417-
1418-
__ Drop(2);
1419-
__ pop(t4);
1420-
__ SmiUntag(t4);
1421-
scope.GenerateLeaveFrame();
1422-
1423-
__ Addu(t4, t4, Operand(1));
1424-
__ Lsa(sp, sp, t4, kPointerSizeLog2);
1425-
__ Ret();
1426-
1427-
__ bind(&failed);
1428-
// Restore target function and new target.
1429-
__ Pop(a0, a1, a3);
1430-
__ SmiUntag(a0);
1431-
}
1432-
// On failure, tail call back to regular js by re-calling the function
1433-
// which has be reset to the compile lazy builtin.
1434-
static_assert(kJavaScriptCallCodeStartRegister == a2, "ABI mismatch");
1435-
__ lw(a2, FieldMemOperand(a1, JSFunction::kCodeOffset));
1436-
__ Addu(a2, a2, Code::kHeaderSize - kHeapObjectTag);
1437-
__ Jump(a2);
1438-
}
1439-
14401375
namespace {
14411376
void Generate_ContinueToBuiltinHelper(MacroAssembler* masm,
14421377
bool java_script_builtin,

0 commit comments

Comments
 (0)