Skip to content

Commit ee3acb4

Browse files
committed
media-libs/openh264: wire up tests, add mips patch
Patch backports cisco/openh264#3630 Tests are currently broken on BE but pass on LE. cisco/openh264#3634 Bug: https://bugs.gentoo.org/896138 Signed-off-by: Matoro Mahri <[email protected]>
1 parent 0773873 commit ee3acb4

File tree

2 files changed

+172
-4
lines changed

2 files changed

+172
-4
lines changed
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
From f60e7d9bdc39e51b644db7624256116202cac992 Mon Sep 17 00:00:00 2001
2+
From: matoro <[email protected]>
3+
Date: Thu, 2 Mar 2023 17:39:45 -0500
4+
Subject: [PATCH] Use environment for mips feature detection
5+
6+
The -march= option is perfectly happy to emit code to run on a processor
7+
different than the one on which it is being compiled. This results in
8+
misdetection of mips features because the test compiles specify that a
9+
given extension should be emitted, but this does not check whether or
10+
not this corresponds to the subarchitecture targeted in CFLAGS by the
11+
rest of the build.
12+
13+
$ echo "void main(void){ __asm__ volatile(\"punpcklhw \$f0, \$f0, \$f0\"); }" > test.c
14+
$ CFLAGS="-march=loongson3a" make test
15+
cc -march=loongson3a test.c -o test
16+
$ ./test
17+
Illegal instruction
18+
$ CFLAGS="-march=native" make -B test
19+
cc -march=native test.c -o test
20+
/tmp/ccLbeyM1.s: Assembler messages:
21+
/tmp/ccLbeyM1.s:25: Error: opcode not supported on this processor: octeon2 (mips64r2) `punpcklhw $f0,$f0,$f0'
22+
make: *** [<builtin>: test] Error 1
23+
24+
This leads to -march=loongson3a getting appended to CFLAGS, which may
25+
conflict with previously specified -march= levels for the build, or
26+
other options. Calling make in the test will use whatever CC/CFLAGS are
27+
specified in the environment to determine whether the actual compile
28+
command line to be used in the build supports these features.
29+
30+
Fixes: 8b942ee ("Adjust the mmi/msa detection mode for mips platform.")
31+
---
32+
build/arch.mk | 8 ++++----
33+
build/loongarch-simd-check.sh | 17 +++++++----------
34+
build/mips-simd-check.sh | 17 +++++++----------
35+
3 files changed, 18 insertions(+), 24 deletions(-)
36+
37+
diff --git a/build/arch.mk b/build/arch.mk
38+
index 4e1538c45c..80983686f7 100644
39+
--- a/build/arch.mk
40+
+++ b/build/arch.mk
41+
@@ -39,14 +39,14 @@ ASM_ARCH = mips
42+
ASMFLAGS += -I$(SRC_PATH)codec/common/mips/
43+
#mmi
44+
ifeq ($(ENABLE_MMI), Yes)
45+
-ENABLE_MMI = $(shell $(SRC_PATH)build/mips-simd-check.sh $(CC) mmi)
46+
+ENABLE_MMI = $(shell CC="$(CC)" CFLAGS="$(CFLAGS)" $(SRC_PATH)build/mips-simd-check.sh mmi)
47+
ifeq ($(ENABLE_MMI), Yes)
48+
CFLAGS += -DHAVE_MMI -march=loongson3a
49+
endif
50+
endif
51+
#msa
52+
ifeq ($(ENABLE_MSA), Yes)
53+
-ENABLE_MSA = $(shell $(SRC_PATH)build/mips-simd-check.sh $(CC) msa)
54+
+ENABLE_MSA = $(shell CC="$(CC)" CFLAGS="$(CFLAGS)" $(SRC_PATH)build/mips-simd-check.sh msa)
55+
ifeq ($(ENABLE_MSA), Yes)
56+
CFLAGS += -DHAVE_MSA -mmsa
57+
endif
58+
@@ -63,14 +63,14 @@ ASM_ARCH = loongarch
59+
ASMFLAGS += -I$(SRC_PATH)codec/common/loongarch/
60+
#lsx
61+
ifeq ($(ENABLE_LSX), Yes)
62+
-ENABLE_LSX = $(shell $(SRC_PATH)build/loongarch-simd-check.sh $(CC) lsx)
63+
+ENABLE_LSX = $(shell CC="$(CC)" CFLAGS="$(CFLAGS)" $(SRC_PATH)build/loongarch-simd-check.sh lsx)
64+
ifeq ($(ENABLE_LSX), Yes)
65+
CFLAGS += -DHAVE_LSX -mlsx
66+
endif
67+
endif
68+
#lasx
69+
ifeq ($(ENABLE_LASX), Yes)
70+
-ENABLE_LASX = $(shell $(SRC_PATH)build/loongarch-simd-check.sh $(CC) lasx)
71+
+ENABLE_LASX = $(shell CC="$(CC)" CFLAGS="$(CFLAGS)" $(SRC_PATH)build/loongarch-simd-check.sh lasx)
72+
ifeq ($(ENABLE_LASX), Yes)
73+
CFLAGS += -DHAVE_LASX -mlasx
74+
endif
75+
diff --git a/build/loongarch-simd-check.sh b/build/loongarch-simd-check.sh
76+
index 597ddcdc22..2e609443b9 100755
77+
--- a/build/loongarch-simd-check.sh
78+
+++ b/build/loongarch-simd-check.sh
79+
@@ -8,29 +8,26 @@
80+
# lsx, lasx (maybe more in the future).
81+
#
82+
# --usage:
83+
-# ./loongarch-simd-check.sh $(CC) lsx
84+
-# or ./loongarch-simd-check.sh $(CC) lasx
85+
+# ./loongarch-simd-check.sh lsx
86+
+# or ./loongarch-simd-check.sh lasx
87+
#
88+
# date: 11/23/2021 Created
89+
#***************************************************************************************
90+
91+
TMPC=$(mktemp tmp.XXXXXX.c)
92+
-TMPO=$(mktemp tmp.XXXXXX.o)
93+
-if [ $2 == "lsx" ]
94+
+if [ $1 == "lsx" ]
95+
then
96+
echo "void main(void){ __asm__ volatile(\"vadd.b \$vr0, \$vr1, \$vr1\"); }" > $TMPC
97+
- $1 -mlsx $TMPC -o $TMPO &> /dev/null
98+
- if test -s $TMPO
99+
+ if make -f /dev/null "${TMPC/.c/.o}"
100+
then
101+
echo "Yes"
102+
fi
103+
-elif [ $2 == "lasx" ]
104+
+elif [ $1 == "lasx" ]
105+
then
106+
echo "void main(void){ __asm__ volatile(\"xvadd.b \$xr0, \$xr1, \$xr1\"); }" > $TMPC
107+
- $1 -mlasx $TMPC -o $TMPO &> /dev/null
108+
- if test -s $TMPO
109+
+ if make -f /dev/null "${TMPC/.c/.o}"
110+
then
111+
echo "Yes"
112+
fi
113+
fi
114+
-rm -f $TMPC $TMPO
115+
+rm -f $TMPC
116+
diff --git a/build/mips-simd-check.sh b/build/mips-simd-check.sh
117+
index d0d72f9edd..5ff1eb432c 100755
118+
--- a/build/mips-simd-check.sh
119+
+++ b/build/mips-simd-check.sh
120+
@@ -4,29 +4,26 @@
121+
# mmi, msa (maybe more in the future).
122+
#
123+
# --usage:
124+
-# ./mips-simd-check.sh $(CC) mmi
125+
-# or ./mips-simd-check.sh $(CC) msa
126+
+# ./mips-simd-check.sh mmi
127+
+# or ./mips-simd-check.sh msa
128+
#
129+
# date: 10/17/2019 Created
130+
#**********************************************************************************
131+
132+
TMPC=$(mktemp tmp.XXXXXX.c)
133+
-TMPO=$(mktemp tmp.XXXXXX.o)
134+
-if [ $2 == "mmi" ]
135+
+if [ $1 == "mmi" ]
136+
then
137+
echo "void main(void){ __asm__ volatile(\"punpcklhw \$f0, \$f0, \$f0\"); }" > $TMPC
138+
- $1 -march=loongson3a $TMPC -o $TMPO &> /dev/null
139+
- if test -s $TMPO
140+
+ if make -f /dev/null "${TMPC/.c/.o}" &> /dev/null
141+
then
142+
echo "Yes"
143+
fi
144+
-elif [ $2 == "msa" ]
145+
+elif [ $1 == "msa" ]
146+
then
147+
echo "void main(void){ __asm__ volatile(\"addvi.b \$w0, \$w1, 1\"); }" > $TMPC
148+
- $1 -mmsa $TMPC -o $TMPO &> /dev/null
149+
- if test -s $TMPO
150+
+ if make -f /dev/null "${TMPC/.c/.o}" &> /dev/null
151+
then
152+
echo "Yes"
153+
fi
154+
fi
155+
-rm -f $TMPC $TMPO
156+
+rm -f $TMPC

media-libs/openh264/openh264-2.3.1-r1.ebuild

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,28 @@ LICENSE="BSD"
1919
# https://github.com/cisco/openh264/issues/3459 )
2020
SLOT="0/7"
2121
KEYWORDS="~alpha amd64 arm arm64 ~hppa ~ia64 ~loong ppc ppc64 ~riscv sparc x86"
22-
IUSE="cpu_flags_arm_neon cpu_flags_x86_avx2 +plugin utils"
22+
IUSE="cpu_flags_arm_neon cpu_flags_x86_avx2 +plugin test utils"
2323

24-
RESTRICT="bindist test"
24+
RESTRICT="bindist !test? ( test )"
2525

2626
BDEPEND="
2727
abi_x86_32? ( dev-lang/nasm )
28-
abi_x86_64? ( dev-lang/nasm )"
28+
abi_x86_64? ( dev-lang/nasm )
29+
test? ( dev-cpp/gtest[${MULTILIB_USEDEP}] )"
2930

3031
DOCS=( LICENSE CONTRIBUTORS README.md )
3132

32-
PATCHES=( "${FILESDIR}"/openh264-2.3.0-pkgconfig-pathfix.patch )
33+
PATCHES=(
34+
"${FILESDIR}"/openh264-2.3.0-pkgconfig-pathfix.patch
35+
"${FILESDIR}"/${PN}-2.3.1-pr3630.patch
36+
)
3337

3438
src_prepare() {
3539
default
3640

41+
ln -svf "/dev/null" "build/gtest-targets.mk" || die
42+
sed -i -e 's/$(LIBPREFIX)gtest.$(LIBSUFFIX)//g' Makefile || die
43+
3744
sed -i -e 's/ | generate-version//g' Makefile || die
3845
sed -e 's|$FULL_VERSION|""|g' codec/common/inc/version_gen.h.template > \
3946
codec/common/inc/version_gen.h
@@ -53,6 +60,7 @@ emakecmd() {
5360
SHAREDLIB_DIR="${EPREFIX}/usr/$(get_libdir)" \
5461
INCLUDES_DIR="${EPREFIX}/usr/include/${PN}" \
5562
HAVE_AVX2=$(usex cpu_flags_x86_avx2 Yes No) \
63+
HAVE_GTEST=$(usex test Yes No) \
5664
ARCH="$(tc-arch)" \
5765
$@
5866
}
@@ -71,6 +79,10 @@ multilib_src_compile() {
7179
use plugin && emakecmd ${myopts} plugin
7280
}
7381

82+
multilib_src_test() {
83+
emakecmd test
84+
}
85+
7486
multilib_src_install() {
7587
emakecmd DESTDIR="${D}" install-shared
7688

0 commit comments

Comments
 (0)