Skip to content

expose CPU and features as part of the target #2051

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

Closed
justinbalexander opened this issue Mar 11, 2019 · 5 comments
Closed

expose CPU and features as part of the target #2051

justinbalexander opened this issue Mar 11, 2019 · 5 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. stage1 The process of building from source via WebAssembly and the C backend. zig build system std.Build, the build runner, `zig build` subcommand, package management
Milestone

Comments

@justinbalexander
Copy link
Contributor

When building for a Cortex-M4F there is currently no way to tell LLVM to use the floating point unit on the processor.

With clang you can pass the option -mfpu=fpv4-sp-d16 and -mfloat-abi=hard and it will output the correct assembly and use the FPU.

Using the options "-mllvm -float-abi=hard -mllvm -fpu=fpv4-sp-d16" gives an llvm error unless I am mistaken.

Regardless, having a zig native way to specify those options would be nice.

@andrewrk andrewrk added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Mar 11, 2019
@andrewrk andrewrk added this to the 0.5.0 milestone Mar 11, 2019
@andrewrk andrewrk added the contributor friendly This issue is limited in scope and/or knowledge of Zig internals. label Mar 11, 2019
@andrewrk
Copy link
Member

Thanks for typing up the issue. Float-abi = hard should work by specifying gnueabihf, eabihf, or musleabihf` for the target ABI. Is that not working?

As for -fpu=fpv4-sp-d16, I think this is a general problem of exposing CPU args/features. I'm guessing here:

zig/src/codegen.cpp

Lines 7830 to 7835 in f2ca2ac

target_specific_cpu_args = "";
target_specific_features = "";
}
g->target_machine = LLVMCreateTargetMachine(target_ref, buf_ptr(&g->triple_str),
target_specific_cpu_args, target_specific_features, opt_level, reloc_mode, LLVMCodeModelDefault);

This is something I haven't looked into yet to know the best way to do it, but I'd accept a pull request that provides a workaround exposing this option to the CLI (and the build system which is mostly in std/build.zig).

@justinbalexander
Copy link
Contributor Author

justinbalexander commented Mar 11, 2019 via email

@andrewrk andrewrk added the zig build system std.Build, the build runner, `zig build` subcommand, package management label Jul 4, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Aug 28, 2019
@andrewrk andrewrk removed the contributor friendly This issue is limited in scope and/or knowledge of Zig internals. label Sep 3, 2019
@andrewrk
Copy link
Member

andrewrk commented Sep 3, 2019

I think this issue may be a bit difficult for drive-by contributors. I'll repeat the comment I made on a pull request here:

Although LLVM is currently the only backend of Zig, the language does not depend on LLVM, and it is planned to support non-LLVM backends. Even though the target cpu and features options need to eventually be given to LLVM in a way that LLVM understands, we still need to expose these options in a way that is independent of LLVM. That means the CLI option cannot be called --llvm-cpu or --llvm- anything. zig targets must list all the possible options. The CLI should be able to reject invalid options without consulting LLVM.

I recognize this is in direct contradiction with my earlier comment, and I apologize for that. Sometimes it takes me a while to realize the path forward.

@andrewrk andrewrk changed the title Support specifying the floating point unit with build system expose CPU and features as part of the target Sep 3, 2019
@andrewrk andrewrk added the stage1 The process of building from source via WebAssembly and the C backend. label Sep 3, 2019
@andrewrk
Copy link
Member

andrewrk commented Sep 3, 2019

I'm not sure I'll be able to do it in time for 0.5.0, but I'll give this a slight priority bump, at the expense of other issues in the 0.5.0 milestone.

@andrewrk
Copy link
Member

I accidentally made a duplicate issue here: #2883

But since that issue has the checklist, I'll make this one refer to that one. I consider this a high priority issue for this milestone.

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. stage1 The process of building from source via WebAssembly and the C backend. zig build system std.Build, the build runner, `zig build` subcommand, package management
Projects
None yet
Development

No branches or pull requests

2 participants