Skip to content
0.2.0-dev Download ZIP
66 lines ·2.0 KB Raw
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 <jinbo@loongson.cn>
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)
20static int
21png_has_lsx(void)
22{
23 int flags = 0;
24 int flag = (int)getauxval(AT_HWCAP);
25
26 if (flag & LA_HWCAP_LSX)
27 return 1;
28
29 return 0;
30}
31
32void
33png_init_filter_functions_lsx(png_structp pp, unsigned int bpp)
34{
35 /* IMPORTANT: any new external functions used here must be declared using
36 * PNG_INTERNAL_FUNCTION in ../pngpriv.h. This is required so that the
37 * 'prefix' option to configure works:
38 *
39 * ./configure --with-libpng-prefix=foobar_
40 *
41 * Verify you have got this right by running the above command, doing a build
42 * and examining pngprefix.h; it must contain a #define for every external
43 * function you add. (Notice that this happens automatically for the
44 * initialization function.)
45 */
46
47 if (png_has_lsx())
48 {
49 pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_lsx;
50 if (bpp == 3)
51 {
52 pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_lsx;
53 pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_lsx;
54 pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = png_read_filter_row_paeth3_lsx;
55 }
56 else if (bpp == 4)
57 {
58 pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_lsx;
59 pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_lsx;
60 pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = png_read_filter_row_paeth4_lsx;
61 }
62 }
63}
64
65#endif /* PNG_LOONGARCH_LSX_IMPLEMENTATION == 1 */
66#endif /* PNG_READ_SUPPORTED */