Skip to content

Commit 86a403a

Browse files
committed
Bug 1499682 - SIMD-accelerate the data state in the HTML tokenizer. r=smaug,sergesanspaille
Other tokenizer states and the serializer are potential follow-ups. The code movement from nsHtml5Tokenizer.cpp to nsHtml5Tokeniner.h is for enabling the eventual non-unified build of nsHtml5TokenizerSIMD.cpp once the LLVM bug has been fixed. Differential Revision: https://phabricator.services.mozilla.com/D227317
1 parent 62e14be commit 86a403a

20 files changed

+5749
-4493
lines changed

build/moz.configure/toolchain.configure

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3914,6 +3914,35 @@ set_config(
39143914
),
39153915
)
39163916

3917+
3918+
@depends(target, c_compiler)
3919+
def htmlaccel_config(target, c_compiler):
3920+
# Keep this is sync with the mozilla::htmlaccel::htmlaccelEnabled function.
3921+
#
3922+
# The code compiles on SSSE3, but AVX+BMI generates better code
3923+
# and has been available for 12 years at the time of landing this,
3924+
# so let's give the best code to users with reasonably recent hardware.
3925+
#
3926+
# Not enabled on 32-bit x86, due to lack of insight into what hardware is
3927+
# representative at this point in time and due to lack of such hardware
3928+
# for testing to see what config would actually be an optimization.
3929+
#
3930+
# aarch64 does not need extra flags.
3931+
#
3932+
# clang-cl doesn't tolerate -flax-vector-conversions but GCC requires it.
3933+
#
3934+
# -mavx2 doesn't change codegen vs. -mavx. AVX2 and BMI always co-occur
3935+
# in Intel CPUs, but there are AMD CPUs that have AVX and BMI without
3936+
# AVX2.
3937+
if target.cpu != "x86_64":
3938+
return []
3939+
if c_compiler.type == "gcc":
3940+
return ["-mavx", "-mbmi", "-flax-vector-conversions"]
3941+
return ["-mavx", "-mbmi"]
3942+
3943+
3944+
set_config("HTML_ACCEL_FLAGS", htmlaccel_config)
3945+
39173946
# dtrace support
39183947
##
39193948
option("--enable-dtrace", help="Build with dtrace support")

parser/html/javasrc/Tokenizer.java

Lines changed: 260 additions & 118 deletions
Large diffs are not rendered by default.

parser/html/moz.build

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,42 @@ UNIFIED_SOURCES += [
8585
"nsParserUtils.cpp",
8686
]
8787

88+
# Each target needs to compile:
89+
# (nsHtml5TokenizerALU.cpp XOR nsHtml5TokenizerALUStubs.cpp)
90+
# AND
91+
# (nsHtml5TokenizerSIMD.cpp XOR nsHtml5TokenizerSIMDStubs.cpp)
92+
# AND
93+
# (nsHtml5TokenizerALU.cpp OR nsHtml5TokenizerSIMD.cpp)
94+
#
95+
# Make sure the result is consistent with mozilla::htmlaccel::htmlaccelEnabled().
96+
#
97+
# Due to https://github.com/llvm/llvm-project/issues/160886, none of the
98+
# code here actually ends up with SIMD instructions, and SIMD stays in
99+
# htmlaccelNotInline.cpp instead. Once the LLVM bug is fixed, the functions
100+
# in htmlaccelNotInline.cpp should becomed always inlined and
101+
# nsHtml5TokenizerSIMD.cpp should be built with HTML_ACCEL_FLAGS.
102+
103+
if (CONFIG["TARGET_CPU"] == "x86_64") and (
104+
CONFIG["CC_TYPE"] != "gcc" or int(CONFIG["CC_VERSION"].split(".")[0]) >= 12
105+
):
106+
UNIFIED_SOURCES += [
107+
"nsHtml5TokenizerALU.cpp",
108+
"nsHtml5TokenizerSIMD.cpp",
109+
]
110+
elif (
111+
CONFIG["TARGET_CPU"] == "aarch64" and CONFIG["TARGET_ENDIANNESS"] == "little"
112+
) and (CONFIG["CC_TYPE"] != "gcc" or int(CONFIG["CC_VERSION"].split(".")[0]) >= 12):
113+
# aarch64 doesn't need special flags for SIMD.
114+
UNIFIED_SOURCES += [
115+
"nsHtml5TokenizerALUStubs.cpp",
116+
"nsHtml5TokenizerSIMD.cpp",
117+
]
118+
else:
119+
UNIFIED_SOURCES += [
120+
"nsHtml5TokenizerALU.cpp",
121+
"nsHtml5TokenizerSIMDStubs.cpp",
122+
]
123+
88124
FINAL_LIBRARY = "xul"
89125

90126
LOCAL_INCLUDES += [

0 commit comments

Comments
 (0)