Bug 1709303 - Part 1. Prepare scripts and patches for libjpeg-turbo update. r=jrmuizel,tnikkel

media/libjpeg/1050342.diff is no longer necessary and a correction
appears to have been made in the library. Chromium no longer uses this
patch either.

media/libjpeg/assembly-tables.diff and media/libjpeg/externalize-table.diff
require significant changes in order to apply. This may be done in a
future followup patch, but is deemed less important than updating
libjpeg-turbo.

With these patches, an update to libjpeg-turbo 2.1.1 should apply
cleanly and build.

Differential Revision: https://phabricator.services.mozilla.com/D125458
This commit is contained in:
Andrew Osmond
2021-09-13 21:55:12 +00:00
parent 5493dbcfa3
commit b119cafa3f
10 changed files with 179 additions and 4287 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@@ -1,77 +0,0 @@
Bug 1050342. Fix a case where the fast huffman decoder in libjpeg-turbo can produce different results depending on how data is fed to it.
This change comes from the blink repo https://codereview.appspot.com/229430043/ and is unlikely to be accepted upstream into libjpeg-turbo.
diff --git jdhuff.c jdhuff.c
--- jdhuff.c
+++ jdhuff.c
@@ -674,9 +674,9 @@ decode_mcu_fast(j_decompress_ptr cinfo,
d_derived_tbl *dctbl = entropy->dc_cur_tbls[blkn];
d_derived_tbl *actbl = entropy->ac_cur_tbls[blkn];
register int s, k, r, l;
- HUFF_DECODE_FAST(s, l, dctbl);
+ HUFF_DECODE_FAST(s, l, dctbl, slow_decode_mcu);
if (s) {
FILL_BIT_BUFFER_FAST
r = GET_BITS(s);
s = HUFF_EXTEND(r, s);
@@ -692,9 +692,9 @@ decode_mcu_fast(j_decompress_ptr cinfo,
if (entropy->ac_needed[blkn] && block) {
for (k = 1; k < DCTSIZE2; k++) {
- HUFF_DECODE_FAST(s, l, actbl);
+ HUFF_DECODE_FAST(s, l, actbl, slow_decode_mcu);
r = s >> 4;
s &= 15;
if (s) {
@@ -711,9 +711,9 @@ decode_mcu_fast(j_decompress_ptr cinfo,
} else {
for (k = 1; k < DCTSIZE2; k++) {
- HUFF_DECODE_FAST(s, l, actbl);
+ HUFF_DECODE_FAST(s, l, actbl, slow_decode_mcu);
r = s >> 4;
s &= 15;
if (s) {
@@ -728,8 +728,9 @@ decode_mcu_fast(j_decompress_ptr cinfo,
}
}
if (cinfo->unread_marker != 0) {
+slow_decode_mcu:
cinfo->unread_marker = 0;
return FALSE;
}
diff --git jdhuff.h jdhuff.h
--- jdhuff.h
+++ jdhuff.h
@@ -210,9 +210,9 @@ slowlabel: \
get_buffer = state.get_buffer; bits_left = state.bits_left; \
} \
}
-#define HUFF_DECODE_FAST(s, nb, htbl) \
+#define HUFF_DECODE_FAST(s, nb, htbl, slowlabel) \
FILL_BIT_BUFFER_FAST; \
s = PEEK_BITS(HUFF_LOOKAHEAD); \
s = htbl->lookup[s]; \
nb = s >> HUFF_LOOKAHEAD; \
@@ -227,9 +227,11 @@ slowlabel: \
s <<= 1; \
s |= GET_BITS(1); \
nb++; \
} \
- s = htbl->pub->huffval[(int)(s + htbl->valoffset[nb]) & 0xFF]; \
+ if (nb > 16) \
+ goto slowlabel; \
+ s = htbl->pub->huffval[ (int) (s + htbl->valoffset[nb]) ]; \
}
/* Out-of-line case for Huffman code fetching */
EXTERN(int) jpeg_huff_decode(bitread_working_state *state,

View File

@@ -48,6 +48,10 @@ To upgrade to a new revision of libjpeg-turbo, do the following:
$ hg addremove
== September 9, 2021 (libjpeg-turbo v2.1.1 0a9b9721782d3a60a5c16c8c9a7abf3d4b1ecd42 2020-08-10) ==
* Updated to v2.1.1 release.
== November 19, 2020 (libjpeg-turbo v2.0.6 10ba6ed3365615ed5c2995fe2d240cb2d5000173 2020-11-16) ==
* Updated to v2.0.6 release.

View File

@@ -1,70 +0,0 @@
diff --git a/media/libjpeg/simd/i386/jchuff-sse2.asm b/media/libjpeg/simd/i386/jchuff-sse2.asm
index 6ea69f6..fea4de3 100644
--- a/media/libjpeg/simd/i386/jchuff-sse2.asm
+++ b/media/libjpeg/simd/i386/jchuff-sse2.asm
@@ -27,11 +27,10 @@
alignz 32
GLOBAL_DATA(jconst_huff_encode_one_block)
+ EXTERN EXTN(jpeg_nbits_table)
EXTN(jconst_huff_encode_one_block):
-%include "jpeg_nbits_table.inc"
-
alignz 32
; --------------------------------------------------------------------------
@@ -233,7 +232,7 @@ EXTN(jsimd_huff_encode_one_block_sse2):
; Find the number of bits needed for the magnitude of the coefficient
movpic ebp, POINTER [esp+gotptr] ; load GOT address (ebp)
- movzx edx, byte [GOTOFF(ebp, jpeg_nbits_table + ecx)] ; nbits = JPEG_NBITS(temp);
+ movzx edx, byte [GOTOFF(ebp, EXTN(jpeg_nbits_table) + ecx)] ; nbits = JPEG_NBITS(temp);
mov DWORD [esp+temp2], edx ; backup nbits in temp2
; Emit the Huffman-coded symbol for the number of bits
@@ -305,7 +304,7 @@ EXTN(jsimd_huff_encode_one_block_sse2):
.ERLOOP:
movsx eax, word [esi] ; temp = t1[k];
movpic edx, POINTER [esp+gotptr] ; load GOT address (edx)
- movzx eax, byte [GOTOFF(edx, jpeg_nbits_table + eax)] ; nbits = JPEG_NBITS(temp);
+ movzx eax, byte [GOTOFF(edx, EXTN(jpeg_nbits_table) + eax)] ; nbits = JPEG_NBITS(temp);
mov DWORD [esp+temp2], eax
; Emit Huffman symbol for run length / number of bits
shl ecx, 4 ; temp3 = (r << 4) + nbits;
diff --git a/media/libjpeg/simd/x86_64/jchuff-sse2.asm b/media/libjpeg/simd/x86_64/jchuff-sse2.asm
index 1b091ad..5ec8b1a 100644
--- a/media/libjpeg/simd/x86_64/jchuff-sse2.asm
+++ b/media/libjpeg/simd/x86_64/jchuff-sse2.asm
@@ -27,11 +27,10 @@
alignz 32
GLOBAL_DATA(jconst_huff_encode_one_block)
+ EXTERN EXTN(jpeg_nbits_table)
EXTN(jconst_huff_encode_one_block):
-%include "jpeg_nbits_table.inc"
-
alignz 32
; --------------------------------------------------------------------------
@@ -222,7 +221,7 @@ EXTN(jsimd_huff_encode_one_block_sse2):
add ebx, esi ; temp2 += temp3;
; Find the number of bits needed for the magnitude of the coefficient
- lea r11, [rel jpeg_nbits_table]
+ lea r11, [rel EXTN(jpeg_nbits_table)]
movzx rdi, byte [r11 + rdi] ; nbits = JPEG_NBITS(temp);
; Emit the Huffman-coded symbol for the number of bits
mov r11d, INT [r14 + rdi * 4] ; code = dctbl->ehufco[nbits];
@@ -289,7 +288,7 @@ EXTN(jsimd_huff_encode_one_block_sse2):
lea rsi, [rsi+r12*2] ; k += r;
shr r11, cl ; index >>= r;
movzx rdi, word [rsi] ; temp = t1[k];
- lea rbx, [rel jpeg_nbits_table]
+ lea rbx, [rel EXTN(jpeg_nbits_table)]
movzx rdi, byte [rbx + rdi] ; nbits = JPEG_NBITS(temp);
.BRLOOP:
cmp r12, 16 ; while (r > 15) {

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
/* libjpeg-turbo build number */
#define BUILD "20191231"
#define BUILD "20210810"
/* Need to use Mozilla-specific function inlining. */
#include "mozilla/Attributes.h"
@@ -9,7 +9,7 @@
#define PACKAGE_NAME "libjpeg-turbo"
/* Version number of package */
#define VERSION "2.0.4"
#define VERSION "2.1.1"
/* The size of `size_t', as computed by sizeof. */
#ifdef HAVE_64BIT_BUILD
@@ -35,3 +35,13 @@
#define HAVE_BITSCANFORWARD
#endif
#endif
#if defined(__has_attribute)
#if __has_attribute(fallthrough)
#define FALLTHROUGH __attribute__((fallthrough));
#else
#define FALLTHROUGH
#endif
#else
#define FALLTHROUGH
#endif

View File

@@ -71,24 +71,100 @@ SOURCES += [
'jctrans.c',
]
SOURCES += [
'jpeg_nbits_table.c',
]
if CONFIG['LIBJPEG_TURBO_HAVE_VLD1_S16_X3']:
DEFINES['HAVE_VLD1_S16_X3'] = True
if CONFIG['LIBJPEG_TURBO_HAVE_VLD1_U16_X2']:
DEFINES['HAVE_VLD1_U16_X2'] = True
if CONFIG['LIBJPEG_TURBO_HAVE_VLD1Q_U8_X4']:
DEFINES['HAVE_VLD1Q_U8_X4'] = True
if CONFIG['LIBJPEG_TURBO_NEON_INTRINSICS']:
DEFINES['NEON_INTRINSICS'] = True
if CONFIG['LIBJPEG_TURBO_USE_NASM']:
USE_NASM = True
if CONFIG['LIBJPEG_TURBO_ASFLAGS']:
if CONFIG['LIBJPEG_TURBO_SIMD_FLAGS']:
if CONFIG['CPU_ARCH'] == 'arm':
SOURCES += [
'simd/arm/jsimd.c',
'simd/arm/jsimd_neon.S',
LOCAL_INCLUDES += [
'/media/libjpeg/simd/arm',
'/media/libjpeg/simd/arm/aarch32',
]
SOURCES += [
'simd/arm/aarch32/jsimd.c',
]
simd_sources = [
'simd/arm/aarch32/jchuff-neon.c',
'simd/arm/jcgray-neon.c',
'simd/arm/jcphuff-neon.c',
'simd/arm/jcsample-neon.c',
'simd/arm/jdcolor-neon.c',
'simd/arm/jdmerge-neon.c',
'simd/arm/jdsample-neon.c',
'simd/arm/jfdctfst-neon.c',
'simd/arm/jfdctint-neon.c',
'simd/arm/jidctred-neon.c',
'simd/arm/jquanti-neon.c',
]
SOURCES += simd_sources
if CONFIG['LIBJPEG_TURBO_NEON_INTRINSICS']:
simd_sources_intrinsics = [
'simd/arm/jccolor-neon.c',
'simd/arm/jidctfst-neon.c',
'simd/arm/jidctint-neon.c',
]
SOURCES += simd_sources_intrinsics
simd_sources += simd_sources_intrinsics
else:
SOURCES += [
'simd/arm/aarch32/jsimd_neon.S',
]
for srcfile in simd_sources:
SOURCES[srcfile].flags += CONFIG['LIBJPEG_TURBO_SIMD_FLAGS']
elif CONFIG['CPU_ARCH'] == 'aarch64':
SOURCES += [
'simd/arm64/jsimd.c',
'simd/arm64/jsimd_neon.S',
LOCAL_INCLUDES += [
'/media/libjpeg/simd/arm',
'/media/libjpeg/simd/arm/aarch64',
]
SOURCES += [
'simd/arm/aarch64/jsimd.c',
]
simd_sources = [
'simd/arm/jcgray-neon.c',
'simd/arm/jcphuff-neon.c',
'simd/arm/jcsample-neon.c',
'simd/arm/jdmerge-neon.c',
'simd/arm/jdsample-neon.c',
'simd/arm/jfdctfst-neon.c',
'simd/arm/jidctfst-neon.c',
'simd/arm/jidctred-neon.c',
'simd/arm/jquanti-neon.c',
]
SOURCES += simd_sources
if CONFIG['LIBJPEG_TURBO_NEON_INTRINSICS']:
simd_sources_intrinsics = [
'simd/arm/aarch64/jchuff-neon.c',
'simd/arm/jccolor-neon.c',
'simd/arm/jdcolor-neon.c',
'simd/arm/jfdctint-neon.c',
'simd/arm/jidctint-neon.c',
]
SOURCES += simd_sources_intrinsics
simd_sources += simd_sources_intrinsics
else:
SOURCES += [
'simd/arm/aarch64/jsimd_neon.S',
]
for srcfile in simd_sources:
SOURCES[srcfile].flags += CONFIG['LIBJPEG_TURBO_SIMD_FLAGS']
elif CONFIG['CPU_ARCH'] == 'mips32':
SOURCES += [
'simd/mips/jsimd.c',
@@ -98,6 +174,27 @@ if CONFIG['LIBJPEG_TURBO_ASFLAGS']:
SOURCES['simd/mips/jsimd_dspr2.S'].flags += [
'-fno-integrated-as',
]
elif CONFIG['CPU_ARCH'] == 'mips64':
LOCAL_INCLUDES += ['/media/libjpeg/simd/mips64']
simd_sources = [
'simd/mips64/jccolor-mmi.c',
'simd/mips64/jcgray-mmi.c',
'simd/mips64/jcsample-mmi.c',
'simd/mips64/jdcolor-mmi.c',
'simd/mips64/jdmerge-mmi.c',
'simd/mips64/jdsample-mmi.c',
'simd/mips64/jfdctfst-mmi.c',
'simd/mips64/jfdctint-mmi.c',
'simd/mips64/jidctfst-mmi.c',
'simd/mips64/jidctint-mmi.c',
'simd/mips64/jquanti-mmi.c',
]
SOURCES += simd_sources
SOURCES += [
'simd/mips64/jsimd.c'
]
for srcfile in simd_sources:
SOURCES[srcfile].flags += CONFIG['LIBJPEG_TURBO_SIMD_FLAGS']
elif CONFIG['CPU_ARCH'] == 'x86_64':
SOURCES += [
'simd/x86_64/jccolor-avx2.asm',
@@ -209,7 +306,7 @@ else: # No SIMD support?
'jsimd_none.c',
]
ASFLAGS += CONFIG['LIBJPEG_TURBO_ASFLAGS']
ASFLAGS += CONFIG['LIBJPEG_TURBO_SIMD_FLAGS']
# Make sure the x86 & x86-64 ASM files can see the necessary includes.
if CONFIG['CPU_ARCH'] == 'x86':

View File

@@ -11,20 +11,12 @@ diff --git jmorecfg.h jmorecfg.h
/*
* Maximum number of components (color channels) allowed in JPEG image.
* To meet the letter of Rec. ITU-T T.81 | ISO/IEC 10918-1, set this to 255.
@@ -122,31 +123,17 @@ typedef char JOCTET;
@@ -95,23 +96,17 @@ typedef unsigned char JOCTET;
*/
/* UINT8 must hold at least the values 0..255. */
-#ifdef HAVE_UNSIGNED_CHAR
-typedef unsigned char UINT8;
-#else /* not HAVE_UNSIGNED_CHAR */
-#ifdef __CHAR_UNSIGNED__
-typedef char UINT8;
-#else /* not __CHAR_UNSIGNED__ */
-typedef short UINT8;
-#endif /* __CHAR_UNSIGNED__ */
-#endif /* HAVE_UNSIGNED_CHAR */
+typedef uint8_t UINT8;
/* UINT16 must hold at least the values 0..65535. */
@@ -46,7 +38,7 @@ diff --git jmorecfg.h jmorecfg.h
/* INT32 must hold at least signed 32-bit values.
*
* NOTE: The INT32 typedef dates back to libjpeg v5 (1994.) Integers were
@@ -171,17 +158,9 @@ typedef short INT16;
@@ -136,17 +131,9 @@ typedef short INT16;
* for internal use, which ensures that internal behavior will always be the
* same regardless of any external headers that may be included.
*/

View File

@@ -17,17 +17,12 @@ tag=${2-HEAD}
(cd $repo; git archive --prefix=media/libjpeg/ $tag) | (cd $srcdir/..; tar xf -)
cd $srcdir/libjpeg
cp win/jsimdcfg.inc simd/
revert_files="1050342.diff assembly-tables.diff externalize-table.diff 1520760-avx2-detection.diff jconfig.h jconfigint.h jpeg_nbits_table.c moz.build MOZCHANGES mozilla.diff simd/jsimdcfg.inc"
revert_files="jconfig.h jconfigint.h moz.build MOZCHANGES mozilla.diff"
if test -d ${topsrcdir}/.hg; then
hg revert --no-backup $revert_files
elif test -d ${topsrcdir}/.git; then
elif test -e ${topsrcdir}/.git; then
git checkout HEAD -- $revert_files
fi
patch -p0 -i mozilla.diff
patch -p0 -i 1050342.diff
patch -p3 -i externalize-table.diff
patch -p3 -i assembly-tables.diff
patch -p0 -i 1520760-avx2-detection.diff

View File

@@ -1798,12 +1798,26 @@ with only_when(compile_environment):
set_config("MOZ_JPEG_CFLAGS", jpeg_flags.cflags)
set_config("MOZ_JPEG_LIBS", jpeg_flags.ldflags)
@depends("--with-system-jpeg", target)
def in_tree_jpeg_arm(system_jpeg, target):
if system_jpeg:
return
if target.cpu == "arm":
return ("-march=armv7-a", "-mfpu=neon")
elif target.cpu == "aarch64":
return ("-march=armv8-a",)
@depends("--with-system-jpeg", target)
def in_tree_jpeg(system_jpeg, target):
if system_jpeg:
return
if target.kernel == "Darwin":
if target.cpu == "arm":
return ("-march=armv7-a", "-mfpu=neon")
elif target.cpu == "aarch64":
return ("-march=armv8-a",)
elif target.kernel == "Darwin":
if target.cpu == "x86":
return ("-DPIC", "-DMACHO")
elif target.cpu == "x86_64":
@@ -1813,12 +1827,10 @@ with only_when(compile_environment):
return ("-DPIC", "-DWIN32")
elif target.cpu == "x86_64":
return ("-D__x86_64__", "-DPIC", "-DWIN64", "-DMSVC")
elif target.cpu == "arm":
return ("-march=armv7-a", "-mfpu=neon")
elif target.cpu == "aarch64":
return ("-march=armv8-a",)
elif target.cpu == "mips32":
return ("-mdspr2",)
elif target.cpu == "mips64":
return ("-Wa,-mloongson-mmi", "-mloongson-ext")
elif target.cpu == "x86":
return ("-DPIC", "-DELF")
elif target.cpu == "x86_64":
@@ -1830,8 +1842,41 @@ with only_when(compile_environment):
# libjpeg-turbo 2.0.6 requires nasm 2.10.
return namespace(version="2.10", what="JPEG")
jpeg_arm_neon_vld1_s16_x3 = c_compiler.try_compile(
includes=["arm_neon.h"],
body="int16_t input[12] = {}; int16x4x3_t output = vld1_s16_x3(input);",
check_msg="for vld1_s16_x3 in arm_neon.h",
flags=in_tree_jpeg_arm,
when=in_tree_jpeg_arm,
)
jpeg_arm_neon_vld1_u16_x2 = c_compiler.try_compile(
includes=["arm_neon.h"],
body="uint16_t input[8] = {}; uint16x4x2_t output = vld1_u16_x2(input);",
check_msg="for vld1_u16_x2 in arm_neon.h",
flags=in_tree_jpeg_arm,
when=in_tree_jpeg_arm,
)
jpeg_arm_neon_vld1q_u8_x4 = c_compiler.try_compile(
includes=["arm_neon.h"],
body="uint8_t input[64] = {}; uint8x16x4_t output = vld1q_u8_x4(input);",
check_msg="for vld1q_u8_x4 in arm_neon.h",
flags=in_tree_jpeg_arm,
when=in_tree_jpeg_arm,
)
set_config("LIBJPEG_TURBO_USE_NASM", True, when=jpeg_nasm)
set_config("LIBJPEG_TURBO_ASFLAGS", in_tree_jpeg)
set_config("LIBJPEG_TURBO_SIMD_FLAGS", in_tree_jpeg)
set_config("LIBJPEG_TURBO_HAVE_VLD1_S16_X3", jpeg_arm_neon_vld1_s16_x3)
set_config("LIBJPEG_TURBO_HAVE_VLD1_U16_X2", jpeg_arm_neon_vld1_u16_x2)
set_config("LIBJPEG_TURBO_HAVE_VLD1Q_U8_X4", jpeg_arm_neon_vld1q_u8_x4)
set_config(
"LIBJPEG_TURBO_NEON_INTRINSICS",
jpeg_arm_neon_vld1_s16_x3
& jpeg_arm_neon_vld1_u16_x2
& jpeg_arm_neon_vld1q_u8_x4,
)
# FFmpeg's ffvpx configuration