Skip to content

Commit 38de045

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 a998d9c commit 38de045

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
@@ -8208,6 +8208,69 @@ match
82088208
*
82098209
self
82108210
{
8211+
PropertyDeclaration
8212+
:
8213+
:
8214+
Custom
8215+
(
8216+
ref
8217+
name
8218+
_
8219+
)
8220+
=
8221+
>
8222+
{
8223+
return
8224+
PropertyDeclarationId
8225+
:
8226+
:
8227+
Custom
8228+
(
8229+
name
8230+
)
8231+
}
8232+
PropertyDeclaration
8233+
:
8234+
:
8235+
CSSWideKeyword
8236+
(
8237+
id
8238+
_
8239+
)
8240+
|
8241+
PropertyDeclaration
8242+
:
8243+
:
8244+
WithVariables
8245+
(
8246+
id
8247+
_
8248+
)
8249+
=
8250+
>
8251+
{
8252+
return
8253+
PropertyDeclarationId
8254+
:
8255+
:
8256+
Longhand
8257+
(
8258+
id
8259+
)
8260+
}
8261+
_
8262+
=
8263+
>
8264+
{
8265+
}
8266+
}
8267+
let
8268+
longhand_id
8269+
=
8270+
match
8271+
*
8272+
self
8273+
{
82118274
%
82128275
for
82138276
property
@@ -8231,11 +8294,6 @@ camel_case
82318294
=
82328295
>
82338296
{
8234-
PropertyDeclarationId
8235-
:
8236-
:
8237-
Longhand
8238-
(
82398297
LonghandId
82408298
:
82418299
:
@@ -8244,7 +8302,6 @@ property
82448302
.
82458303
camel_case
82468304
}
8247-
)
82488305
}
82498306
%
82508307
endfor
@@ -8253,57 +8310,91 @@ PropertyDeclaration
82538310
:
82548311
CSSWideKeyword
82558312
(
8256-
id
8257-
_
8258-
)
8259-
=
8260-
>
8261-
PropertyDeclarationId
8262-
:
8263-
:
8264-
Longhand
8265-
(
8266-
id
8313+
.
8314+
.
82678315
)
8316+
|
82688317
PropertyDeclaration
82698318
:
82708319
:
82718320
WithVariables
82728321
(
8273-
id
8274-
_
8275-
)
8276-
=
8277-
>
8278-
PropertyDeclarationId
8279-
:
8280-
:
8281-
Longhand
8282-
(
8283-
id
8322+
.
8323+
.
82848324
)
8325+
|
82858326
PropertyDeclaration
82868327
:
82878328
:
82888329
Custom
82898330
(
8290-
ref
8291-
name
8292-
_
8331+
.
8332+
.
82938333
)
82948334
=
82958335
>
82968336
{
8337+
debug_assert
8338+
!
8339+
(
8340+
false
8341+
"
8342+
unreachable
8343+
"
8344+
)
8345+
;
8346+
/
8347+
/
8348+
This
8349+
value
8350+
is
8351+
never
8352+
used
8353+
but
8354+
having
8355+
an
8356+
expression
8357+
of
8358+
the
8359+
same
8360+
"
8361+
shape
8362+
"
8363+
/
8364+
/
8365+
as
8366+
for
8367+
other
8368+
variants
8369+
helps
8370+
the
8371+
optimizer
8372+
compile
8373+
this
8374+
match
8375+
expression
8376+
/
8377+
/
8378+
to
8379+
a
8380+
lookup
8381+
table
8382+
.
8383+
LonghandId
8384+
:
8385+
:
8386+
BackgroundColor
8387+
}
8388+
}
8389+
;
82978390
PropertyDeclarationId
82988391
:
82998392
:
8300-
Custom
8393+
Longhand
83018394
(
8302-
name
8395+
longhand_id
83038396
)
83048397
}
8305-
}
8306-
}
83078398
fn
83088399
with_variables_from_shorthand
83098400
(

0 commit comments

Comments
 (0)