1 https://bugs.gentoo.org/show_bug.cgi?id=896138
2 https://github.com/cisco/openh264/pull/3630
4 From f60e7d9bdc39e51b644db7624256116202cac992 Mon Sep 17 00:00:00 2001
5 From: matoro <matoro@users.noreply.github.com>
6 Date: Thu, 2 Mar 2023 17:39:45 -0500
7 Subject: [PATCH] Use environment for mips feature detection
9 The -march= option is perfectly happy to emit code to run on a processor
10 different than the one on which it is being compiled. This results in
11 misdetection of mips features because the test compiles specify that a
12 given extension should be emitted, but this does not check whether or
13 not this corresponds to the subarchitecture targeted in CFLAGS by the
16 $ echo "void main(void){ __asm__ volatile(\"punpcklhw \$f0, \$f0, \$f0\"); }" > test.c
17 $ CFLAGS="-march=loongson3a" make test
18 cc -march=loongson3a test.c -o test
21 $ CFLAGS="-march=native" make -B test
22 cc -march=native test.c -o test
23 /tmp/ccLbeyM1.s: Assembler messages:
24 /tmp/ccLbeyM1.s:25: Error: opcode not supported on this processor: octeon2 (mips64r2) `punpcklhw $f0,$f0,$f0'
25 make: *** [<builtin>: test] Error 1
27 This leads to -march=loongson3a getting appended to CFLAGS, which may
28 conflict with previously specified -march= levels for the build, or
29 other options. Calling make in the test will use whatever CC/CFLAGS are
30 specified in the environment to determine whether the actual compile
31 command line to be used in the build supports these features.
33 Fixes: 8b942ee ("Adjust the mmi/msa detection mode for mips platform.")
35 build/arch.mk | 8 ++++----
36 build/loongarch-simd-check.sh | 17 +++++++----------
37 build/mips-simd-check.sh | 17 +++++++----------
38 3 files changed, 18 insertions(+), 24 deletions(-)
40 diff --git a/build/arch.mk b/build/arch.mk
41 index 4e1538c45c..80983686f7 100644
44 @@ -39,14 +39,14 @@ ASM_ARCH = mips
45 ASMFLAGS += -I$(SRC_PATH)codec/common/mips/
47 ifeq ($(ENABLE_MMI), Yes)
48 -ENABLE_MMI = $(shell $(SRC_PATH)build/mips-simd-check.sh $(CC) mmi)
49 +ENABLE_MMI = $(shell CC="$(CC)" CFLAGS="$(CFLAGS)" $(SRC_PATH)build/mips-simd-check.sh mmi)
50 ifeq ($(ENABLE_MMI), Yes)
51 CFLAGS += -DHAVE_MMI -march=loongson3a
55 ifeq ($(ENABLE_MSA), Yes)
56 -ENABLE_MSA = $(shell $(SRC_PATH)build/mips-simd-check.sh $(CC) msa)
57 +ENABLE_MSA = $(shell CC="$(CC)" CFLAGS="$(CFLAGS)" $(SRC_PATH)build/mips-simd-check.sh msa)
58 ifeq ($(ENABLE_MSA), Yes)
59 CFLAGS += -DHAVE_MSA -mmsa
61 @@ -63,14 +63,14 @@ ASM_ARCH = loongarch
62 ASMFLAGS += -I$(SRC_PATH)codec/common/loongarch/
64 ifeq ($(ENABLE_LSX), Yes)
65 -ENABLE_LSX = $(shell $(SRC_PATH)build/loongarch-simd-check.sh $(CC) lsx)
66 +ENABLE_LSX = $(shell CC="$(CC)" CFLAGS="$(CFLAGS)" $(SRC_PATH)build/loongarch-simd-check.sh lsx)
67 ifeq ($(ENABLE_LSX), Yes)
68 CFLAGS += -DHAVE_LSX -mlsx
72 ifeq ($(ENABLE_LASX), Yes)
73 -ENABLE_LASX = $(shell $(SRC_PATH)build/loongarch-simd-check.sh $(CC) lasx)
74 +ENABLE_LASX = $(shell CC="$(CC)" CFLAGS="$(CFLAGS)" $(SRC_PATH)build/loongarch-simd-check.sh lasx)
75 ifeq ($(ENABLE_LASX), Yes)
76 CFLAGS += -DHAVE_LASX -mlasx
78 diff --git a/build/loongarch-simd-check.sh b/build/loongarch-simd-check.sh
79 index 597ddcdc22..2e609443b9 100755
80 --- a/build/loongarch-simd-check.sh
81 +++ b/build/loongarch-simd-check.sh
83 # lsx, lasx (maybe more in the future).
86 -# ./loongarch-simd-check.sh $(CC) lsx
87 -# or ./loongarch-simd-check.sh $(CC) lasx
88 +# ./loongarch-simd-check.sh lsx
89 +# or ./loongarch-simd-check.sh lasx
91 # date: 11/23/2021 Created
92 #***************************************************************************************
94 TMPC=$(mktemp tmp.XXXXXX.c)
95 -TMPO=$(mktemp tmp.XXXXXX.o)
99 echo "void main(void){ __asm__ volatile(\"vadd.b \$vr0, \$vr1, \$vr1\"); }" > $TMPC
100 - $1 -mlsx $TMPC -o $TMPO &> /dev/null
102 + if make -f /dev/null "${TMPC/.c/.o}"
106 -elif [ $2 == "lasx" ]
107 +elif [ $1 == "lasx" ]
109 echo "void main(void){ __asm__ volatile(\"xvadd.b \$xr0, \$xr1, \$xr1\"); }" > $TMPC
110 - $1 -mlasx $TMPC -o $TMPO &> /dev/null
112 + if make -f /dev/null "${TMPC/.c/.o}"
119 diff --git a/build/mips-simd-check.sh b/build/mips-simd-check.sh
120 index d0d72f9edd..5ff1eb432c 100755
121 --- a/build/mips-simd-check.sh
122 +++ b/build/mips-simd-check.sh
124 # mmi, msa (maybe more in the future).
127 -# ./mips-simd-check.sh $(CC) mmi
128 -# or ./mips-simd-check.sh $(CC) msa
129 +# ./mips-simd-check.sh mmi
130 +# or ./mips-simd-check.sh msa
132 # date: 10/17/2019 Created
133 #**********************************************************************************
135 TMPC=$(mktemp tmp.XXXXXX.c)
136 -TMPO=$(mktemp tmp.XXXXXX.o)
140 echo "void main(void){ __asm__ volatile(\"punpcklhw \$f0, \$f0, \$f0\"); }" > $TMPC
141 - $1 -march=loongson3a $TMPC -o $TMPO &> /dev/null
143 + if make -f /dev/null "${TMPC/.c/.o}" &> /dev/null
147 -elif [ $2 == "msa" ]
148 +elif [ $1 == "msa" ]
150 echo "void main(void){ __asm__ volatile(\"addvi.b \$w0, \$w1, 1\"); }" > $TMPC
151 - $1 -mmsa $TMPC -o $TMPO &> /dev/null
153 + if make -f /dev/null "${TMPC/.c/.o}" &> /dev/null