blob: ae9d41ee4ceeaafb43b49cf9e475ac260028c910 [file] [log] [blame]
DRC0be9fa52013-07-24 21:50:20 +00001/*
2 * jsimd_mips.c
3 *
4 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5 * Copyright 2009-2011 D. R. Commander
DRC34347862014-05-06 09:53:21 +00006 * Copyright (C) 2013-2014, MIPS Technologies, Inc., California
DRC49eaa752013-09-27 17:39:57 +00007 *
DRC0be9fa52013-07-24 21:50:20 +00008 * 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
DRC14198522014-05-15 19:45:11 +000013 * of the library and the SIMD implementations when running on a
DRC0be9fa52013-07-24 21:50:20 +000014 * MIPS architecture.
DRC0be9fa52013-07-24 21:50:20 +000015 */
16
17#define JPEG_INTERNALS
18#include "../jinclude.h"
19#include "../jpeglib.h"
20#include "../jsimd.h"
21#include "../jdct.h"
22#include "../jsimddct.h"
23#include "jsimd.h"
24
25#include <stdio.h>
26#include <string.h>
27#include <ctype.h>
28
29static unsigned int simd_support = ~0;
30
31#if defined(__linux__)
32
33LOCAL(int)
34parse_proc_cpuinfo(const char* search_string)
35{
36 const char* file_name = "/proc/cpuinfo";
37 char cpuinfo_line[256];
38 FILE* f = NULL;
39 simd_support = 0;
40
41 if ((f = fopen(file_name, "r")) != NULL) {
42 while (fgets(cpuinfo_line, sizeof(cpuinfo_line), f) != NULL) {
43 if (strstr(cpuinfo_line, search_string) != NULL) {
44 fclose(f);
45 simd_support |= JSIMD_MIPS_DSPR2;
46 return 1;
47 }
48 }
49 fclose(f);
50 }
51 /* Did not find string in the proc file, or not Linux ELF. */
52 return 0;
53}
DRC14198522014-05-15 19:45:11 +000054
DRC0be9fa52013-07-24 21:50:20 +000055#endif
56
57/*
58 * Check what SIMD accelerations are supported.
59 *
60 * FIXME: This code is racy under a multi-threaded environment.
61 */
62LOCAL(void)
63init_simd (void)
64{
65 if (simd_support != ~0U)
66 return;
67
68 simd_support = 0;
69
70#if defined(__mips__) && defined(__mips_dsp) && (__mips_dsp_rev >= 2)
71 simd_support |= JSIMD_MIPS_DSPR2;
72#elif defined(__linux__)
73 /* We still have a chance to use MIPS DSPR2 regardless of globally used
74 * -mdspr2 options passed to gcc by performing runtime detection via
75 * /proc/cpuinfo parsing on linux */
76 if (!parse_proc_cpuinfo("MIPS 74K"))
77 return;
78#endif
79}
DRC14198522014-05-15 19:45:11 +000080
DRCd3131c12013-10-08 02:18:59 +000081static 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};
DRC0be9fa52013-07-24 21:50:20 +000087
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;
DRC14198522014-05-15 19:45:11 +0000100
DRC0be9fa52013-07-24 21:50:20 +0000101 if (simd_support & JSIMD_MIPS_DSPR2)
102 return 1;
103
104 return 0;
105}
106
107GLOBAL(int)
108jsimd_can_rgb_gray (void)
109{
DRC49eaa752013-09-27 17:39:57 +0000110 init_simd();
111
112 /* The code is optimised for these values only */
113 if (BITS_IN_JSAMPLE != 8)
114 return 0;
115 if (sizeof(JDIMENSION) != 4)
116 return 0;
117 if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
118 return 0;
DRC14198522014-05-15 19:45:11 +0000119
DRC49eaa752013-09-27 17:39:57 +0000120 if (simd_support & JSIMD_MIPS_DSPR2)
121 return 1;
122
DRC0be9fa52013-07-24 21:50:20 +0000123 return 0;
124}
125
126GLOBAL(int)
127jsimd_can_ycc_rgb (void)
128{
129 init_simd();
130
131 /* The code is optimised for these values only */
132 if (BITS_IN_JSAMPLE != 8)
133 return 0;
134 if (sizeof(JDIMENSION) != 4)
135 return 0;
136 if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
137 return 0;
DRC14198522014-05-15 19:45:11 +0000138
DRC0be9fa52013-07-24 21:50:20 +0000139 if (simd_support & JSIMD_MIPS_DSPR2)
140 return 1;
141
142 return 0;
143}
144
DRC1b3fd7e2014-05-15 18:26:01 +0000145GLOBAL(int)
146jsimd_c_can_null_convert (void)
147{
148 init_simd();
149
150 /* The code is optimised for these values only */
151 if (BITS_IN_JSAMPLE != 8)
152 return 0;
153 if (sizeof(JDIMENSION) != 4)
154 return 0;
DRC14198522014-05-15 19:45:11 +0000155
DRC1b3fd7e2014-05-15 18:26:01 +0000156 if (simd_support & JSIMD_MIPS_DSPR2)
157 return 1;
158
159 return 0;
160}
161
DRC0be9fa52013-07-24 21:50:20 +0000162GLOBAL(void)
163jsimd_rgb_ycc_convert (j_compress_ptr cinfo,
164 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
165 JDIMENSION output_row, int num_rows)
166{
167 void (*mipsdspr2fct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
DRC14198522014-05-15 19:45:11 +0000168
169 switch(cinfo->in_color_space) {
DRC0be9fa52013-07-24 21:50:20 +0000170 case JCS_EXT_RGB:
171 mipsdspr2fct=jsimd_extrgb_ycc_convert_mips_dspr2;
172 break;
173 case JCS_EXT_RGBX:
174 case JCS_EXT_RGBA:
175 mipsdspr2fct=jsimd_extrgbx_ycc_convert_mips_dspr2;
176 break;
177 case JCS_EXT_BGR:
178 mipsdspr2fct=jsimd_extbgr_ycc_convert_mips_dspr2;
179 break;
180 case JCS_EXT_BGRX:
181 case JCS_EXT_BGRA:
182 mipsdspr2fct=jsimd_extbgrx_ycc_convert_mips_dspr2;
183 break;
184 case JCS_EXT_XBGR:
185 case JCS_EXT_ABGR:
186 mipsdspr2fct=jsimd_extxbgr_ycc_convert_mips_dspr2;
187
188 break;
189 case JCS_EXT_XRGB:
190 case JCS_EXT_ARGB:
191 mipsdspr2fct=jsimd_extxrgb_ycc_convert_mips_dspr2;
192 break;
193 default:
194 mipsdspr2fct=jsimd_extrgb_ycc_convert_mips_dspr2;
195 break;
196 }
197
198 if (simd_support & JSIMD_MIPS_DSPR2)
DRC14198522014-05-15 19:45:11 +0000199 mipsdspr2fct(cinfo->image_width, input_buf, output_buf, output_row,
200 num_rows);
DRC0be9fa52013-07-24 21:50:20 +0000201}
202
203GLOBAL(void)
204jsimd_rgb_gray_convert (j_compress_ptr cinfo,
205 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
206 JDIMENSION output_row, int num_rows)
207{
DRC49eaa752013-09-27 17:39:57 +0000208 void (*mipsdspr2fct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
DRC14198522014-05-15 19:45:11 +0000209
210 switch(cinfo->in_color_space) {
DRC49eaa752013-09-27 17:39:57 +0000211 case JCS_EXT_RGB:
212 mipsdspr2fct=jsimd_extrgb_gray_convert_mips_dspr2;
213 break;
214 case JCS_EXT_RGBX:
215 case JCS_EXT_RGBA:
216 mipsdspr2fct=jsimd_extrgbx_gray_convert_mips_dspr2;
217 break;
218 case JCS_EXT_BGR:
219 mipsdspr2fct=jsimd_extbgr_gray_convert_mips_dspr2;
220 break;
221 case JCS_EXT_BGRX:
222 case JCS_EXT_BGRA:
223 mipsdspr2fct=jsimd_extbgrx_gray_convert_mips_dspr2;
224 break;
225 case JCS_EXT_XBGR:
226 case JCS_EXT_ABGR:
227 mipsdspr2fct=jsimd_extxbgr_gray_convert_mips_dspr2;
228 break;
229 case JCS_EXT_XRGB:
230 case JCS_EXT_ARGB:
231 mipsdspr2fct=jsimd_extxrgb_gray_convert_mips_dspr2;
232 break;
233 default:
234 mipsdspr2fct=jsimd_extrgb_gray_convert_mips_dspr2;
235 break;
236 }
237
238 if (simd_support & JSIMD_MIPS_DSPR2)
DRC14198522014-05-15 19:45:11 +0000239 mipsdspr2fct(cinfo->image_width, input_buf, output_buf, output_row,
240 num_rows);
DRC0be9fa52013-07-24 21:50:20 +0000241}
242
243GLOBAL(void)
244jsimd_ycc_rgb_convert (j_decompress_ptr cinfo,
245 JSAMPIMAGE input_buf, JDIMENSION input_row,
246 JSAMPARRAY output_buf, int num_rows)
247{
248 void (*mipsdspr2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
249
DRC14198522014-05-15 19:45:11 +0000250 switch(cinfo->out_color_space) {
DRC0be9fa52013-07-24 21:50:20 +0000251 case JCS_EXT_RGB:
252 mipsdspr2fct=jsimd_ycc_extrgb_convert_mips_dspr2;
253 break;
254 case JCS_EXT_RGBX:
255 case JCS_EXT_RGBA:
256 mipsdspr2fct=jsimd_ycc_extrgbx_convert_mips_dspr2;
257 break;
258 case JCS_EXT_BGR:
259 mipsdspr2fct=jsimd_ycc_extbgr_convert_mips_dspr2;
260 break;
261 case JCS_EXT_BGRX:
262 case JCS_EXT_BGRA:
263 mipsdspr2fct=jsimd_ycc_extbgrx_convert_mips_dspr2;
264 break;
265 case JCS_EXT_XBGR:
266 case JCS_EXT_ABGR:
267 mipsdspr2fct=jsimd_ycc_extxbgr_convert_mips_dspr2;
268 break;
269 case JCS_EXT_XRGB:
270 case JCS_EXT_ARGB:
271 mipsdspr2fct=jsimd_ycc_extxrgb_convert_mips_dspr2;
272 break;
273 default:
274 mipsdspr2fct=jsimd_ycc_extrgb_convert_mips_dspr2;
275 break;
276 }
277
278 if (simd_support & JSIMD_MIPS_DSPR2)
DRC14198522014-05-15 19:45:11 +0000279 mipsdspr2fct(cinfo->output_width, input_buf, input_row, output_buf,
280 num_rows);
DRC0be9fa52013-07-24 21:50:20 +0000281}
282
DRC1b3fd7e2014-05-15 18:26:01 +0000283GLOBAL(void)
284jsimd_c_null_convert (j_compress_ptr cinfo,
285 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
286 JDIMENSION output_row, int num_rows)
287{
288 if (simd_support & JSIMD_MIPS_DSPR2)
DRCc728cfd2014-05-18 19:36:05 +0000289 jsimd_c_null_convert_mips_dspr2(cinfo->image_width, input_buf,
290 output_buf, output_row, num_rows,
291 cinfo->num_components);
DRC1b3fd7e2014-05-15 18:26:01 +0000292}
293
DRC0be9fa52013-07-24 21:50:20 +0000294GLOBAL(int)
295jsimd_can_h2v2_downsample (void)
296{
DRC6f2d3c22013-07-27 21:48:18 +0000297 init_simd();
298
299 /* The code is optimised for these values only */
300 if (BITS_IN_JSAMPLE != 8)
301 return 0;
302 if (sizeof(JDIMENSION) != 4)
303 return 0;
DRC14198522014-05-15 19:45:11 +0000304
DRC6f2d3c22013-07-27 21:48:18 +0000305 if (simd_support & JSIMD_MIPS_DSPR2)
306 return 1;
307
DRC0be9fa52013-07-24 21:50:20 +0000308 return 0;
309}
310
311GLOBAL(int)
DRC6a61c1e2014-05-14 15:00:10 +0000312jsimd_can_h2v2_smooth_downsample (void)
313{
314 init_simd();
315
316 /* The code is optimised for these values only */
317 if (BITS_IN_JSAMPLE != 8)
318 return 0;
319 if (sizeof(JDIMENSION) != 4)
320 return 0;
321 if(DCTSIZE != 8)
322 return 0;
DRC14198522014-05-15 19:45:11 +0000323
DRC6a61c1e2014-05-14 15:00:10 +0000324 if (simd_support & JSIMD_MIPS_DSPR2)
325 return 1;
326
327 return 0;
328}
329
330GLOBAL(int)
DRC0be9fa52013-07-24 21:50:20 +0000331jsimd_can_h2v1_downsample (void)
332{
DRC6f2d3c22013-07-27 21:48:18 +0000333 init_simd();
334
335 /* The code is optimised for these values only */
336 if (BITS_IN_JSAMPLE != 8)
337 return 0;
338 if (sizeof(JDIMENSION) != 4)
339 return 0;
DRC14198522014-05-15 19:45:11 +0000340
DRC6f2d3c22013-07-27 21:48:18 +0000341 if (simd_support & JSIMD_MIPS_DSPR2)
342 return 1;
343
DRC0be9fa52013-07-24 21:50:20 +0000344 return 0;
345}
346
347GLOBAL(void)
348jsimd_h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
349 JSAMPARRAY input_data, JSAMPARRAY output_data)
350{
DRC6f2d3c22013-07-27 21:48:18 +0000351 if (simd_support & JSIMD_MIPS_DSPR2)
352 jsimd_h2v2_downsample_mips_dspr2(cinfo->image_width,
DRC14198522014-05-15 19:45:11 +0000353 cinfo->max_v_samp_factor,
354 compptr->v_samp_factor,
355 compptr->width_in_blocks, input_data,
356 output_data);
DRC0be9fa52013-07-24 21:50:20 +0000357}
358
359GLOBAL(void)
DRC14198522014-05-15 19:45:11 +0000360jsimd_h2v2_smooth_downsample (j_compress_ptr cinfo,
361 jpeg_component_info * compptr,
DRC6a61c1e2014-05-14 15:00:10 +0000362 JSAMPARRAY input_data, JSAMPARRAY output_data)
363{
364 jsimd_h2v2_smooth_downsample_mips_dspr2(input_data, output_data,
DRC14198522014-05-15 19:45:11 +0000365 compptr->v_samp_factor,
366 cinfo->max_v_samp_factor,
367 cinfo->smoothing_factor,
368 compptr->width_in_blocks,
369 cinfo->image_width);
DRC6a61c1e2014-05-14 15:00:10 +0000370}
371
372GLOBAL(void)
DRC0be9fa52013-07-24 21:50:20 +0000373jsimd_h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
374 JSAMPARRAY input_data, JSAMPARRAY output_data)
375{
DRC6f2d3c22013-07-27 21:48:18 +0000376 if (simd_support & JSIMD_MIPS_DSPR2)
377 jsimd_h2v1_downsample_mips_dspr2(cinfo->image_width,
DRC14198522014-05-15 19:45:11 +0000378 cinfo->max_v_samp_factor,
379 compptr->v_samp_factor,
380 compptr->width_in_blocks,
381 input_data, output_data);
DRC0be9fa52013-07-24 21:50:20 +0000382}
383
384GLOBAL(int)
385jsimd_can_h2v2_upsample (void)
386{
DRC16962c12013-07-27 21:50:02 +0000387 init_simd();
388
389 /* The code is optimised for these values only */
390 if (BITS_IN_JSAMPLE != 8)
391 return 0;
392 if (sizeof(JDIMENSION) != 4)
393 return 0;
DRC14198522014-05-15 19:45:11 +0000394
DRC16962c12013-07-27 21:50:02 +0000395 if (simd_support & JSIMD_MIPS_DSPR2)
396 return 1;
397
DRC0be9fa52013-07-24 21:50:20 +0000398 return 0;
399}
400
401GLOBAL(int)
402jsimd_can_h2v1_upsample (void)
403{
DRC16962c12013-07-27 21:50:02 +0000404 init_simd();
405
406 /* The code is optimised for these values only */
407 if (BITS_IN_JSAMPLE != 8)
408 return 0;
409 if (sizeof(JDIMENSION) != 4)
410 return 0;
DRC14198522014-05-15 19:45:11 +0000411
DRC16962c12013-07-27 21:50:02 +0000412 if (simd_support & JSIMD_MIPS_DSPR2)
413 return 1;
414
DRC0be9fa52013-07-24 21:50:20 +0000415 return 0;
416}
417
418GLOBAL(void)
419jsimd_h2v2_upsample (j_decompress_ptr cinfo,
420 jpeg_component_info * compptr,
421 JSAMPARRAY input_data,
422 JSAMPARRAY * output_data_ptr)
423{
DRC16962c12013-07-27 21:50:02 +0000424 if (simd_support & JSIMD_MIPS_DSPR2)
425 jsimd_h2v2_upsample_mips_dspr2(cinfo->max_v_samp_factor,
DRC14198522014-05-15 19:45:11 +0000426 cinfo->output_width, input_data,
427 output_data_ptr);
DRC0be9fa52013-07-24 21:50:20 +0000428}
429
430GLOBAL(void)
431jsimd_h2v1_upsample (j_decompress_ptr cinfo,
432 jpeg_component_info * compptr,
433 JSAMPARRAY input_data,
434 JSAMPARRAY * output_data_ptr)
435{
DRC16962c12013-07-27 21:50:02 +0000436 if (simd_support & JSIMD_MIPS_DSPR2)
437 jsimd_h2v1_upsample_mips_dspr2(cinfo->max_v_samp_factor,
DRC14198522014-05-15 19:45:11 +0000438 cinfo->output_width, input_data,
439 output_data_ptr);
DRC0be9fa52013-07-24 21:50:20 +0000440}
441
442GLOBAL(int)
443jsimd_can_h2v2_fancy_upsample (void)
444{
DRC86fbf352013-07-27 21:44:14 +0000445 init_simd();
446
447 /* The code is optimised for these values only */
448 if (BITS_IN_JSAMPLE != 8)
449 return 0;
450 if (sizeof(JDIMENSION) != 4)
451 return 0;
DRC14198522014-05-15 19:45:11 +0000452
DRC86fbf352013-07-27 21:44:14 +0000453 if (simd_support & JSIMD_MIPS_DSPR2)
454 return 1;
455
DRC0be9fa52013-07-24 21:50:20 +0000456 return 0;
457}
458
459GLOBAL(int)
460jsimd_can_h2v1_fancy_upsample (void)
461{
DRC86fbf352013-07-27 21:44:14 +0000462 init_simd();
463
464 /* The code is optimised for these values only */
465 if (BITS_IN_JSAMPLE != 8)
466 return 0;
467 if (sizeof(JDIMENSION) != 4)
468 return 0;
DRC14198522014-05-15 19:45:11 +0000469
DRC86fbf352013-07-27 21:44:14 +0000470 if (simd_support & JSIMD_MIPS_DSPR2)
471 return 1;
472
DRC0be9fa52013-07-24 21:50:20 +0000473 return 0;
474}
475
476GLOBAL(void)
477jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo,
478 jpeg_component_info * compptr,
479 JSAMPARRAY input_data,
480 JSAMPARRAY * output_data_ptr)
481{
DRC86fbf352013-07-27 21:44:14 +0000482 if (simd_support & JSIMD_MIPS_DSPR2)
483 jsimd_h2v2_fancy_upsample_mips_dspr2(cinfo->max_v_samp_factor,
DRC14198522014-05-15 19:45:11 +0000484 compptr->downsampled_width,
485 input_data, output_data_ptr);
DRC0be9fa52013-07-24 21:50:20 +0000486}
487
488GLOBAL(void)
489jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo,
490 jpeg_component_info * compptr,
491 JSAMPARRAY input_data,
492 JSAMPARRAY * output_data_ptr)
493{
DRC86fbf352013-07-27 21:44:14 +0000494 if (simd_support & JSIMD_MIPS_DSPR2)
495 jsimd_h2v1_fancy_upsample_mips_dspr2(cinfo->max_v_samp_factor,
DRC14198522014-05-15 19:45:11 +0000496 compptr->downsampled_width,
497 input_data, output_data_ptr);
DRC0be9fa52013-07-24 21:50:20 +0000498}
499
500GLOBAL(int)
501jsimd_can_h2v2_merged_upsample (void)
502{
DRCb844eaa2014-05-13 18:40:14 +0000503 if (BITS_IN_JSAMPLE != 8)
504 return 0;
505 if (sizeof(JDIMENSION) != 4)
506 return 0;
507
508 if (simd_support & JSIMD_MIPS_DSPR2)
509 return 1;
510
DRC0be9fa52013-07-24 21:50:20 +0000511 return 0;
512}
513
514GLOBAL(int)
515jsimd_can_h2v1_merged_upsample (void)
516{
DRCb844eaa2014-05-13 18:40:14 +0000517 if (BITS_IN_JSAMPLE != 8)
518 return 0;
519 if (sizeof(JDIMENSION) != 4)
520 return 0;
521
522 if (simd_support & JSIMD_MIPS_DSPR2)
523 return 1;
524
DRC0be9fa52013-07-24 21:50:20 +0000525 return 0;
526}
527
528GLOBAL(void)
529jsimd_h2v2_merged_upsample (j_decompress_ptr cinfo,
530 JSAMPIMAGE input_buf,
531 JDIMENSION in_row_group_ctr,
532 JSAMPARRAY output_buf)
533{
DRC14198522014-05-15 19:45:11 +0000534 void (*mipsdspr2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY,
535 JSAMPLE *);
DRCb844eaa2014-05-13 18:40:14 +0000536
DRC14198522014-05-15 19:45:11 +0000537 switch(cinfo->out_color_space) {
DRCb844eaa2014-05-13 18:40:14 +0000538 case JCS_EXT_RGB:
539 mipsdspr2fct=jsimd_h2v2_extrgb_merged_upsample_mips_dspr2;
540 break;
541 case JCS_EXT_RGBX:
542 case JCS_EXT_RGBA:
543 mipsdspr2fct=jsimd_h2v2_extrgbx_merged_upsample_mips_dspr2;
544 break;
545 case JCS_EXT_BGR:
546 mipsdspr2fct=jsimd_h2v2_extbgr_merged_upsample_mips_dspr2;
547 break;
548 case JCS_EXT_BGRX:
549 case JCS_EXT_BGRA:
550 mipsdspr2fct=jsimd_h2v2_extbgrx_merged_upsample_mips_dspr2;
551 break;
552 case JCS_EXT_XBGR:
553 case JCS_EXT_ABGR:
554 mipsdspr2fct=jsimd_h2v2_extxbgr_merged_upsample_mips_dspr2;
555 break;
556 case JCS_EXT_XRGB:
557 case JCS_EXT_ARGB:
558 mipsdspr2fct=jsimd_h2v2_extxrgb_merged_upsample_mips_dspr2;
559 break;
560 default:
561 mipsdspr2fct=jsimd_h2v2_extrgb_merged_upsample_mips_dspr2;
562 break;
563 }
564
DRC14198522014-05-15 19:45:11 +0000565 mipsdspr2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf,
566 cinfo->sample_range_limit);
DRC0be9fa52013-07-24 21:50:20 +0000567}
568
569GLOBAL(void)
570jsimd_h2v1_merged_upsample (j_decompress_ptr cinfo,
571 JSAMPIMAGE input_buf,
572 JDIMENSION in_row_group_ctr,
573 JSAMPARRAY output_buf)
574{
DRC14198522014-05-15 19:45:11 +0000575 void (*mipsdspr2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY,
576 JSAMPLE *);
DRCb844eaa2014-05-13 18:40:14 +0000577
DRC14198522014-05-15 19:45:11 +0000578 switch(cinfo->out_color_space) {
DRCb844eaa2014-05-13 18:40:14 +0000579 case JCS_EXT_RGB:
580 mipsdspr2fct=jsimd_h2v1_extrgb_merged_upsample_mips_dspr2;
581 break;
582 case JCS_EXT_RGBX:
583 case JCS_EXT_RGBA:
584 mipsdspr2fct=jsimd_h2v1_extrgbx_merged_upsample_mips_dspr2;
585 break;
586 case JCS_EXT_BGR:
587 mipsdspr2fct=jsimd_h2v1_extbgr_merged_upsample_mips_dspr2;
588 break;
589 case JCS_EXT_BGRX:
590 case JCS_EXT_BGRA:
591 mipsdspr2fct=jsimd_h2v1_extbgrx_merged_upsample_mips_dspr2;
592 break;
593 case JCS_EXT_XBGR:
594 case JCS_EXT_ABGR:
595 mipsdspr2fct=jsimd_h2v1_extxbgr_merged_upsample_mips_dspr2;
596 break;
597 case JCS_EXT_XRGB:
598 case JCS_EXT_ARGB:
599 mipsdspr2fct=jsimd_h2v1_extxrgb_merged_upsample_mips_dspr2;
600 break;
601 default:
602 mipsdspr2fct=jsimd_h2v1_extrgb_merged_upsample_mips_dspr2;
603 break;
604 }
605
DRC14198522014-05-15 19:45:11 +0000606 mipsdspr2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf,
607 cinfo->sample_range_limit);
DRC0be9fa52013-07-24 21:50:20 +0000608}
609
610GLOBAL(int)
611jsimd_can_convsamp (void)
612{
DRCfff6c232013-10-12 21:39:20 +0000613 init_simd();
614
615 /* The code is optimised for these values only */
616 if (DCTSIZE != 8)
617 return 0;
618 if (BITS_IN_JSAMPLE != 8)
619 return 0;
620 if (sizeof(JDIMENSION) != 4)
621 return 0;
622 if (sizeof(DCTELEM) != 2)
623 return 0;
624
625 if (simd_support & JSIMD_MIPS_DSPR2)
626 return 1;
627
DRC0be9fa52013-07-24 21:50:20 +0000628 return 0;
629}
630
631GLOBAL(int)
632jsimd_can_convsamp_float (void)
633{
DRC3d727282013-10-09 18:39:44 +0000634 init_simd();
635
636 /* The code is optimised for these values only */
637 if (DCTSIZE != 8)
638 return 0;
639 if (sizeof(JCOEF) != 2)
640 return 0;
641 if (BITS_IN_JSAMPLE != 8)
642 return 0;
643 if (sizeof(JDIMENSION) != 4)
644 return 0;
645 if (sizeof(ISLOW_MULT_TYPE) != 2)
646 return 0;
647
DRC14198522014-05-15 19:45:11 +0000648 if (simd_support & JSIMD_MIPS_DSPR2)
DRC3d727282013-10-09 18:39:44 +0000649 return 1;
650
DRC0be9fa52013-07-24 21:50:20 +0000651 return 0;
652}
653
654GLOBAL(void)
655jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col,
656 DCTELEM * workspace)
657{
DRCfff6c232013-10-12 21:39:20 +0000658 if (simd_support & JSIMD_MIPS_DSPR2)
659 jsimd_convsamp_mips_dspr2(sample_data, start_col, workspace);
DRC0be9fa52013-07-24 21:50:20 +0000660}
661
662GLOBAL(void)
663jsimd_convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col,
664 FAST_FLOAT * workspace)
665{
DRC3d727282013-10-09 18:39:44 +0000666 if ((simd_support & JSIMD_MIPS_DSPR2))
667 jsimd_convsamp_float_mips_dspr2(sample_data, start_col, workspace);
DRC0be9fa52013-07-24 21:50:20 +0000668}
669
670GLOBAL(int)
671jsimd_can_fdct_islow (void)
672{
DRCa6b7fbd2013-09-30 18:13:27 +0000673 init_simd();
674
675 /* The code is optimised for these values only */
676 if (DCTSIZE != 8)
677 return 0;
678 if (sizeof(DCTELEM) != 2)
679 return 0;
680
681 if (simd_support & JSIMD_MIPS_DSPR2)
682 return 1;
683
DRC0be9fa52013-07-24 21:50:20 +0000684 return 0;
685}
686
687GLOBAL(int)
688jsimd_can_fdct_ifast (void)
689{
DRC71e06a72013-10-08 02:11:21 +0000690 init_simd();
691
692 /* The code is optimised for these values only */
693 if (DCTSIZE != 8)
694 return 0;
695 if (sizeof(DCTELEM) != 2)
696 return 0;
697
698 if (simd_support & JSIMD_MIPS_DSPR2)
699 return 1;
700
DRC0be9fa52013-07-24 21:50:20 +0000701 return 0;
702}
703
704GLOBAL(int)
705jsimd_can_fdct_float (void)
706{
DRC14198522014-05-15 19:45:11 +0000707 init_simd();
708
DRC0be9fa52013-07-24 21:50:20 +0000709 return 0;
710}
711
712GLOBAL(void)
713jsimd_fdct_islow (DCTELEM * data)
714{
DRCa6b7fbd2013-09-30 18:13:27 +0000715 if (simd_support & JSIMD_MIPS_DSPR2)
716 jsimd_fdct_islow_mips_dspr2(data);
DRC0be9fa52013-07-24 21:50:20 +0000717}
718
719GLOBAL(void)
720jsimd_fdct_ifast (DCTELEM * data)
721{
DRC71e06a72013-10-08 02:11:21 +0000722 if (simd_support & JSIMD_MIPS_DSPR2)
723 jsimd_fdct_ifast_mips_dspr2(data);
DRC0be9fa52013-07-24 21:50:20 +0000724}
725
726GLOBAL(void)
727jsimd_fdct_float (FAST_FLOAT * data)
728{
729}
730
731GLOBAL(int)
732jsimd_can_quantize (void)
733{
DRCa6b7fbd2013-09-30 18:13:27 +0000734 init_simd();
735
736 /* The code is optimised for these values only */
737 if (DCTSIZE != 8)
738 return 0;
739 if (sizeof(JCOEF) != 2)
740 return 0;
741 if (sizeof(DCTELEM) != 2)
742 return 0;
743
744 if (simd_support & JSIMD_MIPS_DSPR2)
745 return 1;
746
DRC0be9fa52013-07-24 21:50:20 +0000747 return 0;
748}
749
750GLOBAL(int)
751jsimd_can_quantize_float (void)
752{
DRC3d727282013-10-09 18:39:44 +0000753 init_simd();
754
755 /* The code is optimised for these values only */
756 if (DCTSIZE != 8)
757 return 0;
758 if (sizeof(JCOEF) != 2)
759 return 0;
760 if (BITS_IN_JSAMPLE != 8)
761 return 0;
762 if (sizeof(JDIMENSION) != 4)
763 return 0;
764 if (sizeof(ISLOW_MULT_TYPE) != 2)
765 return 0;
766
DRC14198522014-05-15 19:45:11 +0000767 if (simd_support & JSIMD_MIPS_DSPR2)
DRC3d727282013-10-09 18:39:44 +0000768 return 1;
769
DRC0be9fa52013-07-24 21:50:20 +0000770 return 0;
771}
772
773GLOBAL(void)
774jsimd_quantize (JCOEFPTR coef_block, DCTELEM * divisors,
775 DCTELEM * workspace)
776{
DRCa6b7fbd2013-09-30 18:13:27 +0000777 if (simd_support & JSIMD_MIPS_DSPR2)
778 jsimd_quantize_mips_dspr2(coef_block, divisors, workspace);
DRC0be9fa52013-07-24 21:50:20 +0000779}
780
781GLOBAL(void)
782jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors,
783 FAST_FLOAT * workspace)
784{
DRC14198522014-05-15 19:45:11 +0000785 if (simd_support & JSIMD_MIPS_DSPR2)
DRC3d727282013-10-09 18:39:44 +0000786 jsimd_quantize_float_mips_dspr2(coef_block, divisors, workspace);
DRC0be9fa52013-07-24 21:50:20 +0000787}
788
789GLOBAL(int)
790jsimd_can_idct_2x2 (void)
791{
DRC2ccf4d12013-09-27 17:43:23 +0000792 init_simd();
793
794 /* The code is optimised for these values only */
795 if (DCTSIZE != 8)
796 return 0;
797 if (sizeof(JCOEF) != 2)
798 return 0;
799 if (BITS_IN_JSAMPLE != 8)
800 return 0;
801 if (sizeof(JDIMENSION) != 4)
802 return 0;
803 if (sizeof(ISLOW_MULT_TYPE) != 2)
804 return 0;
805
DRC14198522014-05-15 19:45:11 +0000806 if (simd_support & JSIMD_MIPS_DSPR2)
DRC2ccf4d12013-09-27 17:43:23 +0000807 return 1;
808
DRC0be9fa52013-07-24 21:50:20 +0000809 return 0;
810}
811
812GLOBAL(int)
813jsimd_can_idct_4x4 (void)
814{
DRC2ccf4d12013-09-27 17:43:23 +0000815 init_simd();
816
817 /* The code is optimised for these values only */
818 if (DCTSIZE != 8)
819 return 0;
820 if (sizeof(JCOEF) != 2)
821 return 0;
822 if (BITS_IN_JSAMPLE != 8)
823 return 0;
824 if (sizeof(JDIMENSION) != 4)
825 return 0;
826 if (sizeof(ISLOW_MULT_TYPE) != 2)
827 return 0;
828
DRC14198522014-05-15 19:45:11 +0000829 if (simd_support & JSIMD_MIPS_DSPR2)
DRC2ccf4d12013-09-27 17:43:23 +0000830 return 1;
831
DRC0be9fa52013-07-24 21:50:20 +0000832 return 0;
833}
834
DRCe5005912013-09-27 17:51:08 +0000835GLOBAL(int)
836jsimd_can_idct_6x6 (void)
837{
838 init_simd();
839
840 /* The code is optimised for these values only */
841 if (DCTSIZE != 8)
842 return 0;
843 if (sizeof(JCOEF) != 2)
844 return 0;
845 if (BITS_IN_JSAMPLE != 8)
846 return 0;
847 if (sizeof(JDIMENSION) != 4)
848 return 0;
849 if (sizeof(ISLOW_MULT_TYPE) != 2)
850 return 0;
851
DRC14198522014-05-15 19:45:11 +0000852 if (simd_support & JSIMD_MIPS_DSPR2)
DRCe5005912013-09-27 17:51:08 +0000853 return 1;
854
855 return 0;
856}
857
858GLOBAL(int)
859jsimd_can_idct_12x12 (void)
860{
861 init_simd();
862
863 if (BITS_IN_JSAMPLE != 8)
864 return 0;
865 if (DCTSIZE != 8)
866 return 0;
867 if (sizeof(JCOEF) != 2)
868 return 0;
869 if (sizeof(JDIMENSION) != 4)
870 return 0;
871 if (sizeof(ISLOW_MULT_TYPE) != 2)
872 return 0;
873
874 if (simd_support & JSIMD_MIPS_DSPR2)
875 return 1;
876
877 return 0;
878}
879
DRC0be9fa52013-07-24 21:50:20 +0000880GLOBAL(void)
881jsimd_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
882 JCOEFPTR coef_block, JSAMPARRAY output_buf,
883 JDIMENSION output_col)
884{
DRC14198522014-05-15 19:45:11 +0000885 if (simd_support & JSIMD_MIPS_DSPR2)
886 jsimd_idct_2x2_mips_dspr2(compptr->dct_table, coef_block, output_buf,
887 output_col);
DRC0be9fa52013-07-24 21:50:20 +0000888}
889
890GLOBAL(void)
891jsimd_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
892 JCOEFPTR coef_block, JSAMPARRAY output_buf,
893 JDIMENSION output_col)
894{
DRC14198522014-05-15 19:45:11 +0000895 if (simd_support & JSIMD_MIPS_DSPR2) {
DRC2ccf4d12013-09-27 17:43:23 +0000896 int workspace[DCTSIZE*4]; /* buffers data between passes */
DRC14198522014-05-15 19:45:11 +0000897 jsimd_idct_4x4_mips_dspr2(compptr->dct_table, coef_block, output_buf,
898 output_col, workspace);
DRC2ccf4d12013-09-27 17:43:23 +0000899 }
DRC0be9fa52013-07-24 21:50:20 +0000900}
DRCa6b7fbd2013-09-30 18:13:27 +0000901
DRCe5005912013-09-27 17:51:08 +0000902GLOBAL(void)
903jsimd_idct_6x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
904 JCOEFPTR coef_block, JSAMPARRAY output_buf,
905 JDIMENSION output_col)
906{
DRC14198522014-05-15 19:45:11 +0000907 if (simd_support & JSIMD_MIPS_DSPR2)
908 jsimd_idct_6x6_mips_dspr2(compptr->dct_table, coef_block, output_buf,
909 output_col);
DRCe5005912013-09-27 17:51:08 +0000910}
911
912GLOBAL(void)
913jsimd_idct_12x12 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
914 JCOEFPTR coef_block,
915 JSAMPARRAY output_buf, JDIMENSION output_col)
916{
917 if (simd_support & JSIMD_MIPS_DSPR2) {
918 int workspace[96];
919 int output[12] = {
920 (int)(output_buf[0] + output_col),
921 (int)(output_buf[1] + output_col),
922 (int)(output_buf[2] + output_col),
923 (int)(output_buf[3] + output_col),
924 (int)(output_buf[4] + output_col),
925 (int)(output_buf[5] + output_col),
926 (int)(output_buf[6] + output_col),
927 (int)(output_buf[7] + output_col),
928 (int)(output_buf[8] + output_col),
929 (int)(output_buf[9] + output_col),
930 (int)(output_buf[10] + output_col),
931 (int)(output_buf[11] + output_col),
932 };
DRC14198522014-05-15 19:45:11 +0000933 jsimd_idct_12x12_pass1_mips_dspr2(coef_block, compptr->dct_table,
934 workspace);
DRCe5005912013-09-27 17:51:08 +0000935 jsimd_idct_12x12_pass2_mips_dspr2(workspace, output);
936 }
937}
DRC0be9fa52013-07-24 21:50:20 +0000938
939GLOBAL(int)
940jsimd_can_idct_islow (void)
941{
DRC34347862014-05-06 09:53:21 +0000942 init_simd();
943
944 /* The code is optimised for these values only */
945 if (DCTSIZE != 8)
946 return 0;
947 if (sizeof(JCOEF) != 2)
948 return 0;
949 if (BITS_IN_JSAMPLE != 8)
950 return 0;
951 if (sizeof(JDIMENSION) != 4)
952 return 0;
953 if (sizeof(ISLOW_MULT_TYPE) != 2)
954 return 0;
955
956 if (simd_support & JSIMD_MIPS_DSPR2)
957 return 1;
958
DRC0be9fa52013-07-24 21:50:20 +0000959 return 0;
960}
961
962GLOBAL(int)
963jsimd_can_idct_ifast (void)
964{
DRCd3131c12013-10-08 02:18:59 +0000965 init_simd();
966
967 /* The code is optimised for these values only */
968 if (DCTSIZE != 8)
969 return 0;
970 if (sizeof(JCOEF) != 2)
971 return 0;
972 if (BITS_IN_JSAMPLE != 8)
973 return 0;
974 if (sizeof(JDIMENSION) != 4)
975 return 0;
976 if (sizeof(IFAST_MULT_TYPE) != 2)
977 return 0;
978 if (IFAST_SCALE_BITS != 2)
979 return 0;
980
DRC14198522014-05-15 19:45:11 +0000981 if (simd_support & JSIMD_MIPS_DSPR2)
DRCd3131c12013-10-08 02:18:59 +0000982 return 1;
983
DRC0be9fa52013-07-24 21:50:20 +0000984 return 0;
985}
986
987GLOBAL(int)
988jsimd_can_idct_float (void)
989{
DRC14198522014-05-15 19:45:11 +0000990 init_simd();
991
DRC0be9fa52013-07-24 21:50:20 +0000992 return 0;
993}
994
995GLOBAL(void)
996jsimd_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
DRC14198522014-05-15 19:45:11 +0000997 JCOEFPTR coef_block, JSAMPARRAY output_buf,
998 JDIMENSION output_col)
DRC0be9fa52013-07-24 21:50:20 +0000999{
DRC34347862014-05-06 09:53:21 +00001000 if (simd_support & JSIMD_MIPS_DSPR2) {
1001 int output[8] = {
1002 (int)(output_buf[0] + output_col),
1003 (int)(output_buf[1] + output_col),
1004 (int)(output_buf[2] + output_col),
1005 (int)(output_buf[3] + output_col),
1006 (int)(output_buf[4] + output_col),
1007 (int)(output_buf[5] + output_col),
1008 (int)(output_buf[6] + output_col),
1009 (int)(output_buf[7] + output_col),
1010 };
1011
1012 jsimd_idct_islow_mips_dspr2(coef_block, compptr->dct_table,
1013 output, IDCT_range_limit(cinfo));
1014 }
DRC0be9fa52013-07-24 21:50:20 +00001015}
1016
1017GLOBAL(void)
1018jsimd_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
DRCd3131c12013-10-08 02:18:59 +00001019 JCOEFPTR coef_block, JSAMPARRAY output_buf,
1020 JDIMENSION output_col)
DRC0be9fa52013-07-24 21:50:20 +00001021{
DRCd3131c12013-10-08 02:18:59 +00001022 if (simd_support & JSIMD_MIPS_DSPR2) {
1023 JCOEFPTR inptr;
1024 IFAST_MULT_TYPE * quantptr;
1025 DCTELEM workspace[DCTSIZE2]; /* buffers data between passes */
1026
1027 /* Pass 1: process columns from input, store into work array. */
1028
1029 inptr = coef_block;
1030 quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
1031
1032 jsimd_idct_ifast_cols_mips_dspr2(inptr, quantptr,
1033 workspace, mips_idct_ifast_coefs);
1034
1035 /* Pass 2: process rows from work array, store into output array. */
1036 /* Note that we must descale the results by a factor of 8 == 2**3, */
1037 /* and also undo the PASS1_BITS scaling. */
1038
1039 jsimd_idct_ifast_rows_mips_dspr2(workspace, output_buf,
1040 output_col, mips_idct_ifast_coefs);
1041 }
DRC0be9fa52013-07-24 21:50:20 +00001042}
1043
1044GLOBAL(void)
1045jsimd_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
DRC14198522014-05-15 19:45:11 +00001046 JCOEFPTR coef_block, JSAMPARRAY output_buf,
1047 JDIMENSION output_col)
DRC0be9fa52013-07-24 21:50:20 +00001048{
1049}