jsimd.c 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142
  1. /*
  2. * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
  3. * Copyright (C) 2009-2011, 2014, 2016, 2018, 2020, 2022, 2024,
  4. * D. R. Commander.
  5. * Copyright (C) 2013-2014, MIPS Technologies, Inc., California.
  6. * Copyright (C) 2015-2016, 2018, 2022, 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. * MIPS architecture.
  15. */
  16. #define JPEG_INTERNALS
  17. #include "../../src/jinclude.h"
  18. #include "../../src/jpeglib.h"
  19. #include "../../src/jsimd.h"
  20. #include "../../src/jdct.h"
  21. #include "../../src/jsimddct.h"
  22. #include "../jsimd.h"
  23. #include <ctype.h>
  24. static THREAD_LOCAL unsigned int simd_support = ~0;
  25. #if !(defined(__mips_dsp) && (__mips_dsp_rev >= 2)) && defined(__linux__)
  26. LOCAL(void)
  27. parse_proc_cpuinfo(const char *search_string)
  28. {
  29. const char *file_name = "/proc/cpuinfo";
  30. char cpuinfo_line[256];
  31. FILE *f = NULL;
  32. simd_support = 0;
  33. if ((f = fopen(file_name, "r")) != NULL) {
  34. while (fgets(cpuinfo_line, sizeof(cpuinfo_line), f) != NULL) {
  35. if (strstr(cpuinfo_line, search_string) != NULL) {
  36. fclose(f);
  37. simd_support |= JSIMD_DSPR2;
  38. return;
  39. }
  40. }
  41. fclose(f);
  42. }
  43. /* Did not find string in the proc file, or not Linux ELF. */
  44. }
  45. #endif
  46. /*
  47. * Check what SIMD accelerations are supported.
  48. */
  49. LOCAL(void)
  50. init_simd(void)
  51. {
  52. #ifndef NO_GETENV
  53. char *env = NULL;
  54. #endif
  55. if (simd_support != ~0U)
  56. return;
  57. simd_support = 0;
  58. #if defined(__mips_dsp) && (__mips_dsp_rev >= 2)
  59. simd_support |= JSIMD_DSPR2;
  60. #elif defined(__linux__)
  61. /* We still have a chance to use MIPS DSPR2 regardless of globally used
  62. * -mdspr2 options passed to gcc by performing runtime detection via
  63. * /proc/cpuinfo parsing on linux */
  64. parse_proc_cpuinfo("MIPS 74K");
  65. #endif
  66. #ifndef NO_GETENV
  67. /* Force different settings through environment variables */
  68. env = getenv("JSIMD_FORCEDSPR2");
  69. if ((env != NULL) && (strcmp(env, "1") == 0))
  70. simd_support = JSIMD_DSPR2;
  71. env = getenv("JSIMD_FORCENONE");
  72. if ((env != NULL) && (strcmp(env, "1") == 0))
  73. simd_support = 0;
  74. #endif
  75. }
  76. static const int mips_idct_ifast_coefs[4] = {
  77. 0x45404540, /* FIX( 1.082392200 / 2) = 17734 = 0x4546 */
  78. 0x5A805A80, /* FIX( 1.414213562 / 2) = 23170 = 0x5A82 */
  79. 0x76407640, /* FIX( 1.847759065 / 2) = 30274 = 0x7642 */
  80. 0xAC60AC60 /* FIX(-2.613125930 / 4) = -21407 = 0xAC61 */
  81. };
  82. /* The following struct is borrowed from jdsample.c */
  83. typedef void (*upsample1_ptr) (j_decompress_ptr cinfo,
  84. jpeg_component_info *compptr,
  85. JSAMPARRAY input_data,
  86. JSAMPARRAY *output_data_ptr);
  87. typedef struct {
  88. struct jpeg_upsampler pub;
  89. JSAMPARRAY color_buf[MAX_COMPONENTS];
  90. upsample1_ptr methods[MAX_COMPONENTS];
  91. int next_row_out;
  92. JDIMENSION rows_to_go;
  93. int rowgroup_height[MAX_COMPONENTS];
  94. UINT8 h_expand[MAX_COMPONENTS];
  95. UINT8 v_expand[MAX_COMPONENTS];
  96. } my_upsampler;
  97. typedef my_upsampler *my_upsample_ptr;
  98. GLOBAL(int)
  99. jsimd_can_rgb_ycc(void)
  100. {
  101. init_simd();
  102. /* The code is optimised for these values only */
  103. if (BITS_IN_JSAMPLE != 8)
  104. return 0;
  105. if (sizeof(JDIMENSION) != 4)
  106. return 0;
  107. if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
  108. return 0;
  109. if (simd_support & JSIMD_DSPR2)
  110. return 1;
  111. return 0;
  112. }
  113. GLOBAL(int)
  114. jsimd_can_rgb_gray(void)
  115. {
  116. init_simd();
  117. /* The code is optimised for these values only */
  118. if (BITS_IN_JSAMPLE != 8)
  119. return 0;
  120. if (sizeof(JDIMENSION) != 4)
  121. return 0;
  122. if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
  123. return 0;
  124. if (simd_support & JSIMD_DSPR2)
  125. return 1;
  126. return 0;
  127. }
  128. GLOBAL(int)
  129. jsimd_can_ycc_rgb(void)
  130. {
  131. init_simd();
  132. /* The code is optimised for these values only */
  133. if (BITS_IN_JSAMPLE != 8)
  134. return 0;
  135. if (sizeof(JDIMENSION) != 4)
  136. return 0;
  137. if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
  138. return 0;
  139. if (simd_support & JSIMD_DSPR2)
  140. return 1;
  141. return 0;
  142. }
  143. GLOBAL(int)
  144. jsimd_can_ycc_rgb565(void)
  145. {
  146. return 0;
  147. }
  148. GLOBAL(int)
  149. jsimd_c_can_null_convert(void)
  150. {
  151. init_simd();
  152. /* The code is optimised for these values only */
  153. if (BITS_IN_JSAMPLE != 8)
  154. return 0;
  155. if (sizeof(JDIMENSION) != 4)
  156. return 0;
  157. if (simd_support & JSIMD_DSPR2)
  158. return 1;
  159. return 0;
  160. }
  161. GLOBAL(void)
  162. jsimd_rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
  163. JSAMPIMAGE output_buf, JDIMENSION output_row,
  164. int num_rows)
  165. {
  166. void (*dspr2fct) (JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
  167. switch (cinfo->in_color_space) {
  168. case JCS_EXT_RGB:
  169. dspr2fct = jsimd_extrgb_ycc_convert_dspr2;
  170. break;
  171. case JCS_EXT_RGBX:
  172. case JCS_EXT_RGBA:
  173. dspr2fct = jsimd_extrgbx_ycc_convert_dspr2;
  174. break;
  175. case JCS_EXT_BGR:
  176. dspr2fct = jsimd_extbgr_ycc_convert_dspr2;
  177. break;
  178. case JCS_EXT_BGRX:
  179. case JCS_EXT_BGRA:
  180. dspr2fct = jsimd_extbgrx_ycc_convert_dspr2;
  181. break;
  182. case JCS_EXT_XBGR:
  183. case JCS_EXT_ABGR:
  184. dspr2fct = jsimd_extxbgr_ycc_convert_dspr2;
  185. break;
  186. case JCS_EXT_XRGB:
  187. case JCS_EXT_ARGB:
  188. dspr2fct = jsimd_extxrgb_ycc_convert_dspr2;
  189. break;
  190. default:
  191. dspr2fct = jsimd_extrgb_ycc_convert_dspr2;
  192. break;
  193. }
  194. dspr2fct(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 (*dspr2fct) (JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
  202. switch (cinfo->in_color_space) {
  203. case JCS_EXT_RGB:
  204. dspr2fct = jsimd_extrgb_gray_convert_dspr2;
  205. break;
  206. case JCS_EXT_RGBX:
  207. case JCS_EXT_RGBA:
  208. dspr2fct = jsimd_extrgbx_gray_convert_dspr2;
  209. break;
  210. case JCS_EXT_BGR:
  211. dspr2fct = jsimd_extbgr_gray_convert_dspr2;
  212. break;
  213. case JCS_EXT_BGRX:
  214. case JCS_EXT_BGRA:
  215. dspr2fct = jsimd_extbgrx_gray_convert_dspr2;
  216. break;
  217. case JCS_EXT_XBGR:
  218. case JCS_EXT_ABGR:
  219. dspr2fct = jsimd_extxbgr_gray_convert_dspr2;
  220. break;
  221. case JCS_EXT_XRGB:
  222. case JCS_EXT_ARGB:
  223. dspr2fct = jsimd_extxrgb_gray_convert_dspr2;
  224. break;
  225. default:
  226. dspr2fct = jsimd_extrgb_gray_convert_dspr2;
  227. break;
  228. }
  229. dspr2fct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
  230. }
  231. GLOBAL(void)
  232. jsimd_ycc_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  233. JDIMENSION input_row, JSAMPARRAY output_buf,
  234. int num_rows)
  235. {
  236. void (*dspr2fct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
  237. switch (cinfo->out_color_space) {
  238. case JCS_EXT_RGB:
  239. dspr2fct = jsimd_ycc_extrgb_convert_dspr2;
  240. break;
  241. case JCS_EXT_RGBX:
  242. case JCS_EXT_RGBA:
  243. dspr2fct = jsimd_ycc_extrgbx_convert_dspr2;
  244. break;
  245. case JCS_EXT_BGR:
  246. dspr2fct = jsimd_ycc_extbgr_convert_dspr2;
  247. break;
  248. case JCS_EXT_BGRX:
  249. case JCS_EXT_BGRA:
  250. dspr2fct = jsimd_ycc_extbgrx_convert_dspr2;
  251. break;
  252. case JCS_EXT_XBGR:
  253. case JCS_EXT_ABGR:
  254. dspr2fct = jsimd_ycc_extxbgr_convert_dspr2;
  255. break;
  256. case JCS_EXT_XRGB:
  257. case JCS_EXT_ARGB:
  258. dspr2fct = jsimd_ycc_extxrgb_convert_dspr2;
  259. break;
  260. default:
  261. dspr2fct = jsimd_ycc_extrgb_convert_dspr2;
  262. break;
  263. }
  264. dspr2fct(cinfo->output_width, input_buf, input_row, output_buf, num_rows);
  265. }
  266. GLOBAL(void)
  267. jsimd_ycc_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  268. JDIMENSION input_row, JSAMPARRAY output_buf,
  269. int num_rows)
  270. {
  271. }
  272. GLOBAL(void)
  273. jsimd_c_null_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
  274. JSAMPIMAGE output_buf, JDIMENSION output_row,
  275. int num_rows)
  276. {
  277. jsimd_c_null_convert_dspr2(cinfo->image_width, input_buf, output_buf,
  278. output_row, num_rows, cinfo->num_components);
  279. }
  280. GLOBAL(int)
  281. jsimd_can_h2v2_downsample(void)
  282. {
  283. init_simd();
  284. /* The code is optimised for these values only */
  285. if (BITS_IN_JSAMPLE != 8)
  286. return 0;
  287. if (sizeof(JDIMENSION) != 4)
  288. return 0;
  289. /* FIXME: jsimd_h2v2_downsample_dspr2() fails some of the TJBench tiling
  290. * regression tests, probably because the DSPr2 SIMD implementation predates
  291. * those tests. */
  292. #if 0
  293. if (simd_support & JSIMD_DSPR2)
  294. return 1;
  295. #endif
  296. return 0;
  297. }
  298. GLOBAL(int)
  299. jsimd_can_h2v2_smooth_downsample(void)
  300. {
  301. init_simd();
  302. /* The code is optimised for these values only */
  303. if (BITS_IN_JSAMPLE != 8)
  304. return 0;
  305. if (sizeof(JDIMENSION) != 4)
  306. return 0;
  307. if (DCTSIZE != 8)
  308. return 0;
  309. if (simd_support & JSIMD_DSPR2)
  310. return 1;
  311. return 0;
  312. }
  313. GLOBAL(int)
  314. jsimd_can_h2v1_downsample(void)
  315. {
  316. init_simd();
  317. /* The code is optimised for these values only */
  318. if (BITS_IN_JSAMPLE != 8)
  319. return 0;
  320. if (sizeof(JDIMENSION) != 4)
  321. return 0;
  322. /* FIXME: jsimd_h2v1_downsample_dspr2() fails some of the TJBench tiling
  323. * regression tests, probably because the DSPr2 SIMD implementation predates
  324. * those tests. */
  325. #if 0
  326. if (simd_support & JSIMD_DSPR2)
  327. return 1;
  328. #endif
  329. return 0;
  330. }
  331. GLOBAL(void)
  332. jsimd_h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
  333. JSAMPARRAY input_data, JSAMPARRAY output_data)
  334. {
  335. jsimd_h2v2_downsample_dspr2(cinfo->image_width, cinfo->max_v_samp_factor,
  336. compptr->v_samp_factor, compptr->width_in_blocks,
  337. input_data, output_data);
  338. }
  339. GLOBAL(void)
  340. jsimd_h2v2_smooth_downsample(j_compress_ptr cinfo,
  341. jpeg_component_info *compptr,
  342. JSAMPARRAY input_data, JSAMPARRAY output_data)
  343. {
  344. jsimd_h2v2_smooth_downsample_dspr2(input_data, output_data,
  345. compptr->v_samp_factor,
  346. cinfo->max_v_samp_factor,
  347. cinfo->smoothing_factor,
  348. compptr->width_in_blocks,
  349. cinfo->image_width);
  350. }
  351. GLOBAL(void)
  352. jsimd_h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
  353. JSAMPARRAY input_data, JSAMPARRAY output_data)
  354. {
  355. jsimd_h2v1_downsample_dspr2(cinfo->image_width, cinfo->max_v_samp_factor,
  356. compptr->v_samp_factor, compptr->width_in_blocks,
  357. input_data, output_data);
  358. }
  359. GLOBAL(int)
  360. jsimd_can_h2v2_upsample(void)
  361. {
  362. init_simd();
  363. /* The code is optimised for these values only */
  364. if (BITS_IN_JSAMPLE != 8)
  365. return 0;
  366. if (sizeof(JDIMENSION) != 4)
  367. return 0;
  368. if (simd_support & JSIMD_DSPR2)
  369. return 1;
  370. return 0;
  371. }
  372. GLOBAL(int)
  373. jsimd_can_h2v1_upsample(void)
  374. {
  375. init_simd();
  376. /* The code is optimised for these values only */
  377. if (BITS_IN_JSAMPLE != 8)
  378. return 0;
  379. if (sizeof(JDIMENSION) != 4)
  380. return 0;
  381. #if defined(__MIPSEL__)
  382. if (simd_support & JSIMD_DSPR2)
  383. return 1;
  384. #endif
  385. return 0;
  386. }
  387. GLOBAL(int)
  388. jsimd_can_int_upsample(void)
  389. {
  390. init_simd();
  391. /* The code is optimised for these values only */
  392. if (BITS_IN_JSAMPLE != 8)
  393. return 0;
  394. if (sizeof(JDIMENSION) != 4)
  395. return 0;
  396. if (simd_support & JSIMD_DSPR2)
  397. return 1;
  398. return 0;
  399. }
  400. GLOBAL(void)
  401. jsimd_h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  402. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  403. {
  404. jsimd_h2v2_upsample_dspr2(cinfo->max_v_samp_factor, cinfo->output_width,
  405. input_data, output_data_ptr);
  406. }
  407. GLOBAL(void)
  408. jsimd_h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  409. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  410. {
  411. jsimd_h2v1_upsample_dspr2(cinfo->max_v_samp_factor, cinfo->output_width,
  412. input_data, output_data_ptr);
  413. }
  414. GLOBAL(void)
  415. jsimd_int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  416. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  417. {
  418. my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
  419. jsimd_int_upsample_dspr2(upsample->h_expand[compptr->component_index],
  420. upsample->v_expand[compptr->component_index],
  421. input_data, output_data_ptr, cinfo->output_width,
  422. cinfo->max_v_samp_factor);
  423. }
  424. GLOBAL(int)
  425. jsimd_can_h2v2_fancy_upsample(void)
  426. {
  427. init_simd();
  428. /* The code is optimised for these values only */
  429. if (BITS_IN_JSAMPLE != 8)
  430. return 0;
  431. if (sizeof(JDIMENSION) != 4)
  432. return 0;
  433. #if defined(__MIPSEL__)
  434. if (simd_support & JSIMD_DSPR2)
  435. return 1;
  436. #endif
  437. return 0;
  438. }
  439. GLOBAL(int)
  440. jsimd_can_h2v1_fancy_upsample(void)
  441. {
  442. init_simd();
  443. /* The code is optimised for these values only */
  444. if (BITS_IN_JSAMPLE != 8)
  445. return 0;
  446. if (sizeof(JDIMENSION) != 4)
  447. return 0;
  448. #if defined(__MIPSEL__)
  449. if (simd_support & JSIMD_DSPR2)
  450. return 1;
  451. #endif
  452. return 0;
  453. }
  454. GLOBAL(void)
  455. jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  456. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  457. {
  458. jsimd_h2v2_fancy_upsample_dspr2(cinfo->max_v_samp_factor,
  459. compptr->downsampled_width, input_data,
  460. output_data_ptr);
  461. }
  462. GLOBAL(void)
  463. jsimd_h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  464. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  465. {
  466. jsimd_h2v1_fancy_upsample_dspr2(cinfo->max_v_samp_factor,
  467. compptr->downsampled_width, input_data,
  468. output_data_ptr);
  469. }
  470. GLOBAL(int)
  471. jsimd_can_h2v2_merged_upsample(void)
  472. {
  473. init_simd();
  474. /* The code is optimised for these values only */
  475. if (BITS_IN_JSAMPLE != 8)
  476. return 0;
  477. if (sizeof(JDIMENSION) != 4)
  478. return 0;
  479. if (simd_support & JSIMD_DSPR2)
  480. return 1;
  481. return 0;
  482. }
  483. GLOBAL(int)
  484. jsimd_can_h2v1_merged_upsample(void)
  485. {
  486. init_simd();
  487. /* The code is optimised for these values only */
  488. if (BITS_IN_JSAMPLE != 8)
  489. return 0;
  490. if (sizeof(JDIMENSION) != 4)
  491. return 0;
  492. if (simd_support & JSIMD_DSPR2)
  493. return 1;
  494. return 0;
  495. }
  496. GLOBAL(void)
  497. jsimd_h2v2_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  498. JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
  499. {
  500. void (*dspr2fct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, JSAMPLE *);
  501. switch (cinfo->out_color_space) {
  502. case JCS_EXT_RGB:
  503. dspr2fct = jsimd_h2v2_extrgb_merged_upsample_dspr2;
  504. break;
  505. case JCS_EXT_RGBX:
  506. case JCS_EXT_RGBA:
  507. dspr2fct = jsimd_h2v2_extrgbx_merged_upsample_dspr2;
  508. break;
  509. case JCS_EXT_BGR:
  510. dspr2fct = jsimd_h2v2_extbgr_merged_upsample_dspr2;
  511. break;
  512. case JCS_EXT_BGRX:
  513. case JCS_EXT_BGRA:
  514. dspr2fct = jsimd_h2v2_extbgrx_merged_upsample_dspr2;
  515. break;
  516. case JCS_EXT_XBGR:
  517. case JCS_EXT_ABGR:
  518. dspr2fct = jsimd_h2v2_extxbgr_merged_upsample_dspr2;
  519. break;
  520. case JCS_EXT_XRGB:
  521. case JCS_EXT_ARGB:
  522. dspr2fct = jsimd_h2v2_extxrgb_merged_upsample_dspr2;
  523. break;
  524. default:
  525. dspr2fct = jsimd_h2v2_extrgb_merged_upsample_dspr2;
  526. break;
  527. }
  528. dspr2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf,
  529. cinfo->sample_range_limit);
  530. }
  531. GLOBAL(void)
  532. jsimd_h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  533. JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
  534. {
  535. void (*dspr2fct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, JSAMPLE *);
  536. switch (cinfo->out_color_space) {
  537. case JCS_EXT_RGB:
  538. dspr2fct = jsimd_h2v1_extrgb_merged_upsample_dspr2;
  539. break;
  540. case JCS_EXT_RGBX:
  541. case JCS_EXT_RGBA:
  542. dspr2fct = jsimd_h2v1_extrgbx_merged_upsample_dspr2;
  543. break;
  544. case JCS_EXT_BGR:
  545. dspr2fct = jsimd_h2v1_extbgr_merged_upsample_dspr2;
  546. break;
  547. case JCS_EXT_BGRX:
  548. case JCS_EXT_BGRA:
  549. dspr2fct = jsimd_h2v1_extbgrx_merged_upsample_dspr2;
  550. break;
  551. case JCS_EXT_XBGR:
  552. case JCS_EXT_ABGR:
  553. dspr2fct = jsimd_h2v1_extxbgr_merged_upsample_dspr2;
  554. break;
  555. case JCS_EXT_XRGB:
  556. case JCS_EXT_ARGB:
  557. dspr2fct = jsimd_h2v1_extxrgb_merged_upsample_dspr2;
  558. break;
  559. default:
  560. dspr2fct = jsimd_h2v1_extrgb_merged_upsample_dspr2;
  561. break;
  562. }
  563. dspr2fct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf,
  564. cinfo->sample_range_limit);
  565. }
  566. GLOBAL(int)
  567. jsimd_can_convsamp(void)
  568. {
  569. init_simd();
  570. /* The code is optimised for these values only */
  571. if (DCTSIZE != 8)
  572. return 0;
  573. if (BITS_IN_JSAMPLE != 8)
  574. return 0;
  575. if (sizeof(JDIMENSION) != 4)
  576. return 0;
  577. if (sizeof(DCTELEM) != 2)
  578. return 0;
  579. #if defined(__MIPSEL__)
  580. if (simd_support & JSIMD_DSPR2)
  581. return 1;
  582. #endif
  583. return 0;
  584. }
  585. GLOBAL(int)
  586. jsimd_can_convsamp_float(void)
  587. {
  588. init_simd();
  589. /* The code is optimised for these values only */
  590. if (DCTSIZE != 8)
  591. return 0;
  592. if (sizeof(JCOEF) != 2)
  593. return 0;
  594. if (BITS_IN_JSAMPLE != 8)
  595. return 0;
  596. if (sizeof(JDIMENSION) != 4)
  597. return 0;
  598. if (sizeof(ISLOW_MULT_TYPE) != 2)
  599. return 0;
  600. #ifndef __mips_soft_float
  601. if (simd_support & JSIMD_DSPR2)
  602. return 1;
  603. #endif
  604. return 0;
  605. }
  606. GLOBAL(void)
  607. jsimd_convsamp(JSAMPARRAY sample_data, JDIMENSION start_col,
  608. DCTELEM *workspace)
  609. {
  610. jsimd_convsamp_dspr2(sample_data, start_col, workspace);
  611. }
  612. GLOBAL(void)
  613. jsimd_convsamp_float(JSAMPARRAY sample_data, JDIMENSION start_col,
  614. FAST_FLOAT *workspace)
  615. {
  616. #ifndef __mips_soft_float
  617. jsimd_convsamp_float_dspr2(sample_data, start_col, workspace);
  618. #endif
  619. }
  620. GLOBAL(int)
  621. jsimd_can_fdct_islow(void)
  622. {
  623. init_simd();
  624. /* The code is optimised for these values only */
  625. if (DCTSIZE != 8)
  626. return 0;
  627. if (sizeof(DCTELEM) != 2)
  628. return 0;
  629. #if defined(__MIPSEL__)
  630. if (simd_support & JSIMD_DSPR2)
  631. return 1;
  632. #endif
  633. return 0;
  634. }
  635. GLOBAL(int)
  636. jsimd_can_fdct_ifast(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 defined(__MIPSEL__)
  645. if (simd_support & JSIMD_DSPR2)
  646. return 1;
  647. #endif
  648. return 0;
  649. }
  650. GLOBAL(int)
  651. jsimd_can_fdct_float(void)
  652. {
  653. return 0;
  654. }
  655. GLOBAL(void)
  656. jsimd_fdct_islow(DCTELEM *data)
  657. {
  658. jsimd_fdct_islow_dspr2(data);
  659. }
  660. GLOBAL(void)
  661. jsimd_fdct_ifast(DCTELEM *data)
  662. {
  663. jsimd_fdct_ifast_dspr2(data);
  664. }
  665. GLOBAL(void)
  666. jsimd_fdct_float(FAST_FLOAT *data)
  667. {
  668. }
  669. GLOBAL(int)
  670. jsimd_can_quantize(void)
  671. {
  672. init_simd();
  673. /* The code is optimised for these values only */
  674. if (DCTSIZE != 8)
  675. return 0;
  676. if (sizeof(JCOEF) != 2)
  677. return 0;
  678. if (sizeof(DCTELEM) != 2)
  679. return 0;
  680. if (simd_support & JSIMD_DSPR2)
  681. return 1;
  682. return 0;
  683. }
  684. GLOBAL(int)
  685. jsimd_can_quantize_float(void)
  686. {
  687. init_simd();
  688. /* The code is optimised for these values only */
  689. if (DCTSIZE != 8)
  690. return 0;
  691. if (sizeof(JCOEF) != 2)
  692. return 0;
  693. if (BITS_IN_JSAMPLE != 8)
  694. return 0;
  695. if (sizeof(JDIMENSION) != 4)
  696. return 0;
  697. if (sizeof(ISLOW_MULT_TYPE) != 2)
  698. return 0;
  699. #ifndef __mips_soft_float
  700. if (simd_support & JSIMD_DSPR2)
  701. return 1;
  702. #endif
  703. return 0;
  704. }
  705. GLOBAL(void)
  706. jsimd_quantize(JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace)
  707. {
  708. jsimd_quantize_dspr2(coef_block, divisors, workspace);
  709. }
  710. GLOBAL(void)
  711. jsimd_quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors,
  712. FAST_FLOAT *workspace)
  713. {
  714. #ifndef __mips_soft_float
  715. jsimd_quantize_float_dspr2(coef_block, divisors, workspace);
  716. #endif
  717. }
  718. GLOBAL(int)
  719. jsimd_can_idct_2x2(void)
  720. {
  721. init_simd();
  722. /* The code is optimised for these values only */
  723. if (DCTSIZE != 8)
  724. return 0;
  725. if (sizeof(JCOEF) != 2)
  726. return 0;
  727. if (BITS_IN_JSAMPLE != 8)
  728. return 0;
  729. if (sizeof(JDIMENSION) != 4)
  730. return 0;
  731. if (sizeof(ISLOW_MULT_TYPE) != 2)
  732. return 0;
  733. if (simd_support & JSIMD_DSPR2)
  734. return 1;
  735. return 0;
  736. }
  737. GLOBAL(int)
  738. jsimd_can_idct_4x4(void)
  739. {
  740. init_simd();
  741. /* The code is optimised for these values only */
  742. if (DCTSIZE != 8)
  743. return 0;
  744. if (sizeof(JCOEF) != 2)
  745. return 0;
  746. if (BITS_IN_JSAMPLE != 8)
  747. return 0;
  748. if (sizeof(JDIMENSION) != 4)
  749. return 0;
  750. if (sizeof(ISLOW_MULT_TYPE) != 2)
  751. return 0;
  752. #if defined(__MIPSEL__)
  753. if (simd_support & JSIMD_DSPR2)
  754. return 1;
  755. #endif
  756. return 0;
  757. }
  758. GLOBAL(int)
  759. jsimd_can_idct_6x6(void)
  760. {
  761. init_simd();
  762. /* The code is optimised for these values only */
  763. if (DCTSIZE != 8)
  764. return 0;
  765. if (sizeof(JCOEF) != 2)
  766. return 0;
  767. if (BITS_IN_JSAMPLE != 8)
  768. return 0;
  769. if (sizeof(JDIMENSION) != 4)
  770. return 0;
  771. if (sizeof(ISLOW_MULT_TYPE) != 2)
  772. return 0;
  773. if (simd_support & JSIMD_DSPR2)
  774. return 1;
  775. return 0;
  776. }
  777. GLOBAL(int)
  778. jsimd_can_idct_12x12(void)
  779. {
  780. init_simd();
  781. if (BITS_IN_JSAMPLE != 8)
  782. return 0;
  783. if (DCTSIZE != 8)
  784. return 0;
  785. if (sizeof(JCOEF) != 2)
  786. return 0;
  787. if (sizeof(JDIMENSION) != 4)
  788. return 0;
  789. if (sizeof(ISLOW_MULT_TYPE) != 2)
  790. return 0;
  791. if (simd_support & JSIMD_DSPR2)
  792. return 1;
  793. return 0;
  794. }
  795. GLOBAL(void)
  796. jsimd_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  797. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  798. JDIMENSION output_col)
  799. {
  800. jsimd_idct_2x2_dspr2(compptr->dct_table, coef_block, output_buf, output_col);
  801. }
  802. GLOBAL(void)
  803. jsimd_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  804. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  805. JDIMENSION output_col)
  806. {
  807. int workspace[DCTSIZE * 4]; /* buffers data between passes */
  808. jsimd_idct_4x4_dspr2(compptr->dct_table, coef_block, output_buf, output_col,
  809. workspace);
  810. }
  811. GLOBAL(void)
  812. jsimd_idct_6x6(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  813. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  814. JDIMENSION output_col)
  815. {
  816. jsimd_idct_6x6_dspr2(compptr->dct_table, coef_block, output_buf, output_col);
  817. }
  818. GLOBAL(void)
  819. jsimd_idct_12x12(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  820. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  821. JDIMENSION output_col)
  822. {
  823. int workspace[96];
  824. int output[12] = {
  825. (int)(output_buf[0] + output_col),
  826. (int)(output_buf[1] + output_col),
  827. (int)(output_buf[2] + output_col),
  828. (int)(output_buf[3] + output_col),
  829. (int)(output_buf[4] + output_col),
  830. (int)(output_buf[5] + output_col),
  831. (int)(output_buf[6] + output_col),
  832. (int)(output_buf[7] + output_col),
  833. (int)(output_buf[8] + output_col),
  834. (int)(output_buf[9] + output_col),
  835. (int)(output_buf[10] + output_col),
  836. (int)(output_buf[11] + output_col)
  837. };
  838. jsimd_idct_12x12_pass1_dspr2(coef_block, compptr->dct_table, workspace);
  839. jsimd_idct_12x12_pass2_dspr2(workspace, output);
  840. }
  841. GLOBAL(int)
  842. jsimd_can_idct_islow(void)
  843. {
  844. init_simd();
  845. /* The code is optimised for these values only */
  846. if (DCTSIZE != 8)
  847. return 0;
  848. if (sizeof(JCOEF) != 2)
  849. return 0;
  850. if (BITS_IN_JSAMPLE != 8)
  851. return 0;
  852. if (sizeof(JDIMENSION) != 4)
  853. return 0;
  854. if (sizeof(ISLOW_MULT_TYPE) != 2)
  855. return 0;
  856. if (simd_support & JSIMD_DSPR2)
  857. return 1;
  858. return 0;
  859. }
  860. GLOBAL(int)
  861. jsimd_can_idct_ifast(void)
  862. {
  863. init_simd();
  864. /* The code is optimised for these values only */
  865. if (DCTSIZE != 8)
  866. return 0;
  867. if (sizeof(JCOEF) != 2)
  868. return 0;
  869. if (BITS_IN_JSAMPLE != 8)
  870. return 0;
  871. if (sizeof(JDIMENSION) != 4)
  872. return 0;
  873. if (sizeof(IFAST_MULT_TYPE) != 2)
  874. return 0;
  875. if (IFAST_SCALE_BITS != 2)
  876. return 0;
  877. #if defined(__MIPSEL__)
  878. if (simd_support & JSIMD_DSPR2)
  879. return 1;
  880. #endif
  881. return 0;
  882. }
  883. GLOBAL(int)
  884. jsimd_can_idct_float(void)
  885. {
  886. return 0;
  887. }
  888. GLOBAL(void)
  889. jsimd_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  890. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  891. JDIMENSION output_col)
  892. {
  893. int output[8] = {
  894. (int)(output_buf[0] + output_col),
  895. (int)(output_buf[1] + output_col),
  896. (int)(output_buf[2] + output_col),
  897. (int)(output_buf[3] + output_col),
  898. (int)(output_buf[4] + output_col),
  899. (int)(output_buf[5] + output_col),
  900. (int)(output_buf[6] + output_col),
  901. (int)(output_buf[7] + output_col)
  902. };
  903. jsimd_idct_islow_dspr2(coef_block, compptr->dct_table, output,
  904. IDCT_range_limit(cinfo));
  905. }
  906. GLOBAL(void)
  907. jsimd_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  908. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  909. JDIMENSION output_col)
  910. {
  911. JCOEFPTR inptr;
  912. IFAST_MULT_TYPE *quantptr;
  913. DCTELEM workspace[DCTSIZE2]; /* buffers data between passes */
  914. /* Pass 1: process columns from input, store into work array. */
  915. inptr = coef_block;
  916. quantptr = (IFAST_MULT_TYPE *)compptr->dct_table;
  917. jsimd_idct_ifast_cols_dspr2(inptr, quantptr, workspace,
  918. mips_idct_ifast_coefs);
  919. /* Pass 2: process rows from work array, store into output array. */
  920. /* Note that we must descale the results by a factor of 8 == 2**3, */
  921. /* and also undo the PASS1_BITS scaling. */
  922. jsimd_idct_ifast_rows_dspr2(workspace, output_buf, output_col,
  923. mips_idct_ifast_coefs);
  924. }
  925. GLOBAL(void)
  926. jsimd_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  927. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  928. JDIMENSION output_col)
  929. {
  930. }
  931. GLOBAL(int)
  932. jsimd_can_huff_encode_one_block(void)
  933. {
  934. return 0;
  935. }
  936. GLOBAL(JOCTET *)
  937. jsimd_huff_encode_one_block(void *state, JOCTET *buffer, JCOEFPTR block,
  938. int last_dc_val, c_derived_tbl *dctbl,
  939. c_derived_tbl *actbl)
  940. {
  941. return NULL;
  942. }
  943. GLOBAL(int)
  944. jsimd_can_encode_mcu_AC_first_prepare(void)
  945. {
  946. return 0;
  947. }
  948. GLOBAL(void)
  949. jsimd_encode_mcu_AC_first_prepare(const JCOEF *block,
  950. const int *jpeg_natural_order_start, int Sl,
  951. int Al, UJCOEF *values, size_t *zerobits)
  952. {
  953. }
  954. GLOBAL(int)
  955. jsimd_can_encode_mcu_AC_refine_prepare(void)
  956. {
  957. return 0;
  958. }
  959. GLOBAL(int)
  960. jsimd_encode_mcu_AC_refine_prepare(const JCOEF *block,
  961. const int *jpeg_natural_order_start, int Sl,
  962. int Al, UJCOEF *absvalues, size_t *bits)
  963. {
  964. return 0;
  965. }