Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7723f50

Browse filesBrowse files
committed
Build: Don't modify CMAKE_C_FLAGS_* if specified
The build system originally force-enabled the maximum optimization level (-O3) with GCC because it significantly improved the performance of the C Huffman encoder on x86 platforms. Since libjpeg-turbo 1.5.x, the Huffman encoder has been SIMD-accelerated on x86 and Arm platforms, and in my testing on various Intel CPUs, the difference between -O2 and -O3 is no longer statistically significant. However, on certain Arm CPUs, I observe that grayscale decompression slows down by 16-27% with -O2 vs. -O3. Although modern versions of CMake use -O3 as the default optimization level for Release builds, -O2 is still the default optimization level for RelWithDebInfo builds. Thus, I am reluctant to change the default behavior of our build system. However, referring to #815, some users observe better performance with -O2 vs. -O3 on other Arm CPUs, so the build system needs to allow users to override the default behavior. Closes #815
1 parent d163c99 commit 7723f50
Copy full SHA for 7723f50

1 file changed

+23-8Lines changed: 23 additions & 8 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎CMakeLists.txt‎

Copy file name to clipboardExpand all lines: CMakeLists.txt
+23-8Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ if(CMAKE_EXECUTABLE_SUFFIX)
44
set(CMAKE_EXECUTABLE_SUFFIX_TMP ${CMAKE_EXECUTABLE_SUFFIX})
55
endif()
66

7+
set(CMAKE_C_FLAGS_RELEASE_INITIALIZED_TO_DEFAULT 1)
8+
if(CMAKE_C_FLAGS_RELEASE)
9+
set(CMAKE_C_FLAGS_RELEASE_INITIALIZED_TO_DEFAULT 0)
10+
endif()
11+
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INITIALIZED_TO_DEFAULT 1)
12+
if(CMAKE_C_FLAGS_RELWITHDEBINFO)
13+
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INITIALIZED_TO_DEFAULT 0)
14+
endif()
15+
716
project(libjpeg-turbo C)
817
set(VERSION 3.1.1)
918
set(COPYRIGHT_YEAR "1991-2024")
@@ -428,22 +437,28 @@ endif()
428437

429438
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
430439
# Use the maximum optimization level for release builds
431-
foreach(var CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO)
432-
if(${var} MATCHES "-O2")
433-
string(REGEX REPLACE "-O2" "-O3" ${var} "${${var}}")
440+
foreach(build_type RELEASE RELWITHDEBINFO)
441+
if(CMAKE_C_FLAGS_${build_type} MATCHES "-O2" AND
442+
CMAKE_C_FLAGS_${build_type}_INITIALIZED_TO_DEFAULT)
443+
string(REGEX REPLACE "-O2" "-O3" CMAKE_C_FLAGS_${build_type}
444+
"${CMAKE_C_FLAGS_${build_type}}")
434445
endif()
435446
endforeach()
436447
endif()
437448

438449
if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
439450
if(CMAKE_C_COMPILER_ID MATCHES "SunPro")
440451
# Use the maximum optimization level for release builds
441-
foreach(var CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO)
442-
if(${var} MATCHES "-xO3")
443-
string(REGEX REPLACE "-xO3" "-xO5" ${var} "${${var}}")
452+
foreach(build_type RELEASE RELWITHDEBINFO)
453+
if(CMAKE_C_FLAGS_${build_type} MATCHES "-xO3" AND
454+
CMAKE_C_FLAGS_${build_type}_INITIALIZED_TO_DEFAULT)
455+
string(REGEX REPLACE "-xO3" "-xO5" CMAKE_C_FLAGS_${build_type}
456+
"${CMAKE_C_FLAGS_${build_type}}")
444457
endif()
445-
if(${var} MATCHES "-xO2")
446-
string(REGEX REPLACE "-xO2" "-xO5" ${var} "${${var}}")
458+
if(CMAKE_C_FLAGS_${build_type} MATCHES "-xO2" AND
459+
CMAKE_C_FLAGS_${build_type}_INITIALIZED_TO_DEFAULT)
460+
string(REGEX REPLACE "-xO2" "-xO5" CMAKE_C_FLAGS_${build_type}
461+
"${CMAKE_C_FLAGS_${build_type}}")
447462
endif()
448463
endforeach()
449464
endif()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.