Compare commits

...

46 Commits

Author SHA1 Message Date
James Zern
0d7614fddf README.wasm: add instructions for enabling mulhi
Change-Id: I1e9dd737f06ad76f73824352291a6e129ca5ded1
2017-11-02 11:20:09 -07:00
James Zern
88692490a5 WebPMemToUint32: remove ptr cast to int
this can result in an alignment hint on arm causing a SIGBUS. casting
the input ptr to anything aside from its type is unnecessary for memcpy
and is contrary to the intent of this function.

Change-Id: I9a4d3f4be90f80cd8c3e96ccbe557e51e34cf7a5
(cherry picked from commit 04b029d236ff00a29de757b23b8787efd4a5a8f2)
2017-10-31 18:24:54 -07:00
James Zern
0af22e17d6 dec_wasm,NEON mulhi: use local vector types in cast
fixes the compile with ENABLE_NEON_BUILTIN_MULHI_INT16X8 without relying
on arm_neon.h when using __builtin_neon_vqdmulhq_v; the typedefs are
assumed to resolve to the same underlying type.

Change-Id: I8840e90d894b5045e0742030cff5e800d7d56efc
2017-10-30 20:40:48 -07:00
James Zern
08af967025 add LOCAL_CLANG_PREREQ and avoid WORK_AROUND_GCC w/3.8+
this results in a 15-20% speedup for lossy decoding on a N5/S6/CM1

BUG=webp:339

Change-Id: Icdeb84c3e0b8908147ac276b4d8f76c3d565b735
(cherry picked from commit f78da3dea6b2e02974a647122e96777667875d21)
2017-10-28 11:49:18 -07:00
James Zern
a26996116f define WEBP_USE_INTRINSICS w/gcc-4.9+
32-bit builds are neutral to slightly faster using ndk r15c on a
N5/S6/CM1

BUG=webp:339

Change-Id: I94b9442e0ceaf2f5edb2b4026bc8b99cd77c918b
(cherry picked from commit 01c426f1e7bd83e6a6f86d77f08103d1dca1f2af)
2017-10-28 11:49:18 -07:00
James Zern
5505a5b107 Android.mk,mips: fix clang build with r15
-integrated-as is now required, the opposite of r14

Change-Id: Ic478b2b3b933e66e7d159030eac29f58743eecda
(cherry picked from commit 4fbdc9fb12e515aad41adb08692c6bdbf5999bf9)
2017-10-28 11:49:18 -07:00
Scott LaVarnway
8ed24a564c wasm: replace _mulhi_int16x8() with neon builtin
BUG=webp:352

Change-Id: I5c21ee4c631fb7eccff36c7d3cd47a72badf1a89
2017-08-23 12:10:37 -07:00
James Zern
0e8c3004be fix Android standalone toolchain build
add a check for cpu-features.h and rework some of the ifdef's around
android + neon. for android builds with cpu-features enabled the
*_neon.c files will still need to be flagged correctly (with e.g.,
.c.neon in Android.mk) to properly build them.

BUG=webp:353

Change-Id: I905ce305af0a204e560b915d8665093a3edaceb9
(cherry picked from commit c6d1db4b36a3f45b55bd850589f4eefd191d4d35)
2017-08-22 12:23:25 -07:00
Scott LaVarnway
6fcc3a720d wasm: Add simple loopfilter
BUG=webp:352

Change-Id: If51454b8f54fb14ced91fa703e86e057457f454f
2017-07-28 09:04:30 -07:00
Scott LaVarnway
2371724d79 Merge "wasm: replace _mulhi_int16x8() with x86 builtin" into portable-intrinsics 2017-07-28 11:43:05 +00:00
Scott LaVarnway
9d1e151bf5 wasm: replace _mulhi_int16x8() with x86 builtin
BUG=webp:352

Change-Id: Ie51a8bb68211d7778610a818bba02e7455e47e23
2017-07-27 15:03:52 -07:00
James Zern
a1ab868427 README.wasm: add android build instructions
Change-Id: I819dc373b20b2d0255bf396de5e9b467166bb9c2
2017-07-19 12:48:29 -07:00
Scott LaVarnway
0b8ecc8cfa wasm: Rename _pack_sw_2_sb to _pack_epi16_to_epi8
BUG=webp:352

