jsimd_i386.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  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, D. R. Commander.
  6. * Copyright (C) 2015, Matthieu Darbois.
  7. *
  8. * Based on the x86 SIMD extension for IJG JPEG library,
  9. * Copyright (C) 1999-2006, MIYASAKA Masaru.
  10. * For conditions of distribution and use, see copyright notice in jsimdext.inc
  11. *
  12. * This file contains the interface between the "normal" portions
  13. * of the library and the SIMD implementations when running on a
  14. * 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. /*
  24. * In the PIC cases, we have no guarantee that constants will keep
  25. * their alignment. This macro allows us to verify it at runtime.
  26. */
  27. #define IS_ALIGNED(ptr, order) (((unsigned)ptr & ((1 << order) - 1)) == 0)
  28. #define IS_ALIGNED_SSE(ptr) (IS_ALIGNED(ptr, 4)) /* 16 byte alignment */
  29. static unsigned int simd_support = ~0;
  30. static unsigned int simd_huffman = 1;
  31. /*
  32. * Check what SIMD accelerations are supported.
  33. *
  34. * FIXME: This code is racy under a multi-threaded environment.
  35. */
  36. LOCAL(void)
  37. init_simd (void)
  38. {
  39. char *env = NULL;
  40. if (simd_support != ~0U)
  41. return;
  42. simd_support = jpeg_simd_cpu_support();
  43. /* Force different settings through environment variables */
  44. env = getenv("JSIMD_FORCEMMX");
  45. if ((env != NULL) && (strcmp(env, "1") == 0))
  46. simd_support &= JSIMD_MMX;
  47. env = getenv("JSIMD_FORCE3DNOW");
  48. if ((env != NULL) && (strcmp(env, "1") == 0))
  49. simd_support &= JSIMD_3DNOW|JSIMD_MMX;
  50. env = getenv("JSIMD_FORCESSE");
  51. if ((env != NULL) && (strcmp(env, "1") == 0))
  52. simd_support &= JSIMD_SSE|JSIMD_MMX;
  53. env = getenv("JSIMD_FORCESSE2");
  54. if ((env != NULL) && (strcmp(env, "1") == 0))
  55. simd_support &= JSIMD_SSE2;
  56. env = getenv("JSIMD_FORCENONE");
  57. if ((env != NULL) && (strcmp(env, "1") == 0))
  58. simd_support = 0;
  59. env = getenv("JSIMD_NOHUFFENC");
  60. if ((env != NULL) && (strcmp(env, "1") == 0))
  61. simd_huffman = 0;
  62. }
  63. GLOBAL(int)
  64. jsimd_can_rgb_ycc (void)
  65. {
  66. init_simd();
  67. /* The code is optimised for these values only */
  68. if (BITS_IN_JSAMPLE != 8)
  69. return 0;
  70. if (sizeof(JDIMENSION) != 4)
  71. return 0;
  72. if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
  73. return 0;
  74. if ((simd_support & JSIMD_SSE2) &&
  75. IS_ALIGNED_SSE(jconst_rgb_ycc_convert_sse2))
  76. return 1;
  77. if (simd_support & JSIMD_MMX)
  78. return 1;
  79. return 0;
  80. }
  81. GLOBAL(int)
  82. jsimd_can_rgb_gray (void)
  83. {
  84. init_simd();
  85. /* The code is optimised for these values only */
  86. if (BITS_IN_JSAMPLE != 8)
  87. return 0;
  88. if (sizeof(JDIMENSION) != 4)
  89. return 0;
  90. if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
  91. return 0;
  92. if ((simd_support & JSIMD_SSE2) &&
  93. IS_ALIGNED_SSE(jconst_rgb_gray_convert_sse2))
  94. return 1;
  95. if (simd_support & JSIMD_MMX)
  96. return 1;
  97. return 0;
  98. }
  99. GLOBAL(int)
  100. jsimd_can_ycc_rgb (void)
  101. {
  102. init_simd();
  103. /* The code is optimised for these values only */
  104. if (BITS_IN_JSAMPLE != 8)
  105. return 0;
  106. if (sizeof(JDIMENSION) != 4)
  107. return 0;
  108. if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
  109. return 0;
  110. if ((simd_support & JSIMD_SSE2) &&
  111. IS_ALIGNED_SSE(jconst_ycc_rgb_convert_sse2))
  112. return 1;
  113. if (simd_support & JSIMD_MMX)
  114. return 1;
  115. return 0;
  116. }
  117. GLOBAL(int)
  118. jsimd_can_ycc_rgb565 (void)
  119. {
  120. return 0;
  121. }
  122. GLOBAL(void)
  123. jsimd_rgb_ycc_convert (j_compress_ptr cinfo,
  124. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  125. JDIMENSION output_row, int num_rows)
  126. {
  127. void (*sse2fct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
  128. void (*mmxfct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
  129. switch(cinfo->in_color_space) {
  130. case JCS_EXT_RGB:
  131. sse2fct=jsimd_extrgb_ycc_convert_sse2;
  132. mmxfct=jsimd_extrgb_ycc_convert_mmx;
  133. break;
  134. case JCS_EXT_RGBX:
  135. case JCS_EXT_RGBA:
  136. sse2fct=jsimd_extrgbx_ycc_convert_sse2;
  137. mmxfct=jsimd_extrgbx_ycc_convert_mmx;
  138. break;
  139. case JCS_EXT_BGR:
  140. sse2fct=jsimd_extbgr_ycc_convert_sse2;
  141. mmxfct=jsimd_extbgr_ycc_convert_mmx;
  142. break;
  143. case JCS_EXT_BGRX:
  144. case JCS_EXT_BGRA:
  145. sse2fct=jsimd_extbgrx_ycc_convert_sse2;
  146. mmxfct=jsimd_extbgrx_ycc_convert_mmx;
  147. break;
  148. case JCS_EXT_XBGR:
  149. case JCS_EXT_ABGR:
  150. sse2fct=jsimd_extxbgr_ycc_convert_sse2;
  151. mmxfct=jsimd_extxbgr_ycc_convert_mmx;
  152. break;
  153. case JCS_EXT_XRGB:
  154. case JCS_EXT_ARGB:
  155. sse2fct=jsimd_extxrgb_ycc_convert_sse2;
  156. mmxfct=jsimd_extxrgb_ycc_convert_mmx;
  157. break;
  158. default:
  159. sse2fct=jsimd_rgb_ycc_convert_sse2;
  160. mmxfct=jsimd_rgb_ycc_convert_mmx;
  161. break;
  162. }
  163. if ((simd_support & JSIMD_SSE2) &&
  164. IS_ALIGNED_SSE(jconst_rgb_ycc_convert_sse2))
  165. sse2fct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
  166. else if (simd_support & JSIMD_MMX)
  167. mmxfct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
  168. }
  169. GLOBAL(void)
  170. jsimd_rgb_gray_convert (j_compress_ptr cinfo,
  171. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  172. JDIMENSION output_row, int num_rows)
  173. {
  174. void (*sse2fct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
  175. void (*mmxfct)(JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
  176. switch(cinfo->in_color_space) {
  177. case JCS_EXT_RGB:
  178. sse2fct=jsimd_extrgb_gray_convert_sse2;
  179. mmxfct=jsimd_extrgb_gray_convert_mmx;
  180. break;
  181. case JCS_EXT_RGBX:
  182. case JCS_EXT_RGBA:
  183. sse2fct=jsimd_extrgbx_gray_convert_sse2;
  184. mmxfct=jsimd_extrgbx_gray_convert_mmx;
  185. break;
  186. case JCS_EXT_BGR:
  187. sse2fct=jsimd_extbgr_gray_convert_sse2;
  188. mmxfct=jsimd_extbgr_gray_convert_mmx;
  189. break;
  190. case JCS_EXT_BGRX:
  191. case JCS_EXT_BGRA:
  192. sse2fct=jsimd_extbgrx_gray_convert_sse2;
  193. mmxfct=jsimd_extbgrx_gray_convert_mmx;
  194. break;
  195. case JCS_EXT_XBGR:
  196. case JCS_EXT_ABGR:
  197. sse2fct=jsimd_extxbgr_gray_convert_sse2;
  198. mmxfct=jsimd_extxbgr_gray_convert_mmx;
  199. break;
  200. case JCS_EXT_XRGB:
  201. case JCS_EXT_ARGB:
  202. sse2fct=jsimd_extxrgb_gray_convert_sse2;
  203. mmxfct=jsimd_extxrgb_gray_convert_mmx;
  204. break;
  205. default:
  206. sse2fct=jsimd_rgb_gray_convert_sse2;
  207. mmxfct=jsimd_rgb_gray_convert_mmx;
  208. break;
  209. }
  210. if ((simd_support & JSIMD_SSE2) &&
  211. IS_ALIGNED_SSE(jconst_rgb_gray_convert_sse2))
  212. sse2fct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
  213. else if (simd_support & JSIMD_MMX)
  214. mmxfct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
  215. }
  216. GLOBAL(void)
  217. jsimd_ycc_rgb_convert (j_decompress_ptr cinfo,
  218. JSAMPIMAGE input_buf, JDIMENSION input_row,
  219. JSAMPARRAY output_buf, int num_rows)
  220. {
  221. void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
  222. void (*mmxfct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
  223. switch(cinfo->out_color_space) {
  224. case JCS_EXT_RGB:
  225. sse2fct=jsimd_ycc_extrgb_convert_sse2;
  226. mmxfct=jsimd_ycc_extrgb_convert_mmx;
  227. break;
  228. case JCS_EXT_RGBX:
  229. case JCS_EXT_RGBA:
  230. sse2fct=jsimd_ycc_extrgbx_convert_sse2;
  231. mmxfct=jsimd_ycc_extrgbx_convert_mmx;
  232. break;
  233. case JCS_EXT_BGR:
  234. sse2fct=jsimd_ycc_extbgr_convert_sse2;
  235. mmxfct=jsimd_ycc_extbgr_convert_mmx;
  236. break;
  237. case JCS_EXT_BGRX:
  238. case JCS_EXT_BGRA:
  239. sse2fct=jsimd_ycc_extbgrx_convert_sse2;
  240. mmxfct=jsimd_ycc_extbgrx_convert_mmx;
  241. break;
  242. case JCS_EXT_XBGR:
  243. case JCS_EXT_ABGR:
  244. sse2fct=jsimd_ycc_extxbgr_convert_sse2;
  245. mmxfct=jsimd_ycc_extxbgr_convert_mmx;
  246. break;
  247. case JCS_EXT_XRGB:
  248. case JCS_EXT_ARGB:
  249. sse2fct=jsimd_ycc_extxrgb_convert_sse2;
  250. mmxfct=jsimd_ycc_extxrgb_convert_mmx;
  251. break;
  252. default:
  253. sse2fct=jsimd_ycc_rgb_convert_sse2;
  254. mmxfct=jsimd_ycc_rgb_convert_mmx;
  255. break;
  256. }
  257. if ((simd_support & JSIMD_SSE2) &&
  258. IS_ALIGNED_SSE(jconst_ycc_rgb_convert_sse2))
  259. sse2fct(cinfo->output_width, input_buf, input_row, output_buf, num_rows);
  260. else if (simd_support & JSIMD_MMX)
  261. mmxfct(cinfo->output_width, input_buf, input_row, output_buf, num_rows);
  262. }
  263. GLOBAL(void)
  264. jsimd_ycc_rgb565_convert (j_decompress_ptr cinfo,
  265. JSAMPIMAGE input_buf, JDIMENSION input_row,
  266. JSAMPARRAY output_buf, int num_rows)
  267. {
  268. }
  269. GLOBAL(int)
  270. jsimd_can_h2v2_downsample (void)
  271. {
  272. init_simd();
  273. /* The code is optimised for these values only */
  274. if (BITS_IN_JSAMPLE != 8)
  275. return 0;
  276. if (sizeof(JDIMENSION) != 4)
  277. return 0;
  278. if (simd_support & JSIMD_SSE2)
  279. return 1;
  280. if (simd_support & JSIMD_MMX)
  281. return 1;
  282. return 0;
  283. }
  284. GLOBAL(int)
  285. jsimd_can_h2v1_downsample (void)
  286. {
  287. init_simd();
  288. /* The code is optimised for these values only */
  289. if (BITS_IN_JSAMPLE != 8)
  290. return 0;
  291. if (sizeof(JDIMENSION) != 4)
  292. return 0;
  293. if (simd_support & JSIMD_SSE2)
  294. return 1;
  295. if (simd_support & JSIMD_MMX)
  296. return 1;
  297. return 0;
  298. }
  299. GLOBAL(void)
  300. jsimd_h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  301. JSAMPARRAY input_data, JSAMPARRAY output_data)
  302. {
  303. if (simd_support & JSIMD_SSE2)
  304. jsimd_h2v2_downsample_sse2(cinfo->image_width, cinfo->max_v_samp_factor,
  305. compptr->v_samp_factor,
  306. compptr->width_in_blocks, input_data,
  307. output_data);
  308. else if (simd_support & JSIMD_MMX)
  309. jsimd_h2v2_downsample_mmx(cinfo->image_width, cinfo->max_v_samp_factor,
  310. compptr->v_samp_factor, compptr->width_in_blocks,
  311. input_data, output_data);
  312. }
  313. GLOBAL(void)
  314. jsimd_h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  315. JSAMPARRAY input_data, JSAMPARRAY output_data)
  316. {
  317. if (simd_support & JSIMD_SSE2)
  318. jsimd_h2v1_downsample_sse2(cinfo->image_width, cinfo->max_v_samp_factor,
  319. compptr->v_samp_factor,
  320. compptr->width_in_blocks, input_data,
  321. output_data);
  322. else if (simd_support & JSIMD_MMX)
  323. jsimd_h2v1_downsample_mmx(cinfo->image_width, cinfo->max_v_samp_factor,
  324. compptr->v_samp_factor, compptr->width_in_blocks,
  325. input_data, output_data);
  326. }
  327. GLOBAL(int)
  328. jsimd_can_h2v2_upsample (void)
  329. {
  330. init_simd();
  331. /* The code is optimised for these values only */
  332. if (BITS_IN_JSAMPLE != 8)
  333. return 0;
  334. if (sizeof(JDIMENSION) != 4)
  335. return 0;
  336. if (simd_support & JSIMD_SSE2)
  337. return 1;
  338. if (simd_support & JSIMD_MMX)
  339. return 1;
  340. return 0;
  341. }
  342. GLOBAL(int)
  343. jsimd_can_h2v1_upsample (void)
  344. {
  345. init_simd();
  346. /* The code is optimised for these values only */
  347. if (BITS_IN_JSAMPLE != 8)
  348. return 0;
  349. if (sizeof(JDIMENSION) != 4)
  350. return 0;
  351. if (simd_support & JSIMD_SSE2)
  352. return 1;
  353. if (simd_support & JSIMD_MMX)
  354. return 1;
  355. return 0;
  356. }
  357. GLOBAL(void)
  358. jsimd_h2v2_upsample (j_decompress_ptr cinfo,
  359. jpeg_component_info *compptr,
  360. JSAMPARRAY input_data,
  361. JSAMPARRAY *output_data_ptr)
  362. {
  363. if (simd_support & JSIMD_SSE2)
  364. jsimd_h2v2_upsample_sse2(cinfo->max_v_samp_factor, cinfo->output_width,
  365. input_data, output_data_ptr);
  366. else if (simd_support & JSIMD_MMX)
  367. jsimd_h2v2_upsample_mmx(cinfo->max_v_samp_factor, cinfo->output_width,
  368. input_data, output_data_ptr);
  369. }
  370. GLOBAL(void)
  371. jsimd_h2v1_upsample (j_decompress_ptr cinfo,
  372. jpeg_component_info *compptr,
  373. JSAMPARRAY input_data,
  374. JSAMPARRAY *output_data_ptr)
  375. {
  376. if (simd_support & JSIMD_SSE2)
  377. jsimd_h2v1_upsample_sse2(cinfo->max_v_samp_factor, cinfo->output_width,
  378. input_data, output_data_ptr);
  379. else if (simd_support & JSIMD_MMX)
  380. jsimd_h2v1_upsample_mmx(cinfo->max_v_samp_factor, cinfo->output_width,
  381. input_data, output_data_ptr);
  382. }
  383. GLOBAL(int)
  384. jsimd_can_h2v2_fancy_upsample (void)
  385. {
  386. init_simd();
  387. /* The code is optimised for these values only */
  388. if (BITS_IN_JSAMPLE != 8)
  389. return 0;
  390. if (sizeof(JDIMENSION) != 4)
  391. return 0;
  392. if ((simd_support & JSIMD_SSE2) &&
  393. IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
  394. return 1;
  395. if (simd_support & JSIMD_MMX)
  396. return 1;
  397. return 0;
  398. }
  399. GLOBAL(int)
  400. jsimd_can_h2v1_fancy_upsample (void)
  401. {
  402. init_simd();
  403. /* The code is optimised for these values only */
  404. if (BITS_IN_JSAMPLE != 8)
  405. return 0;
  406. if (sizeof(JDIMENSION) != 4)
  407. return 0;
  408. if ((simd_support & JSIMD_SSE2) &&
  409. IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
  410. return 1;
  411. if (simd_support & JSIMD_MMX)
  412. return 1;
  413. return 0;
  414. }
  415. GLOBAL(void)
  416. jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo,
  417. jpeg_component_info *compptr,
  418. JSAMPARRAY input_data,
  419. JSAMPARRAY *output_data_ptr)
  420. {
  421. if ((simd_support & JSIMD_SSE2) &&
  422. IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
  423. jsimd_h2v2_fancy_upsample_sse2(cinfo->max_v_samp_factor,
  424. compptr->downsampled_width, input_data,
  425. output_data_ptr);
  426. else if (simd_support & JSIMD_MMX)
  427. jsimd_h2v2_fancy_upsample_mmx(cinfo->max_v_samp_factor,
  428. compptr->downsampled_width, input_data,
  429. output_data_ptr);
  430. }
  431. GLOBAL(void)
  432. jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo,
  433. jpeg_component_info *compptr,
  434. JSAMPARRAY input_data,
  435. JSAMPARRAY *output_data_ptr)
  436. {
  437. if ((simd_support & JSIMD_SSE2) &&
  438. IS_ALIGNED_SSE(jconst_fancy_upsample_sse2))
  439. jsimd_h2v1_fancy_upsample_sse2(cinfo->max_v_samp_factor,
  440. compptr->downsampled_width, input_data,
  441. output_data_ptr);
  442. else if (simd_support & JSIMD_MMX)
  443. jsimd_h2v1_fancy_upsample_mmx(cinfo->max_v_samp_factor,
  444. compptr->downsampled_width, input_data,
  445. output_data_ptr);
  446. }
  447. GLOBAL(int)
  448. jsimd_can_h2v2_merged_upsample (void)
  449. {
  450. init_simd();
  451. /* The code is optimised for these values only */
  452. if (BITS_IN_JSAMPLE != 8)
  453. return 0;
  454. if (sizeof(JDIMENSION) != 4)
  455. return 0;
  456. if ((simd_support & JSIMD_SSE2) &&
  457. IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
  458. return 1;
  459. if (simd_support & JSIMD_MMX)
  460. return 1;
  461. return 0;
  462. }
  463. GLOBAL(int)
  464. jsimd_can_h2v1_merged_upsample (void)
  465. {
  466. init_simd();
  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. if ((simd_support & JSIMD_SSE2) &&
  473. IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
  474. return 1;
  475. if (simd_support & JSIMD_MMX)
  476. return 1;
  477. return 0;
  478. }
  479. GLOBAL(void)
  480. jsimd_h2v2_merged_upsample (j_decompress_ptr cinfo,
  481. JSAMPIMAGE input_buf,
  482. JDIMENSION in_row_group_ctr,
  483. JSAMPARRAY output_buf)
  484. {
  485. void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
  486. void (*mmxfct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
  487. switch(cinfo->out_color_space) {
  488. case JCS_EXT_RGB:
  489. sse2fct=jsimd_h2v2_extrgb_merged_upsample_sse2;
  490. mmxfct=jsimd_h2v2_extrgb_merged_upsample_mmx;
  491. break;
  492. case JCS_EXT_RGBX:
  493. case JCS_EXT_RGBA:
  494. sse2fct=jsimd_h2v2_extrgbx_merged_upsample_sse2;
  495. mmxfct=jsimd_h2v2_extrgbx_merged_upsample_mmx;
  496. break;
  497. case JCS_EXT_BGR:
  498. sse2fct=jsimd_h2v2_extbgr_merged_upsample_sse2;
  499. mmxfct=jsimd_h2v2_extbgr_merged_upsample_mmx;
  500. break;
  501. case JCS_EXT_BGRX:
  502. case JCS_EXT_BGRA:
  503. sse2fct=jsimd_h2v2_extbgrx_merged_upsample_sse2;
  504. mmxfct=jsimd_h2v2_extbgrx_merged_upsample_mmx;
  505. break;
  506. case JCS_EXT_XBGR:
  507. case JCS_EXT_ABGR:
  508. sse2fct=jsimd_h2v2_extxbgr_merged_upsample_sse2;
  509. mmxfct=jsimd_h2v2_extxbgr_merged_upsample_mmx;
  510. break;
  511. case JCS_EXT_XRGB:
  512. case JCS_EXT_ARGB:
  513. sse2fct=jsimd_h2v2_extxrgb_merged_upsample_sse2;
  514. mmxfct=jsimd_h2v2_extxrgb_merged_upsample_mmx;
  515. break;
  516. default:
  517. sse2fct=jsimd_h2v2_merged_upsample_sse2;
  518. mmxfct=jsimd_h2v2_merged_upsample_mmx;
  519. break;
  520. }
  521. if ((simd_support & JSIMD_SSE2) &&
  522. IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
  523. sse2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
  524. else if (simd_support & JSIMD_MMX)
  525. mmxfct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
  526. }
  527. GLOBAL(void)
  528. jsimd_h2v1_merged_upsample (j_decompress_ptr cinfo,
  529. JSAMPIMAGE input_buf,
  530. JDIMENSION in_row_group_ctr,
  531. JSAMPARRAY output_buf)
  532. {
  533. void (*sse2fct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
  534. void (*mmxfct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
  535. switch(cinfo->out_color_space) {
  536. case JCS_EXT_RGB:
  537. sse2fct=jsimd_h2v1_extrgb_merged_upsample_sse2;
  538. mmxfct=jsimd_h2v1_extrgb_merged_upsample_mmx;
  539. break;
  540. case JCS_EXT_RGBX:
  541. case JCS_EXT_RGBA:
  542. sse2fct=jsimd_h2v1_extrgbx_merged_upsample_sse2;
  543. mmxfct=jsimd_h2v1_extrgbx_merged_upsample_mmx;
  544. break;
  545. case JCS_EXT_BGR:
  546. sse2fct=jsimd_h2v1_extbgr_merged_upsample_sse2;
  547. mmxfct=jsimd_h2v1_extbgr_merged_upsample_mmx;
  548. break;
  549. case JCS_EXT_BGRX:
  550. case JCS_EXT_BGRA:
  551. sse2fct=jsimd_h2v1_extbgrx_merged_upsample_sse2;
  552. mmxfct=jsimd_h2v1_extbgrx_merged_upsample_mmx;
  553. break;
  554. case JCS_EXT_XBGR:
  555. case JCS_EXT_ABGR:
  556. sse2fct=jsimd_h2v1_extxbgr_merged_upsample_sse2;
  557. mmxfct=jsimd_h2v1_extxbgr_merged_upsample_mmx;
  558. break;
  559. case JCS_EXT_XRGB:
  560. case JCS_EXT_ARGB:
  561. sse2fct=jsimd_h2v1_extxrgb_merged_upsample_sse2;
  562. mmxfct=jsimd_h2v1_extxrgb_merged_upsample_mmx;
  563. break;
  564. default:
  565. sse2fct=jsimd_h2v1_merged_upsample_sse2;
  566. mmxfct=jsimd_h2v1_merged_upsample_mmx;
  567. break;
  568. }
  569. if ((simd_support & JSIMD_SSE2) &&
  570. IS_ALIGNED_SSE(jconst_merged_upsample_sse2))
  571. sse2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
  572. else if (simd_support & JSIMD_MMX)
  573. mmxfct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
  574. }
  575. GLOBAL(int)
  576. jsimd_can_convsamp (void)
  577. {
  578. init_simd();
  579. /* The code is optimised for these values only */
  580. if (DCTSIZE != 8)
  581. return 0;
  582. if (BITS_IN_JSAMPLE != 8)
  583. return 0;
  584. if (sizeof(JDIMENSION) != 4)
  585. return 0;
  586. if (sizeof(DCTELEM) != 2)
  587. return 0;
  588. if (simd_support & JSIMD_SSE2)
  589. return 1;
  590. if (simd_support & JSIMD_MMX)
  591. return 1;
  592. return 0;
  593. }
  594. GLOBAL(int)
  595. jsimd_can_convsamp_float (void)
  596. {
  597. init_simd();
  598. /* The code is optimised for these values only */
  599. if (DCTSIZE != 8)
  600. return 0;
  601. if (BITS_IN_JSAMPLE != 8)
  602. return 0;
  603. if (sizeof(JDIMENSION) != 4)
  604. return 0;
  605. if (sizeof(FAST_FLOAT) != 4)
  606. return 0;
  607. if (simd_support & JSIMD_SSE2)
  608. return 1;
  609. if (simd_support & JSIMD_SSE)
  610. return 1;
  611. if (simd_support & JSIMD_3DNOW)
  612. return 1;
  613. return 0;
  614. }
  615. GLOBAL(void)
  616. jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col,
  617. DCTELEM *workspace)
  618. {
  619. if (simd_support & JSIMD_SSE2)
  620. jsimd_convsamp_sse2(sample_data, start_col, workspace);
  621. else if (simd_support & JSIMD_MMX)
  622. jsimd_convsamp_mmx(sample_data, start_col, workspace);
  623. }
  624. GLOBAL(void)
  625. jsimd_convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col,
  626. FAST_FLOAT *workspace)
  627. {
  628. if (simd_support & JSIMD_SSE2)
  629. jsimd_convsamp_float_sse2(sample_data, start_col, workspace);
  630. else if (simd_support & JSIMD_SSE)
  631. jsimd_convsamp_float_sse(sample_data, start_col, workspace);
  632. else if (simd_support & JSIMD_3DNOW)
  633. jsimd_convsamp_float_3dnow(sample_data, start_col, workspace);
  634. }
  635. GLOBAL(int)
  636. jsimd_can_fdct_islow (void)
  637. {
  638. init_simd();
  639. /* The code is optimised for these values only */
  640. if (DCTSIZE != 8)
  641. return 0;
  642. if (sizeof(DCTELEM) != 2)
  643. return 0;
  644. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_islow_sse2))
  645. return 1;
  646. if (simd_support & JSIMD_MMX)
  647. return 1;
  648. return 0;
  649. }
  650. GLOBAL(int)
  651. jsimd_can_fdct_ifast (void)
  652. {
  653. init_simd();
  654. /* The code is optimised for these values only */
  655. if (DCTSIZE != 8)
  656. return 0;
  657. if (sizeof(DCTELEM) != 2)
  658. return 0;
  659. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_ifast_sse2))
  660. return 1;
  661. if (simd_support & JSIMD_MMX)
  662. return 1;
  663. return 0;
  664. }
  665. GLOBAL(int)
  666. jsimd_can_fdct_float (void)
  667. {
  668. init_simd();
  669. /* The code is optimised for these values only */
  670. if (DCTSIZE != 8)
  671. return 0;
  672. if (sizeof(FAST_FLOAT) != 4)
  673. return 0;
  674. if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_fdct_float_sse))
  675. return 1;
  676. if (simd_support & JSIMD_3DNOW)
  677. return 1;
  678. return 0;
  679. }
  680. GLOBAL(void)
  681. jsimd_fdct_islow (DCTELEM *data)
  682. {
  683. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_islow_sse2))
  684. jsimd_fdct_islow_sse2(data);
  685. else if (simd_support & JSIMD_MMX)
  686. jsimd_fdct_islow_mmx(data);
  687. }
  688. GLOBAL(void)
  689. jsimd_fdct_ifast (DCTELEM *data)
  690. {
  691. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_fdct_islow_sse2))
  692. jsimd_fdct_ifast_sse2(data);
  693. else if (simd_support & JSIMD_MMX)
  694. jsimd_fdct_ifast_mmx(data);
  695. }
  696. GLOBAL(void)
  697. jsimd_fdct_float (FAST_FLOAT *data)
  698. {
  699. if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_fdct_float_sse))
  700. jsimd_fdct_float_sse(data);
  701. else if (simd_support & JSIMD_3DNOW)
  702. jsimd_fdct_float_3dnow(data);
  703. }
  704. GLOBAL(int)
  705. jsimd_can_quantize (void)
  706. {
  707. init_simd();
  708. /* The code is optimised for these values only */
  709. if (DCTSIZE != 8)
  710. return 0;
  711. if (sizeof(JCOEF) != 2)
  712. return 0;
  713. if (sizeof(DCTELEM) != 2)
  714. return 0;
  715. if (simd_support & JSIMD_SSE2)
  716. return 1;
  717. if (simd_support & JSIMD_MMX)
  718. return 1;
  719. return 0;
  720. }
  721. GLOBAL(int)
  722. jsimd_can_quantize_float (void)
  723. {
  724. init_simd();
  725. /* The code is optimised for these values only */
  726. if (DCTSIZE != 8)
  727. return 0;
  728. if (sizeof(JCOEF) != 2)
  729. return 0;
  730. if (sizeof(FAST_FLOAT) != 4)
  731. return 0;
  732. if (simd_support & JSIMD_SSE2)
  733. return 1;
  734. if (simd_support & JSIMD_SSE)
  735. return 1;
  736. if (simd_support & JSIMD_3DNOW)
  737. return 1;
  738. return 0;
  739. }
  740. GLOBAL(void)
  741. jsimd_quantize (JCOEFPTR coef_block, DCTELEM *divisors,
  742. DCTELEM *workspace)
  743. {
  744. if (simd_support & JSIMD_SSE2)
  745. jsimd_quantize_sse2(coef_block, divisors, workspace);
  746. else if (simd_support & JSIMD_MMX)
  747. jsimd_quantize_mmx(coef_block, divisors, workspace);
  748. }
  749. GLOBAL(void)
  750. jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT *divisors,
  751. FAST_FLOAT *workspace)
  752. {
  753. if (simd_support & JSIMD_SSE2)
  754. jsimd_quantize_float_sse2(coef_block, divisors, workspace);
  755. else if (simd_support & JSIMD_SSE)
  756. jsimd_quantize_float_sse(coef_block, divisors, workspace);
  757. else if (simd_support & JSIMD_3DNOW)
  758. jsimd_quantize_float_3dnow(coef_block, divisors, workspace);
  759. }
  760. GLOBAL(int)
  761. jsimd_can_idct_2x2 (void)
  762. {
  763. init_simd();
  764. /* The code is optimised for these values only */
  765. if (DCTSIZE != 8)
  766. return 0;
  767. if (sizeof(JCOEF) != 2)
  768. return 0;
  769. if (BITS_IN_JSAMPLE != 8)
  770. return 0;
  771. if (sizeof(JDIMENSION) != 4)
  772. return 0;
  773. if (sizeof(ISLOW_MULT_TYPE) != 2)
  774. return 0;
  775. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2))
  776. return 1;
  777. if (simd_support & JSIMD_MMX)
  778. return 1;
  779. return 0;
  780. }
  781. GLOBAL(int)
  782. jsimd_can_idct_4x4 (void)
  783. {
  784. init_simd();
  785. /* The code is optimised for these values only */
  786. if (DCTSIZE != 8)
  787. return 0;
  788. if (sizeof(JCOEF) != 2)
  789. return 0;
  790. if (BITS_IN_JSAMPLE != 8)
  791. return 0;
  792. if (sizeof(JDIMENSION) != 4)
  793. return 0;
  794. if (sizeof(ISLOW_MULT_TYPE) != 2)
  795. return 0;
  796. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2))
  797. return 1;
  798. if (simd_support & JSIMD_MMX)
  799. return 1;
  800. return 0;
  801. }
  802. GLOBAL(void)
  803. jsimd_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info *compptr,
  804. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  805. JDIMENSION output_col)
  806. {
  807. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2))
  808. jsimd_idct_2x2_sse2(compptr->dct_table, coef_block, output_buf,
  809. output_col);
  810. else if (simd_support & JSIMD_MMX)
  811. jsimd_idct_2x2_mmx(compptr->dct_table, coef_block, output_buf, output_col);
  812. }
  813. GLOBAL(void)
  814. jsimd_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info *compptr,
  815. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  816. JDIMENSION output_col)
  817. {
  818. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_red_sse2))
  819. jsimd_idct_4x4_sse2(compptr->dct_table, coef_block, output_buf,
  820. output_col);
  821. else if (simd_support & JSIMD_MMX)
  822. jsimd_idct_4x4_mmx(compptr->dct_table, coef_block, output_buf, output_col);
  823. }
  824. GLOBAL(int)
  825. jsimd_can_idct_islow (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 (BITS_IN_JSAMPLE != 8)
  834. return 0;
  835. if (sizeof(JDIMENSION) != 4)
  836. return 0;
  837. if (sizeof(ISLOW_MULT_TYPE) != 2)
  838. return 0;
  839. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_islow_sse2))
  840. return 1;
  841. if (simd_support & JSIMD_MMX)
  842. return 1;
  843. return 0;
  844. }
  845. GLOBAL(int)
  846. jsimd_can_idct_ifast (void)
  847. {
  848. init_simd();
  849. /* The code is optimised for these values only */
  850. if (DCTSIZE != 8)
  851. return 0;
  852. if (sizeof(JCOEF) != 2)
  853. return 0;
  854. if (BITS_IN_JSAMPLE != 8)
  855. return 0;
  856. if (sizeof(JDIMENSION) != 4)
  857. return 0;
  858. if (sizeof(IFAST_MULT_TYPE) != 2)
  859. return 0;
  860. if (IFAST_SCALE_BITS != 2)
  861. return 0;
  862. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_ifast_sse2))
  863. return 1;
  864. if (simd_support & JSIMD_MMX)
  865. return 1;
  866. return 0;
  867. }
  868. GLOBAL(int)
  869. jsimd_can_idct_float (void)
  870. {
  871. init_simd();
  872. if (DCTSIZE != 8)
  873. return 0;
  874. if (sizeof(JCOEF) != 2)
  875. return 0;
  876. if (BITS_IN_JSAMPLE != 8)
  877. return 0;
  878. if (sizeof(JDIMENSION) != 4)
  879. return 0;
  880. if (sizeof(FAST_FLOAT) != 4)
  881. return 0;
  882. if (sizeof(FLOAT_MULT_TYPE) != 4)
  883. return 0;
  884. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_float_sse2))
  885. return 1;
  886. if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_idct_float_sse))
  887. return 1;
  888. if (simd_support & JSIMD_3DNOW)
  889. return 1;
  890. return 0;
  891. }
  892. GLOBAL(void)
  893. jsimd_idct_islow (j_decompress_ptr cinfo, jpeg_component_info *compptr,
  894. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  895. JDIMENSION output_col)
  896. {
  897. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_islow_sse2))
  898. jsimd_idct_islow_sse2(compptr->dct_table, coef_block, output_buf,
  899. output_col);
  900. else if (simd_support & JSIMD_MMX)
  901. jsimd_idct_islow_mmx(compptr->dct_table, coef_block, output_buf,
  902. output_col);
  903. }
  904. GLOBAL(void)
  905. jsimd_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info *compptr,
  906. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  907. JDIMENSION output_col)
  908. {
  909. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_ifast_sse2))
  910. jsimd_idct_ifast_sse2(compptr->dct_table, coef_block, output_buf,
  911. output_col);
  912. else if (simd_support & JSIMD_MMX)
  913. jsimd_idct_ifast_mmx(compptr->dct_table, coef_block, output_buf,
  914. output_col);
  915. }
  916. GLOBAL(void)
  917. jsimd_idct_float (j_decompress_ptr cinfo, jpeg_component_info *compptr,
  918. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  919. JDIMENSION output_col)
  920. {
  921. if ((simd_support & JSIMD_SSE2) && IS_ALIGNED_SSE(jconst_idct_float_sse2))
  922. jsimd_idct_float_sse2(compptr->dct_table, coef_block, output_buf,
  923. output_col);
  924. else if ((simd_support & JSIMD_SSE) && IS_ALIGNED_SSE(jconst_idct_float_sse))
  925. jsimd_idct_float_sse(compptr->dct_table, coef_block, output_buf,
  926. output_col);
  927. else if (simd_support & JSIMD_3DNOW)
  928. jsimd_idct_float_3dnow(compptr->dct_table, coef_block, output_buf,
  929. output_col);
  930. }
  931. GLOBAL(int)
  932. jsimd_can_huff_encode_one_block (void)
  933. {
  934. init_simd();
  935. if (DCTSIZE != 8)
  936. return 0;
  937. if (sizeof(JCOEF) != 2)
  938. return 0;
  939. if ((simd_support & JSIMD_SSE2) && simd_huffman &&
  940. IS_ALIGNED_SSE(jconst_huff_encode_one_block))
  941. return 1;
  942. return 0;
  943. }
  944. GLOBAL(JOCTET*)
  945. jsimd_huff_encode_one_block (void *state, JOCTET *buffer, JCOEFPTR block,
  946. int last_dc_val, c_derived_tbl *dctbl,
  947. c_derived_tbl *actbl)
  948. {
  949. return jsimd_huff_encode_one_block_sse2(state, buffer, block, last_dc_val,
  950. dctbl, actbl);
  951. }