Coverage Report

Created: 2026-02-26 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.dev/simd/jsimd.c
Line
Count
Source
1
/*
2
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
3
 * Copyright (C) 2009-2011, 2013-2014, 2016, 2018, 2020, 2022-2026,
4
 *           D. R. Commander.
5
 * Copyright (C) 2011, Nokia Corporation and/or its subsidiary(-ies).
6
 * Copyright (C) 2015-2016, 2018, 2022, Matthieu Darbois.
7
 * Copyright (C) 2016-2018, Loongson Technology Corporation Limited, BeiJing.
8
 * Copyright (C) 2019, Google LLC.
9
 * Copyright (C) 2020, Arm Limited.
10
 * Copyright (C) 2025, Samsung Electronics Co., Ltd.
11
 *                     Author:  Filip Wasil
12
 *
13
 * This software is provided 'as-is', without any express or implied
14
 * warranty.  In no event will the authors be held liable for any damages
15
 * arising from the use of this software.
16
 *
17
 * Permission is granted to anyone to use this software for any purpose,
18
 * including commercial applications, and to alter it and redistribute it
19
 * freely, subject to the following restrictions:
20
 *
21
 * 1. The origin of this software must not be misrepresented; you must not
22
 *    claim that you wrote the original software. If you use this software
23
 *    in a product, an acknowledgment in the product documentation would be
24
 *    appreciated but is not required.
25
 * 2. Altered source versions must be plainly marked as such, and must not be
26
 *    misrepresented as being the original software.
27
 * 3. This notice may not be removed or altered from any source distribution.
28
 *
29
 * This file contains the interface between the "normal" portions
30
 * of the library and the SIMD implementations.
31
 */
32
33
#include "jsimddct.h"
34
#include "jsimd.h"
35
#include "jsimdint.h"
36
37
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
38
39
/*
40
 * In the PIC cases, we have no guarantee that constants will keep
41
 * their alignment. This macro allows us to verify it at runtime.
42
 */
43
6.98k
#define IS_ALIGNED(ptr, order)  (((JUINTPTR)ptr & ((1 << order) - 1)) == 0)
44
45
5.27k
#define IS_ALIGNED_SSE(ptr)  (IS_ALIGNED(ptr, 4)) /* 16 byte alignment */
46
1.70k
#define IS_ALIGNED_AVX(ptr)  (IS_ALIGNED(ptr, 5)) /* 32 byte alignment */
47
48
#endif
49
50
51
/*
52
 * Check what SIMD accelerations are supported.
53
 */
54
LOCAL(void)
55
init_simd(j_common_ptr cinfo)
56
13.1k
{
57
13.1k
#ifndef NO_GETENV
58
13.1k
  char env[2] = { 0 };
59
13.1k
#endif
60
13.1k
  unsigned int simd_support = cinfo->is_decompressor ?
61
0
                              ((j_decompress_ptr)cinfo)->master->simd_support :
62
13.1k
                              ((j_compress_ptr)cinfo)->master->simd_support;
63
13.1k
  unsigned int simd_huffman = cinfo->is_decompressor ?
64
0
                              ((j_decompress_ptr)cinfo)->master->simd_huffman :
65
13.1k
                              ((j_compress_ptr)cinfo)->master->simd_huffman;
66
67
13.1k
  if (simd_support != JSIMD_UNDEFINED)
68
10.4k
    return;
69
70
2.63k
  simd_support = jpeg_simd_cpu_support();
71
72
2.63k
#ifndef NO_GETENV
73
  /* Force different settings through environment variables */
74
2.63k
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
75
2.63k
  if (!GETENV_S(env, 2, "JSIMD_FORCESSE2") && !strcmp(env, "1"))
76
0
    simd_support &= JSIMD_SSE2 | JSIMD_SSE;
77
#if SIMD_ARCHITECTURE == I386
78
  if (!GETENV_S(env, 2, "JSIMD_FORCESSE") && !strcmp(env, "1"))
79
    simd_support &= JSIMD_SSE | JSIMD_MMX;
80
  if (!GETENV_S(env, 2, "JSIMD_FORCEMMX") && !strcmp(env, "1"))
81
    simd_support &= JSIMD_MMX;
82
  if (!GETENV_S(env, 2, "JSIMD_FORCE3DNOW") && !strcmp(env, "1"))
83
    simd_support &= JSIMD_3DNOW | JSIMD_MMX;
84
#endif
85
#elif SIMD_ARCHITECTURE == ARM
86
  if (!GETENV_S(env, 2, "JSIMD_FORCENEON") && !strcmp(env, "1"))
87
    simd_support = JSIMD_NEON;
88
#elif SIMD_ARCHITECTURE == RISCV64
89
  if (!GETENV_S(env, 2, "JSIMD_FORCERVV") && !strcmp(env, "1"))
90
    simd_support = JSIMD_RVV;
91
#elif SIMD_ARCHITECTURE == MIPS64
92
  if (!GETENV_S(env, 2, "JSIMD_FORCEMMI") && !strcmp(env, "1"))
93
    simd_support = JSIMD_MMI;
94
#endif
95
2.63k
  if (!GETENV_S(env, 2, "JSIMD_FORCENONE") && !strcmp(env, "1"))
96
0
    simd_support = 0;
97
2.63k
  if (!GETENV_S(env, 2, "JSIMD_NOHUFFENC") && !strcmp(env, "1"))
98
0
    simd_huffman = 0;
99
2.63k
#endif
100
101
2.63k
  if (cinfo->is_decompressor) {
102
0
    ((j_decompress_ptr)cinfo)->master->simd_support = simd_support;
103
0
    ((j_decompress_ptr)cinfo)->master->simd_huffman = simd_huffman;
104
2.63k
  } else {
105
2.63k
    ((j_compress_ptr)cinfo)->master->simd_support = simd_support;
106
2.63k
    ((j_compress_ptr)cinfo)->master->simd_huffman = simd_huffman;
107
2.63k
  }
108
2.63k
}
109
110
111
HIDDEN unsigned int
112
jsimd_set_rgb_ycc(j_compress_ptr cinfo)
113
1.70k
{
114
1.70k
  init_simd((j_common_ptr)cinfo);
115
116
1.70k
  if (BITS_IN_JSAMPLE != 8)
117
0
    return JSIMD_NONE;
118
1.70k
  if (sizeof(JDIMENSION) != 4)
119
0
    return JSIMD_NONE;
120
1.70k
  if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
121
0
    return JSIMD_NONE;
122
1.70k
  if (!cinfo->cconvert)
123
0
    return JSIMD_NONE;
124
125
1.70k
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
126
1.70k
  if ((cinfo->master->simd_support & JSIMD_AVX2) &&
127
1.70k
      IS_ALIGNED_AVX(jconst_rgb_ycc_convert_avx2)) {
128
1.70k
    SET_SIMD_EXTRGB_COLOR_CONVERTER(ycc, avx2);
129
1.70k
    return JSIMD_AVX2;
130
1.70k
  }
131
0
  if ((cinfo->master->simd_support & JSIMD_SSE2) &&
132
0
      IS_ALIGNED_SSE(jconst_rgb_ycc_convert_sse2)) {
133
0
    SET_SIMD_EXTRGB_COLOR_CONVERTER(ycc, sse2);
134
0
    return JSIMD_SSE2;
135
0
  }
136
#if SIMD_ARCHITECTURE == I386
137
  if (cinfo->master->simd_support & JSIMD_MMX) {
138
    SET_SIMD_EXTRGB_COLOR_CONVERTER(ycc, mmx);
139
    return JSIMD_MMX;
140
  }
141
#endif
142
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
143
  if (cinfo->master->simd_support & JSIMD_NEON) {
144
    SET_SIMD_EXTRGB_COLOR_CONVERTER(ycc, neon);
145
    return JSIMD_NEON;
146
  }
147
#elif SIMD_ARCHITECTURE == POWERPC
148
  if (cinfo->master->simd_support & JSIMD_ALTIVEC) {
149
    SET_SIMD_EXTRGB_COLOR_CONVERTER(ycc, altivec);
150
    return JSIMD_ALTIVEC;
151
  }
152
#elif SIMD_ARCHITECTURE == RISCV64
153
  if (cinfo->master->simd_support & JSIMD_RVV) {
154
    SET_SIMD_EXTRGB_COLOR_CONVERTER(ycc, rvv);
155
    return JSIMD_RVV;
156
  }
157
#elif SIMD_ARCHITECTURE == MIPS64
158
  if (cinfo->master->simd_support & JSIMD_MMI) {
159
    SET_SIMD_EXTRGB_COLOR_CONVERTER(ycc, mmi);
160
    return JSIMD_MMI;
161
  }
162
#endif
163
164
0
  return JSIMD_NONE;
165
0
}
166
167
168
HIDDEN unsigned int
169
jsimd_set_rgb_gray(j_compress_ptr cinfo)
170
0
{
171
0
  init_simd((j_common_ptr)cinfo);
172
173
0
  if (BITS_IN_JSAMPLE != 8)
174
0
    return JSIMD_NONE;
175
0
  if (sizeof(JDIMENSION) != 4)
176
0
    return JSIMD_NONE;
177
0
  if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
178
0
    return JSIMD_NONE;
179
0
  if (!cinfo->cconvert)
180
0
    return JSIMD_NONE;
181
182
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
183
0
  if ((cinfo->master->simd_support & JSIMD_AVX2) &&
184
0
      IS_ALIGNED_AVX(jconst_rgb_gray_convert_avx2)) {
185
0
    SET_SIMD_EXTRGB_COLOR_CONVERTER(gray, avx2);
186
0
    return JSIMD_AVX2;
187
0
  }
188
0
  if ((cinfo->master->simd_support & JSIMD_SSE2) &&
189
0
      IS_ALIGNED_SSE(jconst_rgb_gray_convert_sse2)) {
190
0
    SET_SIMD_EXTRGB_COLOR_CONVERTER(gray, sse2);
191
0
    return JSIMD_SSE2;
192
0
  }
193
#if SIMD_ARCHITECTURE == I386
194
  if (cinfo->master->simd_support & JSIMD_MMX) {
195
    SET_SIMD_EXTRGB_COLOR_CONVERTER(gray, mmx);
196
    return JSIMD_MMX;
197
  }
198
#endif
199
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
200
  if (cinfo->master->simd_support & JSIMD_NEON) {
201
    SET_SIMD_EXTRGB_COLOR_CONVERTER(gray, neon);
202
    return JSIMD_NEON;
203
  }
204
#elif SIMD_ARCHITECTURE == POWERPC
205
  if (cinfo->master->simd_support & JSIMD_ALTIVEC) {
206
    SET_SIMD_EXTRGB_COLOR_CONVERTER(gray, altivec);
207
    return JSIMD_ALTIVEC;
208
  }
209
#elif SIMD_ARCHITECTURE == RISCV64
210
  if (cinfo->master->simd_support & JSIMD_RVV) {
211
    SET_SIMD_EXTRGB_COLOR_CONVERTER(gray, rvv);
212
    return JSIMD_RVV;
213
  }
214
#elif SIMD_ARCHITECTURE == MIPS64
215
  if (cinfo->master->simd_support & JSIMD_MMI) {
216
    SET_SIMD_EXTRGB_COLOR_CONVERTER(gray, mmi);
217
    return JSIMD_MMI;
218
  }
219
#endif
220
221
0
  return JSIMD_NONE;
222
0
}
223
224
225
HIDDEN void
226
jsimd_color_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
227
                    JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