Change-Id: I67beb9297d3a37f3691779e0ad6f557f06195219
2017-07-18 13:34:21 -07:00
James Zern
c646241391 README.wasm: normalize cmake command lines
+ enable NEON for armv7

Change-Id: If914f3973391271a1817e7ff16541f3272b2ad88
2017-07-18 11:09:07 -07:00
James Zern
cfaebe3e95 dec_wasm,armv7: set ENABLE_NEON_BUILTIN_ADDSUB_SAT
this path works with -march=armv7a -mfpu=neon with clang

Change-Id: I0c04ab9a195c353aa2bfaf3ba2ca8a21e68ee5e1
2017-07-17 22:15:38 -07:00
James Zern
c0eb3ff7d4 dec_wasm,x86: define ENABLE_X86_BUILTIN_ADDSUB_SAT
this matches the behavior for aarch64

Change-Id: I243ca6cc5ffec107065a7e0dc442ee69322936ae
2017-07-15 11:54:25 -07:00
Scott LaVarnway
415b98ffad wasm: Enable neon add,sub with sat builtins
For performance testing

BUG=webp:352

Change-Id: I3fab48ee610437ac07dd603208972edf17c6f50b
2017-07-14 15:11:57 -07:00
James Zern
09bcd9a397 Merge "wasm: Replace 5 __builtin_shufflevector()" into portable-intrinsics 2017-07-11 22:57:32 +00:00
Scott LaVarnway
e83df9d208 wasm: replace #if with #ifdef
BUG=webp:352

Change-Id: Ib173e8cdb9077b385141c0e3a2f7ceb1a183b89e
2017-07-11 13:18:15 -07:00
Scott LaVarnway
3387fb6fa6 wasm: Replace 5 __builtin_shufflevector()
with _unpack*()

BUG=webp:352

Change-Id: Iea17286260afe7d242c91b02d888c5af59ab0cb7
2017-07-11 13:06:24 -07:00
Scott LaVarnway
599bddb658 Merge "wasm: cleanup _pack_sw_2_sb(), SignedShift8b()" into portable-intrinsics 2017-07-11 19:27:57 +00:00
Scott LaVarnway
28fbe808b9 Merge "wasm: Add VFilter8i and HFilter8i" into portable-intrinsics 2017-07-11 18:53:51 +00:00
Scott LaVarnway
c396e6701b wasm: cleanup _pack_sw_2_sb(), SignedShift8b()
BUG=webp:352

Change-Id: I35a36e1841f71f286fa7e032866a878b52ba56ba
2017-07-11 08:48:49 -07:00
Scott LaVarnway
96ef09107c Merge "wasm: Generic add,sub saturate" into portable-intrinsics 2017-07-10 22:52:40 +00:00
James Zern
bc01db116f Merge "add README.wasm" into portable-intrinsics 2017-07-10 22:15:16 +00:00
James Zern
d2adc08095 add README.wasm
describes how to build dwebp using portable intrinsics

BUG=webp:352

Change-Id: Ibd39dd156d6b64b52f9ade871b969a070bc9ab61
2017-07-10 22:15:00 +00:00
Scott LaVarnway
d6f90a3d83 wasm: Add VFilter8i and HFilter8i
BUG=webp:352

Change-Id: I76bac76d55ba2ac62bac479ee60291acacfc491c
2017-07-10 13:19:58 -07:00
Scott LaVarnway
cd01fc3944 wasm: Add VFilter8 and HFilter8
BUG=webp:352

Change-Id: Ic43eb5edd7e2508d2975c8f4f72cdba60c4b70f7
2017-07-10 11:54:39 -07:00
Scott LaVarnway
9a1a3aa827 wasm: Generic add,sub saturate
BUG=webp:352

Change-Id: I2640df736ea852ca5adcb5048550e26475c777ef
2017-07-10 11:46:53 -07:00
Scott LaVarnway
9eceff25c0 wasm: Add VFilter16i and HFilter16i
BUG=webp:352

