jsimd.c 24 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  1. /*
  2. * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
  3. * Copyright (C) 2011, Nokia Corporation and/or its subsidiary(-ies).
  4. * Copyright (C) 2009-2011, 2013-2014, 2016, 2018, 2020, 2022, 2024,
  5. * D. R. Commander.
  6. * Copyright (C) 2015-2016, 2018, 2022, Matthieu Darbois.
  7. * Copyright (C) 2020, Arm Limited.
  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. * 64-bit Arm architecture.
  16. */
  17. #define JPEG_INTERNALS
  18. #include "../../../src/jinclude.h"
  19. #include "../../../src/jpeglib.h"
  20. #include "../../../src/jsimd.h"
  21. #include "../../../src/jdct.h"
  22. #include "../../../src/jsimddct.h"
  23. #include "../../jsimd.h"
  24. #include <ctype.h>
  25. #define JSIMD_FASTLD3 1
  26. #define JSIMD_FASTST3 2
  27. #define JSIMD_FASTTBL 4
  28. static THREAD_LOCAL unsigned int simd_support = ~0;
  29. static THREAD_LOCAL unsigned int simd_huffman = 1;
  30. static THREAD_LOCAL unsigned int simd_features = JSIMD_FASTLD3 |
  31. JSIMD_FASTST3 | JSIMD_FASTTBL;
  32. #if defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
  33. #define SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT (1024 * 1024)
  34. LOCAL(int)
  35. check_cpuinfo(char *buffer, const char *field, char *value)
  36. {
  37. char *p;
  38. if (*value == 0)
  39. return 0;
  40. if (strncmp(buffer, field, strlen(field)) != 0)
  41. return 0;
  42. buffer += strlen(field);
  43. while (isspace(*buffer))
  44. buffer++;
  45. /* Check if 'value' is present in the buffer as a separate word */
  46. while ((p = strstr(buffer, value))) {
  47. if (p > buffer && !isspace(*(p - 1))) {
  48. buffer++;
  49. continue;
  50. }
  51. p += strlen(value);
  52. if (*p != 0 && !isspace(*p)) {
  53. buffer++;
  54. continue;
  55. }
  56. return 1;
  57. }
  58. return 0;
  59. }
  60. LOCAL(int)
  61. parse_proc_cpuinfo(int bufsize)
  62. {
  63. char *buffer = (char *)malloc(bufsize);
  64. FILE *fd;
  65. if (!buffer)
  66. return 0;
  67. fd = fopen("/proc/cpuinfo", "r");
  68. if (fd) {
  69. while (fgets(buffer, bufsize, fd)) {
  70. if (!strchr(buffer, '\n') && !feof(fd)) {
  71. /* "impossible" happened - insufficient size of the buffer! */
  72. fclose(fd);
  73. free(buffer);
  74. return 0;
  75. }
  76. if (check_cpuinfo(buffer, "CPU part", "0xd03") ||
  77. check_cpuinfo(buffer, "CPU part", "0xd07"))
  78. /* The Cortex-A53 has a slow tbl implementation. We can gain a few
  79. percent speedup by disabling the use of that instruction. The
  80. speedup on Cortex-A57 is more subtle but still measurable. */
  81. simd_features &= ~JSIMD_FASTTBL;
  82. else if (check_cpuinfo(buffer, "CPU part", "0x0a1"))
  83. /* The SIMD version of Huffman encoding is slower than the C version on
  84. Cavium ThunderX. Also, ld3 and st3 are abyssmally slow on that
  85. CPU. */
  86. simd_huffman = simd_features = 0;
  87. }
  88. fclose(fd);
  89. }
  90. free(buffer);
  91. return 1;
  92. }
  93. #endif
  94. /*
  95. * Check what SIMD accelerations are supported.
  96. */
  97. /*
  98. * Armv8 architectures support Neon extensions by default.
  99. * It is no longer optional as it was with Armv7.
  100. */
  101. LOCAL(void)
  102. init_simd(void)
  103. {
  104. #ifndef NO_GETENV
  105. char env[2] = { 0 };
  106. #endif
  107. #if defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
  108. int bufsize = 1024; /* an initial guess for the line buffer size limit */
  109. #endif
  110. if (simd_support != ~0U)
  111. return;
  112. simd_support = 0;
  113. simd_support |= JSIMD_NEON;
  114. #if defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
  115. while (!parse_proc_cpuinfo(bufsize)) {
  116. bufsize *= 2;
  117. if (bufsize > SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT)
  118. break;
  119. }
  120. #endif
  121. #ifndef NO_GETENV
  122. /* Force different settings through environment variables */
  123. if (!GETENV_S(env, 2, "JSIMD_FORCENEON") && !strcmp(env, "1"))
  124. simd_support = JSIMD_NEON;
  125. if (!GETENV_S(env, 2, "JSIMD_FORCENONE") && !strcmp(env, "1"))
  126. simd_support = 0;
  127. if (!GETENV_S(env, 2, "JSIMD_NOHUFFENC") && !strcmp(env, "1"))
  128. simd_huffman = 0;
  129. if (!GETENV_S(env, 2, "JSIMD_FASTLD3") && !strcmp(env, "1"))
  130. simd_features |= JSIMD_FASTLD3;
  131. if (!GETENV_S(env, 2, "JSIMD_FASTLD3") && !strcmp(env, "0"))
  132. simd_features &= ~JSIMD_FASTLD3;
  133. if (!GETENV_S(env, 2, "JSIMD_FASTST3") && !strcmp(env, "1"))
  134. simd_features |= JSIMD_FASTST3;
  135. if (!GETENV_S(env, 2, "JSIMD_FASTST3") && !strcmp(env, "0"))
  136. simd_features &= ~JSIMD_FASTST3;
  137. #endif
  138. }
  139. GLOBAL(int)
  140. jsimd_can_rgb_ycc(void)
  141. {
  142. init_simd();
  143. /* The code is optimised for these values only */
  144. if (BITS_IN_JSAMPLE != 8)
  145. return 0;
  146. if (sizeof(JDIMENSION) != 4)
  147. return 0;
  148. if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
  149. return 0;
  150. if (simd_support & JSIMD_NEON)
  151. return 1;
  152. return 0;
  153. }
  154. GLOBAL(int)
  155. jsimd_can_rgb_gray(void)
  156. {
  157. init_simd();
  158. /* The code is optimised for these values only */
  159. if (BITS_IN_JSAMPLE != 8)
  160. return 0;
  161. if (sizeof(JDIMENSION) != 4)
  162. return 0;
  163. if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
  164. return 0;
  165. if (simd_support & JSIMD_NEON)
  166. return 1;
  167. return 0;
  168. }
  169. GLOBAL(int)
  170. jsimd_can_ycc_rgb(void)
  171. {
  172. init_simd();
  173. /* The code is optimised for these values only */
  174. if (BITS_IN_JSAMPLE != 8)
  175. return 0;
  176. if (sizeof(JDIMENSION) != 4)
  177. return 0;
  178. if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
  179. return 0;
  180. if (simd_support & JSIMD_NEON)
  181. return 1;
  182. return 0;
  183. }
  184. GLOBAL(int)
  185. jsimd_can_ycc_rgb565(void)
  186. {
  187. init_simd();
  188. /* The code is optimised for these values only */
  189. if (BITS_IN_JSAMPLE != 8)
  190. return 0;
  191. if (sizeof(JDIMENSION) != 4)
  192. return 0;
  193. if (simd_support & JSIMD_NEON)
  194. return 1;
  195. return 0;
  196. }
  197. GLOBAL(void)
  198. jsimd_rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
  199. JSAMPIMAGE output_buf, JDIMENSION output_row,
  200. int num_rows)
  201. {
  202. void (*neonfct) (JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
  203. switch (cinfo->in_color_space) {
  204. case JCS_EXT_RGB:
  205. #ifndef NEON_INTRINSICS
  206. if (simd_features & JSIMD_FASTLD3)
  207. #endif
  208. neonfct = jsimd_extrgb_ycc_convert_neon;
  209. #ifndef NEON_INTRINSICS
  210. else
  211. neonfct = jsimd_extrgb_ycc_convert_neon_slowld3;
  212. #endif
  213. break;
  214. case JCS_EXT_RGBX:
  215. case JCS_EXT_RGBA:
  216. neonfct = jsimd_extrgbx_ycc_convert_neon;
  217. break;
  218. case JCS_EXT_BGR:
  219. #ifndef NEON_INTRINSICS
  220. if (simd_features & JSIMD_FASTLD3)
  221. #endif
  222. neonfct = jsimd_extbgr_ycc_convert_neon;
  223. #ifndef NEON_INTRINSICS
  224. else
  225. neonfct = jsimd_extbgr_ycc_convert_neon_slowld3;
  226. #endif
  227. break;
  228. case JCS_EXT_BGRX:
  229. case JCS_EXT_BGRA:
  230. neonfct = jsimd_extbgrx_ycc_convert_neon;
  231. break;
  232. case JCS_EXT_XBGR:
  233. case JCS_EXT_ABGR:
  234. neonfct = jsimd_extxbgr_ycc_convert_neon;
  235. break;
  236. case JCS_EXT_XRGB:
  237. case JCS_EXT_ARGB:
  238. neonfct = jsimd_extxrgb_ycc_convert_neon;
  239. break;
  240. default:
  241. #ifndef NEON_INTRINSICS
  242. if (simd_features & JSIMD_FASTLD3)
  243. #endif
  244. neonfct = jsimd_extrgb_ycc_convert_neon;
  245. #ifndef NEON_INTRINSICS
  246. else
  247. neonfct = jsimd_extrgb_ycc_convert_neon_slowld3;
  248. #endif
  249. break;
  250. }
  251. neonfct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
  252. }
  253. GLOBAL(void)
  254. jsimd_rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
  255. JSAMPIMAGE output_buf, JDIMENSION output_row,
  256. int num_rows)
  257. {
  258. void (*neonfct) (JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
  259. switch (cinfo->in_color_space) {
  260. case JCS_EXT_RGB:
  261. neonfct = jsimd_extrgb_gray_convert_neon;
  262. break;
  263. case JCS_EXT_RGBX:
  264. case JCS_EXT_RGBA:
  265. neonfct = jsimd_extrgbx_gray_convert_neon;
  266. break;
  267. case JCS_EXT_BGR:
  268. neonfct = jsimd_extbgr_gray_convert_neon;
  269. break;
  270. case JCS_EXT_BGRX:
  271. case JCS_EXT_BGRA:
  272. neonfct = jsimd_extbgrx_gray_convert_neon;
  273. break;
  274. case JCS_EXT_XBGR:
  275. case JCS_EXT_ABGR:
  276. neonfct = jsimd_extxbgr_gray_convert_neon;
  277. break;
  278. case JCS_EXT_XRGB:
  279. case JCS_EXT_ARGB:
  280. neonfct = jsimd_extxrgb_gray_convert_neon;
  281. break;
  282. default:
  283. neonfct = jsimd_extrgb_gray_convert_neon;
  284. break;
  285. }
  286. neonfct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
  287. }
  288. GLOBAL(void)
  289. jsimd_ycc_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  290. JDIMENSION input_row, JSAMPARRAY output_buf,
  291. int num_rows)
  292. {
  293. void (*neonfct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
  294. switch (cinfo->out_color_space) {
  295. case JCS_EXT_RGB:
  296. #ifndef NEON_INTRINSICS
  297. if (simd_features & JSIMD_FASTST3)
  298. #endif
  299. neonfct = jsimd_ycc_extrgb_convert_neon;
  300. #ifndef NEON_INTRINSICS
  301. else
  302. neonfct = jsimd_ycc_extrgb_convert_neon_slowst3;
  303. #endif
  304. break;
  305. case JCS_EXT_RGBX:
  306. case JCS_EXT_RGBA:
  307. neonfct = jsimd_ycc_extrgbx_convert_neon;
  308. break;
  309. case JCS_EXT_BGR:
  310. #ifndef NEON_INTRINSICS
  311. if (simd_features & JSIMD_FASTST3)
  312. #endif
  313. neonfct = jsimd_ycc_extbgr_convert_neon;
  314. #ifndef NEON_INTRINSICS
  315. else
  316. neonfct = jsimd_ycc_extbgr_convert_neon_slowst3;
  317. #endif
  318. break;
  319. case JCS_EXT_BGRX:
  320. case JCS_EXT_BGRA:
  321. neonfct = jsimd_ycc_extbgrx_convert_neon;
  322. break;
  323. case JCS_EXT_XBGR:
  324. case JCS_EXT_ABGR:
  325. neonfct = jsimd_ycc_extxbgr_convert_neon;
  326. break;
  327. case JCS_EXT_XRGB:
  328. case JCS_EXT_ARGB:
  329. neonfct = jsimd_ycc_extxrgb_convert_neon;
  330. break;
  331. default:
  332. #ifndef NEON_INTRINSICS
  333. if (simd_features & JSIMD_FASTST3)
  334. #endif
  335. neonfct = jsimd_ycc_extrgb_convert_neon;
  336. #ifndef NEON_INTRINSICS
  337. else
  338. neonfct = jsimd_ycc_extrgb_convert_neon_slowst3;
  339. #endif
  340. break;
  341. }
  342. neonfct(cinfo->output_width, input_buf, input_row, output_buf, num_rows);
  343. }
  344. GLOBAL(void)
  345. jsimd_ycc_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  346. JDIMENSION input_row, JSAMPARRAY output_buf,
  347. int num_rows)
  348. {
  349. jsimd_ycc_rgb565_convert_neon(cinfo->output_width, input_buf, input_row,
  350. output_buf, num_rows);
  351. }
  352. GLOBAL(int)
  353. jsimd_can_h2v2_downsample(void)
  354. {
  355. init_simd();
  356. /* The code is optimised for these values only */
  357. if (BITS_IN_JSAMPLE != 8)
  358. return 0;
  359. if (DCTSIZE != 8)
  360. return 0;
  361. if (sizeof(JDIMENSION) != 4)
  362. return 0;
  363. if (simd_support & JSIMD_NEON)
  364. return 1;
  365. return 0;
  366. }
  367. GLOBAL(int)
  368. jsimd_can_h2v1_downsample(void)
  369. {
  370. init_simd();
  371. /* The code is optimised for these values only */
  372. if (BITS_IN_JSAMPLE != 8)
  373. return 0;
  374. if (DCTSIZE != 8)
  375. return 0;
  376. if (sizeof(JDIMENSION) != 4)
  377. return 0;
  378. if (simd_support & JSIMD_NEON)
  379. return 1;
  380. return 0;
  381. }
  382. GLOBAL(void)
  383. jsimd_h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
  384. JSAMPARRAY input_data, JSAMPARRAY output_data)
  385. {
  386. jsimd_h2v2_downsample_neon(cinfo->image_width, cinfo->max_v_samp_factor,
  387. compptr->v_samp_factor, compptr->width_in_blocks,
  388. input_data, output_data);
  389. }
  390. GLOBAL(void)
  391. jsimd_h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
  392. JSAMPARRAY input_data, JSAMPARRAY output_data)
  393. {
  394. jsimd_h2v1_downsample_neon(cinfo->image_width, cinfo->max_v_samp_factor,
  395. compptr->v_samp_factor, compptr->width_in_blocks,
  396. input_data, output_data);
  397. }
  398. GLOBAL(int)
  399. jsimd_can_h2v2_upsample(void)
  400. {
  401. init_simd();
  402. /* The code is optimised for these values only */
  403. if (BITS_IN_JSAMPLE != 8)
  404. return 0;
  405. if (sizeof(JDIMENSION) != 4)
  406. return 0;
  407. if (simd_support & JSIMD_NEON)
  408. return 1;
  409. return 0;
  410. }
  411. GLOBAL(int)
  412. jsimd_can_h2v1_upsample(void)
  413. {
  414. init_simd();
  415. /* The code is optimised for these values only */
  416. if (BITS_IN_JSAMPLE != 8)
  417. return 0;
  418. if (sizeof(JDIMENSION) != 4)
  419. return 0;
  420. if (simd_support & JSIMD_NEON)
  421. return 1;
  422. return 0;
  423. }
  424. GLOBAL(void)
  425. jsimd_h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  426. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  427. {
  428. jsimd_h2v2_upsample_neon(cinfo->max_v_samp_factor, cinfo->output_width,
  429. input_data, output_data_ptr);
  430. }
  431. GLOBAL(void)
  432. jsimd_h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  433. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  434. {
  435. jsimd_h2v1_upsample_neon(cinfo->max_v_samp_factor, cinfo->output_width,
  436. input_data, output_data_ptr);
  437. }
  438. GLOBAL(int)
  439. jsimd_can_h2v2_fancy_upsample(void)
  440. {
  441. init_simd();
  442. /* The code is optimised for these values only */
  443. if (BITS_IN_JSAMPLE != 8)
  444. return 0;
  445. if (sizeof(JDIMENSION) != 4)
  446. return 0;
  447. if (simd_support & JSIMD_NEON)
  448. return 1;
  449. return 0;
  450. }
  451. GLOBAL(int)
  452. jsimd_can_h2v1_fancy_upsample(void)
  453. {
  454. init_simd();
  455. /* The code is optimised for these values only */
  456. if (BITS_IN_JSAMPLE != 8)
  457. return 0;
  458. if (sizeof(JDIMENSION) != 4)
  459. return 0;
  460. if (simd_support & JSIMD_NEON)
  461. return 1;
  462. return 0;
  463. }
  464. GLOBAL(int)
  465. jsimd_can_h1v2_fancy_upsample(void)
  466. {
  467. init_simd();
  468. /* The code is optimised for these values only */
  469. if (BITS_IN_JSAMPLE != 8)
  470. return 0;
  471. if (sizeof(JDIMENSION) != 4)
  472. return 0;
  473. if (simd_support & JSIMD_NEON)
  474. return 1;
  475. return 0;
  476. }
  477. GLOBAL(void)
  478. jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  479. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  480. {
  481. jsimd_h2v2_fancy_upsample_neon(cinfo->max_v_samp_factor,
  482. compptr->downsampled_width, input_data,
  483. output_data_ptr);
  484. }
  485. GLOBAL(void)
  486. jsimd_h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  487. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  488. {
  489. jsimd_h2v1_fancy_upsample_neon(cinfo->max_v_samp_factor,
  490. compptr->downsampled_width, input_data,
  491. output_data_ptr);
  492. }
  493. GLOBAL(void)
  494. jsimd_h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  495. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  496. {
  497. jsimd_h1v2_fancy_upsample_neon(cinfo->max_v_samp_factor,
  498. compptr->downsampled_width, input_data,
  499. output_data_ptr);
  500. }
  501. GLOBAL(int)
  502. jsimd_can_h2v2_merged_upsample(void)
  503. {
  504. init_simd();
  505. /* The code is optimised for these values only */
  506. if (BITS_IN_JSAMPLE != 8)
  507. return 0;
  508. if (sizeof(JDIMENSION) != 4)
  509. return 0;
  510. if (simd_support & JSIMD_NEON)
  511. return 1;
  512. return 0;
  513. }
  514. GLOBAL(int)
  515. jsimd_can_h2v1_merged_upsample(void)
  516. {
  517. init_simd();
  518. /* The code is optimised for these values only */
  519. if (BITS_IN_JSAMPLE != 8)
  520. return 0;
  521. if (sizeof(JDIMENSION) != 4)
  522. return 0;
  523. if (simd_support & JSIMD_NEON)
  524. return 1;
  525. return 0;
  526. }
  527. GLOBAL(void)
  528. jsimd_h2v2_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  529. JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
  530. {
  531. void (*neonfct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
  532. switch (cinfo->out_color_space) {
  533. case JCS_EXT_RGB:
  534. neonfct = jsimd_h2v2_extrgb_merged_upsample_neon;
  535. break;
  536. case JCS_EXT_RGBX:
  537. case JCS_EXT_RGBA:
  538. neonfct = jsimd_h2v2_extrgbx_merged_upsample_neon;
  539. break;
  540. case JCS_EXT_BGR:
  541. neonfct = jsimd_h2v2_extbgr_merged_upsample_neon;
  542. break;
  543. case JCS_EXT_BGRX:
  544. case JCS_EXT_BGRA:
  545. neonfct = jsimd_h2v2_extbgrx_merged_upsample_neon;
  546. break;
  547. case JCS_EXT_XBGR:
  548. case JCS_EXT_ABGR:
  549. neonfct = jsimd_h2v2_extxbgr_merged_upsample_neon;
  550. break;
  551. case JCS_EXT_XRGB:
  552. case JCS_EXT_ARGB:
  553. neonfct = jsimd_h2v2_extxrgb_merged_upsample_neon;
  554. break;
  555. default:
  556. neonfct = jsimd_h2v2_extrgb_merged_upsample_neon;
  557. break;
  558. }
  559. neonfct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
  560. }
  561. GLOBAL(void)
  562. jsimd_h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  563. JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
  564. {
  565. void (*neonfct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
  566. switch (cinfo->out_color_space) {
  567. case JCS_EXT_RGB:
  568. neonfct = jsimd_h2v1_extrgb_merged_upsample_neon;
  569. break;
  570. case JCS_EXT_RGBX:
  571. case JCS_EXT_RGBA:
  572. neonfct = jsimd_h2v1_extrgbx_merged_upsample_neon;
  573. break;
  574. case JCS_EXT_BGR:
  575. neonfct = jsimd_h2v1_extbgr_merged_upsample_neon;
  576. break;
  577. case JCS_EXT_BGRX:
  578. case JCS_EXT_BGRA:
  579. neonfct = jsimd_h2v1_extbgrx_merged_upsample_neon;
  580. break;
  581. case JCS_EXT_XBGR:
  582. case JCS_EXT_ABGR:
  583. neonfct = jsimd_h2v1_extxbgr_merged_upsample_neon;
  584. break;
  585. case JCS_EXT_XRGB:
  586. case JCS_EXT_ARGB:
  587. neonfct = jsimd_h2v1_extxrgb_merged_upsample_neon;
  588. break;
  589. default:
  590. neonfct = jsimd_h2v1_extrgb_merged_upsample_neon;
  591. break;
  592. }
  593. neonfct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
  594. }
  595. GLOBAL(int)
  596. jsimd_can_convsamp(void)
  597. {
  598. init_simd();
  599. /* The code is optimised for these values only */
  600. if (DCTSIZE != 8)
  601. return 0;
  602. if (BITS_IN_JSAMPLE != 8)
  603. return 0;
  604. if (sizeof(JDIMENSION) != 4)
  605. return 0;
  606. if (sizeof(DCTELEM) != 2)
  607. return 0;
  608. if (simd_support & JSIMD_NEON)
  609. return 1;
  610. return 0;
  611. }
  612. GLOBAL(int)
  613. jsimd_can_convsamp_float(void)
  614. {
  615. return 0;
  616. }
  617. GLOBAL(void)
  618. jsimd_convsamp(JSAMPARRAY sample_data, JDIMENSION start_col,
  619. DCTELEM *workspace)
  620. {
  621. jsimd_convsamp_neon(sample_data, start_col, workspace);
  622. }
  623. GLOBAL(void)
  624. jsimd_convsamp_float(JSAMPARRAY sample_data, JDIMENSION start_col,
  625. FAST_FLOAT *workspace)
  626. {
  627. }
  628. GLOBAL(int)
  629. jsimd_can_fdct_islow(void)
  630. {
  631. init_simd();
  632. /* The code is optimised for these values only */
  633. if (DCTSIZE != 8)
  634. return 0;
  635. if (sizeof(DCTELEM) != 2)
  636. return 0;
  637. if (simd_support & JSIMD_NEON)
  638. return 1;
  639. return 0;
  640. }
  641. GLOBAL(int)
  642. jsimd_can_fdct_ifast(void)
  643. {
  644. init_simd();
  645. /* The code is optimised for these values only */
  646. if (DCTSIZE != 8)
  647. return 0;
  648. if (sizeof(DCTELEM) != 2)
  649. return 0;
  650. if (simd_support & JSIMD_NEON)
  651. return 1;
  652. return 0;
  653. }
  654. GLOBAL(int)
  655. jsimd_can_fdct_float(void)
  656. {
  657. return 0;
  658. }
  659. GLOBAL(void)
  660. jsimd_fdct_islow(DCTELEM *data)
  661. {
  662. jsimd_fdct_islow_neon(data);
  663. }
  664. GLOBAL(void)
  665. jsimd_fdct_ifast(DCTELEM *data)
  666. {
  667. jsimd_fdct_ifast_neon(data);
  668. }
  669. GLOBAL(void)
  670. jsimd_fdct_float(FAST_FLOAT *data)
  671. {
  672. }
  673. GLOBAL(int)
  674. jsimd_can_quantize(void)
  675. {
  676. init_simd();
  677. /* The code is optimised for these values only */
  678. if (DCTSIZE != 8)
  679. return 0;
  680. if (sizeof(JCOEF) != 2)
  681. return 0;
  682. if (sizeof(DCTELEM) != 2)
  683. return 0;
  684. if (simd_support & JSIMD_NEON)
  685. return 1;
  686. return 0;
  687. }
  688. GLOBAL(int)
  689. jsimd_can_quantize_float(void)
  690. {
  691. return 0;
  692. }
  693. GLOBAL(void)
  694. jsimd_quantize(JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace)
  695. {
  696. jsimd_quantize_neon(coef_block, divisors, workspace);
  697. }
  698. GLOBAL(void)
  699. jsimd_quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors,
  700. FAST_FLOAT *workspace)
  701. {
  702. }
  703. GLOBAL(int)
  704. jsimd_can_idct_2x2(void)
  705. {
  706. init_simd();
  707. /* The code is optimised for these values only */
  708. if (DCTSIZE != 8)
  709. return 0;
  710. if (sizeof(JCOEF) != 2)
  711. return 0;
  712. if (BITS_IN_JSAMPLE != 8)
  713. return 0;
  714. if (sizeof(JDIMENSION) != 4)
  715. return 0;
  716. if (sizeof(ISLOW_MULT_TYPE) != 2)
  717. return 0;
  718. if (simd_support & JSIMD_NEON)
  719. return 1;
  720. return 0;
  721. }
  722. GLOBAL(int)
  723. jsimd_can_idct_4x4(void)
  724. {
  725. init_simd();
  726. /* The code is optimised for these values only */
  727. if (DCTSIZE != 8)
  728. return 0;
  729. if (sizeof(JCOEF) != 2)
  730. return 0;
  731. if (BITS_IN_JSAMPLE != 8)
  732. return 0;
  733. if (sizeof(JDIMENSION) != 4)
  734. return 0;
  735. if (sizeof(ISLOW_MULT_TYPE) != 2)
  736. return 0;
  737. if (simd_support & JSIMD_NEON)
  738. return 1;
  739. return 0;
  740. }
  741. GLOBAL(void)
  742. jsimd_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  743. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  744. JDIMENSION output_col)
  745. {
  746. jsimd_idct_2x2_neon(compptr->dct_table, coef_block, output_buf, output_col);
  747. }
  748. GLOBAL(void)
  749. jsimd_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  750. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  751. JDIMENSION output_col)
  752. {
  753. jsimd_idct_4x4_neon(compptr->dct_table, coef_block, output_buf, output_col);
  754. }
  755. GLOBAL(int)
  756. jsimd_can_idct_islow(void)
  757. {
  758. init_simd();
  759. /* The code is optimised for these values only */
  760. if (DCTSIZE != 8)
  761. return 0;
  762. if (sizeof(JCOEF) != 2)
  763. return 0;
  764. if (BITS_IN_JSAMPLE != 8)
  765. return 0;
  766. if (sizeof(JDIMENSION) != 4)
  767. return 0;
  768. if (sizeof(ISLOW_MULT_TYPE) != 2)
  769. return 0;
  770. if (simd_support & JSIMD_NEON)
  771. return 1;
  772. return 0;
  773. }
  774. GLOBAL(int)
  775. jsimd_can_idct_ifast(void)
  776. {
  777. init_simd();
  778. /* The code is optimised for these values only */
  779. if (DCTSIZE != 8)
  780. return 0;
  781. if (sizeof(JCOEF) != 2)
  782. return 0;
  783. if (BITS_IN_JSAMPLE != 8)
  784. return 0;
  785. if (sizeof(JDIMENSION) != 4)
  786. return 0;
  787. if (sizeof(IFAST_MULT_TYPE) != 2)
  788. return 0;
  789. if (IFAST_SCALE_BITS != 2)
  790. return 0;
  791. if (simd_support & JSIMD_NEON)
  792. return 1;
  793. return 0;
  794. }
  795. GLOBAL(int)
  796. jsimd_can_idct_float(void)
  797. {
  798. return 0;
  799. }
  800. GLOBAL(void)
  801. jsimd_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  802. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  803. JDIMENSION output_col)
  804. {
  805. jsimd_idct_islow_neon(compptr->dct_table, coef_block, output_buf,
  806. output_col);
  807. }
  808. GLOBAL(void)
  809. jsimd_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  810. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  811. JDIMENSION output_col)
  812. {
  813. jsimd_idct_ifast_neon(compptr->dct_table, coef_block, output_buf,
  814. output_col);
  815. }
  816. GLOBAL(void)
  817. jsimd_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  818. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  819. JDIMENSION output_col)
  820. {
  821. }
  822. GLOBAL(int)
  823. jsimd_can_huff_encode_one_block(void)
  824. {
  825. init_simd();
  826. if (DCTSIZE != 8)
  827. return 0;
  828. if (sizeof(JCOEF) != 2)
  829. return 0;
  830. if (simd_support & JSIMD_NEON && simd_huffman)
  831. return 1;
  832. return 0;
  833. }
  834. GLOBAL(JOCTET *)
  835. jsimd_huff_encode_one_block(void *state, JOCTET *buffer, JCOEFPTR block,
  836. int last_dc_val, c_derived_tbl *dctbl,
  837. c_derived_tbl *actbl)
  838. {
  839. #ifndef NEON_INTRINSICS
  840. if (simd_features & JSIMD_FASTTBL)
  841. #endif
  842. return jsimd_huff_encode_one_block_neon(state, buffer, block, last_dc_val,
  843. dctbl, actbl);
  844. #ifndef NEON_INTRINSICS
  845. else
  846. return jsimd_huff_encode_one_block_neon_slowtbl(state, buffer, block,
  847. last_dc_val, dctbl, actbl);
  848. #endif
  849. }
  850. GLOBAL(int)
  851. jsimd_can_encode_mcu_AC_first_prepare(void)
  852. {
  853. init_simd();
  854. if (DCTSIZE != 8)
  855. return 0;
  856. if (sizeof(JCOEF) != 2)
  857. return 0;
  858. if (SIZEOF_SIZE_T != 8)
  859. return 0;
  860. if (simd_support & JSIMD_NEON)
  861. return 1;
  862. return 0;
  863. }
  864. GLOBAL(void)
  865. jsimd_encode_mcu_AC_first_prepare(const JCOEF *block,
  866. const int *jpeg_natural_order_start, int Sl,
  867. int Al, UJCOEF *values, size_t *zerobits)
  868. {
  869. jsimd_encode_mcu_AC_first_prepare_neon(block, jpeg_natural_order_start,
  870. Sl, Al, values, zerobits);
  871. }
  872. GLOBAL(int)
  873. jsimd_can_encode_mcu_AC_refine_prepare(void)
  874. {
  875. init_simd();
  876. if (DCTSIZE != 8)
  877. return 0;
  878. if (sizeof(JCOEF) != 2)
  879. return 0;
  880. if (SIZEOF_SIZE_T != 8)
  881. return 0;
  882. if (simd_support & JSIMD_NEON)
  883. return 1;
  884. return 0;
  885. }
  886. GLOBAL(int)
  887. jsimd_encode_mcu_AC_refine_prepare(const JCOEF *block,
  888. const int *jpeg_natural_order_start, int Sl,
  889. int Al, UJCOEF *absvalues, size_t *bits)
  890. {
  891. return jsimd_encode_mcu_AC_refine_prepare_neon(block,
  892. jpeg_natural_order_start,
  893. Sl, Al, absvalues, bits);
  894. }