mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-12 16:57:26 +00:00
Experiment with autovectorization
This commit is contained in:
@@ -2,14 +2,14 @@ CODEC_URL := https://github.com/mozilla/mozjpeg/archive/v3.3.1.tar.gz
|
|||||||
CODEC_DIR := node_modules/mozjpeg
|
CODEC_DIR := node_modules/mozjpeg
|
||||||
CODEC_OUT_RELATIVE := .libs/libjpeg.a rdswitch.o
|
CODEC_OUT_RELATIVE := .libs/libjpeg.a rdswitch.o
|
||||||
CODEC_OUT := $(addprefix $(CODEC_DIR)/, $(CODEC_OUT_RELATIVE))
|
CODEC_OUT := $(addprefix $(CODEC_DIR)/, $(CODEC_OUT_RELATIVE))
|
||||||
OUT_JS := mozjpeg_enc.js
|
OUT_JS := mozjpeg_enc_simd.js
|
||||||
OUT_WASM := $(OUT_JS:.js=.wasm)
|
OUT_WASM := $(OUT_JS:.js=.wasm)
|
||||||
|
|
||||||
CFLAGS += -msimd128 -msse --em-config /src/.emscripten
|
CFLAGS += -msimd128 -msse --em-config /src/.emscripten
|
||||||
CXXFLAGS += -msimd128 -msse --em-config /src/.emscripten
|
CXXFLAGS += -msimd128 -msse --em-config /src/.emscripten
|
||||||
|
|
||||||
#override CFLAGS += "-msimd128 -msse"
|
#CFLAGS += --em-config /src/.emscripten
|
||||||
#override CXXFLAGS += "-msimd128 -msse"
|
#CXXFLAGS += --em-config /src/.emscripten
|
||||||
|
|
||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
|
|
||||||
@@ -28,6 +28,7 @@ all: $(OUT_JS)
|
|||||||
--closure 1 \
|
--closure 1 \
|
||||||
-s ALLOW_MEMORY_GROWTH=1 \
|
-s ALLOW_MEMORY_GROWTH=1 \
|
||||||
-s MODULARIZE=1 \
|
-s MODULARIZE=1 \
|
||||||
|
-s EXPORT_ES6=1 \
|
||||||
-s 'EXPORT_NAME="$(basename $(@F))"' \
|
-s 'EXPORT_NAME="$(basename $(@F))"' \
|
||||||
-o $@ \
|
-o $@ \
|
||||||
$+
|
$+
|
||||||
|
|||||||
62
codecs/mozjpeg_enc/bench.d8.js
Normal file
62
codecs/mozjpeg_enc/bench.d8.js
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import mozjpeg from "./mozjpeg_enc.js";
|
||||||
|
import mozjpegSimd from "./mozjpeg_enc_simd.js";
|
||||||
|
|
||||||
|
const width = 2048;
|
||||||
|
const height = 2048;
|
||||||
|
const size = width * height * 4;
|
||||||
|
const data = new Uint8ClampedArray(size);
|
||||||
|
for(let i = 0; i < size; i++) {
|
||||||
|
data[i] = Math.random() * 256;
|
||||||
|
}
|
||||||
|
|
||||||
|
mozjpeg({
|
||||||
|
onRuntimeInitialized() {
|
||||||
|
const start = performance.now();
|
||||||
|
const result = this.encode(data, width, height, {
|
||||||
|
quality: 75,
|
||||||
|
baseline: false,
|
||||||
|
arithmetic: false,
|
||||||
|
progressive: true,
|
||||||
|
optimize_coding: true,
|
||||||
|
smoothing: 0,
|
||||||
|
color_space: 3,
|
||||||
|
quant_table: 3,
|
||||||
|
trellis_multipass: false,
|
||||||
|
trellis_opt_zero: false,
|
||||||
|
trellis_opt_table: false,
|
||||||
|
trellis_loops: 1,
|
||||||
|
auto_subsample: true,
|
||||||
|
chroma_subsample: 2,
|
||||||
|
separate_chroma_quality: false,
|
||||||
|
chroma_quality: 75,
|
||||||
|
});
|
||||||
|
const end = performance.now();
|
||||||
|
console.log("No SIMD", end - start);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
mozjpegSimd({
|
||||||
|
onRuntimeInitialized() {
|
||||||
|
const start = performance.now();
|
||||||
|
const result = this.encode(data, width, height, {
|
||||||
|
quality: 75,
|
||||||
|
baseline: false,
|
||||||
|
arithmetic: false,
|
||||||
|
progressive: true,
|
||||||
|
optimize_coding: true,
|
||||||
|
smoothing: 0,
|
||||||
|
color_space: 3,
|
||||||
|
quant_table: 3,
|
||||||
|
trellis_multipass: false,
|
||||||
|
trellis_opt_zero: false,
|
||||||
|
trellis_opt_table: false,
|
||||||
|
trellis_loops: 1,
|
||||||
|
auto_subsample: true,
|
||||||
|
chroma_subsample: 2,
|
||||||
|
separate_chroma_quality: false,
|
||||||
|
chroma_quality: 75,
|
||||||
|
});
|
||||||
|
const end = performance.now();
|
||||||
|
console.log("SIMD", end - start);
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
#include <emscripten/bind.h>
|
#include <emscripten/bind.h>
|
||||||
#include <emscripten/val.h>
|
#include <emscripten/val.h>
|
||||||
#include <wasm_simd128.h>
|
|
||||||
#include <xmmintrin.h>
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
var mozjpeg_enc = (function() {
|
var mozjpeg_enc = (function() {
|
||||||
var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
|
var _scriptDir = import.meta.url;
|
||||||
if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename;
|
|
||||||
return (
|
return (
|
||||||
function(mozjpeg_enc) {
|
function(mozjpeg_enc) {
|
||||||
mozjpeg_enc = mozjpeg_enc || {};
|
mozjpeg_enc = mozjpeg_enc || {};
|
||||||
@@ -63,10 +63,4 @@ d.run=Cb;if(d.preInit)for("function"==typeof d.preInit&&(d.preInit=[d.preInit]);
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
})();
|
})();
|
||||||
if (typeof exports === 'object' && typeof module === 'object')
|
export default mozjpeg_enc;
|
||||||
module.exports = mozjpeg_enc;
|
|
||||||
else if (typeof define === 'function' && define['amd'])
|
|
||||||
define([], function() { return mozjpeg_enc; });
|
|
||||||
else if (typeof exports === 'object')
|
|
||||||
exports["mozjpeg_enc"] = mozjpeg_enc;
|
|
||||||
|
|
||||||
Binary file not shown.
Reference in New Issue
Block a user