Bug 1379663 - Update libjpeg-turbo to version 1.5.2. r=jrmuizel
authorRyan VanderMeulen <ryanvm@gmail.com>
Thu, 13 Jul 2017 20:12:47 -0400
changeset 368970 7534510da000dfe1017ca66e3148ccb6153c6831
parent 368969 aaa4ae876a53ff08bb58ffcfa9cb1989e3c0623e
child 368971 ba31bf7e9dc7d3a462eb60b603cc31972b5a2b13
push id32179
push userkwierso@gmail.com
push dateSat, 15 Jul 2017 00:14:54 +0000
treeherdermozilla-central@bd1b6a4e5d8e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1379663
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1379663 - Update libjpeg-turbo to version 1.5.2. r=jrmuizel
media/libjpeg/LICENSE.md
media/libjpeg/README.md
media/libjpeg/jconfig.h
media/libjpeg/jconfigint.h
media/libjpeg/jdarith.c
media/libjpeg/jmemmgr.c
media/libjpeg/jmemnobs.c
media/libjpeg/jversion.h
media/libjpeg/mozilla.diff
media/libjpeg/simd/jchuff-sse2.asm
media/libjpeg/simd/jsimd_arm.c
media/libjpeg/simd/jsimd_arm64.c
media/libjpeg/simd/jsimd_mips.c
media/libjpeg/simd/jsimd_powerpc.c
--- a/media/libjpeg/LICENSE.md
+++ b/media/libjpeg/LICENSE.md
@@ -4,22 +4,21 @@ libjpeg-turbo Licenses
 libjpeg-turbo is covered by three compatible BSD-style open source licenses:
 
 - The IJG (Independent JPEG Group) License, which is listed in
   [README.ijg](README.ijg)
 
   This license applies to the libjpeg API library and associated programs
   (any code inherited from libjpeg, and any modifications to that code.)
 
-- The Modified (3-clause) BSD License, which is listed in
-  [turbojpeg.c](turbojpeg.c)
+- The Modified (3-clause) BSD License, which is listed below
 
   This license covers the TurboJPEG API library and associated programs.
 
-- The zlib License, which is listed in [simd/jsimdext.inc](simd/jsimdext.inc)
+- The zlib License, which is listed below
 
   This license is a subset of the other two, and it covers the libjpeg-turbo
   SIMD extensions.
 
 
 Complying with the libjpeg-turbo Licenses
 =========================================
 
@@ -81,8 +80,60 @@ 3.  You cannot use the name of the IJG o
 4.  The IJG and The libjpeg-turbo Project do not warrant libjpeg-turbo to be
     free of defects, nor do we accept any liability for undesirable
     consequences resulting from your use of the software.
 
     **Origin**
     - IJG License
     - Modified BSD License
     - zlib License
+
+
+The Modified (3-clause) BSD License
+===================================
+
+Copyright (C)\<YEAR\> \<AUTHOR\>.  All Rights Reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+- Redistributions of source code must retain the above copyright notice,
+  this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright notice,
+  this list of conditions and the following disclaimer in the documentation
+  and/or other materials provided with the distribution.
+- Neither the name of the libjpeg-turbo Project nor the names of its
+  contributors may be used to endorse or promote products derived from this
+  software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+
+The zlib License
+================
+
+Copyright (C) \<YEAR\>, \<AUTHOR\>.
+
+This software is provided 'as-is', without any express or implied
+warranty.  In no event will the authors be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not
+   claim that you wrote the original software. If you use this software
+   in a product, an acknowledgment in the product documentation would be
+   appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be
+   misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
--- a/media/libjpeg/README.md
+++ b/media/libjpeg/README.md
@@ -37,25 +37,25 @@ Refer to [BUILDING.md](BUILDING.md) for 
 
 
 Using libjpeg-turbo
 ===================
 
 libjpeg-turbo includes two APIs that can be used to compress and decompress
 JPEG images:
 
-- **TurboJPEG API**  
+- **TurboJPEG API**<br>
   This API provides an easy-to-use interface for compressing and decompressing
   JPEG images in memory.  It also provides some functionality that would not be
   straightforward to achieve using the underlying libjpeg API, such as
   generating planar YUV images and performing multiple simultaneous lossless
   transforms on an image.  The Java interface for libjpeg-turbo is written on
   top of the TurboJPEG API.
 
