30
23
#include "../jsimddct.h"
33
30
static unsigned int simd_support = ~0;
35
extern volatile ElfW(auxv_t) *auxv;
32
#if defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
34
#define SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT (1024 * 1024)
37
check_feature (char *buffer, char *feature)
42
if (strncmp(buffer, "Features", 8) != 0)
45
while (isspace(*buffer))
48
/* Check if 'feature' is present in the buffer as a separate word */
49
while ((p = strstr(buffer, feature))) {
50
if (p > buffer && !isspace(*(p - 1))) {
55
if (*p != 0 && !isspace(*p)) {
65
parse_proc_cpuinfo (int bufsize)
67
char *buffer = (char *)malloc(bufsize);
74
fd = fopen("/proc/cpuinfo", "r");
76
while (fgets(buffer, bufsize, fd)) {
77
if (!strchr(buffer, '\n') && !feof(fd)) {
78
/* "impossible" happened - insufficient size of the buffer! */
83
if (check_feature(buffer, "neon"))
84
simd_support |= JSIMD_ARM_NEON;
38
95
* Check what SIMD accelerations are supported.
39
* this is called once and ONLY once from libjpeg_general_init
97
* FIXME: This code is racy under a multi-threaded environment.
45
ElfW(auxv_t) *tauxv=(ElfW(auxv_t) *)auxv;
103
#if !defined(__ARM_NEON__) && defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
104
int bufsize = 1024; /* an initial guess for the line buffer size limit */
47
if (simd_support != ~0)
107
if (simd_support != ~0U)
51
while (tauxv && tauxv->a_type != AT_HWCAP)
112
#if defined(__ARM_NEON__)
113
simd_support |= JSIMD_ARM_NEON;
114
#elif defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
115
/* We still have a chance to use NEON regardless of globally used
116
* -mcpu/-mfpu options passed to gcc by performing runtime detection via
117
* /proc/cpuinfo parsing on linux/android */
118
while (!parse_proc_cpuinfo(bufsize)) {
120
if (bufsize > SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT)
54
if( tauxv && tauxv->a_un.a_val & HWCAP_NEON )
55
simd_support |= JSIMD_ARM_NEON;
57
125
/* Force different settings through environment variables */
58
126
env = getenv("JSIMD_FORCE_ARM_NEON");
59
127
if ((env != NULL) && (strcmp(env, "1") == 0))
247
329
jsimd_can_h2v2_fancy_upsample (void)
253
337
jsimd_can_h2v1_fancy_upsample (void)
341
/* The code is optimised for these values only */
342
if (BITS_IN_JSAMPLE != 8)
344
if (sizeof(JDIMENSION) != 4)
347
if (simd_support & JSIMD_ARM_NEON)
269
364
JSAMPARRAY input_data,
270
365
JSAMPARRAY * output_data_ptr)
367
if (simd_support & JSIMD_ARM_NEON)
368
jsimd_h2v1_fancy_upsample_neon(cinfo->max_v_samp_factor,
369
compptr->downsampled_width, input_data, output_data_ptr);
275
373
jsimd_can_h2v2_merged_upsample (void)
281
381
jsimd_can_h2v1_merged_upsample (void)