Skip to content

Commit 98d341e

Browse files
authored
Merge pull request #293 from flightaware/starch-fixes
Fix generate-wisdom, update dsp cpu detection code
2 parents f2dc3a9 + badda02 commit 98d341e

71 files changed

Lines changed: 117 additions & 8752 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ ifeq ($(UNAME), Linux)
5555
LIBS += -lrt
5656
LIBS_USB += -lusb-1.0
5757
LIBS_CURSES := -lncurses
58-
CPUFEATURES ?= yes
5958
endif
6059

6160
ifeq ($(UNAME), Darwin)
@@ -70,10 +69,6 @@ ifeq ($(UNAME), Darwin)
7069
endif
7170
LIBS_USB += -lusb-1.0
7271
LIBS_CURSES := -lncurses
73-
# cpufeatures reportedly does not work (yet) on darwin arm64
74-
ifneq ($(ARCH),arm64)
75-
CPUFEATURES ?= yes
76-
endif
7772
endif
7873

7974
ifeq ($(UNAME), OpenBSD)
@@ -97,13 +92,6 @@ ifeq ($(UNAME), NetBSD)
9792
LIBS_CURSES := -lcurses
9893
endif
9994

100-
CPUFEATURES ?= no
101-
102-
ifeq ($(CPUFEATURES),yes)
103-
include Makefile.cpufeatures
104-
DUMP1090_CPPFLAGS += -DENABLE_CPUFEATURES -Icpu_features/include
105-
endif
106-
10795
RTLSDR ?= yes
10896
BLADERF ?= yes
10997

@@ -172,35 +160,30 @@ endif
172160
## starch (runtime DSP code selection) mix, architecture-specific
173161
##
174162

175-
ifneq ($(CPUFEATURES),yes)
176-
# need to be able to detect CPU features at runtime to enable any non-standard compiler flags
163+
ifeq ($(ARCH),x86_64)
164+
# AVX, AVX2
165+
STARCH_MIX := x86
166+
DUMP1090_CPPFLAGS += -DSTARCH_MIX_X86
167+
else ifeq ($(ARCH),amd64)
168+
# this is the Debian naming of x86_64
169+
STARCH_MIX := x86
170+
DUMP1090_CPPFLAGS += -DSTARCH_MIX_X86
171+
else ifeq ($(findstring aarch,$(ARCH)),aarch)
172+
STARCH_MIX := aarch64
173+
DUMP1090_CPPFLAGS += -DSTARCH_MIX_AARCH64
174+
else ifeq ($(findstring arm64,$(ARCH)),arm64)
175+
# Apple calls this arm64, not aarch64
176+
STARCH_MIX := aarch64
177+
DUMP1090_CPPFLAGS += -DSTARCH_MIX_AARCH64
178+
else ifeq ($(findstring arm,$(ARCH)),arm)
179+
# ARMv7 NEON
180+
STARCH_MIX := arm
181+
DUMP1090_CPPFLAGS += -DSTARCH_MIX_ARM
182+
else
177183
STARCH_MIX := generic
178184
DUMP1090_CPPFLAGS += -DSTARCH_MIX_GENERIC
179-
else
180-
ifeq ($(ARCH),x86_64)
181-
# AVX, AVX2
182-
STARCH_MIX := x86
183-
DUMP1090_CPPFLAGS += -DSTARCH_MIX_X86
184-
else ifeq ($(ARCH),amd64)
185-
# this is the Debian naming of x86_64
186-
STARCH_MIX := x86
187-
DUMP1090_CPPFLAGS += -DSTARCH_MIX_X86
188-
else ifeq ($(findstring aarch,$(ARCH)),aarch)
189-
STARCH_MIX := aarch64
190-
DUMP1090_CPPFLAGS += -DSTARCH_MIX_AARCH64
191-
else ifeq ($(findstring arm64,$(ARCH)),arm64)
192-
# Apple calls this arm64, not aarch64
193-
STARCH_MIX := aarch64
194-
DUMP1090_CPPFLAGS += -DSTARCH_MIX_AARCH64
195-
else ifeq ($(findstring arm,$(ARCH)),arm)
196-
# ARMv7 NEON
197-
STARCH_MIX := arm
198-
DUMP1090_CPPFLAGS += -DSTARCH_MIX_ARM
199-
else
200-
STARCH_MIX := generic
201-
DUMP1090_CPPFLAGS += -DSTARCH_MIX_GENERIC
202-
endif
203185
endif
186+
204187
all: showconfig dump1090 view1090 starch-benchmark
205188

206189
ALL_CCFLAGS := $(CPPFLAGS) $(DUMP1090_CPPFLAGS) $(CFLAGS) $(DUMP1090_CFLAGS)
@@ -222,7 +205,7 @@ showconfig:
222205
%.o: %.c *.h
223206
$(CC) $(ALL_CCFLAGS) -c $< -o $@
224207