Change-Id: If2cf5737d7aeab9e2d7205adfd334e3041a83c9f
2017-07-10 06:31:00 -07:00
Scott LaVarnway
fe6184d706 wasm: Add HFilter16
BUG=webp:352

Change-Id: I8f1124b36bb5769790b0e7b193acb775e8f463b1
2017-07-07 10:52:48 -07:00
James Zern
cb6c3a2a36 cosmetics,dec_wasm: constify function params
Change-Id: I10f2f612b553dc2c8282f4a7d4176f645aba97c9
2017-07-06 23:23:58 -07:00
James Zern
ec666c7526 cmake: split gif detection from IMG deps
gifdec isn't part of imageio lib, it's only used by gif2webp.

Change-Id: I70bff378a32f8fb2ebb8a5a7701049ffff7f7992
(cherry picked from commit dcbc1c881a001f45081834a47391d673c1b96907)
2017-07-07 04:11:49 +00:00
Scott LaVarnway
bafa90ccd8 wasm: Add VFilter16
BUG=webp:352

Change-Id: I97f38aee5de063957c1512f6bd429c0e84c02087
2017-07-06 11:21:53 -07:00
Scott LaVarnway
e6e3ec335c wasm: Add Truemotion
BUG=webp:352

Change-Id: Ie65e155ac2d8253a5706ee85e830ec220a12ab4b
2017-07-05 15:56:01 -07:00
Scott LaVarnway
168a3a9e28 Merge "wasm: Add Transform" into portable-intrinsics 2017-07-05 19:50:31 +00:00
Scott LaVarnway
ad4ca27449 wasm: Add Transform
BUG=webp:352

Change-Id: Ib119b4121c6fd1a5165088dd132b4ab2aca627a5
2017-07-05 12:16:05 -07:00
Scott LaVarnway
3a5528713b wasm: Add VR4, LD4, and VL4
BUG=webp:352

Change-Id: I28ec852da8aef65b7f3c372c08be5c6bf68256be
2017-07-03 05:36:24 -07:00
Scott LaVarnway
b4cefba731 wasm: Add VE4 and RD4
BUG=webp:352

Change-Id: I24286685d7c002ec55534a98bcb88ecd82562f79
2017-06-30 11:08:43 -07:00
Scott LaVarnway
440945ca57 wasm: Add DC8uv*, VE8uv, and HE8uv functions
BUG=webp:352

Change-Id: Ia0b2b0d5007c12fff201ac94673312420da42a53
2017-06-30 02:14:12 +00:00
Scott LaVarnway
a37a7b00d5 wasm: Add DC16*, VE16, and HE16 functions
BUG=webp:352

Change-Id: Ia003257d00c2c2ea16a6e6344671237e78c0eac6
2017-06-29 21:48:14 +00:00
James Zern
a604ab5600 cpu.cmake: skip simd disable flag check w/wasm
this workarounds an ICE with clang. WASM overrides the native simd so
apart from binary size building it isn't an issue.

BUG=webp:350

Change-Id: Ib0195049249e6cb86d3225ce5db7247ac22cdbd6
2017-06-28 19:34:24 -07:00
James Zern
b005d916f8 dsp/cpu: correct wasmCPUInfo placement
WASM needs to precede platform specific architecture checks as the
defines will still be present when building this target.

Change-Id: I823f4922829561ea298c6837068b79bf9f1aee1b
2017-06-26 16:05:51 -07:00
James Zern
586eda373d Revert "dsp/cpu: correct wasmCPUInfo placement"
This reverts commit 4026e34e3f2edaf4b61824e06994527e45d2b6d8.

fails to build; not all x86 paths were protected

Change-Id: I27bcc83e74440205bfd99c31c6da319c205ef145
2017-06-26 15:49:20 -07:00
James Zern
4026e34e3f dsp/cpu: correct wasmCPUInfo placement
WASM needs to precede platform specific architecture checks as the
defines will still be present when building this target.

Change-Id: If25467ea286e582b928e26e716e41aff72898c50
2017-06-26 12:12:46 -07:00
James Zern
4b21971337 add dec_wasm.c
stub + basic cmake support for targeting native code generation using
portable intrinsics / wasm (WebAssembly). integrating this into the
webp_js path will be left until the implementation is more complete.

