Skip to content

Commit 6727511

Browse files
committed
servo: Merge #15992 - Rewrite PropertyDeclaration::id to help the optimizer (from servo:id-table); r=bholley
If I’m reading the release-mode assembly correctly, before this change `PropertyDeclaration::id` is implemented with a computed jump: ```assembly lea rcx, [rip + .LJTI117_0] movsxd rax, dword ptr [rcx + 4*rax] add rax, rcx jmp rax .LBB117_3: mov dword ptr [rdi], 65536 mov rax, rdi ret .LBB117_2: mov dword ptr [rdi], 0 mov rax, rdi ret .LBB117_4: mov dword ptr [rdi], 131072 mov rax, rdi ret .LBB117_6: mov dword ptr [rdi], 262144 mov rax, rdi ret .LBB117_7: mov dword ptr [rdi], 327680 mov rax, rdi ret ; Four similar lines repeated for each of the few hundred variants... ``` With Rust 1.15 (currently used for geckolib) this doesn’t change significantly. In Nightly 1.17 however, the compiled code uses a lookup table, possibly thanks to rust-lang/rust#39456. ```assembly movq (%rsi), %rax cmpq $171, %rax jne .LBB23_1 addq $8, %rsi movq %rsi, 8(%rdi) movb $1, %al jmp .LBB23_3 .LBB23_1: xorq $128, %rax leaq .Lswitch.table.6(%rip), %rcx movb (%rax,%rcx), %al movb %al, 1(%rdi) xorl %eax, %eax .LBB23_3: movb %al, (%rdi) movq %rdi, %rax retq ``` Source-Repo: https://github.com/servo/servo Source-Revision: 9e8e1a47241c6906b4f5777da0d04e3655982fae UltraBlame original commit: af90f70b05df8c81f440b222728ae48c2e2bf5f8
1 parent cab5a6e commit 6727511

File tree

1 file changed

+126
-35
lines changed

1 file changed

+126
-35
lines changed

servo/components/style/properties/properties.mako.rs

Lines changed: 126 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8359,6 +8359,69 @@ match
83598359
*
83608360
self
83618361
{
8362+
PropertyDeclaration
8363+
:
8364+
:
8365+
Custom
8366+
(
8367+
ref
8368+
name
8369+
_
8370+
)
8371+
=
8372+
>
8373+
{
8374+
return
8375+
PropertyDeclarationId
8376+
:
8377+
:
8378+
Custom
8379+
(
8380+
name
8381+
)
8382+
}
8383+
PropertyDeclaration
8384+
:
8385+
:
8386+
CSSWideKeyword
8387+
(
8388+
id
8389+
_
8390+
)
8391+
|
8392+
PropertyDeclaration
8393+
:
8394+
:
8395+
WithVariables
8396+
(
8397+
id
8398+
_
8399+
)
8400+
=
8401+
>
8402+
{
8403+
return
8404+
PropertyDeclarationId
8405+
:
8406+
:
8407+
Longhand
8408+
(
8409+
id
8410+
)
8411+
}
8412+
_
8413+
=
8414+
>
8415+
{
8416+
}
8417+
}
8418+
let
8419+
longhand_id
8420+
=
8421+
match
8422+
*
8423+
self
8424+
{
83628425
%
83638426
for
83648427
property
@@ -8382,11 +8445,6 @@ camel_case
83828445
=
83838446
>
83848447
{
8385-
PropertyDeclarationId
8386-
:
8387-
:
8388-
Longhand
8389-
(
83908448
LonghandId
83918449
:
83928450
:
@@ -8395,7 +8453,6 @@ property
83958453
.
83968454
camel_case
83978455
}
8398-
)
83998456
}
84008457
%
84018458
endfor
@@ -8404,57 +8461,91 @@ PropertyDeclaration
84048461
:
84058462
CSSWideKeyword
84068463
(
8407-
id
8408-
_
8409-
)
8410-
=
8411-
>
8412-
PropertyDeclarationId
8413-
:
8414-
:
8415-
Longhand
8416-
(
8417-
id
8464+
.
8465+
.
84188466
)
8467+
|
84198468
PropertyDeclaration
84208469
:
84218470
:
84228471
WithVariables
84238472
(
8424-
id
8425-
_
8426-
)
8427-
=
8428-
>
8429-
PropertyDeclarationId
8430-
:
8431-
:
8432-
Longhand
8433-
(
8434-
id
8473+
.
8474+
.
84358475
)
8476+
|
84368477
PropertyDeclaration
84378478
:
84388479
:
84398480
Custom
84408481
(
8441-
ref
8442-
name
8443-
_
8482+
.
8483+
.
84448484
)
84458485
=
84468486
>
84478487
{
8488+
debug_assert
8489+
!
8490+
(
8491+
false
8492+
"
8493+
unreachable
8494+
"
8495+
)
8496+
;
8497+
/
8498+
/
8499+
This
8500+
value
8501+
is
8502+
never
8503+
used
8504+
but
8505+
having
8506+
an
8507+
expression
8508+
of
8509+
the
8510+
same
8511+
"
8512+
shape
8513+
"
8514+
/
8515+
/
8516+
as
8517+
for
8518+
other
8519+
variants
8520+
helps
8521+
the
8522+
optimizer
8523+
compile
8524+
this
8525+
match
8526+
expression
8527+
/
8528+
/
8529+
to
8530+
a
8531+
lookup
8532+
table
8533+
.
8534+
LonghandId
8535+
:
8536+
:
8537+
BackgroundColor
8538+
}
8539+
}
8540+
;
84488541
PropertyDeclarationId
84498542
:
84508543
:
8451-
Custom
8544+
Longhand
84528545
(
8453-
name
8546+
longhand_id
84548547
)
84558548
}
8456-
}
8457-
}
84588549
fn
84598550
with_variables_from_shorthand
84608551
(

0 commit comments

Comments
 (0)