mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[libpng15] Use approved/supported Android method to check for NEON, use Linux/POSIX
1003.1 API to check /proc/self/auxv avoiding buffer allocation and other library calls.
This commit is contained in:
parent
1679d4ce0f
commit
da3031a7d9
7
ANNOUNCE
7
ANNOUNCE
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
Libpng 1.5.15beta05 - February 15, 2013
|
Libpng 1.5.15beta05 - February 16, 2013
|
||||||
|
|
||||||
This is not intended to be a public release. It will be replaced
|
This is not intended to be a public release. It will be replaced
|
||||||
within a few weeks by a public version or by another test version.
|
within a few weeks by a public version or by another test version.
|
||||||
@ -49,7 +49,10 @@ Version 1.5.15beta04 [February 15, 2013]
|
|||||||
Enclosed the new png_get_palette_max in #ifdef PNG_GET_PALETTE_MAX_SUPPORTED
|
Enclosed the new png_get_palette_max in #ifdef PNG_GET_PALETTE_MAX_SUPPORTED
|
||||||
block, and revised pnglibconf.h and pnglibconf.h.prebuilt accordingly.
|
block, and revised pnglibconf.h and pnglibconf.h.prebuilt accordingly.
|
||||||
|
|
||||||
Version 1.5.15beta05 [February 15, 2013]
|
Version 1.5.15beta05 [February 16, 2013]
|
||||||
|
Use approved/supported Android method to check for NEON, use Linux/POSIX
|
||||||
|
1003.1 API to check /proc/self/auxv avoiding buffer allocation and other
|
||||||
|
library calls.
|
||||||
|
|
||||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||||
(subscription required; visit
|
(subscription required; visit
|
||||||
|
|||||||
5
CHANGES
5
CHANGES
@ -4006,7 +4006,10 @@ Version 1.5.15beta04 [February 15, 2013]
|
|||||||
Enclosed the new png_get_palette_max in #ifdef PNG_GET_PALETTE_MAX_SUPPORTED
|
Enclosed the new png_get_palette_max in #ifdef PNG_GET_PALETTE_MAX_SUPPORTED
|
||||||
block, and revised pnglibconf.h and pnglibconf.h.prebuilt accordingly.
|
block, and revised pnglibconf.h and pnglibconf.h.prebuilt accordingly.
|
||||||
|
|
||||||
Version 1.5.15beta05 [February 15, 2013]
|
Version 1.5.15beta05 [February 16, 2013]
|
||||||
|
Use approved/supported Android method to check for NEON, use Linux/POSIX
|
||||||
|
1003.1 API to check /proc/self/auxv avoiding buffer allocation and other
|
||||||
|
library calls.
|
||||||
|
|
||||||
===========================================================================
|
===========================================================================
|
||||||
NOTICE November 17, 2012:
|
NOTICE November 17, 2012:
|
||||||
|
|||||||
149
arm/arm_init.c
149
arm/arm_init.c
@ -9,45 +9,154 @@
|
|||||||
* For conditions of distribution and use, see the disclaimer
|
* For conditions of distribution and use, see the disclaimer
|
||||||
* and license in png.h
|
* and license in png.h
|
||||||
*/
|
*/
|
||||||
|
/* Below, after checking __linux__, various non-C90 POSIX 1003.1 functions are
|
||||||
|
* called.
|
||||||
|
*/
|
||||||
|
#define _POSIX_SOURCE 1
|
||||||
|
|
||||||
#include "../pngpriv.h"
|
#include "../pngpriv.h"
|
||||||
|
|
||||||
/* __arm__ is defined by GCC, MSVC defines _M_ARM to the ARM version number */
|
/* __arm__ is defined by GCC, MSVC defines _M_ARM to the ARM version number,
|
||||||
|
* Andoid intends to define __ANDROID__, however there are bugs in their
|
||||||
|
* toolchain; use -D__ANDROID__ to work round this.
|
||||||
|
*/
|
||||||
#if defined __linux__ && defined __arm__
|
#if defined __linux__ && defined __arm__
|
||||||
#include <stdio.h>
|
#define CHECK_NEON
|
||||||
|
#include <signal.h> /* for sig_atomic_t */
|
||||||
|
|
||||||
|
#ifdef __ANDROID__
|
||||||
|
/* Linux provides access to information about CPU capabilites via
|
||||||
|
* /proc/self/auxv, however Android blocks this while still claiming to be
|
||||||
|
* Linux. The Andoid NDK, however, provides appropriate support.
|
||||||
|
*
|
||||||
|
* Documentation: http://www.kandroid.org/ndk/docs/CPU-ARM-NEON.html
|
||||||
|
*/
|
||||||
|
#include <cpu-features.h>
|
||||||
|
|
||||||
|
static int
|
||||||
|
png_have_neon(png_structp png_ptr)
|
||||||
|
{
|
||||||
|
/* This is a whole lot easier than the mess below, however it is probably
|
||||||
|
* implemented as below, therefore it is better to cache the result (these
|
||||||
|
* function calls may be slow!)
|
||||||
|
*/
|
||||||
|
return andoid_getCpuFamily() == ANDROID_CPU_FAMILY_ARM &&
|
||||||
|
(android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/* The generic __linux__ implementation requires reading /proc/self/auxv and
|
||||||
|
* looking at each element for one that records NEON capabilities.
|
||||||
|
*/
|
||||||
|
#include <unistd.h> /* for POSIX 1003.1 */
|
||||||
|
#include <errno.h> /* for EINTR */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <elf.h>
|
#include <elf.h>
|
||||||
#include <asm/hwcap.h>
|
#include <asm/hwcap.h>
|
||||||
|
|
||||||
static int png_have_hwcap(unsigned cap)
|
/* A read call may be interupted, in which case it returns -1 and sets errno to
|
||||||
|
* EINTR if nothing was done, otherwise (if something was done) a partial read
|
||||||
|
* may result.
|
||||||
|
*/
|
||||||
|
static size_t
|
||||||
|
safe_read(png_structp png_ptr, int fd, void *buffer_in, size_t nbytes)
|
||||||
{
|
{
|
||||||
FILE *f = fopen("/proc/self/auxv", "r");
|
size_t ntotal = 0;
|
||||||
Elf32_auxv_t aux;
|
char *buffer = png_voidcast(char*, buffer_in);
|
||||||
int have_cap = 0;
|
|
||||||
|
|
||||||
if (!f)
|
while (nbytes > 0)
|
||||||
|
{
|
||||||
|
unsigned int nread;
|
||||||
|
int iread;
|
||||||
|
|
||||||
|
/* Passing nread > INT_MAX to read is implementation defined in POSIX
|
||||||
|
* 1003.1, therefore despite the unsigned argument portable code must
|
||||||
|
* limit the value to INT_MAX!
|
||||||
|
*/
|
||||||
|
if (nbytes > INT_MAX)
|
||||||
|
nread = INT_MAX;
|
||||||
|
|
||||||
|
else
|
||||||
|
nread = (unsigned int)/*SAFE*/nbytes;
|
||||||
|
|
||||||
|
iread = read(fd, buffer, nread);
|
||||||
|
|
||||||
|
if (iread == -1)
|
||||||
|
{
|
||||||
|
/* This is the devil in the details, a read can terminate early with 0
|
||||||
|
* bytes read because of EINTR, yet it still returns -1 otherwise end
|
||||||
|
* of file cannot be distinguished.
|
||||||
|
*/
|
||||||
|
if (errno != EINTR)
|
||||||
|
{
|
||||||
|
png_warning(png_ptr, "/proc read failed");
|
||||||
|
return 0; /* I.e. a permanent failure */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (iread < 0)
|
||||||
|
{
|
||||||
|
/* Not a valid 'read' result: */
|
||||||
|
png_warning(png_ptr, "OS /proc read bug");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
while (fread(&aux, sizeof(aux), 1, f) > 0)
|
|
||||||
{
|
|
||||||
if (aux.a_type == AT_HWCAP &&
|
|
||||||
aux.a_un.a_val & cap)
|
|
||||||
{
|
|
||||||
have_cap = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
else if (iread > 0)
|
||||||
|
{
|
||||||
|
/* Continue reading until a permanent failure, or EOF */
|
||||||
|
buffer += iread;
|
||||||
|
nbytes -= (unsigned int)/*SAFE*/iread;
|
||||||
|
ntotal += (unsigned int)/*SAFE*/iread;
|
||||||
|
}
|
||||||
|
|
||||||
return have_cap;
|
else
|
||||||
|
return ntotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ntotal; /* nbytes == 0 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
png_have_neon(png_structp png_ptr)
|
||||||
|
{
|
||||||
|
int fd = open("/proc/self/auxv", O_RDONLY);
|
||||||
|
Elf32_auxv_t aux;
|
||||||
|
|
||||||
|
/* Failsafe: failure to open means no NEON */
|
||||||
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
png_warning(png_ptr, "/proc/self/auxv open failed");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (safe_read(png_ptr, fd, &aux, sizeof aux) == sizeof aux)
|
||||||
|
{
|
||||||
|
if (aux.a_type == AT_HWCAP && (aux.a_un.a_val & HWCAP_NEON) != 0)
|
||||||
|
{
|
||||||
|
close(fd);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif /* !__ANDROID__ */
|
||||||
#endif /* __linux__ && __arm__ */
|
#endif /* __linux__ && __arm__ */
|
||||||
|
|
||||||
void
|
void
|
||||||
png_init_filter_functions_neon(png_structp pp, unsigned int bpp)
|
png_init_filter_functions_neon(png_structp pp, unsigned int bpp)
|
||||||
{
|
{
|
||||||
#ifdef __arm__
|
#ifdef __arm__
|
||||||
#ifdef __linux__
|
#ifdef CHECK_NEON
|
||||||
if (!png_have_hwcap(HWCAP_NEON))
|
static volatile sig_atomic_t no_neon = -1; /* not checked */
|
||||||
|
|
||||||
|
if (no_neon < 0)
|
||||||
|
no_neon = !png_have_neon(png_structp);
|
||||||
|
|
||||||
|
if (no_neon)
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user