Skip to content

Commit de70798

Browse files
Rollup merge of rust-lang#147302 - esp-rs:xtensa-asm, r=Amanieu
asm! support for the Xtensa architecture This implements the asm! support for Xtensa. We've been using this code for a few years in [our fork](https://github.com/esp-rs/rust) and it's been working well. I finally found some time to clean it up a bit and start the upstreaming process. This should be one of the final PRs for Xtensa support on the Rust side (minus bug fixes of course). After this, we're mostly just waiting on the LLVM upstreaming which is going well. This PR doesn't cover all possible asm options for Xtensa, but the base ISA plus a few extras that are used in Espressif chips. r? Amanieu
2 parents 877a131 + 768fc10 commit de70798

12 files changed

Lines changed: 665 additions & 2 deletions

File tree

compiler/rustc_codegen_gcc/src/asm.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,11 @@ fn reg_class_to_gcc(reg_class: InlineAsmRegClass) -> &'static str {
751751
| X86InlineAsmRegClass::mmx_reg
752752
| X86InlineAsmRegClass::tmm_reg,
753753
) => unreachable!("clobber-only"),
754+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => "r",
755+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => "f",
756+
InlineAsmRegClass::Xtensa(
757+
XtensaInlineAsmRegClass::sreg | XtensaInlineAsmRegClass::breg,
758+
) => unreachable!("clobber-only"),
754759
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
755760
bug!("GCC backend does not support SPIR-V")
756761
}
@@ -872,6 +877,11 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
872877
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
873878
bug!("GCC backend does not support SPIR-V")
874879
}
880+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
881+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
882+
InlineAsmRegClass::Xtensa(
883+
XtensaInlineAsmRegClass::sreg | XtensaInlineAsmRegClass::breg,
884+
) => unreachable!("clobber-only"),
875885
InlineAsmRegClass::Err => unreachable!(),
876886
}
877887
}
@@ -1070,6 +1080,7 @@ fn modifier_to_gcc(
10701080
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
10711081
bug!("LLVM backend does not support SPIR-V")
10721082
}
1083+
InlineAsmRegClass::Xtensa(_) => None,
10731084
InlineAsmRegClass::Err => unreachable!(),
10741085
}
10751086
}

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
278278
}
279279
InlineAsmArch::SpirV => {}
280280
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {}
281+
InlineAsmArch::Xtensa => {}
281282
InlineAsmArch::Bpf => {}
282283
InlineAsmArch::Msp430 => {
283284
constraints.push("~{sr}".to_string());
@@ -740,6 +741,11 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
740741
| X86InlineAsmRegClass::kreg0
741742
| X86InlineAsmRegClass::tmm_reg,
742743
) => unreachable!("clobber-only"),
744+
Xtensa(XtensaInlineAsmRegClass::freg) => "f",
745+
Xtensa(XtensaInlineAsmRegClass::reg) => "r",
746+
Xtensa(XtensaInlineAsmRegClass::sreg | XtensaInlineAsmRegClass::breg) => {
747+
unreachable!("clobber-only")
748+
}
743749
Wasm(WasmInlineAsmRegClass::local) => "r",
744750
Bpf(BpfInlineAsmRegClass::reg) => "r",
745751
Bpf(BpfInlineAsmRegClass::wreg) => "w",
@@ -845,6 +851,7 @@ fn modifier_to_llvm(
845851
| X86InlineAsmRegClass::kreg0
846852
| X86InlineAsmRegClass::tmm_reg,
847853
) => unreachable!("clobber-only"),
854+
Xtensa(_) => None,
848855
Wasm(WasmInlineAsmRegClass::local) => None,
849856
Bpf(_) => None,
850857
Avr(AvrInlineAsmRegClass::reg_pair)
@@ -939,6 +946,11 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
939946
| X86InlineAsmRegClass::kreg0
940947
| X86InlineAsmRegClass::tmm_reg,
941948
) => unreachable!("clobber-only"),
949+
Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
950+
Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
951+
Xtensa(XtensaInlineAsmRegClass::sreg | XtensaInlineAsmRegClass::breg) => {
952+
unreachable!("clobber-only")
953+
}
942954
Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
943955
Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
944956
Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(),

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,8 @@ declare_features! (
775775
(unstable, x87_target_feature, "1.85.0", Some(150261)),
776776
/// Allows use of the `xop` target-feature
777777
(unstable, xop_target_feature, "1.81.0", Some(127208)),
778+
/// Allows use of the Xtensa target-features
779+
(unstable, xtensa_target_feature, "CURRENT_RUSTC_VERSION", Some(157063)),
778780
/// Allows `do yeet` expressions
779781
(unstable, yeet_expr, "1.62.0", Some(96373)),
780782
(unstable, yield_expr, "1.87.0", Some(43122)),

compiler/rustc_span/src/symbol.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ symbols! {
468468
async_iterator,
469469
async_iterator_poll_next,
470470
async_trait_bounds,
471+
atomic,
471472
atomic_and,
472473
atomic_cxchg,
473474
atomic_cxchgweak,
@@ -542,6 +543,7 @@ symbols! {
542543
braced_empty_structs,
543544
branch,
544545
breakpoint,
546+
breg,
545547
bridge,
546548
bswap,
547549
built,
@@ -706,6 +708,7 @@ symbols! {
706708
contracts_internals,
707709
contracts_requires,
708710
convert,
711+
coprocessor,
709712
copy,
710713
copy_closures,
711714
copy_nonoverlapping,
@@ -881,6 +884,7 @@ symbols! {
881884
ermsb_target_feature,
882885
exact_div,
883886
except,
887+
exception,
884888
exception_handling: "exception-handling",
885889
exclusive_range_pattern,
886890
exhaustive_integer_patterns,
@@ -907,6 +911,7 @@ symbols! {
907911
expr_fragment_specifier_2024,
908912
extended_key_value_attributes,
909913
extended_varargs_abi_support,
914+
extendedl32r,
910915
extern_absolute_paths,
911916
extern_crate_item_prelude,
912917
extern_crate_self,
@@ -990,6 +995,9 @@ symbols! {
990995
format_argument,
991996
format_arguments,
992997
format_macro,
998+
format_placeholder,
999+
format_unsafe_arg,
1000+
fp,
9931001
framework,
9941002
freeze,
9951003
freeze_impls,
@@ -1051,6 +1059,8 @@ symbols! {
10511059
hexagon_target_feature,
10521060
hidden,
10531061
hide,
1062+
highpriinterrupts,
1063+
hint,
10541064
homogeneous_aggregate,
10551065
html_favicon_url,
10561066
html_logo_url,
@@ -1111,6 +1121,7 @@ symbols! {
11111121
internal,
11121122
internal_eq_trait_method_impls,
11131123
internal_features,
1124+
interrupt,
11141125
into_async_iter_into_iter,
11151126
into_future,
11161127
into_iter,
@@ -1206,6 +1217,7 @@ symbols! {
12061217
lt,
12071218
m68k,
12081219
m68k_target_feature,
1220+
mac16,
12091221
macho: "mach-o",
12101222
macro_at_most_once_rep,
12111223
macro_attr,
@@ -1318,6 +1330,8 @@ symbols! {
13181330
mir_unwind_unreachable,
13191331
mir_variant,
13201332
miri,
1333+
misc,
1334+
miscsr,
13211335
mmx_reg,
13221336
modifiers,
13231337
module,
@@ -1566,6 +1580,8 @@ symbols! {
15661580
prelude_import,
15671581
preserves_flags,
15681582
prfchw_target_feature,
1583+
prid,
1584+
primitive,
15691585
proc_dash_macro: "proc-macro",
15701586
proc_macro,
15711587
proc_macro_attribute,
@@ -1822,7 +1838,9 @@ symbols! {
18221838
rustdoc_missing_doc_code_examples,
18231839
rustfmt,
18241840
rvalue_static_promotion,
1841+
rvector,
18251842
rwpi,
1843+
s32c1i,
18261844
s390x,
18271845
s390x_target_feature,
18281846
s390x_target_feature_vector,
@@ -2052,9 +2070,11 @@ symbols! {
20522070
test_unstable_lint,
20532071
thread,
20542072
thread_local,
2073+
threadptr,
20552074
three_way_compare,
20562075
thumb2,
20572076
thumb_mode: "thumb-mode",
2077+
time,
20582078
tmm_reg,
20592079
to_owned_method,
20602080
to_string,
@@ -2278,6 +2298,7 @@ symbols! {
22782298
while_let,
22792299
whole_dash_archive: "whole-archive",
22802300
width,
2301+
windowed,
22812302
windows,
22822303
windows_subsystem,
22832304
with_negative_coherence,
@@ -2303,9 +2324,11 @@ symbols! {
23032324
x87_target_feature,
23042325
xcoff,
23052326
xer,
2327+
xloop,
23062328
xmm_reg,
23072329
xop_target_feature,
23082330
xtensa,
2331+
xtensa_target_feature,
23092332
yeet_desugar_details,
23102333
yeet_expr,
23112334
yes,

0 commit comments

Comments
 (0)