jsimd.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  1. /*
  2. * jsimd_i386.c
  3. *
  4. * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
  5. * Copyright (C) 2009-2011, 2013-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. * 32-bit x86 architecture.
  15. */
  16. #define JPEG_INTERNALS
  17. #include "../../jinclude.h"
  18. #include "../../jpeglib.h"
  19. #include "../../jsimd.h"
  20. #include "../../jdct.h"
  21. #include "../../jsimddct.h"
  22. #include "../jsimd.h"
  23. #include "jconfigint.h"
  24. /*
  25. * In the PIC cases, we have no guarantee that constants will keep
  26. * their alignment. This macro allows us to verify it at runtime.
  27. */
  28. #define IS_ALIGNED(ptr, order) (((unsigned)ptr & ((1 << order) - 1)) == 0)
  29. #define IS_ALIGNED_SSE(ptr) (IS_ALIGNED(ptr, 4)) /* 16 byte alignment */
  30. #define IS_ALIGNED_AVX(ptr) (IS_ALIGNED(ptr, 5)) /* 32 byte alignment */
  31. static unsigned int simd_support = (unsigned int)(~0);
  32. static unsigned int simd_huffman = 1;
  33. /*
  34. * Check what SIMD accelerations are supported.
  35. *
  36. * FIXME: This code is racy under a multi-threaded environment.
  37. */
  38. LOCAL(void)
  39. init_simd(void)
  40. {
  41. #ifndef NO_GETENV
  42. char *env = NULL;
  43. #endif
  44. if (simd_support != ~0U)
  45. return;
  46. simd_support = jpeg_simd_cpu_support();
  47. #ifndef NO_GETENV
  48. /* Force different settings through environment variables */
  49. env = getenv("JSIMD_FORCEMMX");
  50. if ((env != NULL) && (strcmp(env, "1") == 0))
  51. simd_support &= JSIMD_MMX;
  52. env = getenv("JSIMD_FORCE3DNOW");
  53. if ((env != NULL) && (strcmp(env, "1") == 0))
  54. simd_support &= JSIMD_3DNOW | JSIMD_MMX;
  55. env = getenv("JSIMD_FORCESSE");
  56. if ((env != NULL) && (strcmp(env, "1") == 0))
  57. simd_support &= JSIMD_SSE | JSIMD_MMX;
  58. env = getenv("JSIMD_FORCESSE2");
  59. if ((env != NULL) && (strcmp(env, "1") == 0))
  60. simd_support &= JSIMD_SSE2;
  61. env = getenv("JSIMD_FORCEAVX2");
  62. if ((env != NULL) && (strcmp(env, "1") == 0))
  63. simd_support &= JSIMD_AVX2;
  64. env = getenv("JSIMD_FORCENONE");
  65. if ((env != NULL) && (strcmp(env, "1") == 0))
  66. simd_support = 0;
  67. env = getenv("JSIMD_NOHUFFENC");
  68. if ((env != NULL) && (strcmp(env, "1") == 0))
  69. simd_huffman = 0;
  70. #endif
  71. }
  72. GLOBAL(int)
  73. jsimd_can_rgb_ycc(void)
  74. {
  75. init_simd();
  76. /* The code is optimised for these values only */
  77. if (BITS_IN_JSAMPLE != 8)
  78. return 0;
  79. if (sizeof(JDIMENSION) != 4)
  80. return 0;
  81. if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
  82. return 0;
  83. if ((simd_support & JSIMD_AVX2) &&
  84. IS_ALIGNED_AVX(jconst_rgb_ycc_convert_avx2))
  85. return 1;
  86. if ((simd_support & JSIMD_SSE2) &&
  87. IS_ALIGNED_SSE(jconst_rgb_ycc_convert_sse2))
  88. return 1;
  89. if (simd_support & JSIMD_MMX)
  90. return 1;
  91. return 0;
  92. }
  93. GLOBAL(int)
  94. jsimd_can_rgb_gray(void)
  95. {
  96. init_simd();
  97. /* The code is optimised for these values only */
  98. if (BITS_IN_JSAMPLE != 8)
  99. return 0;
  100. if (sizeof(JDIMENSION) != 4)
  101. return 0;
  102. if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
  103. return 0;
  104. if ((simd_support & JSIMD_AVX2) &&
  105. IS_ALIGNED_AVX(jconst_rgb_gray_convert_avx2))
  106. return 1;
  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. return 0;
  113. }
  114. GLOBAL(int)
  115. jsimd_can_ycc_rgb(void)
  116. {
  117. init_simd();
  118. /* The code is optimised for these values only */
  119. if (BITS_IN_JSAMPLE != 8)
  120. return 0;
  121. if (sizeof(JDIMENSION) != 4)
  122. return 0;
  123. if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
  124. return 0;
  125. if ((simd_support & JSIMD_AVX2) &&
  126. IS_ALIGNED_AVX(jconst_ycc_rgb_convert_avx2))
  127. return 1;
  128. if ((simd_support & JSIMD_SSE2) &&
  129. IS_ALIGNED_SSE(jconst_ycc_rgb_convert_sse2))
  130. return 1;
  131. if (simd_support & JSIMD_MMX)
  132. return 1;
  133. return 0;
  134. }
  135. GLOBAL(int)
  136. jsimd_can_ycc_rgb565(void)
  137. {
  138. return 0;
  139. }
  140. GLOBAL(void)
  141. jsimd_rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
  142. JSAMPIMAGE output_buf, JDIMENSION output_row,
  143. int num_rows)
  144. {
  145. void (*avx2fct) (JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
  146. void (*sse2fct) (JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
  147. void (*mmxfct) (JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
  148. switch (cinfo->in_color_space) {
  149. case JCS_EXT_RGB:
  150. avx2fct = jsimd_extrgb_ycc_convert_avx2;
  151. sse2fct = jsimd_extrgb_ycc_convert_sse2;
  152. mmxfct = jsimd_extrgb_ycc_convert_mmx;
  153. break;
  154. case JCS_EXT_RGBX:
  155. case JCS_EXT_RGBA:
  156. avx2fct = jsimd_extrgbx_ycc_convert_avx2;
  157. sse2fct = jsimd_extrgbx_ycc_convert_sse2;
  158. mmxfct = jsimd_extrgbx_ycc_convert_mmx;
  159. break;
  160. case JCS_EXT_BGR:
  161. avx2fct = jsimd_extbgr_ycc_convert_avx2;
  162. sse2fct = jsimd_extbgr_ycc_convert_sse2;
  163. mmxfct = jsimd_extbgr_ycc_convert_mmx;
  164. break;
  165. case JCS_EXT_BGRX:
  166. case JCS_EXT_BGRA:
  167. avx2fct = jsimd_extbgrx_ycc_convert_avx2;
  168. sse2fct = jsimd_extbgrx_ycc_convert_sse2;
  169. mmxfct = jsimd_extbgrx_ycc_convert_mmx;
  170. break;
  171. case JCS_EXT_XBGR:
  172. case JCS_EXT_ABGR:
  173. avx2fct = jsimd_extxbgr_ycc_convert_avx2;
  174. sse2fct = jsimd_extxbgr_ycc_convert_sse2;
  175. mmxfct = jsimd_extxbgr_ycc_convert_mmx;
  176. break;
  177. case JCS_EXT_XRGB:
  178. case JCS_EXT_ARGB:
  179. avx2fct = jsimd_extxrgb_ycc_convert_avx2;
  180. sse2fct = jsimd_extxrgb_ycc_convert_sse2;
  181. mmxfct = jsimd_extxrgb_ycc_convert_mmx;
  182. break;
  183. default:
  184. avx2fct = jsimd_rgb_ycc_convert_avx2;
  185. sse2fct = jsimd_rgb_ycc_convert_sse2;
  186. mmxfct = jsimd_rgb_ycc_convert_mmx;
  187. break;
  188. }
  189. if (simd_support & JSIMD_AVX2)
  190. avx2fct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
  191. else if (simd_support & JSIMD_SSE2)
  192. sse2fct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
  193. else
  194. mmxfct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
  195. }
  196. GLOBAL(void)
  197. jsimd_rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
  198. JSAMPIMAGE output_buf, JDIMENSION output_row,
  199. int num_rows)
  200. {
  201. void (*avx2fct) (JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
  202. void (*sse2fct) (JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
  203. void (*mmxfct) (JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
  204. switch (cinfo->in_color_space) {
  205. case JCS_EXT_RGB:
  206. avx2fct = jsimd_extrgb_gray_convert_avx2;
  207. sse2fct = jsimd_extrgb_gray_convert_sse2;
  208. mmxfct = jsimd_extrgb_gray_convert_mmx;
  209. break;
  210. case JCS_EXT_RGBX:
  211. case JCS_EXT_RGBA:
  212. avx2fct = jsimd_extrgbx_gray_convert_avx2;
  213. sse2fct = jsimd_extrgbx_gray_convert_sse2;
  214. mmxfct = jsimd_extrgbx_gray_convert_mmx;
  215. break;
  216. case JCS_EXT_BGR:
  217. avx2fct = jsimd_extbgr_gray_convert_avx2;
  218. sse2fct = jsimd_extbgr_gray_convert_sse2;
  219. mmxfct = jsimd_extbgr_gray_convert_mmx;
  220. break;
  221. case JCS_EXT_BGRX:
  222. case JCS_EXT_BGRA:
  223. avx2fct = jsimd_extbgrx_gray_convert_avx2;
  224. sse2fct = jsimd_extbgrx_gray_convert_sse2;
  225. mmxfct = jsimd_extbgrx_gray_convert_mmx;
  226. break;
  227. case JCS_EXT_XBGR:
  228. case JCS_EXT_ABGR:
  229. avx2fct = jsimd_extxbgr_gray_convert_avx2;
  230. sse2fct = jsimd_extxbgr_gray_convert_sse2;
  231. mmxfct = jsimd_extxbgr_gray_convert_mmx;
  232. break;
  233. case JCS_EXT_XRGB:
  234. case JCS_EXT_ARGB:
  235. avx2fct = jsimd_extxrgb_gray_convert_avx2;
  236. sse2fct = jsimd_extxrgb_gray_convert_sse2;
  237. mmxfct = jsimd_extxrgb_gray_convert_mmx;
  238. break;
  239. default:
  240. avx2fct = jsimd_rgb_gray_convert_avx2;
  241. sse2fct = jsimd_rgb_gray_convert_sse2;
  242. mmxfct = jsimd_rgb_gray_convert_mmx;
  243. break;
  244. }
  245. if (simd_support & JSIMD_AVX2)
  246. avx2fct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
  247. else if (simd_support & JSIMD_SSE2)
  248. sse2fct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
  249. else
  250. mmxfct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
  251. }
  252. GLOBAL(void)
  253. jsimd_ycc_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  254. JDIMENSION input_row, JSAMPARRAY output_buf,
  255. int num_rows)
  256. {
  257. void (*avx2fct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
  258. void (*sse2fct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
  259. void (*mmxfct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
  260. switch (cinfo->out_color_space) {
  261. case JCS_EXT_RGB:
  262. avx2fct = jsimd_ycc_extrgb_convert_avx2;
  263. sse2fct = jsimd_ycc_extrgb_convert_sse2;
  264. mmxfct = jsimd_ycc_extrgb_convert_mmx;
  265. break;
  266. case JCS_EXT_RGBX:
  267. case JCS_EXT_RGBA:
  268. avx2fct = jsimd_ycc_extrgbx_convert_avx2;
  269. sse2fct = jsimd_ycc_extrgbx_convert_sse2;
  270. mmxfct = jsimd_ycc_extrgbx_convert_mmx;
  271. break;
  272. case JCS_EXT_BGR:
  273. avx2fct = jsimd_ycc_extbgr_convert_avx2;
  274. sse2fct = jsimd_ycc_extbgr_convert_sse2;
  275. mmxfct = jsimd_ycc_extbgr_convert_mmx;
  276. break;
  277. case JCS_EXT_BGRX:
  278. case JCS_EXT_BGRA:
  279. avx2fct = jsimd_ycc_extbgrx_convert_avx2;
  280. sse2fct = jsimd_ycc_extbgrx_convert_sse2;
  281. mmxfct = jsimd_ycc_extbgrx_convert_mmx;
  282. break;
  283. case JCS_EXT_XBGR:
  284. case JCS_EXT_ABGR:
  285. avx2fct = jsimd_ycc_extxbgr_convert_avx2;
  286. sse2fct = jsimd_ycc_extxbgr_convert_sse2;
  287. mmxfct = jsimd_ycc_extxbgr_convert_mmx;
  288. break;
  289. case JCS_EXT_XRGB:
  290. case JCS_EXT_ARGB:
  291. avx2fct = jsimd_ycc_extxrgb_convert_avx2;
  292. sse2fct = jsimd_ycc_extxrgb_convert_sse2;
  293. mmxfct = jsimd_ycc_extxrgb_convert_mmx;
  294. break;
  295. default:
  296. avx2fct = jsimd_ycc_rgb_convert_avx2;
  297. sse2fct = jsimd_ycc_rgb_convert_sse2;
  298. mmxfct = jsimd_ycc_rgb_convert_mmx;
  299. break;
  300. }
  301. if (simd_support & JSIMD_AVX2)
  302. avx2fct(cinfo->output_width, input_buf, input_row, output_buf, num_rows);
  303. else if (simd_support & JSIMD_SSE2)
  304. sse2fct(cinfo->output_width, input_buf, input_row, output_buf, num_rows);
  305. else
  306. mmxfct(cinfo->output_width, input_buf, input_row, output_buf, num_rows);
  307. }
  308. GLOBAL(void)
  309. jsimd_ycc_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  310. JDIMENSION input_row, JSAMPARRAY output_buf,
  311. int num_rows)
  312. {
  313. }
  314. GLOBAL(int)
  315. jsimd_can_h2v2_downsample(void)
  316. {
  317. init_simd();
  318. /* The code is optimised for these values only */
  319. if (BITS_IN_JSAMPLE != 8)
  320. return 0;
  321. if (sizeof(JDIMENSION) != 4)
  322. return 0;
  323. if (simd_support & JSIMD_AVX2)
  324. return 1;
  325. if (simd_support & JSIMD_SSE2)
  326. return 1;
  327. if (simd_support & JSIMD_MMX)
  328. return 1;
  329. return 0;
  330. }
  331. GLOBAL(int)
  332. jsimd_can_h2v1_downsample(void)
  333. {
  334. init_simd();
  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;
  340. if (simd_support & JSIMD_AVX2)
  341. return 1;
  342. if (simd_support & JSIMD_SSE2)
  343. return 1;
  344. if (simd_support & JSIMD_MMX)
  345. return 1;
  346. return 0;
  347. }
  348. GLOBAL(void)
  349. jsimd_h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
  350. JSAMPARRAY input_data, JSAMPARRAY output_data)
  351. {
  352. if (simd_support & JSIMD_AVX2)
  353. jsimd_h2v2_downsample_avx2(cinfo->image_width, cinfo->max_v_samp_factor,
  354. compptr->v_samp_factor,
  355. compptr->width_in_blocks, input_data,
  356. output_data);
  357. else if (simd_support & JSIMD_SSE2)
  358. jsimd_h2v2_downsample_sse2(cinfo->image_width, cinfo->max_v_samp_factor,
  359. compptr->v_samp_factor,
  360. compptr->width_in_blocks, input_data,
  361. output_data);
  362. else
  363. jsimd_h2v2_downsample_mmx(cinfo->image_width, cinfo->max_v_samp_factor,
  364. compptr->v_samp_factor, compptr->width_in_blocks,
  365. input_data, output_data);
  366. }
  367. GLOBAL(void)
  368. jsimd_h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
  369. JSAMPARRAY input_data, JSAMPARRAY output_data)
  370. {
  371. if (simd_support & JSIMD_AVX2)
  372. jsimd_h2v1_downsample_avx2(cinfo->image_width, cinfo->max_v_samp_factor,
  373. compptr->v_samp_factor,
  374. compptr->width_in_blocks, input_data,
  375. output_data);
  376. else if (simd_support & JSIMD_SSE2)
  377. jsimd_h2v1_downsample_sse2(cinfo->image_width, cinfo->max_v_samp_factor,
  378. compptr->v_samp_factor,
  379. compptr->width_in_blocks, input_data,
  380. output_data);
  381. else
  382. jsimd_h2v1_downsample_mmx(cinfo->image_width, cinfo->max_v_samp_factor,
  383. compptr->v_samp_factor, compptr->width_in_blocks,
  384. input_data, output_data);
  385. }
  386. GLOBAL(int)
  387. jsimd_can_h2v2_upsample(void)
  388. {
  389. init_simd();
  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. if (simd_support & JSIMD_AVX2)
  396. return 1;
  397. if (simd_support & JSIMD_SSE2)
  398. return 1;
  399. if (simd_support & JSIMD_MMX)
  400. return 1;
  401. return 0;
  402. }
  403. GLOBAL(int)
  404. jsimd_can_h2v1_upsample(void)
  405. {
  406. init_simd();
  407. /* The code is optimised for these values only */
  408. if (BITS_IN_JSAMPLE != 8)
  409. return 0;
  410. if (sizeof(JDIMENSION) != 4)
  411. return 0;
  412. if (simd_support & JSIMD_AVX2)
  413. return 1;
  414. if (simd_support & JSIMD_SSE2)
  415. return 1;
  416. if (simd_support & JSIMD_MMX)
  417. return 1;
  418. return 0;
  419. }
  420. GLOBAL(void)
  421. jsimd_h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  422. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  423. {
  424. if (simd_support & JSIMD_AVX2)
  425. jsimd_h2v2_upsample_avx2(cinfo->max_v_samp_factor, cinfo->output_width,
  426. input_data, output_data_ptr);
  427. else if (simd_support & JSIMD_SSE2)
  428. jsimd_h2v2_upsample_sse2(cinfo->max_v_samp_factor, cinfo->output_width,
  429. input_data, output_data_ptr);
  430. else
  431. jsimd_h2v2_upsample_mmx(cinfo->max_v_samp_factor, cinfo->output_width,
  432. input_data, output_data_ptr);
  433. }
  434. GLOBAL(void)
  435. jsimd_h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  436. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  437. {
  438. if (simd_support & JSIMD_AVX2)
  439. jsimd_h2v1_upsample_avx2(cinfo->max_v_samp_factor, cinfo->output_width,
  440. input_data, output_data_ptr);
  441. else if (simd_support & JSIMD_SSE2)
  442. jsimd_h2v1_upsample_sse2(cinfo->max_v_samp_factor, cinfo->output_width,
  443. input_data, output_data_ptr);
  444. else
  445. jsimd_h2v1_upsample_mmx(cinfo->max_v_samp_factor, cinfo->output_width,
  446. input_data, output_data_ptr);
  447. }
  448. GLOBAL(int)
  449. jsimd_can_h2v2_fancy_upsample(void)
  450. {
  451. init_simd();
  452. /* The code is optimised for these values only */
  453. if (BITS_IN_JSAMPLE != 8)
  454. return 0;
  455. if (sizeof(JDIMENSION) != 4)
  456. return 0;
  457. if ((simd_support & JSIMD_AVX2) &&
  458. IS_ALIGNED_AVX(jconst_fancy_upsample_avx2))
  459. return 1;
  460. if ((simd_support & JSIMD_SSE2) &&
  461. IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
  462. return 1;
  463. if (simd_support & JSIMD_MMX)
  464. return 1;
  465. return 0;
  466. }
  467. GLOBAL(int)
  468. jsimd_can_h2v1_fancy_upsample(void)
  469. {
  470. init_simd();
  471. /* The code is optimised for these values only */
  472. if (BITS_IN_JSAMPLE != 8)
  473. return 0;
  474. if (sizeof(JDIMENSION) != 4)
  475. return 0;
  476. if ((simd_support & JSIMD_AVX2) &&
  477. IS_ALIGNED_AVX(jconst_fancy_upsample_avx2))
  478. return 1;
  479. if ((simd_support & JSIMD_SSE2) &&
  480. IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
  481. return 1;
  482. if (simd_support & JSIMD_MMX)
  483. return 1;
  484. return 0;
  485. }
  486. GLOBAL(void)
  487. jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  488. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  489. {
  490. if (simd_support & JSIMD_AVX2)
  491. jsimd_h2v2_fancy_upsample_avx2(cinfo->max_v_samp_factor,
  492. compptr->downsampled_width, input_data,
  493. output_data_ptr);
  494. else if (simd_support & JSIMD_SSE2)
  495. jsimd_h2v2_fancy_upsample_sse2(cinfo->max_v_samp_factor,
  496. compptr->downsampled_width, input_data,
  497. output_data_ptr);
  498. else
  499. jsimd_h2v2_fancy_upsample_mmx(cinfo->max_v_samp_factor,
  500. compptr->downsampled_width, input_data,
  501. output_data_ptr);
  502. }
  503. GLOBAL(void)
  504. jsimd_h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  505. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  506. {
  507. if (simd_support & JSIMD_AVX2)
  508. jsimd_h2v1_fancy_upsample_avx2(cinfo->max_v_samp_factor,
  509. compptr->downsampled_width, input_data,
  510. output_data_ptr);
  511. else if (simd_support & JSIMD_SSE2)
  512. jsimd_h2v1_fancy_upsample_sse2(cinfo->max_v_samp_factor,
  513. compptr->downsampled_width, input_data,
  514. output_data_ptr);
  515. else
  516. jsimd_h2v1_fancy_upsample_mmx(cinfo->max_v_samp_factor,
  517. compptr->downsampled_width, input_data,
  518. output_data_ptr);
  519. }
  520. GLOBAL(int)
  521. jsimd_can_h2v2_merged_upsample(void)
  522. {
  523. init_simd();
  524. /* The code is optimised for these values only */
  525. if (BITS_IN_JSAMPLE != 8)
  526. return 0;
  527. if (sizeof(JDIMENSION) != 4)
  528. return 0;
  529. if ((simd_support & JSIMD_AVX2) &&
  530. IS_ALIGNED_AVX(jconst_merged_upsample_avx2))
  531. return 1;
  532. if ((simd_support & JSIMD_SSE2) &&
  533. IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
  534. return 1;
  535. if (simd_support & JSIMD_MMX)
  536. return 1;
  537. return 0;
  538. }
  539. GLOBAL(int)
  540. jsimd_can_h2v1_merged_upsample(void)
  541. {
  542. init_simd();
  543. /* The code is optimised for these values only */
  544. if (BITS_IN_JSAMPLE != 8)
  545. return 0;
  546. if (sizeof(JDIMENSION) != 4)
  547. return 0;
  548. if ((simd_support & JSIMD_AVX2) &&
  549. IS_ALIGNED_AVX(jconst_merged_upsample_avx2))
  550. return 1;
  551. if ((simd_support & JSIMD_SSE2) &&
  552. IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
  553. return 1;
  554. if (simd_support & JSIMD_MMX)
  555. return 1;
  556. return 0;
  557. }
  558. GLOBAL(void)
  559. jsimd_h2v2_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  560. JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
  561. {
  562. void (*avx2fct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
  563. void (*sse2fct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
  564. void (*mmxfct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
  565. switch (cinfo->out_color_space) {
  566. case JCS_EXT_RGB:
  567. avx2fct = jsimd_h2v2_extrgb_merged_upsample_avx2;
  568. sse2fct = jsimd_h2v2_extrgb_merged_upsample_sse2;
  569. mmxfct = jsimd_h2v2_extrgb_merged_upsample_mmx;
  570. break;
  571. case JCS_EXT_RGBX:
  572. case JCS_EXT_RGBA:
  573. avx2fct = jsimd_h2v2_extrgbx_merged_upsample_avx2;
  574. sse2fct = jsimd_h2v2_extrgbx_merged_upsample_sse2;
  575. mmxfct = jsimd_h2v2_extrgbx_merged_upsample_mmx;
  576. break;
  577. case JCS_EXT_BGR:
  578. avx2fct = jsimd_h2v2_extbgr_merged_upsample_avx2;
  579. sse2fct = jsimd_h2v2_extbgr_merged_upsample_sse2;
  580. mmxfct = jsimd_h2v2_extbgr_merged_upsample_mmx;
  581. break;
  582. case JCS_EXT_BGRX:
  583. case JCS_EXT_BGRA:
  584. avx2fct = jsimd_h2v2_extbgrx_merged_upsample_avx2;
  585. sse2fct = jsimd_h2v2_extbgrx_merged_upsample_sse2;
  586. mmxfct = jsimd_h2v2_extbgrx_merged_upsample_mmx;
  587. break;
  588. case JCS_EXT_XBGR:
  589. case JCS_EXT_ABGR:
  590. avx2fct = jsimd_h2v2_extxbgr_merged_upsample_avx2;
  591. sse2fct = jsimd_h2v2_extxbgr_merged_upsample_sse2;
  592. mmxfct = jsimd_h2v2_extxbgr_merged_upsample_mmx;
  593. break;
  594. case JCS_EXT_XRGB:
  595. case JCS_EXT_ARGB:
  596. avx2fct = jsimd_h2v2_extxrgb_merged_upsample_avx2;
  597. sse2fct = jsimd_h2v2_extxrgb_merged_upsample_sse2;
  598. mmxfct = jsimd_h2v2_extxrgb_merged_upsample_mmx;
  599. break;
  600. default:
  601. avx2fct = jsimd_h2v2_merged_upsample_avx2;
  602. sse2fct = jsimd_h2v2_merged_upsample_sse2;
  603. mmxfct = jsimd_h2v2_merged_upsample_mmx;
  604. break;
  605. }
  606. if (simd_support & JSIMD_AVX2)
  607. avx2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
  608. else if (simd_support & JSIMD_SSE2)
  609. sse2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
  610. else
  611. mmxfct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
  612. }
  613. GLOBAL(void)
  614. jsimd_h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  615. JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
  616. {
  617. void (*avx2fct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
  618. void (*sse2fct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
  619. void (*mmxfct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
  620. switch (cinfo->out_color_space) {
  621. case JCS_EXT_RGB:
  622. avx2fct = jsimd_h2v1_extrgb_merged_upsample_avx2;
  623. sse2fct = jsimd_h2v1_extrgb_merged_upsample_sse2;
  624. mmxfct = jsimd_h2v1_extrgb_merged_upsample_mmx;
  625. break;
  626. case JCS_EXT_RGBX:
  627. case JCS_EXT_RGBA:
  628. avx2fct = jsimd_h2v1_extrgbx_merged_upsample_avx2;
  629. sse2fct = jsimd_h2v1_extrgbx_merged_upsample_sse2;
  630. mmxfct = jsimd_h2v1_extrgbx_merged_upsample_mmx;
  631. break;
  632. case JCS_EXT_BGR:
  633. avx2fct = jsimd_h2v1_extbgr_merged_upsample_avx2;
  634. sse2fct = jsimd_h2v1_extbgr_merged_upsample_sse2;
  635. mmxfct = jsimd_h2v1_extbgr_merged_upsample_mmx;
  636. break;
  637. case JCS_EXT_BGRX:
  638. case JCS_EXT_BGRA:
  639. avx2fct = jsimd_h2v1_extbgrx_merged_upsample_avx2;
  640. sse2fct = jsimd_h2v1_extbgrx_merged_upsample_sse2;
  641. mmxfct = jsimd_h2v1_extbgrx_merged_upsample_mmx;
  642. break;
  643. case JCS_EXT_XBGR:
  644. case JCS_EXT_ABGR:
  645. avx2fct = jsimd_h2v1_extxbgr_merged_upsample_avx2;
  646. sse2fct = jsimd_h2v1_extxbgr_merged_upsample_sse2;
  647. mmxfct = jsimd_h2v1_extxbgr_merged_upsample_mmx;
  648. break;
  649. case JCS_EXT_XRGB:
  650. case JCS_EXT_ARGB:
  651. avx2fct = jsimd_h2v1_extxrgb_merged_upsample_avx2;
  652. sse2fct = jsimd_h2v1_extxrgb_merged_upsample_sse2;
  653. mmxfct = jsimd_h2v1_extxrgb_merged_upsample_mmx;
  654. break;
  655. default:
  656. avx2fct = jsimd_h2v1_merged_upsample_avx2;
  657. sse2fct = jsimd_h2v1_merged_upsample_sse2;
  658. mmxfct = jsimd_h2v1_merged_upsample_mmx;
  659. break;
  660. }
  661. if (simd_support & JSIMD_AVX2)
  662. avx2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
  663. else if (simd_support & JSIMD_SSE2)
  664. sse2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
  665. else
  666. mmxfct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
  667. }
  668. GLOBAL(int)
  669. jsimd_can_convsamp(void)
  670. {
  671. init_simd();
  672. /* The code is optimised for these values only */
  673. if (DCTSIZE != 8)
  674. return 0;
  675. if (BITS_IN_JSAMPLE != 8)
  676. return 0;
  677. if (sizeof(JDIMENSION) != 4)
  678. return 0;
  679. if (sizeof(DCTELEM) != 2)
  680. return 0;
  681. if (simd_support & JSIMD_AVX2)
  682. return 1;
  683. if (simd_support & JSIMD_SSE2)
  684. return 1;
  685. if (simd_support & JSIMD_MMX)
  686. return 1;
  687. return 0;
  688. }
  689. GLOBAL(int)
  690. jsimd_can_convsamp_float(void)
  691. {
  692. init_simd();
  693. /* The code is optimised for these values only */
  694. if (DCTSIZE != 8)
  695. return 0;
  696. if (BITS_IN_JSAMPLE != 8)
  697. return 0;
  698. if (sizeof(JDIMENSION) != 4)
  699. return 0;
  700. if (sizeof(FAST_FLOAT) != 4)
  701. return 0;
  702. if (simd_support & JSIMD_SSE2)
  703. return 1;
  704. if (simd_support & JSIMD_SSE)
  705. return 1;
  706. if (simd_support & JSIMD_3DNOW)
  707. return 1;
  708. return 0;
  709. }
  710. GLOBAL(void)
  711. jsimd_convsamp(JSAMPARRAY sample_data, JDIMENSION start_col,
  712. DCTELEM *workspace)
  713. {
  714. if (simd_support & JSIMD_AVX2)
  715. jsimd_convsamp_avx2(sample_data, start_col, workspace);
  716. else if (simd_support & JSIMD_SSE2)
  717. jsimd_convsamp_sse2(sample_data, start_col, workspace);
  718. else
  719. jsimd_convsamp_mmx(sample_data, start_col, workspace);
  720. }
  721. GLOBAL(void)
  722. jsimd_convsamp_float(JSAMPARRAY sample_data, JDIMENSION start_col,
  723. FAST_FLOAT *workspace)
  724. {
  725. if (simd_support & JSIMD_SSE2)
  726. jsimd_convsamp_float_sse2(sample_data, start_col, workspace);
  727. else if (simd_support & JSIMD_SSE)
  728. jsimd_convsamp_float_sse(sample_data, start_col, workspace);
  729. else
  730. jsimd_convsamp_float_3dnow(sample_data, start_col, workspace);
  731. }
  732. GLOBAL(int)
  733. jsimd_can_fdct_islow(void)
  734. {
  735. init_simd();
  736. /* The code is optimised for these values only */
  737. if (DCTSIZE != 8)
  738. return 0;
  739. if (sizeof(DCTELEM) != 2)
  740. return 0;
  741. if ((simd_support & JSIMD_AVX2) && IS_ALIGNED_AVX(jconst_fdct_islow_avx2))
  742. return 1;
  743. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_islow_sse2))
  744. return 1;
  745. if (simd_support & JSIMD_MMX)
  746. return 1;
  747. return 0;
  748. }
  749. GLOBAL(int)
  750. jsimd_can_fdct_ifast(void)
  751. {
  752. init_simd();
  753. /* The code is optimised for these values only */
  754. if (DCTSIZE != 8)
  755. return 0;
  756. if (sizeof(DCTELEM) != 2)
  757. return 0;
  758. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_ifast_sse2))
  759. return 1;
  760. if (simd_support & JSIMD_MMX)
  761. return 1;
  762. return 0;
  763. }
  764. GLOBAL(int)
  765. jsimd_can_fdct_float(void)
  766. {
  767. init_simd();
  768. /* The code is optimised for these values only */
  769. if (DCTSIZE != 8)
  770. return 0;
  771. if (sizeof(FAST_FLOAT) != 4)
  772. return 0;
  773. if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_fdct_float_sse))
  774. return 1;
  775. if (simd_support & JSIMD_3DNOW)
  776. return 1;
  777. return 0;
  778. }
  779. GLOBAL(void)
  780. jsimd_fdct_islow(DCTELEM *data)
  781. {
  782. if (simd_support & JSIMD_AVX2)
  783. jsimd_fdct_islow_avx2(data);
  784. else if (simd_support & JSIMD_SSE2)
  785. jsimd_fdct_islow_sse2(data);
  786. else
  787. jsimd_fdct_islow_mmx(data);
  788. }
  789. GLOBAL(void)
  790. jsimd_fdct_ifast(DCTELEM *data)
  791. {
  792. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_islow_sse2))
  793. jsimd_fdct_ifast_sse2(data);
  794. else
  795. jsimd_fdct_ifast_mmx(data);
  796. }
  797. GLOBAL(void)
  798. jsimd_fdct_float(FAST_FLOAT *data)
  799. {
  800. if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_fdct_float_sse))
  801. jsimd_fdct_float_sse(data);
  802. else if (simd_support & JSIMD_3DNOW)
  803. jsimd_fdct_float_3dnow(data);
  804. }
  805. GLOBAL(int)
  806. jsimd_can_quantize(void)
  807. {
  808. init_simd();
  809. /* The code is optimised for these values only */
  810. if (DCTSIZE != 8)
  811. return 0;
  812. if (sizeof(JCOEF) != 2)
  813. return 0;
  814. if (sizeof(DCTELEM) != 2)
  815. return 0;
  816. if (simd_support & JSIMD_AVX2)
  817. return 1;
  818. if (simd_support & JSIMD_SSE2)
  819. return 1;
  820. if (simd_support & JSIMD_MMX)
  821. return 1;
  822. return 0;
  823. }
  824. GLOBAL(int)
  825. jsimd_can_quantize_float(void)
  826. {
  827. init_simd();
  828. /* The code is optimised for these values only */
  829. if (DCTSIZE != 8)
  830. return 0;
  831. if (sizeof(JCOEF) != 2)
  832. return 0;
  833. if (sizeof(FAST_FLOAT) != 4)
  834. return 0;
  835. if (simd_support & JSIMD_SSE2)
  836. return 1;
  837. if (simd_support & JSIMD_SSE)
  838. return 1;
  839. if (simd_support & JSIMD_3DNOW)
  840. return 1;
  841. return 0;
  842. }
  843. GLOBAL(void)
  844. jsimd_quantize(JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace)
  845. {
  846. if (simd_support & JSIMD_AVX2)
  847. jsimd_quantize_avx2(coef_block, divisors, workspace);
  848. else if (simd_support & JSIMD_SSE2)
  849. jsimd_quantize_sse2(coef_block, divisors, workspace);
  850. else
  851. jsimd_quantize_mmx(coef_block, divisors, workspace);
  852. }
  853. GLOBAL(void)
  854. jsimd_quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors,
  855. FAST_FLOAT *workspace)
  856. {
  857. if (simd_support & JSIMD_SSE2)
  858. jsimd_quantize_float_sse2(coef_block, divisors, workspace);
  859. else if (simd_support & JSIMD_SSE)
  860. jsimd_quantize_float_sse(coef_block, divisors, workspace);
  861. else
  862. jsimd_quantize_float_3dnow(coef_block, divisors, workspace);
  863. }
  864. GLOBAL(int)
  865. jsimd_can_idct_2x2(void)
  866. {
  867. init_simd();
  868. /* The code is optimised for these values only */
  869. if (DCTSIZE != 8)
  870. return 0;
  871. if (sizeof(JCOEF) != 2)
  872. return 0;
  873. if (BITS_IN_JSAMPLE != 8)
  874. return 0;
  875. if (sizeof(JDIMENSION) != 4)
  876. return 0;
  877. if (sizeof(ISLOW_MULT_TYPE) != 2)
  878. return 0;
  879. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2))
  880. return 1;
  881. if (simd_support & JSIMD_MMX)
  882. return 1;
  883. return 0;
  884. }
  885. GLOBAL(int)
  886. jsimd_can_idct_4x4(void)
  887. {
  888. init_simd();
  889. /* The code is optimised for these values only */
  890. if (DCTSIZE != 8)
  891. return 0;
  892. if (sizeof(JCOEF) != 2)
  893. return 0;
  894. if (BITS_IN_JSAMPLE != 8)
  895. return 0;
  896. if (sizeof(JDIMENSION) != 4)
  897. return 0;
  898. if (sizeof(ISLOW_MULT_TYPE) != 2)
  899. return 0;
  900. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2))
  901. return 1;
  902. if (simd_support & JSIMD_MMX)
  903. return 1;
  904. return 0;
  905. }
  906. GLOBAL(void)
  907. jsimd_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  908. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  909. JDIMENSION output_col)
  910. {
  911. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2))
  912. jsimd_idct_2x2_sse2(compptr->dct_table, coef_block, output_buf,
  913. output_col);
  914. else
  915. jsimd_idct_2x2_mmx(compptr->dct_table, coef_block, output_buf, output_col);
  916. }
  917. GLOBAL(void)
  918. jsimd_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  919. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  920. JDIMENSION output_col)
  921. {
  922. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2))
  923. jsimd_idct_4x4_sse2(compptr->dct_table, coef_block, output_buf,
  924. output_col);
  925. else
  926. jsimd_idct_4x4_mmx(compptr->dct_table, coef_block, output_buf, output_col);
  927. }
  928. GLOBAL(int)
  929. jsimd_can_idct_islow(void)
  930. {
  931. init_simd();
  932. /* The code is optimised for these values only */
  933. if (DCTSIZE != 8)
  934. return 0;
  935. if (sizeof(JCOEF) != 2)
  936. return 0;
  937. if (BITS_IN_JSAMPLE != 8)
  938. return 0;
  939. if (sizeof(JDIMENSION) != 4)
  940. return 0;
  941. if (sizeof(ISLOW_MULT_TYPE) != 2)
  942. return 0;
  943. if ((simd_support & JSIMD_AVX2) && IS_ALIGNED_AVX(jconst_idct_islow_avx2))
  944. return 1;
  945. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_islow_sse2))
  946. return 1;
  947. if (simd_support & JSIMD_MMX)
  948. return 1;
  949. return 0;
  950. }
  951. GLOBAL(int)
  952. jsimd_can_idct_ifast(void)
  953. {
  954. init_simd();
  955. /* The code is optimised for these values only */
  956. if (DCTSIZE != 8)
  957. return 0;
  958. if (sizeof(JCOEF) != 2)
  959. return 0;
  960. if (BITS_IN_JSAMPLE != 8)
  961. return 0;
  962. if (sizeof(JDIMENSION) != 4)
  963. return 0;
  964. if (sizeof(IFAST_MULT_TYPE) != 2)
  965. return 0;
  966. if (IFAST_SCALE_BITS != 2)
  967. return 0;
  968. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_ifast_sse2))
  969. return 1;
  970. if (simd_support & JSIMD_MMX)
  971. return 1;
  972. return 0;
  973. }
  974. GLOBAL(int)
  975. jsimd_can_idct_float(void)
  976. {
  977. init_simd();
  978. if (DCTSIZE != 8)
  979. return 0;
  980. if (sizeof(JCOEF) != 2)
  981. return 0;
  982. if (BITS_IN_JSAMPLE != 8)
  983. return 0;
  984. if (sizeof(JDIMENSION) != 4)
  985. return 0;
  986. if (sizeof(FAST_FLOAT) != 4)
  987. return 0;
  988. if (sizeof(FLOAT_MULT_TYPE) != 4)
  989. return 0;
  990. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_float_sse2))
  991. return 1;
  992. if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_idct_float_sse))
  993. return 1;
  994. if (simd_support & JSIMD_3DNOW)
  995. return 1;
  996. return 0;
  997. }
  998. GLOBAL(void)
  999. jsimd_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  1000. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  1001. JDIMENSION output_col)
  1002. {
  1003. if (simd_support & JSIMD_AVX2)
  1004. jsimd_idct_islow_avx2(compptr->dct_table, coef_block, output_buf,
  1005. output_col);
  1006. else if (simd_support & JSIMD_SSE2)
  1007. jsimd_idct_islow_sse2(compptr->dct_table, coef_block, output_buf,
  1008. output_col);
  1009. else
  1010. jsimd_idct_islow_mmx(compptr->dct_table, coef_block, output_buf,
  1011. output_col);
  1012. }
  1013. GLOBAL(void)
  1014. jsimd_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  1015. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  1016. JDIMENSION output_col)
  1017. {
  1018. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_ifast_sse2))
  1019. jsimd_idct_ifast_sse2(compptr->dct_table, coef_block, output_buf,
  1020. output_col);
  1021. else
  1022. jsimd_idct_ifast_mmx(compptr->dct_table, coef_block, output_buf,
  1023. output_col);
  1024. }
  1025. GLOBAL(void)
  1026. jsimd_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  1027. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  1028. JDIMENSION output_col)
  1029. {
  1030. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_float_sse2))
  1031. jsimd_idct_float_sse2(compptr->dct_table, coef_block, output_buf,
  1032. output_col);
  1033. else if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_idct_float_sse))
  1034. jsimd_idct_float_sse(compptr->dct_table, coef_block, output_buf,
  1035. output_col);
  1036. else
  1037. jsimd_idct_float_3dnow(compptr->dct_table, coef_block, output_buf,
  1038. output_col);
  1039. }
  1040. GLOBAL(int)
  1041. jsimd_can_huff_encode_one_block(void)
  1042. {
  1043. init_simd();
  1044. if (DCTSIZE != 8)
  1045. return 0;
  1046. if (sizeof(JCOEF) != 2)
  1047. return 0;
  1048. if ((simd_support & JSIMD_SSE2) && simd_huffman &&
  1049. IS_ALIGNED_SSE(jconst_huff_encode_one_block))
  1050. return 1;
  1051. return 0;
  1052. }
  1053. GLOBAL(JOCTET *)
  1054. jsimd_huff_encode_one_block(void *state, JOCTET *buffer, JCOEFPTR block,
  1055. int last_dc_val, c_derived_tbl *dctbl,
  1056. c_derived_tbl *actbl)
  1057. {
  1058. return jsimd_huff_encode_one_block_sse2(state, buffer, block, last_dc_val,
  1059. dctbl, actbl);
  1060. }
  1061. GLOBAL(int)
  1062. jsimd_can_encode_mcu_AC_first_prepare(void)
  1063. {
  1064. init_simd();
  1065. if (DCTSIZE != 8)
  1066. return 0;
  1067. if (sizeof(JCOEF) != 2)
  1068. return 0;
  1069. if (SIZEOF_SIZE_T != 4)
  1070. return 0;
  1071. if (simd_support & JSIMD_SSE2)
  1072. return 1;
  1073. return 0;
  1074. }
  1075. GLOBAL(void)
  1076. jsimd_encode_mcu_AC_first_prepare(const JCOEF *block,
  1077. const int *jpeg_natural_order_start, int Sl,
  1078. int Al, JCOEF *values, size_t *zerobits)
  1079. {
  1080. jsimd_encode_mcu_AC_first_prepare_sse2(block, jpeg_natural_order_start,
  1081. Sl, Al, values, zerobits);
  1082. }
  1083. GLOBAL(int)
  1084. jsimd_can_encode_mcu_AC_refine_prepare(void)
  1085. {
  1086. init_simd();
  1087. if (DCTSIZE != 8)
  1088. return 0;
  1089. if (sizeof(JCOEF) != 2)
  1090. return 0;
  1091. if (SIZEOF_SIZE_T != 4)
  1092. return 0;
  1093. if (simd_support & JSIMD_SSE2)
  1094. return 1;
  1095. return 0;
  1096. }
  1097. GLOBAL(int)
  1098. jsimd_encode_mcu_AC_refine_prepare(const JCOEF *block,
  1099. const int *jpeg_natural_order_start, int Sl,
  1100. int Al, JCOEF *absvalues, size_t *bits)
  1101. {
  1102. return jsimd_encode_mcu_AC_refine_prepare_sse2(block,
  1103. jpeg_natural_order_start,
  1104. Sl, Al, absvalues, bits);
  1105. }