Coverage Report

Created: 2025-10-10 07:05

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