Skip to content

Commit 3afa815

Browse files
committed
asm! support for the Xtensa architecture (rust-lang#68)
1 parent 7ac3cb2 commit 3afa815

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
@@ -255,6 +255,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
255255
}
256256
InlineAsmArch::SpirV => {}
257257
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {}
258+
InlineAsmArch::Xtensa => {}
258259
InlineAsmArch::Bpf => {}
259260
InlineAsmArch::Msp430 => {
260261
constraints.push("~{sr}".to_string());
@@ -682,6 +683,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
682683
| X86InlineAsmRegClass::tmm_reg,
683684
) => unreachable!("clobber-only"),
684685
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
686+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => "r",
687+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => "f",
688+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => "b",
685689
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
686690
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
687691
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => "r",
@@ -743,6 +747,7 @@ fn modifier_to_llvm(
743747
InlineAsmRegClass::Mips(_) => None,
744748
InlineAsmRegClass::Nvptx(_) => None,
745749
InlineAsmRegClass::PowerPC(_) => None,
750+
InlineAsmRegClass::Xtensa(_) => None,
746751
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg)
747752
| InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => None,
748753
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => {
@@ -860,6 +865,9 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
860865
unreachable!("clobber-only")
861866
}
862867
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
868+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
869+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
870+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => cx.type_i1(),
863871
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
864872
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(),
865873
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
@@ -294,6 +294,35 @@ const WASM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
294294
// tidy-alphabetical-end
295295
];
296296

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

299328
const CSKY_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
@@ -356,6 +385,7 @@ pub fn all_known_features() -> impl Iterator<Item = (&'static str, Option<Symbol
356385
.chain(MIPS_ALLOWED_FEATURES.iter())
357386
.chain(RISCV_ALLOWED_FEATURES.iter())
358387
.chain(WASM_ALLOWED_FEATURES.iter())
388+
.chain(XTENSA_ALLOWED_FEATURES.iter())
359389
.chain(BPF_ALLOWED_FEATURES.iter())
360390
.chain(CSKY_ALLOWED_FEATURES)
361391
.cloned()
@@ -371,6 +401,7 @@ pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Opt
371401
"powerpc" | "powerpc64" => POWERPC_ALLOWED_FEATURES,
372402
"riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES,
373403
"wasm32" | "wasm64" => WASM_ALLOWED_FEATURES,
404+
"xtensa" => XTENSA_ALLOWED_FEATURES,
374405
"bpf" => BPF_ALLOWED_FEATURES,
375406
"csky" => CSKY_ALLOWED_FEATURES,
376407
_ => &[],

compiler/rustc_span/src/symbol.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ symbols! {
402402
async_closure,
403403
async_fn_in_trait,
404404
async_fn_track_caller,
405+
atomctl,
405406
atomic,
406407
atomic_mod,
407408
atomics,
@@ -442,6 +443,7 @@ symbols! {
442443
braced_empty_structs,
443444
branch,
444445
breakpoint,
446+
breg,
445447
bridge,
446448
bswap,
447449
builtin_syntax,
@@ -555,7 +557,10 @@ symbols! {
555557
const_try,
556558
constant,
557559
constructor,
560+
contents,
558561
context,
562+
convert,
563+
coprocessor,
559564
copy,
560565
copy_closures,
561566
copy_nonoverlapping,
@@ -626,6 +631,7 @@ symbols! {
626631
derive_default_enum,
627632
destruct,
628633
destructuring_assignment,
634+
dfpaccel,
629635
diagnostic,
630636
diagnostic_namespace,
631637
direct,
@@ -685,6 +691,7 @@ symbols! {
685691
ermsb_target_feature,
686692
exact_div,
687693
except,
694+
exception,
688695
exchange_malloc,
689696
exclusive_range_pattern,
690697
exhaustive_integer_patterns,
@@ -702,6 +709,7 @@ symbols! {
702709
expr,
703710
extended_key_value_attributes,
704711
extended_varargs_abi_support,
712+
extendedl32r,
705713
extern_absolute_paths,
706714
extern_crate_item_prelude,
707715
extern_crate_self,
@@ -762,6 +770,7 @@ symbols! {
762770
format_macro,
763771
format_placeholder,
764772
format_unsafe_arg,
773+
fp,
765774
freeze,
766775
freg,
767776
frem_fast,
@@ -803,6 +812,7 @@ symbols! {
803812
hash,
804813
hexagon_target_feature,
805814
hidden,
815+
highpriinterrupts,
806816
homogeneous_aggregate,
807817
host,
808818
html_favicon_url,
@@ -856,6 +866,8 @@ symbols! {
856866
instruction_set,
857867
integer_: "integer",
858868
integral,
869+
intel,
870+
interrupt,
859871
into_future,
860872
into_iter,
861873
intra_doc_pointers,
@@ -920,6 +932,7 @@ symbols! {
920932
logf64,
921933
loop_break_value,
922934
lt,
935+
mac16,
923936
macro_at_most_once_rep,
924937
macro_attributes_in_derive_output,
925938
macro_escape,
@@ -958,6 +971,7 @@ symbols! {
958971
mem_variant_count,
959972
mem_zeroed,
960973
member_constraints,
974+
memctl,
961975
memory,
962976
memtag,
963977
message,
@@ -975,6 +989,7 @@ symbols! {
975989
mips_target_feature,
976990
miri,
977991
misc,
992+
miscsr,
978993
mmx_reg,
979994
modifiers,
980995
module,
@@ -1148,6 +1163,7 @@ symbols! {
11481163
prelude,
11491164
prelude_import,
11501165
preserves_flags,
1166+
prid,
11511167
primitive,
11521168
print_macro,
11531169
println_macro,
@@ -1362,8 +1378,10 @@ symbols! {
13621378
rustdoc_missing_doc_code_examples,
13631379
rustfmt,
13641380
rvalue_static_promotion,
1381+
rvector,
13651382
rwpi,
13661383
s,
1384+
s32c1i,
13671385
safety,
13681386
sanitize,
13691387
sanitizer_cfi_generalize_pointers,
@@ -1545,8 +1563,10 @@ symbols! {
15451563
thread,
15461564
thread_local,
15471565
thread_local_macro,
1566+
threadptr,
15481567
thumb2,
15491568
thumb_mode: "thumb-mode",
1569+
timerint,
15501570
tmm_reg,
15511571
to_string,
15521572
to_vec,
@@ -1683,6 +1703,7 @@ symbols! {
16831703
wasm_target_feature,
16841704
while_let,
16851705
width,
1706+
windowed,
16861707
windows,
16871708
windows_subsystem,
16881709
with_negative_coherence,
@@ -1697,7 +1718,9 @@ symbols! {
16971718
writeln_macro,
16981719
x87_reg,
16991720
xer,
1721+
xloop,
17001722
xmm_reg,
1723+
xtensa_target_feature,
17011724
yeet_desugar_details,
17021725
yeet_expr,
17031726
ymm_reg,

0 commit comments

Comments
 (0)