jsimd_mips.c revision fff6c23a65f1359b9e80e469f4fa36e10f869288
1/*
2 * jsimd_mips.c
3 *
4 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5 * Copyright 2009-2011 D. R. Commander
6 * Copyright (C) 2013, MIPS Technologies, Inc., California
7 *
8 * Based on the x86 SIMD extension for IJG JPEG library,
9 * Copyright (C) 1999-2006, MIYASAKA Masaru.
10 * For conditions of distribution and use, see copyright notice in jsimdext.inc
11 *
12 * This file contains the interface between the "normal" portions
13 * of the library and the SIMD implementations when running on
14 * MIPS architecture.
15 *
16 * Based on the stubs from 'jsimd_none.c'
17 */
18
19#define JPEG_INTERNALS
20#include "../jinclude.h"
21#include "../jpeglib.h"
22#include "../jsimd.h"
23#include "../jdct.h"
24#include "../jsimddct.h"
25#include "jsimd.h"
26
27#include <stdio.h>
28#include <string.h>
29#include <ctype.h>
30
31static unsigned int simd_support = ~0;
32
33#if defined(__linux__)
34
35LOCAL(int)
36parse_proc_cpuinfo(const char* search_string)
37{
38  const char* file_name = "/proc/cpuinfo";
39  char cpuinfo_line[256];
40  FILE* f = NULL;
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_MIPS_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#endif
57
58/*
59 * Check what SIMD accelerations are supported.
60 *
61 * FIXME: This code is racy under a multi-threaded environment.
62 */
63LOCAL(void)
64init_simd (void)
65{
66  if (simd_support != ~0U)
67    return;
68
69  simd_support = 0;
70
71#if defined(__mips__) && defined(__mips_dsp) && (__mips_dsp_rev >= 2)
72  simd_support |= JSIMD_MIPS_DSPR2;
73#elif defined(__linux__)
74  /* We still have a chance to use MIPS DSPR2 regardless of globally used
75   * -mdspr2 options passed to gcc by performing runtime detection via
76   * /proc/cpuinfo parsing on linux */
77  if (!parse_proc_cpuinfo("MIPS 74K"))
78    return;
79#endif
80}
81static const int mips_idct_ifast_coefs[4] = {
82  0x45404540,           // FIX( 1.082392200 / 2) =  17734 = 0x4546
83  0x5A805A80,           // FIX( 1.414213562 / 2) =  23170 = 0x5A82
84  0x76407640,           // FIX( 1.847759065 / 2) =  30274 = 0x7642
85  0xAC60AC60            // FIX(-2.613125930 / 4) = -21407 = 0xAC61
86};
87
88GLOBAL(int)
89jsimd_can_rgb_ycc (void)
90{
91  init_simd();
92
93  /* The code is optimised for these values only */
94  if (BITS_IN_JSAMPLE != 8)
95    return 0;
96  if (sizeof(JDIMENSION) != 4)
97    return 0;
98  if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
99    return 0;
100  if (simd_support & JSIMD_MIPS_DSPR2)
101    return 1;
102
103  return 0;
104}
105
106GLOBAL(int)
107jsimd_can_rgb_gray (void)
108{
109  init_simd();
110
111  /* The code is optimised for these values only */
112  if (BITS_IN_JSAMPLE != 8)
113    return 0;
114  if (sizeof(JDIMENSION) != 4)
115    return 0;
116  if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
117    return 0;
118  if (simd_support & JSIMD_MIPS_DSPR2)
119    return 1;
120
121  return 0;
122}
123
124GLOBAL(int)
125jsimd_can_ycc_rgb (void)
126{
127  init_simd();
128
129  /* The code is optimised for these values only */
130  if (BITS_IN_JSAMPLE != 8)
131    return 0;
132  if (sizeof(JDIMENSION) != 4)
133    return 0;
134  if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
135    return 0;
136  if (simd_support & JSIMD_MIPS_DSPR2)
137    return 1;
138
139  return 0;
140}
141
142GLOBAL(void)
143jsimd_rgb_ycc_convert (j_compress_ptr cinfo,
144                       JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
145                       JDIMENSION output_row, int num_rows)
146{
147  void (*mipsdspr2fct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
148  switch(cinfo->in_color_space)
149  {
150    case JCS_EXT_RGB:
151      mipsdspr2fct=jsimd_extrgb_ycc_convert_mips_dspr2;
152      break;
153    case JCS_EXT_RGBX:
154    case JCS_EXT_RGBA:
155      mipsdspr2fct=jsimd_extrgbx_ycc_convert_mips_dspr2;
156      break;
157    case JCS_EXT_BGR:
158      mipsdspr2fct=jsimd_extbgr_ycc_convert_mips_dspr2;
159      break;
160    case JCS_EXT_BGRX:
161    case JCS_EXT_BGRA:
162      mipsdspr2fct=jsimd_extbgrx_ycc_convert_mips_dspr2;
163      break;
164    case JCS_EXT_XBGR:
165    case JCS_EXT_ABGR:
166      mipsdspr2fct=jsimd_extxbgr_ycc_convert_mips_dspr2;
167
168      break;
169    case JCS_EXT_XRGB:
170    case JCS_EXT_ARGB:
171      mipsdspr2fct=jsimd_extxrgb_ycc_convert_mips_dspr2;
172      break;
173    default:
174      mipsdspr2fct=jsimd_extrgb_ycc_convert_mips_dspr2;
175      break;
176  }
177
178  if (simd_support & JSIMD_MIPS_DSPR2)
179    mipsdspr2fct(cinfo->image_width, input_buf,
180        output_buf, output_row, num_rows);
181}
182
183GLOBAL(void)
184jsimd_rgb_gray_convert (j_compress_ptr cinfo,
185                        JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
186                        JDIMENSION output_row, int num_rows)
187{
188  void (*mipsdspr2fct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
189  switch(cinfo->in_color_space)
190  {
191    case JCS_EXT_RGB:
192      mipsdspr2fct=jsimd_extrgb_gray_convert_mips_dspr2;
193      break;
194    case JCS_EXT_RGBX:
195    case JCS_EXT_RGBA:
196      mipsdspr2fct=jsimd_extrgbx_gray_convert_mips_dspr2;
197      break;
198    case JCS_EXT_BGR:
199      mipsdspr2fct=jsimd_extbgr_gray_convert_mips_dspr2;
200      break;
201    case JCS_EXT_BGRX:
202    case JCS_EXT_BGRA:
203      mipsdspr2fct=jsimd_extbgrx_gray_convert_mips_dspr2;
204      break;
205    case JCS_EXT_XBGR:
206    case JCS_EXT_ABGR:
207      mipsdspr2fct=jsimd_extxbgr_gray_convert_mips_dspr2;
208      break;
209    case JCS_EXT_XRGB:
210    case JCS_EXT_ARGB:
211      mipsdspr2fct=jsimd_extxrgb_gray_convert_mips_dspr2;
212      break;
213    default:
214      mipsdspr2fct=jsimd_extrgb_gray_convert_mips_dspr2;
215      break;
216  }
217
218  if (simd_support & JSIMD_MIPS_DSPR2)
219    mipsdspr2fct(cinfo->image_width, input_buf,
220        output_buf, output_row, num_rows);
221
222}
223
224GLOBAL(void)
225jsimd_ycc_rgb_convert (j_decompress_ptr cinfo,
226                       JSAMPIMAGE input_buf, JDIMENSION input_row,
227                       JSAMPARRAY output_buf, int num_rows)
228{
229  void (*mipsdspr2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
230
231  switch(cinfo->out_color_space)
232  {
233    case JCS_EXT_RGB:
234      mipsdspr2fct=jsimd_ycc_extrgb_convert_mips_dspr2;
235      break;
236    case JCS_EXT_RGBX:
237    case JCS_EXT_RGBA:
238      mipsdspr2fct=jsimd_ycc_extrgbx_convert_mips_dspr2;
239      break;
240    case JCS_EXT_BGR:
241      mipsdspr2fct=jsimd_ycc_extbgr_convert_mips_dspr2;
242      break;
243    case JCS_EXT_BGRX:
244    case JCS_EXT_BGRA:
245      mipsdspr2fct=jsimd_ycc_extbgrx_convert_mips_dspr2;
246      break;
247    case JCS_EXT_XBGR:
248    case JCS_EXT_ABGR:
249      mipsdspr2fct=jsimd_ycc_extxbgr_convert_mips_dspr2;
250      break;
251    case JCS_EXT_XRGB:
252    case JCS_EXT_ARGB:
253      mipsdspr2fct=jsimd_ycc_extxrgb_convert_mips_dspr2;
254      break;
255  default:
256      mipsdspr2fct=jsimd_ycc_extrgb_convert_mips_dspr2;
257      break;
258  }
259
260  if (simd_support & JSIMD_MIPS_DSPR2)
261    mipsdspr2fct(cinfo->output_width, input_buf,
262        input_row, output_buf, num_rows);
263}
264
265GLOBAL(int)
266jsimd_can_h2v2_downsample (void)
267{
268  init_simd();
269
270  /* The code is optimised for these values only */
271  if (BITS_IN_JSAMPLE != 8)
272    return 0;
273  if (sizeof(JDIMENSION) != 4)
274    return 0;
275  if (simd_support & JSIMD_MIPS_DSPR2)
276    return 1;
277
278  return 0;
279}
280
281GLOBAL(int)
282jsimd_can_h2v1_downsample (void)
283{
284  init_simd();
285
286  /* The code is optimised for these values only */
287  if (BITS_IN_JSAMPLE != 8)
288    return 0;
289  if (sizeof(JDIMENSION) != 4)
290    return 0;
291  if (simd_support & JSIMD_MIPS_DSPR2)
292    return 1;
293
294  return 0;
295}
296
297GLOBAL(void)
298jsimd_h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
299                       JSAMPARRAY input_data, JSAMPARRAY output_data)
300{
301  if (simd_support & JSIMD_MIPS_DSPR2)
302    jsimd_h2v2_downsample_mips_dspr2(cinfo->image_width,
303        cinfo->max_v_samp_factor, compptr->v_samp_factor,
304        compptr->width_in_blocks, input_data, output_data);
305}
306
307GLOBAL(void)
308jsimd_h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
309                       JSAMPARRAY input_data, JSAMPARRAY output_data)
310{
311  if (simd_support & JSIMD_MIPS_DSPR2)
312    jsimd_h2v1_downsample_mips_dspr2(cinfo->image_width,
313        cinfo->max_v_samp_factor, compptr->v_samp_factor,
314        compptr->width_in_blocks, input_data, output_data);
315}
316
317GLOBAL(int)
318jsimd_can_h2v2_upsample (void)
319{
320  init_simd();
321
322  /* The code is optimised for these values only */
323  if (BITS_IN_JSAMPLE != 8)
324    return 0;
325  if (sizeof(JDIMENSION) != 4)
326    return 0;
327  if (simd_support & JSIMD_MIPS_DSPR2)
328    return 1;
329
330  return 0;
331}
332
333GLOBAL(int)
334jsimd_can_h2v1_upsample (void)
335{
336  init_simd();
337
338  /* The code is optimised for these values only */
339  if (BITS_IN_JSAMPLE != 8)
340    return 0;
341  if (sizeof(JDIMENSION) != 4)
342    return 0;
343  if (simd_support & JSIMD_MIPS_DSPR2)
344    return 1;
345
346  return 0;
347}
348
349GLOBAL(void)
350jsimd_h2v2_upsample (j_decompress_ptr cinfo,
351                     jpeg_component_info * compptr,
352                     JSAMPARRAY input_data,
353                     JSAMPARRAY * output_data_ptr)
354{
355  if (simd_support & JSIMD_MIPS_DSPR2)
356    jsimd_h2v2_upsample_mips_dspr2(cinfo->max_v_samp_factor,
357        cinfo->output_width, input_data, output_data_ptr);
358}
359
360GLOBAL(void)
361jsimd_h2v1_upsample (j_decompress_ptr cinfo,
362                     jpeg_component_info * compptr,
363                     JSAMPARRAY input_data,
364                     JSAMPARRAY * output_data_ptr)
365{
366  if (simd_support & JSIMD_MIPS_DSPR2)
367    jsimd_h2v1_upsample_mips_dspr2(cinfo->max_v_samp_factor,
368        cinfo->output_width, input_data, output_data_ptr);
369}
370
371GLOBAL(int)
372jsimd_can_h2v2_fancy_upsample (void)
373{
374  init_simd();
375
376  /* The code is optimised for these values only */
377  if (BITS_IN_JSAMPLE != 8)
378    return 0;
379  if (sizeof(JDIMENSION) != 4)
380    return 0;
381  if (simd_support & JSIMD_MIPS_DSPR2)
382    return 1;
383
384  return 0;
385}
386
387GLOBAL(int)
388jsimd_can_h2v1_fancy_upsample (void)
389{
390  init_simd();
391
392  /* The code is optimised for these values only */
393  if (BITS_IN_JSAMPLE != 8)
394    return 0;
395  if (sizeof(JDIMENSION) != 4)
396    return 0;
397  if (simd_support & JSIMD_MIPS_DSPR2)
398    return 1;
399
400  return 0;
401}
402
403GLOBAL(void)
404jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo,
405                           jpeg_component_info * compptr,
406                           JSAMPARRAY input_data,
407                           JSAMPARRAY * output_data_ptr)
408{
409  if (simd_support & JSIMD_MIPS_DSPR2)
410    jsimd_h2v2_fancy_upsample_mips_dspr2(cinfo->max_v_samp_factor,
411        compptr->downsampled_width, input_data, output_data_ptr);
412}
413
414GLOBAL(void)
415jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo,
416                           jpeg_component_info * compptr,
417                           JSAMPARRAY input_data,
418                           JSAMPARRAY * output_data_ptr)
419{
420  if (simd_support & JSIMD_MIPS_DSPR2)
421    jsimd_h2v1_fancy_upsample_mips_dspr2(cinfo->max_v_samp_factor,
422        compptr->downsampled_width, input_data, output_data_ptr);
423}
424
425GLOBAL(int)
426jsimd_can_h2v2_merged_upsample (void)
427{
428  return 0;
429}
430
431GLOBAL(int)
432jsimd_can_h2v1_merged_upsample (void)
433{
434  return 0;
435}
436
437GLOBAL(void)
438jsimd_h2v2_merged_upsample (j_decompress_ptr cinfo,
439                            JSAMPIMAGE input_buf,
440                            JDIMENSION in_row_group_ctr,
441                            JSAMPARRAY output_buf)
442{
443}
444
445GLOBAL(void)
446jsimd_h2v1_merged_upsample (j_decompress_ptr cinfo,
447                            JSAMPIMAGE input_buf,
448                            JDIMENSION in_row_group_ctr,
449                            JSAMPARRAY output_buf)
450{
451}
452
453GLOBAL(int)
454jsimd_can_convsamp (void)
455{
456  init_simd();
457
458  /* The code is optimised for these values only */
459  if (DCTSIZE != 8)
460    return 0;
461  if (BITS_IN_JSAMPLE != 8)
462    return 0;
463  if (sizeof(JDIMENSION) != 4)
464    return 0;
465  if (sizeof(DCTELEM) != 2)
466    return 0;
467
468  if (simd_support & JSIMD_MIPS_DSPR2)
469    return 1;
470
471  return 0;
472}
473
474GLOBAL(int)
475jsimd_can_convsamp_float (void)
476{
477  init_simd();
478
479  /* The code is optimised for these values only */
480  if (DCTSIZE != 8)
481    return 0;
482  if (sizeof(JCOEF) != 2)
483    return 0;
484  if (BITS_IN_JSAMPLE != 8)
485    return 0;
486  if (sizeof(JDIMENSION) != 4)
487    return 0;
488  if (sizeof(ISLOW_MULT_TYPE) != 2)
489    return 0;
490
491  if ((simd_support & JSIMD_MIPS_DSPR2))
492    return 1;
493
494  return 0;
495}
496
497GLOBAL(void)
498jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col,
499                DCTELEM * workspace)
500{
501  if (simd_support & JSIMD_MIPS_DSPR2)
502    jsimd_convsamp_mips_dspr2(sample_data, start_col, workspace);
503}
504
505GLOBAL(void)
506jsimd_convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col,
507                      FAST_FLOAT * workspace)
508{
509  if ((simd_support & JSIMD_MIPS_DSPR2))
510    jsimd_convsamp_float_mips_dspr2(sample_data, start_col, workspace);
511}
512
513GLOBAL(int)
514jsimd_can_fdct_islow (void)
515{
516  init_simd();
517
518  /* The code is optimised for these values only */
519  if (DCTSIZE != 8)
520    return 0;
521  if (sizeof(DCTELEM) != 2)
522    return 0;
523
524  if (simd_support & JSIMD_MIPS_DSPR2)
525    return 1;
526
527  return 0;
528}
529
530GLOBAL(int)
531jsimd_can_fdct_ifast (void)
532{
533  init_simd();
534
535  /* The code is optimised for these values only */
536  if (DCTSIZE != 8)
537    return 0;
538  if (sizeof(DCTELEM) != 2)
539    return 0;
540
541  if (simd_support & JSIMD_MIPS_DSPR2)
542    return 1;
543
544  return 0;
545}
546
547GLOBAL(int)
548jsimd_can_fdct_float (void)
549{
550  return 0;
551}
552
553GLOBAL(void)
554jsimd_fdct_islow (DCTELEM * data)
555{
556  if (simd_support & JSIMD_MIPS_DSPR2)
557    jsimd_fdct_islow_mips_dspr2(data);
558}
559
560GLOBAL(void)
561jsimd_fdct_ifast (DCTELEM * data)
562{
563  if (simd_support & JSIMD_MIPS_DSPR2)
564    jsimd_fdct_ifast_mips_dspr2(data);
565}
566
567GLOBAL(void)
568jsimd_fdct_float (FAST_FLOAT * data)
569{
570}
571
572GLOBAL(int)
573jsimd_can_quantize (void)
574{
575  init_simd();
576
577  /* The code is optimised for these values only */
578  if (DCTSIZE != 8)
579    return 0;
580  if (sizeof(JCOEF) != 2)
581    return 0;
582  if (sizeof(DCTELEM) != 2)
583    return 0;
584
585  if (simd_support & JSIMD_MIPS_DSPR2)
586    return 1;
587
588  return 0;
589}
590
591GLOBAL(int)
592jsimd_can_quantize_float (void)
593{
594  init_simd();
595
596  /* The code is optimised for these values only */
597  if (DCTSIZE != 8)
598    return 0;
599  if (sizeof(JCOEF) != 2)
600    return 0;
601  if (BITS_IN_JSAMPLE != 8)
602    return 0;
603  if (sizeof(JDIMENSION) != 4)
604    return 0;
605  if (sizeof(ISLOW_MULT_TYPE) != 2)
606    return 0;
607
608  if ((simd_support & JSIMD_MIPS_DSPR2))
609    return 1;
610
611  return 0;
612}
613
614GLOBAL(void)
615jsimd_quantize (JCOEFPTR coef_block, DCTELEM * divisors,
616                DCTELEM * workspace)
617{
618  if (simd_support & JSIMD_MIPS_DSPR2)
619    jsimd_quantize_mips_dspr2(coef_block, divisors, workspace);
620}
621
622GLOBAL(void)
623jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors,
624                      FAST_FLOAT * workspace)
625{
626  if ((simd_support & JSIMD_MIPS_DSPR2))
627    jsimd_quantize_float_mips_dspr2(coef_block, divisors, workspace);
628}
629
630GLOBAL(int)
631jsimd_can_idct_2x2 (void)
632{
633  init_simd();
634
635  /* The code is optimised for these values only */
636  if (DCTSIZE != 8)
637    return 0;
638  if (sizeof(JCOEF) != 2)
639    return 0;
640  if (BITS_IN_JSAMPLE != 8)
641    return 0;
642  if (sizeof(JDIMENSION) != 4)
643    return 0;
644  if (sizeof(ISLOW_MULT_TYPE) != 2)
645    return 0;
646
647  if ((simd_support & JSIMD_MIPS_DSPR2))
648    return 1;
649
650  return 0;
651}
652
653GLOBAL(int)
654jsimd_can_idct_4x4 (void)
655{
656  init_simd();
657
658  /* The code is optimised for these values only */
659  if (DCTSIZE != 8)
660    return 0;
661  if (sizeof(JCOEF) != 2)
662    return 0;
663  if (BITS_IN_JSAMPLE != 8)
664    return 0;
665  if (sizeof(JDIMENSION) != 4)
666    return 0;
667  if (sizeof(ISLOW_MULT_TYPE) != 2)
668    return 0;
669
670  if ((simd_support & JSIMD_MIPS_DSPR2))
671    return 1;
672
673  return 0;
674}
675
676GLOBAL(int)
677jsimd_can_idct_6x6 (void)
678{
679  init_simd();
680
681  /* The code is optimised for these values only */
682  if (DCTSIZE != 8)
683    return 0;
684  if (sizeof(JCOEF) != 2)
685    return 0;
686  if (BITS_IN_JSAMPLE != 8)
687    return 0;
688  if (sizeof(JDIMENSION) != 4)
689    return 0;
690  if (sizeof(ISLOW_MULT_TYPE) != 2)
691    return 0;
692
693  if ((simd_support & JSIMD_MIPS_DSPR2))
694    return 1;
695
696  return 0;
697}
698
699GLOBAL(int)
700jsimd_can_idct_12x12 (void)
701{
702  init_simd();
703
704  if (BITS_IN_JSAMPLE != 8)
705    return 0;
706  if (DCTSIZE != 8)
707    return 0;
708  if (sizeof(JCOEF) != 2)
709    return 0;
710  if (sizeof(JDIMENSION) != 4)
711    return 0;
712  if (sizeof(ISLOW_MULT_TYPE) != 2)
713    return 0;
714
715  if (simd_support & JSIMD_MIPS_DSPR2)
716    return 1;
717
718  return 0;
719}
720
721GLOBAL(void)
722jsimd_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
723                JCOEFPTR coef_block, JSAMPARRAY output_buf,
724                JDIMENSION output_col)
725{
726  if ((simd_support & JSIMD_MIPS_DSPR2))
727    jsimd_idct_2x2_mips_dspr2(compptr->dct_table, coef_block,
728                              output_buf, output_col);
729}
730
731GLOBAL(void)
732jsimd_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
733                JCOEFPTR coef_block, JSAMPARRAY output_buf,
734                JDIMENSION output_col)
735{
736  if ((simd_support & JSIMD_MIPS_DSPR2))
737  {
738    int workspace[DCTSIZE*4];  /* buffers data between passes */
739    jsimd_idct_4x4_mips_dspr2(compptr->dct_table, coef_block,
740                              output_buf, output_col, workspace);
741  }
742}
743
744GLOBAL(void)
745jsimd_idct_6x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
746           JCOEFPTR coef_block, JSAMPARRAY output_buf,
747           JDIMENSION output_col)
748{
749    if ((simd_support & JSIMD_MIPS_DSPR2))
750      jsimd_idct_6x6_mips_dspr2(compptr->dct_table, coef_block,
751                                output_buf, output_col);
752}
753
754GLOBAL(void)
755jsimd_idct_12x12 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
756                  JCOEFPTR coef_block,
757                  JSAMPARRAY output_buf, JDIMENSION output_col)
758{
759  if (simd_support & JSIMD_MIPS_DSPR2) {
760    int workspace[96];
761    int output[12] = {
762      (int)(output_buf[0] + output_col),
763      (int)(output_buf[1] + output_col),
764      (int)(output_buf[2] + output_col),
765      (int)(output_buf[3] + output_col),
766      (int)(output_buf[4] + output_col),
767      (int)(output_buf[5] + output_col),
768      (int)(output_buf[6] + output_col),
769      (int)(output_buf[7] + output_col),
770      (int)(output_buf[8] + output_col),
771      (int)(output_buf[9] + output_col),
772      (int)(output_buf[10] + output_col),
773      (int)(output_buf[11] + output_col),
774    };
775    jsimd_idct_12x12_pass1_mips_dspr2(coef_block,
776                                      compptr->dct_table, workspace);
777    jsimd_idct_12x12_pass2_mips_dspr2(workspace, output);
778  }
779}
780
781GLOBAL(int)
782jsimd_can_idct_islow (void)
783{
784  return 0;
785}
786
787GLOBAL(int)
788jsimd_can_idct_ifast (void)
789{
790  init_simd();
791
792  /* The code is optimised for these values only */
793  if (DCTSIZE != 8)
794    return 0;
795  if (sizeof(JCOEF) != 2)
796    return 0;
797  if (BITS_IN_JSAMPLE != 8)
798    return 0;
799  if (sizeof(JDIMENSION) != 4)
800    return 0;
801  if (sizeof(IFAST_MULT_TYPE) != 2)
802    return 0;
803  if (IFAST_SCALE_BITS != 2)
804    return 0;
805
806  if ((simd_support & JSIMD_MIPS_DSPR2))
807    return 1;
808
809  return 0;
810}
811
812GLOBAL(int)
813jsimd_can_idct_float (void)
814{
815  return 0;
816}
817
818GLOBAL(void)
819jsimd_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
820                JCOEFPTR coef_block, JSAMPARRAY output_buf,
821                JDIMENSION output_col)
822{
823}
824
825GLOBAL(void)
826jsimd_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
827                  JCOEFPTR coef_block, JSAMPARRAY output_buf,
828                  JDIMENSION output_col)
829{
830  if (simd_support & JSIMD_MIPS_DSPR2) {
831    JCOEFPTR inptr;
832    IFAST_MULT_TYPE * quantptr;
833    DCTELEM workspace[DCTSIZE2];  /* buffers data between passes */
834
835    /* Pass 1: process columns from input, store into work array. */
836
837    inptr = coef_block;
838    quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
839
840    jsimd_idct_ifast_cols_mips_dspr2(inptr, quantptr,
841                                     workspace, mips_idct_ifast_coefs);
842
843    /* Pass 2: process rows from work array, store into output array. */
844    /* Note that we must descale the results by a factor of 8 == 2**3, */
845    /* and also undo the PASS1_BITS scaling. */
846
847    jsimd_idct_ifast_rows_mips_dspr2(workspace, output_buf,
848                                     output_col, mips_idct_ifast_coefs);
849  }
850}
851
852GLOBAL(void)
853jsimd_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
854                JCOEFPTR coef_block, JSAMPARRAY output_buf,
855                JDIMENSION output_col)
856{
857}
858