Skip to content

Commit ef1517b

Browse files
committed
asm! support for the Xtensa architecture (#68)
1 parent 16eda93 commit ef1517b

File tree

6 files changed

+524
-0
lines changed

6 files changed

+524
-0
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

+8
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

+31
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,35 @@ const WASM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
303303
// tidy-alphabetical-end
304304
];
305305

306+
const XTENSA_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
307+
("fp", Some(sym::xtensa_target_feature)),
308+
("windowed", Some(sym::xtensa_target_feature)),
309+
("bool", Some(sym::xtensa_target_feature)),
310+
("loop", Some(sym::xtensa_target_feature)),
311+
("sext", Some(sym::xtensa_target_feature)),
312+
("nsa", Some(sym::xtensa_target_feature)),
313+
("mul32", Some(sym::xtensa_target_feature)),
314+
("mul32high", Some(sym::xtensa_target_feature)),
315+
("div32", Some(sym::xtensa_target_feature)),
316+
("mac16", Some(sym::xtensa_target_feature)),
317+
("dfpaccel", Some(sym::xtensa_target_feature)),
318+
("s32c1i", Some(sym::xtensa_target_feature)),
319+
("threadptr", Some(sym::xtensa_target_feature)),
320+
("extendedl32r", Some(sym::xtensa_target_feature)),
321+
("atomctl", Some(sym::xtensa_target_feature)),
322+
("memctl", Some(sym::xtensa_target_feature)),
323+
("debug", Some(sym::xtensa_target_feature)),
324+
("exception", Some(sym::xtensa_target_feature)),
325+
("highpriinterrupts", Some(sym::xtensa_target_feature)),
326+
("coprocessor", Some(sym::xtensa_target_feature)),
327+
("interrupt", Some(sym::xtensa_target_feature)),
328+
("rvector", Some(sym::xtensa_target_feature)),
329+
("timerint", Some(sym::xtensa_target_feature)),
330+
("prid", Some(sym::xtensa_target_feature)),
331+
("regprotect", Some(sym::xtensa_target_feature)),
332+
("miscsr", Some(sym::xtensa_target_feature)),
333+
];
334+
306335
const BPF_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[("alu32", Some(sym::bpf_target_feature))];
307336