-- **libjpeg API**  
+- **libjpeg API**<br>
   This is the de facto industry-standard API for compressing and decompressing
   JPEG images.  It is more difficult to use than the TurboJPEG API but also
   more powerful.  The libjpeg API implementation in libjpeg-turbo is both
   API/ABI-compatible and mathematically compatible with libjpeg v6b.  It can
   also optionally be configured to be API/ABI-compatible with libjpeg v7 and v8
   (see below.)
 
 There is no significant performance advantage to either API when both are used
@@ -136,27 +136,27 @@ version of libjpeg-turbo that emulates t
 programs that are built against libjpeg v7 or v8 can be run with libjpeg-turbo.
 The following section describes which libjpeg v7+ features are supported and
 which aren't.
 
 ### Support for libjpeg v7 and v8 Features
 
 #### Fully supported
 
-- **libjpeg: IDCT scaling extensions in decompressor**  
+- **libjpeg: IDCT scaling extensions in decompressor**<br>
   libjpeg-turbo supports IDCT scaling with scaling factors of 1/8, 1/4, 3/8,
   1/2, 5/8, 3/4, 7/8, 9/8, 5/4, 11/8, 3/2, 13/8, 7/4, 15/8, and 2/1 (only 1/4
   and 1/2 are SIMD-accelerated.)
 
 - **libjpeg: Arithmetic coding**
 
-- **libjpeg: In-memory source and destination managers**  
+- **libjpeg: In-memory source and destination managers**<br>
   See notes below.
 
-- **cjpeg: Separate quality settings for luminance and chrominance**  
+- **cjpeg: Separate quality settings for luminance and chrominance**<br>
   Note that the libpjeg v7+ API was extended to accommodate this feature only
   for convenience purposes.  It has always been possible to implement this
   feature with libjpeg v6b (see rdswitch.c for an example.)
 
 - **cjpeg: 32-bit BMP support**
 
 - **cjpeg: `-rgb` option**
 
@@ -175,45 +175,45 @@ which aren't.
 
 NOTE:  As of this writing, extensive research has been conducted into the
 usefulness of DCT scaling as a means of data reduction and SmartScale as a
 means of quality improvement.  The reader is invited to peruse the research at
 <http://www.libjpeg-turbo.org/About/SmartScale> and draw his/her own conclusions,
 but it is the general belief of our project that these features have not
 demonstrated sufficient usefulness to justify inclusion in libjpeg-turbo.
 
-- **libjpeg: DCT scaling in compressor**  
+- **libjpeg: DCT scaling in compressor**<br>
   `cinfo.scale_num` and `cinfo.scale_denom` are silently ignored.
   There is no technical reason why DCT scaling could not be supported when
   emulating the libjpeg v7+ API/ABI, but without the SmartScale extension (see
   below), only scaling factors of 1/2, 8/15, 4/7, 8/13, 2/3, 8/11, 4/5, and
   8/9 would be available, which is of limited usefulness.
 
-- **libjpeg: SmartScale**  
+- **libjpeg: SmartScale**<br>
   `cinfo.block_size` is silently ignored.
   SmartScale is an extension to the JPEG format that allows for DCT block
   sizes other than 8x8.  Providing support for this new format would be
   feasible (particularly without full acceleration.)  However, until/unless
   the format becomes either an official industry standard or, at minimum, an
   accepted solution in the community, we are hesitant to implement it, as
   there is no sense of whether or how it might change in the future.  It is
   our belief that SmartScale has not demonstrated sufficient usefulness as a
   lossless format nor as a means of quality enhancement, and thus our primary
   interest in providing this feature would be as a means of supporting
   additional DCT scaling factors.
 
-- **libjpeg: Fancy downsampling in compressor**  
+- **libjpeg: Fancy downsampling in compressor**<br>
   `cinfo.do_fancy_downsampling` is silently ignored.
   This requires the DCT scaling feature, which is not supported.
 
-- **jpegtran: Scaling**  
+- **jpegtran: Scaling**<br>
   This requires both the DCT scaling and SmartScale features, which are not
   supported.
 
