Skip to content

Commit 2d73921

Browse files
committed
asm! support for the Xtensa architecture (#68)
1 parent f20b838 commit 2d73921

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
@@ -240,6 +240,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
240240
InlineAsmArch::S390x => {}
241241
InlineAsmArch::SpirV => {}
242242
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {}
243+
InlineAsmArch::Xtensa => {}
243244
InlineAsmArch::Bpf => {}
244245
InlineAsmArch::Msp430 => {
245246
constraints.push("~{sr}".to_string());
@@ -661,6 +662,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
661662
| X86InlineAsmRegClass::tmm_reg,
662663
) => unreachable!("clobber-only"),
663664
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
665+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => "r",
666+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => "f",
667+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => "b",
664668
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
665669
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
666670
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => "r",
@@ -716,6 +720,7 @@ fn modifier_to_llvm(
716720
InlineAsmRegClass::Mips(_) => None,
717721
InlineAsmRegClass::Nvptx(_) => None,
718722
InlineAsmRegClass::PowerPC(_) => None,
723+
InlineAsmRegClass::Xtensa(_) => None,
719724
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg)
720725
| InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => None,
721726
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => {
@@ -829,6 +834,9 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
829834
unreachable!("clobber-only")
830835
}
831836
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
837+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
838+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
839+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => cx.type_i1(),
832840
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
833841
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(),
834842
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
@@ -395,6 +395,7 @@ symbols! {
395395
async_await,
396396
async_closure,
397397
async_fn_in_trait,
398+
atomctl,
398399
atomic,
399400
atomic_mod,
400401
atomics,
@@ -435,6 +436,7 @@ symbols! {
435436
braced_empty_structs,
436437
branch,
437438
breakpoint,
439+
breg,
438440
bridge,
439441
bswap,
440442
c_str,
@@ -538,7 +540,10 @@ symbols! {
538540
const_try,
539541
constant,
540542
constructor,
543+
contents,
541544
context,
545+
convert,
546+
coprocessor,
542547
copy,
543548
copy_closures,
544549
copy_nonoverlapping,
@@ -608,6 +613,7 @@ symbols! {
608613
derive_default_enum,
609614
destruct,
610615
destructuring_assignment,
616+
dfpaccel,
611617
diagnostic,
612618
direct,
613619
discriminant_kind,
@@ -663,6 +669,7 @@ symbols! {
663669
ermsb_target_feature,
664670
exact_div,
665671
except,
672+
exception,
666673
exchange_malloc,
667674
exclusive_range_pattern,
668675
exhaustive_integer_patterns,
@@ -679,6 +686,7 @@ symbols! {
679686
expr,
680687
extended_key_value_attributes,
681688
extended_varargs_abi_support,
689+
extendedl32r,
682690
extern_absolute_paths,
683691
extern_crate_item_prelude,
684692
extern_crate_self,
@@ -735,6 +743,7 @@ symbols! {
735743
format_macro,
736744
format_placeholder,
737745
format_unsafe_arg,
746+
fp,
738747
freeze,
739748
freg,
740749
frem_fast,
@@ -776,6 +785,7 @@ symbols! {
776785
hash,
777786
hexagon_target_feature,
778787
hidden,
788+
highpriinterrupts,
779789
homogeneous_aggregate,
780790
html_favicon_url,
781791
html_logo_url,
@@ -827,6 +837,8 @@ symbols! {
827837
instruction_set,
828838
integer_: "integer",
829839
integral,
840+
intel,
841+
interrupt,
830842
into_future,
831843
into_iter,
832844
intra_doc_pointers,
@@ -889,6 +901,7 @@ symbols! {
889901
logf64,
890902
loop_break_value,
891903
lt,
904+
mac16,
892905
macro_at_most_once_rep,
893906
macro_attributes_in_derive_output,
894907
macro_escape,
@@ -927,6 +940,7 @@ symbols! {
927940
mem_variant_count,
928941
mem_zeroed,
929942
member_constraints,
943+
memctl,
930944
memory,
931945
memtag,
932946
message,
@@ -944,6 +958,7 @@ symbols! {
944958
mips_target_feature,
945959
miri,
946960
misc,
961+
miscsr,
947962
mmx_reg,
948963
modifiers,
949964
module,
@@ -1108,6 +1123,7 @@ symbols! {
11081123
prelude,
11091124
prelude_import,
11101125
preserves_flags,
1126+
prid,
11111127
primitive,
11121128
print_macro,
11131129
println_macro,
@@ -1301,7 +1317,9 @@ symbols! {
13011317
rustdoc_missing_doc_code_examples,
13021318
rustfmt,
13031319
rvalue_static_promotion,
1320+
rvector,
13041321
s,
1322+
s32c1i,
13051323
safety,
13061324
sanitize,
13071325
sanitizer_runtime,
@@ -1473,8 +1491,10 @@ symbols! {
14731491
thread,
14741492
thread_local,
14751493
thread_local_macro,
1494+
threadptr,
14761495
thumb2,
14771496
thumb_mode: "thumb-mode",
1497+
timerint,
14781498
tmm_reg,
14791499
to_string,
14801500
to_vec,
@@ -1607,6 +1627,7 @@ symbols! {
16071627
wasm_target_feature,
16081628
while_let,
16091629
width,
1630+
windowed,
16101631
windows,
16111632
windows_subsystem,
16121633
with_negative_coherence,
@@ -1620,7 +1641,9 @@ symbols! {
16201641
writeln_macro,
16211642
x87_reg,
16221643
xer,
1644+
xloop,
16231645
xmm_reg,
1646+
xtensa_target_feature,
16241647
yeet_desugar_details,
16251648
yeet_expr,
16261649
ymm_reg,

0 commit comments

Comments
 (0)