228
2.96M
{
229
2.96M
  cinfo->cconvert->color_convert_simd(cinfo->image_width, input_buf,
230
2.96M
                                      output_buf, output_row, num_rows);
231
2.96M
}
232
233
234
HIDDEN unsigned int
235
jsimd_set_ycc_rgb(j_decompress_ptr cinfo)
236
0
{
237
0
  init_simd((j_common_ptr)cinfo);
238
239
0
  if (BITS_IN_JSAMPLE != 8)
240
0
    return JSIMD_NONE;
241
0
  if (sizeof(JDIMENSION) != 4)
242
0
    return JSIMD_NONE;
243
0
  if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
244
0
    return JSIMD_NONE;
245
0
  if (!cinfo->cconvert)
246
0
    return JSIMD_NONE;
247
248
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
249
0
  if ((cinfo->master->simd_support & JSIMD_AVX2) &&
250
0
      IS_ALIGNED_AVX(jconst_ycc_rgb_convert_avx2)) {
251
0
    SET_SIMD_EXTRGB_COLOR_DECONVERTER(avx2);
252
0
    return JSIMD_AVX2;
253
0
  }
254
0
  if ((cinfo->master->simd_support & JSIMD_SSE2) &&
255
0
      IS_ALIGNED_SSE(jconst_ycc_rgb_convert_sse2)) {
256
0
    SET_SIMD_EXTRGB_COLOR_DECONVERTER(sse2);
257
0
    return JSIMD_SSE2;
258
0
  }
259
#if SIMD_ARCHITECTURE == I386
260
  if (cinfo->master->simd_support & JSIMD_MMX) {
261
    SET_SIMD_EXTRGB_COLOR_DECONVERTER(mmx);
262
    return JSIMD_MMX;
263
  }
264
#endif
265
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
266
  if (cinfo->master->simd_support & JSIMD_NEON) {
267
    SET_SIMD_EXTRGB_COLOR_DECONVERTER(neon);
268
    return JSIMD_NEON;
269
  }
270
#elif SIMD_ARCHITECTURE == POWERPC
271
  if (cinfo->master->simd_support & JSIMD_ALTIVEC) {
272
    SET_SIMD_EXTRGB_COLOR_DECONVERTER(altivec);
273
    return JSIMD_ALTIVEC;
274
  }
275
#elif SIMD_ARCHITECTURE == RISCV64
276
  if (cinfo->master->simd_support & JSIMD_RVV) {
277
    SET_SIMD_EXTRGB_COLOR_DECONVERTER(rvv);
278
    return JSIMD_RVV;
279
  }
280
#elif SIMD_ARCHITECTURE == MIPS64
281
  if (cinfo->master->simd_support & JSIMD_MMI) {
282
    SET_SIMD_EXTRGB_COLOR_DECONVERTER(mmi);
283
    return JSIMD_MMI;
284
  }
285
#endif
286
287
0
  return JSIMD_NONE;
288
0
}
289
290
291
HIDDEN unsigned int
292
jsimd_set_ycc_rgb565(j_decompress_ptr cinfo)
293
0
{
294
#if SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
295
  init_simd((j_common_ptr)cinfo);
296
297
  if (BITS_IN_JSAMPLE != 8)
298
    return JSIMD_NONE;
299
  if (sizeof(JDIMENSION) != 4)
300
    return JSIMD_NONE;
301
  if (!cinfo->cconvert)
302
    return JSIMD_NONE;
303
304
  if (cinfo->master->simd_support & JSIMD_NEON) {
305
    cinfo->cconvert->color_convert_simd = jsimd_ycc_rgb565_convert_neon;
306
    return JSIMD_NEON;
307
  }
308
#endif
309
310
0
  return JSIMD_NONE;
311
0
}
312
313
314
HIDDEN void
315
jsimd_color_deconvert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
316
                      JDIMENSION input_row, JSAMPARRAY output_buf,
317
                      int num_rows)
318
0
{
319
0
  cinfo->cconvert->color_convert_simd(cinfo->output_width, input_buf,
320
0
                                      input_row, output_buf, num_rows);
321
0
}
322
323
324
HIDDEN unsigned int
325
jsimd_set_h2v1_downsample(j_compress_ptr cinfo)
326
854
{
327
854
  init_simd((j_common_ptr)cinfo);
328
329
854
  if (BITS_IN_JSAMPLE != 8)
330
0
    return JSIMD_NONE;
331
854
  if (sizeof(JDIMENSION) != 4)
332
0
    return JSIMD_NONE;
333
854
  if (!cinfo->downsample)
334
0
    return JSIMD_NONE;
335
336
854
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
337
854
  if (cinfo->master->simd_support & JSIMD_AVX2) {
338
854
    cinfo->downsample->h2v1_downsample_simd = jsimd_h2v1_downsample_avx2;
339
854
    return JSIMD_AVX2;
340
854
  }
341
0
  if (cinfo->master->simd_support & JSIMD_SSE2) {
342
0
    cinfo->downsample->h2v1_downsample_simd = jsimd_h2v1_downsample_sse2;
343
0
    return JSIMD_SSE2;
344
0
  }
345
#if SIMD_ARCHITECTURE == I386
346
  if (cinfo->master->simd_support & JSIMD_MMX) {
347
    cinfo->downsample->h2v1_downsample_simd = jsimd_h2v1_downsample_mmx;
348
    return JSIMD_MMX;
349
  }
350
#endif
351
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
352
  if (cinfo->master->simd_support & JSIMD_NEON) {
353
    cinfo->downsample->h2v1_downsample_simd = jsimd_h2v1_downsample_neon;
354
    return JSIMD_NEON;
355
  }
356
#elif SIMD_ARCHITECTURE == POWERPC
357
  if (cinfo->master->simd_support & JSIMD_ALTIVEC) {
358
    cinfo->downsample->h2v1_downsample_simd = jsimd_h2v1_downsample_altivec;
359
    return JSIMD_ALTIVEC;
360
  }
361
#elif SIMD_ARCHITECTURE == RISCV64
362
  if (cinfo->master->simd_support & JSIMD_RVV) {
363
    cinfo->downsample->h2v1_downsample_simd = jsimd_h2v1_downsample_rvv;
364
    return JSIMD_RVV;
365
  }
366
#endif
367
368
0
  return JSIMD_NONE;
369
0
}
370
371
372
HIDDEN void
373
jsimd_h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
374
                      JSAMPARRAY input_data, JSAMPARRAY output_data)
