Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG FIX] Let pngpriv.h control all architecture optimizations #613

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 26 additions & 165 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,182 +131,43 @@ endif()
if(PNG_HARDWARE_OPTIMIZATIONS)

# Set definitions and sources for ARM.
if(PNG_TARGET_ARCHITECTURE MATCHES "^(arm|aarch)")
if(PNG_TARGET_ARCHITECTURE MATCHES "^(arm64|aarch64)")
set(PNG_ARM_NEON_POSSIBLE_VALUES on off)
set(PNG_ARM_NEON "on"
CACHE STRING "Enable ARM NEON optimizations: on|off; on is default")
else()
set(PNG_ARM_NEON_POSSIBLE_VALUES check on off)
set(PNG_ARM_NEON "off"
CACHE STRING "Enable ARM NEON optimizations: check|on|off; off is default")
endif()
set_property(CACHE PNG_ARM_NEON
PROPERTY STRINGS ${PNG_ARM_NEON_POSSIBLE_VALUES})
list(FIND PNG_ARM_NEON_POSSIBLE_VALUES ${PNG_ARM_NEON} index)
if(index EQUAL -1)
message(FATAL_ERROR "PNG_ARM_NEON must be one of [${PNG_ARM_NEON_POSSIBLE_VALUES}]")
elseif(NOT PNG_ARM_NEON STREQUAL "off")
set(libpng_arm_sources
arm/arm_init.c
arm/filter_neon_intrinsics.c
arm/palette_neon_intrinsics.c)
if(PNG_ARM_NEON STREQUAL "on")
add_definitions(-DPNG_ARM_NEON_OPT=2)
elseif(PNG_ARM_NEON STREQUAL "check")
add_definitions(-DPNG_ARM_NEON_CHECK_SUPPORTED)
endif()
else()
add_definitions(-DPNG_ARM_NEON_OPT=0)
endif()
endif()
set(libpng_arm_sources
arm/arm_init.c
arm/filter_neon_intrinsics.c
arm/palette_neon_intrinsics.c)

# Set definitions and sources for PowerPC.
if(PNG_TARGET_ARCHITECTURE MATCHES "^(powerpc|ppc64)")
set(PNG_POWERPC_VSX_POSSIBLE_VALUES on off)
set(PNG_POWERPC_VSX "on"
CACHE STRING "Enable POWERPC VSX optimizations: on|off; on is default")
set_property(CACHE PNG_POWERPC_VSX
PROPERTY STRINGS ${PNG_POWERPC_VSX_POSSIBLE_VALUES})
list(FIND PNG_POWERPC_VSX_POSSIBLE_VALUES ${PNG_POWERPC_VSX} index)
if(index EQUAL -1)
message(FATAL_ERROR "PNG_POWERPC_VSX must be one of [${PNG_POWERPC_VSX_POSSIBLE_VALUES}]")
elseif(NOT PNG_POWERPC_VSX STREQUAL "off")
set(libpng_powerpc_sources
powerpc/powerpc_init.c
powerpc/filter_vsx_intrinsics.c)
if(PNG_POWERPC_VSX STREQUAL "on")
add_definitions(-DPNG_POWERPC_VSX_OPT=2)
endif()
else()
add_definitions(-DPNG_POWERPC_VSX_OPT=0)
endif()
endif()
set(libpng_powerpc_sources
powerpc/powerpc_init.c
powerpc/filter_vsx_intrinsics.c)

# Set definitions and sources for Intel.
if(PNG_TARGET_ARCHITECTURE MATCHES "^(i[3-6]86|x86|amd64)")
set(PNG_INTEL_SSE_POSSIBLE_VALUES on off)
set(PNG_INTEL_SSE "on"
CACHE STRING "Enable INTEL_SSE optimizations: on|off; on is default")
set_property(CACHE PNG_INTEL_SSE
PROPERTY STRINGS ${PNG_INTEL_SSE_POSSIBLE_VALUES})
list(FIND PNG_INTEL_SSE_POSSIBLE_VALUES ${PNG_INTEL_SSE} index)
if(index EQUAL -1)
message(FATAL_ERROR "PNG_INTEL_SSE must be one of [${PNG_INTEL_SSE_POSSIBLE_VALUES}]")
elseif(NOT PNG_INTEL_SSE STREQUAL "off")
set(libpng_intel_sources
intel/intel_init.c
intel/filter_sse2_intrinsics.c)
if(PNG_INTEL_SSE STREQUAL "on")
add_definitions(-DPNG_INTEL_SSE_OPT=1)
endif()
else()
add_definitions(-DPNG_INTEL_SSE_OPT=0)
endif()
endif()
set(libpng_intel_sources
intel/intel_init.c
intel/filter_sse2_intrinsics.c)

