hartwork / resolve-march-native

:snail: Tool to determine what GCC flags -march=native would resolve into
https://pypi.python.org/pypi/resolve-march-native
44 stars 7 forks source link

gcc: error: unrecognized command-line option ‘-mno-branch-cost=2’; did you mean ‘-mbranch-cost=’? #127

Closed mercuriete closed 9 months ago

mercuriete commented 10 months ago
resolve-march-native 
-march=pentium-m -mtune=generic -mbranch-cost=3 -mno-accumulate-outgoing-args -mno-branch-cost=2 -mno-sahf --param=l1-cache-line-size=64 --param=l1-cache-size=32 --param=l2-cache-size=1024

then you take this flags and try to use it:

gcc -Q -march=pentium-m -mtune=generic -mbranch-cost=3 -mno-accumulate-outgoing-args -mno-branch-cost=2 -mno-sahf --param=l1-cache-line-size=64 --param=l1-cache-size=32 --param=l2-cache-size=1024 --help=target 
gcc: error: unrecognized command-line option ‘-mno-branch-cost=2’; did you mean ‘-mbranch-cost=’?

Sorry if this ticket is too vague, I will try to increase the information if you require me to do so.

Thanks :)

hartwork commented 10 months ago

Hi @mercuriete I think I know what the problem might be. To be able to debug this in detail and add a regression test to detect future breakage, could should share the four texts file produced by running:

gcc -S -fverbose-asm -o /dev/stdout "$(mktemp --suffix=.c)" -march=native > pentium-m--assembly--native.txt
gcc -S -fverbose-asm -o /dev/stdout "$(mktemp --suffix=.c)" -march=pentium-m > pentium-m--assembly--explicit.txt
gcc -Q --help=target -march=native > pentium-m--target-help--native.txt
gcc -Q --help=target -march=pentium-m > pentium-m--target-help--explicit.txt 

Thanks in advance!

hartwork commented 9 months ago

@mercuriete once I have these files I can jump right in with fixing the issue. Any chance to share them this week?

mercuriete commented 9 months ago

I will try to do It today. Thanks for answering.

hartwork commented 9 months ago

@mercuriete cool! :+1:

mercuriete commented 9 months ago

I am spanish so this files have some information in spanish.

pentium-m--assembly--explicit.txt pentium-m--assembly--native.txt pentium-m--target-help--explicit.txt pentium-m--target-help--native.txt

for example in some file you can see:

  Argumentos válidos conocidos para la opción -mtune=:

I dont know if that is a problem for you.

Tell me if you need more information.

Thank you for your job. I am using Gentoo Linux and your project is very good and it is on official Gentoo documentation. I have a setup with distcc and your project is very important and very awesome for preserving old hardware. Thank you very much.

mercuriete commented 9 months ago

ok after doing export LC_ALL=C

this is the result: pentium-m--assembly--explicit.txt pentium-m--assembly--native.txt pentium-m--target-help--explicit.txt pentium-m--target-help--native.txt

I hope it helps you. I think now is in english

Thank you very much.

mercuriete commented 9 months ago

I dont know if this will be useful but I will post you my cpuinfo:

cat /proc/cpuinfo 
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 13
model name      : Intel(R) Celeron(R) M processor         1.60GHz
stepping        : 8
microcode       : 0x20
cpu MHz         : 1600.000
cache size      : 1024 KB
fdiv_bug        : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 2
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov clflush dts acpi mmx fxsr sse sse2 ss tm pbe nx bts cpuid pti
bugs            : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit mmio_unknown
bogomips        : 3191.96
clflush size    : 64
cache_alignment : 64
address sizes   : 32 bits physical, 32 bits virtual
power management:

I think my acer laptop was branded as intel celeron. hope it helps you.

hartwork commented 9 months ago

@mercuriete thanks for the kind words, the files, and the second take with the C locale! :+1:

I have pull request #129 now for a candidate fix. To see the related branch in action, one way would be:

cd "$(mktemp -d)"
git clone --branch issue-127 https://github.com/hartwork/resolve-march-native
cd resolve-march-native/
python3 -m venv venv  # or: virtualenv venv
source venv/bin/activate
pip3 install -e .
hash resolve-march-native
resolve-march-native --debug

Does it work as you would expect?

mercuriete commented 9 months ago

I will try tonight. Thanks!

mercuriete commented 9 months ago

after doing that commands I got this:

resolve-march-native
-march=pentium-m -mtune=generic -mbranch-cost=3 -mno-accumulate-outgoing-args -mno-sahf --param=l1-cache-line-size=64 --param=l1-cache-size=32 --param=l2-cache-size=1024

