Skip to content

Commit 4478eff

Browse files
committed
asm! support for the Xtensa architecture (#68)
1 parent fb21d2d commit 4478eff

File tree

6 files changed

+525
-0
lines changed

6 files changed

+525
-0
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

+8
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());
@@ -664,6 +665,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
664665
| X86InlineAsmRegClass::tmm_reg,
665666
) => unreachable!("clobber-only"),
666667
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
668+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => "r",
669+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => "f",
670+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => "b",
667671
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
668672
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
669673
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => "r",
@@ -722,6 +726,7 @@ fn modifier_to_llvm(
722726
InlineAsmRegClass::Mips(_) => None,
723727
InlineAsmRegClass::Nvptx(_) => None,
724728
InlineAsmRegClass::PowerPC(_) => None,
729+
InlineAsmRegClass::Xtensa(_) => None,
725730
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg)
726731
| InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => None,
727732
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => {
@@ -836,6 +841,9 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
836841
unreachable!("clobber-only")
837842
}
838843
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
844+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
845+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
846+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => cx.type_i1(),
839847
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
840848
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(),
841849
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => cx.type_i8(),

compiler/rustc_codegen_ssa/src/target_features.rs

+31
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,35 @@ const WASM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
293293
// tidy-alphabetical-end
294294
];
295295

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

298327
/// When rustdoc is running, provide a list of all known features so that all their respective
@@ -309,6 +338,7 @@ pub fn all_known_features() -> impl Iterator<Item = (&'static str, Option<Symbol
309338
.chain(MIPS_ALLOWED_FEATURES.iter())
310339
.chain(RISCV_ALLOWED_FEATURES.iter())
311340
.chain(WASM_ALLOWED_FEATURES.iter())
341+
.chain(XTENSA_ALLOWED_FEATURES.iter())
312342
.chain(BPF_ALLOWED_FEATURES.iter())
313343
.cloned()
314344
}
@@ -323,6 +353,7 @@ pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Opt
323353
"powerpc" | "powerpc64" => POWERPC_ALLOWED_FEATURES,
324354
"riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES,
325355
"wasm32" | "wasm64" => WASM_ALLOWED_FEATURES,
356+
"xtensa" => XTENSA_ALLOWED_FEATURES,
326357
"bpf" => BPF_ALLOWED_FEATURES,
327358
_ => &[],
328359
}

compiler/rustc_span/src/symbol.rs

+23
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ symbols! {
396396
async_await,
397397
async_closure,
398398
async_fn_in_trait,
399+
atomctl,
399400
atomic,
400401
atomic_mod,
401402
atomics,
@@ -437,6 +438,7 @@ symbols! {
437438
braced_empty_structs,
438439
branch,
439440
breakpoint,
441+
breg,
440442
bridge,
441443
bswap,
442444
c_str,
@@ -540,7 +542,10 @@ symbols! {
540542
const_try,
541543
constant,
542544
constructor,
545+
contents,
543546
context,
547+
convert,
548+
coprocessor,
544549
copy,
545550
copy_closures,
546551
copy_nonoverlapping,
@@ -610,6 +615,7 @@ symbols! {
610615
derive_default_enum,
611616
destruct,
612617
destructuring_assignment,
618+
dfpaccel,
613619
diagnostic,
614620
direct,
615621
discriminant_kind,
@@ -665,6 +671,7 @@ symbols! {
665671
ermsb_target_feature,
666672
exact_div,
667673
except,
674+
exception,
668675
exchange_malloc,
669676
exclusive_range_pattern,
670677
exhaustive_integer_patterns,
@@ -681,6 +688,7 @@ symbols! {
681688
expr,
682689
extended_key_value_attributes,
683690
extended_varargs_abi_support,
691+
extendedl32r,
684692
extern_absolute_paths,
685693
extern_crate_item_prelude,
686694
extern_crate_self,
@@ -739,6 +747,7 @@ symbols! {
739747
format_macro,
740748
format_placeholder,
741749
format_unsafe_arg,
750+
fp,
742751
freeze,
743752
freg,
744753
frem_fast,
@@ -780,6 +789,7 @@ symbols! {
780789
hash,
781790
hexagon_target_feature,
782791
hidden,
792+
highpriinterrupts,
783793
homogeneous_aggregate,
784794
html_favicon_url,
785795
html_logo_url,
@@ -831,6 +841,8 @@ symbols! {
831841
instruction_set,
832842
integer_: "integer",
833843
integral,
844+
intel,
845+
interrupt,
834846
into_future,
835847
into_iter,
836848
intra_doc_pointers,
@@ -893,6 +905,7 @@ symbols! {
893905
logf64,
894906
loop_break_value,
895907
lt,
908+
mac16,
896909
macro_at_most_once_rep,
897910
macro_attributes_in_derive_output,
898911
macro_escape,
@@ -931,6 +944,7 @@ symbols! {
931944
mem_variant_count,
932945
mem_zeroed,
933946
member_constraints,
947+
memctl,
934948
memory,
935949
memtag,
936950
message,
@@ -948,6 +962,7 @@ symbols! {
948962
mips_target_feature,
949963
miri,
950964
misc,
965+
miscsr,
951966
mmx_reg,
952967
modifiers,
953968
module,
@@ -1115,6 +1130,7 @@ symbols! {
11151130
prelude,
11161131
prelude_import,
11171132
preserves_flags,
1133+
prid,
11181134
primitive,
11191135
print_macro,
11201136
println_macro,
@@ -1315,7 +1331,9 @@ symbols! {
13151331
rustdoc_missing_doc_code_examples,
13161332
rustfmt,
13171333
rvalue_static_promotion,
1334+
rvector,
13181335
s,
1336+
s32c1i,
13191337
safety,
13201338
sanitize,
13211339
sanitizer_runtime,
@@ -1487,8 +1505,10 @@ symbols! {
14871505
thread,
14881506
thread_local,
14891507
thread_local_macro,
1508+
threadptr,
14901509
thumb2,
14911510
thumb_mode: "thumb-mode",
1511+
timerint,
14921512
tmm_reg,
14931513
to_string,
14941514
to_vec,
@@ -1622,6 +1642,7 @@ symbols! {
16221642
wasm_target_feature,
16231643
while_let,
16241644
width,
1645+
windowed,
16251646
windows,
16261647
windows_subsystem,
16271648
with_negative_coherence,
@@ -1635,7 +1656,9 @@ symbols! {
16351656
writeln_macro,
16361657
x87_reg,
16371658
xer,
1659+
xloop,
16381660
xmm_reg,
1661+
xtensa_target_feature,
16391662
yeet_desugar_details,
16401663
yeet_expr,
16411664
ymm_reg,

0 commit comments

Comments
 (0)