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