225-
dump1090: dump1090.o anet.o interactive.o mode_ac.o mode_s.o comm_b.o net_io.o crc.o demod_2400.o stats.o cpr.o icao_filter.o track.o util.o convert.o ais_charset.o adaptive.o $(SDR_OBJ) $(COMPAT) $(CPUFEATURES_OBJS) $(STARCH_OBJS)
208+
dump1090: dump1090.o anet.o interactive.o mode_ac.o mode_s.o comm_b.o net_io.o crc.o demod_2400.o stats.o cpr.o icao_filter.o track.o util.o convert.o ais_charset.o adaptive.o $(SDR_OBJ) $(COMPAT) $(STARCH_OBJS)
226209
$(CC) -g -o $@ $^ $(LDFLAGS) $(LIBS) $(LIBS_SDR) $(LIBS_CURSES)
227210

228211
view1090: view1090.o anet.o interactive.o mode_ac.o mode_s.o comm_b.o net_io.o crc.o stats.o cpr.o icao_filter.o track.o util.o ais_charset.o sdr_stub.o $(COMPAT)
@@ -231,11 +214,11 @@ view1090: view1090.o anet.o interactive.o mode_ac.o mode_s.o comm_b.o net_io.o c
231214
faup1090: faup1090.o anet.o mode_ac.o mode_s.o comm_b.o net_io.o crc.o stats.o cpr.o icao_filter.o track.o util.o ais_charset.o sdr_stub.o $(COMPAT)
232215
$(CC) -g -o $@ $^ $(LDFLAGS) $(LIBS)
233216

234-
starch-benchmark: cpu.o dsp/helpers/tables.o $(CPUFEATURES_OBJS) $(STARCH_OBJS) $(STARCH_BENCHMARK_OBJ)
217+
starch-benchmark: cpu.o dsp/helpers/tables.o $(STARCH_OBJS) $(STARCH_BENCHMARK_OBJ)
235218
$(CC) -g -o $@ $^ $(LDFLAGS) $(LIBS)
236219

