Skip to content

Commit 6aa5d1c

Browse files
committed
asm! support for the Xtensa architecture (#68)
1 parent fec5f2a commit 6aa5d1c

File tree

6 files changed

+525
-0
lines changed

6 files changed

+525
-0
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
254254
}
255255
InlineAsmArch::SpirV => {}
256256
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {}
257+
InlineAsmArch::Xtensa => {}
257258
InlineAsmArch::Bpf => {}
258259
InlineAsmArch::Msp430 => {
259260
constraints.push("~{sr}".to_string());
@@ -680,6 +681,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
680681
| X86InlineAsmRegClass::tmm_reg,
681682
) => unreachable!("clobber-only"),
682683
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
684+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => "r",
685+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => "f",
686+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => "b",
683687
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
684688
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
685689
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => "r",
@@ -739,6 +743,7 @@ fn modifier_to_llvm(
739743
InlineAsmRegClass::Mips(_) => None,
740744
InlineAsmRegClass::Nvptx(_) => None,
741745
InlineAsmRegClass::PowerPC(_) => None,
746+
InlineAsmRegClass::Xtensa(_) => None,
742747
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg)
743748
| InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => None,
744749
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => {
@@ -855,6 +860,9 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
855860
unreachable!("clobber-only")
856861
}
857862
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
863+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
864+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
865+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => cx.type_i1(),
858866
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
859867
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(),
860868
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => cx.type_i8(),

compiler/rustc_codegen_ssa/src/target_features.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,35 @@ const WASM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
292292
// tidy-alphabetical-end
293293
];
294294

295+
const XTENSA_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
296+
("fp", Some(sym::xtensa_target_feature)),
297+
("windowed", Some(sym::xtensa_target_feature)),
298+
("bool", Some(sym::xtensa_target_feature)),
299+
("loop", Some(sym::xtensa_target_feature)),
300+
("sext", Some(sym::xtensa_target_feature)),
301+
("nsa", Some(sym::xtensa_target_feature)),
302+
("mul32", Some(sym::xtensa_target_feature)),
303+
("mul32high", Some(sym::xtensa_target_feature)),
304+
("div32", Some(sym::xtensa_target_feature)),
305+
("mac16", Some(sym::xtensa_target_feature)),
306+
("dfpaccel", Some(sym::xtensa_target_feature)),
307+
("s32c1i", Some(sym::xtensa_target_feature)),
308+
("threadptr", Some(sym::xtensa_target_feature)),
309+
("extendedl32r", Some(sym::xtensa_target_feature)),
310+
("atomctl", Some(sym::xtensa_target_feature)),
311+
("memctl", Some(sym::xtensa_target_feature)),
312+
("debug", Some(sym::xtensa_target_feature)),
313+
("exception", Some(sym::xtensa_target_feature)),
314+
("highpriinterrupts", Some(sym::xtensa_target_feature)),
315+
("coprocessor", Some(sym::xtensa_target_feature)),
316+
("interrupt", Some(sym::xtensa_target_feature)),
317+
("rvector", Some(sym::xtensa_target_feature)),
318+
("timerint", Some(sym::xtensa_target_feature)),
319+
("prid", Some(sym::xtensa_target_feature)),
320+
("regprotect", Some(sym::xtensa_target_feature)),
321+
("miscsr", Some(sym::xtensa_target_feature)),
322+
];
323+
295324
const BPF_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[("alu32", Some(sym::bpf_target_feature))];
296325

297326
/// When rustdoc is running, provide a list of all known features so that all their respective
@@ -308,6 +337,7 @@ pub fn all_known_features() -> impl Iterator<Item = (&'static str, Option<Symbol
308337
.chain(MIPS_ALLOWED_FEATURES.iter())
309338
.chain(RISCV_ALLOWED_FEATURES.iter())
310339
.chain(WASM_ALLOWED_FEATURES.iter())
340+
.chain(XTENSA_ALLOWED_FEATURES.iter())
311341
.chain(BPF_ALLOWED_FEATURES.iter())
312342
.cloned()
313343
}
@@ -322,6 +352,7 @@ pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Opt
322352
"powerpc" | "powerpc64" => POWERPC_ALLOWED_FEATURES,
323353
"riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES,
324354
"wasm32" | "wasm64" => WASM_ALLOWED_FEATURES,
355+
"xtensa" => XTENSA_ALLOWED_FEATURES,
325356
"bpf" => BPF_ALLOWED_FEATURES,
326357
_ => &[],
327358
}