-- **Lossless RGB JPEG files**  
+- **Lossless RGB JPEG files**<br>
   This requires the SmartScale feature, which is not supported.
 
 ### What About libjpeg v9?
 
 libjpeg v9 introduced yet another field to the JPEG compression structure
 (`color_transform`), thus making the ABI backward incompatible with that of
 libjpeg v8.  This new field was introduced solely for the purpose of supporting
 lossless SmartScale encoding.  Furthermore, there was actually no reason to
@@ -221,17 +221,17 @@ extend the API in this manner, as the co
 been activated by way of a new JPEG colorspace constant, thus preserving
 backward ABI compatibility.
 
 Our research (see link above) has shown that lossless SmartScale does not
 generally accomplish anything that can't already be accomplished better with
 existing, standard lossless formats.  Therefore, at this time it is our belief
 that there is not sufficient technical justification for software projects to
 upgrade from libjpeg v8 to libjpeg v9, and thus there is not sufficient
-echnical justification for us to emulate the libjpeg v9 ABI.
+technical justification for us to emulate the libjpeg v9 ABI.
 
 In-Memory Source/Destination Managers
 -------------------------------------
 
 By default, libjpeg-turbo 1.3 and later includes the `jpeg_mem_src()` and
 `jpeg_mem_dest()` functions, even when not emulating the libjpeg v8 API/ABI.
 Previously, it was necessary to build libjpeg-turbo from source with libjpeg v8
 API/ABI emulation in order to use the in-memory source/destination managers,
@@ -244,18 +244,18 @@ libjpeg-turbo binaries.
 Those who are concerned about maintaining strict conformance with the libjpeg
 v6b or v7 API can pass an argument of `--without-mem-srcdst` to `configure` or
 an argument of `-DWITH_MEM_SRCDST=0` to `cmake` prior to building
 libjpeg-turbo.  This will restore the pre-1.3 behavior, in which
 `jpeg_mem_src()` and `jpeg_mem_dest()` are only included when emulating the
 libjpeg v8 API/ABI.
 
 On Un*x systems, including the in-memory source/destination managers changes
-the dynamic library version from 62.0.0 to 62.1.0 if using libjpeg v6b API/ABI
-emulation and from 7.0.0 to 7.1.0 if using libjpeg v7 API/ABI emulation.
+the dynamic library version from 62.1.0 to 62.2.0 if using libjpeg v6b API/ABI
+emulation and from 7.1.0 to 7.2.0 if using libjpeg v7 API/ABI emulation.
 
 Note that, on most Un*x systems, the dynamic linker will not look for a
 function in a library until that function is actually used.  Thus, if a program
 is built against libjpeg-turbo 1.3+ and uses `jpeg_mem_src()` or
 `jpeg_mem_dest()`, that program will not fail if run against an older version
 of libjpeg-turbo or against libjpeg v7- until the program actually tries to
 call `jpeg_mem_src()` or `jpeg_mem_dest()`.  Such is not the case on Windows.
 If a program is built against the libjpeg-turbo 1.3+ DLL and uses
--- a/media/libjpeg/jconfig.h
+++ b/media/libjpeg/jconfig.h
@@ -1,16 +1,16 @@
 /* jconfig.h.  Generated from jconfig.h.in by configure, then manually edited
    for Mozilla. */
 
 /* Export libjpeg v6.2's ABI. */
 #define JPEG_LIB_VERSION 62
 
 /* libjpeg-turbo version */
-#define LIBJPEG_TURBO_VERSION 1.5.1
+#define LIBJPEG_TURBO_VERSION 1.5.2
 
 /* Support arithmetic encoding */
 /*#undef C_ARITH_CODING_SUPPORTED */
 
 /* Support arithmetic decoding */
 /*#undef D_ARITH_CODING_SUPPORTED */
 
 /*
--- a/media/libjpeg/jconfigint.h
+++ b/media/libjpeg/jconfigint.h
@@ -1,7 +1,7 @@
-#define VERSION "1.5.1"
-#define BUILD "2016-09-20"
+#define VERSION "1.5.2"
+#define BUILD "2017-07-07"
 #define PACKAGE_NAME "libjpeg-turbo"
 
 /* Need to use Mozilla-specific function inlining. */
 #include "mozilla/Attributes.h"
 #define INLINE MOZ_ALWAYS_INLINE
