Changeset 103316 in vbox for trunk/src/libs/libpng-1.6.42/contrib/mips-msa
- Timestamp:
- Feb 12, 2024 3:57:56 PM (12 months ago)
- svn:sync-xref-src-repo-rev:
- 161613
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/libpng-1.6.42/contrib/mips-msa/linux.c
r96425 r103316 1 1 2 /* contrib/mips-msa/linux.c 2 3 * 4 * Copyright (c) 2020-2023 Cosmin Truta 3 5 * Copyright (c) 2016 Glenn Randers-Pehrson 4 6 * Written by Mandar Sahastrabuddhe, 2016. 5 * Last changed in libpng 1.6.25beta03 [August 29, 2016]7 * Updated by Sui Jingfeng, 2021. 6 8 * 7 9 * This code is released under the libpng license. … … 9 11 * and license in png.h 10 12 * 11 * SEE contrib/mips-msa/README before reporting bugs 13 * On Linux, png_have_msa is implemented by reading the pseudo-file 14 * "/proc/self/auxv". 15 * 16 * See contrib/mips-msa/README before reporting bugs. 12 17 * 13 18 * STATUS: SUPPORTED 14 19 * BUG REPORTS: [email protected] 15 *16 * png_have_msa implemented for Linux by reading the widely available17 * pseudo-file /proc/cpuinfo.18 *19 * This code is strict ANSI-C and is probably moderately portable; it does20 * however use <stdio.h> and it assumes that /proc/cpuinfo is never localized.21 20 */ 22 21 23 #include < stdio.h>24 #include < string.h>22 #include <elf.h> 23 #include <fcntl.h> 25 24 #include <stdlib.h> 25 #include <unistd.h> 26 26 27 27 static int 28 28 png_have_msa(png_structp png_ptr) 29 29 { 30 FILE *f = fopen("/proc/cpuinfo", "rb"); 30 Elf64_auxv_t aux; 31 int fd; 32 int has_msa = 0; 31 33 32 char *string = "msa"; 33 char word[10]; 34 fd = open("/proc/self/auxv", O_RDONLY); 35 if (fd >= 0) 36 { 37 while (read(fd, &aux, sizeof(Elf64_auxv_t)) == sizeof(Elf64_auxv_t)) 38 { 39 if (aux.a_type == AT_HWCAP) 40 { 41 uint64_t hwcap = aux.a_un.a_val; 34 42 35 if (f != NULL) 36 { 37 while(!feof(f)) 38 { 39 int ch = fgetc(f); 40 static int i = 0; 41 42 while(!(ch <= 32)) 43 { 44 word[i++] = ch; 45 ch = fgetc(f); 43 has_msa = (hwcap >> 1) & 1; 44 break; 46 45 } 47 48 int val = strcmp(string, word);49 50 if (val == 0)51 return 1;52 53 i = 0;54 memset(word, 0, 10);55 46 } 56 57 fclose(f); 47 close(fd); 58 48 } 59 49 #ifdef PNG_WARNINGS_SUPPORTED 60 50 else 61 png_warning(png_ptr, "/proc/ cpuinfoopen failed");51 png_warning(png_ptr, "/proc/self/auxv open failed"); 62 52 #endif 63 return 0; 53 54 return has_msa; 64 55 }
Note:
See TracChangeset
for help on using the changeset viewer.