1 /*
2 * jsimd_powerpc.c
3 *
4 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5 * Copyright (C) 2009-2011, 2014-2016, D. R. Commander.
6 * Copyright (C) 2015, Matthieu Darbois.
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 a
14 * PowerPC architecture.
15 */
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
29 static unsigned int simd_support = ~0;
30
31 #if defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
32
33 #define SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT (1024 * 1024)
34
35 LOCAL(int)
check_feature(char * buffer,char * feature)36 check_feature (char *buffer, char *feature)
37 {
38 char *p;
39 if (*feature == 0)
40 return 0;
41 if (strncmp(buffer, "cpu", 3) != 0)
42 return 0;
43 buffer += 3;
44 while (isspace(*buffer))
45 buffer++;
46
47 /* Check if 'feature' is present in the buffer as a separate word */
48 while ((p = strstr(buffer, feature))) {
49 if (p > buffer && !isspace(*(p - 1))) {
50 buffer++;
51 continue;
52 }
53 p += strlen(feature);
54 if (*p != 0 && !isspace(*p)) {
55 buffer++;
56 continue;
57 }
58 return 1;
59 }
60 return 0;
61 }
62
63 LOCAL(int)
parse_proc_cpuinfo(int bufsize)64 parse_proc_cpuinfo (int bufsize)
65 {
66 char *buffer = (char *)malloc(bufsize);
67 FILE *fd;
68 simd_support = 0;
69
70 if (!buffer)
71 return 0;
72
73 fd = fopen("/proc/cpuinfo", "r");
74 if (fd) {
75 while (fgets(buffer, bufsize, fd)) {
76 if (!strchr(buffer, '\n') && !feof(fd)) {
77 /* "impossible" happened - insufficient size of the buffer! */
78 fclose(fd);
79 free(buffer);
80 return 0;
81 }
82 if (check_feature(buffer, "altivec"))
83 simd_support |= JSIMD_ALTIVEC;
84 }
85 fclose(fd);
86 }
87 free(buffer);
88 return 1;
89 }
90
91 #endif
92
93 /*
94 * Check what SIMD accelerations are supported.
95 *
96 * FIXME: This code is racy under a multi-threaded environment.
97 */
98 LOCAL(void)
init_simd(void)99 init_simd (void)
100 {
101 char *env = NULL;
102 #if !defined(__ALTIVEC__) && (defined(__linux__) || defined(ANDROID) || defined(__ANDROID__))
103 int bufsize = 1024; /* an initial guess for the line buffer size limit */
104 #endif
105
106 if (simd_support != ~0U)
107 return;
108
109 simd_support = 0;
110
111 #if defined(__ALTIVEC__) || defined(__APPLE__)
112 simd_support |= JSIMD_ALTIVEC;
113 #elif defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
114 while (!parse_proc_cpuinfo(bufsize)) {
115 bufsize *= 2;
116 if (bufsize > SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT)
117 break;
118 }
119 #endif
120
121 /* Force different settings through environment variables */
122 env = getenv("JSIMD_FORCEALTIVEC");
123 if ((env != NULL) && (strcmp(env, "1") == 0))
124 simd_support = JSIMD_ALTIVEC;
125 env = getenv("JSIMD_FORCENONE");
126 if ((env != NULL) && (strcmp(env, "1") == 0))
127 simd_support = 0;
128 }
129
130 GLOBAL(int)
jsimd_can_rgb_ycc(void)131 jsimd_can_rgb_ycc (void)
132 {
133 init_simd();
134
135 /* The code is optimised for these values only */
136 if (BITS_IN_JSAMPLE != 8)
137 return 0;
138 if (sizeof(JDIMENSION) != 4)
139 return 0;
140 if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
141 return 0;
142
143 if (simd_support & JSIMD_ALTIVEC)
144 return 1;
145
146 return 0;
147 }
148
149 GLOBAL(int)
jsimd_can_rgb_gray(void)150 jsimd_can_rgb_gray (void)
151 {
152 init_simd();
153
154 /* The code is optimised for these values only */
155 if (BITS_IN_JSAMPLE != 8)
156 return 0;
157 if (sizeof(JDIMENSION) != 4)
158 return 0;
159 if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
160 return 0;
161
162 if (simd_support & JSIMD_ALTIVEC)
163 return 1;
164
165 return 0;
166 }
167
168 GLOBAL(int)
jsimd_can_ycc_rgb(void)169 jsimd_can_ycc_rgb (void)
170 {
171 init_simd();
172
173 /* The code is optimised for these values only */
174 if (BITS_IN_JSAMPLE != 8)
175 return 0;
176 if (sizeof(JDIMENSION) != 4)
177 return 0;
178 if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
179 return 0;
180
181 if (simd_support & JSIMD_ALTIVEC)
182 return 1;
183
184 return 0;
185 }
186
187 GLOBAL(int)
jsimd_can_ycc_rgb565(void)188 jsimd_can_ycc_rgb565 (void)
189 {
190 return 0;
191 }
192
193 GLOBAL(void)
jsimd_rgb_ycc_convert(j_compress_ptr cinfo,JSAMPARRAY input_buf,JSAMPIMAGE output_buf,JDIMENSION output_row,int num_rows)194 jsimd_rgb_ycc_convert (j_compress_ptr cinfo,
195 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
196 JDIMENSION output_row, int num_rows)
197 {
198 void (*altivecfct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
199
200 switch(cinfo->in_color_space) {
201 case JCS_EXT_RGB:
202 altivecfct=jsimd_extrgb_ycc_convert_altivec;
203 break;
204 case JCS_EXT_RGBX:
205 case JCS_EXT_RGBA:
206 altivecfct=jsimd_extrgbx_ycc_convert_altivec;
207 break;
208 case JCS_EXT_BGR:
209 altivecfct=jsimd_extbgr_ycc_convert_altivec;
210 break;
211 case JCS_EXT_BGRX:
212 case JCS_EXT_BGRA:
213 altivecfct=jsimd_extbgrx_ycc_convert_altivec;
214 break;
215 case JCS_EXT_XBGR:
216 case JCS_EXT_ABGR:
217 altivecfct=jsimd_extxbgr_ycc_convert_altivec;
218 break;
219 case JCS_EXT_XRGB:
220 case JCS_EXT_ARGB:
221 altivecfct=jsimd_extxrgb_ycc_convert_altivec;
222 break;
223 default:
224 altivecfct=jsimd_rgb_ycc_convert_altivec;
225 break;
226 }
227
228 altivecfct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
229 }
230
231 GLOBAL(void)
jsimd_rgb_gray_convert(j_compress_ptr cinfo,JSAMPARRAY input_buf,JSAMPIMAGE output_buf,JDIMENSION output_row,int num_rows)232 jsimd_rgb_gray_convert (j_compress_ptr cinfo,
233 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
234 JDIMENSION output_row, int num_rows)
235 {
236 void (*altivecfct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
237
238 switch(cinfo->in_color_space) {
239 case JCS_EXT_RGB:
240 altivecfct=jsimd_extrgb_gray_convert_altivec;
241 break;
242 case JCS_EXT_RGBX:
243 case JCS_EXT_RGBA:
244 altivecfct=jsimd_extrgbx_gray_convert_altivec;
245 break;
246 case JCS_EXT_BGR:
247 altivecfct=jsimd_extbgr_gray_convert_altivec;
248 break;
249 case JCS_EXT_BGRX:
250 case JCS_EXT_BGRA:
251 altivecfct=jsimd_extbgrx_gray_convert_altivec;
252 break;
253 case JCS_EXT_XBGR:
254 case JCS_EXT_ABGR:
255 altivecfct=jsimd_extxbgr_gray_convert_altivec;
256 break;
257 case JCS_EXT_XRGB:
258 case JCS_EXT_ARGB:
259 altivecfct=jsimd_extxrgb_gray_convert_altivec;
260 break;
261 default:
262 altivecfct=jsimd_rgb_gray_convert_altivec;
263 break;
264 }
265
266 altivecfct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
267 }
268
269 GLOBAL(void)
jsimd_ycc_rgb_convert(j_decompress_ptr cinfo,JSAMPIMAGE input_buf,JDIMENSION input_row,JSAMPARRAY output_buf,int num_rows)270 jsimd_ycc_rgb_convert (j_decompress_ptr cinfo,
271 JSAMPIMAGE input_buf, JDIMENSION input_row,
272 JSAMPARRAY output_buf, int num_rows)
273 {
274 void (*altivecfct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
275
276 switch(cinfo->out_color_space) {
277 case JCS_EXT_RGB:
278 altivecfct=jsimd_ycc_extrgb_convert_altivec;
279 break;
280 case JCS_EXT_RGBX:
281 case JCS_EXT_RGBA:
282 altivecfct=jsimd_ycc_extrgbx_convert_altivec;
283 break;
284 case JCS_EXT_BGR:
285 altivecfct=jsimd_ycc_extbgr_convert_altivec;
286 break;
287 case JCS_EXT_BGRX:
288 case JCS_EXT_BGRA:
289 altivecfct=jsimd_ycc_extbgrx_convert_altivec;
290 break;
291 case JCS_EXT_XBGR:
292 case JCS_EXT_ABGR:
293 altivecfct=jsimd_ycc_extxbgr_convert_altivec;
294 break;
295 case JCS_EXT_XRGB:
296 case JCS_EXT_ARGB:
297 altivecfct=jsimd_ycc_extxrgb_convert_altivec;
298 break;
299 default:
300 altivecfct=jsimd_ycc_rgb_convert_altivec;
301 break;
302 }
303
304 altivecfct(cinfo->output_width, input_buf, input_row, output_buf, num_rows);
305 }
306
307 GLOBAL(void)
jsimd_ycc_rgb565_convert(j_decompress_ptr cinfo,JSAMPIMAGE input_buf,JDIMENSION input_row,JSAMPARRAY output_buf,int num_rows)308 jsimd_ycc_rgb565_convert (j_decompress_ptr cinfo,
309 JSAMPIMAGE input_buf, JDIMENSION input_row,
310 JSAMPARRAY output_buf, int num_rows)
311 {
312 }
313
314 GLOBAL(int)
jsimd_can_h2v2_downsample(void)315 jsimd_can_h2v2_downsample (void)
316 {
317 init_simd();
318
319 /* The code is optimised for these values only */
320 if (BITS_IN_JSAMPLE != 8)
321 return 0;
322 if (sizeof(JDIMENSION) != 4)
323 return 0;
324
325 if (simd_support & JSIMD_ALTIVEC)
326 return 1;
327
328 return 0;
329 }
330
331 GLOBAL(int)
jsimd_can_h2v1_downsample(void)332 jsimd_can_h2v1_downsample (void)
333 {
334 init_simd();
335
336 /* The code is optimised for these values only */
337 if (BITS_IN_JSAMPLE != 8)
338 return 0;
339 if (sizeof(JDIMENSION) != 4)
340 return 0;
341
342 if (simd_support & JSIMD_ALTIVEC)
343 return 1;
344
345 return 0;
346 }
347
348 GLOBAL(void)
jsimd_h2v2_downsample(j_compress_ptr cinfo,jpeg_component_info * compptr,JSAMPARRAY input_data,JSAMPARRAY output_data)349 jsimd_h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
350 JSAMPARRAY input_data, JSAMPARRAY output_data)
351 {
352 jsimd_h2v2_downsample_altivec(cinfo->image_width, cinfo->max_v_samp_factor,
353 compptr->v_samp_factor,
354 compptr->width_in_blocks,
355 input_data, output_data);
356 }
357
358 GLOBAL(void)
jsimd_h2v1_downsample(j_compress_ptr cinfo,jpeg_component_info * compptr,JSAMPARRAY input_data,JSAMPARRAY output_data)359 jsimd_h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
360 JSAMPARRAY input_data, JSAMPARRAY output_data)
361 {
362 jsimd_h2v1_downsample_altivec(cinfo->image_width, cinfo->max_v_samp_factor,
363 compptr->v_samp_factor,
364 compptr->width_in_blocks,
365 input_data, output_data);
366 }
367
368 GLOBAL(int)
jsimd_can_h2v2_upsample(void)369 jsimd_can_h2v2_upsample (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_ALTIVEC)
380 return 1;
381
382 return 0;
383 }
384
385 GLOBAL(int)
jsimd_can_h2v1_upsample(void)386 jsimd_can_h2v1_upsample (void)
387 {
388 init_simd();
389
390 /* The code is optimised for these values only */
391 if (BITS_IN_JSAMPLE != 8)
392 return 0;
393 if (sizeof(JDIMENSION) != 4)
394 return 0;
395
396 if (simd_support & JSIMD_ALTIVEC)
397 return 1;
398
399 return 0;
400 }
401
402 GLOBAL(void)
jsimd_h2v2_upsample(j_decompress_ptr cinfo,jpeg_component_info * compptr,JSAMPARRAY input_data,JSAMPARRAY * output_data_ptr)403 jsimd_h2v2_upsample (j_decompress_ptr cinfo,
404 jpeg_component_info *compptr,
405 JSAMPARRAY input_data,
406 JSAMPARRAY *output_data_ptr)
407 {
408 jsimd_h2v2_upsample_altivec(cinfo->max_v_samp_factor, cinfo->output_width,
409 input_data, output_data_ptr);
410 }
411
412 GLOBAL(void)
jsimd_h2v1_upsample(j_decompress_ptr cinfo,jpeg_component_info * compptr,JSAMPARRAY input_data,JSAMPARRAY * output_data_ptr)413 jsimd_h2v1_upsample (j_decompress_ptr cinfo,
414 jpeg_component_info *compptr,
415 JSAMPARRAY input_data,
416 JSAMPARRAY *output_data_ptr)
417 {
418 jsimd_h2v1_upsample_altivec(cinfo->max_v_samp_factor, cinfo->output_width,
419 input_data, output_data_ptr);
420 }
421
422 GLOBAL(int)
jsimd_can_h2v2_fancy_upsample(void)423 jsimd_can_h2v2_fancy_upsample (void)
424 {
425 init_simd();
426
427 /* The code is optimised for these values only */
428 if (BITS_IN_JSAMPLE != 8)
429 return 0;
430 if (sizeof(JDIMENSION) != 4)
431 return 0;
432
433 if (simd_support & JSIMD_ALTIVEC)
434 return 1;
435
436 return 0;
437 }
438
439 GLOBAL(int)
jsimd_can_h2v1_fancy_upsample(void)440 jsimd_can_h2v1_fancy_upsample (void)
441 {
442 init_simd();
443
444 /* The code is optimised for these values only */
445 if (BITS_IN_JSAMPLE != 8)
446 return 0;
447 if (sizeof(JDIMENSION) != 4)
448 return 0;
449
450 if (simd_support & JSIMD_ALTIVEC)
451 return 1;
452
453 return 0;
454 }
455
456 GLOBAL(void)
jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo,jpeg_component_info * compptr,JSAMPARRAY input_data,JSAMPARRAY * output_data_ptr)457 jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo,
458 jpeg_component_info *compptr,
459 JSAMPARRAY input_data,
460 JSAMPARRAY *output_data_ptr)
461 {
462 jsimd_h2v2_fancy_upsample_altivec(cinfo->max_v_samp_factor,
463 compptr->downsampled_width, input_data,
464 output_data_ptr);
465 }
466
467 GLOBAL(void)
jsimd_h2v1_fancy_upsample(j_decompress_ptr cinfo,jpeg_component_info * compptr,JSAMPARRAY input_data,JSAMPARRAY * output_data_ptr)468 jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo,
469 jpeg_component_info *compptr,
470 JSAMPARRAY input_data,
471 JSAMPARRAY *output_data_ptr)
472 {
473 jsimd_h2v1_fancy_upsample_altivec(cinfo->max_v_samp_factor,
474 compptr->downsampled_width, input_data,
475 output_data_ptr);
476 }
477
478 GLOBAL(int)
jsimd_can_h2v2_merged_upsample(void)479 jsimd_can_h2v2_merged_upsample (void)
480 {
481 init_simd();
482
483 /* The code is optimised for these values only */
484 if (BITS_IN_JSAMPLE != 8)
485 return 0;
486 if (sizeof(JDIMENSION) != 4)
487 return 0;
488
489 if (simd_support & JSIMD_ALTIVEC)
490 return 1;
491
492 return 0;
493 }
494
495 GLOBAL(int)
jsimd_can_h2v1_merged_upsample(void)496 jsimd_can_h2v1_merged_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_ALTIVEC)
507 return 1;
508
509 return 0;
510 }
511
512 GLOBAL(void)
jsimd_h2v2_merged_upsample(j_decompress_ptr cinfo,JSAMPIMAGE input_buf,JDIMENSION in_row_group_ctr,JSAMPARRAY output_buf)513 jsimd_h2v2_merged_upsample (j_decompress_ptr cinfo,
514 JSAMPIMAGE input_buf,
515 JDIMENSION in_row_group_ctr,
516 JSAMPARRAY output_buf)
517 {
518 void (*altivecfct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
519
520 switch(cinfo->out_color_space) {
521 case JCS_EXT_RGB:
522 altivecfct=jsimd_h2v2_extrgb_merged_upsample_altivec;
523 break;
524 case JCS_EXT_RGBX:
525 case JCS_EXT_RGBA:
526 altivecfct=jsimd_h2v2_extrgbx_merged_upsample_altivec;
527 break;
528 case JCS_EXT_BGR:
529 altivecfct=jsimd_h2v2_extbgr_merged_upsample_altivec;
530 break;
531 case JCS_EXT_BGRX:
532 case JCS_EXT_BGRA:
533 altivecfct=jsimd_h2v2_extbgrx_merged_upsample_altivec;
534 break;
535 case JCS_EXT_XBGR:
536 case JCS_EXT_ABGR:
537 altivecfct=jsimd_h2v2_extxbgr_merged_upsample_altivec;
538 break;
539 case JCS_EXT_XRGB:
540 case JCS_EXT_ARGB:
541 altivecfct=jsimd_h2v2_extxrgb_merged_upsample_altivec;
542 break;
543 default:
544 altivecfct=jsimd_h2v2_merged_upsample_altivec;
545 break;
546 }
547
548 altivecfct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
549 }
550
551 GLOBAL(void)
jsimd_h2v1_merged_upsample(j_decompress_ptr cinfo,JSAMPIMAGE input_buf,JDIMENSION in_row_group_ctr,JSAMPARRAY output_buf)552 jsimd_h2v1_merged_upsample (j_decompress_ptr cinfo,
553 JSAMPIMAGE input_buf,
554 JDIMENSION in_row_group_ctr,
555 JSAMPARRAY output_buf)
556 {
557 void (*altivecfct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
558
559 switch(cinfo->out_color_space) {
560 case JCS_EXT_RGB:
561 altivecfct=jsimd_h2v1_extrgb_merged_upsample_altivec;
562 break;
563 case JCS_EXT_RGBX:
564 case JCS_EXT_RGBA:
565 altivecfct=jsimd_h2v1_extrgbx_merged_upsample_altivec;
566 break;
567 case JCS_EXT_BGR:
568 altivecfct=jsimd_h2v1_extbgr_merged_upsample_altivec;
569 break;
570 case JCS_EXT_BGRX:
571 case JCS_EXT_BGRA:
572 altivecfct=jsimd_h2v1_extbgrx_merged_upsample_altivec;
573 break;
574 case JCS_EXT_XBGR:
575 case JCS_EXT_ABGR:
576 altivecfct=jsimd_h2v1_extxbgr_merged_upsample_altivec;
577 break;
578 case JCS_EXT_XRGB:
579 case JCS_EXT_ARGB:
580 altivecfct=jsimd_h2v1_extxrgb_merged_upsample_altivec;
581 break;
582 default:
583 altivecfct=jsimd_h2v1_merged_upsample_altivec;
584 break;
585 }
586
587 altivecfct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
588 }
589
590 GLOBAL(int)
jsimd_can_convsamp(void)591 jsimd_can_convsamp (void)
592 {
593 init_simd();
594
595 /* The code is optimised for these values only */
596 if (DCTSIZE != 8)
597 return 0;
598 if (BITS_IN_JSAMPLE != 8)
599 return 0;
600 if (sizeof(JDIMENSION) != 4)
601 return 0;
602 if (sizeof(DCTELEM) != 2)
603 return 0;
604
605 if (simd_support & JSIMD_ALTIVEC)
606 return 1;
607
608 return 0;
609 }
610
611 GLOBAL(int)
jsimd_can_convsamp_float(void)612 jsimd_can_convsamp_float (void)
613 {
614 return 0;
615 }
616
617 GLOBAL(void)
jsimd_convsamp(JSAMPARRAY sample_data,JDIMENSION start_col,DCTELEM * workspace)618 jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col,
619 DCTELEM *workspace)
620 {
621 jsimd_convsamp_altivec(sample_data, start_col, workspace);
622 }
623
624 GLOBAL(void)
jsimd_convsamp_float(JSAMPARRAY sample_data,JDIMENSION start_col,FAST_FLOAT * workspace)625 jsimd_convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col,
626 FAST_FLOAT *workspace)
627 {
628 }
629
630 GLOBAL(int)
jsimd_can_fdct_islow(void)631 jsimd_can_fdct_islow (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(DCTELEM) != 2)
639 return 0;
640
641 if (simd_support & JSIMD_ALTIVEC)
642 return 1;
643
644 return 0;
645 }
646
647 GLOBAL(int)
jsimd_can_fdct_ifast(void)648 jsimd_can_fdct_ifast (void)
649 {
650 init_simd();
651
652 /* The code is optimised for these values only */
653 if (DCTSIZE != 8)
654 return 0;
655 if (sizeof(DCTELEM) != 2)
656 return 0;
657
658 if (simd_support & JSIMD_ALTIVEC)
659 return 1;
660
661 return 0;
662 }
663
664 GLOBAL(int)
jsimd_can_fdct_float(void)665 jsimd_can_fdct_float (void)
666 {
667 return 0;
668 }
669
670 GLOBAL(void)
jsimd_fdct_islow(DCTELEM * data)671 jsimd_fdct_islow (DCTELEM *data)
672 {
673 jsimd_fdct_islow_altivec(data);
674 }
675
676 GLOBAL(void)
jsimd_fdct_ifast(DCTELEM * data)677 jsimd_fdct_ifast (DCTELEM *data)
678 {
679 jsimd_fdct_ifast_altivec(data);
680 }
681
682 GLOBAL(void)
jsimd_fdct_float(FAST_FLOAT * data)683 jsimd_fdct_float (FAST_FLOAT *data)
684 {
685 }
686
687 GLOBAL(int)
jsimd_can_quantize(void)688 jsimd_can_quantize (void)
689 {
690 init_simd();
691
692 /* The code is optimised for these values only */
693 if (DCTSIZE != 8)
694 return 0;
695 if (sizeof(JCOEF) != 2)
696 return 0;
697 if (sizeof(DCTELEM) != 2)
698 return 0;
699
700 if (simd_support & JSIMD_ALTIVEC)
701 return 1;
702
703 return 0;
704 }
705
706 GLOBAL(int)
jsimd_can_quantize_float(void)707 jsimd_can_quantize_float (void)
708 {
709 return 0;
710 }
711
712 GLOBAL(void)
jsimd_quantize(JCOEFPTR coef_block,DCTELEM * divisors,DCTELEM * workspace)713 jsimd_quantize (JCOEFPTR coef_block, DCTELEM *divisors,
714 DCTELEM *workspace)
715 {
716 jsimd_quantize_altivec(coef_block, divisors, workspace);
717 }
718
719 GLOBAL(void)
jsimd_quantize_float(JCOEFPTR coef_block,FAST_FLOAT * divisors,FAST_FLOAT * workspace)720 jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT *divisors,
721 FAST_FLOAT *workspace)
722 {
723 }
724
725 GLOBAL(int)
jsimd_can_idct_2x2(void)726 jsimd_can_idct_2x2 (void)
727 {
728 return 0;
729 }
730
731 GLOBAL(int)
jsimd_can_idct_4x4(void)732 jsimd_can_idct_4x4 (void)
733 {
734 return 0;
735 }
736
737 GLOBAL(void)
jsimd_idct_2x2(j_decompress_ptr cinfo,jpeg_component_info * compptr,JCOEFPTR coef_block,JSAMPARRAY output_buf,JDIMENSION output_col)738 jsimd_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info *compptr,
739 JCOEFPTR coef_block, JSAMPARRAY output_buf,
740 JDIMENSION output_col)
741 {
742 }
743
744 GLOBAL(void)
jsimd_idct_4x4(j_decompress_ptr cinfo,jpeg_component_info * compptr,JCOEFPTR coef_block,JSAMPARRAY output_buf,JDIMENSION output_col)745 jsimd_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info *compptr,
746 JCOEFPTR coef_block, JSAMPARRAY output_buf,
747 JDIMENSION output_col)
748 {
749 }
750
751 GLOBAL(int)
jsimd_can_idct_islow(void)752 jsimd_can_idct_islow (void)
753 {
754 init_simd();
755
756 /* The code is optimised for these values only */
757 if (DCTSIZE != 8)
758 return 0;
759 if (sizeof(JCOEF) != 2)
760 return 0;
761
762 if (simd_support & JSIMD_ALTIVEC)
763 return 1;
764
765 return 0;
766 }
767
768 GLOBAL(int)
jsimd_can_idct_ifast(void)769 jsimd_can_idct_ifast (void)
770 {
771 init_simd();
772
773 /* The code is optimised for these values only */
774 if (DCTSIZE != 8)
775 return 0;
776 if (sizeof(JCOEF) != 2)
777 return 0;
778
779 if (simd_support & JSIMD_ALTIVEC)
780 return 1;
781
782 return 0;
783 }
784
785 GLOBAL(int)
jsimd_can_idct_float(void)786 jsimd_can_idct_float (void)
787 {
788 return 0;
789 }
790
791 GLOBAL(void)
jsimd_idct_islow(j_decompress_ptr cinfo,jpeg_component_info * compptr,JCOEFPTR coef_block,JSAMPARRAY output_buf,JDIMENSION output_col)792 jsimd_idct_islow (j_decompress_ptr cinfo, jpeg_component_info *compptr,
793 JCOEFPTR coef_block, JSAMPARRAY output_buf,
794 JDIMENSION output_col)
795 {
796 jsimd_idct_islow_altivec(compptr->dct_table, coef_block, output_buf,
797 output_col);
798 }
799
800 GLOBAL(void)
jsimd_idct_ifast(j_decompress_ptr cinfo,jpeg_component_info * compptr,JCOEFPTR coef_block,JSAMPARRAY output_buf,JDIMENSION output_col)801 jsimd_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info *compptr,
802 JCOEFPTR coef_block, JSAMPARRAY output_buf,
803 JDIMENSION output_col)
804 {
805 jsimd_idct_ifast_altivec(compptr->dct_table, coef_block, output_buf,
806 output_col);
807 }
808
809 GLOBAL(void)
jsimd_idct_float(j_decompress_ptr cinfo,jpeg_component_info * compptr,JCOEFPTR coef_block,JSAMPARRAY output_buf,JDIMENSION output_col)810 jsimd_idct_float (j_decompress_ptr cinfo, jpeg_component_info *compptr,
811 JCOEFPTR coef_block, JSAMPARRAY output_buf,
812 JDIMENSION output_col)
813 {
814 }
815
816 GLOBAL(int)
jsimd_can_huff_encode_one_block(void)817 jsimd_can_huff_encode_one_block (void)
818 {
819 return 0;
820 }
821
822 GLOBAL(JOCTET*)
jsimd_huff_encode_one_block(void * state,JOCTET * buffer,JCOEFPTR block,int last_dc_val,c_derived_tbl * dctbl,c_derived_tbl * actbl)823 jsimd_huff_encode_one_block (void *state, JOCTET *buffer, JCOEFPTR block,
824 int last_dc_val, c_derived_tbl *dctbl,
825 c_derived_tbl *actbl)
826 {
827 return NULL;
828 }
829