375
741k
{
376
741k
  cinfo->downsample->h2v1_downsample_simd(cinfo->image_width,
377
741k
                                          cinfo->max_v_samp_factor,
378
741k
                                          compptr->v_samp_factor,
379
741k
                                          compptr->width_in_blocks, input_data,
380
741k
                                          output_data);
381
741k
}
382
383
384
HIDDEN unsigned int
385
jsimd_set_h2v2_downsample(j_compress_ptr cinfo)
386
0
{
387
0
  init_simd((j_common_ptr)cinfo);
388
389
0
  if (BITS_IN_JSAMPLE != 8)
390
0
    return JSIMD_NONE;
391
0
  if (sizeof(JDIMENSION) != 4)
392
0
    return JSIMD_NONE;
393
0
  if (!cinfo->downsample)
394
0
    return JSIMD_NONE;
395
396
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
397
0
  if (cinfo->master->simd_support & JSIMD_AVX2) {
398
0
    cinfo->downsample->h2v2_downsample_simd = jsimd_h2v2_downsample_avx2;
399
0
    return JSIMD_AVX2;
400
0
  }
401
0
  if (cinfo->master->simd_support & JSIMD_SSE2) {
402
0
    cinfo->downsample->h2v2_downsample_simd = jsimd_h2v2_downsample_sse2;
403
0
    return JSIMD_SSE2;
404
0
  }
405
#if SIMD_ARCHITECTURE == I386
406
  if (cinfo->master->simd_support & JSIMD_MMX) {
407
    cinfo->downsample->h2v2_downsample_simd = jsimd_h2v2_downsample_mmx;
408
    return JSIMD_MMX;
409
  }
410
#endif
411
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
412
  if (cinfo->master->simd_support & JSIMD_NEON) {
413
    cinfo->downsample->h2v2_downsample_simd = jsimd_h2v2_downsample_neon;
414
    return JSIMD_NEON;
415
  }
416
#elif SIMD_ARCHITECTURE == POWERPC
417
  if (cinfo->master->simd_support & JSIMD_ALTIVEC) {
418
    cinfo->downsample->h2v2_downsample_simd = jsimd_h2v2_downsample_altivec;
419
    return JSIMD_ALTIVEC;
420
  }
421
#elif SIMD_ARCHITECTURE == RISCV64
422
  if (cinfo->master->simd_support & JSIMD_RVV) {
423
    cinfo->downsample->h2v2_downsample_simd = jsimd_h2v2_downsample_rvv;
424
    return JSIMD_RVV;
425
  }
426
#elif SIMD_ARCHITECTURE == MIPS64
427
  if (cinfo->master->simd_support & JSIMD_MMI) {
428
    cinfo->downsample->h2v2_downsample_simd = jsimd_h2v2_downsample_mmi;
429
    return JSIMD_MMI;
430
  }
431
#endif
432
433
0
  return JSIMD_NONE;
434
0
}
435
436
437
HIDDEN void
438
jsimd_h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
439
                      JSAMPARRAY input_data, JSAMPARRAY output_data)
440
0
{
441
0
  cinfo->downsample->h2v2_downsample_simd(cinfo->image_width,
442
0
                                          cinfo->max_v_samp_factor,
443
0
                                          compptr->v_samp_factor,
444
0
                                          compptr->width_in_blocks, input_data,
445
0
                                          output_data);
446
0
}
447
448
449
HIDDEN unsigned int
450
jsimd_set_h2v1_upsample(j_decompress_ptr cinfo)
451
0
{
452
0
  init_simd((j_common_ptr)cinfo);
453
454
0
  if (BITS_IN_JSAMPLE != 8)
455
0
    return JSIMD_NONE;
456
0
  if (sizeof(JDIMENSION) != 4)
457
0
    return JSIMD_NONE;
458
0
  if (!cinfo->upsample)
459
0
    return JSIMD_NONE;
460
461
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
462
0
  if (cinfo->master->simd_support & JSIMD_AVX2) {
463
0
    cinfo->upsample->h2v1_upsample_simd = jsimd_h2v1_upsample_avx2;
464
0
    return JSIMD_AVX2;
465
0
  }
466
0
  if (cinfo->master->simd_support & JSIMD_SSE2) {
467
0
    cinfo->upsample->h2v1_upsample_simd = jsimd_h2v1_upsample_sse2;
468
0
    return JSIMD_SSE2;
469
0
  }
470
#if SIMD_ARCHITECTURE == I386
471
  if (cinfo->master->simd_support & JSIMD_MMX) {
472
    cinfo->upsample->h2v1_upsample_simd = jsimd_h2v1_upsample_mmx;
473
    return JSIMD_MMX;
474
  }
475
#endif
476
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
477
  if (cinfo->master->simd_support & JSIMD_NEON) {
478
    cinfo->upsample->h2v1_upsample_simd = jsimd_h2v1_upsample_neon;
479
    return JSIMD_NEON;
480
  }
481
#elif SIMD_ARCHITECTURE == POWERPC
482
  if (cinfo->master->simd_support & JSIMD_ALTIVEC) {
483
    cinfo->upsample->h2v1_upsample_simd = jsimd_h2v1_upsample_altivec;
484
    return JSIMD_ALTIVEC;
485
  }
486
#elif SIMD_ARCHITECTURE == RISCV64
487
  if (cinfo->master->simd_support & JSIMD_RVV) {
488
    cinfo->upsample->h2v1_upsample_simd = jsimd_h2v1_upsample_rvv;
489
    return JSIMD_RVV;
490
  }
491
#endif
492
493
0
  return JSIMD_NONE;
494
0
}
495
496
497
HIDDEN void
498
jsimd_h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
499
                    JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
500
0
{
501
0
  cinfo->upsample->h2v1_upsample_simd(cinfo->max_v_samp_factor,
502
0
                                      cinfo->output_width, input_data,
503
0
                                      output_data_ptr);
504
0
}
505
506
507
HIDDEN unsigned int
508
jsimd_set_h2v2_upsample(j_decompress_ptr cinfo)
509
0
{
510
0
  init_simd((j_common_ptr)cinfo);
511
512
0
  if (BITS_IN_JSAMPLE != 8)
513
0
    return JSIMD_NONE;
514
0
  if (sizeof(JDIMENSION) != 4)
515
0
    return JSIMD_NONE;
516
0
  if (!cinfo->upsample)
517
0
    return JSIMD_NONE;
518
519
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
520
0
  if (cinfo->master->simd_support & JSIMD_AVX2) {
521
0
    cinfo->upsample->h2v2_upsample_simd = jsimd_h2v2_upsample_avx2;
522
0
    return JSIMD_AVX2;
523
0
  }
524
0
  if (cinfo->master->simd_support & JSIMD_SSE2) {
525
0
    cinfo->upsample->h2v2_upsample_simd = jsimd_h2v2_upsample_sse2;
526
0
    return JSIMD_SSE2;
527
0
  }
528
#if SIMD_ARCHITECTURE == I386
529
  if (cinfo->master->simd_support & JSIMD_MMX) {
530
    cinfo->upsample->h2v2_upsample_simd = jsimd_h2v2_upsample_mmx;
531
    return JSIMD_MMX;
532
  }
533
#endif
534
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
535
  if (cinfo->master->simd_support & JSIMD_NEON) {
536
    cinfo->upsample->h2v2_upsample_simd = jsimd_h2v2_upsample_neon;
537
    return JSIMD_NEON;
538
  }
539
#elif SIMD_ARCHITECTURE == POWERPC
540
  if (cinfo->master->simd_support & JSIMD_ALTIVEC) {
541
    cinfo->upsample->h2v2_upsample_simd = jsimd_h2v2_upsample_altivec;
542
    return JSIMD_ALTIVEC;
543
  }
544
#elif SIMD_ARCHITECTURE == RISCV64
545
  if (cinfo->master->simd_support & JSIMD_RVV) {
546
    cinfo->upsample->h2v2_upsample_simd = jsimd_h2v2_upsample_rvv;
547
    return JSIMD_RVV;
548
  }
549
#endif
550
551
0
  return JSIMD_NONE;
552
0
}
553
554
555
HIDDEN void
556
jsimd_h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
557
                    JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
