|
| 1 | +From f60e7d9bdc39e51b644db7624256116202cac992 Mon Sep 17 00:00:00 2001 |
| 2 | + |
| 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 |
0 commit comments