Skip to content

Commit

Permalink
AltiVec: Disable/Fix some strict compiler warnings
Browse files Browse the repository at this point in the history
We use a standard set of strict compiler warnings with Clang and GCC to
continuously test and maintain C89 conformance in the libjpeg API code.
However, SIMD extensions need not comply with that.  The AltiVec code
specifically uses some C99isms, so disable -Wc99-extensions and
-Wpedantic in the scope of that code.  Also disable -Wshadow, because
I'm too lazy to fix the TRANSPOSE() macro.  Also
use #ifdef __BIG_ENDIAN__ and #if defined(__BIG_ENDIAN__) instead
of #if __BIG_ENDIAN__
  • Loading branch information
dcommander committed Dec 12, 2024
1 parent ab56b98 commit 1c864a9
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 40 deletions.
14 changes: 7 additions & 7 deletions simd/powerpc/jccolext-altivec.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* AltiVec optimizations for libjpeg-turbo
*
* Copyright (C) 2014-2015, D. R. Commander. All Rights Reserved.
* Copyright (C) 2014-2015, 2024, D. R. Commander. All Rights Reserved.
* Copyright (C) 2014, Jay Foad. All Rights Reserved.
*
* This software is provided 'as-is', without any express or implied
Expand Down Expand Up @@ -30,17 +30,17 @@ void jsimd_rgb_ycc_convert_altivec(JDIMENSION img_width, JSAMPARRAY input_buf,
{
JSAMPROW inptr, outptr0, outptr1, outptr2;
int pitch = img_width * RGB_PIXELSIZE, num_cols;
#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
int offset;
#endif
unsigned char __attribute__((aligned(16))) tmpbuf[RGB_PIXELSIZE * 16];

__vector unsigned char rgb0, rgb1 = { 0 }, rgb2 = { 0 },
rgbg0, rgbg1, rgbg2, rgbg3, y, cb, cr;
#if __BIG_ENDIAN__ || RGB_PIXELSIZE == 4
#if defined(__BIG_ENDIAN__) || RGB_PIXELSIZE == 4
__vector unsigned char rgb3 = { 0 };
#endif
#if __BIG_ENDIAN__ && RGB_PIXELSIZE == 4
#if defined(__BIG_ENDIAN__) && RGB_PIXELSIZE == 4
__vector unsigned char rgb4 = { 0 };
#endif
__vector short rg0, rg1, rg2, rg3, bg0, bg1, bg2, bg3;
Expand All @@ -56,7 +56,7 @@ void jsimd_rgb_ycc_convert_altivec(JDIMENSION img_width, JSAMPARRAY input_buf,
__vector int pd_onehalf = { __4X(ONE_HALF) },
pd_onehalfm1_cj = { __4X(ONE_HALF - 1 + (CENTERJSAMPLE << SCALEBITS)) };
__vector unsigned char pb_zero = { __16X(0) },
#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
shift_pack_index =
{ 0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29 };
#else
Expand All @@ -75,7 +75,7 @@ void jsimd_rgb_ycc_convert_altivec(JDIMENSION img_width, JSAMPARRAY input_buf,
num_cols -= RGB_PIXELSIZE * 16, inptr += RGB_PIXELSIZE * 16,
outptr0 += 16, outptr1 += 16, outptr2 += 16) {

#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
/* Load 16 pixels == 48 or 64 bytes */
offset = (size_t)inptr & 15;
if (offset) {
Expand Down Expand Up @@ -141,7 +141,7 @@ void jsimd_rgb_ycc_convert_altivec(JDIMENSION img_width, JSAMPARRAY input_buf,
rgb3 = VEC_LD(48, inptr);
#endif
}
#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
}
#endif

Expand Down
12 changes: 6 additions & 6 deletions simd/powerpc/jcgryext-altivec.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* AltiVec optimizations for libjpeg-turbo
*
* Copyright (C) 2014-2015, D. R. Commander. All Rights Reserved.
* Copyright (C) 2014-2015, 2024, D. R. Commander. All Rights Reserved.
* Copyright (C) 2014, Jay Foad. All Rights Reserved.
*
* This software is provided 'as-is', without any express or implied
Expand Down Expand Up @@ -30,17 +30,17 @@ void jsimd_rgb_gray_convert_altivec(JDIMENSION img_width, JSAMPARRAY input_buf,
{
JSAMPROW inptr, outptr;
int pitch = img_width * RGB_PIXELSIZE, num_cols;
#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
int offset;
unsigned char __attribute__((aligned(16))) tmpbuf[RGB_PIXELSIZE * 16];
#endif

__vector unsigned char rgb0, rgb1 = { 0 }, rgb2 = { 0 },
rgbg0, rgbg1, rgbg2, rgbg3, y;
#if __BIG_ENDIAN__ || RGB_PIXELSIZE == 4
#if defined(__BIG_ENDIAN__) || RGB_PIXELSIZE == 4
__vector unsigned char rgb3 = { 0 };
#endif
#if __BIG_ENDIAN__ && RGB_PIXELSIZE == 4
#if defined(__BIG_ENDIAN__) && RGB_PIXELSIZE == 4
__vector unsigned char rgb4 = { 0 };
#endif
__vector short rg0, rg1, rg2, rg3, bg0, bg1, bg2, bg3;
Expand All @@ -52,7 +52,7 @@ void jsimd_rgb_gray_convert_altivec(JDIMENSION img_width, JSAMPARRAY input_buf,
pw_f0114_f0250 = { __4X2(F_0_114, F_0_250) };
__vector int pd_onehalf = { __4X(ONE_HALF) };
__vector unsigned char pb_zero = { __16X(0) },
#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
shift_pack_index =
{ 0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29 };
#else
Expand All @@ -69,7 +69,7 @@ void jsimd_rgb_gray_convert_altivec(JDIMENSION img_width, JSAMPARRAY input_buf,
num_cols -= RGB_PIXELSIZE * 16, inptr += RGB_PIXELSIZE * 16,
outptr += 16) {

#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
/* Load 16 pixels == 48 or 64 bytes */
offset = (size_t)inptr & 15;
if (offset) {
Expand Down
6 changes: 3 additions & 3 deletions simd/powerpc/jcsample-altivec.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* AltiVec optimizations for libjpeg-turbo
*
* Copyright (C) 2015, D. R. Commander. All Rights Reserved.
* Copyright (C) 2015, 2024, D. R. Commander. All Rights Reserved.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -50,7 +50,7 @@ void jsimd_h2v1_downsample_altivec(JDIMENSION image_width,
expand_right_edge(input_data, max_v_samp_factor, image_width,
output_cols * 2);

for (outrow = 0; outrow < v_samp_factor; outrow++) {
for (outrow = 0; outrow < (int)v_samp_factor; outrow++) {
outptr = output_data[outrow];
inptr = input_data[outrow];

Expand Down Expand Up @@ -107,7 +107,7 @@ jsimd_h2v2_downsample_altivec(JDIMENSION image_width, int max_v_samp_factor,
expand_right_edge(input_data, max_v_samp_factor, image_width,
output_cols * 2);

for (inrow = 0, outrow = 0; outrow < v_samp_factor;
for (inrow = 0, outrow = 0; outrow < (int)v_samp_factor;
inrow += 2, outrow++) {

inptr0 = input_data[inrow];
Expand Down
12 changes: 6 additions & 6 deletions simd/powerpc/jdcolext-altivec.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* AltiVec optimizations for libjpeg-turbo
*
* Copyright (C) 2015, D. R. Commander. All Rights Reserved.
* Copyright (C) 2015, 2024, D. R. Commander. All Rights Reserved.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -29,14 +29,14 @@ void jsimd_ycc_rgb_convert_altivec(JDIMENSION out_width, JSAMPIMAGE input_buf,
{
JSAMPROW outptr, inptr0, inptr1, inptr2;
int pitch = out_width * RGB_PIXELSIZE, num_cols;
#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
int offset;
#endif
unsigned char __attribute__((aligned(16))) tmpbuf[RGB_PIXELSIZE * 16];

__vector unsigned char rgb0, rgb1, rgb2, rgbx0, rgbx1, rgbx2, rgbx3,
y, cb, cr;
#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
__vector unsigned char edgel, edgeh, edges, out0, out1, out2, out3;
#if RGB_PIXELSIZE == 4
__vector unsigned char out4;
Expand All @@ -60,7 +60,7 @@ void jsimd_ycc_rgb_convert_altivec(JDIMENSION out_width, JSAMPIMAGE input_buf,
pw_cj = { __8X(CENTERJSAMPLE) };
__vector int pd_onehalf = { __4X(ONE_HALF) };
__vector unsigned char pb_zero = { __16X(0) },
#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
shift_pack_index =
{ 0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29 };
#else
Expand Down Expand Up @@ -196,7 +196,7 @@ void jsimd_ycc_rgb_convert_altivec(JDIMENSION out_width, JSAMPIMAGE input_buf,
rgb3 = vec_perm(rgbx3, rgbx3, (__vector unsigned char)RGB_INDEX);
#endif

#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
offset = (size_t)outptr & 15;
if (offset) {
__vector unsigned char unaligned_shift_index;
Expand Down Expand Up @@ -268,7 +268,7 @@ void jsimd_ycc_rgb_convert_altivec(JDIMENSION out_width, JSAMPIMAGE input_buf,
VEC_ST(rgb3, 48, outptr);
#endif
}
#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
}
#endif
}
Expand Down
12 changes: 6 additions & 6 deletions simd/powerpc/jdmrgext-altivec.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* AltiVec optimizations for libjpeg-turbo
*
* Copyright (C) 2015, D. R. Commander. All Rights Reserved.
* Copyright (C) 2015, 2024, D. R. Commander. All Rights Reserved.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -30,14 +30,14 @@ void jsimd_h2v1_merged_upsample_altivec(JDIMENSION output_width,
{
JSAMPROW outptr, inptr0, inptr1, inptr2;
int pitch = output_width * RGB_PIXELSIZE, num_cols, yloop;
#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
int offset;
#endif
unsigned char __attribute__((aligned(16))) tmpbuf[RGB_PIXELSIZE * 16];

__vector unsigned char rgb0, rgb1, rgb2, rgbx0, rgbx1, rgbx2, rgbx3,
y, cb, cr;
#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
__vector unsigned char edgel, edgeh, edges, out0, out1, out2, out3;
#if RGB_PIXELSIZE == 4
__vector unsigned char out4;
Expand All @@ -62,7 +62,7 @@ void jsimd_h2v1_merged_upsample_altivec(JDIMENSION output_width,
pw_cj = { __8X(CENTERJSAMPLE) };
__vector int pd_onehalf = { __4X(ONE_HALF) };
__vector unsigned char pb_zero = { __16X(0) },
#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
shift_pack_index =
{ 0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29 },
even_index =
Expand Down Expand Up @@ -225,7 +225,7 @@ void jsimd_h2v1_merged_upsample_altivec(JDIMENSION output_width,
rgb3 = vec_perm(rgbx3, rgbx3, (__vector unsigned char)RGB_INDEX);
#endif

#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
offset = (size_t)outptr & 15;
if (offset) {
__vector unsigned char unaligned_shift_index;
Expand Down Expand Up @@ -297,7 +297,7 @@ void jsimd_h2v1_merged_upsample_altivec(JDIMENSION output_width,
VEC_ST(rgb3, 48, outptr);
#endif
}
#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
}
#endif
}
Expand Down
6 changes: 3 additions & 3 deletions simd/powerpc/jdsample-altivec.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* AltiVec optimizations for libjpeg-turbo
*
* Copyright (C) 2015, D. R. Commander. All Rights Reserved.
* Copyright (C) 2015, 2024, D. R. Commander. All Rights Reserved.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -49,7 +49,7 @@ void jsimd_h2v1_fancy_upsample_altivec(int max_v_samp_factor,
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 },
next_index_lastcol =
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15 },
#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
merge_pack_index =
{ 1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31 };
#else
Expand Down Expand Up @@ -155,7 +155,7 @@ void jsimd_h2v2_fancy_upsample_altivec(int max_v_samp_factor,
{ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 },
next_index_lastcol =
{ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 15 },
#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
merge_pack_index =
{ 1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31 };
#else
Expand Down
6 changes: 3 additions & 3 deletions simd/powerpc/jidctfst-altivec.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* AltiVec optimizations for libjpeg-turbo
*
* Copyright (C) 2014-2015, D. R. Commander. All Rights Reserved.
* Copyright (C) 2014-2015, 2024, D. R. Commander. All Rights Reserved.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -127,12 +127,12 @@ void jsimd_idct_ifast_altivec(void *dct_table_, JCOEFPTR coef_block,
__vector short pw_zero = { __8X(0) },
pw_F1414 = { __8X(F_1_414 << CONST_SHIFT) },
pw_F1847 = { __8X(F_1_847 << CONST_SHIFT) },
pw_MF1613 = { __8X(-F_1_613 << CONST_SHIFT) },
pw_MF1613 = { __8X((short)((unsigned short)(-F_1_613) << CONST_SHIFT)) },
pw_F1082 = { __8X(F_1_082 << CONST_SHIFT) };
__vector unsigned short
pre_multiply_scale_bits = { __8X(PRE_MULTIPLY_SCALE_BITS) },
pass1_bits3 = { __8X(PASS1_BITS + 3) };
__vector signed char pb_centerjsamp = { __16X(CENTERJSAMPLE) };
__vector signed char pb_centerjsamp = { __16X((signed char)CENTERJSAMPLE) };

/* Pass 1: process columns */

Expand Down
4 changes: 2 additions & 2 deletions simd/powerpc/jidctint-altivec.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* AltiVec optimizations for libjpeg-turbo
*
* Copyright (C) 2014-2015, 2020, D. R. Commander. All Rights Reserved.
* Copyright (C) 2014-2015, 2020, 2024, D. R. Commander. All Rights Reserved.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -241,7 +241,7 @@ void jsimd_idct_islow_altivec(void *dct_table_, JCOEFPTR coef_block,
__vector unsigned int descale_p1 = { __4X(DESCALE_P1) },
descale_p2 = { __4X(DESCALE_P2) },
const_bits = { __4X(CONST_BITS) };
__vector signed char pb_centerjsamp = { __16X(CENTERJSAMPLE) };
__vector signed char pb_centerjsamp = { __16X((signed char)CENTERJSAMPLE) };

/* Pass 1: process columns */

Expand Down
6 changes: 3 additions & 3 deletions simd/powerpc/jquanti-altivec.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* AltiVec optimizations for libjpeg-turbo
*
* Copyright (C) 2014-2015, D. R. Commander. All Rights Reserved.
* Copyright (C) 2014-2015, 2024, D. R. Commander. All Rights Reserved.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -29,7 +29,7 @@
* always get the data we want by using a single vector load (although we may
* have to permute the result.)
*/
#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__

#define LOAD_ROW(row) { \
elemptr = sample_data[row] + start_col; \
Expand Down Expand Up @@ -125,7 +125,7 @@ void jsimd_quantize_altivec(JCOEFPTR coef_block, DCTELEM *divisors,

/* Constants */
__vector unsigned short pw_word_bit_m1 = { __8X(WORD_BIT - 1) };
#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__
__vector unsigned char shift_pack_index =
{ 0, 1, 16, 17, 4, 5, 20, 21, 8, 9, 24, 25, 12, 13, 28, 29 };
#else
Expand Down
11 changes: 10 additions & 1 deletion simd/powerpc/jsimd_altivec.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

/* Macros to abstract big/little endian bit twiddling */

#if __BIG_ENDIAN__
#ifdef __BIG_ENDIAN__

#define VEC_LD(a, b) vec_ld(a, b)
#define VEC_ST(a, b, c) vec_st(a, b, c)
Expand All @@ -96,3 +96,12 @@
#define VEC_UNPACKLU(a) vec_mergel(a, pb_zero)

#endif


#if defined(__clang__)
#pragma clang diagnostic ignored "-Wc99-extensions"
#pragma clang diagnostic ignored "-Wshadow"
#elif defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wpedantic"
#pragma GCC diagnostic ignored "-Wshadow"
#endif

0 comments on commit 1c864a9

Please sign in to comment.