1 /* contrib/arm-neon/linux.c
3 * Copyright (c) 2014 Glenn Randers-Pehrson
4 * Written by John Bowler, 2014.
5 * Last changed in libpng 1.6.10 [March 6, 2014]
7 * This code is released under the libpng license.
8 * For conditions of distribution and use, see the disclaimer
11 * SEE contrib/arm-neon/README before reporting bugs
14 * BUG REPORTS: png-mng-implement@sourceforge.net
16 * png_have_neon implemented for Linux by reading the widely available
17 * pseudo-file /proc/cpuinfo.
19 * This code is strict ANSI-C and is probably moderately portable, it does
20 * however use <stdio.h> and assumes that /proc/cpuinfo is never localized.
25 png_have_neon(png_structp png_ptr
)
27 FILE *f
= fopen("/proc/cpuinfo", "rb");
31 /* This is a simple state machine which reads the input byte-by-byte until
32 * it gets a match on the 'neon' feature or reaches the end of the stream.
34 static const char ch_feature
[] = { 70, 69, 65, 84, 85, 82, 69, 83 };
35 static const char ch_neon
[] = { 78, 69, 79, 78 };
39 StartLine
, Feature
, Colon
, StartTag
, Neon
, HaveNeon
, SkipTag
, SkipLine
43 for (state
=StartLine
, counter
=0;;)
49 /* EOF means error or end-of-file, return false; neon at EOF is
50 * assumed to be a mistake.
59 /* Match spaces at the start of line */
60 if (ch
<= 32) /* skip control characters and space */
68 /* Match 'FEATURE', ASCII case insensitive. */
69 if ((ch
& ~0x20) == ch_feature
[counter
])
71 if (++counter
== (sizeof ch_feature
))
76 /* did not match 'feature' */
82 /* Skip everything until we see linefeed or carriage return */
83 if (ch
!= 10 && ch
!= 13)
90 /* Match any number of space or tab followed by ':' */
91 if (ch
== 32 || ch
== 9)
94 if (ch
== 58) /* i.e. ':' */
100 /* Either a bad line format or a 'feature' prefix followed by
107 /* Skip space characters before a tag */
108 if (ch
== 32 || ch
== 9)
116 /* Look for 'neon' tag */
117 if ((ch
& ~0x20) == ch_neon
[counter
])
119 if (++counter
== (sizeof ch_neon
))
128 /* Skip non-space characters */
129 if (ch
== 10 || ch
== 13)
132 else if (ch
== 32 || ch
== 9)
137 /* Have seen a 'neon' prefix, but there must be a space or new
138 * line character to terminate it.
140 if (ch
== 10 || ch
== 13 || ch
== 32 || ch
== 9)
150 png_error(png_ptr
, "png_have_neon: internal error (bug)");
156 png_warning(png_ptr
, "/proc/cpuinfo open failed");