blob: 6da8bd8913c4fcddd71940d72a440f56b3a936f9 [file] [log] [blame]
Pierre Ossman59a39382009-03-09 13:15:56 +00001/*
Pierre Ossmanba82ddf2009-06-29 11:20:42 +00002 * jsimd_i386.c
Pierre Ossman59a39382009-03-09 13:15:56 +00003 *
4 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
Alex Naidis6eb7d372016-10-16 23:10:08 +02005 * Copyright (C) 2009-2011, 2013-2014, 2016, D. R. Commander.
6 * Copyright (C) 2015, Matthieu Darbois.
DRC1a45b812014-05-09 18:06:58 +00007 *
Pierre Ossman59a39382009-03-09 13:15:56 +00008 * Based on the x86 SIMD extension for IJG JPEG library,
9 * Copyright (C) 1999-2006, MIYASAKA Masaru.
DRCaf1ca9b2011-02-02 05:42:37 +000010 * For conditions of distribution and use, see copyright notice in jsimdext.inc
Pierre Ossman59a39382009-03-09 13:15:56 +000011 *
12 * This file contains the interface between the "normal" portions
Pierre Ossmanba82ddf2009-06-29 11:20:42 +000013 * of the library and the SIMD implementations when running on a
14 * 32-bit x86 architecture.
Pierre Ossman59a39382009-03-09 13:15:56 +000015 */
16
17#define JPEG_INTERNALS
Pierre Ossmanba82ddf2009-06-29 11:20:42 +000018#include "../jinclude.h"
19#include "../jpeglib.h"
20#include "../jsimd.h"
21#include "../jdct.h"
22#include "../jsimddct.h"
Peter Åstrandadfd2332009-08-19 13:53:48 +000023#include "jsimd.h"
Pierre Ossman59a39382009-03-09 13:15:56 +000024
Pierre Ossman018fc422009-03-09 13:31:56 +000025/*
26 * In the PIC cases, we have no guarantee that constants will keep
27 * their alignment. This macro allows us to verify it at runtime.
28 */
Pierre Ossman018fc422009-03-09 13:31:56 +000029#define IS_ALIGNED(ptr, order) (((unsigned)ptr & ((1 << order) - 1)) == 0)
Pierre Ossman018fc422009-03-09 13:31:56 +000030
31#define IS_ALIGNED_SSE(ptr) (IS_ALIGNED(ptr, 4)) /* 16 byte alignment */
32
Pierre Ossman59a39382009-03-09 13:15:56 +000033static unsigned int simd_support = ~0;
Alex Naidis6eb7d372016-10-16 23:10:08 +020034static unsigned int simd_huffman = 1;
Pierre Ossman59a39382009-03-09 13:15:56 +000035
36/*
37 * Check what SIMD accelerations are supported.
38 *
39 * FIXME: This code is racy under a multi-threaded environment.
40 */
41LOCAL(void)
42init_simd (void)
43{
DRC59c1a252009-04-03 11:27:17 +000044 char *env = NULL;
Pierre Ossmanba82ddf2009-06-29 11:20:42 +000045
DRCd65d99a2012-01-31 03:39:23 +000046 if (simd_support != ~0U)
Pierre Ossman59a39382009-03-09 13:15:56 +000047 return;
48
Pierre Ossman2ae181c2009-03-09 13:21:27 +000049 simd_support = jpeg_simd_cpu_support();
Pierre Ossmanba82ddf2009-06-29 11:20:42 +000050
51 /* Force different settings through environment variables */
52 env = getenv("JSIMD_FORCEMMX");
53 if ((env != NULL) && (strcmp(env, "1") == 0))
DRCf8b77c42010-03-03 08:46:29 +000054 simd_support &= JSIMD_MMX;
Pierre Ossmanba82ddf2009-06-29 11:20:42 +000055 env = getenv("JSIMD_FORCE3DNOW");
56 if ((env != NULL) && (strcmp(env, "1") == 0))
DRCf8b77c42010-03-03 08:46:29 +000057 simd_support &= JSIMD_3DNOW|JSIMD_MMX;
Pierre Ossmanba82ddf2009-06-29 11:20:42 +000058 env = getenv("JSIMD_FORCESSE");
59 if ((env != NULL) && (strcmp(env, "1") == 0))
DRCf8b77c42010-03-03 08:46:29 +000060 simd_support &= JSIMD_SSE|JSIMD_MMX;
Pierre Ossmanba82ddf2009-06-29 11:20:42 +000061 env = getenv("JSIMD_FORCESSE2");
62 if ((env != NULL) && (strcmp(env, "1") == 0))
DRCf8b77c42010-03-03 08:46:29 +000063 simd_support &= JSIMD_SSE2;
DRC19eeaa72013-10-31 07:40:24 +000064 env = getenv("JSIMD_FORCENONE");
65 if ((env != NULL) && (strcmp(env, "1") == 0))
66 simd_support = 0;
Alex Naidis6eb7d372016-10-16 23:10:08 +020067 env = getenv("JSIMD_NOHUFFENC");
68 if ((env != NULL) && (strcmp(env, "1") == 0))
69 simd_huffman = 0;
Pierre Ossman59a39382009-03-09 13:15:56 +000070}
71
72GLOBAL(int)
73jsimd_can_rgb_ycc (void)
74{
75 init_simd();
76
Pierre Ossman5eb84ff2009-03-09 13:25:30 +000077 /* The code is optimised for these values only */
78 if (BITS_IN_JSAMPLE != 8)
79 return 0;
80 if (sizeof(JDIMENSION) != 4)
81 return 0;
82 if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
83 return 0;
84
Pierre Ossmaneea72152009-03-09 13:34:17 +000085 if ((simd_support & JSIMD_SSE2) &&
86 IS_ALIGNED_SSE(jconst_rgb_ycc_convert_sse2))
87 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +000088 if (simd_support & JSIMD_MMX)
89 return 1;
90
Pierre Ossman59a39382009-03-09 13:15:56 +000091 return 0;
92}
93
94GLOBAL(int)
DRCc8666332011-02-18 11:23:45 +000095jsimd_can_rgb_gray (void)
96{
97 init_simd();
98
99 /* The code is optimised for these values only */
100 if (BITS_IN_JSAMPLE != 8)
101 return 0;
102 if (sizeof(JDIMENSION) != 4)
103 return 0;
104 if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
105 return 0;
106
107 if ((simd_support & JSIMD_SSE2) &&
108 IS_ALIGNED_SSE(jconst_rgb_gray_convert_sse2))
109 return 1;
110 if (simd_support & JSIMD_MMX)
111 return 1;
112
113 return 0;
114}
115
116GLOBAL(int)
Pierre Ossman59a39382009-03-09 13:15:56 +0000117jsimd_can_ycc_rgb (void)
118{
119 init_simd();
120
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000121 /* The code is optimised for these values only */
122 if (BITS_IN_JSAMPLE != 8)
123 return 0;
124 if (sizeof(JDIMENSION) != 4)
125 return 0;
126 if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
127 return 0;
128
Pierre Ossmaneea72152009-03-09 13:34:17 +0000129 if ((simd_support & JSIMD_SSE2) &&
130 IS_ALIGNED_SSE(jconst_ycc_rgb_convert_sse2))
131 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000132 if (simd_support & JSIMD_MMX)
133 return 1;
134
Pierre Ossman59a39382009-03-09 13:15:56 +0000135 return 0;
136}
137
DRCd729f4d2014-08-23 15:47:51 +0000138GLOBAL(int)
139jsimd_can_ycc_rgb565 (void)
140{
141 return 0;
142}
143
Pierre Ossman59a39382009-03-09 13:15:56 +0000144GLOBAL(void)
145jsimd_rgb_ycc_convert (j_compress_ptr cinfo,
146 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
147 JDIMENSION output_row, int num_rows)
148{
DRCf25c0712009-04-03 12:00:51 +0000149 void (*sse2fct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
150 void (*mmxfct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
Pierre Ossmanba82ddf2009-06-29 11:20:42 +0000151
DRC14198522014-05-15 19:45:11 +0000152 switch(cinfo->in_color_space) {
DRCf25c0712009-04-03 12:00:51 +0000153 case JCS_EXT_RGB:
154 sse2fct=jsimd_extrgb_ycc_convert_sse2;
155 mmxfct=jsimd_extrgb_ycc_convert_mmx;
156 break;
157 case JCS_EXT_RGBX:
DRC67ce3b22011-12-19 02:21:03 +0000158 case JCS_EXT_RGBA:
DRCf25c0712009-04-03 12:00:51 +0000159 sse2fct=jsimd_extrgbx_ycc_convert_sse2;
160 mmxfct=jsimd_extrgbx_ycc_convert_mmx;
161 break;
162 case JCS_EXT_BGR:
163 sse2fct=jsimd_extbgr_ycc_convert_sse2;
164 mmxfct=jsimd_extbgr_ycc_convert_mmx;
165 break;
166 case JCS_EXT_BGRX:
DRC67ce3b22011-12-19 02:21:03 +0000167 case JCS_EXT_BGRA:
DRCf25c0712009-04-03 12:00:51 +0000168 sse2fct=jsimd_extbgrx_ycc_convert_sse2;
169 mmxfct=jsimd_extbgrx_ycc_convert_mmx;
170 break;
171 case JCS_EXT_XBGR:
DRC67ce3b22011-12-19 02:21:03 +0000172 case JCS_EXT_ABGR:
DRCf25c0712009-04-03 12:00:51 +0000173 sse2fct=jsimd_extxbgr_ycc_convert_sse2;
174 mmxfct=jsimd_extxbgr_ycc_convert_mmx;
175 break;
176 case JCS_EXT_XRGB:
DRC67ce3b22011-12-19 02:21:03 +0000177 case JCS_EXT_ARGB:
DRCf25c0712009-04-03 12:00:51 +0000178 sse2fct=jsimd_extxrgb_ycc_convert_sse2;
179 mmxfct=jsimd_extxrgb_ycc_convert_mmx;
180 break;
181 default:
182 sse2fct=jsimd_rgb_ycc_convert_sse2;
183 mmxfct=jsimd_rgb_ycc_convert_mmx;
184 break;
185 }
Pierre Ossmanba82ddf2009-06-29 11:20:42 +0000186
Pierre Ossmaneea72152009-03-09 13:34:17 +0000187 if ((simd_support & JSIMD_SSE2) &&
188 IS_ALIGNED_SSE(jconst_rgb_ycc_convert_sse2))
DRC14198522014-05-15 19:45:11 +0000189 sse2fct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
Pierre Ossmaneea72152009-03-09 13:34:17 +0000190 else if (simd_support & JSIMD_MMX)
DRC14198522014-05-15 19:45:11 +0000191 mmxfct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
Pierre Ossman59a39382009-03-09 13:15:56 +0000192}
193
194GLOBAL(void)
DRCc8666332011-02-18 11:23:45 +0000195jsimd_rgb_gray_convert (j_compress_ptr cinfo,
196 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
197 JDIMENSION output_row, int num_rows)
198{
199 void (*sse2fct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
200 void (*mmxfct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
201
DRC14198522014-05-15 19:45:11 +0000202 switch(cinfo->in_color_space) {
DRCc8666332011-02-18 11:23:45 +0000203 case JCS_EXT_RGB:
204 sse2fct=jsimd_extrgb_gray_convert_sse2;
205 mmxfct=jsimd_extrgb_gray_convert_mmx;
206 break;
207 case JCS_EXT_RGBX:
DRC67ce3b22011-12-19 02:21:03 +0000208 case JCS_EXT_RGBA:
DRCc8666332011-02-18 11:23:45 +0000209 sse2fct=jsimd_extrgbx_gray_convert_sse2;
210 mmxfct=jsimd_extrgbx_gray_convert_mmx;
211 break;
212 case JCS_EXT_BGR:
213 sse2fct=jsimd_extbgr_gray_convert_sse2;
214 mmxfct=jsimd_extbgr_gray_convert_mmx;
215 break;
216 case JCS_EXT_BGRX:
DRC67ce3b22011-12-19 02:21:03 +0000217 case JCS_EXT_BGRA:
DRCc8666332011-02-18 11:23:45 +0000218 sse2fct=jsimd_extbgrx_gray_convert_sse2;
219 mmxfct=jsimd_extbgrx_gray_convert_mmx;
220 break;
221 case JCS_EXT_XBGR:
DRC67ce3b22011-12-19 02:21:03 +0000222 case JCS_EXT_ABGR:
DRCc8666332011-02-18 11:23:45 +0000223 sse2fct=jsimd_extxbgr_gray_convert_sse2;
224 mmxfct=jsimd_extxbgr_gray_convert_mmx;
225 break;
226 case JCS_EXT_XRGB:
DRC67ce3b22011-12-19 02:21:03 +0000227 case JCS_EXT_ARGB:
DRCc8666332011-02-18 11:23:45 +0000228 sse2fct=jsimd_extxrgb_gray_convert_sse2;
229 mmxfct=jsimd_extxrgb_gray_convert_mmx;
230 break;
231 default:
232 sse2fct=jsimd_rgb_gray_convert_sse2;
233 mmxfct=jsimd_rgb_gray_convert_mmx;
234 break;
235 }
236
237 if ((simd_support & JSIMD_SSE2) &&
238 IS_ALIGNED_SSE(jconst_rgb_gray_convert_sse2))
DRC14198522014-05-15 19:45:11 +0000239 sse2fct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
DRCc8666332011-02-18 11:23:45 +0000240 else if (simd_support & JSIMD_MMX)
DRC14198522014-05-15 19:45:11 +0000241 mmxfct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
DRCc8666332011-02-18 11:23:45 +0000242}
243
244GLOBAL(void)
Pierre Ossman59a39382009-03-09 13:15:56 +0000245jsimd_ycc_rgb_convert (j_decompress_ptr cinfo,
246 JSAMPIMAGE input_buf, JDIMENSION input_row,
247 JSAMPARRAY output_buf, int num_rows)
248{
DRCf25c0712009-04-03 12:00:51 +0000249 void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
250 void (*mmxfct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
Pierre Ossmanba82ddf2009-06-29 11:20:42 +0000251
DRC14198522014-05-15 19:45:11 +0000252 switch(cinfo->out_color_space) {
DRCf25c0712009-04-03 12:00:51 +0000253 case JCS_EXT_RGB:
254 sse2fct=jsimd_ycc_extrgb_convert_sse2;
255 mmxfct=jsimd_ycc_extrgb_convert_mmx;
256 break;
257 case JCS_EXT_RGBX:
DRC67ce3b22011-12-19 02:21:03 +0000258 case JCS_EXT_RGBA:
DRCf25c0712009-04-03 12:00:51 +0000259 sse2fct=jsimd_ycc_extrgbx_convert_sse2;
260 mmxfct=jsimd_ycc_extrgbx_convert_mmx;
261 break;
262 case JCS_EXT_BGR:
263 sse2fct=jsimd_ycc_extbgr_convert_sse2;
264 mmxfct=jsimd_ycc_extbgr_convert_mmx;
265 break;
266 case JCS_EXT_BGRX:
DRC67ce3b22011-12-19 02:21:03 +0000267 case JCS_EXT_BGRA:
DRCf25c0712009-04-03 12:00:51 +0000268 sse2fct=jsimd_ycc_extbgrx_convert_sse2;
269 mmxfct=jsimd_ycc_extbgrx_convert_mmx;
270 break;
271 case JCS_EXT_XBGR:
DRC67ce3b22011-12-19 02:21:03 +0000272 case JCS_EXT_ABGR:
DRCf25c0712009-04-03 12:00:51 +0000273 sse2fct=jsimd_ycc_extxbgr_convert_sse2;
274 mmxfct=jsimd_ycc_extxbgr_convert_mmx;
275 break;
276 case JCS_EXT_XRGB:
DRC67ce3b22011-12-19 02:21:03 +0000277 case JCS_EXT_ARGB:
DRCf25c0712009-04-03 12:00:51 +0000278 sse2fct=jsimd_ycc_extxrgb_convert_sse2;
279 mmxfct=jsimd_ycc_extxrgb_convert_mmx;
280 break;
281 default:
282 sse2fct=jsimd_ycc_rgb_convert_sse2;
283 mmxfct=jsimd_ycc_rgb_convert_mmx;
284 break;
285 }
Pierre Ossmanba82ddf2009-06-29 11:20:42 +0000286
Pierre Ossmaneea72152009-03-09 13:34:17 +0000287 if ((simd_support & JSIMD_SSE2) &&
288 IS_ALIGNED_SSE(jconst_ycc_rgb_convert_sse2))
DRC14198522014-05-15 19:45:11 +0000289 sse2fct(cinfo->output_width, input_buf, input_row, output_buf, num_rows);
Pierre Ossmaneea72152009-03-09 13:34:17 +0000290 else if (simd_support & JSIMD_MMX)
DRC14198522014-05-15 19:45:11 +0000291 mmxfct(cinfo->output_width, input_buf, input_row, output_buf, num_rows);
Pierre Ossman59a39382009-03-09 13:15:56 +0000292}
293
DRCd729f4d2014-08-23 15:47:51 +0000294GLOBAL(void)
295jsimd_ycc_rgb565_convert (j_decompress_ptr cinfo,
296 JSAMPIMAGE input_buf, JDIMENSION input_row,
297 JSAMPARRAY output_buf, int num_rows)
298{
299}
300
Pierre Ossman59a39382009-03-09 13:15:56 +0000301GLOBAL(int)
302jsimd_can_h2v2_downsample (void)
303{
304 init_simd();
305
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000306 /* The code is optimised for these values only */
307 if (BITS_IN_JSAMPLE != 8)
308 return 0;
309 if (sizeof(JDIMENSION) != 4)
310 return 0;
311
Pierre Ossmaneea72152009-03-09 13:34:17 +0000312 if (simd_support & JSIMD_SSE2)
313 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000314 if (simd_support & JSIMD_MMX)
315 return 1;
316
Pierre Ossman59a39382009-03-09 13:15:56 +0000317 return 0;
318}
319
320GLOBAL(int)
321jsimd_can_h2v1_downsample (void)
322{
323 init_simd();
324
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000325 /* The code is optimised for these values only */
326 if (BITS_IN_JSAMPLE != 8)
327 return 0;
328 if (sizeof(JDIMENSION) != 4)
329 return 0;
330
Pierre Ossmaneea72152009-03-09 13:34:17 +0000331 if (simd_support & JSIMD_SSE2)
332 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000333 if (simd_support & JSIMD_MMX)
334 return 1;
335
Pierre Ossman59a39382009-03-09 13:15:56 +0000336 return 0;
337}
338
339GLOBAL(void)
Alex Naidis6eb7d372016-10-16 23:10:08 +0200340jsimd_h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
Pierre Ossman59a39382009-03-09 13:15:56 +0000341 JSAMPARRAY input_data, JSAMPARRAY output_data)
342{
Pierre Ossmaneea72152009-03-09 13:34:17 +0000343 if (simd_support & JSIMD_SSE2)
344 jsimd_h2v2_downsample_sse2(cinfo->image_width, cinfo->max_v_samp_factor,
DRC14198522014-05-15 19:45:11 +0000345 compptr->v_samp_factor,
346 compptr->width_in_blocks, input_data,
347 output_data);
Pierre Ossmaneea72152009-03-09 13:34:17 +0000348 else if (simd_support & JSIMD_MMX)
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000349 jsimd_h2v2_downsample_mmx(cinfo->image_width, cinfo->max_v_samp_factor,
DRC14198522014-05-15 19:45:11 +0000350 compptr->v_samp_factor, compptr->width_in_blocks,
351 input_data, output_data);
Pierre Ossman59a39382009-03-09 13:15:56 +0000352}
353
354GLOBAL(void)
Alex Naidis6eb7d372016-10-16 23:10:08 +0200355jsimd_h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
Pierre Ossman59a39382009-03-09 13:15:56 +0000356 JSAMPARRAY input_data, JSAMPARRAY output_data)
357{
Pierre Ossmaneea72152009-03-09 13:34:17 +0000358 if (simd_support & JSIMD_SSE2)
359 jsimd_h2v1_downsample_sse2(cinfo->image_width, cinfo->max_v_samp_factor,
DRC14198522014-05-15 19:45:11 +0000360 compptr->v_samp_factor,
361 compptr->width_in_blocks, input_data,
362 output_data);
Pierre Ossmaneea72152009-03-09 13:34:17 +0000363 else if (simd_support & JSIMD_MMX)
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000364 jsimd_h2v1_downsample_mmx(cinfo->image_width, cinfo->max_v_samp_factor,
DRC14198522014-05-15 19:45:11 +0000365 compptr->v_samp_factor, compptr->width_in_blocks,
366 input_data, output_data);
Pierre Ossman59a39382009-03-09 13:15:56 +0000367}
368
369GLOBAL(int)
370jsimd_can_h2v2_upsample (void)
371{
372 init_simd();
373
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000374 /* The code is optimised for these values only */
375 if (BITS_IN_JSAMPLE != 8)
376 return 0;
377 if (sizeof(JDIMENSION) != 4)
378 return 0;
379
Pierre Ossmaneea72152009-03-09 13:34:17 +0000380 if (simd_support & JSIMD_SSE2)
381 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000382 if (simd_support & JSIMD_MMX)
383 return 1;
384
Pierre Ossman59a39382009-03-09 13:15:56 +0000385 return 0;
386}
387
388GLOBAL(int)
389jsimd_can_h2v1_upsample (void)
390{
391 init_simd();
392
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000393 /* The code is optimised for these values only */
394 if (BITS_IN_JSAMPLE != 8)
395 return 0;
396 if (sizeof(JDIMENSION) != 4)
397 return 0;
398
Pierre Ossmaneea72152009-03-09 13:34:17 +0000399 if (simd_support & JSIMD_SSE2)
400 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000401 if (simd_support & JSIMD_MMX)
402 return 1;
403
Pierre Ossman59a39382009-03-09 13:15:56 +0000404 return 0;
405}
406
407GLOBAL(void)
408jsimd_h2v2_upsample (j_decompress_ptr cinfo,
Alex Naidis6eb7d372016-10-16 23:10:08 +0200409 jpeg_component_info *compptr,
Pierre Ossman59a39382009-03-09 13:15:56 +0000410 JSAMPARRAY input_data,
Alex Naidis6eb7d372016-10-16 23:10:08 +0200411 JSAMPARRAY *output_data_ptr)
Pierre Ossman59a39382009-03-09 13:15:56 +0000412{
Pierre Ossmaneea72152009-03-09 13:34:17 +0000413 if (simd_support & JSIMD_SSE2)
DRC14198522014-05-15 19:45:11 +0000414 jsimd_h2v2_upsample_sse2(cinfo->max_v_samp_factor, cinfo->output_width,
415 input_data, output_data_ptr);
Pierre Ossmaneea72152009-03-09 13:34:17 +0000416 else if (simd_support & JSIMD_MMX)
DRC14198522014-05-15 19:45:11 +0000417 jsimd_h2v2_upsample_mmx(cinfo->max_v_samp_factor, cinfo->output_width,
418 input_data, output_data_ptr);
Pierre Ossman59a39382009-03-09 13:15:56 +0000419}
420
421GLOBAL(void)
422jsimd_h2v1_upsample (j_decompress_ptr cinfo,
Alex Naidis6eb7d372016-10-16 23:10:08 +0200423 jpeg_component_info *compptr,
Pierre Ossman59a39382009-03-09 13:15:56 +0000424 JSAMPARRAY input_data,
Alex Naidis6eb7d372016-10-16 23:10:08 +0200425 JSAMPARRAY *output_data_ptr)
Pierre Ossman59a39382009-03-09 13:15:56 +0000426{
Pierre Ossmaneea72152009-03-09 13:34:17 +0000427 if (simd_support & JSIMD_SSE2)
DRC14198522014-05-15 19:45:11 +0000428 jsimd_h2v1_upsample_sse2(cinfo->max_v_samp_factor, cinfo->output_width,
429 input_data, output_data_ptr);
Pierre Ossmaneea72152009-03-09 13:34:17 +0000430 else if (simd_support & JSIMD_MMX)
DRC14198522014-05-15 19:45:11 +0000431 jsimd_h2v1_upsample_mmx(cinfo->max_v_samp_factor, cinfo->output_width,
432 input_data, output_data_ptr);
Pierre Ossman59a39382009-03-09 13:15:56 +0000433}
434
435GLOBAL(int)
436jsimd_can_h2v2_fancy_upsample (void)
437{
438 init_simd();
439
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000440 /* The code is optimised for these values only */
441 if (BITS_IN_JSAMPLE != 8)
442 return 0;
443 if (sizeof(JDIMENSION) != 4)
444 return 0;
445
Pierre Ossmaneea72152009-03-09 13:34:17 +0000446 if ((simd_support & JSIMD_SSE2) &&
447 IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
448 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000449 if (simd_support & JSIMD_MMX)
450 return 1;
451
Pierre Ossman59a39382009-03-09 13:15:56 +0000452 return 0;
453}
454
455GLOBAL(int)
456jsimd_can_h2v1_fancy_upsample (void)
457{
458 init_simd();
459
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000460 /* The code is optimised for these values only */
461 if (BITS_IN_JSAMPLE != 8)
462 return 0;
463 if (sizeof(JDIMENSION) != 4)
464 return 0;
465
Pierre Ossmaneea72152009-03-09 13:34:17 +0000466 if ((simd_support & JSIMD_SSE2) &&
467 IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
468 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000469 if (simd_support & JSIMD_MMX)
470 return 1;
471
Pierre Ossman59a39382009-03-09 13:15:56 +0000472 return 0;
473}
474
475GLOBAL(void)
476jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo,
Alex Naidis6eb7d372016-10-16 23:10:08 +0200477 jpeg_component_info *compptr,
Pierre Ossman59a39382009-03-09 13:15:56 +0000478 JSAMPARRAY input_data,
Alex Naidis6eb7d372016-10-16 23:10:08 +0200479 JSAMPARRAY *output_data_ptr)
Pierre Ossman59a39382009-03-09 13:15:56 +0000480{
Pierre Ossmaneea72152009-03-09 13:34:17 +0000481 if ((simd_support & JSIMD_SSE2) &&
482 IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
DRC30959712010-08-07 16:06:56 +0000483 jsimd_h2v2_fancy_upsample_sse2(cinfo->max_v_samp_factor,
DRC14198522014-05-15 19:45:11 +0000484 compptr->downsampled_width, input_data,
485 output_data_ptr);
Pierre Ossmaneea72152009-03-09 13:34:17 +0000486 else if (simd_support & JSIMD_MMX)
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000487 jsimd_h2v2_fancy_upsample_mmx(cinfo->max_v_samp_factor,
DRC14198522014-05-15 19:45:11 +0000488 compptr->downsampled_width, input_data,
489 output_data_ptr);
Pierre Ossman59a39382009-03-09 13:15:56 +0000490}
491
492GLOBAL(void)
493jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo,
Alex Naidis6eb7d372016-10-16 23:10:08 +0200494 jpeg_component_info *compptr,
Pierre Ossman59a39382009-03-09 13:15:56 +0000495 JSAMPARRAY input_data,
Alex Naidis6eb7d372016-10-16 23:10:08 +0200496 JSAMPARRAY *output_data_ptr)
Pierre Ossman59a39382009-03-09 13:15:56 +0000497{
Pierre Ossmaneea72152009-03-09 13:34:17 +0000498 if ((simd_support & JSIMD_SSE2) &&
499 IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
500 jsimd_h2v1_fancy_upsample_sse2(cinfo->max_v_samp_factor,
DRC14198522014-05-15 19:45:11 +0000501 compptr->downsampled_width, input_data,
502 output_data_ptr);
Pierre Ossmaneea72152009-03-09 13:34:17 +0000503 else if (simd_support & JSIMD_MMX)
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000504 jsimd_h2v1_fancy_upsample_mmx(cinfo->max_v_samp_factor,
DRC14198522014-05-15 19:45:11 +0000505 compptr->downsampled_width, input_data,
506 output_data_ptr);
Pierre Ossman59a39382009-03-09 13:15:56 +0000507}
508
509GLOBAL(int)
510jsimd_can_h2v2_merged_upsample (void)
511{
512 init_simd();
513
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000514 /* The code is optimised for these values only */
515 if (BITS_IN_JSAMPLE != 8)
516 return 0;
517 if (sizeof(JDIMENSION) != 4)
518 return 0;
519
Pierre Ossmaneea72152009-03-09 13:34:17 +0000520 if ((simd_support & JSIMD_SSE2) &&
521 IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
522 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000523 if (simd_support & JSIMD_MMX)
524 return 1;
525
Pierre Ossman59a39382009-03-09 13:15:56 +0000526 return 0;
527}
528
529GLOBAL(int)
530jsimd_can_h2v1_merged_upsample (void)
531{
532 init_simd();
533
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000534 /* The code is optimised for these values only */
535 if (BITS_IN_JSAMPLE != 8)
536 return 0;
537 if (sizeof(JDIMENSION) != 4)
538 return 0;
539
Pierre Ossmaneea72152009-03-09 13:34:17 +0000540 if ((simd_support & JSIMD_SSE2) &&
541 IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
542 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000543 if (simd_support & JSIMD_MMX)
544 return 1;
545
Pierre Ossman59a39382009-03-09 13:15:56 +0000546 return 0;
547}
548
549GLOBAL(void)
550jsimd_h2v2_merged_upsample (j_decompress_ptr cinfo,
551 JSAMPIMAGE input_buf,
552 JDIMENSION in_row_group_ctr,
553 JSAMPARRAY output_buf)
554{
DRC720e1612009-04-05 21:51:25 +0000555 void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
556 void (*mmxfct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
Pierre Ossmanba82ddf2009-06-29 11:20:42 +0000557
DRC14198522014-05-15 19:45:11 +0000558 switch(cinfo->out_color_space) {
DRC720e1612009-04-05 21:51:25 +0000559 case JCS_EXT_RGB:
560 sse2fct=jsimd_h2v2_extrgb_merged_upsample_sse2;
561 mmxfct=jsimd_h2v2_extrgb_merged_upsample_mmx;
562 break;
563 case JCS_EXT_RGBX:
DRC67ce3b22011-12-19 02:21:03 +0000564 case JCS_EXT_RGBA:
DRC720e1612009-04-05 21:51:25 +0000565 sse2fct=jsimd_h2v2_extrgbx_merged_upsample_sse2;
566 mmxfct=jsimd_h2v2_extrgbx_merged_upsample_mmx;
567 break;
568 case JCS_EXT_BGR:
569 sse2fct=jsimd_h2v2_extbgr_merged_upsample_sse2;
570 mmxfct=jsimd_h2v2_extbgr_merged_upsample_mmx;
571 break;
572 case JCS_EXT_BGRX:
DRC67ce3b22011-12-19 02:21:03 +0000573 case JCS_EXT_BGRA:
DRC720e1612009-04-05 21:51:25 +0000574 sse2fct=jsimd_h2v2_extbgrx_merged_upsample_sse2;
575 mmxfct=jsimd_h2v2_extbgrx_merged_upsample_mmx;
576 break;
577 case JCS_EXT_XBGR:
DRC67ce3b22011-12-19 02:21:03 +0000578 case JCS_EXT_ABGR:
DRC720e1612009-04-05 21:51:25 +0000579 sse2fct=jsimd_h2v2_extxbgr_merged_upsample_sse2;
580 mmxfct=jsimd_h2v2_extxbgr_merged_upsample_mmx;
581 break;
582 case JCS_EXT_XRGB:
DRC67ce3b22011-12-19 02:21:03 +0000583 case JCS_EXT_ARGB:
DRC720e1612009-04-05 21:51:25 +0000584 sse2fct=jsimd_h2v2_extxrgb_merged_upsample_sse2;
585 mmxfct=jsimd_h2v2_extxrgb_merged_upsample_mmx;
586 break;
587 default:
588 sse2fct=jsimd_h2v2_merged_upsample_sse2;
589 mmxfct=jsimd_h2v2_merged_upsample_mmx;
590 break;
591 }
Pierre Ossmanba82ddf2009-06-29 11:20:42 +0000592
Pierre Ossmaneea72152009-03-09 13:34:17 +0000593 if ((simd_support & JSIMD_SSE2) &&
594 IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
DRC14198522014-05-15 19:45:11 +0000595 sse2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
Pierre Ossmaneea72152009-03-09 13:34:17 +0000596 else if (simd_support & JSIMD_MMX)
DRC14198522014-05-15 19:45:11 +0000597 mmxfct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
Pierre Ossman59a39382009-03-09 13:15:56 +0000598}
599
600GLOBAL(void)
601jsimd_h2v1_merged_upsample (j_decompress_ptr cinfo,
602 JSAMPIMAGE input_buf,
603 JDIMENSION in_row_group_ctr,
604 JSAMPARRAY output_buf)
605{
DRC720e1612009-04-05 21:51:25 +0000606 void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
607 void (*mmxfct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
Pierre Ossmanba82ddf2009-06-29 11:20:42 +0000608
DRC14198522014-05-15 19:45:11 +0000609 switch(cinfo->out_color_space) {
DRC720e1612009-04-05 21:51:25 +0000610 case JCS_EXT_RGB:
611 sse2fct=jsimd_h2v1_extrgb_merged_upsample_sse2;
612 mmxfct=jsimd_h2v1_extrgb_merged_upsample_mmx;
613 break;
614 case JCS_EXT_RGBX:
DRC67ce3b22011-12-19 02:21:03 +0000615 case JCS_EXT_RGBA:
DRC720e1612009-04-05 21:51:25 +0000616 sse2fct=jsimd_h2v1_extrgbx_merged_upsample_sse2;
617 mmxfct=jsimd_h2v1_extrgbx_merged_upsample_mmx;
618 break;
619 case JCS_EXT_BGR:
620 sse2fct=jsimd_h2v1_extbgr_merged_upsample_sse2;
621 mmxfct=jsimd_h2v1_extbgr_merged_upsample_mmx;
622 break;
623 case JCS_EXT_BGRX:
DRC67ce3b22011-12-19 02:21:03 +0000624 case JCS_EXT_BGRA:
DRC720e1612009-04-05 21:51:25 +0000625 sse2fct=jsimd_h2v1_extbgrx_merged_upsample_sse2;
626 mmxfct=jsimd_h2v1_extbgrx_merged_upsample_mmx;
627 break;
628 case JCS_EXT_XBGR:
DRC67ce3b22011-12-19 02:21:03 +0000629 case JCS_EXT_ABGR:
DRC720e1612009-04-05 21:51:25 +0000630 sse2fct=jsimd_h2v1_extxbgr_merged_upsample_sse2;
631 mmxfct=jsimd_h2v1_extxbgr_merged_upsample_mmx;
632 break;
633 case JCS_EXT_XRGB:
DRC67ce3b22011-12-19 02:21:03 +0000634 case JCS_EXT_ARGB:
DRC720e1612009-04-05 21:51:25 +0000635 sse2fct=jsimd_h2v1_extxrgb_merged_upsample_sse2;
636 mmxfct=jsimd_h2v1_extxrgb_merged_upsample_mmx;
637 break;
638 default:
639 sse2fct=jsimd_h2v1_merged_upsample_sse2;
640 mmxfct=jsimd_h2v1_merged_upsample_mmx;
641 break;
642 }
Pierre Ossmanba82ddf2009-06-29 11:20:42 +0000643
Pierre Ossmaneea72152009-03-09 13:34:17 +0000644 if ((simd_support & JSIMD_SSE2) &&
645 IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
DRC14198522014-05-15 19:45:11 +0000646 sse2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
Pierre Ossmaneea72152009-03-09 13:34:17 +0000647 else if (simd_support & JSIMD_MMX)
DRC14198522014-05-15 19:45:11 +0000648 mmxfct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
Pierre Ossman59a39382009-03-09 13:15:56 +0000649}
650
651GLOBAL(int)
652jsimd_can_convsamp (void)
653{
654 init_simd();
655
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000656 /* The code is optimised for these values only */
657 if (DCTSIZE != 8)
658 return 0;
659 if (BITS_IN_JSAMPLE != 8)
660 return 0;
661 if (sizeof(JDIMENSION) != 4)
662 return 0;
663 if (sizeof(DCTELEM) != 2)
664 return 0;
665
Pierre Ossmaneea72152009-03-09 13:34:17 +0000666 if (simd_support & JSIMD_SSE2)
667 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000668 if (simd_support & JSIMD_MMX)
669 return 1;
670
Pierre Ossman59a39382009-03-09 13:15:56 +0000671 return 0;
672}
673
674GLOBAL(int)
675jsimd_can_convsamp_float (void)
676{
677 init_simd();
678
Pierre Ossman65d03172009-03-09 13:28:10 +0000679 /* The code is optimised for these values only */
680 if (DCTSIZE != 8)
681 return 0;
682 if (BITS_IN_JSAMPLE != 8)
683 return 0;
684 if (sizeof(JDIMENSION) != 4)
685 return 0;
686 if (sizeof(FAST_FLOAT) != 4)
687 return 0;
688
Pierre Ossmaneea72152009-03-09 13:34:17 +0000689 if (simd_support & JSIMD_SSE2)
690 return 1;
Pierre Ossman018fc422009-03-09 13:31:56 +0000691 if (simd_support & JSIMD_SSE)
692 return 1;
Pierre Ossman65d03172009-03-09 13:28:10 +0000693 if (simd_support & JSIMD_3DNOW)
694 return 1;
695
Pierre Ossman59a39382009-03-09 13:15:56 +0000696 return 0;
697}
698
699GLOBAL(void)
700jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col,
Alex Naidis6eb7d372016-10-16 23:10:08 +0200701 DCTELEM *workspace)
Pierre Ossman59a39382009-03-09 13:15:56 +0000702{
Pierre Ossmaneea72152009-03-09 13:34:17 +0000703 if (simd_support & JSIMD_SSE2)
704 jsimd_convsamp_sse2(sample_data, start_col, workspace);
705 else if (simd_support & JSIMD_MMX)
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000706 jsimd_convsamp_mmx(sample_data, start_col, workspace);
Pierre Ossman59a39382009-03-09 13:15:56 +0000707}
708
709GLOBAL(void)
710jsimd_convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col,
Alex Naidis6eb7d372016-10-16 23:10:08 +0200711 FAST_FLOAT *workspace)
Pierre Ossman59a39382009-03-09 13:15:56 +0000712{
Pierre Ossmaneea72152009-03-09 13:34:17 +0000713 if (simd_support & JSIMD_SSE2)
714 jsimd_convsamp_float_sse2(sample_data, start_col, workspace);
715 else if (simd_support & JSIMD_SSE)
Pierre Ossman018fc422009-03-09 13:31:56 +0000716 jsimd_convsamp_float_sse(sample_data, start_col, workspace);
717 else if (simd_support & JSIMD_3DNOW)
Pierre Ossman65d03172009-03-09 13:28:10 +0000718 jsimd_convsamp_float_3dnow(sample_data, start_col, workspace);
Pierre Ossman59a39382009-03-09 13:15:56 +0000719}
720
721GLOBAL(int)
722jsimd_can_fdct_islow (void)
723{
724 init_simd();
725
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000726 /* The code is optimised for these values only */
727 if (DCTSIZE != 8)
728 return 0;
729 if (sizeof(DCTELEM) != 2)
730 return 0;
731
Pierre Ossmaneea72152009-03-09 13:34:17 +0000732 if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_islow_sse2))
733 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000734 if (simd_support & JSIMD_MMX)
735 return 1;
736
Pierre Ossman59a39382009-03-09 13:15:56 +0000737 return 0;
738}
739
740GLOBAL(int)
741jsimd_can_fdct_ifast (void)
742{
743 init_simd();
744
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000745 /* The code is optimised for these values only */
746 if (DCTSIZE != 8)
747 return 0;
748 if (sizeof(DCTELEM) != 2)
749 return 0;
750
Pierre Ossmaneea72152009-03-09 13:34:17 +0000751 if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_ifast_sse2))
752 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000753 if (simd_support & JSIMD_MMX)
754 return 1;
755
Pierre Ossman59a39382009-03-09 13:15:56 +0000756 return 0;
757}
758
759GLOBAL(int)
760jsimd_can_fdct_float (void)
761{
762 init_simd();
763
Pierre Ossman65d03172009-03-09 13:28:10 +0000764 /* The code is optimised for these values only */
765 if (DCTSIZE != 8)
766 return 0;
767 if (sizeof(FAST_FLOAT) != 4)
768 return 0;
769
Pierre Ossman018fc422009-03-09 13:31:56 +0000770 if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_fdct_float_sse))
771 return 1;
Pierre Ossman65d03172009-03-09 13:28:10 +0000772 if (simd_support & JSIMD_3DNOW)
773 return 1;
774
Pierre Ossman59a39382009-03-09 13:15:56 +0000775 return 0;
776}
777
778GLOBAL(void)
Alex Naidis6eb7d372016-10-16 23:10:08 +0200779jsimd_fdct_islow (DCTELEM *data)
Pierre Ossman59a39382009-03-09 13:15:56 +0000780{
Pierre Ossmaneea72152009-03-09 13:34:17 +0000781 if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_islow_sse2))
782 jsimd_fdct_islow_sse2(data);
783 else if (simd_support & JSIMD_MMX)
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000784 jsimd_fdct_islow_mmx(data);
Pierre Ossman59a39382009-03-09 13:15:56 +0000785}
786
787GLOBAL(void)
Alex Naidis6eb7d372016-10-16 23:10:08 +0200788jsimd_fdct_ifast (DCTELEM *data)
Pierre Ossman59a39382009-03-09 13:15:56 +0000789{
Pierre Ossmaneea72152009-03-09 13:34:17 +0000790 if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_islow_sse2))
791 jsimd_fdct_ifast_sse2(data);
792 else if (simd_support & JSIMD_MMX)
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000793 jsimd_fdct_ifast_mmx(data);
Pierre Ossman59a39382009-03-09 13:15:56 +0000794}
795
796GLOBAL(void)
Alex Naidis6eb7d372016-10-16 23:10:08 +0200797jsimd_fdct_float (FAST_FLOAT *data)
Pierre Ossman59a39382009-03-09 13:15:56 +0000798{
Pierre Ossman018fc422009-03-09 13:31:56 +0000799 if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_fdct_float_sse))
800 jsimd_fdct_float_sse(data);
801 else if (simd_support & JSIMD_3DNOW)
Pierre Ossman65d03172009-03-09 13:28:10 +0000802 jsimd_fdct_float_3dnow(data);
Pierre Ossman59a39382009-03-09 13:15:56 +0000803}
804
805GLOBAL(int)
806jsimd_can_quantize (void)
807{
808 init_simd();
809
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000810 /* The code is optimised for these values only */
811 if (DCTSIZE != 8)
812 return 0;
813 if (sizeof(JCOEF) != 2)
814 return 0;
815 if (sizeof(DCTELEM) != 2)
816 return 0;
817
Pierre Ossmaneea72152009-03-09 13:34:17 +0000818 if (simd_support & JSIMD_SSE2)
819 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000820 if (simd_support & JSIMD_MMX)
821 return 1;
822
Pierre Ossman59a39382009-03-09 13:15:56 +0000823 return 0;
824}
825
826GLOBAL(int)
827jsimd_can_quantize_float (void)
828{
829 init_simd();
830
Pierre Ossman65d03172009-03-09 13:28:10 +0000831 /* The code is optimised for these values only */
832 if (DCTSIZE != 8)
833 return 0;
834 if (sizeof(JCOEF) != 2)
835 return 0;
836 if (sizeof(FAST_FLOAT) != 4)
837 return 0;
838
Pierre Ossmaneea72152009-03-09 13:34:17 +0000839 if (simd_support & JSIMD_SSE2)
840 return 1;
Pierre Ossman018fc422009-03-09 13:31:56 +0000841 if (simd_support & JSIMD_SSE)
842 return 1;
Pierre Ossman65d03172009-03-09 13:28:10 +0000843 if (simd_support & JSIMD_3DNOW)
844 return 1;
845
Pierre Ossman59a39382009-03-09 13:15:56 +0000846 return 0;
847}
848
849GLOBAL(void)
Alex Naidis6eb7d372016-10-16 23:10:08 +0200850jsimd_quantize (JCOEFPTR coef_block, DCTELEM *divisors,
851 DCTELEM *workspace)
Pierre Ossman59a39382009-03-09 13:15:56 +0000852{
Pierre Ossmaneea72152009-03-09 13:34:17 +0000853 if (simd_support & JSIMD_SSE2)
854 jsimd_quantize_sse2(coef_block, divisors, workspace);
855 else if (simd_support & JSIMD_MMX)
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000856 jsimd_quantize_mmx(coef_block, divisors, workspace);
Pierre Ossman59a39382009-03-09 13:15:56 +0000857}
858
859GLOBAL(void)
Alex Naidis6eb7d372016-10-16 23:10:08 +0200860jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT *divisors,
861 FAST_FLOAT *workspace)
Pierre Ossman59a39382009-03-09 13:15:56 +0000862{
Pierre Ossmaneea72152009-03-09 13:34:17 +0000863 if (simd_support & JSIMD_SSE2)
864 jsimd_quantize_float_sse2(coef_block, divisors, workspace);
865 else if (simd_support & JSIMD_SSE)
Pierre Ossman018fc422009-03-09 13:31:56 +0000866 jsimd_quantize_float_sse(coef_block, divisors, workspace);
867 else if (simd_support & JSIMD_3DNOW)
Pierre Ossman65d03172009-03-09 13:28:10 +0000868 jsimd_quantize_float_3dnow(coef_block, divisors, workspace);
Pierre Ossman59a39382009-03-09 13:15:56 +0000869}
870
871GLOBAL(int)
872jsimd_can_idct_2x2 (void)
873{
874 init_simd();
875
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000876 /* The code is optimised for these values only */
877 if (DCTSIZE != 8)
878 return 0;
879 if (sizeof(JCOEF) != 2)
880 return 0;
881 if (BITS_IN_JSAMPLE != 8)
882 return 0;
883 if (sizeof(JDIMENSION) != 4)
884 return 0;
885 if (sizeof(ISLOW_MULT_TYPE) != 2)
886 return 0;
887
Pierre Ossmaneea72152009-03-09 13:34:17 +0000888 if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2))
889 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000890 if (simd_support & JSIMD_MMX)
891 return 1;
892
Pierre Ossman59a39382009-03-09 13:15:56 +0000893 return 0;
894}
895
896GLOBAL(int)
897jsimd_can_idct_4x4 (void)
898{
899 init_simd();
900
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000901 /* The code is optimised for these values only */
902 if (DCTSIZE != 8)
903 return 0;
904 if (sizeof(JCOEF) != 2)
905 return 0;
906 if (BITS_IN_JSAMPLE != 8)
907 return 0;
908 if (sizeof(JDIMENSION) != 4)
909 return 0;
910 if (sizeof(ISLOW_MULT_TYPE) != 2)
911 return 0;
912
Pierre Ossmaneea72152009-03-09 13:34:17 +0000913 if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2))
914 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000915 if (simd_support & JSIMD_MMX)
916 return 1;
917
Pierre Ossman59a39382009-03-09 13:15:56 +0000918 return 0;
919}
920
921GLOBAL(void)
Alex Naidis6eb7d372016-10-16 23:10:08 +0200922jsimd_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info *compptr,
Pierre Ossman59a39382009-03-09 13:15:56 +0000923 JCOEFPTR coef_block, JSAMPARRAY output_buf,
924 JDIMENSION output_col)
925{
Pierre Ossmaneea72152009-03-09 13:34:17 +0000926 if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2))
DRC14198522014-05-15 19:45:11 +0000927 jsimd_idct_2x2_sse2(compptr->dct_table, coef_block, output_buf,
928 output_col);
Pierre Ossmaneea72152009-03-09 13:34:17 +0000929 else if (simd_support & JSIMD_MMX)
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000930 jsimd_idct_2x2_mmx(compptr->dct_table, coef_block, output_buf, output_col);
Pierre Ossman59a39382009-03-09 13:15:56 +0000931}
932
933GLOBAL(void)
Alex Naidis6eb7d372016-10-16 23:10:08 +0200934jsimd_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info *compptr,
Pierre Ossman59a39382009-03-09 13:15:56 +0000935 JCOEFPTR coef_block, JSAMPARRAY output_buf,
936 JDIMENSION output_col)
937{
Pierre Ossmaneea72152009-03-09 13:34:17 +0000938 if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2))
DRC14198522014-05-15 19:45:11 +0000939 jsimd_idct_4x4_sse2(compptr->dct_table, coef_block, output_buf,
940 output_col);
Pierre Ossmaneea72152009-03-09 13:34:17 +0000941 else if (simd_support & JSIMD_MMX)
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000942 jsimd_idct_4x4_mmx(compptr->dct_table, coef_block, output_buf, output_col);
Pierre Ossman59a39382009-03-09 13:15:56 +0000943}
944
945GLOBAL(int)
946jsimd_can_idct_islow (void)
947{
948 init_simd();
949
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000950 /* The code is optimised for these values only */
951 if (DCTSIZE != 8)
952 return 0;
953 if (sizeof(JCOEF) != 2)
954 return 0;
955 if (BITS_IN_JSAMPLE != 8)
956 return 0;
957 if (sizeof(JDIMENSION) != 4)
958 return 0;
959 if (sizeof(ISLOW_MULT_TYPE) != 2)
960 return 0;
961
Pierre Ossmaneea72152009-03-09 13:34:17 +0000962 if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_islow_sse2))
963 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000964 if (simd_support & JSIMD_MMX)
965 return 1;
966
Pierre Ossman59a39382009-03-09 13:15:56 +0000967 return 0;
968}
969
970GLOBAL(int)
971jsimd_can_idct_ifast (void)
972{
973 init_simd();
974
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000975 /* The code is optimised for these values only */
976 if (DCTSIZE != 8)
977 return 0;
978 if (sizeof(JCOEF) != 2)
979 return 0;
980 if (BITS_IN_JSAMPLE != 8)
981 return 0;
982 if (sizeof(JDIMENSION) != 4)
983 return 0;
984 if (sizeof(IFAST_MULT_TYPE) != 2)
985 return 0;
986 if (IFAST_SCALE_BITS != 2)
987 return 0;
988
Pierre Ossmaneea72152009-03-09 13:34:17 +0000989 if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_ifast_sse2))
990 return 1;
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000991 if (simd_support & JSIMD_MMX)
992 return 1;
993
Pierre Ossman59a39382009-03-09 13:15:56 +0000994 return 0;
995}
996
997GLOBAL(int)
998jsimd_can_idct_float (void)
999{
1000 init_simd();
1001
Pierre Ossman65d03172009-03-09 13:28:10 +00001002 if (DCTSIZE != 8)
1003 return 0;
1004 if (sizeof(JCOEF) != 2)
1005 return 0;
1006 if (BITS_IN_JSAMPLE != 8)
1007 return 0;
1008 if (sizeof(JDIMENSION) != 4)
1009 return 0;
1010 if (sizeof(FAST_FLOAT) != 4)
1011 return 0;
1012 if (sizeof(FLOAT_MULT_TYPE) != 4)
1013 return 0;
1014
Pierre Ossmaneea72152009-03-09 13:34:17 +00001015 if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_float_sse2))
1016 return 1;
Pierre Ossman018fc422009-03-09 13:31:56 +00001017 if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_idct_float_sse))
1018 return 1;
Pierre Ossman65d03172009-03-09 13:28:10 +00001019 if (simd_support & JSIMD_3DNOW)
1020 return 1;
1021
Pierre Ossman59a39382009-03-09 13:15:56 +00001022 return 0;
1023}
1024
1025GLOBAL(void)
Alex Naidis6eb7d372016-10-16 23:10:08 +02001026jsimd_idct_islow (j_decompress_ptr cinfo, jpeg_component_info *compptr,
DRC14198522014-05-15 19:45:11 +00001027 JCOEFPTR coef_block, JSAMPARRAY output_buf,
1028 JDIMENSION output_col)
Pierre Ossman59a39382009-03-09 13:15:56 +00001029{
Pierre Ossmaneea72152009-03-09 13:34:17 +00001030 if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_islow_sse2))
DRC14198522014-05-15 19:45:11 +00001031 jsimd_idct_islow_sse2(compptr->dct_table, coef_block, output_buf,
1032 output_col);
Pierre Ossmaneea72152009-03-09 13:34:17 +00001033 else if (simd_support & JSIMD_MMX)
DRC14198522014-05-15 19:45:11 +00001034 jsimd_idct_islow_mmx(compptr->dct_table, coef_block, output_buf,
1035 output_col);
Pierre Ossman59a39382009-03-09 13:15:56 +00001036}
1037
1038GLOBAL(void)
Alex Naidis6eb7d372016-10-16 23:10:08 +02001039jsimd_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info *compptr,
DRC14198522014-05-15 19:45:11 +00001040 JCOEFPTR coef_block, JSAMPARRAY output_buf,
1041 JDIMENSION output_col)
Pierre Ossman59a39382009-03-09 13:15:56 +00001042{
Pierre Ossmaneea72152009-03-09 13:34:17 +00001043 if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_ifast_sse2))
DRC14198522014-05-15 19:45:11 +00001044 jsimd_idct_ifast_sse2(compptr->dct_table, coef_block, output_buf,
1045 output_col);
Pierre Ossmaneea72152009-03-09 13:34:17 +00001046 else if (simd_support & JSIMD_MMX)
DRC14198522014-05-15 19:45:11 +00001047 jsimd_idct_ifast_mmx(compptr->dct_table, coef_block, output_buf,
1048 output_col);
Pierre Ossman59a39382009-03-09 13:15:56 +00001049}
1050
1051GLOBAL(void)
Alex Naidis6eb7d372016-10-16 23:10:08 +02001052jsimd_idct_float (j_decompress_ptr cinfo, jpeg_component_info *compptr,
DRC14198522014-05-15 19:45:11 +00001053 JCOEFPTR coef_block, JSAMPARRAY output_buf,
1054 JDIMENSION output_col)
Pierre Ossman59a39382009-03-09 13:15:56 +00001055{
Pierre Ossmaneea72152009-03-09 13:34:17 +00001056 if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_float_sse2))
DRC14198522014-05-15 19:45:11 +00001057 jsimd_idct_float_sse2(compptr->dct_table, coef_block, output_buf,
1058 output_col);
Pierre Ossmaneea72152009-03-09 13:34:17 +00001059 else if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_idct_float_sse))
DRC14198522014-05-15 19:45:11 +00001060 jsimd_idct_float_sse(compptr->dct_table, coef_block, output_buf,
1061 output_col);
Pierre Ossman018fc422009-03-09 13:31:56 +00001062 else if (simd_support & JSIMD_3DNOW)
DRC14198522014-05-15 19:45:11 +00001063 jsimd_idct_float_3dnow(compptr->dct_table, coef_block, output_buf,
1064 output_col);
Pierre Ossman59a39382009-03-09 13:15:56 +00001065}
1066
Alex Naidis6eb7d372016-10-16 23:10:08 +02001067GLOBAL(int)
1068jsimd_can_huff_encode_one_block (void)
1069{
1070 init_simd();
1071
1072 if (DCTSIZE != 8)
1073 return 0;
1074 if (sizeof(JCOEF) != 2)
1075 return 0;
1076
1077 if ((simd_support & JSIMD_SSE2) && simd_huffman &&
1078 IS_ALIGNED_SSE(jconst_huff_encode_one_block))
1079 return 1;
1080
1081 return 0;
1082}
1083
1084GLOBAL(JOCTET*)
1085jsimd_huff_encode_one_block (void *state, JOCTET *buffer, JCOEFPTR block,
1086 int last_dc_val, c_derived_tbl *dctbl,
1087 c_derived_tbl *actbl)
1088{
1089 return jsimd_huff_encode_one_block_sse2(state, buffer, block, last_dc_val,
1090 dctbl, actbl);
1091}