Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zig cc: integration with -m flags #4912

Closed
andrewrk opened this issue Apr 2, 2020 · 3 comments
Closed

zig cc: integration with -m flags #4912

andrewrk opened this issue Apr 2, 2020 · 3 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. zig cc Zig as a drop-in C compiler feature
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Apr 2, 2020

Extracted from #4784.

As you can see there are quite a few -m flags that control CPU features:

flagpd1("m16"),
flagpd1("m32"),
flagpd1("m3dnow"),
flagpd1("m3dnowa"),
flagpd1("m64"),
flagpd1("m80387"),
flagpd1("mabi=ieeelongdouble"),
flagpd1("mabicalls"),
flagpd1("madx"),
flagpd1("maes"),
sepd1("main-file-name"),
flagpd1("malign-double"),
flagpd1("maltivec"),
flagpd1("marm"),
flagpd1("masm-verbose"),
flagpd1("massembler-fatal-warnings"),
flagpd1("massembler-no-warn"),
flagpd1("matomics"),
flagpd1("mavx"),
flagpd1("mavx2"),
flagpd1("mavx512bf16"),
flagpd1("mavx512bitalg"),
flagpd1("mavx512bw"),
flagpd1("mavx512cd"),
flagpd1("mavx512dq"),
flagpd1("mavx512er"),
flagpd1("mavx512f"),
flagpd1("mavx512ifma"),
flagpd1("mavx512pf"),
flagpd1("mavx512vbmi"),
flagpd1("mavx512vbmi2"),
flagpd1("mavx512vl"),
flagpd1("mavx512vnni"),
flagpd1("mavx512vp2intersect"),
flagpd1("mavx512vpopcntdq"),
flagpd1("fmax-identifier-length"),
flagpd1("fno-max-identifier-length"),
flagpd1("mbackchain"),
flagpd1("mbig-endian"),
flagpd1("mbmi"),
flagpd1("mbmi2"),
flagpd1("mbranch-likely"),
flagpd1("mbranch-target-enforce"),
flagpd1("mbranches-within-32B-boundaries"),
flagpd1("mbulk-memory"),
flagpd1("mcheck-zero-division"),
flagpd1("mcldemote"),
flagpd1("mclflushopt"),
flagpd1("mclwb"),
flagpd1("mclzero"),
flagpd1("mcmodel=medany"),
flagpd1("mcmodel=medlow"),
flagpd1("mcmpb"),
flagpd1("mcmse"),
sepd1("mcode-model"),
flagpd1("mcode-object-v3"),
flagpd1("mconstant-cfstrings"),
flagpd1("mconstructor-aliases"),
flagpd1("mcpu=?"),
flagpd1("mcrbits"),
flagpd1("mcrc"),
flagpd1("mcumode"),
flagpd1("mcx16"),
sepd1("mdebug-pass"),
flagpd1("mdirect-move"),
flagpd1("mdisable-tail-calls"),
flagpd1("mdouble-float"),
flagpd1("mdsp"),
flagpd1("mdspr2"),
sepd1("meabi"),
flagpd1("membedded-data"),
flagpd1("menable-no-infs"),
flagpd1("menable-no-nans"),
flagpd1("menable-unsafe-fp-math"),
flagpd1("menqcmd"),
flagpd1("fmerge-constants"),
flagpd1("fno-merge-constants"),
flagpd1("mexception-handling"),
flagpd1("mexecute-only"),
flagpd1("mextern-sdata"),
flagpd1("mf16c"),
flagpd1("mfancy-math-387"),
flagpd1("mfentry"),
flagpd1("mfix-and-continue"),
flagpd1("mfix-cortex-a53-835769"),
flagpd1("mfloat128"),
sepd1("mfloat-abi"),
flagpd1("mfma"),
flagpd1("mfma4"),
flagpd1("mfp32"),
flagpd1("mfp64"),
sepd1("mfpmath"),
flagpd1("mfprnd"),
flagpd1("mfpxx"),
flagpd1("mfsgsbase"),
flagpd1("mfxsr"),
flagpd1("mgeneral-regs-only"),
flagpd1("mgfni"),
flagpd1("mginv"),
flagpd1("mglibc"),
flagpd1("mglobal-merge"),
flagpd1("mgpopt"),
flagpd1("mhard-float"),
flagpd1("mhvx"),
flagpd1("mhtm"),
flagpd1("miamcu"),
flagpd1("mieee-fp"),
flagpd1("mieee-rnd-near"),
flagpd1("migrate"),
flagpd1("no-finalize-removal"),
flagpd1("no-ns-alloc-error"),
flagpd1("mimplicit-float"),
flagpd1("mincremental-linker-compatible"),
flagpd1("minline-all-stringops"),
flagpd1("minvariant-function-descriptors"),
flagpd1("minvpcid"),
flagpd1("mips1"),
flagpd1("mips16"),
flagpd1("mips2"),
flagpd1("mips3"),
flagpd1("mips32"),
flagpd1("mips32r2"),
flagpd1("mips32r3"),
flagpd1("mips32r5"),
flagpd1("mips32r6"),
flagpd1("mips4"),
flagpd1("mips5"),
flagpd1("mips64"),
flagpd1("mips64r2"),
flagpd1("mips64r3"),
flagpd1("mips64r5"),
flagpd1("mips64r6"),
flagpd1("misel"),
flagpd1("mkernel"),
flagpd1("mldc1-sdc1"),
sepd1("mlimit-float-precision"),
sepd1("mlink-bitcode-file"),
sepd1("mlink-builtin-bitcode"),
sepd1("mlink-cuda-bitcode"),
flagpd1("mlittle-endian"),
sepd1("mllvm"),
flagpd1("mlocal-sdata"),
flagpd1("mlong-calls"),
flagpd1("mlong-double-128"),
flagpd1("mlong-double-64"),
flagpd1("mlong-double-80"),
flagpd1("mlongcall"),
flagpd1("mlwp"),
flagpd1("mlzcnt"),
flagpd1("mmadd4"),
flagpd1("mmemops"),
flagpd1("mmfcrf"),
flagpd1("mmfocrf"),
flagpd1("mmicromips"),
flagpd1("mmmx"),
flagpd1("mmovbe"),
flagpd1("mmovdir64b"),
flagpd1("mmovdiri"),
flagpd1("mmpx"),
flagpd1("mms-bitfields"),
flagpd1("mmsa"),
flagpd1("mmt"),
flagpd1("mmultivalue"),
flagpd1("mmutable-globals"),
flagpd1("mmwaitx"),
flagpd1("mno-3dnow"),
flagpd1("mno-3dnowa"),
flagpd1("mno-80387"),
flagpd1("mno-abicalls"),
flagpd1("mno-adx"),
flagpd1("mno-aes"),
flagpd1("mno-altivec"),
flagpd1("mno-atomics"),
flagpd1("mno-avx"),
flagpd1("mno-avx2"),
flagpd1("mno-avx512bf16"),
flagpd1("mno-avx512bitalg"),
flagpd1("mno-avx512bw"),
flagpd1("mno-avx512cd"),
flagpd1("mno-avx512dq"),
flagpd1("mno-avx512er"),
flagpd1("mno-avx512f"),
flagpd1("mno-avx512ifma"),
flagpd1("mno-avx512pf"),
flagpd1("mno-avx512vbmi"),
flagpd1("mno-avx512vbmi2"),
flagpd1("mno-avx512vl"),
flagpd1("mno-avx512vnni"),
flagpd1("mno-avx512vp2intersect"),
flagpd1("mno-avx512vpopcntdq"),
flagpd1("mno-backchain"),
flagpd1("mno-bmi"),
flagpd1("mno-bmi2"),
flagpd1("mno-branch-likely"),
flagpd1("mno-bulk-memory"),
flagpd1("mno-check-zero-division"),
flagpd1("mno-cldemote"),
flagpd1("mno-clflushopt"),
flagpd1("mno-clwb"),
flagpd1("mno-clzero"),
flagpd1("mno-cmpb"),
flagpd1("mno-code-object-v3"),
flagpd1("mno-constant-cfstrings"),
flagpd1("mno-crbits"),
flagpd1("mno-crc"),
flagpd1("mno-cumode"),
flagpd1("mno-cx16"),
flagpd1("mno-dsp"),
flagpd1("mno-dspr2"),
flagpd1("mno-embedded-data"),
flagpd1("mno-enqcmd"),
flagpd1("mno-exception-handling"),
flagpd1("mnoexecstack"),
flagpd1("mno-execute-only"),
flagpd1("mno-extern-sdata"),
flagpd1("mno-f16c"),
flagpd1("mno-fix-cortex-a53-835769"),
flagpd1("mno-float128"),
flagpd1("mno-fma"),
flagpd1("mno-fma4"),
flagpd1("mno-fprnd"),
flagpd1("mno-fsgsbase"),
flagpd1("mno-fxsr"),
flagpd1("mno-gfni"),
flagpd1("mno-ginv"),
flagpd1("mno-global-merge"),
flagpd1("mno-gpopt"),
flagpd1("mno-hvx"),
flagpd1("mno-htm"),
flagpd1("mno-iamcu"),
flagpd1("mno-implicit-float"),
flagpd1("mno-incremental-linker-compatible"),
flagpd1("mno-inline-all-stringops"),
flagpd1("mno-invariant-function-descriptors"),
flagpd1("mno-invpcid"),
flagpd1("mno-isel"),
flagpd1("mno-ldc1-sdc1"),
flagpd1("mno-local-sdata"),
flagpd1("mno-long-calls"),
flagpd1("mno-longcall"),
flagpd1("mno-lwp"),
flagpd1("mno-lzcnt"),
flagpd1("mno-madd4"),
flagpd1("mno-memops"),
flagpd1("mno-mfcrf"),
flagpd1("mno-mfocrf"),
flagpd1("mno-micromips"),
flagpd1("mno-mips16"),
flagpd1("mno-mmx"),
flagpd1("mno-movbe"),
flagpd1("mno-movdir64b"),
flagpd1("mno-movdiri"),
flagpd1("mno-movt"),
flagpd1("mno-mpx"),
flagpd1("mno-ms-bitfields"),
flagpd1("mno-msa"),
flagpd1("mno-mt"),
flagpd1("mno-multivalue"),
flagpd1("mno-mutable-globals"),
flagpd1("mno-mwaitx"),
flagpd1("mno-neg-immediates"),
flagpd1("mno-nontrapping-fptoint"),
flagpd1("mno-nvj"),
flagpd1("mno-nvs"),
flagpd1("mno-odd-spreg"),
flagpd1("mno-omit-leaf-frame-pointer"),
flagpd1("mno-outline"),
flagpd1("mno-packed-stack"),
flagpd1("mno-packets"),
flagpd1("mno-pascal-strings"),
flagpd1("mno-pclmul"),
flagpd1("mno-pconfig"),
flagpd1("mno-pie-copy-relocations"),
flagpd1("mno-pku"),
flagpd1("mno-popcnt"),
flagpd1("mno-popcntd"),
flagpd1("mno-power8-vector"),
flagpd1("mno-power9-vector"),
flagpd1("mno-prefetchwt1"),
flagpd1("mno-prfchw"),
flagpd1("mno-ptwrite"),
flagpd1("mno-pure-code"),
flagpd1("mno-qpx"),
flagpd1("mno-rdpid"),
flagpd1("mno-rdrnd"),
flagpd1("mno-rdseed"),
flagpd1("mno-red-zone"),
flagpd1("mno-reference-types"),
flagpd1("mno-relax"),
flagpd1("mno-relax-all"),
flagpd1("mno-relax-pic-calls"),
flagpd1("mno-restrict-it"),
flagpd1("mno-retpoline"),
flagpd1("mno-retpoline-external-thunk"),
flagpd1("mno-rtd"),
flagpd1("mno-rtm"),
flagpd1("mno-sahf"),
flagpd1("mno-save-restore"),
flagpd1("mno-sgx"),
flagpd1("mno-sha"),
flagpd1("mno-shstk"),
flagpd1("mno-sign-ext"),
flagpd1("mno-simd128"),
flagpd1("mno-soft-float"),
flagpd1("mno-spe"),
flagpd1("mno-speculative-load-hardening"),
flagpd1("mno-sram-ecc"),
flagpd1("mno-sse"),
flagpd1("mno-sse2"),
flagpd1("mno-sse3"),
flagpd1("mno-sse4"),
flagpd1("mno-sse4.1"),
flagpd1("mno-sse4.2"),
flagpd1("mno-sse4a"),
flagpd1("mno-ssse3"),
flagpd1("mno-stack-arg-probe"),
flagpd1("mno-stackrealign"),
flagpd1("mno-tail-call"),
flagpd1("mno-tbm"),
flagpd1("mno-thumb"),
flagpd1("mno-tls-direct-seg-refs"),
flagpd1("mno-unaligned-access"),
flagpd1("mno-unimplemented-simd128"),
flagpd1("mno-vaes"),
flagpd1("mno-virt"),
flagpd1("mno-vpclmulqdq"),
flagpd1("mno-vsx"),
flagpd1("mno-vx"),
flagpd1("mno-vzeroupper"),
flagpd1("mno-waitpkg"),
flagpd1("mno-warn-nonportable-cfstrings"),
flagpd1("mno-wavefrontsize64"),
flagpd1("mno-wbnoinvd"),
flagpd1("mno-x87"),
flagpd1("mno-xgot"),
flagpd1("mno-xnack"),
flagpd1("mno-xop"),
flagpd1("mno-xsave"),
flagpd1("mno-xsavec"),
flagpd1("mno-xsaveopt"),
flagpd1("mno-xsaves"),
flagpd1("mno-zero-initialized-in-bss"),
flagpd1("mno-zvector"),
flagpd1("mnocrc"),
flagpd1("mno-direct-move"),
flagpd1("mnontrapping-fptoint"),
flagpd1("mnop-mcount"),
flagpd1("mno-crypto"),

