Skip to content

Commit 34f3222

Browse files
committed
asm! support for the Xtensa architecture (#68)
1 parent 86d3373 commit 34f3222

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
@@ -295,6 +295,35 @@ const WASM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
295295
// tidy-alphabetical-end
296296
];
297297

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

300329
/// When rustdoc is running, provide a list of all known features so that all their respective
@@ -311,6 +340,7 @@ pub fn all_known_features() -> impl Iterator<Item = (&'static str, Option<Symbol
311340
.chain(MIPS_ALLOWED_FEATURES.iter())
312341
.chain(RISCV_ALLOWED_FEATURES.iter())
313342
.chain(WASM_ALLOWED_FEATURES.iter())
343+
.chain(XTENSA_ALLOWED_FEATURES.iter())
314344
.chain(BPF_ALLOWED_FEATURES.iter())
315345
.cloned()
316346
}
@@ -325,6 +355,7 @@ pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Opt
325355
"powerpc" | "powerpc64" => POWERPC_ALLOWED_FEATURES,
326356
"riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES,
327357
"wasm32" | "wasm64" => WASM_ALLOWED_FEATURES,
358+
"xtensa" => XTENSA_ALLOWED_FEATURES,
328359
"bpf" => BPF_ALLOWED_FEATURES,
329360
_ => &[],
330361
}

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,
@@ -439,6 +440,7 @@ symbols! {
439440
braced_empty_structs,
440441
branch,
441442
breakpoint,
443+
breg,
442444
bridge,
443445
bswap,
444446
builtin_syntax,
@@ -548,7 +550,10 @@ symbols! {
548550
const_try,
549551
constant,
550552
constructor,
553+
contents,
551554
context,
555+
convert,
556+
coprocessor,
552557
copy,
553558
copy_closures,
554559
copy_nonoverlapping,
@@ -618,6 +623,7 @@ symbols! {
618623
derive_default_enum,
619624
destruct,
620625
destructuring_assignment,
626+
dfpaccel,
621627
diagnostic,
622628
direct,
623629
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,
@@ -692,6 +699,7 @@ symbols! {
692699
expr,
693700
extended_key_value_attributes,
694701
extended_varargs_abi_support,
702+
extendedl32r,
695703
extern_absolute_paths,
696704
extern_crate_item_prelude,
697705
extern_crate_self,
@@ -752,6 +760,7 @@ symbols! {
752760
format_macro,
753761
format_placeholder,
754762
format_unsafe_arg,
763+
fp,
755764
freeze,
756765
freg,
757766
frem_fast,
@@ -792,6 +801,7 @@ symbols! {
792801
hash,
793802
hexagon_target_feature,
794803
hidden,
804+
highpriinterrupts,
795805
homogeneous_aggregate,
796806
host,
797807
html_favicon_url,
@@ -845,6 +855,8 @@ symbols! {
845855
instruction_set,
846856
integer_: "integer",
847857
integral,
858+
intel,
859+
interrupt,
848860
into_future,
849861
into_iter,
850862
intra_doc_pointers,
@@ -908,6 +920,7 @@ symbols! {
908920
logf64,
909921
loop_break_value,
910922
lt,
923+
mac16,
911924
macro_at_most_once_rep,
912925
macro_attributes_in_derive_output,
913926
macro_escape,
@@ -946,6 +959,7 @@ symbols! {
946959
mem_variant_count,
947960
mem_zeroed,
948961
member_constraints,
962+
memctl,
949963
memory,
950964
memtag,
951965
message,
@@ -963,6 +977,7 @@ symbols! {
963977
mips_target_feature,
964978
miri,
965979
misc,
980+
miscsr,
966981
mmx_reg,
967982
modifiers,
968983
module,
@@ -1134,6 +1149,7 @@ symbols! {
11341149
prelude,
11351150
prelude_import,
11361151
preserves_flags,
1152+
prid,
11371153
primitive,
11381154
print_macro,
11391155
println_macro,
@@ -1339,7 +1355,9 @@ symbols! {
13391355
rustdoc_missing_doc_code_examples,
13401356
rustfmt,
13411357
rvalue_static_promotion,
1358+
rvector,
13421359
s,
1360+
s32c1i,
13431361
safety,
13441362
sanitize,
13451363
sanitizer_cfi_generalize_pointers,
@@ -1517,8 +1535,10 @@ symbols! {
15171535
thread,
15181536
thread_local,
15191537
thread_local_macro,
1538+
threadptr,
15201539
thumb2,
15211540
thumb_mode: "thumb-mode",
1541+
timerint,
15221542
tmm_reg,
15231543
to_string,
15241544
to_vec,
@@ -1655,6 +1675,7 @@ symbols! {
16551675
wasm_target_feature,
16561676
while_let,
16571677
width,
1678+
windowed,
16581679
windows,
16591680
windows_subsystem,
16601681
with_negative_coherence,
@@ -1669,7 +1690,9 @@ symbols! {
16691690
writeln_macro,
16701691
x87_reg,
16711692
xer,
1693+
xloop,
16721694
xmm_reg,
1695+
xtensa_target_feature,
16731696
yeet_desugar_details,
16741697
yeet_expr,
16751698
ymm_reg,

0 commit comments

Comments
 (0)