558
0
{
559
0
  cinfo->upsample->h2v2_upsample_simd(cinfo->max_v_samp_factor,
560
0
                                      cinfo->output_width, input_data,
561
0
                                      output_data_ptr);
562
0
}
563
564
565
HIDDEN unsigned int
566
jsimd_set_h2v1_fancy_upsample(j_decompress_ptr cinfo)
567
0
{
568
0
  init_simd((j_common_ptr)cinfo);
569
570
0
  if (BITS_IN_JSAMPLE != 8)
571
0
    return JSIMD_NONE;
572
0
  if (sizeof(JDIMENSION) != 4)
573
0
    return JSIMD_NONE;
574
0
  if (!cinfo->upsample)
575
0
    return JSIMD_NONE;
576
577
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
578
0
  if ((cinfo->master->simd_support & JSIMD_AVX2) &&
579
0
      IS_ALIGNED_AVX(jconst_fancy_upsample_avx2)) {
580
0
    cinfo->upsample->h2v1_upsample_simd = jsimd_h2v1_fancy_upsample_avx2;
581
0
    return JSIMD_AVX2;
582
0
  }
583
0
  if ((cinfo->master->simd_support & JSIMD_SSE2) &&
584
0
      IS_ALIGNED_SSE(jconst_fancy_upsample_sse2)) {
585
0
    cinfo->upsample->h2v1_upsample_simd = jsimd_h2v1_fancy_upsample_sse2;
586
0
    return JSIMD_SSE2;
587
0
  }
588
#if SIMD_ARCHITECTURE == I386
589
  if (cinfo->master->simd_support & JSIMD_MMX) {
590
    cinfo->upsample->h2v1_upsample_simd = jsimd_h2v1_fancy_upsample_mmx;
591
    return JSIMD_MMX;
592
  }
593
#endif
594
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
595
  if (cinfo->master->simd_support & JSIMD_NEON) {
596
    cinfo->upsample->h2v1_upsample_simd = jsimd_h2v1_fancy_upsample_neon;
597
    return JSIMD_NEON;
598
  }
599
#elif SIMD_ARCHITECTURE == POWERPC
600
  if (cinfo->master->simd_support & JSIMD_ALTIVEC) {
601
    cinfo->upsample->h2v1_upsample_simd = jsimd_h2v1_fancy_upsample_altivec;
602
    return JSIMD_ALTIVEC;
603
  }
604
#elif SIMD_ARCHITECTURE == RISCV64
605
  if (cinfo->master->simd_support & JSIMD_RVV) {
606
    cinfo->upsample->h2v1_upsample_simd = jsimd_h2v1_fancy_upsample_rvv;
607
    return JSIMD_RVV;
608
  }
609
#elif SIMD_ARCHITECTURE == MIPS64
610
  if (cinfo->master->simd_support & JSIMD_MMI) {
611
    cinfo->upsample->h2v1_upsample_simd = jsimd_h2v1_fancy_upsample_mmi;
612
    return JSIMD_MMI;
613
  }
614
#endif
615
616
0
  return JSIMD_NONE;
617
0
}
618
619
620
HIDDEN void
621
jsimd_h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
622
                          JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
623
0
{
624
0
  cinfo->upsample->h2v1_upsample_simd(cinfo->max_v_samp_factor,
625
0
                                      compptr->downsampled_width, input_data,
626
0
                                      output_data_ptr);
627
0
}
628
629
630
HIDDEN unsigned int
631
jsimd_set_h2v2_fancy_upsample(j_decompress_ptr cinfo)
632
0
{
633
0
  init_simd((j_common_ptr)cinfo);
634
635
0
  if (BITS_IN_JSAMPLE != 8)
636
0
    return JSIMD_NONE;
637
0
  if (sizeof(JDIMENSION) != 4)
638
0
    return JSIMD_NONE;
639
0
  if (!cinfo->upsample)
640
0
    return JSIMD_NONE;
641
642
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
643
0
  if ((cinfo->master->simd_support & JSIMD_AVX2) &&
644
0
      IS_ALIGNED_AVX(jconst_fancy_upsample_avx2)) {
645
0
    cinfo->upsample->h2v2_upsample_simd = jsimd_h2v2_fancy_upsample_avx2;
646
0
    return JSIMD_AVX2;
647
0
  }
648
0
  if ((cinfo->master->simd_support & JSIMD_SSE2) &&
649
0
      IS_ALIGNED_SSE(jconst_fancy_upsample_sse2)) {
650
0
    cinfo->upsample->h2v2_upsample_simd = jsimd_h2v2_fancy_upsample_sse2;
651
0
    return JSIMD_SSE2;
652
0
  }
653
#if SIMD_ARCHITECTURE == I386
654
  if (cinfo->master->simd_support & JSIMD_MMX) {
655
    cinfo->upsample->h2v2_upsample_simd = jsimd_h2v2_fancy_upsample_mmx;
656
    return JSIMD_MMX;
657
  }
658
#endif
659
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
660
  if (cinfo->master->simd_support & JSIMD_NEON) {
661
    cinfo->upsample->h2v2_upsample_simd = jsimd_h2v2_fancy_upsample_neon;
662
    return JSIMD_NEON;
663
  }
664
#elif SIMD_ARCHITECTURE == POWERPC
665
  if (cinfo->master->simd_support & JSIMD_ALTIVEC) {
666
    cinfo->upsample->h2v2_upsample_simd = jsimd_h2v2_fancy_upsample_altivec;
667
    return JSIMD_ALTIVEC;
668
  }
669
#elif SIMD_ARCHITECTURE == RISCV64
670
  if (cinfo->master->simd_support & JSIMD_RVV) {
671
    cinfo->upsample->h2v2_upsample_simd = jsimd_h2v2_fancy_upsample_rvv;
672
    return JSIMD_RVV;
673
  }
674
#elif SIMD_ARCHITECTURE == MIPS64
675
  if (cinfo->master->simd_support & JSIMD_MMI) {
676
    cinfo->upsample->h2v2_upsample_simd = jsimd_h2v2_fancy_upsample_mmi;
677
    return JSIMD_MMI;
678
  }
679
#endif
680
681
0
  return JSIMD_NONE;
682
0
}
683
684
685
HIDDEN void
686
jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
687
                          JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
688
0
{
689
0
  cinfo->upsample->h2v2_upsample_simd(cinfo->max_v_samp_factor,
690
0
                                      compptr->downsampled_width, input_data,
691
0
                                      output_data_ptr);
692
0
}
693
694
695
#if SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
696
697
HIDDEN unsigned int
698
jsimd_set_h1v2_fancy_upsample(j_decompress_ptr cinfo)
699
{
700
  init_simd((j_common_ptr)cinfo);
701
702
  if (BITS_IN_JSAMPLE != 8)
703
    return JSIMD_NONE;
704
  if (sizeof(JDIMENSION) != 4)
705
    return JSIMD_NONE;
706
  if (!cinfo->upsample)
707
    return JSIMD_NONE;
708
709
  if (cinfo->master->simd_support & JSIMD_NEON) {
710
    cinfo->upsample->h1v2_upsample_simd = jsimd_h1v2_fancy_upsample_neon;
711
    return JSIMD_NEON;
712
  }
713
714
  return JSIMD_NONE;
715
}
716
717
718
HIDDEN void
719
jsimd_h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
720
                          JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
