我有一个功能,Rust的/ LLVM的优化失败并导致恐慌(在发布版本中),而未优化的代码(调试版本)工作正常.如果我比较生成的汇编代码,我甚至无法理解优化器试图完成的任务.(原因可能是这个函数使用内联汇编程序.)
有没有办法告诉Rust在优化过程中单独保留某些功能,还是必须关闭所有优化?
这是具体功能:
#[naked]
pub extern "C" fn dispatch_svc(){
Cpu::save_context();
let mut nr: u32 = 0;
unsafe {
asm!("ldr r0, [lr, #-4]
bic $0, r0, #0xff000000":"=r"(nr)::"r0":"volatile")
};
swi_service_routine(nr);
Cpu::restore_context_and_return();
}
Run Code Online (Sandbox Code Playgroud) 是否可以为工作空间成员指定特定的配置文件?如果我将个人资料写入会员,Cargo.toml我将得到:
警告:非根软件包的配置文件将被忽略,请在工作区根目录中指定配置文件:
我还尝试将特定的配置文件放入工作区根目录Cargo.toml:
[profile.release]
opt-level = 3
[profile.release.hal]
# optimizer kills assembly code
opt-level = 1
Run Code Online (Sandbox Code Playgroud)
但是,它似乎也被忽略了,因为详细输出中的应用选项显示:
运行`rustc --crate-name hal src / hal / lib.rs --crate-type lib -C opt-level = 3 --emit = dep-info,link [...]
除了完全避免工作空间之外,还有其他方法吗?
我正在为Rust中的AMR板写一个裸机应用程序,它涉及中断服务程序.目前,我使用#naked自己的汇编程序prolog/epilog函数.但是,我想知道是否有更好的(并且希望更便携)方式我错过了,也许#interruptRust中的类似属性或任何其他编译器支持.我认为,就像GCC一样__attribute__ ((interrupt ("IRQ"))),Rust的后端LLVM提供了这样的属性.
RFC 1358提出了一个对齐属性#[repr(align="N")],它被接受了.Rust问题33626将该功能纳入夜间版本.
我无法使用此功能rustc 1.19.0-nightly (777ee2079 2017-05-01).如果我在没有 feature gate(#![feature(repr_align)])的情况下编译:
#[repr(align="16")]
struct Foo {
bar: u32,
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误声明:
error: the struct `#[repr(align(u16))]` attribute is experimental (see issue #33626)
--> foo.rs:3:1
|
3 | / struct Foo {
4 | | bar: u32,
5 | | }
| |_^
|
= help: add #![feature(repr_align)] to the crate attributes to enable
Run Code Online (Sandbox Code Playgroud)
当我使用功能门编译时,错误消息显示:
error[E0552]: unrecognized representation hint
--> foo.rs:3:8 …Run Code Online (Sandbox Code Playgroud) 我有一个场景,对于任何给定的数字,我需要识别相应的2值的权力.例如,如果给定的数字是12:
图12中的2表示功率为:2表示功率为3表示2表示功率为2表示功率为2表示为2表示功率为2表示功率为2表示功率为2表示功率为2表示功率为2
我可以知道在这种情况下命名的算法吗?