308337
const CSKY_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
@@ -378,6 +407,7 @@ pub fn all_known_features() -> impl Iterator<Item = (&'static str, Option<Symbol
378407
.chain(MIPS_ALLOWED_FEATURES.iter())
379408
.chain(RISCV_ALLOWED_FEATURES.iter())
380409
.chain(WASM_ALLOWED_FEATURES.iter())
410+
.chain(XTENSA_ALLOWED_FEATURES.iter())
381411
.chain(BPF_ALLOWED_FEATURES.iter())
382412
.chain(CSKY_ALLOWED_FEATURES)
383413
.chain(LOONGARCH_ALLOWED_FEATURES)
@@ -394,6 +424,7 @@ pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Opt
394424
"powerpc" | "powerpc64" => POWERPC_ALLOWED_FEATURES,
395425
"riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES,
396426
"wasm32" | "wasm64" => WASM_ALLOWED_FEATURES,
427+
"xtensa" => XTENSA_ALLOWED_FEATURES,
397428
"bpf" => BPF_ALLOWED_FEATURES,
398429
"csky" => CSKY_ALLOWED_FEATURES,
399430
"loongarch64" => LOONGARCH_ALLOWED_FEATURES,

compiler/rustc_span/src/symbol.rs

+22
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ symbols! {
432432
async_closure,
433433
async_fn_in_trait,
434434
async_fn_track_caller,
435+
atomctl,
435436
atomic,
436437
atomic_mod,
437438
atomics,
@@ -472,6 +473,7 @@ symbols! {
472473
braced_empty_structs,
473474
branch,
474475
breakpoint,
476+
breg,
475477
bridge,
476478
bswap,
477479
builtin_syntax,
@@ -585,8 +587,10 @@ symbols! {
585587
const_try,
586588
constant,
587589
constructor,
590+
contents,
588591
context,
589592
convert_identity,
593+
coprocessor,
590594
copy,
591595
copy_closures,
592596
copy_nonoverlapping,
@@ -666,6 +670,7 @@ symbols! {
666670
derive_default_enum,
667671
destruct,
668672
destructuring_assignment,
673+
dfpaccel,
669674
diagnostic,
670675
diagnostic_namespace,
671676
direct,
@@ -726,6 +731,7 @@ symbols! {
726731
ermsb_target_feature,
727732
exact_div,
728733
except,
734+
exception,
729735
exchange_malloc,
730736
exclusive_range_pattern,
731737
exhaustive_integer_patterns,
@@ -743,6 +749,7 @@ symbols! {
743749
expr,
744750
extended_key_value_attributes,
745751
extended_varargs_abi_support,
752+
extendedl32r,
746753
extern_absolute_paths,
747754
extern_crate_item_prelude,
748755
extern_crate_self,
@@ -803,6 +810,7 @@ symbols! {
803810
format_macro,
804811
format_placeholder,
805812
format_unsafe_arg,
813+
fp,
806814
freeze,
807815
freg,
808816
frem_fast,
@@ -846,6 +854,7 @@ symbols! {
846854
hash,
847855
hexagon_target_feature,
848856
hidden,
857+
highpriinterrupts,
849858
homogeneous_aggregate,
850859
host,
851860
html_favicon_url,
@@ -899,6 +908,8 @@ symbols! {
899908
instruction_set,
900909
integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below
901910
integral,
911+
intel,
912+
interrupt,
902913
into_future,
903914
into_iter,
904915
intra_doc_pointers,
@@ -969,6 +980,7 @@ symbols! {
969980
loongarch_target_feature,
970981
loop_break_value,
971982
lt,
983+
mac16,
972984
macro_at_most_once_rep,
973985
macro_attributes_in_derive_output,
974986
macro_escape,
@@ -1008,6 +1020,7 @@ symbols! {
10081020
mem_variant_count,
10091021
mem_zeroed,
10101022
member_constraints,
1023+
memctl,
10111024
memory,
10121025
memtag,
10131026
message,
@@ -1025,6 +1038,7 @@ symbols! {
10251038
mips_target_feature,
10261039
miri,
10271040
misc,
1041+
miscsr,
10281042
mmx_reg,
10291043
modifiers,
10301044
module,
@@ -1201,6 +1215,7 @@ symbols! {
12011215
prelude,
12021216
prelude_import,
12031217
preserves_flags,
1218+
prid,
12041219
primitive,
12051220
print_macro,
12061221
println_macro,
@@ -1437,8 +1452,10 @@ symbols! {
14371452
rustdoc_missing_doc_code_examples,
14381453
rustfmt,
14391454
rvalue_static_promotion,
1455+
rvector,
14401456
rwpi,
14411457
s,
1458+
s32c1i,
14421459
safety,
14431460
sanitize,
14441461
sanitizer_cfi_generalize_pointers,
@@ -1624,8 +1641,10 @@ symbols! {
16241641
thread,
16251642
thread_local,
16261643
thread_local_macro,
1644+
threadptr,
16271645
thumb2,
16281646
thumb_mode: "thumb-mode",
1647+
timerint,
16291648
tmm_reg,
16301649
to_owned_method,
16311650
to_string,
@@ -1767,6 +1786,7 @@ symbols! {
17671786
wasm_target_feature,
17681787
while_let,
17691788
width,
1789+
windowed,
17701790
windows,
17711791
windows_subsystem,
17721792
with_negative_coherence,
@@ -1784,7 +1804,9 @@ symbols! {
17841804
writeln_macro,
17851805
x87_reg,
17861806
xer,
1807+
xloop,
17871808
xmm_reg,
1809+
xtensa_target_feature,
17881810
yeet_desugar_details,
17891811
yeet_expr,
17901812
yield_expr,

0 commit comments

Comments
 (0)