721
{
722
  cinfo->upsample->h1v2_upsample_simd(cinfo->max_v_samp_factor,
723
                                      compptr->downsampled_width, input_data,
724
                                      output_data_ptr);
725
}
726
727
#endif
728
729
730
HIDDEN unsigned int
731
jsimd_set_h2v1_merged_upsample(j_decompress_ptr cinfo)
732
0
{
733
0
  init_simd((j_common_ptr)cinfo);
734
735
0
  if (BITS_IN_JSAMPLE != 8)
736
0
    return JSIMD_NONE;
737
0
  if (sizeof(JDIMENSION) != 4)
738
0
    return JSIMD_NONE;
739
0
  if (!cinfo->upsample)
740
0
    return JSIMD_NONE;
741
742
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
743
0
  if ((cinfo->master->simd_support & JSIMD_AVX2) &&
744
0
      IS_ALIGNED_AVX(jconst_merged_upsample_avx2)) {
745
0
    SET_SIMD_EXTRGB_MERGED_UPSAMPLER(h2v1, avx2);
746
0
    return JSIMD_AVX2;
747
0
  }
748
0
  if ((cinfo->master->simd_support & JSIMD_SSE2) &&
749
0
      IS_ALIGNED_SSE(jconst_merged_upsample_sse2)) {
750
0
    SET_SIMD_EXTRGB_MERGED_UPSAMPLER(h2v1, sse2);
751
0
    return JSIMD_SSE2;
752
0
  }
753
#if SIMD_ARCHITECTURE == I386
754
  if (cinfo->master->simd_support & JSIMD_MMX) {
755
    SET_SIMD_EXTRGB_MERGED_UPSAMPLER(h2v1, mmx);
756
    return JSIMD_MMX;
757
  }
758
#endif
759
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
760
  if (cinfo->master->simd_support & JSIMD_NEON) {
761
    SET_SIMD_EXTRGB_MERGED_UPSAMPLER(h2v1, neon);
762
    return JSIMD_NEON;
763
  }
764
#elif SIMD_ARCHITECTURE == POWERPC
765
  if (cinfo->master->simd_support & JSIMD_ALTIVEC) {
766
    SET_SIMD_EXTRGB_MERGED_UPSAMPLER(h2v1, altivec);
767
    return JSIMD_ALTIVEC;
768
  }
769
#elif SIMD_ARCHITECTURE == RISCV64
770
  if (cinfo->master->simd_support & JSIMD_RVV) {
771
    SET_SIMD_EXTRGB_MERGED_UPSAMPLER(h2v1, rvv);
772
    return JSIMD_RVV;
773
  }
774
#elif SIMD_ARCHITECTURE == MIPS64
775
  if (cinfo->master->simd_support & JSIMD_MMI) {
776
    SET_SIMD_EXTRGB_MERGED_UPSAMPLER(h2v1, mmi);
777
    return JSIMD_MMI;
778
  }
779
#endif
780
781
0
  return JSIMD_NONE;
782
0
}
783
784
785
HIDDEN void
786
jsimd_h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
787
                           JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
788
0
{
789
0
  cinfo->upsample->merged_upsample_simd(cinfo->output_width, input_buf,
790
0
                                        in_row_group_ctr, output_buf);
791
0
}
792
793
794
HIDDEN unsigned int
795
jsimd_set_h2v2_merged_upsample(j_decompress_ptr cinfo)
796
0
{
797
0
  init_simd((j_common_ptr)cinfo);
798
799
0
  if (BITS_IN_JSAMPLE != 8)
800
0
    return JSIMD_NONE;
801
0
  if (sizeof(JDIMENSION) != 4)
802
0
    return JSIMD_NONE;
803
0
  if (!cinfo->upsample)
804
0
    return JSIMD_NONE;
805
806
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
807
0
  if ((cinfo->master->simd_support & JSIMD_AVX2) &&
808
0
      IS_ALIGNED_AVX(jconst_merged_upsample_avx2)) {
809
0
    SET_SIMD_EXTRGB_MERGED_UPSAMPLER(h2v2, avx2);
810
0
    return JSIMD_AVX2;
811
0
  }
812
0
  if ((cinfo->master->simd_support & JSIMD_SSE2) &&
813
0
      IS_ALIGNED_SSE(jconst_merged_upsample_sse2)) {
814
0
    SET_SIMD_EXTRGB_MERGED_UPSAMPLER(h2v2, sse2);
815
0
    return JSIMD_SSE2;
816
0
  }
817
#if SIMD_ARCHITECTURE == I386
818
  if (cinfo->master->simd_support & JSIMD_MMX) {
819
    SET_SIMD_EXTRGB_MERGED_UPSAMPLER(h2v2, mmx);
820
    return JSIMD_MMX;
821
  }
822
#endif
823
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
824
  if (cinfo->master->simd_support & JSIMD_NEON) {
825
    SET_SIMD_EXTRGB_MERGED_UPSAMPLER(h2v2, neon);
826
    return JSIMD_NEON;
827
  }
828
#elif SIMD_ARCHITECTURE == POWERPC
829
  if (cinfo->master->simd_support & JSIMD_ALTIVEC) {
830
    SET_SIMD_EXTRGB_MERGED_UPSAMPLER(h2v2, altivec);
831
    return JSIMD_ALTIVEC;
832
  }
833
#elif SIMD_ARCHITECTURE == RISCV64
834
  if (cinfo->master->simd_support & JSIMD_RVV) {
835
    SET_SIMD_EXTRGB_MERGED_UPSAMPLER(h2v2, rvv);
836
    return JSIMD_RVV;
837
  }
838
#elif SIMD_ARCHITECTURE == MIPS64
839
  if (cinfo->master->simd_support & JSIMD_MMI) {
840
    SET_SIMD_EXTRGB_MERGED_UPSAMPLER(h2v2, mmi);
841
    return JSIMD_MMI;
842
  }
843
#endif
844
845
0
  return JSIMD_NONE;
846
0
}
847
848
849
HIDDEN void
850
jsimd_h2v2_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
851
                           JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
852
0
{
853
0
  cinfo->upsample->merged_upsample_simd(cinfo->output_width, input_buf,
854
0
                                        in_row_group_ctr, output_buf);
855
0
}
856
857
858
HIDDEN unsigned int
859
jsimd_set_convsamp(j_compress_ptr cinfo, convsamp_method_ptr *method)
860
0
{
861
0
  init_simd((j_common_ptr)cinfo);
862
863
0
  if (BITS_IN_JSAMPLE != 8)
864
0
    return JSIMD_NONE;
865
0
  if (sizeof(JDIMENSION) != 4)
866
0
    return JSIMD_NONE;
867
0
  if (sizeof(DCTELEM) != 2)
868
0
    return JSIMD_NONE;
869
870
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
871
0
  if (cinfo->master->simd_support & JSIMD_AVX2) {
872
0
    *method = jsimd_convsamp_avx2;
873
0
    return JSIMD_AVX2;
874
0
  }
875
0
  if (cinfo->master->simd_support & JSIMD_SSE2) {
876
0
    *method = jsimd_convsamp_sse2;
877
0
    return JSIMD_SSE2;
878
0
  }
879
#if SIMD_ARCHITECTURE == I386
880
  if (cinfo->master->simd_support & JSIMD_MMX) {
881
    *method = jsimd_convsamp_mmx;
882
    return JSIMD_MMX;
883
  }
884
#endif
885
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
886
  if (cinfo->master->simd_support & JSIMD_NEON) {
887
    *method = jsimd_convsamp_neon;
888
    return JSIMD_NEON;
889
  }
890
#elif SIMD_ARCHITECTURE == POWERPC
891
  if (cinfo->master->simd_support & JSIMD_ALTIVEC) {
892
    *method = jsimd_convsamp_altivec;
893
    return JSIMD_ALTIVEC;
894
  }
895
#elif SIMD_ARCHITECTURE == RISCV64
896
  if (cinfo->master->simd_support & JSIMD_RVV) {
897
    *method = jsimd_convsamp_rvv;
898
    return JSIMD_RVV;
899
  }
900
#endif
901
902
0
  return JSIMD_NONE;
903
0
}
904
905
906
HIDDEN unsigned int
907
jsimd_set_convsamp_float(j_compress_ptr cinfo,
908
                         float_convsamp_method_ptr *method)