--- a/media/libjpeg/jdarith.c
+++ b/media/libjpeg/jdarith.c
@@ -16,16 +16,19 @@
  * Suspension is not currently supported in this module.
  */
 
 #define JPEG_INTERNALS
 #include "jinclude.h"
 #include "jpeglib.h"
 
 
+#define NEG_1 ((unsigned int)-1)
+
+
 /* Expanded entropy decoder object for arithmetic decoding. */
 
 typedef struct {
   struct jpeg_entropy_decoder pub; /* public fields */
 
   JLONG c;       /* C register, base of coding interval + input bit buffer */
   JLONG a;               /* A register, normalized size of coding interval */
   int ct;     /* bit shift counter, # of bits left in bit buffer part of C */
@@ -445,17 +448,17 @@ decode_mcu_AC_refine (j_decompress_ptr c
 
   if (entropy->ct == -1) return TRUE;   /* if error do nothing */
 
   /* There is always only one block per MCU */
   block = MCU_data[0];
   tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
 
   p1 = 1 << cinfo->Al;          /* 1 in the bit position being coded */
-  m1 = (-1) << cinfo->Al;       /* -1 in the bit position being coded */
+  m1 = (NEG_1) << cinfo->Al;    /* -1 in the bit position being coded */
 
   /* Establish EOBx (previous stage end-of-block) index */
   for (kex = cinfo->Se; kex > 0; kex--)
     if ((*block)[jpeg_natural_order[kex]]) break;
 
   for (k = cinfo->Ss; k <= cinfo->Se; k++) {
     st = entropy->ac_stats[tbl] + 3 * (k - 1);
     if (k > kex)
--- a/media/libjpeg/jmemmgr.c
+++ b/media/libjpeg/jmemmgr.c
@@ -27,18 +27,20 @@
  * memory then you shouldn't care about a little bit of unused code...)
  */
 
 #define JPEG_INTERNALS
 #define AM_MEMORY_MANAGER       /* we define jvirt_Xarray_control structs */
 #include "jinclude.h"
 #include "jpeglib.h"
 #include "jmemsys.h"            /* import the system-dependent declarations */
+#ifndef _WIN32
 #include <stdint.h>
-#include <limits.h>             /* some NDKs define SIZE_MAX in limits.h */
+#endif
+#include <limits.h>
 
 #ifndef NO_GETENV
 #ifndef HAVE_STDLIB_H           /* <stdlib.h> should declare getenv() */
 extern char *getenv (const char *name);
 #endif
 #endif
 
 
--- a/media/libjpeg/jmemnobs.c
+++ b/media/libjpeg/jmemnobs.c
@@ -1,26 +1,25 @@
 /*
  * jmemnobs.c
  *
  * This file was part of the Independent JPEG Group's software:
  * Copyright (C) 1992-1996, Thomas G. Lane.
- * It was modified by The libjpeg-turbo Project to include only code and
- * information relevant to libjpeg-turbo.
+ * libjpeg-turbo Modifications:
+ * Copyright (C) 2017, D. R. Commander.
  * For conditions of distribution and use, see the accompanying README.ijg
  * file.
  *
  * This file provides a really simple implementation of the system-
  * dependent portion of the JPEG memory manager.  This implementation
  * assumes that no backing-store files are needed: all required space
  * can be obtained from malloc().
  * This is very portable in the sense that it'll compile on almost anything,
  * but you'd better have lots of main memory (or virtual memory) if you want
  * to process big images.
- * Note that the max_memory_to_use option is ignored by this implementation.
  */
 
 #define JPEG_INTERNALS
 #include "jinclude.h"
 #include "jpeglib.h"
 #include "jmemsys.h"            /* import the system-dependent declarations */
 
 #ifndef HAVE_STDLIB_H           /* <stdlib.h> should declare malloc(),free() */
@@ -61,24 +60,31 @@ GLOBAL(void)
 jpeg_free_large (j_common_ptr cinfo, void *object, size_t sizeofobject)
 {
   free(object);
 }
 
 
 /*
  * This routine computes the total memory space available for allocation.
- * Here we always say, "we got all you want bud!"
  */
 
 GLOBAL(size_t)
 jpeg_mem_available (j_common_ptr cinfo, size_t min_bytes_needed,
                     size_t max_bytes_needed, size_t already_allocated)
 {
-  return max_bytes_needed;
+  if (cinfo->mem->max_memory_to_use) {
+    if (cinfo->mem->max_memory_to_use > already_allocated)
+      return cinfo->mem->max_memory_to_use - already_allocated;
+    else
+      return 0;
+  } else {
+    /* Here we always say, "we got all you want bud!" */
+    return max_bytes_needed;
+  }
 }
 
 
 /*
  * Backing store (temporary file) management.
  * Since jpeg_mem_available always promised the moon,
  * this should never be called and we can just error out.
  */
--- a/media/libjpeg/jversion.h
+++ b/media/libjpeg/jversion.h
@@ -1,15 +1,15 @@
 /*
  * jversion.h
  *
  * This file was part of the Independent JPEG Group's software:
  * Copyright (C) 1991-2012, Thomas G. Lane, Guido Vollbeding.
  * libjpeg-turbo Modifications:
- * Copyright (C) 2010, 2012-2016, D. R. Commander.
+ * Copyright (C) 2010, 2012-2017, D. R. Commander.
  * For conditions of distribution and use, see the accompanying README.ijg
  * file.
  *
  * This file contains software version identification.
  */
 
 
 #if JPEG_LIB_VERSION >= 80
@@ -30,20 +30,20 @@
  * NOTE: It is our convention to place the authors in the following order:
  * - libjpeg-turbo authors (2009-) in descending order of the date of their
  *   most recent contribution to the project, then in ascending order of the
  *   date of their first contribution to the project
  * - Upstream authors in descending order of the date of the first inclusion of
  *   their code
  */
 
-#define JCOPYRIGHT      "Copyright (C) 2009-2016 D. R. Commander\n" \
+#define JCOPYRIGHT      "Copyright (C) 2009-2017 D. R. Commander\n" \
                         "Copyright (C) 2011-2016 Siarhei Siamashka\n" \
                         "Copyright (C) 2015-2016 Matthieu Darbois\n" \
                         "Copyright (C) 2015 Google, Inc.\n" \
                         "Copyright (C) 2013-2014 MIPS Technologies, Inc.\n" \
                         "Copyright (C) 2013 Linaro Limited\n" \
                         "Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)\n" \
                         "Copyright (C) 2009 Pierre Ossman for Cendio AB\n" \
                         "Copyright (C) 1999-2006 MIYASAKA Masaru\n" \
                         "Copyright (C) 1991-2016 Thomas G. Lane, Guido Vollbeding" \
 
-#define JCOPYRIGHT_SHORT "Copyright (C) 1991-2016 The libjpeg-turbo Project and many others"
+#define JCOPYRIGHT_SHORT "Copyright (C) 1991-2017 The libjpeg-turbo Project and many others"
--- a/media/libjpeg/mozilla.diff
+++ b/media/libjpeg/mozilla.diff
@@ -1,29 +1,8 @@
-diff --git jmemmgr.c jmemmgr.c
---- jmemmgr.c
-+++ jmemmgr.c
-@@ -28,16 +28,17 @@
-  */
- 
- #define JPEG_INTERNALS
- #define AM_MEMORY_MANAGER       /* we define jvirt_Xarray_control structs */
- #include "jinclude.h"
- #include "jpeglib.h"
- #include "jmemsys.h"            /* import the system-dependent declarations */
- #include <stdint.h>
-+#include <limits.h>             /* some NDKs define SIZE_MAX in limits.h */
- 
- #ifndef NO_GETENV
- #ifndef HAVE_STDLIB_H           /* <stdlib.h> should declare getenv() */
- extern char *getenv (const char *name);
- #endif
- #endif
-
-
 diff --git jmorecfg.h jmorecfg.h
 --- jmorecfg.h
 +++ jmorecfg.h
 @@ -9,16 +9,17 @@
   * For conditions of distribution and use, see the accompanying README.ijg
   * file.
   *
   * This file contains additional configuration options that customize the
--- a/media/libjpeg/simd/jchuff-sse2.asm
+++ b/media/libjpeg/simd/jchuff-sse2.asm
@@ -1,12 +1,12 @@
 ;
 ; jchuff-sse2.asm - Huffman entropy encoding (SSE2)
 ;
-; Copyright (C) 2009-2011, 2014-2016, D. R. Commander.
+; Copyright (C) 2009-2011, 2014-2017, D. R. Commander.
 ; Copyright (C) 2015, Matthieu Darbois.
 ;
 ; Based on the x86 SIMD extension for IJG JPEG library
 ; Copyright (C) 1999-2006, MIYASAKA Masaru.
 ; For conditions of distribution and use, see copyright notice in jsimdext.inc
 ;
 ; This file should be assembled with NASM (Netwide Assembler),
 ; can *not* be assembled with Microsoft's MASM or any compatible
@@ -283,23 +283,23 @@ EXTN(jsimd_huff_encode_one_block_sse2):
         or  edx, ecx
         not edx  ; index = ~index;
 
         lea esi, [esp+t1]
         mov ebp, POINTER [esp+actbl]  ; ebp = actbl
 
 .BLOOP:
         bsf ecx, edx  ; r = __builtin_ctzl(index);
-        jz .ELOOP
+        jz near .ELOOP
         lea esi, [esi+ecx*2]  ; k += r;
         shr edx, cl  ; index >>= r;
         mov DWORD [esp+temp3], edx
 .BRLOOP:
         cmp ecx, 16  ; while (r > 15) {
-        jl .ERLOOP
+        jl near .ERLOOP
         sub ecx, 16 ; r -= 16;
         mov DWORD [esp+temp], ecx
         mov   eax, INT [ebp + 240 * 4]  ; code_0xf0 = actbl->ehufco[0xf0];
         movzx ecx, byte [ebp + 1024 + 240]  ; size_0xf0 = actbl->ehufsi[0xf0];
         EMIT_BITS eax  ; EMIT_BITS(code_0xf0, size_0xf0)
         mov ecx, DWORD [esp+temp]
         jmp .BRLOOP
 .ERLOOP:
@@ -343,31 +343,31 @@ EXTN(jsimd_huff_encode_one_block_sse2):
         shl ecx, 16
         or  edx, ecx
         not edx  ; index = ~index;
 
         lea eax, [esp + t1 + (DCTSIZE2/2) * 2]
         sub eax, esi
         shr eax, 1
         bsf ecx, edx  ; r = __builtin_ctzl(index);
-        jz .ELOOP2
+        jz near .ELOOP2
         shr edx, cl  ; index >>= r;
         add ecx, eax
         lea esi, [esi+ecx*2]  ; k += r;
         mov DWORD [esp+temp3], edx
         jmp .BRLOOP2
 .BLOOP2:
         bsf ecx, edx  ; r = __builtin_ctzl(index);
-        jz .ELOOP2
+        jz near .ELOOP2
         lea esi, [esi+ecx*2]  ; k += r;
         shr edx, cl  ; index >>= r;
         mov DWORD [esp+temp3], edx
 .BRLOOP2:
         cmp ecx, 16  ; while (r > 15) {
-        jl .ERLOOP2
+        jl near .ERLOOP2
         sub ecx, 16  ; r -= 16;
         mov DWORD [esp+temp], ecx
         mov   eax, INT [ebp + 240 * 4]  ; code_0xf0 = actbl->ehufco[0xf0];
         movzx ecx, byte [ebp + 1024 + 240]  ; size_0xf0 = actbl->ehufsi[0xf0];
         EMIT_BITS eax  ; EMIT_BITS(code_0xf0, size_0xf0)
         mov ecx, DWORD [esp+temp]
         jmp .BRLOOP2
 .ERLOOP2:
--- a/media/libjpeg/simd/jsimd_arm.c
+++ b/media/libjpeg/simd/jsimd_arm.c
@@ -1,12 +1,13 @@
 /*
  * jsimd_arm.c
  *
  * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
+ * Copyright (C) 2011, Nokia Corporation and/or its subsidiary(-ies).
  * Copyright (C) 2009-2011, 2013-2014, 2016, D. R. Commander.
  * Copyright (C) 2015-2016, Matthieu Darbois.
  *
  * Based on the x86 SIMD extension for IJG JPEG library,
  * Copyright (C) 1999-2006, MIYASAKA Masaru.
  * For conditions of distribution and use, see copyright notice in jsimdext.inc
  *
  * This file contains the interface between the "normal" portions
--- a/media/libjpeg/simd/jsimd_arm64.c
+++ b/media/libjpeg/simd/jsimd_arm64.c
@@ -1,12 +1,13 @@
 /*
  * jsimd_arm64.c
  *
  * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
+ * Copyright (C) 2011, Nokia Corporation and/or its subsidiary(-ies).
  * Copyright (C) 2009-2011, 2013-2014, 2016, D. R. Commander.
  * Copyright (C) 2015-2016, Matthieu Darbois.
  *
  * Based on the x86 SIMD extension for IJG JPEG library,
  * Copyright (C) 1999-2006, MIYASAKA Masaru.
  * For conditions of distribution and use, see copyright notice in jsimdext.inc
  *
  * This file contains the interface between the "normal" portions
--- a/media/libjpeg/simd/jsimd_mips.c
+++ b/media/libjpeg/simd/jsimd_mips.c
@@ -58,16 +58,18 @@ parse_proc_cpuinfo(const char* search_st
 /*
  * Check what SIMD accelerations are supported.
  *
  * FIXME: This code is racy under a multi-threaded environment.
  */
 LOCAL(void)
 init_simd (void)
 {
+  char *env = NULL;
+
   if (simd_support != ~0U)
     return;
 
   simd_support = 0;
 
 #if defined(__MIPSEL__) && defined(__mips_dsp) && (__mips_dsp_rev >= 2)
   simd_support |= JSIMD_MIPS_DSPR2;
 #elif defined(__linux__)
--- a/media/libjpeg/simd/jsimd_powerpc.c
+++ b/media/libjpeg/simd/jsimd_powerpc.c
@@ -9,28 +9,39 @@
  * Copyright (C) 1999-2006, MIYASAKA Masaru.
  * For conditions of distribution and use, see copyright notice in jsimdext.inc
  *
  * This file contains the interface between the "normal" portions
  * of the library and the SIMD implementations when running on a
  * PowerPC architecture.
  */
 
+#ifdef __amigaos4__
+/* This must be defined first as it re-defines GLOBAL otherwise */
+#include <proto/exec.h>
+#endif
+
 #define JPEG_INTERNALS
 #include "../jinclude.h"
 #include "../jpeglib.h"
 #include "../jsimd.h"
 #include "../jdct.h"
 #include "../jsimddct.h"
 #include "jsimd.h"
 
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 
+#if defined(__OpenBSD__)
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <machine/cpu.h>
+#endif
+
 static unsigned int simd_support = ~0;
 
 #if defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
 
 #define SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT (1024 * 1024)
 
 LOCAL(int)
 check_feature (char *buffer, char *feature)
@@ -96,31 +107,44 @@ parse_proc_cpuinfo (int bufsize)
  * FIXME: This code is racy under a multi-threaded environment.
  */
 LOCAL(void)
 init_simd (void)
 {
   char *env = NULL;
 #if !defined(__ALTIVEC__) && (defined(__linux__) || defined(ANDROID) || defined(__ANDROID__))
   int bufsize = 1024; /* an initial guess for the line buffer size limit */
+#elif defined(__amigaos4__)
+  uint32 altivec = 0;
+#elif defined(__OpenBSD__)
+  int mib[2] = { CTL_MACHDEP, CPU_ALTIVEC };
+  int altivec;
+  size_t len = sizeof(altivec);
 #endif
 
   if (simd_support != ~0U)
     return;
 
   simd_support = 0;
 
 #if defined(__ALTIVEC__) || defined(__APPLE__)
   simd_support |= JSIMD_ALTIVEC;
 #elif defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
   while (!parse_proc_cpuinfo(bufsize)) {
     bufsize *= 2;
     if (bufsize > SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT)
       break;
   }
+#elif defined(__amigaos4__)
+  IExec->GetCPUInfoTags(GCIT_VectorUnit, &altivec, TAG_DONE);
+  if(altivec == VECTORTYPE_ALTIVEC)
+    simd_support |= JSIMD_ALTIVEC;
+#elif defined(__OpenBSD__)
+  if (sysctl(mib, 2, &altivec, &len, NULL, 0) == 0 && altivec != 0)
+    simd_support |= JSIMD_ALTIVEC;
 #endif
 
   /* Force different settings through environment variables */
   env = getenv("JSIMD_FORCEALTIVEC");
   if ((env != NULL) && (strcmp(env, "1") == 0))
     simd_support = JSIMD_ALTIVEC;
   env = getenv("JSIMD_FORCENONE");
   if ((env != NULL) && (strcmp(env, "1") == 0))