/src/cairo/subprojects/pixman-0.44.2/pixman/pixman-mips.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright © 2000 SuSE, Inc. |
3 | | * Copyright © 2007 Red Hat, Inc. |
4 | | * |
5 | | * Permission to use, copy, modify, distribute, and sell this software and its |
6 | | * documentation for any purpose is hereby granted without fee, provided that |
7 | | * the above copyright notice appear in all copies and that both that |
8 | | * copyright notice and this permission notice appear in supporting |
9 | | * documentation, and that the name of SuSE not be used in advertising or |
10 | | * publicity pertaining to distribution of the software without specific, |
11 | | * written prior permission. SuSE makes no representations about the |
12 | | * suitability of this software for any purpose. It is provided "as is" |
13 | | * without express or implied warranty. |
14 | | * |
15 | | * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL |
16 | | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE |
17 | | * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
18 | | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
19 | | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
20 | | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
21 | | */ |
22 | | #ifdef HAVE_CONFIG_H |
23 | | #include <pixman-config.h> |
24 | | #endif |
25 | | |
26 | | #include "pixman-private.h" |
27 | | |
28 | | #if defined(USE_MIPS_DSPR2) || defined(USE_LOONGSON_MMI) |
29 | | |
30 | | #include <string.h> |
31 | | #include <stdlib.h> |
32 | | |
33 | | static pixman_bool_t |
34 | | have_feature (const char *search_string) |
35 | | { |
36 | | #if defined (__linux__) /* linux ELF */ |
37 | | /* Simple detection of MIPS features at runtime for Linux. |
38 | | * It is based on /proc/cpuinfo, which reveals hardware configuration |
39 | | * to user-space applications. According to MIPS (early 2010), no similar |
40 | | * facility is universally available on the MIPS architectures, so it's up |
41 | | * to individual OSes to provide such. |
42 | | */ |
43 | | const char *file_name = "/proc/cpuinfo"; |
44 | | char cpuinfo_line[256]; |
45 | | FILE *f = NULL; |
46 | | |
47 | | if ((f = fopen (file_name, "r")) == NULL) |
48 | | return FALSE; |
49 | | |
50 | | while (fgets (cpuinfo_line, sizeof (cpuinfo_line), f) != NULL) |
51 | | { |
52 | | if (strstr (cpuinfo_line, search_string) != NULL) |
53 | | { |
54 | | fclose (f); |
55 | | return TRUE; |
56 | | } |
57 | | } |
58 | | |
59 | | fclose (f); |
60 | | #endif |
61 | | |
62 | | #if defined (CI_HAS_ALL_MIPS_CPU_FEATURES) |
63 | | /* Used to force feature discovery in CI where /proc/cpuinfo is unreliable. |
64 | | * It can happen, e.g., if executed in qemu-user-static mode. |
65 | | * |
66 | | * For such a build, MIPS-specific features need to be manually disabled by |
67 | | * using `PIXMAN_DISABLE` env variable |
68 | | * |
69 | | * SHOULD NOT BE USED IN RELEASE BUILD! |
70 | | */ |
71 | | #warning "Building with disabled MIPS feature discovery. SHOULD NOT BE USED IN RELEASE BUILD!" |
72 | | return TRUE; |
73 | | #endif |
74 | | |
75 | | /* Did not find string in the proc file, or not Linux ELF. */ |
76 | | return FALSE; |
77 | | } |
78 | | |
79 | | #endif |
80 | | |
81 | | pixman_implementation_t * |
82 | | _pixman_mips_get_implementations (pixman_implementation_t *imp) |
83 | 12 | { |
84 | | #ifdef USE_LOONGSON_MMI |
85 | | /* I really don't know if some Loongson CPUs don't have MMI. */ |
86 | | if (!_pixman_disabled ("loongson-mmi") && have_feature ("Loongson")) |
87 | | imp = _pixman_implementation_create_mmx (imp); |
88 | | #endif |
89 | | |
90 | | #ifdef USE_MIPS_DSPR2 |
91 | | if (!_pixman_disabled ("mips-dspr2")) |
92 | | { |
93 | | int already_compiling_everything_for_dspr2 = 0; |
94 | | #if defined(__mips_dsp) && (__mips_dsp_rev >= 2) |
95 | | already_compiling_everything_for_dspr2 = 1; |
96 | | #endif |
97 | | if (already_compiling_everything_for_dspr2 || |
98 | | /* Only currently available MIPS core that supports DSPr2 is 74K. */ |
99 | | have_feature ("MIPS 74K")) |
100 | | { |
101 | | imp = _pixman_implementation_create_mips_dspr2 (imp); |
102 | | } |
103 | | } |
104 | | #endif |
105 | | |
106 | 12 | return imp; |
107 | 12 | } |