jsimd.c 26 KB

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