Coverage Report

Created: 2026-08-31 06:56

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