Skip to content

Commit

Permalink
Set the stack alignment to 64 bytes for x86 microkernel builds.
Browse files Browse the repository at this point in the history
This makes register spilling a _lot_ faster in some cases.

PiperOrigin-RevId: 719315622
  • Loading branch information
gonnet authored and xnnpack-bot committed Jan 24, 2025
1 parent a108468 commit dc1f822
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,13 @@ IF(XNNPACK_TARGET_PROCESSOR MATCHES "^x86(_64)?$")
SET_PROPERTY(SOURCE ${ALL_AVX512AMX_MICROKERNEL_SRCS} APPEND_STRING PROPERTY COMPILE_FLAGS " -clang:-mf16c -clang:-mfma -clang:-mavx512f -clang:-mavx512cd -clang:-mavx512bw -clang:-mavx512dq -clang:-mavx512vl -clang:-mavx512vnni -clang:-mgfni -clang:-mamx-tile -clang:-mamx-int8 ")
ENDIF()
ELSE()
IF(CMAKE_C_COMPILER_ID STREQUAL "GNU")
SET_PROPERTY(SOURCE ${ALL_MICROKERNEL_SRCS} APPEND_STRING PROPERTY COMPILE_FLAGS " -mpreferred-stack-boundary=6 -fomit-frame-pointer ")
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "Clang")
SET_PROPERTY(SOURCE ${ALL_MICROKERNEL_SRCS} APPEND_STRING PROPERTY COMPILE_FLAGS " -mstack-alignment=64 -fomit-frame-pointer ")
ELSE()
SET_PROPERTY(SOURCE ${ALL_MICROKERNEL_SRCS} APPEND_STRING PROPERTY COMPILE_FLAGS " -fomit-frame-pointer ")
ENDIF()
SET_PROPERTY(SOURCE ${ALL_SSE_MICROKERNEL_SRCS} APPEND_STRING PROPERTY COMPILE_FLAGS " -msse -mno-sse2 ")
SET_PROPERTY(SOURCE ${ALL_SSE2_MICROKERNEL_SRCS} APPEND_STRING PROPERTY COMPILE_FLAGS " -msse2 -mno-sse3 ")
SET_PROPERTY(SOURCE ${ALL_SSSE3_MICROKERNEL_SRCS} APPEND_STRING PROPERTY COMPILE_FLAGS " -mssse3 -mno-sse4.1 ")
Expand Down
30 changes: 30 additions & 0 deletions build_config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,20 @@ config_setting(
},
)

config_setting(
name = "clang",
flag_values = {
"@bazel_tools//tools/cpp:compiler": "clang",
},
)

config_setting(
name = "gcc",
flag_values = {
"@bazel_tools//tools/cpp:compiler": "gcc",
},
)

######################## Composite build configurations #######################

selects.config_setting_group(
Expand Down Expand Up @@ -334,3 +348,19 @@ selects.config_setting_group(
name = "riscv",
match_any = [":linux_riscv64"],
)

selects.config_setting_group(
name = "x86_clang",
match_all = = [
":x86",
":clang",
],
)

selects.config_setting_group(
name = "x86_gcc",
match_all = = [
":x86",
":gcc",
],
)
11 changes: 11 additions & 0 deletions build_params.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ def xnnpack_cc_library_for_arch(arch, name, deps = None, **kwargs):
else:
kwargs[key] = val

# Add extra copts.
copts = select({
"//build_config:x86_clang": ["-mstack-algiment=64", "-fomit-frame-pointer"],
"//build_config:x86_gcc": ["-mpreferred-stack-boundary=6", "-fomit-frame-pointer"],
"//conditions:default": [],
})
if "copts" in kwargs:
kwargs["copts"] += copts
else:
kwargs["copts"] = copts

xnnpack_cc_library(
name = name,
target_compatible_with = xnnpack_select_if(
Expand Down

0 comments on commit dc1f822

Please sign in to comment.