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