Change-Id: I3e751b511f6d671da5ba8afc88ca412f31f097b0
2017-06-22 23:21:31 -07:00
15 changed files with 1823 additions and 29 deletions

View File

@ -15,8 +15,11 @@ endif
# https://bugs.chromium.org/p/webp/issues/detail?id=343
ifeq ($(findstring clang,$(NDK_TOOLCHAIN_VERSION)),clang)
ifeq ($(TARGET_ARCH),mips)
clang_version := $(shell $(TARGET_CC) --version)
ifneq ($(findstring clang version 3,$(clang_version)),)
WEBP_CFLAGS += -no-integrated-as
endif
endif
endif
ifneq ($(findstring armeabi-v7a, $(TARGET_ARCH_ABI)),)
@ -25,6 +28,7 @@ ifneq ($(findstring armeabi-v7a, $(TARGET_ARCH_ABI)),)
# specifically.
NEON := c.neon
USE_CPUFEATURES := yes
WEBP_CFLAGS += -DHAVE_CPU_FEATURES_H
else
NEON := c
endif

View File

@ -4,6 +4,7 @@ project(libwebp C)
# Options for coder / decoder executables.
option(WEBP_ENABLE_SIMD "Enable any SIMD optimization." ON)
option(WEBP_ENABLE_WASM "Enable WebAssembly optimizations." OFF)
option(WEBP_BUILD_CWEBP "Build the cwebp command line tool." OFF)
option(WEBP_BUILD_DWEBP "Build the dwebp command line tool." OFF)
option(WEBP_BUILD_GIF2WEBP "Build the gif2webp conversion tool." OFF)
@ -13,7 +14,7 @@ option(WEBP_BUILD_WEBP_JS "Emscripten build of webp.js." OFF)
option(WEBP_EXPERIMENTAL_FEATURES "Build with experimental features." OFF)
option(WEBP_ENABLE_SWAP_16BIT_CSP "Enable byte swap for 16 bit colorspaces." OFF)
if(WEBP_BUILD_WEBP_JS)
if(WEBP_BUILD_WEBP_JS OR WEBP_ENABLE_WASM)
set(WEBP_ENABLE_SIMD OFF)
endif()
@ -37,6 +38,9 @@ string(REGEX MATCH "[0-9.]+" WEBP_VERSION ${SOURCE_FILE})
if(WEBP_ENABLE_SWAP_16BIT_CSP)
add_definitions(-DWEBP_SWAP_16BIT_CSP)
endif()
if(WEBP_ENABLE_WASM)
add_definitions(-DWEBP_USE_WASM)
endif()
################################################################################
# Android only.
@ -50,6 +54,7 @@ if(ANDROID)
set(WEBP_DEP_INCLUDE_DIRS ${WEBP_DEP_INCLUDE_DIRS}
${ANDROID_NDK}/sources/android/cpufeatures
)
add_definitions(-DHAVE_CPU_FEATURES_H)
endif()
################################################################################
@ -162,9 +167,11 @@ math(EXPR WEBP_SIMD_FILES_TO_INCLUDE_RANGE
foreach(I_FILE RANGE ${WEBP_SIMD_FILES_TO_INCLUDE_RANGE})
list(GET WEBP_SIMD_FILES_TO_INCLUDE ${I_FILE} FILE)
list(GET WEBP_SIMD_FLAGS_TO_INCLUDE ${I_FILE} SIMD_COMPILE_FLAG)
if(NOT ${SIMD_COMPILE_FLAG} STREQUAL "NOTFOUND")
set_source_files_properties(${FILE} PROPERTIES
COMPILE_FLAGS ${SIMD_COMPILE_FLAG}
)
endif()
endforeach()
# Build the executables if asked for.
@ -228,12 +235,12 @@ endif()
if(WEBP_BUILD_GIF2WEBP)
# gif2webp
include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS})
include_directories(${WEBP_DEP_GIF_INCLUDE_DIRS})
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "GIF2WEBP_SRCS"
"gif2webp")
add_executable(gif2webp ${GIF2WEBP_SRCS})
target_link_libraries(gif2webp exampleutil imageioutil webp webpmux
${WEBP_DEP_IMG_LIBRARIES})
${WEBP_DEP_GIF_LIBRARIES})
install(TARGETS gif2webp RUNTIME DESTINATION bin)
endif()