compiler/rustc_span/src/symbol.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ symbols! {
399399
async_await,
400400
async_closure,
401401
async_fn_in_trait,
402+
atomctl,
402403
atomic,
403404
atomic_mod,
404405
atomics,
@@ -440,6 +441,7 @@ symbols! {
440441
braced_empty_structs,
441442
branch,
442443
breakpoint,
444+
breg,
443445
bridge,
444446
bswap,
445447
builtin_syntax,
@@ -549,7 +551,10 @@ symbols! {
549551
const_try,
550552
constant,
551553
constructor,
554+
contents,
552555
context,
556+
convert,
557+
coprocessor,
553558
copy,
554559
copy_closures,
555560
copy_nonoverlapping,
@@ -619,6 +624,7 @@ symbols! {
619624
derive_default_enum,
620625
destruct,
621626
destructuring_assignment,
627+
dfpaccel,
622628
diagnostic,
623629
direct,
624630
discriminant_kind,
@@ -675,6 +681,7 @@ symbols! {
675681
ermsb_target_feature,
676682
exact_div,
677683
except,
684+
exception,
678685
exchange_malloc,
679686
exclusive_range_pattern,
680687
exhaustive_integer_patterns,
@@ -691,6 +698,7 @@ symbols! {
691698
expr,
692699
extended_key_value_attributes,
693700
extended_varargs_abi_support,
701+
extendedl32r,
694702
extern_absolute_paths,
695703
extern_crate_item_prelude,
696704
extern_crate_self,
@@ -749,6 +757,7 @@ symbols! {
749757
format_macro,
750758
format_placeholder,
751759
format_unsafe_arg,
760+
fp,
752761
freeze,
753762
freg,
754763
frem_fast,
@@ -790,6 +799,7 @@ symbols! {
790799
hash,
791800
hexagon_target_feature,
792801
hidden,
802+
highpriinterrupts,
793803
homogeneous_aggregate,
794804
html_favicon_url,
795805
html_logo_url,
@@ -841,6 +851,8 @@ symbols! {
841851
instruction_set,
842852
integer_: "integer",
843853
integral,
854+
intel,
855+
interrupt,
844856
into_future,
845857
into_iter,
846858
intra_doc_pointers,
@@ -903,6 +915,7 @@ symbols! {
903915
logf64,
904916
loop_break_value,
905917
lt,
918+
mac16,
906919
macro_at_most_once_rep,
907920
macro_attributes_in_derive_output,
908921
macro_escape,
@@ -941,6 +954,7 @@ symbols! {
941954
mem_variant_count,
942955
mem_zeroed,
943956
member_constraints,
957+
memctl,
944958
memory,
945959
memtag,
946960
message,
@@ -958,6 +972,7 @@ symbols! {
958972
mips_target_feature,
959973
miri,
960974
misc,
975+
miscsr,
961976
mmx_reg,
962977
modifiers,
963978
module,
@@ -1129,6 +1144,7 @@ symbols! {
11291144
prelude,
11301145
prelude_import,
11311146
preserves_flags,
1147+
prid,
11321148
primitive,
11331149
print_macro,
11341150
println_macro,
@@ -1330,7 +1346,9 @@ symbols! {
13301346
rustdoc_missing_doc_code_examples,
13311347
rustfmt,
13321348
rvalue_static_promotion,
1349+
rvector,
13331350
s,
1351+
s32c1i,
13341352
safety,
13351353
sanitize,
13361354
sanitizer_cfi_generalize_pointers,
@@ -1504,8 +1522,10 @@ symbols! {
15041522
thread,
15051523
thread_local,
15061524
thread_local_macro,
1525+
threadptr,
15071526
thumb2,
15081527
thumb_mode: "thumb-mode",
1528+
timerint,
15091529
tmm_reg,
15101530
to_string,
15111531
to_vec,
@@ -1641,6 +1661,7 @@ symbols! {
16411661
wasm_target_feature,
16421662
while_let,
16431663
width,
1664+
windowed,
16441665
windows,
16451666
windows_subsystem,
16461667
with_negative_coherence,
@@ -1655,7 +1676,9 @@ symbols! {
16551676
writeln_macro,
16561677
x87_reg,
16571678
xer,
1679+
xloop,
16581680
xmm_reg,
1681+
xtensa_target_feature,
16591682
yeet_desugar_details,
16601683
yeet_expr,
16611684
ymm_reg,

0 commit comments

Comments
 (0)