jsimd.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. /*
  2. * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
  3. * Copyright (C) 2009-2011, 2014-2016, 2018, 2022, 2024, D. R. Commander.
  4. * Copyright (C) 2015-2016, 2018, 2022, Matthieu Darbois.
  5. *
  6. * Based on the x86 SIMD extension for IJG JPEG library,
  7. * Copyright (C) 1999-2006, MIYASAKA Masaru.
  8. * For conditions of distribution and use, see copyright notice in jsimdext.inc
  9. *
  10. * This file contains the interface between the "normal" portions
  11. * of the library and the SIMD implementations when running on a
  12. * PowerPC architecture.
  13. */
  14. #ifdef __amigaos4__
  15. /* This must be defined first as it re-defines GLOBAL otherwise */
  16. #include <proto/exec.h>
  17. #endif
  18. #define JPEG_INTERNALS
  19. #include "../../src/jinclude.h"
  20. #include "../../src/jpeglib.h"
  21. #include "../../src/jsimd.h"
  22. #include "../../src/jdct.h"
  23. #include "../../src/jsimddct.h"
  24. #include "../jsimd.h"
  25. #include <ctype.h>
  26. #if defined(__APPLE__)
  27. #include <sys/types.h>
  28. #include <sys/sysctl.h>
  29. #elif defined(__OpenBSD__)
  30. #include <sys/param.h>
  31. #include <sys/sysctl.h>
  32. #include <machine/cpu.h>
  33. #elif defined(__FreeBSD__)
  34. #include <machine/cpu.h>
  35. #include <sys/auxv.h>
  36. #endif
  37. static THREAD_LOCAL unsigned int simd_support = ~0;
  38. #if !defined(__ALTIVEC__) && (defined(__linux__) || defined(ANDROID) || defined(__ANDROID__))
  39. #define SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT (1024 * 1024)
  40. LOCAL(int)
  41. check_feature(char *buffer, char *feature)
  42. {
  43. char *p;
  44. if (*feature == 0)
  45. return 0;
  46. if (strncmp(buffer, "cpu", 3) != 0)
  47. return 0;
  48. buffer += 3;
  49. while (isspace(*buffer))
  50. buffer++;
  51. /* Check if 'feature' is present in the buffer as a separate word */
  52. while ((p = strstr(buffer, feature))) {
  53. if (p > buffer && !isspace(*(p - 1))) {
  54. buffer++;
  55. continue;
  56. }
  57. p += strlen(feature);
  58. if (*p != 0 && !isspace(*p)) {
  59. buffer++;
  60. continue;
  61. }
  62. return 1;
  63. }
  64. return 0;
  65. }
  66. LOCAL(int)
  67. parse_proc_cpuinfo(int bufsize)
  68. {
  69. char *buffer = (char *)malloc(bufsize);
  70. FILE *fd;
  71. simd_support = 0;
  72. if (!buffer)
  73. return 0;
  74. fd = fopen("/proc/cpuinfo", "r");
  75. if (fd) {
  76. while (fgets(buffer, bufsize, fd)) {
  77. if (!strchr(buffer, '\n') && !feof(fd)) {
  78. /* "impossible" happened - insufficient size of the buffer! */
  79. fclose(fd);
  80. free(buffer);
  81. return 0;
  82. }
  83. if (check_feature(buffer, "altivec"))
  84. simd_support |= JSIMD_ALTIVEC;
  85. }
  86. fclose(fd);
  87. }
  88. free(buffer);
  89. return 1;
  90. }
  91. #endif
  92. /*
  93. * Check what SIMD accelerations are supported.
  94. */
  95. LOCAL(void)
  96. init_simd(void)
  97. {
  98. #ifndef NO_GETENV
  99. char *env = NULL;
  100. #endif
  101. #if !defined(__ALTIVEC__) && (defined(__linux__) || defined(ANDROID) || defined(__ANDROID__))
  102. int bufsize = 1024; /* an initial guess for the line buffer size limit */
  103. #elif defined(__amigaos4__)
  104. uint32 altivec = 0;
  105. #elif defined(__APPLE__)
  106. int mib[2] = { CTL_HW, HW_VECTORUNIT };
  107. int altivec;
  108. size_t len = sizeof(altivec);
  109. #elif defined(__OpenBSD__)
  110. int mib[2] = { CTL_MACHDEP, CPU_ALTIVEC };
  111. int altivec;
  112. size_t len = sizeof(altivec);
  113. #elif defined(__FreeBSD__)
  114. unsigned long cpufeatures = 0;
  115. #endif
  116. if (simd_support != ~0U)
  117. return;
  118. simd_support = 0;
  119. #if defined(__ALTIVEC__)
  120. simd_support |= JSIMD_ALTIVEC;
  121. #elif defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
  122. while (!parse_proc_cpuinfo(bufsize)) {
  123. bufsize *= 2;
  124. if (bufsize > SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT)
  125. break;
  126. }
  127. #elif defined(__amigaos4__)
  128. IExec->GetCPUInfoTags(GCIT_VectorUnit, &altivec, TAG_DONE);
  129. if (altivec == VECTORTYPE_ALTIVEC)
  130. simd_support |= JSIMD_ALTIVEC;
  131. #elif defined(__APPLE__) || defined(__OpenBSD__)
  132. if (sysctl(mib, 2, &altivec, &len, NULL, 0) == 0 && altivec != 0)
  133. simd_support |= JSIMD_ALTIVEC;
  134. #elif defined(__FreeBSD__)
  135. elf_aux_info(AT_HWCAP, &cpufeatures, sizeof(cpufeatures));
  136. if (cpufeatures & PPC_FEATURE_HAS_ALTIVEC)
  137. simd_support |= JSIMD_ALTIVEC;
  138. #endif
  139. #ifndef NO_GETENV
  140. /* Force different settings through environment variables */
  141. env = getenv("JSIMD_FORCEALTIVEC");
  142. if ((env != NULL) && (strcmp(env, "1") == 0))
  143. simd_support = JSIMD_ALTIVEC;
  144. env = getenv("JSIMD_FORCENONE");
  145. if ((env != NULL) && (strcmp(env, "1") == 0))
  146. simd_support = 0;
  147. #endif
  148. }
  149. GLOBAL(int)
  150. jsimd_can_rgb_ycc(void)
  151. {
  152. init_simd();
  153. /* The code is optimised for these values only */
  154. if (BITS_IN_JSAMPLE != 8)
  155. return 0;
  156. if (sizeof(JDIMENSION) != 4)
  157. return 0;
  158. if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
  159. return 0;
  160. if (simd_support & JSIMD_ALTIVEC)
  161. return 1;
  162. return 0;
  163. }
  164. GLOBAL(int)
  165. jsimd_can_rgb_gray(void)
  166. {
  167. init_simd();
  168. /* The code is optimised for these values only */
  169. if (BITS_IN_JSAMPLE != 8)
  170. return 0;
  171. if (sizeof(JDIMENSION) != 4)
  172. return 0;
  173. if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
  174. return 0;
  175. if (simd_support & JSIMD_ALTIVEC)
  176. return 1;
  177. return 0;
  178. }
  179. GLOBAL(int)
  180. jsimd_can_ycc_rgb(void)
  181. {
  182. init_simd();
  183. /* The code is optimised for these values only */
  184. if (BITS_IN_JSAMPLE != 8)
  185. return 0;
  186. if (sizeof(JDIMENSION) != 4)
  187. return 0;
  188. if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4))
  189. return 0;
  190. if (simd_support & JSIMD_ALTIVEC)
  191. return 1;
  192. return 0;
  193. }
  194. GLOBAL(int)
  195. jsimd_can_ycc_rgb565(void)
  196. {
  197. return 0;
  198. }
  199. GLOBAL(void)
  200. jsimd_rgb_ycc_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
  201. JSAMPIMAGE output_buf, JDIMENSION output_row,
  202. int num_rows)
  203. {
  204. void (*altivecfct) (JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
  205. switch (cinfo->in_color_space) {
  206. case JCS_EXT_RGB:
  207. altivecfct = jsimd_extrgb_ycc_convert_altivec;
  208. break;
  209. case JCS_EXT_RGBX:
  210. case JCS_EXT_RGBA:
  211. altivecfct = jsimd_extrgbx_ycc_convert_altivec;
  212. break;
  213. case JCS_EXT_BGR:
  214. altivecfct = jsimd_extbgr_ycc_convert_altivec;
  215. break;
  216. case JCS_EXT_BGRX:
  217. case JCS_EXT_BGRA:
  218. altivecfct = jsimd_extbgrx_ycc_convert_altivec;
  219. break;
  220. case JCS_EXT_XBGR:
  221. case JCS_EXT_ABGR:
  222. altivecfct = jsimd_extxbgr_ycc_convert_altivec;
  223. break;
  224. case JCS_EXT_XRGB:
  225. case JCS_EXT_ARGB:
  226. altivecfct = jsimd_extxrgb_ycc_convert_altivec;
  227. break;
  228. default:
  229. altivecfct = jsimd_rgb_ycc_convert_altivec;
  230. break;
  231. }
  232. altivecfct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
  233. }
  234. GLOBAL(void)
  235. jsimd_rgb_gray_convert(j_compress_ptr cinfo, JSAMPARRAY input_buf,
  236. JSAMPIMAGE output_buf, JDIMENSION output_row,
  237. int num_rows)
  238. {
  239. void (*altivecfct) (JDIMENSION, JSAMPARRAY, JSAMPIMAGE, JDIMENSION, int);
  240. switch (cinfo->in_color_space) {
  241. case JCS_EXT_RGB:
  242. altivecfct = jsimd_extrgb_gray_convert_altivec;
  243. break;
  244. case JCS_EXT_RGBX:
  245. case JCS_EXT_RGBA:
  246. altivecfct = jsimd_extrgbx_gray_convert_altivec;
  247. break;
  248. case JCS_EXT_BGR:
  249. altivecfct = jsimd_extbgr_gray_convert_altivec;
  250. break;
  251. case JCS_EXT_BGRX:
  252. case JCS_EXT_BGRA:
  253. altivecfct = jsimd_extbgrx_gray_convert_altivec;
  254. break;
  255. case JCS_EXT_XBGR:
  256. case JCS_EXT_ABGR:
  257. altivecfct = jsimd_extxbgr_gray_convert_altivec;
  258. break;
  259. case JCS_EXT_XRGB:
  260. case JCS_EXT_ARGB:
  261. altivecfct = jsimd_extxrgb_gray_convert_altivec;
  262. break;
  263. default:
  264. altivecfct = jsimd_rgb_gray_convert_altivec;
  265. break;
  266. }
  267. altivecfct(cinfo->image_width, input_buf, output_buf, output_row, num_rows);
  268. }
  269. GLOBAL(void)
  270. jsimd_ycc_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  271. JDIMENSION input_row, JSAMPARRAY output_buf,
  272. int num_rows)
  273. {
  274. void (*altivecfct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int);
  275. switch (cinfo->out_color_space) {
  276. case JCS_EXT_RGB:
  277. altivecfct = jsimd_ycc_extrgb_convert_altivec;
  278. break;
  279. case JCS_EXT_RGBX:
  280. case JCS_EXT_RGBA:
  281. altivecfct = jsimd_ycc_extrgbx_convert_altivec;
  282. break;
  283. case JCS_EXT_BGR:
  284. altivecfct = jsimd_ycc_extbgr_convert_altivec;
  285. break;
  286. case JCS_EXT_BGRX:
  287. case JCS_EXT_BGRA:
  288. altivecfct = jsimd_ycc_extbgrx_convert_altivec;
  289. break;
  290. case JCS_EXT_XBGR:
  291. case JCS_EXT_ABGR:
  292. altivecfct = jsimd_ycc_extxbgr_convert_altivec;
  293. break;
  294. case JCS_EXT_XRGB:
  295. case JCS_EXT_ARGB:
  296. altivecfct = jsimd_ycc_extxrgb_convert_altivec;
  297. break;
  298. default:
  299. altivecfct = jsimd_ycc_rgb_convert_altivec;
  300. break;
  301. }
  302. altivecfct(cinfo->output_width, input_buf, input_row, output_buf, num_rows);
  303. }
  304. GLOBAL(void)
  305. jsimd_ycc_rgb565_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  306. JDIMENSION input_row, JSAMPARRAY output_buf,
  307. int num_rows)
  308. {
  309. }
  310. GLOBAL(int)
  311. jsimd_can_h2v2_downsample(void)
  312. {
  313. init_simd();
  314. /* The code is optimised for these values only */
  315. if (BITS_IN_JSAMPLE != 8)
  316. return 0;
  317. if (sizeof(JDIMENSION) != 4)
  318. return 0;
  319. if (simd_support & JSIMD_ALTIVEC)
  320. return 1;
  321. return 0;
  322. }
  323. GLOBAL(int)
  324. jsimd_can_h2v1_downsample(void)
  325. {
  326. init_simd();
  327. /* The code is optimised for these values only */
  328. if (BITS_IN_JSAMPLE != 8)
  329. return 0;
  330. if (sizeof(JDIMENSION) != 4)
  331. return 0;
  332. if (simd_support & JSIMD_ALTIVEC)
  333. return 1;
  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_altivec(cinfo->image_width, cinfo->max_v_samp_factor,
  341. compptr->v_samp_factor,
  342. compptr->width_in_blocks, input_data,
  343. output_data);
  344. }
  345. GLOBAL(void)
  346. jsimd_h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
  347. JSAMPARRAY input_data, JSAMPARRAY output_data)
  348. {
  349. jsimd_h2v1_downsample_altivec(cinfo->image_width, cinfo->max_v_samp_factor,
  350. compptr->v_samp_factor,
  351. compptr->width_in_blocks, input_data,
  352. output_data);
  353. }
  354. GLOBAL(int)
  355. jsimd_can_h2v2_upsample(void)
  356. {
  357. init_simd();
  358. /* The code is optimised for these values only */
  359. if (BITS_IN_JSAMPLE != 8)
  360. return 0;
  361. if (sizeof(JDIMENSION) != 4)
  362. return 0;
  363. if (simd_support & JSIMD_ALTIVEC)
  364. return 1;
  365. return 0;
  366. }
  367. GLOBAL(int)
  368. jsimd_can_h2v1_upsample(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 (sizeof(JDIMENSION) != 4)
  375. return 0;
  376. if (simd_support & JSIMD_ALTIVEC)
  377. return 1;
  378. return 0;
  379. }
  380. GLOBAL(void)
  381. jsimd_h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  382. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  383. {
  384. jsimd_h2v2_upsample_altivec(cinfo->max_v_samp_factor, cinfo->output_width,
  385. input_data, output_data_ptr);
  386. }
  387. GLOBAL(void)
  388. jsimd_h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  389. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  390. {
  391. jsimd_h2v1_upsample_altivec(cinfo->max_v_samp_factor, cinfo->output_width,
  392. input_data, output_data_ptr);
  393. }
  394. GLOBAL(int)
  395. jsimd_can_h2v2_fancy_upsample(void)
  396. {
  397. init_simd();
  398. /* The code is optimised for these values only */
  399. if (BITS_IN_JSAMPLE != 8)
  400. return 0;
  401. if (sizeof(JDIMENSION) != 4)
  402. return 0;
  403. if (simd_support & JSIMD_ALTIVEC)
  404. return 1;
  405. return 0;
  406. }
  407. GLOBAL(int)
  408. jsimd_can_h2v1_fancy_upsample(void)
  409. {
  410. init_simd();
  411. /* The code is optimised for these values only */
  412. if (BITS_IN_JSAMPLE != 8)
  413. return 0;
  414. if (sizeof(JDIMENSION) != 4)
  415. return 0;
  416. if (simd_support & JSIMD_ALTIVEC)
  417. return 1;
  418. return 0;
  419. }
  420. GLOBAL(void)
  421. jsimd_h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  422. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  423. {
  424. jsimd_h2v2_fancy_upsample_altivec(cinfo->max_v_samp_factor,
  425. compptr->downsampled_width, input_data,
  426. output_data_ptr);
  427. }
  428. GLOBAL(void)
  429. jsimd_h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  430. JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
  431. {
  432. jsimd_h2v1_fancy_upsample_altivec(cinfo->max_v_samp_factor,
  433. compptr->downsampled_width, input_data,
  434. output_data_ptr);
  435. }
  436. GLOBAL(int)
  437. jsimd_can_h2v2_merged_upsample(void)
  438. {
  439. init_simd();
  440. /* The code is optimised for these values only */
  441. if (BITS_IN_JSAMPLE != 8)
  442. return 0;
  443. if (sizeof(JDIMENSION) != 4)
  444. return 0;
  445. if (simd_support & JSIMD_ALTIVEC)
  446. return 1;
  447. return 0;
  448. }
  449. GLOBAL(int)
  450. jsimd_can_h2v1_merged_upsample(void)
  451. {
  452. init_simd();
  453. /* The code is optimised for these values only */
  454. if (BITS_IN_JSAMPLE != 8)
  455. return 0;
  456. if (sizeof(JDIMENSION) != 4)
  457. return 0;
  458. if (simd_support & JSIMD_ALTIVEC)
  459. return 1;
  460. return 0;
  461. }
  462. GLOBAL(void)
  463. jsimd_h2v2_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  464. JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
  465. {
  466. void (*altivecfct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
  467. switch (cinfo->out_color_space) {
  468. case JCS_EXT_RGB:
  469. altivecfct = jsimd_h2v2_extrgb_merged_upsample_altivec;
  470. break;
  471. case JCS_EXT_RGBX:
  472. case JCS_EXT_RGBA:
  473. altivecfct = jsimd_h2v2_extrgbx_merged_upsample_altivec;
  474. break;
  475. case JCS_EXT_BGR:
  476. altivecfct = jsimd_h2v2_extbgr_merged_upsample_altivec;
  477. break;
  478. case JCS_EXT_BGRX:
  479. case JCS_EXT_BGRA:
  480. altivecfct = jsimd_h2v2_extbgrx_merged_upsample_altivec;
  481. break;
  482. case JCS_EXT_XBGR:
  483. case JCS_EXT_ABGR:
  484. altivecfct = jsimd_h2v2_extxbgr_merged_upsample_altivec;
  485. break;
  486. case JCS_EXT_XRGB:
  487. case JCS_EXT_ARGB:
  488. altivecfct = jsimd_h2v2_extxrgb_merged_upsample_altivec;
  489. break;
  490. default:
  491. altivecfct = jsimd_h2v2_merged_upsample_altivec;
  492. break;
  493. }
  494. altivecfct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
  495. }
  496. GLOBAL(void)
  497. jsimd_h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
  498. JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
  499. {
  500. void (*altivecfct) (JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY);
  501. switch (cinfo->out_color_space) {
  502. case JCS_EXT_RGB:
  503. altivecfct = jsimd_h2v1_extrgb_merged_upsample_altivec;
  504. break;
  505. case JCS_EXT_RGBX:
  506. case JCS_EXT_RGBA:
  507. altivecfct = jsimd_h2v1_extrgbx_merged_upsample_altivec;
  508. break;
  509. case JCS_EXT_BGR:
  510. altivecfct = jsimd_h2v1_extbgr_merged_upsample_altivec;
  511. break;
  512. case JCS_EXT_BGRX:
  513. case JCS_EXT_BGRA:
  514. altivecfct = jsimd_h2v1_extbgrx_merged_upsample_altivec;
  515. break;
  516. case JCS_EXT_XBGR:
  517. case JCS_EXT_ABGR:
  518. altivecfct = jsimd_h2v1_extxbgr_merged_upsample_altivec;
  519. break;
  520. case JCS_EXT_XRGB:
  521. case JCS_EXT_ARGB:
  522. altivecfct = jsimd_h2v1_extxrgb_merged_upsample_altivec;
  523. break;
  524. default:
  525. altivecfct = jsimd_h2v1_merged_upsample_altivec;
  526. break;
  527. }
  528. altivecfct(cinfo->output_width, input_buf, in_row_group_ctr, output_buf);
  529. }
  530. GLOBAL(int)
  531. jsimd_can_convsamp(void)
  532. {
  533. init_simd();
  534. /* The code is optimised for these values only */
  535. if (DCTSIZE != 8)
  536. return 0;
  537. if (BITS_IN_JSAMPLE != 8)
  538. return 0;
  539. if (sizeof(JDIMENSION) != 4)
  540. return 0;
  541. if (sizeof(DCTELEM) != 2)
  542. return 0;
  543. if (simd_support & JSIMD_ALTIVEC)
  544. return 1;
  545. return 0;
  546. }
  547. GLOBAL(int)
  548. jsimd_can_convsamp_float(void)
  549. {
  550. return 0;
  551. }
  552. GLOBAL(void)
  553. jsimd_convsamp(JSAMPARRAY sample_data, JDIMENSION start_col,
  554. DCTELEM *workspace)
  555. {
  556. jsimd_convsamp_altivec(sample_data, start_col, workspace);
  557. }
  558. GLOBAL(void)
  559. jsimd_convsamp_float(JSAMPARRAY sample_data, JDIMENSION start_col,
  560. FAST_FLOAT *workspace)
  561. {
  562. }
  563. GLOBAL(int)
  564. jsimd_can_fdct_islow(void)
  565. {
  566. init_simd();
  567. /* The code is optimised for these values only */
  568. if (DCTSIZE != 8)
  569. return 0;
  570. if (sizeof(DCTELEM) != 2)
  571. return 0;
  572. if (simd_support & JSIMD_ALTIVEC)
  573. return 1;
  574. return 0;
  575. }
  576. GLOBAL(int)
  577. jsimd_can_fdct_ifast(void)
  578. {
  579. init_simd();
  580. /* The code is optimised for these values only */
  581. if (DCTSIZE != 8)
  582. return 0;
  583. if (sizeof(DCTELEM) != 2)
  584. return 0;
  585. if (simd_support & JSIMD_ALTIVEC)
  586. return 1;
  587. return 0;
  588. }
  589. GLOBAL(int)
  590. jsimd_can_fdct_float(void)
  591. {
  592. return 0;
  593. }
  594. GLOBAL(void)
  595. jsimd_fdct_islow(DCTELEM *data)
  596. {
  597. jsimd_fdct_islow_altivec(data);
  598. }
  599. GLOBAL(void)
  600. jsimd_fdct_ifast(DCTELEM *data)
  601. {
  602. jsimd_fdct_ifast_altivec(data);
  603. }
  604. GLOBAL(void)
  605. jsimd_fdct_float(FAST_FLOAT *data)
  606. {
  607. }
  608. GLOBAL(int)
  609. jsimd_can_quantize(void)
  610. {
  611. init_simd();
  612. /* The code is optimised for these values only */
  613. if (DCTSIZE != 8)
  614. return 0;
  615. if (sizeof(JCOEF) != 2)
  616. return 0;
  617. if (sizeof(DCTELEM) != 2)
  618. return 0;
  619. if (simd_support & JSIMD_ALTIVEC)
  620. return 1;
  621. return 0;
  622. }
  623. GLOBAL(int)
  624. jsimd_can_quantize_float(void)
  625. {
  626. return 0;
  627. }
  628. GLOBAL(void)
  629. jsimd_quantize(JCOEFPTR coef_block, DCTELEM *divisors, DCTELEM *workspace)
  630. {
  631. jsimd_quantize_altivec(coef_block, divisors, workspace);
  632. }
  633. GLOBAL(void)
  634. jsimd_quantize_float(JCOEFPTR coef_block, FAST_FLOAT *divisors,
  635. FAST_FLOAT *workspace)
  636. {
  637. }
  638. GLOBAL(int)
  639. jsimd_can_idct_2x2(void)
  640. {
  641. return 0;
  642. }
  643. GLOBAL(int)
  644. jsimd_can_idct_4x4(void)
  645. {
  646. return 0;
  647. }
  648. GLOBAL(void)
  649. jsimd_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  650. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  651. JDIMENSION output_col)
  652. {
  653. }
  654. GLOBAL(void)
  655. jsimd_idct_4x4(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  656. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  657. JDIMENSION output_col)
  658. {
  659. }
  660. GLOBAL(int)
  661. jsimd_can_idct_islow(void)
  662. {
  663. init_simd();
  664. /* The code is optimised for these values only */
  665. if (DCTSIZE != 8)
  666. return 0;
  667. if (sizeof(JCOEF) != 2)
  668. return 0;
  669. if (simd_support & JSIMD_ALTIVEC)
  670. return 1;
  671. return 0;
  672. }
  673. GLOBAL(int)
  674. jsimd_can_idct_ifast(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 (simd_support & JSIMD_ALTIVEC)
  683. return 1;
  684. return 0;
  685. }
  686. GLOBAL(int)
  687. jsimd_can_idct_float(void)
  688. {
  689. return 0;
  690. }
  691. GLOBAL(void)
  692. jsimd_idct_islow(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  693. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  694. JDIMENSION output_col)
  695. {
  696. jsimd_idct_islow_altivec(compptr->dct_table, coef_block, output_buf,
  697. output_col);
  698. }
  699. GLOBAL(void)
  700. jsimd_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  701. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  702. JDIMENSION output_col)
  703. {
  704. jsimd_idct_ifast_altivec(compptr->dct_table, coef_block, output_buf,
  705. output_col);
  706. }
  707. GLOBAL(void)
  708. jsimd_idct_float(j_decompress_ptr cinfo, jpeg_component_info *compptr,
  709. JCOEFPTR coef_block, JSAMPARRAY output_buf,
  710. JDIMENSION output_col)
  711. {
  712. }
  713. GLOBAL(int)
  714. jsimd_can_huff_encode_one_block(void)
  715. {
  716. return 0;
  717. }
  718. GLOBAL(JOCTET *)
  719. jsimd_huff_encode_one_block(void *state, JOCTET *buffer, JCOEFPTR block,
  720. int last_dc_val, c_derived_tbl *dctbl,
  721. c_derived_tbl *actbl)
  722. {
  723. return NULL;
  724. }
  725. GLOBAL(int)
  726. jsimd_can_encode_mcu_AC_first_prepare(void)
  727. {
  728. return 0;
  729. }
  730. GLOBAL(void)
  731. jsimd_encode_mcu_AC_first_prepare(const JCOEF *block,
  732. const int *jpeg_natural_order_start, int Sl,
  733. int Al, UJCOEF *values, size_t *zerobits)
  734. {
  735. }
  736. GLOBAL(int)
  737. jsimd_can_encode_mcu_AC_refine_prepare(void)
  738. {
  739. return 0;
  740. }
  741. GLOBAL(int)
  742. jsimd_encode_mcu_AC_refine_prepare(const JCOEF *block,
  743. const int *jpeg_natural_order_start, int Sl,
  744. int Al, UJCOEF *absvalues, size_t *bits)
  745. {
  746. return 0;
  747. }