1 /* loongarch_lsx_init.c - LSX optimized filter functions 2 * 3 * Copyright (c) 2021 Loongson Technology Corporation Limited 4 * All rights reserved. 5 * Contributed by Jin Bo <[email protected]> 6 * 7 * This code is released under the libpng license. 8 * For conditions of distribution and use, see the disclaimer 9 * and license in png.h 10 */ 11 12 #include "../pngpriv.h" 13 14 #ifdef PNG_READ_SUPPORTED 15 #if PNG_LOONGARCH_LSX_IMPLEMENTATION == 1 16 17 #include <sys/auxv.h> 18 19 #define LA_HWCAP_LSX (1<<4) png_has_lsx(void)20static int png_has_lsx(void) 21 { 22 int flags = 0; 23 int flag = (int)getauxval(AT_HWCAP); 24 25 if (flag & LA_HWCAP_LSX) 26 return 1; 27 28 return 0; 29 } 30 31 void png_init_filter_functions_lsx(png_structp pp,unsigned int bpp)32png_init_filter_functions_lsx(png_structp pp, unsigned int bpp) 33 { 34 /* IMPORTANT: any new external functions used here must be declared using 35 * PNG_INTERNAL_FUNCTION in ../pngpriv.h. This is required so that the 36 * 'prefix' option to configure works: 37 * 38 * ./configure --with-libpng-prefix=foobar_ 39 * 40 * Verify you have got this right by running the above command, doing a build 41 * and examining pngprefix.h; it must contain a #define for every external 42 * function you add. (Notice that this happens automatically for the 43 * initialization function.) 44 */ 45 46 if (png_has_lsx()) 47 { 48 pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_lsx; 49 if (bpp == 3) 50 { 51 pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_lsx; 52 pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_lsx; 53 pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = png_read_filter_row_paeth3_lsx; 54 } 55 else if (bpp == 4) 56 { 57 pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_lsx; 58 pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_lsx; 59 pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = png_read_filter_row_paeth4_lsx; 60 } 61 } 62 } 63 64 #endif /* PNG_LOONGARCH_LSX_IMPLEMENTATION == 1 */ 65 #endif /* PNG_READ_SUPPORTED */ 66