91
README.wasm Normal file
View File

@ -0,0 +1,91 @@
Description:
============
This file describes the compilation of libwebp using portable intrinsics /
WebAssembly (wasm) to native targets using clang and CMake.
Prerequisites:
==============
- cmake 2.8+
- clang 3.9+ for portable intrinsics support; as wasm progresses a tip of tree
build may be necessary.
Building:
=========
- configure the project with CMake using:
$ mkdir -p build && \
cd build && \
cmake -DWEBP_BUILD_DWEBP=1 -DCMAKE_C_COMPILER=clang -DWEBP_ENABLE_WASM=1 ../
- compile dwebp using 'make'.
- Note this currently generates native executables only and is incompatible
with -DWEBP_BUILD_WEBP_JS.
Build options:
==============
- platform specific multiply high (mulhi) implementation, disabled by default.
arm: -DCMAKE_C_FLAGS='-DENABLE_NEON_BUILTIN_MULHI_INT16X8 ...'
x86: -DCMAKE_C_FLAGS='-DENABLE_X86_BUILTIN_MULHI_INT16X8 ...'
Cross compilation:
==================
- arm toolchains can be obtained from:
http://www.linaro.org/downloads/
- the android ndk can be obtained from:
https://developer.android.com/ndk/downloads/index.html
armv7:
------
Android:
$ ./android-ndk-r15b/build/tools/make_standalone_toolchain.py \
--arch arm --api 24 --stl gnustl --install-dir /opt/android-arm-24
$ mkdir -p build && cd build
$ cmake ../libwebp \
-DWEBP_BUILD_DWEBP=1 \
-DCMAKE_C_COMPILER=/opt/android-arm-24/bin/clang \
-DCMAKE_PREFIX_PATH=/opt/android-arm-24/sysroot/usr/lib \
-DCMAKE_C_FLAGS=-fPIE \
-DCMAKE_EXE_LINKER_FLAGS=-Wl,-pie \
-DCMAKE_BUILD_TYPE=Release \
-DWEBP_ENABLE_WASM=1
Linux:
$ gcc_arm=/opt/gcc-arm; target=arm-linux-gnueabihf
$ mkdir -p build && cd build
$ cmake ../libwebp -DWEBP_BUILD_DWEBP=1 -DWEBP_ENABLE_WASM=1 \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_C_FLAGS="--target=$target --gcc-toolchain=$gcc_arm --sysroot=$gcc_arm/$target/libc -march=armv7-a -mfpu=neon" \
-DCMAKE_PREFIX_PATH=$gcc_arm/$target/libc/usr
aarch64 / arm64:
----------------
Android:
$ ./android-ndk-r15b/build/tools/make_standalone_toolchain.py \
--arch arm64 --api 24 --stl gnustl --install-dir /opt/android-arm64-24
$ mkdir -p build && cd build
$ cmake ../libwebp \
-DWEBP_BUILD_DWEBP=1 \
-DCMAKE_C_COMPILER=/opt/android-arm64-24/bin/clang \
-DCMAKE_PREFIX_PATH=/opt/android-arm64-24/sysroot/usr/lib \
-DCMAKE_C_FLAGS=-fPIE \
-DCMAKE_EXE_LINKER_FLAGS=-Wl,-pie \
-DCMAKE_BUILD_TYPE=Release \
-DWEBP_ENABLE_WASM=1
Linux:
$ gcc_arm=/opt/gcc-aarch64; target=aarch64-linux-gnu
$ mkdir -p build && cd build
$ cmake ../libwebp -DWEBP_BUILD_DWEBP=1 -DWEBP_ENABLE_WASM=1 \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_C_FLAGS="--target=$target --gcc-toolchain=$gcc_arm --sysroot=$gcc_arm/$target/libc" \
-DCMAKE_PREFIX_PATH=$gcc_arm/$target/libc/usr

View File

