blob: af886f60b6a5892252bf485bce9af4584e3f9c96 [file] [log] [blame]
Leon Scroggins III3993b372018-07-16 10:43:45 -04001/*
2 * jsimd_mips.c
3 *
4 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5 * Copyright (C) 2009-2011, 2014, 2016, 2018, D. R. Commander.
6 * Copyright (C) 2013-2014, MIPS Technologies, Inc., California.
7 * Copyright (C) 2015-2016, 2018, Matthieu Darbois.
8 *
9 * Based on the x86 SIMD extension for IJG JPEG library,
10 * Copyright (C) 1999-2006, MIYASAKA Masaru.
11 * For conditions of distribution and use, see copyright notice in jsimdext.inc
12 *
13 * This file contains the interface between the "normal" portions
14 * of the library and the SIMD implementations when running on a
15 * MIPS architecture.
16 */
17
18#define JPEG_INTERNALS
19#include "../../jinclude.h"
20#include "../../jpeglib.h"
21#include "../../jsimd.h"
22#include "../../jdct.h"
23#include "../../jsimddct.h"
24#include "../jsimd.h"
25
26#include <stdio.h>
27#include <string.h>
28#include <ctype.h>
29
30static unsigned int simd_support = ~0;
31
32#if defined(__linux__)
33
34LOCAL(int)
35parse_proc_cpuinfo(const char *search_string)
36{
37 const char *file_name = "/proc/cpuinfo";
38 char cpuinfo_line[256];
39 FILE *f = NULL;
40
41 simd_support = 0;
42
43 if ((f = fopen(file_name, "r")) != NULL) {
44 while (fgets(cpuinfo_line, sizeof(cpuinfo_line), f) != NULL) {
45 if (strstr(cpuinfo_line, search_string) != NULL) {
46 fclose(f);
47 simd_support |= JSIMD_DSPR2;
48 return 1;
49 }
50 }
51 fclose(f);
52 }
53 /* Did not find string in the proc file, or not Linux ELF. */
54 return 0;
55}
56
57#endif
58
59/*
60 * Check what SIMD accelerations are supported.
61 *
62 * FIXME: This code is racy under a multi-threaded environment.
63 */
64LOCAL(void)
65init_simd(void)
66{
67#ifndef NO_GETENV
68 char *env = NULL;
69#endif
70
71 if (simd_support != ~0U)
72 return;
73
74 simd_support = 0;
75
76#if defined(__MIPSEL__) && defined(__mips_dsp) && (__mips_dsp_rev >= 2)
77 simd_support |= JSIMD_DSPR2;
78#elif defined(__linux__)
79 /* We still have a chance to use MIPS DSPR2 regardless of globally used
80 * -mdspr2 options passed to gcc by performing runtime detection via
81 * /proc/cpuinfo parsing on linux */
82 if (!parse_proc_cpuinfo("MIPS 74K"))
83 return;
84#endif
85
86#ifndef NO_GETENV
87 /* Force different settings through environment variables */
88 env = getenv("JSIMD_FORCEDSPR2");
89 if ((env != NULL) && (strcmp(env, "1") == 0))
90 simd_support = JSIMD_DSPR2;
91 env = getenv("JSIMD_FORCENONE");
92 if ((env != NULL) && (strcmp(env, "1") == 0))
93 simd_support = 0;
94#endif
95}
96
97static const int mips_idct_ifast_coefs[4] = {
98 0x45404540, /* FIX( 1.082392200 / 2) = 17734 = 0x4546 */
99 0x5A805A80, /* FIX( 1.414213562 / 2) = 23170 = 0x5A82 */
100 0x76407640, /* FIX( 1.847759065 / 2) = 30274 = 0x7642 */
101 0xAC60AC60 /* FIX(-2.613125930 / 4) = -21407 = 0xAC61 */
102};
103
104/* The following struct is borrowed from jdsample.c */
105typedef void (*upsample1_ptr) (j_decompress_ptr cinfo,
106 jpeg_component_info *compptr,
107 JSAMPARRAY input_data,
108 JSAMPARRAY *output_data_ptr);
109typedef struct {
110 struct jpeg_upsampler pub;
111 JSAMPARRAY color_buf[MAX_COMPONENTS];
112 upsample1_ptr methods[MAX_COMPONENTS];
113 int next_row_out;
114 JDIMENSION rows_to_go;
115 int rowgroup_height[MAX_COMPONENTS];
116 UINT8 h_expand[MAX_COMPONENTS];
117 UINT8 v_expand[MAX_COMPONENTS];
118} my_upsampler;
119
120typedef my_upsampler *my_upsample_ptr;
121
122GLOBAL(int)
123jsimd_can_rgb_ycc(void)
124{
125 init_simd();
126
127 /* The code is optimised for these values only */
128 if (BITS_IN_JSAMPLE != 8)
129 return 0;
130 if (sizeof(JDIMENSION) != 4)
131 return 0;
132 if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
133 return 0;
134
135 if (simd_support & JSIMD_DSPR2)
136 return 1;
137
138 return 0;
139}
140
141GLOBAL(int)
142jsimd_can_rgb_gray(void)
143{
144 init_simd();
145
146 /* The code is optimised for these values only */
147 if (BITS_IN_JSAMPLE != 8)
148 return 0;
149 if (sizeof(JDIMENSION) != 4)
150 return 0;
151 if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
152 return 0;
153
154 if (simd_support & JSIMD_DSPR2)
155 return 1;
156
157 return 0;
158}
159
160GLOBAL(int)
161jsimd_can_ycc_rgb(void)
162{
163 init_simd();
164
165 /* The code is optimised for these values only */
166 if (BITS_IN_JSAMPLE != 8)
167 return 0;
168 if (sizeof(JDIMENSION) != 4)
169 return 0;
170 if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
171 return 0;
172
173 if (simd_support & JSIMD_DSPR2)
174 return 1;
175
176 return 0;
177}
178
179GLOBAL(int)
180jsimd_can_ycc_rgb565(void)
181{
182 return 0;
183}
184
185GLOBAL(int)
186jsimd_c_can_null_convert(void)
187{
188 init_simd();
189
190 /* The code is optimised for these values only */
191 if (BITS_IN_JSAMPLE != 8)
192 return 0;
193 if (sizeof(JDIMENSION) != 4)
194 return 0;
195
196 if (simd_support & JSIMD_DSPR2)
197 return 1;
198
199 return 0;
200}
201
202GLOBAL(void)
203jsimd_rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
204 JSAMPIMAGE output_buf, JDIMENSION output_row,
205 int num_rows)
206{
207 void (*dspr2fct) (JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
208
209 switch (cinfo->in_color_space) {
210 case JCS_EXT_RGB:
211 dspr2fct = jsimd_extrgb_ycc_convert_dspr2;
212 break;
213 case JCS_EXT_RGBX:
214 case JCS_EXT_RGBA:
215 dspr2fct = jsimd_extrgbx_ycc_convert_dspr2;
216 break;
217 case JCS_EXT_BGR:
218 dspr2fct = jsimd_extbgr_ycc_convert_dspr2;
219 break;
220 case JCS_EXT_BGRX:
221 case JCS_EXT_BGRA:
222 dspr2fct = jsimd_extbgrx_ycc_convert_dspr2;
223 break;
224 case JCS_EXT_XBGR:
225 case JCS_EXT_ABGR:
226 dspr2fct = jsimd_extxbgr_ycc_convert_dspr2;
227 break;
228 case JCS_EXT_XRGB:
229 case JCS_EXT_ARGB:
230 dspr2fct = jsimd_extxrgb_ycc_convert_dspr2;
231 break;
232 default:
233 dspr2fct = jsimd_extrgb_ycc_convert_dspr2;
234 break;
235 }
236
237 dspr2fct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
238}
239
240GLOBAL(void)
241jsimd_rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
242 JSAMPIMAGE output_buf, JDIMENSION output_row,
243 int num_rows)
244{
245 void (*dspr2fct) (JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
246
247 switch (cinfo->in_color_space) {
248 case JCS_EXT_RGB:
249 dspr2fct = jsimd_extrgb_gray_convert_dspr2;
250 break;
251 case JCS_EXT_RGBX:
252 case JCS_EXT_RGBA:
253 dspr2fct = jsimd_extrgbx_gray_convert_dspr2;
254 break;
255 case JCS_EXT_BGR:
256 dspr2fct = jsimd_extbgr_gray_convert_dspr2;
257 break;
258 case JCS_EXT_BGRX:
259 case JCS_EXT_BGRA:
260 dspr2fct = jsimd_extbgrx_gray_convert_dspr2;
261 break;
262 case JCS_EXT_XBGR:
263 case JCS_EXT_ABGR:
264 dspr2fct = jsimd_extxbgr_gray_convert_dspr2;
265 break;
266 case JCS_EXT_XRGB:
267 case JCS_EXT_ARGB:
268 dspr2fct = jsimd_extxrgb_gray_convert_dspr2;
269 break;
270 default:
271 dspr2fct = jsimd_extrgb_gray_convert_dspr2;
272 break;
273 }
274
275 dspr2fct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
276}
277
278GLOBAL(void)
279jsimd_ycc_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
280 JDIMENSION input_row, JSAMPARRAY output_buf,
281 int num_rows)
282{
283 void (*dspr2fct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
284
285 switch (cinfo->out_color_space) {
286 case JCS_EXT_RGB:
287 dspr2fct = jsimd_ycc_extrgb_convert_dspr2;
288 break;
289 case JCS_EXT_RGBX:
290 case JCS_EXT_RGBA:
291 dspr2fct = jsimd_ycc_extrgbx_convert_dspr2;
292 break;
293 case JCS_EXT_BGR:
294 dspr2fct = jsimd_ycc_extbgr_convert_dspr2;
295 break;
296 case JCS_EXT_BGRX:
297 case JCS_EXT_BGRA:
298 dspr2fct = jsimd_ycc_extbgrx_convert_dspr2;
299 break;
300 case JCS_EXT_XBGR:
301 case JCS_EXT_ABGR:
302 dspr2fct = jsimd_ycc_extxbgr_convert_dspr2;
303 break;
304 case JCS_EXT_XRGB:
305 case JCS_EXT_ARGB:
306 dspr2fct = jsimd_ycc_extxrgb_convert_dspr2;
307 break;
308 default:
309 dspr2fct = jsimd_ycc_extrgb_convert_dspr2;
310 break;
311 }
312
313 dspr2fct(cinfo->output_width, input_buf, input_row, output_buf, num_rows);
314}
315
316GLOBAL(void)
317jsimd_ycc_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
318 JDIMENSION input_row, JSAMPARRAY output_buf,
319 int num_rows)
320{
321}
322
323GLOBAL(void)
324jsimd_c_null_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
325 JSAMPIMAGE output_buf, JDIMENSION output_row,
326 int num_rows)
327{
328 jsimd_c_null_convert_dspr2(cinfo->image_width, input_buf, output_buf,
329 output_row, num_rows, cinfo->num_components);
330}
331
332GLOBAL(int)
333jsimd_can_h2v2_downsample(void)
334{
335 init_simd();
336
337 /* The code is optimised for these values only */
338 if (BITS_IN_JSAMPLE != 8)
339 return 0;
340 if (sizeof(JDIMENSION) != 4)
341 return 0;
342
343 if (simd_support & JSIMD_DSPR2)
344 return 1;
345
346 return 0;
347}
348
349GLOBAL(int)
350jsimd_can_h2v2_smooth_downsample(void)
351{
352 init_simd();
353
354 /* The code is optimised for these values only */
355 if (BITS_IN_JSAMPLE != 8)
356 return 0;
357 if (sizeof(JDIMENSION) != 4)
358 return 0;
359 if (DCTSIZE != 8)
360 return 0;
361
362 if (simd_support & JSIMD_DSPR2)
363 return 1;
364
365 return 0;
366}
367
368GLOBAL(int)
369jsimd_can_h2v1_downsample(void)
370{
371 init_simd();
372
373 /* The code is optimised for these values only */
374 if (BITS_IN_JSAMPLE != 8)
375 return 0;
376 if (sizeof(JDIMENSION) != 4)
377 return 0;
378
379 if (simd_support & JSIMD_DSPR2)
380 return 1;
381
382 return 0;
383}
384
385GLOBAL(void)
386jsimd_h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
387 JSAMPARRAY input_data, JSAMPARRAY output_data)
388{
389 jsimd_h2v2_downsample_dspr2(cinfo->image_width, cinfo->max_v_samp_factor,
390 compptr->v_samp_factor, compptr->width_in_blocks,
391 input_data, output_data);
392}
393
394GLOBAL(void)
395jsimd_h2v2_smooth_downsample(j_compress_ptr cinfo,
396 jpeg_component_info *compptr,
397 JSAMPARRAY input_data, JSAMPARRAY output_data)
398{
399 jsimd_h2v2_smooth_downsample_dspr2(input_data, output_data,
400 compptr->v_samp_factor,
401 cinfo->max_v_samp_factor,
402 cinfo->smoothing_factor,
403 compptr->width_in_blocks,
404 cinfo->image_width);
405}
406
407GLOBAL(void)
408jsimd_h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
409 JSAMPARRAY input_data, JSAMPARRAY output_data)
410{
411 jsimd_h2v1_downsample_dspr2(cinfo->image_width, cinfo->max_v_samp_factor,
412 compptr->v_samp_factor, compptr->width_in_blocks,
413 input_data, output_data);
414}
415
416GLOBAL(int)
417jsimd_can_h2v2_upsample(void)
418{
419 init_simd();
420
421 /* The code is optimised for these values only */
422 if (BITS_IN_JSAMPLE != 8)
423 return 0;
424 if (sizeof(JDIMENSION) != 4)
425 return 0;
426
427 if (simd_support & JSIMD_DSPR2)
428 return 1;
429
430 return 0;
431}
432
433GLOBAL(int)
434jsimd_can_h2v1_upsample(void)
435{
436 init_simd();
437
438 /* The code is optimised for these values only */
439 if (BITS_IN_JSAMPLE != 8)
440 return 0;
441 if (sizeof(JDIMENSION) != 4)
442 return 0;
443
444 if (simd_support & JSIMD_DSPR2)
445 return 1;
446
447 return 0;
448}
449
450GLOBAL(int)
451jsimd_can_int_upsample(void)
452{
453 init_simd();
454
455 /* The code is optimised for these values only */
456 if (BITS_IN_JSAMPLE != 8)
457 return 0;
458 if (sizeof(JDIMENSION) != 4)
459 return 0;
460
461 if (simd_support & JSIMD_DSPR2)
462 return 1;
463
464 return 0;
465}
466
467GLOBAL(void)
468jsimd_h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
469 JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
470{
471 jsimd_h2v2_upsample_dspr2(cinfo->max_v_samp_factor, cinfo->output_width,
472 input_data, output_data_ptr);
473}
474
475GLOBAL(void)
476jsimd_h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
477 JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
478{
479 jsimd_h2v1_upsample_dspr2(cinfo->max_v_samp_factor, cinfo->output_width,
480 input_data, output_data_ptr);
481}
482
483GLOBAL(void)
484jsimd_int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
485 JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
486{
487 my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
488
489 jsimd_int_upsample_dspr2(upsample->h_expand[compptr->component_index],
490 upsample->v_expand[compptr->component_index],
491 input_data, output_data_ptr, cinfo->output_width,
492 cinfo->max_v_samp_factor);
493}
494
495GLOBAL(int)
496jsimd_can_h2v2_fancy_upsample(void)
497{
498 init_simd();
499
500 /* The code is optimised for these values only */
501 if (BITS_IN_JSAMPLE != 8)
502 return 0;
503 if (sizeof(JDIMENSION) != 4)
504 return 0;
505
506 if (simd_support & JSIMD_DSPR2)
507 return 1;
508
509 return 0;
510}
511
512GLOBAL(int)
513jsimd_can_h2v1_fancy_upsample(void)
514{
515 init_simd();
516
517 /* The code is optimised for these values only */
518 if (BITS_IN_JSAMPLE != 8)
519 return 0;
520 if (sizeof(JDIMENSION) != 4)
521 return 0;
522
523 if (simd_support & JSIMD_DSPR2)
524 return 1;
525
526 return 0;
527}
528
529GLOBAL(void)
530jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
531 JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
532{
533 jsimd_h2v2_fancy_upsample_dspr2(cinfo->max_v_samp_factor,
534 compptr->downsampled_width, input_data,
535 output_data_ptr);
536}
537
538GLOBAL(void)
539jsimd_h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
540 JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
541{
542 jsimd_h2v1_fancy_upsample_dspr2(cinfo->max_v_samp_factor,
543 compptr->downsampled_width, input_data,
544 output_data_ptr);
545}
546
547GLOBAL(int)
548jsimd_can_h2v2_merged_upsample(void)
549{
550 init_simd();
551
552 /* The code is optimised for these values only */
553 if (BITS_IN_JSAMPLE != 8)
554 return 0;
555 if (sizeof(JDIMENSION) != 4)
556 return 0;
557
558 if (simd_support & JSIMD_DSPR2)
559 return 1;
560
561 return 0;
562}
563
564GLOBAL(int)
565jsimd_can_h2v1_merged_upsample(void)
566{
567 init_simd();
568
569 /* The code is optimised for these values only */
570 if (BITS_IN_JSAMPLE != 8)
571 return 0;
572 if (sizeof(JDIMENSION) != 4)
573 return 0;
574
575 if (simd_support & JSIMD_DSPR2)
576 return 1;
577
578 return 0;
579}
580
581GLOBAL(void)
582jsimd_h2v2_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
583 JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
584{
585 void (*dspr2fct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, JSAMPLE *);
586
587 switch (cinfo->out_color_space) {
588 case JCS_EXT_RGB:
589 dspr2fct = jsimd_h2v2_extrgb_merged_upsample_dspr2;
590 break;
591 case JCS_EXT_RGBX:
592 case JCS_EXT_RGBA:
593 dspr2fct = jsimd_h2v2_extrgbx_merged_upsample_dspr2;
594 break;
595 case JCS_EXT_BGR:
596 dspr2fct = jsimd_h2v2_extbgr_merged_upsample_dspr2;
597 break;
598 case JCS_EXT_BGRX:
599 case JCS_EXT_BGRA:
600 dspr2fct = jsimd_h2v2_extbgrx_merged_upsample_dspr2;
601 break;
602 case JCS_EXT_XBGR:
603 case JCS_EXT_ABGR:
604 dspr2fct = jsimd_h2v2_extxbgr_merged_upsample_dspr2;
605 break;
606 case JCS_EXT_XRGB:
607 case JCS_EXT_ARGB:
608 dspr2fct = jsimd_h2v2_extxrgb_merged_upsample_dspr2;
609 break;
610 default:
611 dspr2fct = jsimd_h2v2_extrgb_merged_upsample_dspr2;
612 break;
613 }
614
615 dspr2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf,
616 cinfo->sample_range_limit);
617}
618
619GLOBAL(void)
620jsimd_h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
621 JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
622{
623 void (*dspr2fct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, JSAMPLE *);
624
625 switch (cinfo->out_color_space) {
626 case JCS_EXT_RGB:
627 dspr2fct = jsimd_h2v1_extrgb_merged_upsample_dspr2;
628 break;
629 case JCS_EXT_RGBX:
630 case JCS_EXT_RGBA:
631 dspr2fct = jsimd_h2v1_extrgbx_merged_upsample_dspr2;
632 break;
633 case JCS_EXT_BGR:
634 dspr2fct = jsimd_h2v1_extbgr_merged_upsample_dspr2;
635 break;
636 case JCS_EXT_BGRX:
637 case JCS_EXT_BGRA:
638 dspr2fct = jsimd_h2v1_extbgrx_merged_upsample_dspr2;
639 break;
640 case JCS_EXT_XBGR:
641 case JCS_EXT_ABGR:
642 dspr2fct = jsimd_h2v1_extxbgr_merged_upsample_dspr2;
643 break;
644 case JCS_EXT_XRGB:
645 case JCS_EXT_ARGB:
646 dspr2fct = jsimd_h2v1_extxrgb_merged_upsample_dspr2;
647 break;
648 default:
649 dspr2fct = jsimd_h2v1_extrgb_merged_upsample_dspr2;
650 break;
651 }
652
653 dspr2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf,
654 cinfo->sample_range_limit);
655}
656
657GLOBAL(int)
658jsimd_can_convsamp(void)
659{
660 init_simd();
661
662 /* The code is optimised for these values only */
663 if (DCTSIZE != 8)
664 return 0;
665 if (BITS_IN_JSAMPLE != 8)
666 return 0;
667 if (sizeof(JDIMENSION) != 4)
668 return 0;
669 if (sizeof(DCTELEM) != 2)
670 return 0;
671
672 if (simd_support & JSIMD_DSPR2)
673 return 1;
674
675 return 0;
676}
677
678GLOBAL(int)
679jsimd_can_convsamp_float(void)
680{
681 init_simd();
682
683 /* The code is optimised for these values only */
684 if (DCTSIZE != 8)
685 return 0;
686 if (sizeof(JCOEF) != 2)
687 return 0;
688 if (BITS_IN_JSAMPLE != 8)
689 return 0;
690 if (sizeof(JDIMENSION) != 4)
691 return 0;
692 if (sizeof(ISLOW_MULT_TYPE) != 2)
693 return 0;
694
695 if (simd_support & JSIMD_DSPR2)
696 return 1;
697
698 return 0;
699}
700
701GLOBAL(void)
702jsimd_convsamp(JSAMPARRAY sample_data, JDIMENSION start_col,
703 DCTELEM *workspace)
704{
705 jsimd_convsamp_dspr2(sample_data, start_col, workspace);
706}
707
708GLOBAL(void)
709jsimd_convsamp_float(JSAMPARRAY sample_data, JDIMENSION start_col,
710 FAST_FLOAT *workspace)
711{
712 jsimd_convsamp_float_dspr2(sample_data, start_col, workspace);
713}
714
715GLOBAL(int)
716jsimd_can_fdct_islow(void)
717{
718 init_simd();
719
720 /* The code is optimised for these values only */
721 if (DCTSIZE != 8)
722 return 0;
723 if (sizeof(DCTELEM) != 2)
724 return 0;
725
726 if (simd_support & JSIMD_DSPR2)
727 return 1;
728
729 return 0;
730}
731
732GLOBAL(int)
733jsimd_can_fdct_ifast(void)
734{
735 init_simd();
736
737 /* The code is optimised for these values only */
738 if (DCTSIZE != 8)
739 return 0;
740 if (sizeof(DCTELEM) != 2)
741 return 0;
742
743 if (simd_support & JSIMD_DSPR2)
744 return 1;
745
746 return 0;
747}
748
749GLOBAL(int)
750jsimd_can_fdct_float(void)
751{
752 return 0;
753}
754
755GLOBAL(void)
756jsimd_fdct_islow(DCTELEM *data)
757{
758 jsimd_fdct_islow_dspr2(data);
759}
760
761GLOBAL(void)
762jsimd_fdct_ifast(DCTELEM *data)
763{
764 jsimd_fdct_ifast_dspr2(data);
765}
766
767GLOBAL(void)
768jsimd_fdct_float(FAST_FLOAT *data)
769{
770}
771
772GLOBAL(int)
773jsimd_can_quantize(void)
774{
775 init_simd();
776
777 /* The code is optimised for these values only */
778 if (DCTSIZE != 8)
779 return 0;
780 if (sizeof(JCOEF) != 2)
781 return 0;
782 if (sizeof(DCTELEM) != 2)
783 return 0;
784
785 if (simd_support & JSIMD_DSPR2)
786 return 1;
787
788 return 0;
789}
790
791GLOBAL(int)
792jsimd_can_quantize_float(void)
793{
794 init_simd();
795
796 /* The code is optimised for these values only */
797 if (DCTSIZE != 8)
798 return 0;
799 if (sizeof(JCOEF) != 2)
800 return 0;
801 if (BITS_IN_JSAMPLE != 8)
802 return 0;
803 if (sizeof(JDIMENSION) != 4)
804 return 0;
805 if (sizeof(ISLOW_MULT_TYPE) != 2)
806 return 0;
807
808 if (simd_support & JSIMD_DSPR2)
809 return 1;
810
811 return 0;
812}
813
814GLOBAL(void)
815jsimd_quantize(JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace)
816{
817 jsimd_quantize_dspr2(coef_block, divisors, workspace);
818}
819
820GLOBAL(void)
821jsimd_quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors,
822 FAST_FLOAT *workspace)
823{
824 jsimd_quantize_float_dspr2(coef_block, divisors, workspace);
825}
826
827GLOBAL(int)
828jsimd_can_idct_2x2(void)
829{
830 init_simd();
831
832 /* The code is optimised for these values only */
833 if (DCTSIZE != 8)
834 return 0;
835 if (sizeof(JCOEF) != 2)
836 return 0;
837 if (BITS_IN_JSAMPLE != 8)
838 return 0;
839 if (sizeof(JDIMENSION) != 4)
840 return 0;
841 if (sizeof(ISLOW_MULT_TYPE) != 2)
842 return 0;
843
844 if (simd_support & JSIMD_DSPR2)
845 return 1;
846
847 return 0;
848}
849
850GLOBAL(int)
851jsimd_can_idct_4x4(void)
852{
853 init_simd();
854
855 /* The code is optimised for these values only */
856 if (DCTSIZE != 8)
857 return 0;
858 if (sizeof(JCOEF) != 2)
859 return 0;
860 if (BITS_IN_JSAMPLE != 8)
861 return 0;
862 if (sizeof(JDIMENSION) != 4)
863 return 0;
864 if (sizeof(ISLOW_MULT_TYPE) != 2)
865 return 0;
866
867 if (simd_support & JSIMD_DSPR2)
868 return 1;
869
870 return 0;
871}
872
873GLOBAL(int)
874jsimd_can_idct_6x6(void)
875{
876 init_simd();
877
878 /* The code is optimised for these values only */
879 if (DCTSIZE != 8)
880 return 0;
881 if (sizeof(JCOEF) != 2)
882 return 0;
883 if (BITS_IN_JSAMPLE != 8)
884 return 0;
885 if (sizeof(JDIMENSION) != 4)
886 return 0;
887 if (sizeof(ISLOW_MULT_TYPE) != 2)
888 return 0;
889
890 if (simd_support & JSIMD_DSPR2)
891 return 1;
892
893 return 0;
894}
895
896GLOBAL(int)
897jsimd_can_idct_12x12(void)
898{
899 init_simd();
900
901 if (BITS_IN_JSAMPLE != 8)
902 return 0;
903 if (DCTSIZE != 8)
904 return 0;
905 if (sizeof(JCOEF) != 2)
906 return 0;
907 if (sizeof(JDIMENSION) != 4)
908 return 0;
909 if (sizeof(ISLOW_MULT_TYPE) != 2)
910 return 0;
911
912 if (simd_support & JSIMD_DSPR2)
913 return 1;
914
915 return 0;
916}
917
918GLOBAL(void)
919jsimd_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
920 JCOEFPTR coef_block, JSAMPARRAY output_buf,
921 JDIMENSION output_col)
922{
923 jsimd_idct_2x2_dspr2(compptr->dct_table, coef_block, output_buf, output_col);
924}
925
926GLOBAL(void)
927jsimd_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
928 JCOEFPTR coef_block, JSAMPARRAY output_buf,
929 JDIMENSION output_col)
930{
931 int workspace[DCTSIZE * 4]; /* buffers data between passes */
932
933 jsimd_idct_4x4_dspr2(compptr->dct_table, coef_block, output_buf, output_col,
934 workspace);
935}
936
937GLOBAL(void)
938jsimd_idct_6x6(j_decompress_ptr cinfo, jpeg_component_info *compptr,
939 JCOEFPTR coef_block, JSAMPARRAY output_buf,
940 JDIMENSION output_col)
941{
942 jsimd_idct_6x6_dspr2(compptr->dct_table, coef_block, output_buf, output_col);
943}
944
945GLOBAL(void)
946jsimd_idct_12x12(j_decompress_ptr cinfo, jpeg_component_info *compptr,
947 JCOEFPTR coef_block, JSAMPARRAY output_buf,
948 JDIMENSION output_col)
949{
950 int workspace[96];
951 int output[12] = {
952 (int)(output_buf[0] + output_col),
953 (int)(output_buf[1] + output_col),
954 (int)(output_buf[2] + output_col),
955 (int)(output_buf[3] + output_col),
956 (int)(output_buf[4] + output_col),
957 (int)(output_buf[5] + output_col),
958 (int)(output_buf[6] + output_col),
959 (int)(output_buf[7] + output_col),
960 (int)(output_buf[8] + output_col),
961 (int)(output_buf[9] + output_col),
962 (int)(output_buf[10] + output_col),
963 (int)(output_buf[11] + output_col)
964 };
965
966 jsimd_idct_12x12_pass1_dspr2(coef_block, compptr->dct_table, workspace);
967 jsimd_idct_12x12_pass2_dspr2(workspace, output);
968}
969
970GLOBAL(int)
971jsimd_can_idct_islow(void)
972{
973 init_simd();
974
975 /* The code is optimised for these values only */
976 if (DCTSIZE != 8)
977 return 0;
978 if (sizeof(JCOEF) != 2)
979 return 0;
980 if (BITS_IN_JSAMPLE != 8)
981 return 0;
982 if (sizeof(JDIMENSION) != 4)
983 return 0;
984 if (sizeof(ISLOW_MULT_TYPE) != 2)
985 return 0;
986
987 if (simd_support & JSIMD_DSPR2)
988 return 1;
989
990 return 0;
991}
992
993GLOBAL(int)
994jsimd_can_idct_ifast(void)
995{
996 init_simd();
997
998 /* The code is optimised for these values only */
999 if (DCTSIZE != 8)
1000 return 0;
1001 if (sizeof(JCOEF) != 2)
1002 return 0;
1003 if (BITS_IN_JSAMPLE != 8)
1004 return 0;
1005 if (sizeof(JDIMENSION) != 4)
1006 return 0;
1007 if (sizeof(IFAST_MULT_TYPE) != 2)
1008 return 0;
1009 if (IFAST_SCALE_BITS != 2)
1010 return 0;
1011
1012 if (simd_support & JSIMD_DSPR2)
1013 return 1;
1014
1015 return 0;
1016}
1017
1018GLOBAL(int)
1019jsimd_can_idct_float(void)
1020{
1021 return 0;
1022}
1023
1024GLOBAL(void)
1025jsimd_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
1026 JCOEFPTR coef_block, JSAMPARRAY output_buf,
1027 JDIMENSION output_col)
1028{
1029 int output[8] = {
1030 (int)(output_buf[0] + output_col),
1031 (int)(output_buf[1] + output_col),
1032 (int)(output_buf[2] + output_col),
1033 (int)(output_buf[3] + output_col),
1034 (int)(output_buf[4] + output_col),
1035 (int)(output_buf[5] + output_col),
1036 (int)(output_buf[6] + output_col),
1037 (int)(output_buf[7] + output_col)
1038 };
1039
1040 jsimd_idct_islow_dspr2(coef_block, compptr->dct_table, output,
1041 IDCT_range_limit(cinfo));
1042}
1043
1044GLOBAL(void)
1045jsimd_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
1046 JCOEFPTR coef_block, JSAMPARRAY output_buf,
1047 JDIMENSION output_col)
1048{
1049 JCOEFPTR inptr;
1050 IFAST_MULT_TYPE *quantptr;
1051 DCTELEM workspace[DCTSIZE2]; /* buffers data between passes */
1052
1053 /* Pass 1: process columns from input, store into work array. */
1054
1055 inptr = coef_block;
1056 quantptr = (IFAST_MULT_TYPE *)compptr->dct_table;
1057
1058 jsimd_idct_ifast_cols_dspr2(inptr, quantptr, workspace,
1059 mips_idct_ifast_coefs);
1060
1061 /* Pass 2: process rows from work array, store into output array. */
1062 /* Note that we must descale the results by a factor of 8 == 2**3, */
1063 /* and also undo the PASS1_BITS scaling. */
1064
1065 jsimd_idct_ifast_rows_dspr2(workspace, output_buf, output_col,
1066 mips_idct_ifast_coefs);
1067}
1068
1069GLOBAL(void)
1070jsimd_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
1071 JCOEFPTR coef_block, JSAMPARRAY output_buf,
1072 JDIMENSION output_col)
1073{
1074}
1075
1076GLOBAL(int)
1077jsimd_can_huff_encode_one_block(void)
1078{
1079 return 0;
1080}
1081
1082GLOBAL(JOCTET *)
1083jsimd_huff_encode_one_block(void *state, JOCTET *buffer, JCOEFPTR block,
1084 int last_dc_val, c_derived_tbl *dctbl,
1085 c_derived_tbl *actbl)
1086{
1087 return NULL;
1088}
1089
1090GLOBAL(int)
1091jsimd_can_encode_mcu_AC_first_prepare(void)
1092{
1093 return 0;
1094}
1095
1096GLOBAL(void)
1097jsimd_encode_mcu_AC_first_prepare(const JCOEF *block,
1098 const int *jpeg_natural_order_start, int Sl,
1099 int Al, JCOEF *values, size_t *zerobits)
1100{
1101}
1102
1103GLOBAL(int)
1104jsimd_can_encode_mcu_AC_refine_prepare(void)
1105{
1106 return 0;
1107}
1108
1109GLOBAL(int)
1110jsimd_encode_mcu_AC_refine_prepare(const JCOEF *block,
1111 const int *jpeg_natural_order_start, int Sl,
1112 int Al, JCOEF *absvalues, size_t *bits)
1113{
1114 return 0;
1115}