909
2.63k
{
910
2.63k
  init_simd((j_common_ptr)cinfo);
911
912
2.63k
  if (BITS_IN_JSAMPLE != 8)
913
0
    return JSIMD_NONE;
914
2.63k
  if (sizeof(JDIMENSION) != 4)
915
0
    return JSIMD_NONE;
916
2.63k
  if (sizeof(FAST_FLOAT) != 4)
917
0
    return JSIMD_NONE;
918
919
2.63k
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
920
2.63k
  if (cinfo->master->simd_support & JSIMD_SSE2) {
921
2.63k
    *method = jsimd_convsamp_float_sse2;
922
2.63k
    return JSIMD_SSE2;
923
2.63k
  }
924
#if SIMD_ARCHITECTURE == I386
925
  if (cinfo->master->simd_support & JSIMD_SSE) {
926
    *method = jsimd_convsamp_float_sse;
927
    return JSIMD_SSE;
928
  }
929
  if (cinfo->master->simd_support & JSIMD_3DNOW) {
930
    *method = jsimd_convsamp_float_3dnow;
931
    return JSIMD_3DNOW;
932
  }
933
#endif
934
0
#endif
935
936
0
  return JSIMD_NONE;
937
2.63k
}
938
939
940
HIDDEN unsigned int
941
jsimd_set_fdct_islow(j_compress_ptr cinfo, forward_DCT_method_ptr *method)
942
0
{
943
0
  init_simd((j_common_ptr)cinfo);
944
945
0
  if (sizeof(DCTELEM) != 2)
946
0
    return JSIMD_NONE;
947
948
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
949
0
  if ((cinfo->master->simd_support & JSIMD_AVX2) &&
950
0
      IS_ALIGNED_AVX(jconst_fdct_islow_avx2)) {
951
0
    *method = jsimd_fdct_islow_avx2;
952
0
    return JSIMD_AVX2;
953
0
  }
954
0
  if ((cinfo->master->simd_support & JSIMD_SSE2) &&
955
0
      IS_ALIGNED_SSE(jconst_fdct_islow_sse2)) {
956
0
    *method = jsimd_fdct_islow_sse2;
957
0
    return JSIMD_SSE2;
958
0
  }
959
#if SIMD_ARCHITECTURE == I386
960
  if (cinfo->master->simd_support & JSIMD_MMX) {
961
    *method = jsimd_fdct_islow_mmx;
962
    return JSIMD_MMX;
963
  }
964
#endif
965
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
966
  if (cinfo->master->simd_support & JSIMD_NEON) {
967
    *method = jsimd_fdct_islow_neon;
968
    return JSIMD_NEON;
969
  }
970
#elif SIMD_ARCHITECTURE == POWERPC
971
  if (cinfo->master->simd_support & JSIMD_ALTIVEC) {
972
    *method = jsimd_fdct_islow_altivec;
973
    return JSIMD_ALTIVEC;
974
  }
975
#elif SIMD_ARCHITECTURE == RISCV64
976
  if (cinfo->master->simd_support & JSIMD_RVV) {
977
    *method = jsimd_fdct_islow_rvv;
978
    return JSIMD_RVV;
979
  }
980
#elif SIMD_ARCHITECTURE == MIPS64
981
  if (cinfo->master->simd_support & JSIMD_MMI) {
982
    *method = jsimd_fdct_islow_mmi;
983
    return JSIMD_MMI;
984
  }
985
#endif
986
987
0
  return JSIMD_NONE;
988
0
}
989
990
991
HIDDEN unsigned int
992
jsimd_set_fdct_ifast(j_compress_ptr cinfo, forward_DCT_method_ptr *method)
993
0
{
994
0
  init_simd((j_common_ptr)cinfo);
995
996
0
  if (sizeof(DCTELEM) != 2)
997
0
    return JSIMD_NONE;
998
999
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
1000
0
  if ((cinfo->master->simd_support & JSIMD_SSE2) &&
1001
0
      IS_ALIGNED_SSE(jconst_fdct_ifast_sse2)) {
1002
0
    *method = jsimd_fdct_ifast_sse2;
1003
0
    return JSIMD_SSE2;
1004
0
  }
1005
#if SIMD_ARCHITECTURE == I386
1006
  if (cinfo->master->simd_support & JSIMD_MMX) {
1007
    *method = jsimd_fdct_ifast_mmx;
1008
    return JSIMD_MMX;
1009
  }
1010
#endif
1011
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
1012
  if (cinfo->master->simd_support & JSIMD_NEON) {
1013
    *method = jsimd_fdct_ifast_neon;
1014
    return JSIMD_NEON;
1015
  }
1016
#elif SIMD_ARCHITECTURE == POWERPC
1017
  if (cinfo->master->simd_support & JSIMD_ALTIVEC) {
1018
    *method = jsimd_fdct_ifast_altivec;
1019
    return JSIMD_ALTIVEC;
1020
  }
1021
#elif SIMD_ARCHITECTURE == RISCV64
1022
  if (cinfo->master->simd_support & JSIMD_RVV) {
1023
    *method = jsimd_fdct_ifast_rvv;
1024
    return JSIMD_RVV;
1025
  }
1026
#elif SIMD_ARCHITECTURE == MIPS64
1027
  if (cinfo->master->simd_support & JSIMD_MMI) {
1028
    *method = jsimd_fdct_ifast_mmi;
1029
    return JSIMD_MMI;
1030
  }
1031
#endif
1032
1033
0
  return JSIMD_NONE;
1034
0
}
1035
1036
1037
HIDDEN unsigned int
1038
jsimd_set_fdct_float(j_compress_ptr cinfo, float_DCT_method_ptr *method)
1039
2.63k
{
1040
2.63k
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
1041
2.63k
  init_simd((j_common_ptr)cinfo);
1042
1043
2.63k
  if (sizeof(FAST_FLOAT) != 4)
1044
0
    return JSIMD_NONE;
1045
1046
2.63k
  if ((cinfo->master->simd_support & JSIMD_SSE) &&
1047
2.63k
      IS_ALIGNED_SSE(jconst_fdct_float_sse)) {
1048
2.63k
    *method = jsimd_fdct_float_sse;
1049
2.63k
    return JSIMD_SSE;
1050
2.63k
  }
1051
#if SIMD_ARCHITECTURE == I386
1052
  if (cinfo->master->simd_support & JSIMD_3DNOW) {
1053
    *method = jsimd_fdct_float_3dnow;
1054
    return JSIMD_3DNOW;
1055
  }
1056
#endif
1057
0
#endif
1058
1059
0
  return JSIMD_NONE;
1060
2.63k
}
1061
1062
1063
HIDDEN unsigned int
1064
jsimd_set_quantize(j_compress_ptr cinfo, quantize_method_ptr *method)
1065
0
{
1066
0
  init_simd((j_common_ptr)cinfo);
1067
1068
0
  if (sizeof(JCOEF) != 2)
1069
0
    return JSIMD_NONE;
1070
0
  if (sizeof(DCTELEM) != 2)
1071
0
    return JSIMD_NONE;
1072
1073
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
1074
0
  if (cinfo->master->simd_support & JSIMD_AVX2) {
1075
0
    *method = jsimd_quantize_avx2;
1076
0
    return JSIMD_AVX2;
1077
0
  }
1078
0
  if (cinfo->master->simd_support & JSIMD_SSE2) {
1079
0
    *method = jsimd_quantize_sse2;
1080
0
    return JSIMD_SSE2;
1081
0
  }
1082
#if SIMD_ARCHITECTURE == I386
1083
  if (cinfo->master->simd_support & JSIMD_MMX) {
1084
    *method = jsimd_quantize_mmx;
1085
    return JSIMD_MMX;
1086
  }
1087
#endif
1088
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
1089
  if (cinfo->master->simd_support & JSIMD_NEON) {
1090
    *method = jsimd_quantize_neon;
1091
    return JSIMD_NEON;
1092
  }
1093
#elif SIMD_ARCHITECTURE == POWERPC
1094
  if (cinfo->master->simd_support & JSIMD_ALTIVEC) {
1095
    *method = jsimd_quantize_altivec;
1096
    return JSIMD_ALTIVEC;
1097
  }
1098
#elif SIMD_ARCHITECTURE == RISCV64
1099
  if (cinfo->master->simd_support & JSIMD_RVV) {
1100
    *method = jsimd_quantize_rvv;
1101
    return JSIMD_RVV;
1102
  }
1103
#elif SIMD_ARCHITECTURE == MIPS64
1104
  if (cinfo->master->simd_support & JSIMD_MMI) {
1105
    *method = jsimd_quantize_mmi;
1106
    return JSIMD_MMI;
1107
  }
1108
#endif
1109
1110
0
  return JSIMD_NONE;
1111
0
}
1112
1113
1114
HIDDEN unsigned int
1115
jsimd_set_quantize_float(j_compress_ptr cinfo,
1116
                         float_quantize_method_ptr *method)