@ -31,6 +31,11 @@ using Emscripten and CMake.
- that's it! Upon completion, you should have the webp.js and
webp.js.mem files generated.
- Note this generates both webp_js and webp_wasm without any SIMD enabled due
to bugs with this toolchain associated with the SSE2 code.
-DWEBP_ENABLE_WASM is currently meant to generate native (x86, arm)
executables (dwebp, cwebp) and is incompatible with -DWEBP_BUILD_WEBP_JS.
The callable JavaScript function is WebPToSDL(), which decodes a raw WebP
bitstream into a canvas. See webp_js/index.html for a simple usage sample.

View File

@ -84,6 +84,7 @@ model {
// Check for NEON usage.
if (getTargetPlatform() == "arm" || getTargetPlatform() == "arm64") {
NEON = "c.neon"
cCompiler.define "HAVE_CPU_FEATURES_H"
} else {
NEON = "c"
}

View File

@ -65,7 +65,7 @@ endif()
# Find the standard image libraries.
set(WEBP_DEP_IMG_LIBRARIES)
set(WEBP_DEP_IMG_INCLUDE_DIRS)
foreach(I_LIB PNG JPEG TIFF GIF)
foreach(I_LIB PNG JPEG TIFF)
find_package(${I_LIB})
set(WEBP_HAVE_${I_LIB} ${${I_LIB}_FOUND})
if(${I_LIB}_FOUND)
@ -74,6 +74,16 @@ foreach(I_LIB PNG JPEG TIFF GIF)
endif()
endforeach()
# GIF detection, gifdec isn't part of the imageio lib.
set(WEBP_DEP_GIF_LIBRARIES)
set(WEBP_DEP_GIF_INCLUDE_DIRS)
find_package(GIF)
set(WEBP_HAVE_GIF ${GIF_FOUND})
if(GIF_FOUND)
list(APPEND WEBP_DEP_GIF_LIBRARIES ${GIF_LIBRARIES})
list(APPEND WEBP_DEP_GIF_INCLUDE_DIRS ${GIF_INCLUDE_DIR})
endif()
## Check for specific headers.
include(CheckIncludeFiles)
check_include_files("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)

View File

@ -85,8 +85,11 @@ foreach(I_SIMD RANGE ${WEBP_SIMD_FLAGS_RANGE})
foreach(FILE ${SIMD_FILES})
list(APPEND WEBP_SIMD_FILES_NOT_TO_INCLUDE ${FILE})
endforeach()
# Explicitly disable SIMD.
if(SIMD_DISABLE_FLAGS)
# Explicitly disable SIMD. Avoid this with WASM to avoid an ICE with clang:
# https://bugs.chromium.org/p/webp/issues/detail?id=350
# WASM overrides the native SIMD so building it in is harmless aside from
# binary size.
if(NOT WEBP_ENABLE_WASM AND SIMD_DISABLE_FLAGS)
list(GET SIMD_DISABLE_FLAGS ${I_SIMD} SIMD_COMPILE_FLAG)
include(CheckCCompilerFlag)
if(SIMD_COMPILE_FLAG)
@ -116,3 +119,13 @@ foreach(I_SIMD RANGE ${WEBP_SIMD_FLAGS_RANGE})
endif()
endif()
endforeach()
## Add *_wasm.c files if enabled.
if(WEBP_ENABLE_WASM)
file(GLOB SIMD_FILES "${CMAKE_CURRENT_LIST_DIR}/../"
"src/dsp/*_wasm.c"
)
foreach(FILE ${SIMD_FILES})
list(APPEND WEBP_SIMD_FILES_TO_INCLUDE ${FILE})
endforeach()
endif()

View File

@ -243,6 +243,10 @@ AS_IF([test "x$enable_neon" != "xno"], [
NEON_FLAGS=""],
[AC_DEFINE(WEBP_HAVE_NEON_RTCD, [1],
[Set to 1 if runtime detection of NEON is enabled])])])
case "$host_os" in
*android*) AC_CHECK_HEADERS([cpu-features.h]) ;;
esac
;;
esac
AC_SUBST([NEON_FLAGS])])

View File

