jsimd.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /*
  2. * jsimd_loongson.c
  3. *
  4. * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
  5. * Copyright (C) 2009-2011, 2014, 2016, 2018, D. R. Commander.
  6. * Copyright (C) 2013-2014, MIPS Technologies, Inc., California.
  7. * Copyright (C) 2015, 2018, Matthieu Darbois.
  8. * Copyright (C) 2016-2017, Loongson Technology Corporation Limited, BeiJing.
  9. *
  10. * Based on the x86 SIMD extension for IJG JPEG library,
  11. * Copyright (C) 1999-2006, MIYASAKA Masaru.
  12. * For conditions of distribution and use, see copyright notice in jsimdext.inc
  13. *
  14. * This file contains the interface between the "normal" portions
  15. * of the library and the SIMD implementations when running on a
  16. * Loongson architecture.
  17. */
  18. #define JPEG_INTERNALS
  19. #include "../../jinclude.h"
  20. #include "../../jpeglib.h"
  21. #include "../../jsimd.h"
  22. #include "../../jdct.h"
  23. #include "../../jsimddct.h"
  24. #include "../jsimd.h"
  25. static unsigned int simd_support = ~0;
  26. /*
  27. * Check what SIMD accelerations are supported.
  28. *
  29. * FIXME: This code is racy under a multi-threaded environment.
  30. */
  31. LOCAL(void)
  32. init_simd(void)
  33. {
  34. #ifndef NO_GETENV
  35. char *env = NULL;
  36. #endif
  37. if (simd_support != ~0U)
  38. return;
  39. simd_support |= JSIMD_MMI;
  40. #ifndef NO_GETENV
  41. /* Force different settings through environment variables */
  42. env = getenv("JSIMD_FORCENONE");
  43. if ((env != NULL) && (strcmp(env, "1") == 0))
  44. simd_support = 0;
  45. #endif
  46. }
  47. GLOBAL(int)
  48. jsimd_can_rgb_ycc(void)
  49. {
  50. init_simd();
  51. /* The code is optimised for these values only */
  52. if (BITS_IN_JSAMPLE != 8)
  53. return 0;
  54. if (sizeof(JDIMENSION) != 4)
  55. return 0;
  56. if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
  57. return 0;
  58. if (simd_support & JSIMD_MMI)
  59. return 1;
  60. return 0;
  61. }
  62. GLOBAL(int)
  63. jsimd_can_rgb_gray(void)
  64. {
  65. return 0;
  66. }
  67. GLOBAL(int)
  68. jsimd_can_ycc_rgb(void)
  69. {
  70. init_simd();
  71. /* The code is optimised for these values only */
  72. if (BITS_IN_JSAMPLE != 8)
  73. return 0;
  74. if (sizeof(JDIMENSION) != 4)
  75. return 0;
  76. if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
  77. return 0;
  78. if (simd_support & JSIMD_MMI)
  79. return 1;
  80. return 0;
  81. }
  82. GLOBAL(int)
  83. jsimd_can_ycc_rgb565(void)
  84. {
  85. return 0;
  86. }
  87. GLOBAL(int)
  88. jsimd_c_can_null_convert(void)
  89. {
  90. return 0;
  91. }
  92. GLOBAL(void)
  93. jsimd_rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
  94. JSAMPIMAGE output_buf, JDIMENSION output_row,
  95. int num_rows)
  96. {
  97. void (*mmifct) (JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
  98. switch (cinfo->in_color_space) {
  99. case JCS_EXT_RGB:
  100. mmifct = jsimd_extrgb_ycc_convert_mmi;
  101. break;
  102. case JCS_EXT_RGBX:
  103. case JCS_EXT_RGBA:
  104. mmifct = jsimd_extrgbx_ycc_convert_mmi;
  105. break;
  106. case JCS_EXT_BGR:
  107. mmifct = jsimd_extbgr_ycc_convert_mmi;
  108. break;
  109. case JCS_EXT_BGRX:
  110. case JCS_EXT_BGRA:
  111. mmifct = jsimd_extbgrx_ycc_convert_mmi;
  112. break;
  113. case JCS_EXT_XBGR:
  114. case JCS_EXT_ABGR:
  115. mmifct = jsimd_extxbgr_ycc_convert_mmi;
  116. break;
  117. case JCS_EXT_XRGB:
  118. case JCS_EXT_ARGB:
  119. mmifct = jsimd_extxrgb_ycc_convert_mmi;
  120. break;
  121. default:
  122. mmifct = jsimd_rgb_ycc_convert_mmi;
  123. break;
  124. }
  125. mmifct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
  126. }
  127. GLOBAL(void)
  128. jsimd_rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
  129. JSAMPIMAGE output_buf, JDIMENSION output_row,
  130. int num_rows)
  131. {
  132. }
  133. GLOBAL(void)
  134. jsimd_ycc_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  135. JDIMENSION input_row, JSAMPARRAY output_buf,
  136. int num_rows)
  137. {
  138. void (*mmifct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
  139. switch (cinfo->out_color_space) {
  140. case JCS_EXT_RGB:
  141. mmifct = jsimd_ycc_extrgb_convert_mmi;
  142. break;
  143. case JCS_EXT_RGBX:
  144. case JCS_EXT_RGBA:
  145. mmifct = jsimd_ycc_extrgbx_convert_mmi;
  146. break;
  147. case JCS_EXT_BGR:
  148. mmifct = jsimd_ycc_extbgr_convert_mmi;
  149. break;
  150. case JCS_EXT_BGRX:
  151. case JCS_EXT_BGRA:
  152. mmifct = jsimd_ycc_extbgrx_convert_mmi;
  153. break;
  154. case JCS_EXT_XBGR:
  155. case JCS_EXT_ABGR:
  156. mmifct = jsimd_ycc_extxbgr_convert_mmi;
  157. break;
  158. case JCS_EXT_XRGB:
  159. case JCS_EXT_ARGB:
  160. mmifct = jsimd_ycc_extxrgb_convert_mmi;
  161. break;
  162. default:
  163. mmifct = jsimd_ycc_rgb_convert_mmi;
  164. break;
  165. }
  166. mmifct(cinfo->output_width, input_buf, input_row, output_buf, num_rows);
  167. }
  168. GLOBAL(void)
  169. jsimd_ycc_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  170. JDIMENSION input_row, JSAMPARRAY output_buf,
  171. int num_rows)
  172. {
  173. }
  174. GLOBAL(void)
  175. jsimd_c_null_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
  176. JSAMPIMAGE output_buf, JDIMENSION output_row,
  177. int num_rows)
  178. {
  179. }
  180. GLOBAL(int)
  181. jsimd_can_h2v2_downsample(void)
  182. {
  183. init_simd();
  184. /* The code is optimised for these values only */
  185. if (BITS_IN_JSAMPLE != 8)
  186. return 0;
  187. if (sizeof(JDIMENSION) != 4)
  188. return 0;
  189. if (simd_support & JSIMD_MMI)
  190. return 1;
  191. return 0;
  192. }
  193. GLOBAL(int)
  194. jsimd_can_h2v2_smooth_downsample(void)
  195. {
  196. return 0;
  197. }
  198. GLOBAL(int)
  199. jsimd_can_h2v1_downsample(void)
  200. {
  201. return 0;
  202. }
  203. GLOBAL(void)
  204. jsimd_h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
  205. JSAMPARRAY input_data, JSAMPARRAY output_data)
  206. {
  207. jsimd_h2v2_downsample_mmi(cinfo->image_width, cinfo->max_v_samp_factor,
  208. compptr->v_samp_factor, compptr->width_in_blocks,
  209. input_data, output_data);
  210. }
  211. GLOBAL(void)
  212. jsimd_h2v2_smooth_downsample(j_compress_ptr cinfo,
  213. jpeg_component_info *compptr,
  214. JSAMPARRAY input_data, JSAMPARRAY output_data)
  215. {
  216. }
  217. GLOBAL(void)
  218. jsimd_h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
  219. JSAMPARRAY input_data, JSAMPARRAY output_data)
  220. {
  221. }
  222. GLOBAL(int)
  223. jsimd_can_h2v2_upsample(void)
  224. {
  225. return 0;
  226. }
  227. GLOBAL(int)
  228. jsimd_can_h2v1_upsample(void)
  229. {
  230. return 0;
  231. }
  232. GLOBAL(int)
  233. jsimd_can_int_upsample(void)
  234. {
  235. return 0;
  236. }
  237. GLOBAL(void)
  238. jsimd_h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  239. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  240. {
  241. }
  242. GLOBAL(void)
  243. jsimd_h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  244. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  245. {
  246. }
  247. GLOBAL(void)
  248. jsimd_int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  249. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  250. {
  251. }
  252. GLOBAL(int)
  253. jsimd_can_h2v2_fancy_upsample(void)
  254. {
  255. init_simd();
  256. /* The code is optimised for these values only */
  257. if (BITS_IN_JSAMPLE != 8)
  258. return 0;
  259. if (sizeof(JDIMENSION) != 4)
  260. return 0;
  261. if (simd_support & JSIMD_MMI)
  262. return 1;
  263. return 0;
  264. }
  265. GLOBAL(int)
  266. jsimd_can_h2v1_fancy_upsample(void)
  267. {
  268. return 0;
  269. }
  270. GLOBAL(void)
  271. jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  272. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  273. {
  274. jsimd_h2v2_fancy_upsample_mmi(cinfo->max_v_samp_factor,
  275. compptr->downsampled_width, input_data,
  276. output_data_ptr);
  277. }
  278. GLOBAL(void)
  279. jsimd_h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  280. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  281. {
  282. }
  283. GLOBAL(int)
  284. jsimd_can_h2v2_merged_upsample(void)
  285. {
  286. return 0;
  287. }
  288. GLOBAL(int)
  289. jsimd_can_h2v1_merged_upsample(void)
  290. {
  291. return 0;
  292. }
  293. GLOBAL(void)
  294. jsimd_h2v2_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  295. JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
  296. {
  297. }
  298. GLOBAL(void)
  299. jsimd_h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  300. JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
  301. {
  302. }
  303. GLOBAL(int)
  304. jsimd_can_convsamp(void)
  305. {
  306. return 0;
  307. }
  308. GLOBAL(int)
  309. jsimd_can_convsamp_float(void)
  310. {
  311. return 0;
  312. }
  313. GLOBAL(void)
  314. jsimd_convsamp(JSAMPARRAY sample_data, JDIMENSION start_col,
  315. DCTELEM *workspace)
  316. {
  317. }
  318. GLOBAL(void)
  319. jsimd_convsamp_float(JSAMPARRAY sample_data, JDIMENSION start_col,
  320. FAST_FLOAT *workspace)
  321. {
  322. }
  323. GLOBAL(int)
  324. jsimd_can_fdct_islow(void)
  325. {
  326. init_simd();
  327. /* The code is optimised for these values only */
  328. if (DCTSIZE != 8)
  329. return 0;
  330. if (sizeof(DCTELEM) != 2)
  331. return 0;
  332. if (simd_support & JSIMD_MMI)
  333. return 1;
  334. return 0;
  335. }
  336. GLOBAL(int)
  337. jsimd_can_fdct_ifast(void)
  338. {
  339. return 0;
  340. }
  341. GLOBAL(int)
  342. jsimd_can_fdct_float(void)
  343. {
  344. return 0;
  345. }
  346. GLOBAL(void)
  347. jsimd_fdct_islow(DCTELEM *data)
  348. {
  349. jsimd_fdct_islow_mmi(data);
  350. }
  351. GLOBAL(void)
  352. jsimd_fdct_ifast(DCTELEM *data)
  353. {
  354. }
  355. GLOBAL(void)
  356. jsimd_fdct_float(FAST_FLOAT *data)
  357. {
  358. }
  359. GLOBAL(int)
  360. jsimd_can_quantize(void)
  361. {
  362. init_simd();
  363. /* The code is optimised for these values only */
  364. if (DCTSIZE != 8)
  365. return 0;
  366. if (sizeof(JCOEF) != 2)
  367. return 0;
  368. if (sizeof(DCTELEM) != 2)
  369. return 0;
  370. if (simd_support & JSIMD_MMI)
  371. return 1;
  372. return 0;
  373. }
  374. GLOBAL(int)
  375. jsimd_can_quantize_float(void)
  376. {
  377. return 0;
  378. }
  379. GLOBAL(void)
  380. jsimd_quantize(JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace)
  381. {
  382. jsimd_quantize_mmi(coef_block, divisors, workspace);
  383. }
  384. GLOBAL(void)
  385. jsimd_quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors,
  386. FAST_FLOAT *workspace)
  387. {
  388. }
  389. GLOBAL(int)
  390. jsimd_can_idct_2x2(void)
  391. {
  392. return 0;
  393. }
  394. GLOBAL(int)
  395. jsimd_can_idct_4x4(void)
  396. {
  397. return 0;
  398. }
  399. GLOBAL(int)
  400. jsimd_can_idct_6x6(void)
  401. {
  402. return 0;
  403. }
  404. GLOBAL(int)
  405. jsimd_can_idct_12x12(void)
  406. {
  407. return 0;
  408. }
  409. GLOBAL(void)
  410. jsimd_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  411. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  412. JDIMENSION output_col)
  413. {
  414. }
  415. GLOBAL(void)
  416. jsimd_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  417. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  418. JDIMENSION output_col)
  419. {
  420. }
  421. GLOBAL(void)
  422. jsimd_idct_6x6(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  423. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  424. JDIMENSION output_col)
  425. {
  426. }
  427. GLOBAL(void)
  428. jsimd_idct_12x12(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  429. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  430. JDIMENSION output_col)
  431. {
  432. }
  433. GLOBAL(int)
  434. jsimd_can_idct_islow(void)
  435. {
  436. init_simd();
  437. /* The code is optimised for these values only */
  438. if (DCTSIZE != 8)
  439. return 0;
  440. if (sizeof(JCOEF) != 2)
  441. return 0;
  442. if (BITS_IN_JSAMPLE != 8)
  443. return 0;
  444. if (sizeof(JDIMENSION) != 4)
  445. return 0;
  446. if (sizeof(ISLOW_MULT_TYPE) != 2)
  447. return 0;
  448. if (simd_support & JSIMD_MMI)
  449. return 1;
  450. return 0;
  451. }
  452. GLOBAL(int)
  453. jsimd_can_idct_ifast(void)
  454. {
  455. return 0;
  456. }
  457. GLOBAL(int)
  458. jsimd_can_idct_float(void)
  459. {
  460. return 0;
  461. }
  462. GLOBAL(void)
  463. jsimd_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  464. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  465. JDIMENSION output_col)
  466. {
  467. jsimd_idct_islow_mmi(compptr->dct_table, coef_block, output_buf, output_col);
  468. }
  469. GLOBAL(void)
  470. jsimd_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  471. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  472. JDIMENSION output_col)
  473. {
  474. }
  475. GLOBAL(void)
  476. jsimd_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  477. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  478. JDIMENSION output_col)
  479. {
  480. }
  481. GLOBAL(int)
  482. jsimd_can_huff_encode_one_block(void)
  483. {
  484. return 0;
  485. }
  486. GLOBAL(JOCTET *)
  487. jsimd_huff_encode_one_block(void *state, JOCTET *buffer, JCOEFPTR block,
  488. int last_dc_val, c_derived_tbl *dctbl,
  489. c_derived_tbl *actbl)
  490. {
  491. return NULL;
  492. }
  493. GLOBAL(int)
  494. jsimd_can_encode_mcu_AC_first_prepare(void)
  495. {
  496. return 0;
  497. }
  498. GLOBAL(void)
  499. jsimd_encode_mcu_AC_first_prepare(const JCOEF *block,
  500. const int *jpeg_natural_order_start, int Sl,
  501. int Al, JCOEF *values, size_t *zerobits)
  502. {
  503. }
  504. GLOBAL(int)
  505. jsimd_can_encode_mcu_AC_refine_prepare(void)
  506. {
  507. return 0;
  508. }
  509. GLOBAL(int)
  510. jsimd_encode_mcu_AC_refine_prepare(const JCOEF *block,
  511. const int *jpeg_natural_order_start, int Sl,
  512. int Al, JCOEF *absvalues, size_t *bits)
  513. {
  514. return 0;
  515. }