237220
clean:
238-
rm -f *.o oneoff/*.o compat/clock_gettime/*.o compat/clock_nanosleep/*.o cpu_features/src/*.o dsp/generated/*.o dsp/helpers/*.o $(CPUFEATURES_OBJS) dump1090 view1090 faup1090 cprtests crctests oneoff/convert_benchmark oneoff/decode_comm_b oneoff/dsp_error_measurement oneoff/uc8_capture_stats starch-benchmark
221+
rm -f *.o oneoff/*.o compat/clock_gettime/*.o compat/clock_nanosleep/*.o cpu_features/src/*.o dsp/generated/*.o dsp/helpers/*.o dump1090 view1090 faup1090 cprtests crctests oneoff/convert_benchmark oneoff/decode_comm_b oneoff/dsp_error_measurement oneoff/uc8_capture_stats starch-benchmark
239222

240223
test: cprtests starch-benchmark
241224
./cprtests
@@ -250,13 +233,13 @@ crctests: crc.c crc.h
250233
benchmarks: oneoff/convert_benchmark
251234
oneoff/convert_benchmark
252235

253-
oneoff/convert_benchmark: oneoff/convert_benchmark.o convert.o util.o dsp/helpers/tables.o cpu.o $(CPUFEATURES_OBJS) $(STARCH_OBJS)
236+
oneoff/convert_benchmark: oneoff/convert_benchmark.o convert.o util.o dsp/helpers/tables.o cpu.o $(STARCH_OBJS)
254237
$(CC) $(ALL_CCFLAGS) -g -o $@ $^ -lm -lpthread
255238

256239
oneoff/decode_comm_b: oneoff/decode_comm_b.o comm_b.o ais_charset.o
257240
$(CC) $(ALL_CCFLAGS) -g -o $@ $^ -lm
258241

259-
oneoff/dsp_error_measurement: oneoff/dsp_error_measurement.o dsp/helpers/tables.o cpu.o $(CPUFEATURES_OBJS) $(STARCH_OBJS)
242+
oneoff/dsp_error_measurement: oneoff/dsp_error_measurement.o dsp/helpers/tables.o cpu.o $(STARCH_OBJS)
260243
$(CC) $(ALL_CCFLAGS) -g -o $@ $^ -lm
261244

262245
oneoff/uc8_capture_stats: oneoff/uc8_capture_stats.o

cpu.c

Lines changed: 71 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,104 @@
1-
#include "cpu.h"
1+
/*
2+
* cpu.c - flavor/CPU detection support for starch
3+
*
4+
* Copyright (c) 2026 FlightAware All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are
8+
* met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright
11+
* notice, this list of conditions and the following disclaimer.
12+
*
13+
* 2. Redistributions in binary form must reproduce the above copyright
14+
* notice, this list of conditions and the following disclaimer in the
15+
* documentation and/or other materials provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
229

3-
#include <stdbool.h>
30+
#include "cpu.h"
431

5-
#ifdef ENABLE_CPUFEATURES
6-
#include "cpu_features_macros.h"
32+
#if defined(__GNUC__) && defined(__x86_64__)
33+
# include <cpuid.h>
34+
# define HAVE_X86_CPUID
735
#endif
836

9-
//
10-
// x86
11-
//
12-
13-
#ifdef CPU_FEATURES_ARCH_X86
14-
#include "cpuinfo_x86.h"
15-
16-
static X86Info *x86_info()
17-
{
18-
static bool valid = false;
19-
static X86Info cache;
20-
21-
if (!valid) {
22-
cache = GetX86Info();
23-
valid = true;
24-
}
25-
26-
return &cache;
27-
}
37+
#if defined(__linux__) && defined(__arm__)
38+
# include <asm/hwcap.h>
39+
# include <sys/auxv.h>
40+
# define HAVE_ARM32_AUXV
41+
#endif
2842

43+
#if defined(__linux__) && defined(__aarch64__)
44+
# include <asm/hwcap.h>
45+
# include <sys/auxv.h>
46+
# define HAVE_ARM64_AUXV
2947
#endif
3048

31-
int cpu_supports_avx(void)
49+
int cpu_supports_armv7_neon_vfpv4(void)
3250
{
33-
#ifdef CPU_FEATURES_ARCH_X86
34-
return x86_info()->features.avx;
51+
#ifdef HAVE_ARM32_AUXV
52+
long hwcaps = getauxval(AT_HWCAP);
53+
return
54+
(hwcaps & HWCAP_ARM_NEON) &&
55+
(hwcaps & HWCAP_ARM_VFPv4);
3556
#else
3657
return 0;
3758
#endif
3859
}
3960

40-
int cpu_supports_avx2(void)
61+
int cpu_supports_armv8_simd(void)
4162
{
42-
#ifdef CPU_FEATURES_ARCH_X86
43-
return x86_info()->features.avx2;
63+
#ifdef HAVE_ARM64_AUXV
64+
long hwcaps = getauxval(AT_HWCAP);
65+
return (hwcaps & HWCAP_ASIMD);
4466
#else
4567
return 0;
4668
#endif
4769
}
4870

49-
//
50-
// ARM
51-
//
52-
53-
#ifdef CPU_FEATURES_ARCH_ARM
54-
#include "cpuinfo_arm.h"
55-
56-
static ArmInfo *arm_info()
71+
int cpu_supports_avx(void)
5772
{
58-
static bool valid = false;
59-
static ArmInfo cache;
73+
#ifdef HAVE_X86_CPUID
74+
unsigned int maxlevel = __get_cpuid_max (0, 0);
75+
if (maxlevel < 1)
76+
return 0;
6077

61-
if (!valid) {
62-
cache = GetArmInfo();
63-
valid = true;
64-
}
78+
unsigned eax, ebx, ecx, edx;
79+
__cpuid(1, eax, ebx, ecx, edx);
80+
if (!(ecx & bit_AVX))
81+
return 0;
6582

66-
return &cache;
67-
}
68-
69-
#endif
70-
71-
int cpu_supports_armv7_neon_vfpv4(void)
72-
{
73-
#ifdef CPU_FEATURES_ARCH_ARM
74-
return arm_info()->architecture >= 7 && arm_info()->features.neon && arm_info()->features.vfpv4 && arm_info()->features.vfpd32;
83+
return 1;
7584
#else
7685
return 0;
7786
#endif
7887
}
7988

80-
//
81-
// AARCH64
82-
//
83-
84-
#ifdef CPU_FEATURES_ARCH_AARCH64
85-
#include "cpuinfo_aarch64.h"
86-
87-
static Aarch64Info *aarch64_info()
89+
int cpu_supports_avx2(void)
8890
{
89-
static bool valid = false;
90-
static Aarch64Info cache;
91-
92-
if (!valid) {
93-
cache = GetAarch64Info();
94-
valid = true;
95-
}
91+
#ifdef HAVE_X86_CPUID
92+
unsigned int maxlevel = __get_cpuid_max (0, 0);
93+
if (maxlevel < 7)
94+
return 0;
9695

97-
return &cache;
98-
}
96+
unsigned eax, ebx, ecx, edx;
97+
__cpuid_count(7, 0, eax, ebx, ecx, edx);
98+
if (!(ebx & bit_AVX2))
99+
return 0;
99100

100-
#endif
101-
102-
int cpu_supports_armv8_simd(void)
103-
{
104-
#ifdef CPU_FEATURES_ARCH_AARCH64
105-
return aarch64_info()->features.asimd;
101+
return 1;
106102
#else
107103
return 0;
108104
#endif

cpu_features/.clang-format

Lines changed: 0 additions & 4 deletions
This file was deleted.

cpu_features/.gitignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)