@ -3,6 +3,7 @@ noinst_LTLIBRARIES += libwebpdsp_sse2.la libwebpdspdecode_sse2.la
noinst_LTLIBRARIES += libwebpdsp_sse41.la libwebpdspdecode_sse41.la
noinst_LTLIBRARIES += libwebpdsp_neon.la libwebpdspdecode_neon.la
noinst_LTLIBRARIES += libwebpdsp_msa.la libwebpdspdecode_msa.la
noinst_LTLIBRARIES += libwebpdspdecode_wasm.la
if BUILD_LIBWEBPDECODER
noinst_LTLIBRARIES += libwebpdspdecode.la
@ -96,6 +97,10 @@ libwebpdspdecode_msa_la_SOURCES += upsampling_msa.c
libwebpdspdecode_msa_la_CPPFLAGS = $(libwebpdsp_msa_la_CPPFLAGS)
libwebpdspdecode_msa_la_CFLAGS = $(libwebpdsp_msa_la_CFLAGS)
# WASM is not fully integrated into configure; the addition here keeps source
# extraction by cmake simple.
libwebpdspdecode_wasm_la_SOURCES = dec_wasm.c
libwebpdsp_sse2_la_SOURCES =
libwebpdsp_sse2_la_SOURCES += argb_sse2.c
libwebpdsp_sse2_la_SOURCES += cost_sse2.c

View File

