Skip to content

Commit fee3626

Browse files
committed
asm! support for the Xtensa architecture (#68)
1 parent af2f291 commit fee3626

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
@@ -407,6 +407,7 @@ symbols! {
407407
async_closure,
408408
async_fn_in_trait,
409409
async_fn_track_caller,
410+
atomctl,
410411
atomic,
411412
atomic_mod,
412413
atomics,
@@ -447,6 +448,7 @@ symbols! {
447448
braced_empty_structs,
448449
branch,
449450
breakpoint,
451+
breg,
450452
bridge,
451453
bswap,
452454
builtin_syntax,
@@ -560,7 +562,10 @@ symbols! {
560562
const_try,
561563
constant,
562564
constructor,
565+
contents,
563566
context,
567+
convert,
568+
coprocessor,
564569
copy,
565570
copy_closures,
566571
copy_nonoverlapping,
@@ -634,6 +639,7 @@ symbols! {
634639
derive_default_enum,
635640
destruct,
636641
destructuring_assignment,
642+
dfpaccel,
637643
diagnostic,
638644
diagnostic_namespace,
639645
direct,
@@ -693,6 +699,7 @@ symbols! {
693699
ermsb_target_feature,
694700
exact_div,
695701
except,
702+
exception,
696703
exchange_malloc,
697704
exclusive_range_pattern,
698705
exhaustive_integer_patterns,
@@ -710,6 +717,7 @@ symbols! {
710717
expr,
711718
extended_key_value_attributes,
712719
extended_varargs_abi_support,
720+
extendedl32r,
713721
extern_absolute_paths,
714722
extern_crate_item_prelude,
715723
extern_crate_self,
@@ -770,6 +778,7 @@ symbols! {
770778
format_macro,
771779
format_placeholder,
772780
format_unsafe_arg,
781+
fp,
773782
freeze,
774783
freg,
775784
frem_fast,
@@ -811,6 +820,7 @@ symbols! {
811820
hash,
812821
hexagon_target_feature,
813822
hidden,
823+
highpriinterrupts,
814824
homogeneous_aggregate,
815825
host,
816826
html_favicon_url,
@@ -864,6 +874,8 @@ symbols! {
864874
instruction_set,
865875
integer_: "integer",
866876
integral,
877+
intel,
878+
interrupt,
867879
into_future,
868880
into_iter,
869881
intra_doc_pointers,
@@ -928,6 +940,7 @@ symbols! {
928940
logf64,
929941
loop_break_value,
930942
lt,
943+
mac16,
931944
macro_at_most_once_rep,
932945
macro_attributes_in_derive_output,
933946
macro_escape,
@@ -966,6 +979,7 @@ symbols! {
966979
mem_variant_count,
967980
mem_zeroed,
968981
member_constraints,
982+
memctl,
969983
memory,
970984
memtag,
971985
message,
@@ -983,6 +997,7 @@ symbols! {
983997
mips_target_feature,
984998
miri,
985999
misc,
1000+
miscsr,
9861001
mmx_reg,
9871002
modifiers,
9881003
module,
@@ -1158,6 +1173,7 @@ symbols! {
11581173
prelude,
11591174
prelude_import,
11601175
preserves_flags,
1176+
prid,
11611177
primitive,
11621178
print_macro,
11631179
println_macro,
@@ -1377,8 +1393,10 @@ symbols! {
13771393
rustdoc_missing_doc_code_examples,
13781394
rustfmt,
13791395
rvalue_static_promotion,
1396+
rvector,
13801397
rwpi,
13811398
s,
1399+
s32c1i,
13821400
safety,
13831401
sanitize,
13841402
sanitizer_cfi_generalize_pointers,
@@ -1562,8 +1580,10 @@ symbols! {
15621580
thread,
15631581
thread_local,
15641582
thread_local_macro,
1583+
threadptr,
15651584
thumb2,
15661585
thumb_mode: "thumb-mode",
1586+
timerint,
15671587
tmm_reg,
15681588
to_string,
15691589
to_vec,
@@ -1702,6 +1722,7 @@ symbols! {
17021722
wasm_target_feature,
17031723
while_let,
17041724
width,
1725+
windowed,
17051726
windows,
17061727
windows_subsystem,
17071728
with_negative_coherence,
@@ -1719,7 +1740,9 @@ symbols! {
17191740
writeln_macro,
17201741
x87_reg,
17211742
xer,
1743+
xloop,
17221744
xmm_reg,
1745+
xtensa_target_feature,
17231746
yeet_desugar_details,
17241747
yeet_expr,
17251748
ymm_reg,

0 commit comments

Comments
 (0)