# Set definitions and sources for MIPS.
if(PNG_TARGET_ARCHITECTURE MATCHES "^(mipsel|mips64el)")
set(PNG_MIPS_MSA_POSSIBLE_VALUES on off)
set(PNG_MIPS_MSA "on"
CACHE STRING "Enable MIPS_MSA optimizations: on|off; on is default")
set_property(CACHE PNG_MIPS_MSA
PROPERTY STRINGS ${PNG_MIPS_MSA_POSSIBLE_VALUES})
list(FIND PNG_MIPS_MSA_POSSIBLE_VALUES ${PNG_MIPS_MSA} index_msa)
if(index_msa EQUAL -1)
message(FATAL_ERROR "PNG_MIPS_MSA must be one of [${PNG_MIPS_MSA_POSSIBLE_VALUES}]")
endif()

set(PNG_MIPS_MMI_POSSIBLE_VALUES on off)
set(PNG_MIPS_MMI "on"
CACHE STRING "Enable MIPS_MMI optimizations: on|off; on is default")
set_property(CACHE PNG_MIPS_MMI
PROPERTY STRINGS ${PNG_MIPS_MMI_POSSIBLE_VALUES})
list(FIND PNG_MIPS_MMI_POSSIBLE_VALUES ${PNG_MIPS_MMI} index_mmi)
if(index_mmi EQUAL -1)
message(FATAL_ERROR "PNG_MIPS_MMI must be one of [${PNG_MIPS_MMI_POSSIBLE_VALUES}]")
endif()

if(PNG_MIPS_MSA STREQUAL "on" AND PNG_MIPS_MMI STREQUAL "on")
set(libpng_mips_sources
mips/mips_init.c
mips/filter_msa_intrinsics.c
mips/filter_mmi_inline_assembly.c)
add_definitions(-DPNG_MIPS_MSA_OPT=2)
add_definitions(-DPNG_MIPS_MMI_OPT=1)
elseif(PNG_MIPS_MSA STREQUAL "on")
set(libpng_mips_sources
mips/mips_init.c
mips/filter_msa_intrinsics.c)
add_definitions(-DPNG_MIPS_MSA_OPT=2)
add_definitions(-DPNG_MIPS_MMI_OPT=0)
elseif(PNG_MIPS_MMI STREQUAL "on")
set(libpng_mips_sources
mips/mips_init.c
mips/filter_mmi_inline_assembly.c)
add_definitions(-DPNG_MIPS_MSA_OPT=0)
add_definitions(-DPNG_MIPS_MMI_OPT=1)
else()
add_definitions(-DPNG_MIPS_MSA_OPT=0)
add_definitions(-DPNG_MIPS_MMI_OPT=0)
endif()
endif()
set(libpng_mips_sources
mips/mips_init.c
mips/filter_msa_intrinsics.c
mips/filter_mmi_inline_assembly.c)

# Set definitions and sources for LoongArch.
if(PNG_TARGET_ARCHITECTURE MATCHES "^(loongarch)")
include(CheckCCompilerFlag)
set(PNG_LOONGARCH_LSX_POSSIBLE_VALUES on off)
set(PNG_LOONGARCH_LSX "on"
CACHE STRING "Enable LOONGARCH_LSX optimizations: on|off; on is default")
set_property(CACHE PNG_LOONGARCH_LSX
PROPERTY STRINGS ${PNG_LOONGARCH_LSX_POSSIBLE_VALUES})
list(FIND PNG_LOONGARCH_LSX_POSSIBLE_VALUES ${PNG_LOONGARCH_LSX} index)
if(index EQUAL -1)
message(FATAL_ERROR "PNG_LOONGARCH_LSX must be one of [${PNG_LOONGARCH_LSX_POSSIBLE_VALUES}]")
elseif(NOT PNG_LOONGARCH_LSX STREQUAL "off")
CHECK_C_COMPILER_FLAG("-mlsx" COMPILER_SUPPORTS_LSX)
if(COMPILER_SUPPORTS_LSX)
set(libpng_loongarch_sources
loongarch/loongarch_lsx_init.c
loongarch/filter_lsx_intrinsics.c)
set_source_files_properties(${libpng_loongarch_sources}
PROPERTIES
COMPILE_FLAGS "-mlsx")
add_definitions(-DPNG_LOONGARCH_LSX_OPT=1)
else()
message(FATAL_ERROR "Compiler does not support -mlsx option")
endif()
else()
add_definitions(-DPNG_LOONGARCH_LSX_OPT=0)
endif()
endif()
set(libpng_loongarch_sources
loongarch/loongarch_lsx_init.c
loongarch/filter_lsx_intrinsics.c)