1117
2.63k
{
1118
2.63k
  init_simd((j_common_ptr)cinfo);
1119
1120
2.63k
  if (sizeof(JCOEF) != 2)
1121
0
    return JSIMD_NONE;
1122
2.63k
  if (sizeof(FAST_FLOAT) != 4)
1123
0
    return JSIMD_NONE;
1124
1125
2.63k
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
1126
2.63k
  if (cinfo->master->simd_support & JSIMD_SSE2) {
1127
2.63k
    *method = jsimd_quantize_float_sse2;
1128
2.63k
    return JSIMD_SSE2;
1129
2.63k
  }
1130
#if SIMD_ARCHITECTURE == I386
1131
  if (cinfo->master->simd_support & JSIMD_SSE) {
1132
    *method = jsimd_quantize_float_sse;
1133
    return JSIMD_SSE;
1134
  }
1135
  if (cinfo->master->simd_support & JSIMD_3DNOW) {
1136
    *method = jsimd_quantize_float_3dnow;
1137
    return JSIMD_3DNOW;
1138
  }
1139
#endif
1140
0
#endif
1141
1142
0
  return JSIMD_NONE;
1143
2.63k
}
1144
1145
1146
HIDDEN unsigned int
1147
jsimd_set_idct_islow(j_decompress_ptr cinfo)
1148
0
{
1149
0
  init_simd((j_common_ptr)cinfo);
1150
1151
0
  if (sizeof(JCOEF) != 2)
1152
0
    return JSIMD_NONE;
1153
0
  if (BITS_IN_JSAMPLE != 8)
1154
0
    return JSIMD_NONE;
1155
0
  if (sizeof(JDIMENSION) != 4)
1156
0
    return JSIMD_NONE;
1157
0
  if (sizeof(ISLOW_MULT_TYPE) != 2)
1158
0
    return JSIMD_NONE;
1159
0
  if (!cinfo->idct)
1160
0
    return JSIMD_NONE;
1161
1162
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
1163
0
  if ((cinfo->master->simd_support & JSIMD_AVX2) &&
1164
0
      IS_ALIGNED_AVX(jconst_idct_islow_avx2)) {
1165
0
    cinfo->idct->idct_simd = jsimd_idct_islow_avx2;
1166
0
    return JSIMD_AVX2;
1167
0
  }
1168
0
  if ((cinfo->master->simd_support & JSIMD_SSE2) &&
1169
0
      IS_ALIGNED_SSE(jconst_idct_islow_sse2)) {
1170
0
    cinfo->idct->idct_simd = jsimd_idct_islow_sse2;
1171
0
    return JSIMD_SSE2;
1172
0
  }
1173
#if SIMD_ARCHITECTURE == I386
1174
  if (cinfo->master->simd_support & JSIMD_MMX) {
1175
    cinfo->idct->idct_simd = jsimd_idct_islow_mmx;
1176
    return JSIMD_MMX;
1177
  }
1178
#endif
1179
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
1180
  if (cinfo->master->simd_support & JSIMD_NEON) {
1181
    cinfo->idct->idct_simd = jsimd_idct_islow_neon;
1182
    return JSIMD_NEON;
1183
  }
1184
#elif SIMD_ARCHITECTURE == POWERPC
1185
  if (cinfo->master->simd_support & JSIMD_ALTIVEC) {
1186
    cinfo->idct->idct_simd = jsimd_idct_islow_altivec;
1187
    return JSIMD_ALTIVEC;
1188
  }
1189
#elif SIMD_ARCHITECTURE == RISCV64
1190
  if (cinfo->master->simd_support & JSIMD_RVV) {
1191
    cinfo->idct->idct_simd = jsimd_idct_islow_rvv;
1192
    return JSIMD_RVV;
1193
  }
1194
#elif SIMD_ARCHITECTURE == MIPS64
1195
  if (cinfo->master->simd_support & JSIMD_MMI) {
1196
    cinfo->idct->idct_simd = jsimd_idct_islow_mmi;
1197
    return JSIMD_MMI;
1198
  }
1199
#endif
1200
1201
0
  return JSIMD_NONE;
1202
0
}
1203
1204
1205
HIDDEN void
1206
jsimd_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
1207
                 JCOEFPTR coef_block, JSAMPARRAY output_buf,
1208
                 JDIMENSION output_col)
1209
0
{
1210
0
  cinfo->idct->idct_simd(compptr->dct_table, coef_block, output_buf,
1211
0
                         output_col);
1212
0
}
1213
1214
1215
HIDDEN unsigned int
1216
jsimd_set_idct_ifast(j_decompress_ptr cinfo)
1217
0
{
1218
0
  init_simd((j_common_ptr)cinfo);
1219
1220
0
  if (sizeof(JCOEF) != 2)
1221
0
    return JSIMD_NONE;
1222
0
  if (BITS_IN_JSAMPLE != 8)
1223
0
    return JSIMD_NONE;
1224
0
  if (sizeof(JDIMENSION) != 4)
1225
0
    return JSIMD_NONE;
1226
0
  if (sizeof(IFAST_MULT_TYPE) != 2)
1227
0
    return JSIMD_NONE;
1228
0
  if (IFAST_SCALE_BITS != 2)
1229
0
    return JSIMD_NONE;
1230
0
  if (!cinfo->idct)
1231
0
    return JSIMD_NONE;
1232
1233
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
1234
0
  if ((cinfo->master->simd_support & JSIMD_SSE2) &&
1235
0
      IS_ALIGNED_SSE(jconst_idct_ifast_sse2)) {
1236
0
    cinfo->idct->idct_simd = jsimd_idct_ifast_sse2;
1237
0
    return JSIMD_SSE2;
1238
0
  }
1239
#if SIMD_ARCHITECTURE == I386
1240
  if (cinfo->master->simd_support & JSIMD_MMX) {
1241
    cinfo->idct->idct_simd = jsimd_idct_ifast_mmx;
1242
    return JSIMD_MMX;
1243
  }
1244
#endif
1245
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
1246
  if (cinfo->master->simd_support & JSIMD_NEON) {
1247
    cinfo->idct->idct_simd = jsimd_idct_ifast_neon;
1248
    return JSIMD_NEON;
1249
  }
1250
#elif SIMD_ARCHITECTURE == POWERPC
1251
  if (cinfo->master->simd_support & JSIMD_ALTIVEC) {
1252
    cinfo->idct->idct_simd = jsimd_idct_ifast_altivec;
1253
    return JSIMD_ALTIVEC;
1254
  }
1255
#elif SIMD_ARCHITECTURE == RISCV64
1256
  if (cinfo->master->simd_support & JSIMD_RVV) {
1257
    cinfo->idct->idct_simd = jsimd_idct_ifast_rvv;
1258
    return JSIMD_RVV;
1259
  }
1260
#elif SIMD_ARCHITECTURE == MIPS64
1261
  if (cinfo->master->simd_support & JSIMD_MMI) {
1262
    cinfo->idct->idct_simd = jsimd_idct_ifast_mmi;
1263
    return JSIMD_MMI;
1264
  }
1265
#endif
1266
1267
0
  return JSIMD_NONE;
1268
0
}
1269
1270
1271
HIDDEN void
1272
jsimd_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
1273
                 JCOEFPTR coef_block, JSAMPARRAY output_buf,
1274
                 JDIMENSION output_col)
1275
0
{
1276
0
  cinfo->idct->idct_simd(compptr->dct_table, coef_block, output_buf,
1277
0
                         output_col);
1278
0
}
1279
1280
1281
HIDDEN unsigned int
1282
jsimd_set_idct_float(j_decompress_ptr cinfo)
1283
0
{
1284
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
1285
0
  init_simd((j_common_ptr)cinfo);
1286
1287
0
  if (sizeof(JCOEF) != 2)
1288
0
    return JSIMD_NONE;
1289
0
  if (BITS_IN_JSAMPLE != 8)
1290
0
    return JSIMD_NONE;
1291
0
  if (sizeof(JDIMENSION) != 4)
1292
0
    return JSIMD_NONE;
1293
0
  if (sizeof(FAST_FLOAT) != 4)
1294
0
    return JSIMD_NONE;
1295
0
  if (sizeof(FLOAT_MULT_TYPE) != 4)
1296
0
    return JSIMD_NONE;
1297
0
  if (!cinfo->idct)
1298
0
    return JSIMD_NONE;
1299
1300
0
  if ((cinfo->master->simd_support & JSIMD_SSE2) &&
1301
0
      IS_ALIGNED_SSE(jconst_idct_float_sse2)) {
1302
0
    cinfo->idct->idct_simd = jsimd_idct_float_sse2;
1303
0
    return JSIMD_SSE2;
1304
0
  }
1305
#if SIMD_ARCHITECTURE == I386
1306
  if ((cinfo->master->simd_support & JSIMD_SSE) &&
1307
      IS_ALIGNED_SSE(jconst_idct_float_sse)) {
1308
    cinfo->idct->idct_simd = jsimd_idct_float_sse;
1309
    return JSIMD_SSE;
1310
  }
1311
  if (cinfo->master->simd_support & JSIMD_3DNOW) {
1312
    cinfo->idct->idct_simd = jsimd_idct_float_3dnow;
1313
    return JSIMD_3DNOW;
1314
  }
1315
#endif
1316
0
#endif
1317
1318
0
  return JSIMD_NONE;
1319
0
}
1320
1321
1322
HIDDEN void
1323
jsimd_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
1324
                 JCOEFPTR coef_block, JSAMPARRAY output_buf,