Currently the way these work is they will be forwarded to clang without zig being aware of them. The forwarding happens after zig specifies the CPU features flags, so I believe there is not currently a correctness problem here. However, zig does have CPU features awareness, and when these flags are specified, zig's idea of what CPU features are enabled can be incorrect (even though it ends up passing correct flags to clang). I can't think of this causing an actual problem, but it's an "invariant" that is violated, which could have unforeseen consequences in the future. For example, one thing is that these flags will cause false negatives in the cache (zig could have cached something but did not).

Hopefully there is someway to solve these in bulk; although if maintaining a manual mapping of these flags to CPU features is what is required, it would still be workable.

@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. zig cc Zig as a drop-in C compiler feature labels Apr 2, 2020
@andrewrk andrewrk added this to the 0.7.0 milestone Apr 2, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 14, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@ryancinsight
Copy link

is there a way to initiate this bypass, I can't seem to get -mcx16 to work

@LemonBoy
Copy link
Contributor

LemonBoy commented May 7, 2021

is there a way to initiate this bypass, I can't seem to get -mcx16 to work

-mcpu=x86_64_v2 or -mcpu=generic+cx16, replace generic with whatever base model you prefer.

@andrewrk
Copy link
Member Author

Done in b097545.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. zig cc Zig as a drop-in C compiler feature
Projects
None yet
Development

No branches or pull requests

3 participants