Skip to content

Commit 53d4dfc

Browse files
LeszekSwirskiCommit Bot
authored andcommitted
[sfi] Compress function arg counts to 16 bit
Compress the parameter count (and function length) stored in SharedFunctionInfo to a uint16_t. This limits us to 2^16 - 1 parameters per function, minus one for the "don't adapt arguments" sentinel value, which is one fewer than Code::kMaxArguments was already. Anyway, 65534 arguments should be enough for anyone! This drops SFI size by 4 bytes. Bug: chromium:818642 Change-Id: I126bfb24453dcdc5087a104d3a12cf195a56fa9f Reviewed-on: https://chromium-review.googlesource.com/1076627 Commit-Queue: Leszek Swirski <leszeks@chromium.org> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Cr-Commit-Position: refs/heads/master@{#53447}
1 parent c002394 commit 53d4dfc

29 files changed

+119
-105
lines changed

src/arm/macro-assembler-arm.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,9 +1623,9 @@ void MacroAssembler::InvokeFunction(Register fun, Register new_target,
16231623

16241624
ldr(temp_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
16251625
ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
1626-
ldr(expected_reg,
1627-
FieldMemOperand(temp_reg,
1628-
SharedFunctionInfo::kFormalParameterCountOffset));
1626+
ldrh(expected_reg,
1627+
FieldMemOperand(temp_reg,
1628+
SharedFunctionInfo::kFormalParameterCountOffset));
16291629

16301630
ParameterCount expected(expected_reg);
16311631
InvokeFunctionCode(fun, new_target, expected, actual, flag);

src/arm64/macro-assembler-arm64.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,9 +2414,9 @@ void MacroAssembler::InvokeFunction(Register function, Register new_target,
24142414
// extension to correctly handle it.
24152415
Ldr(expected_reg, FieldMemOperand(function,
24162416
JSFunction::kSharedFunctionInfoOffset));
2417-
Ldrsw(expected_reg,
2418-
FieldMemOperand(expected_reg,
2419-
SharedFunctionInfo::kFormalParameterCountOffset));
2417+
Ldrh(expected_reg,
2418+
FieldMemOperand(expected_reg,
2419+
SharedFunctionInfo::kFormalParameterCountOffset));
24202420

24212421
ParameterCount expected(expected_reg);
24222422
InvokeFunctionCode(function, new_target, expected, actual, flag);

src/builtins/arm/builtins-arm.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,8 @@ void Builtins::Generate_ResumeGeneratorTrampoline(MacroAssembler* masm) {
495495

496496
// Copy the function arguments from the generator object's register file.
497497
__ ldr(r3, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
498-
__ ldr(r3,
499-
FieldMemOperand(r3, SharedFunctionInfo::kFormalParameterCountOffset));
498+
__ ldrh(r3,
499+
FieldMemOperand(r3, SharedFunctionInfo::kFormalParameterCountOffset));
500500
__ ldr(r2,
501501
FieldMemOperand(r1, JSGeneratorObject::kParametersAndRegistersOffset));
502502
{
@@ -527,8 +527,8 @@ void Builtins::Generate_ResumeGeneratorTrampoline(MacroAssembler* masm) {
527527
// Resume (Ignition/TurboFan) generator object.
528528
{
529529
__ ldr(r0, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
530-
__ ldr(r0, FieldMemOperand(
531-
r0, SharedFunctionInfo::kFormalParameterCountOffset));
530+
__ ldrh(r0, FieldMemOperand(
531+
r0, SharedFunctionInfo::kFormalParameterCountOffset));
532532
// We abuse new.target both to indicate that this is a resume call and to
533533
// pass in the generator object. In ordinary calls, new.target is always
534534
// undefined because generator functions are non-constructable.
@@ -1981,8 +1981,8 @@ void Builtins::Generate_CallOrConstructForwardVarargs(MacroAssembler* masm,
19811981
{
19821982
__ ldr(r5, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
19831983
__ ldr(r5, FieldMemOperand(r5, JSFunction::kSharedFunctionInfoOffset));
1984-
__ ldr(r5, FieldMemOperand(
1985-
r5, SharedFunctionInfo::kFormalParameterCountOffset));
1984+
__ ldrh(r5, FieldMemOperand(
1985+
r5, SharedFunctionInfo::kFormalParameterCountOffset));
19861986
__ mov(r4, fp);
19871987
}
19881988
__ b(&arguments_done);
@@ -2112,8 +2112,8 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm,
21122112
// -- cp : the function context.
21132113
// -----------------------------------
21142114

2115-
__ ldr(r2,
2116-
FieldMemOperand(r2, SharedFunctionInfo::kFormalParameterCountOffset));
2115+
__ ldrh(r2,
2116+
FieldMemOperand(r2, SharedFunctionInfo::kFormalParameterCountOffset));
21172117
ParameterCount actual(r0);
21182118
ParameterCount expected(r2);
21192119
__ InvokeFunctionCode(r1, no_reg, expected, actual, JUMP_FUNCTION);
@@ -2429,10 +2429,10 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
24292429
Label invoke, dont_adapt_arguments, stack_overflow;
24302430

24312431
Label enough, too_few;
2432-
__ cmp(r0, r2);
2433-
__ b(lt, &too_few);
24342432
__ cmp(r2, Operand(SharedFunctionInfo::kDontAdaptArgumentsSentinel));
24352433
__ b(eq, &dont_adapt_arguments);
2434+
__ cmp(r0, r2);
2435+
__ b(lt, &too_few);
24362436

24372437
Register scratch = r5;
24382438

src/builtins/arm64/builtins-arm64.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,8 @@ void Builtins::Generate_ResumeGeneratorTrampoline(MacroAssembler* masm) {
510510

511511
// Get number of arguments for generator function.
512512
__ Ldr(x10, FieldMemOperand(x4, JSFunction::kSharedFunctionInfoOffset));
513-
__ Ldr(w10,
514-
FieldMemOperand(x10, SharedFunctionInfo::kFormalParameterCountOffset));
513+
__ Ldrh(w10, FieldMemOperand(
514+
x10, SharedFunctionInfo::kFormalParameterCountOffset));
515515

516516
// Claim slots for arguments and receiver (rounded up to a multiple of two).
517517
__ Add(x11, x10, 2);
@@ -571,8 +571,8 @@ void Builtins::Generate_ResumeGeneratorTrampoline(MacroAssembler* masm) {
571571
// Resume (Ignition/TurboFan) generator object.
572572
{
573573
__ Ldr(x0, FieldMemOperand(x4, JSFunction::kSharedFunctionInfoOffset));
574-
__ Ldr(w0, FieldMemOperand(
575-
x0, SharedFunctionInfo::kFormalParameterCountOffset));
574+
__ Ldrh(w0, FieldMemOperand(
575+
x0, SharedFunctionInfo::kFormalParameterCountOffset));
576576
// We abuse new.target both to indicate that this is a resume call and to
577577
// pass in the generator object. In ordinary calls, new.target is always
578578
// undefined because generator functions are non-constructable.
@@ -2328,9 +2328,9 @@ void Builtins::Generate_CallOrConstructForwardVarargs(MacroAssembler* masm,
23282328
MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
23292329
__ Ldr(scratch,
23302330
FieldMemOperand(scratch, JSFunction::kSharedFunctionInfoOffset));
2331-
__ Ldrsw(len,
2332-
FieldMemOperand(
2333-
scratch, SharedFunctionInfo::kFormalParameterCountOffset));
2331+
__ Ldrh(len,
2332+
FieldMemOperand(scratch,
2333+
SharedFunctionInfo::kFormalParameterCountOffset));
23342334
__ Mov(args_fp, fp);
23352335
}
23362336
__ B(&arguments_done);
@@ -2455,8 +2455,8 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm,
24552455
// -- cp : the function context.
24562456
// -----------------------------------
24572457

2458-
__ Ldrsw(
2459-
x2, FieldMemOperand(x2, SharedFunctionInfo::kFormalParameterCountOffset));
2458+
__ Ldrh(x2,
2459+
FieldMemOperand(x2, SharedFunctionInfo::kFormalParameterCountOffset));
24602460
ParameterCount actual(x0);
24612461
ParameterCount expected(x2);
24622462
__ InvokeFunctionCode(x1, no_reg, expected, actual, JUMP_FUNCTION);

src/builtins/builtins-arguments-gen.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ArgumentsBuiltinsAssembler::GetArgumentsFrameAndCount(Node* function,
4545
CSA_SLOW_ASSERT(this, HasInstanceType(shared, SHARED_FUNCTION_INFO_TYPE));
4646
Node* formal_parameter_count =
4747
LoadObjectField(shared, SharedFunctionInfo::kFormalParameterCountOffset,
48-
MachineType::Int32());
48+
MachineType::Uint16());
4949
formal_parameter_count = Int32ToParameter(formal_parameter_count, mode);
5050

5151
argument_count.Bind(formal_parameter_count);

src/builtins/builtins-object-gen.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ TF_BUILTIN(CreateGeneratorObject, ObjectBuiltinsAssembler) {
13671367

13681368
Node* formal_parameter_count = ChangeInt32ToIntPtr(
13691369
LoadObjectField(shared, SharedFunctionInfo::kFormalParameterCountOffset,
1370-
MachineType::Int32()));
1370+
MachineType::Uint16()));
13711371
Node* frame_size = ChangeInt32ToIntPtr(LoadObjectField(
13721372
bytecode_array, BytecodeArray::kFrameSizeOffset, MachineType::Int32()));
13731373
Node* size = IntPtrAdd(WordSar(frame_size, IntPtrConstant(kPointerSizeLog2)),

src/builtins/ia32/builtins-ia32.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ void Builtins::Generate_ResumeGeneratorTrampoline(MacroAssembler* masm) {
541541

542542
// Copy the function arguments from the generator object's register file.
543543
__ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
544-
__ mov(ecx,
545-
FieldOperand(ecx, SharedFunctionInfo::kFormalParameterCountOffset));
544+
__ movzx_w(
545+
ecx, FieldOperand(ecx, SharedFunctionInfo::kFormalParameterCountOffset));
546546
__ mov(ebx,
547547
FieldOperand(edx, JSGeneratorObject::kParametersAndRegistersOffset));
548548
{
@@ -576,8 +576,8 @@ void Builtins::Generate_ResumeGeneratorTrampoline(MacroAssembler* masm) {
576576
{
577577
__ PushReturnAddressFrom(eax);
578578
__ mov(eax, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
579-
__ mov(eax,
580-
FieldOperand(eax, SharedFunctionInfo::kFormalParameterCountOffset));
579+
__ movzx_w(eax, FieldOperand(
580+
eax, SharedFunctionInfo::kFormalParameterCountOffset));
581581
// We abuse new.target both to indicate that this is a resume call and to
582582
// pass in the generator object. In ordinary calls, new.target is always
583583
// undefined because generator functions are non-constructable.
@@ -2101,8 +2101,8 @@ void Builtins::Generate_CallOrConstructForwardVarargs(MacroAssembler* masm,
21012101
{
21022102
__ mov(edx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
21032103
__ mov(edx, FieldOperand(edx, JSFunction::kSharedFunctionInfoOffset));
2104-
__ mov(edx,
2105-
FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset));
2104+
__ movzx_w(edx, FieldOperand(
2105+
edx, SharedFunctionInfo::kFormalParameterCountOffset));
21062106
__ mov(ebx, ebp);
21072107
}
21082108
__ jmp(&arguments_done, Label::kNear);
@@ -2251,8 +2251,8 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm,
22512251
// -- esi : the function context.
22522252
// -----------------------------------
22532253

2254-
__ mov(ebx,
2255-
FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset));
2254+
__ movzx_w(
2255+
ebx, FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset));
22562256
ParameterCount actual(eax);
22572257
ParameterCount expected(ebx);
22582258
__ InvokeFunctionCode(edi, no_reg, expected, actual, JUMP_FUNCTION);
@@ -2584,10 +2584,10 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
25842584
__ IncrementCounter(masm->isolate()->counters()->arguments_adaptors(), 1);
25852585

25862586
Label enough, too_few;
2587-
__ cmp(eax, ebx);
2588-
__ j(less, &too_few);
25892587
__ cmp(ebx, SharedFunctionInfo::kDontAdaptArgumentsSentinel);
25902588
__ j(equal, &dont_adapt_arguments);
2589+
__ cmp(eax, ebx);
2590+
__ j(less, &too_few);
25912591

25922592
{ // Enough parameters: Actual >= expected.
25932593
__ bind(&enough);

src/builtins/mips/builtins-mips.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,8 @@ void Builtins::Generate_ResumeGeneratorTrampoline(MacroAssembler* masm) {
593593
// Copy the function arguments from the generator object's register file.
594594

595595
__ lw(a3, FieldMemOperand(t0, JSFunction::kSharedFunctionInfoOffset));
596-
__ lw(a3,
597-
FieldMemOperand(a3, SharedFunctionInfo::kFormalParameterCountOffset));
596+
__ lhu(a3,
597+
FieldMemOperand(a3, SharedFunctionInfo::kFormalParameterCountOffset));
598598
__ lw(t1,
599599
FieldMemOperand(a1, JSGeneratorObject::kParametersAndRegistersOffset));
600600
{
@@ -624,8 +624,8 @@ void Builtins::Generate_ResumeGeneratorTrampoline(MacroAssembler* masm) {
624624
// Resume (Ignition/TurboFan) generator object.
625625
{
626626
__ lw(a0, FieldMemOperand(t0, JSFunction::kSharedFunctionInfoOffset));
627-
__ lw(a0,
628-
FieldMemOperand(a0, SharedFunctionInfo::kFormalParameterCountOffset));
627+
__ lhu(a0, FieldMemOperand(
628+
a0, SharedFunctionInfo::kFormalParameterCountOffset));
629629
// We abuse new.target both to indicate that this is a resume call and to
630630
// pass in the generator object. In ordinary calls, new.target is always
631631
// undefined because generator functions are non-constructable.
@@ -1982,8 +1982,8 @@ void Builtins::Generate_CallOrConstructForwardVarargs(MacroAssembler* masm,
19821982
{
19831983
__ lw(t2, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
19841984
__ lw(t2, FieldMemOperand(t2, JSFunction::kSharedFunctionInfoOffset));
1985-
__ lw(t2,
1986-
FieldMemOperand(t2, SharedFunctionInfo::kFormalParameterCountOffset));
1985+
__ lhu(t2, FieldMemOperand(
1986+
t2, SharedFunctionInfo::kFormalParameterCountOffset));
19871987
__ mov(t3, fp);
19881988
}
19891989
__ Branch(&arguments_done);
@@ -2117,8 +2117,8 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm,
21172117
// -- cp : the function context.
21182118
// -----------------------------------
21192119

2120-
__ lw(a2,
2121-
FieldMemOperand(a2, SharedFunctionInfo::kFormalParameterCountOffset));
2120+
__ lhu(a2,
2121+
FieldMemOperand(a2, SharedFunctionInfo::kFormalParameterCountOffset));
21222122
ParameterCount actual(a0);
21232123
ParameterCount expected(a2);
21242124
__ InvokeFunctionCode(a1, no_reg, expected, actual, JUMP_FUNCTION);

src/builtins/mips64/builtins-mips64.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ void Builtins::Generate_ResumeGeneratorTrampoline(MacroAssembler* masm) {
486486
// values have already been copied into the context and these dummy values
487487
// will never be used.
488488
__ Ld(a3, FieldMemOperand(a4, JSFunction::kSharedFunctionInfoOffset));
489-
__ Lw(a3,
490-
FieldMemOperand(a3, SharedFunctionInfo::kFormalParameterCountOffset));
489+
__ Lhu(a3,
490+
FieldMemOperand(a3, SharedFunctionInfo::kFormalParameterCountOffset));
491491
__ Ld(t1,
492492
FieldMemOperand(a1, JSGeneratorObject::kParametersAndRegistersOffset));
493493
{
@@ -517,8 +517,8 @@ void Builtins::Generate_ResumeGeneratorTrampoline(MacroAssembler* masm) {
517517
// Resume (Ignition/TurboFan) generator object.
518518
{
519519
__ Ld(a0, FieldMemOperand(a4, JSFunction::kSharedFunctionInfoOffset));
520-
__ Lw(a0,
521-
FieldMemOperand(a0, SharedFunctionInfo::kFormalParameterCountOffset));
520+
__ Lhu(a0, FieldMemOperand(
521+
a0, SharedFunctionInfo::kFormalParameterCountOffset));
522522
// We abuse new.target both to indicate that this is a resume call and to
523523
// pass in the generator object. In ordinary calls, new.target is always
524524
// undefined because generator functions are non-constructable.
@@ -2003,8 +2003,8 @@ void Builtins::Generate_CallOrConstructForwardVarargs(MacroAssembler* masm,
20032003
{
20042004
__ Ld(a7, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
20052005
__ Ld(a7, FieldMemOperand(a7, JSFunction::kSharedFunctionInfoOffset));
2006-
__ Lw(a7,
2007-
FieldMemOperand(a7, SharedFunctionInfo::kFormalParameterCountOffset));
2006+
__ Lhu(a7, FieldMemOperand(
2007+
a7, SharedFunctionInfo::kFormalParameterCountOffset));
20082008
__ mov(a6, fp);
20092009
}
20102010
__ Branch(&arguments_done);
@@ -2138,8 +2138,8 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm,
21382138
// -- cp : the function context.
21392139
// -----------------------------------
21402140

2141-
__ Lw(a2,
2142-
FieldMemOperand(a2, SharedFunctionInfo::kFormalParameterCountOffset));
2141+
__ Lhu(a2,
2142+
FieldMemOperand(a2, SharedFunctionInfo::kFormalParameterCountOffset));
21432143
ParameterCount actual(a0);
21442144
ParameterCount expected(a2);
21452145
__ InvokeFunctionCode(a1, no_reg, expected, actual, JUMP_FUNCTION);

src/builtins/x64/builtins-x64.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@ void Builtins::Generate_ResumeGeneratorTrampoline(MacroAssembler* masm) {
607607

608608
// Copy the function arguments from the generator object's register file.
609609
__ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
610-
__ movl(rcx,
611-
FieldOperand(rcx, SharedFunctionInfo::kFormalParameterCountOffset));
610+
__ movzxwq(
611+
rcx, FieldOperand(rcx, SharedFunctionInfo::kFormalParameterCountOffset));
612612

613613
__ movp(rbx,
614614
FieldOperand(rdx, JSGeneratorObject::kParametersAndRegistersOffset));
@@ -640,7 +640,7 @@ void Builtins::Generate_ResumeGeneratorTrampoline(MacroAssembler* masm) {
640640
{
641641
__ PushReturnAddressFrom(rax);
642642
__ movp(rax, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
643-
__ movsxlq(rax, FieldOperand(
643+
__ movzxwq(rax, FieldOperand(
644644
rax, SharedFunctionInfo::kFormalParameterCountOffset));
645645
// We abuse new.target both to indicate that this is a resume call and to
646646
// pass in the generator object. In ordinary calls, new.target is always
@@ -2023,10 +2023,10 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
20232023
__ IncrementCounter(counters->arguments_adaptors(), 1);
20242024

20252025
Label enough, too_few;
2026-
__ cmpp(rax, rbx);
2027-
__ j(less, &too_few);
20282026
__ cmpp(rbx, Immediate(SharedFunctionInfo::kDontAdaptArgumentsSentinel));
20292027
__ j(equal, &dont_adapt_arguments);
2028+
__ cmpp(rax, rbx);
2029+
__ j(less, &too_few);
20302030

20312031
{ // Enough parameters: Actual >= expected.
20322032
__ bind(&enough);
@@ -2213,8 +2213,8 @@ void Builtins::Generate_CallOrConstructForwardVarargs(MacroAssembler* masm,
22132213
{
22142214
__ movp(r8, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
22152215
__ movp(r8, FieldOperand(r8, JSFunction::kSharedFunctionInfoOffset));
2216-
__ movl(r8,
2217-
FieldOperand(r8, SharedFunctionInfo::kFormalParameterCountOffset));
2216+
__ movzxwq(
2217+
r8, FieldOperand(r8, SharedFunctionInfo::kFormalParameterCountOffset));
22182218
__ movp(rbx, rbp);
22192219
}
22202220
__ jmp(&arguments_done, Label::kNear);
@@ -2354,7 +2354,7 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm,
23542354
// -- rsi : the function context.
23552355
// -----------------------------------
23562356

2357-
__ movsxlq(
2357+
__ movzxwq(
23582358
rbx, FieldOperand(rdx, SharedFunctionInfo::kFormalParameterCountOffset));
23592359
ParameterCount actual(rax);
23602360
ParameterCount expected(rbx);

0 commit comments

Comments
 (0)