1325
                 JDIMENSION output_col)
1326
0
{
1327
0
  cinfo->idct->idct_simd(compptr->dct_table, coef_block, output_buf,
1328
0
                         output_col);
1329
0
}
1330
1331
1332
HIDDEN unsigned int
1333
jsimd_set_idct_2x2(j_decompress_ptr cinfo)
1334
0
{
1335
0
  init_simd((j_common_ptr)cinfo);
1336
1337
0
  if (sizeof(JCOEF) != 2)
1338
0
    return JSIMD_NONE;
1339
0
  if (BITS_IN_JSAMPLE != 8)
1340
0
    return JSIMD_NONE;
1341
0
  if (sizeof(JDIMENSION) != 4)
1342
0
    return JSIMD_NONE;
1343
0
  if (sizeof(ISLOW_MULT_TYPE) != 2)
1344
0
    return JSIMD_NONE;
1345
0
  if (!cinfo->idct)
1346
0
    return JSIMD_NONE;
1347
1348
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
1349
0
  if ((cinfo->master->simd_support & JSIMD_SSE2) &&
1350
0
      IS_ALIGNED_SSE(jconst_idct_red_sse2)) {
1351
0
    cinfo->idct->idct_2x2_simd = jsimd_idct_2x2_sse2;
1352
0
    return JSIMD_SSE2;
1353
0
  }
1354
#if SIMD_ARCHITECTURE == I386
1355
  if (cinfo->master->simd_support & JSIMD_MMX) {
1356
    cinfo->idct->idct_2x2_simd = jsimd_idct_2x2_mmx;
1357
    return JSIMD_MMX;
1358
  }
1359
#endif
1360
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
1361
  if (cinfo->master->simd_support & JSIMD_NEON) {
1362
    cinfo->idct->idct_2x2_simd = jsimd_idct_2x2_neon;
1363
    return JSIMD_NEON;
1364
  }
1365
#endif
1366
1367
0
  return JSIMD_NONE;
1368
0
}
1369
1370
1371
HIDDEN void
1372
jsimd_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
1373
               JCOEFPTR coef_block, JSAMPARRAY output_buf,
1374
               JDIMENSION output_col)
1375
0
{
1376
0
  cinfo->idct->idct_2x2_simd(compptr->dct_table, coef_block, output_buf,
1377
0
                             output_col);
1378
0
}
1379
1380
1381
HIDDEN unsigned int
1382
jsimd_set_idct_4x4(j_decompress_ptr cinfo)
1383
0
{
1384
0
  init_simd((j_common_ptr)cinfo);
1385
1386
0
  if (sizeof(JCOEF) != 2)
1387
0
    return JSIMD_NONE;
1388
0
  if (BITS_IN_JSAMPLE != 8)
1389
0
    return JSIMD_NONE;
1390
0
  if (sizeof(JDIMENSION) != 4)
1391
0
    return JSIMD_NONE;
1392
0
  if (sizeof(ISLOW_MULT_TYPE) != 2)
1393
0
    return JSIMD_NONE;
1394
0
  if (!cinfo->idct)
1395
0
    return JSIMD_NONE;
1396
1397
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
1398
0
  if ((cinfo->master->simd_support & JSIMD_SSE2) &&
1399
0
      IS_ALIGNED_SSE(jconst_idct_red_sse2)) {
1400
0
    cinfo->idct->idct_4x4_simd = jsimd_idct_4x4_sse2;
1401
0
    return JSIMD_SSE2;
1402
0
  }
1403
#if SIMD_ARCHITECTURE == I386
1404
  if (cinfo->master->simd_support & JSIMD_MMX) {
1405
    cinfo->idct->idct_4x4_simd = jsimd_idct_4x4_mmx;
1406
    return JSIMD_MMX;
1407
  }
1408
#endif
1409
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
1410
  if (cinfo->master->simd_support & JSIMD_NEON) {
1411
    cinfo->idct->idct_4x4_simd = jsimd_idct_4x4_neon;
1412
    return JSIMD_NEON;
1413
  }
1414
#endif
1415
1416
0
  return JSIMD_NONE;
1417
0
}
1418
1419
1420
HIDDEN void
1421
jsimd_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
1422
               JCOEFPTR coef_block, JSAMPARRAY output_buf,
1423
               JDIMENSION output_col)
1424
0
{
1425
0
  cinfo->idct->idct_4x4_simd(compptr->dct_table, coef_block, output_buf,
1426
0
                             output_col);
1427
0
}
1428
1429
1430
HIDDEN unsigned int
1431
jsimd_set_huff_encode_one_block(j_compress_ptr cinfo)
1432
2.63k
{
1433
2.63k
  init_simd((j_common_ptr)cinfo);
1434
1435
2.63k
  if (sizeof(JCOEF) != 2)
1436
0
    return JSIMD_NONE;
1437
2.63k
  if (!cinfo->entropy)
1438
0
    return JSIMD_NONE;
1439
1440
2.63k
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
1441
2.63k
  if ((cinfo->master->simd_support & JSIMD_SSE2) &&
1442
2.63k
      cinfo->master->simd_huffman &&
1443
2.63k
      IS_ALIGNED_SSE(jconst_huff_encode_one_block)) {
1444
2.63k
    cinfo->entropy->huff_encode_one_block_simd =
1445
2.63k
      jsimd_huff_encode_one_block_sse2;
1446
2.63k
    return JSIMD_SSE2;
1447
2.63k
  }
1448
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
1449
  if ((cinfo->master->simd_support & JSIMD_NEON) &&
1450
      cinfo->master->simd_huffman) {
1451
    cinfo->entropy->huff_encode_one_block_simd =
1452
      jsimd_huff_encode_one_block_neon;
1453
    return JSIMD_NEON;
1454
  }
1455
#endif
1456
1457
0
  return JSIMD_NONE;
1458
2.63k
}
1459
1460
1461
HIDDEN unsigned int
1462
jsimd_set_encode_mcu_AC_first_prepare(j_compress_ptr cinfo,
1463
  void (**method) (const JCOEF *, const int *, int, int, UJCOEF *, size_t *))
1464
0
{
1465
0
  init_simd((j_common_ptr)cinfo);
1466
1467
0
  if (sizeof(JCOEF) != 2)
1468
0
    return JSIMD_NONE;
1469
1470
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
1471
0
  if ((cinfo->master->simd_support & JSIMD_SSE2) &&
1472
0
      cinfo->master->simd_huffman) {
1473
0
    *method = jsimd_encode_mcu_AC_first_prepare_sse2;
1474
0
    return JSIMD_SSE2;
1475
0
  }
1476
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
1477
  if ((cinfo->master->simd_support & JSIMD_NEON) &&
1478
      cinfo->master->simd_huffman) {
1479
    *method = jsimd_encode_mcu_AC_first_prepare_neon;
1480
    return JSIMD_NEON;
1481
  }
1482
#endif
1483
1484
0
  return JSIMD_NONE;
1485
0
}
1486
1487
1488
HIDDEN unsigned int
1489
jsimd_set_encode_mcu_AC_refine_prepare(j_compress_ptr cinfo,
1490
  int (**method) (const JCOEF *, const int *, int, int, UJCOEF *, size_t *))
1491
0
{
1492
0
  init_simd((j_common_ptr)cinfo);
1493
1494
0
  if (sizeof(JCOEF) != 2)
1495
0
    return JSIMD_NONE;
1496
1497
0
#if SIMD_ARCHITECTURE == X86_64 || SIMD_ARCHITECTURE == I386
1498
0
  if ((cinfo->master->simd_support & JSIMD_SSE2) &&
1499
0
      cinfo->master->simd_huffman) {
1500
0
    *method = jsimd_encode_mcu_AC_refine_prepare_sse2;
1501
0
    return JSIMD_SSE2;
1502
0
  }
1503
#elif SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM
1504
  if ((cinfo->master->simd_support & JSIMD_NEON) &&
1505
      cinfo->master->simd_huffman) {
1506
    *method = jsimd_encode_mcu_AC_refine_prepare_neon;
1507
    return JSIMD_NEON;
1508
  }
1509
#endif
1510
1511
0
  return JSIMD_NONE;
1512
0
}