and using it returns no error, so I think the bug is fixed.

full output:

resolve-march-native --debug
# gcc -S -fverbose-asm -o /dev/stdout /tmp/tmpdijvpd01.c -march=native
Flags extracted: --param=l1-cache-line-size=64 --param=l1-cache-size=32 --param=l2-cache-size=1024 -march=pentium-m -mfxsr -mmmx -mno-3dnow -mno-abm -mno-adx -mno-aes -mno-amx-bf16 -mno-amx-complex -mno-amx-fp16 -mno-amx-int8 -mno-amx-tile -mno-avx -mno-avx2 -mno-avx5124fmaps -mno-avx5124vnniw -mno-avx512bf16 -mno-avx512bitalg -mno-avx512bw -mno-avx512cd -mno-avx512dq -mno-avx512er -mno-avx512f -mno-avx512fp16 -mno-avx512ifma -mno-avx512pf -mno-avx512vbmi -mno-avx512vbmi2 -mno-avx512vl -mno-avx512vnni -mno-avx512vp2intersect -mno-avx512vpopcntdq -mno-avxifma -mno-avxneconvert -mno-avxvnni -mno-avxvnniint8 -mno-bmi -mno-bmi2 -mno-cldemote -mno-clflushopt -mno-clwb -mno-clzero -mno-cmpccxadd -mno-cx16 -mno-enqcmd -mno-f16c -mno-fma -mno-fma4 -mno-fsgsbase -mno-gfni -mno-hle -mno-hreset -mno-kl -mno-lwp -mno-lzcnt -mno-movbe -mno-movdir64b -mno-movdiri -mno-mwaitx -mno-pclmul -mno-pconfig -mno-pku -mno-popcnt -mno-prefetchi -mno-prefetchwt1 -mno-prfchw -mno-ptwrite -mno-raoint -mno-rdpid -mno-rdrnd -mno-rdseed -mno-rtm -mno-sahf -mno-serialize -mno-sgx -mno-sha -mno-shstk -mno-sse3 -mno-sse4.1 -mno-sse4.2 -mno-sse4a -mno-ssse3 -mno-tbm -mno-tsxldtrk -mno-uintr -mno-vaes -mno-vpclmulqdq -mno-waitpkg -mno-wbnoinvd -mno-widekl -mno-xop -mno-xsave -mno-xsavec -mno-xsaveopt -mno-xsaves -msse -msse2 -mtune=generic
# gcc -Q --help=target -march=native
Flags extracted: --param=l1-cache-line-size=64 --param=l1-cache-size=32 --param=l2-cache-size=1024 -m32 -m80387 -m96bit-long-double -mabi=sysv -maddress-mode=short -malign-data=compat -malign-functions=0 -malign-jumps=0 -malign-loops=0 -malign-stringops -march=pentium-m -masm=att -mbranch-cost=3 -mcmodel=32 -mcpu= -mdefault -mdirect-extern-access -mfancy-math-387 -mfentry-name= -mfentry-section= -mfp-ret-in-387 -mfpmath=387 -mfunction-return=keep -mfxsr -mglibc -mhard-float -mharden-sls=none -mieee-fp -mincoming-stack-boundary=0 -mindirect-branch=keep -minstrument-return=none -mlam=none -mlarge-data-threshold=65536 -mlong-double-80 -mmemcpy-strategy= -mmemset-strategy= -mmmx -mmove-max=128 -mno-128bit-long-double -mno-16 -mno-3dnow -mno-3dnowa -mno-64 -mno-8bit-idiv -mno-abm -mno-accumulate-outgoing-args -mno-adx -mno-aes -mno-align-double -mno-amx-bf16 -mno-amx-complex -mno-amx-fp16 -mno-amx-int8 -mno-amx-tile -mno-android -mno-avx -mno-avx2 -mno-avx256-split-unaligned-load -mno-avx256-split-unaligned-store -mno-avx5124fmaps -mno-avx5124vnniw -mno-avx512bf16 -mno-avx512bitalg -mno-avx512bw -mno-avx512cd -mno-avx512dq -mno-avx512er -mno-avx512f -mno-avx512fp16 -mno-avx512ifma -mno-avx512pf -mno-avx512vbmi -mno-avx512vbmi2 -mno-avx512vl -mno-avx512vnni -mno-avx512vp2intersect -mno-avx512vpopcntdq -mno-avxifma -mno-avxneconvert -mno-avxvnni -mno-avxvnniint8 -mno-bionic -mno-bmi -mno-bmi2 -mno-call-ms2sysv-xlogues -mno-cet-switch -mno-cld -mno-cldemote -mno-clflushopt -mno-clwb -mno-clzero -mno-cmpccxadd -mno-crc32 -mno-cx16 -mno-daz-ftz -mno-dispatch-scheduler -mno-dump-tune-features -mno-enqcmd -mno-f16c -mno-fentry -mno-fma -mno-fma4 -mno-force-drap -mno-force-indirect-call -mno-fsgsbase -mno-general-regs-only -mno-gfni -mno-hle -mno-hreset -mno-iamcu -mno-indirect-branch-cs-prefix -mno-indirect-branch-register -mno-inline-all-stringops -mno-inline-stringops-dynamically -mno-kl -mno-long-double-128 -mno-long-double-64 -mno-lwp -mno-lzcnt -mno-manual-endbr -mno-mitigate-rop -mno-movbe -mno-movdir64b -mno-movdiri -mno-mpx -mno-ms-bitfields -mno-musl -mno-mwait -mno-mwaitx -mno-needed -mno-nop-mcount -mno-omit-leaf-frame-pointer -mno-pc32 -mno-pc64 -mno-pc80 -mno-pclmul -mno-pcommit -mno-pconfig -mno-pku -mno-popcnt -mno-prefetchi -mno-prefetchwt1 -mno-prfchw -mno-ptwrite -mno-raoint -mno-rdpid -mno-rdrnd -mno-rdseed -mno-recip -mno-record-mcount -mno-record-return -mno-red-zone -mno-relax-cmpxchg-loop -mno-rtd -mno-rtm -mno-sahf -mno-serialize -mno-sgx -mno-sha -mno-shstk -mno-skip-rax-setup -mno-soft-float -mno-sse2avx -mno-sse3 -mno-sse4 -mno-sse4.1 -mno-sse4.2 -mno-sse4a -mno-sseregparm -mno-ssse3 -mno-stack-arg-probe -mno-stackrealign -mno-tbm -mno-tsxldtrk -mno-uclibc -mno-uintr -mno-unroll-only-small-loops -mno-vaes -mno-vect8-ret-in-mem -mno-vpclmulqdq -mno-vzeroupper -mno-waitpkg -mno-wbnoinvd -mno-widekl -mno-x32 -mno-xop -mno-xsave -mno-xsavec -mno-xsaveopt -mno-xsaves -mprefer-vector-width=none -mpreferred-stack-boundary=0 -mpush-args -mrecip= -mregparm=0 -msse -msse2 -mstack-protector-guard-offset= -mstack-protector-guard-reg= -mstack-protector-guard-symbol= -mstack-protector-guard=tls -mstore-max=128 -mstv -mtls-dialect=gnu -mtls-direct-seg-refs -mtune-ctrl= -mtune=generic
# gcc -S -fverbose-asm -o /dev/stdout /tmp/tmpd351yg3_.c -march=pentium-m
Flags extracted: -march=pentium-m
# gcc -Q --help=target -march=pentium-m
Flags extracted: -m32 -m80387 -m96bit-long-double -mabi=sysv -maccumulate-outgoing-args -maddress-mode=short -malign-data=compat -malign-functions=0 -malign-jumps=0 -malign-loops=0 -malign-stringops -march=pentium-m -masm=att -mbranch-cost=2 -mcmodel=32 -mcpu= -mdefault -mdirect-extern-access -mfancy-math-387 -mfentry-name= -mfentry-section= -mfp-ret-in-387 -mfpmath=387 -mfunction-return=keep -mfxsr -mglibc -mhard-float -mharden-sls=none -mieee-fp -mincoming-stack-boundary=0 -mindirect-branch=keep -minstrument-return=none -mlam=none -mlarge-data-threshold=65536 -mlong-double-80 -mmemcpy-strategy= -mmemset-strategy= -mmmx -mmove-max=128 -mno-128bit-long-double -mno-16 -mno-3dnow -mno-3dnowa -mno-64 -mno-8bit-idiv -mno-abm -mno-adx -mno-aes -mno-align-double -mno-amx-bf16 -mno-amx-complex -mno-amx-fp16 -mno-amx-int8 -mno-amx-tile -mno-android -mno-avx -mno-avx2 -mno-avx256-split-unaligned-load -mno-avx256-split-unaligned-store -mno-avx5124fmaps -mno-avx5124vnniw -mno-avx512bf16 -mno-avx512bitalg -mno-avx512bw -mno-avx512cd -mno-avx512dq -mno-avx512er -mno-avx512f -mno-avx512fp16 -mno-avx512ifma -mno-avx512pf -mno-avx512vbmi -mno-avx512vbmi2 -mno-avx512vl -mno-avx512vnni -mno-avx512vp2intersect -mno-avx512vpopcntdq -mno-avxifma -mno-avxneconvert -mno-avxvnni -mno-avxvnniint8 -mno-bionic -mno-bmi -mno-bmi2 -mno-call-ms2sysv-xlogues -mno-cet-switch -mno-cld -mno-cldemote -mno-clflushopt -mno-clwb -mno-clzero -mno-cmpccxadd -mno-crc32 -mno-cx16 -mno-daz-ftz -mno-dispatch-scheduler -mno-dump-tune-features -mno-enqcmd -mno-f16c -mno-fentry -mno-fma -mno-fma4 -mno-force-drap -mno-force-indirect-call -mno-fsgsbase -mno-general-regs-only -mno-gfni -mno-hle -mno-hreset -mno-iamcu -mno-indirect-branch-cs-prefix -mno-indirect-branch-register -mno-inline-all-stringops -mno-inline-stringops-dynamically -mno-kl -mno-long-double-128 -mno-long-double-64 -mno-lwp -mno-lzcnt -mno-manual-endbr -mno-mitigate-rop -mno-movbe -mno-movdir64b -mno-movdiri -mno-mpx -mno-ms-bitfields -mno-musl -mno-mwait -mno-mwaitx -mno-needed -mno-nop-mcount -mno-omit-leaf-frame-pointer -mno-pc32 -mno-pc64 -mno-pc80 -mno-pclmul -mno-pcommit -mno-pconfig -mno-pku -mno-popcnt -mno-prefetchi -mno-prefetchwt1 -mno-prfchw -mno-ptwrite -mno-raoint -mno-rdpid -mno-rdrnd -mno-rdseed -mno-recip -mno-record-mcount -mno-record-return -mno-red-zone -mno-relax-cmpxchg-loop -mno-rtd -mno-rtm -mno-serialize -mno-sgx -mno-sha -mno-shstk -mno-skip-rax-setup -mno-soft-float -mno-sse2avx -mno-sse3 -mno-sse4 -mno-sse4.1 -mno-sse4.2 -mno-sse4a -mno-sseregparm -mno-ssse3 -mno-stack-arg-probe -mno-stackrealign -mno-tbm -mno-tsxldtrk -mno-uclibc -mno-uintr -mno-unroll-only-small-loops -mno-vaes -mno-vect8-ret-in-mem -mno-vpclmulqdq -mno-vzeroupper -mno-waitpkg -mno-wbnoinvd -mno-widekl -mno-x32 -mno-xop -mno-xsave -mno-xsavec -mno-xsaveopt -mno-xsaves -mprefer-vector-width=none -mpreferred-stack-boundary=0 -mpush-args -mrecip= -mregparm=0 -msahf -msse -msse2 -mstack-protector-guard-offset= -mstack-protector-guard-reg= -mstack-protector-guard-symbol= -mstack-protector-guard=tls -mstore-max=128 -mstv -mtls-dialect=gnu -mtls-direct-seg-refs -mtune-ctrl= -mtune=pentium-m
-march=pentium-m -mtune=generic -mbranch-cost=3 -mno-accumulate-outgoing-args -mno-sahf --param=l1-cache-line-size=64 --param=l1-cache-size=32 --param=l2-cache-size=1024