@ -23,11 +23,13 @@
#endif
//------------------------------------------------------------------------------
// SSE2 detection.
// x86/x86-64 micro-arch detection.
//
// skip x86 specific code for WASM builds
#if defined(WEBP_USE_WASM)
// apple/darwin gcc-4.0.1 defines __PIC__, but not __pic__ with -fPIC.
#if (defined(__pic__) || defined(__PIC__)) && defined(__i386__)
#elif (defined(__pic__) || defined(__PIC__)) && defined(__i386__)
static WEBP_INLINE void GetCPUInfo(int cpu_info[4], int info_type) {
__asm__ volatile (
"mov %%ebx, %%edi\n"
@ -63,8 +65,10 @@ static WEBP_INLINE void GetCPUInfo(int cpu_info[4], int info_type) {
#define GetCPUInfo __cpuid
#endif
// skip xgetbv definition for WASM builds
#if defined(WEBP_USE_WASM)
// NaCl has no support for xgetbv or the raw opcode.
#if !defined(__native_client__) && (defined(__i386__) || defined(__x86_64__))
#elif !defined(__native_client__) && (defined(__i386__) || defined(__x86_64__))
static WEBP_INLINE uint64_t xgetbv(void) {
const uint32_t ecx = 0;
uint32_t eax, edx;
@ -94,7 +98,19 @@ static WEBP_INLINE uint64_t xgetbv(void) {
#define xgetbv() 0U // no AVX for older x64 or unrecognized toolchains.
#endif
#if defined(__i386__) || defined(__x86_64__) || defined(WEBP_MSC_SSE2)
//------------------------------------------------------------------------------
// Platform specific VP8CPUInfo functions.
//
// WASM needs to precede platform specific architecture checks as the defines
// will still be present when building this target.
#if defined(WEBP_USE_WASM)
static int wasmCPUInfo(CPUFeature feature) {
if (feature != kWASM) return 0;
return 1;
}
VP8CPUInfo VP8GetCPUInfo = wasmCPUInfo;
#elif defined(__i386__) || defined(__x86_64__) || defined(WEBP_MSC_SSE2)
// helper function for run-time detection of slow SSSE3 platforms
static int CheckSlowModel(int info) {

View File

@ -700,6 +700,7 @@ extern void VP8DspInitNEON(void);
extern void VP8DspInitMIPS32(void);
extern void VP8DspInitMIPSdspR2(void);
extern void VP8DspInitMSA(void);
extern void VP8DspInitWASM(void);
static volatile VP8CPUInfo dec_last_cpuinfo_used =
(VP8CPUInfo)&dec_last_cpuinfo_used;
@ -789,6 +790,11 @@ WEBP_TSAN_IGNORE_FUNCTION void VP8DspInit(void) {
if (VP8GetCPUInfo(kMSA)) {
VP8DspInitMSA();
}
#endif
#if defined(WEBP_USE_WASM)
if (VP8GetCPUInfo(kWASM)) {
VP8DspInitWASM();
}
#endif
}
dec_last_cpuinfo_used = VP8GetCPUInfo;

1618
src/dsp/dec_wasm.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -38,12 +38,22 @@ extern "C" {
# define LOCAL_GCC_PREREQ(maj, min) 0
#endif
#if defined(__clang__)
# define LOCAL_CLANG_VERSION ((__clang_major__ << 8) | __clang_minor__)
# define LOCAL_CLANG_PREREQ(maj, min) \
(LOCAL_CLANG_VERSION >= (((maj) << 8) | (min)))
#else
# define LOCAL_CLANG_VERSION 0
# define LOCAL_CLANG_PREREQ(maj, min) 0
#endif
#ifndef __has_builtin
# define __has_builtin(x) 0
#endif
// for now, none of the optimizations below are available in emscripten
#if !defined(EMSCRIPTEN)
// For now, none of the optimizations below are available in emscripten.
// WebAssembly overrides native optimizations.
#if !(defined(EMSCRIPTEN) || defined(WEBP_USE_WASM))
#if defined(_MSC_VER) && _MSC_VER > 1310 && \
(defined(_M_X64) || defined(_M_IX86))
@ -71,18 +81,20 @@ extern "C" {
#define WEBP_USE_AVX2
#endif
#if defined(__ANDROID__) && defined(__ARM_ARCH_7A__)
#define WEBP_ANDROID_NEON // Android targets that might support NEON
#endif
// The intrinsics currently cause compiler errors with arm-nacl-gcc and the
// inline assembly would need to be modified for use with Native Client.
#if (defined(__ARM_NEON__) || defined(WEBP_ANDROID_NEON) || \
#if (defined(__ARM_NEON__) || \
defined(__aarch64__) || defined(WEBP_HAVE_NEON)) && \
!defined(__native_client__)
#define WEBP_USE_NEON
#endif
#if !defined(WEBP_USE_NEON) && defined(__ANDROID__) && \
defined(__ARM_ARCH_7A__) && defined(HAVE_CPU_FEATURES_H)
#define WEBP_ANDROID_NEON // Android targets that may have NEON
#define WEBP_USE_NEON
#endif
#if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_M_ARM)
#define WEBP_USE_NEON
#define WEBP_USE_INTRINSICS
@ -144,7 +156,8 @@ typedef enum {
kNEON,
kMIPS32,
kMIPSdspR2,
kMSA
kMSA,
kWASM
} CPUFeature;
// returns true if the CPU supports the feature.
typedef int (*VP8CPUInfo)(CPUFeature feature);

View File

@ -17,8 +17,9 @@
#include "./dsp.h"
// Right now, some intrinsics functions seem slower, so we disable them
// everywhere except aarch64 where the inline assembly is incompatible.
#if defined(__aarch64__)
// everywhere except newer clang/gcc or aarch64 where the inline assembly is
// incompatible.
#if LOCAL_CLANG_PREREQ(3,8) || LOCAL_GCC_PREREQ(4,9) || defined(__aarch64__)
#define WEBP_USE_INTRINSICS // use intrinsics when possible
#endif
@ -43,7 +44,7 @@
// if using intrinsics, this flag avoids some functions that make gcc-4.6.3
// crash ("internal compiler error: in immed_double_const, at emit-rtl.").
// (probably similar to gcc.gnu.org/bugzilla/show_bug.cgi?id=48183)
#if !(LOCAL_GCC_PREREQ(4,8) || defined(__aarch64__))
#if !(LOCAL_CLANG_PREREQ(3,8) || LOCAL_GCC_PREREQ(4,8) || defined(__aarch64__))
#define WORK_AROUND_GCC
#endif

View File

@ -66,7 +66,7 @@ WEBP_EXTERN(void) WebPSafeFree(void* const ptr);
// memcpy() is the safe way of moving potentially unaligned 32b memory.
static WEBP_INLINE uint32_t WebPMemToUint32(const uint8_t* const ptr) {
uint32_t A;
memcpy(&A, (const int*)ptr, sizeof(A));
memcpy(&A, ptr, sizeof(A));
return A;
}
static WEBP_INLINE void WebPUint32ToMem(uint8_t* const ptr, uint32_t val) {