else(PNG_HARDWARE_OPTIMIZATIONS)

# Set definitions and sources for ARM.
if(PNG_TARGET_ARCHITECTURE MATCHES "^(arm|aarch)")
add_definitions(-DPNG_ARM_NEON_OPT=0)
endif()

# Set definitions and sources for PowerPC.
if(PNG_TARGET_ARCHITECTURE MATCHES "^(powerpc|ppc64)")
add_definitions(-DPNG_POWERPC_VSX_OPT=0)
endif()

# Set definitions and sources for Intel.
if(PNG_TARGET_ARCHITECTURE MATCHES "^(i[3-6]86|x86|amd64)")
add_definitions(-DPNG_INTEL_SSE_OPT=0)
endif()

# Set definitions and sources for MIPS.
if(PNG_TARGET_ARCHITECTURE MATCHES "^(mipsel|mips64el)")
add_definitions(-DPNG_MIPS_MSA_OPT=0)
endif()

# Set definitions and sources for LoongArch.
if(PNG_TARGET_ARCHITECTURE MATCHES "^(loongarch)")
add_definitions(-DPNG_LOONGARCH_LSX_OPT=0)
endif()
# Disable opt for all arches
add_definitions(
-DPNG_ARM_NEON_OPT=0
-DPNG_POWERPC_VSX_OPT=0
-DPNG_INTEL_SSE_OPT=0
-DPNG_MIPS_MSA_OPT=0
-DPNG_MIPS_MMI_OPT=0
-DPNG_LOONGARCH_LSX_OPT=0
)

endif(PNG_HARDWARE_OPTIMIZATIONS)

Expand Down
50 changes: 8 additions & 42 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -104,44 +104,14 @@ lib_LTLIBRARIES=libpng@PNGLIB_MAJOR@@[email protected]
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = png.c pngerror.c\
pngget.c pngmem.c pngpread.c pngread.c pngrio.c pngrtran.c pngrutil.c\
pngset.c pngtrans.c pngwio.c pngwrite.c pngwtran.c pngwutil.c\
png.h pngconf.h pngdebug.h pnginfo.h pngpriv.h pngstruct.h pngusr.dfa

if PNG_ARM_NEON
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += arm/arm_init.c\
arm/filter_neon_intrinsics.c \
arm/palette_neon_intrinsics.c
endif

if PNG_MIPS_MSA
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += mips/mips_init.c\
mips/filter_msa_intrinsics.c
endif

if PNG_MIPS_MMI
if !PNG_MIPS_MSA
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += mips/mips_init.c
endif
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += mips/filter_mmi_inline_assembly.c
endif

if PNG_INTEL_SSE
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += intel/intel_init.c\
intel/filter_sse2_intrinsics.c
endif

if PNG_POWERPC_VSX
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += powerpc/powerpc_init.c\
powerpc/filter_vsx_intrinsics.c
endif

if PNG_LOONGARCH_LSX
noinst_LTLIBRARIES= libpng@PNGLIB_MAJOR@@[email protected]
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@lsx_la_SOURCES = loongarch/loongarch_lsx_init.c\
loongarch/filter_lsx_intrinsics.c
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@lsx_la_CFLAGS = -mlsx
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LIBADD = libpng@PNGLIB_MAJOR@@[email protected]
# libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_DEPENDENCIES = libpng@PNGLIB_MAJOR@@[email protected]
endif
png.h pngconf.h pngdebug.h pnginfo.h pngpriv.h pngstruct.h pngusr.dfa\
arm/arm_init.c arm/filter_neon_intrinsics.c\
arm/palette_neon_intrinsics.c\
intel/intel_init.c intel/filter_sse2_intrinsics.c\
loongarch/loongarch_lsx_init.c loongarch/filter_lsx_intrinsics.c\
mips/mips_init.c mips/filter_msa_intrinsics.c\
mips/filter_mmi_inline_assembly.c\
powerpc/powerpc_init.c powerpc/filter_vsx_intrinsics.c

nodist_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = pnglibconf.h

Expand All @@ -163,10 +133,6 @@ else
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_DEPENDENCIES = libpng.sym
endif

if PNG_LOONGARCH_LSX
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_DEPENDENCIES += libpng@PNGLIB_MAJOR@@[email protected]
endif

#distribute headers in /usr/include/libpng/*
pkgincludedir= $(includedir)/$(PNGLIB_BASENAME)
pkginclude_HEADERS= png.h pngconf.h
Expand Down
Loading