jsimd_mips.c 27 KB

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