So, I am not an expert so I don't know if that is the correct fix but it seems so.

Thanks you very much for your help and your quick answer. I hope you and this project succed. :heart:

hartwork commented 9 months ago

@mercuriete thanks for testing and reporting back! I have already published 5.0.2 with this fix to GitHub and PyPI but Gentoo SSH rejects my push because it rejects GPG keys that are 12 days near expiration. I hope to be able to push 5.0.2 tomorrow, with some luck.

mercuriete commented 9 months ago

@hartwork dont worry. I appreciate your work. I already know what are my safe CFLAGS so I will wait until is gentoo is ready.

Thanks again for your quick answer. This projects is allowing me to keep old hardware running properly :smile:

hartwork commented 9 months ago

I hope to be able to push 5.0.2 tomorrow, with some luck.

Quick update: I published a prolonged GPG public key by now and pushing 5.0.2 to Gentoo succeeded: https://github.com/gentoo/gentoo/commit/61a56b72f82db351d87ef24a7d554221a4b91a32 .

mercuriete commented 9 months ago

Sorry for commenting in a closed ticket. It just for say thank you again.

Today I am doing an emerge --update --deep with the new CFLAGS reported by this tool. I am using the official release on Gentoo 5.0.2 of this tool right now.

It works perfectly so thank you.

hartwork commented 9 months ago

@mercuriete glad I could help your case, thanks for the report! :+1: