Skip to content

Commit f8c17ac

Browse files
authored
Unrolled build for rust-lang#136217
Rollup merge of rust-lang#136217 - taiki-e:csky-asm-flags, r=Amanieu Mark condition/carry bit as clobbered in C-SKY inline assembly C-SKY's compare and some arithmetic/logical instructions modify condition/carry bit (C) in PSR, but there is currently no way to mark it as clobbered in `asm!`. This PR marks it as clobbered except when [`options(preserves_flags)`](https://doc.rust-lang.org/reference/inline-assembly.html#r-asm.options.supported-options.preserves_flags) is used. Refs: - Section 1.3 "Programming model" and Section 1.3.5 "Condition/carry bit" in CSKY Architecture user_guide: https://github.com/c-sky/csky-doc/blob/9f7121f7d40970ba5cc0f15716da033db2bb9d07/CSKY%20Architecture%20user_guide.pdf > Under user mode, condition/carry bit (C) is located in the lowest bit of PSR, and it can be accessed and changed by common user instructions. It is the only data bit that can be visited under user mode in PSR. > Condition or carry bit represents the result after one operation. Condition/carry bit can be clearly set according to the results of compare instructions or unclearly set as some high-precision arithmetic or logical instructions. In addition, special instructions such as DEC[GT,LT,NE] and XTRB[0-3] will influence the value of condition/carry bit. - Register definition in LLVM: https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/CSKY/CSKYRegisterInfo.td#L88 cc ```@Dirreke``` ([target maintainer](https://github.com/rust-lang/rust/blob/aa6f5ab18e67cb815f73e0d53d217bc54b0da924/src/doc/rustc/src/platform-support/csky-unknown-linux-gnuabiv2.md#target-maintainers)) r? ```@Amanieu``` ```@rustbot``` label +O-csky +A-inline-assembly
2 parents 6dce9f8 + 93465e6 commit f8c17ac

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
286286
InlineAsmArch::M68k => {
287287
constraints.push("~{ccr}".to_string());
288288
}
289-
InlineAsmArch::CSKY => {}
289+
InlineAsmArch::CSKY => {
290+
constraints.push("~{psr}".to_string());
291+
}
290292
}
291293
}
292294
if !options.contains(InlineAsmOptions::NOMEM) {

src/doc/unstable-book/src/language-features/asm-experimental-arch.md

+2
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,5 @@ These flags registers must be restored upon exiting the asm block if the `preser
199199
- SPARC
200200
- Integer condition codes (`icc` and `xcc`)
201201
- Floating-point condition codes (`fcc[0-3]`)
202+
- CSKY
203+
- Condition/carry bit (C) in `PSR`.

tests/codegen/asm/csky-clobbers.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//@ add-core-stubs
2+
//@ compile-flags: --target csky-unknown-linux-gnuabiv2
3+
//@ needs-llvm-components: csky
4+
5+
#![crate_type = "rlib"]
6+
#![feature(no_core, asm_experimental_arch)]
7+
#![no_core]
8+
9+
extern crate minicore;
10+
use minicore::*;
11+
12+
// CHECK-LABEL: @flags_clobber
13+
// CHECK: call void asm sideeffect "", "~{psr}"()
14+
#[no_mangle]
15+
pub unsafe fn flags_clobber() {
16+
asm!("", options(nostack, nomem));
17+
}
18+
19+
// CHECK-LABEL: @no_clobber
20+
// CHECK: call void asm sideeffect "", ""()
21+
#[no_mangle]
22+
pub unsafe fn no_clobber() {
23+
asm!("", options(nostack, nomem, preserves_flags));
24+
}

0 commit comments

Comments
 (0)