Skip to content

Commit b4d8153

Browse files
committed
asm! support for the Xtensa architecture (#68)
1 parent 75c254c commit b4d8153

File tree

6 files changed

+521
-0
lines changed

6 files changed

+521
-0
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

+8
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
233233
InlineAsmArch::S390x => {}
234234
InlineAsmArch::SpirV => {}
235235
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {}
236+
InlineAsmArch::Xtensa => {}
236237
InlineAsmArch::Bpf => {}
237238
InlineAsmArch::Msp430 => {
238239
constraints.push("~{sr}".to_string());
@@ -608,6 +609,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
608609
| X86InlineAsmRegClass::tmm_reg,
609610
) => unreachable!("clobber-only"),
610611
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
612+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => "r",
613+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => "f",
614+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => "b",
611615
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
612616
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
613617
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => "r",
@@ -661,6 +665,7 @@ fn modifier_to_llvm(
661665
InlineAsmRegClass::Mips(_) => None,
662666
InlineAsmRegClass::Nvptx(_) => None,
663667
InlineAsmRegClass::PowerPC(_) => None,
668+
InlineAsmRegClass::Xtensa(_) => None,
664669
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg)
665670
| InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => None,
666671
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => {
@@ -774,6 +779,9 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
774779
unreachable!("clobber-only")
775780
}
776781
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(),
782+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::reg) => cx.type_i32(),
783+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::freg) => cx.type_f32(),
784+
InlineAsmRegClass::Xtensa(XtensaInlineAsmRegClass::breg) => cx.type_i1(),
777785
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(),
778786
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(),
779787
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => cx.type_i8(),

compiler/rustc_codegen_ssa/src/target_features.rs

+31
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,35 @@ const WASM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
251251
("reference-types", Some(sym::wasm_target_feature)),
252252
];
253253

254+
const XTENSA_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
255+
("fp", Some(sym::xtensa_target_feature)),
256+
("windowed", Some(sym::xtensa_target_feature)),
257+
("bool", Some(sym::xtensa_target_feature)),
258+
("loop", Some(sym::xtensa_target_feature)),
259+
("sext", Some(sym::xtensa_target_feature)),
260+
("nsa", Some(sym::xtensa_target_feature)),
261+
("mul32", Some(sym::xtensa_target_feature)),
262+
("mul32high", Some(sym::xtensa_target_feature)),
263+
("div32", Some(sym::xtensa_target_feature)),
264+
("mac16", Some(sym::xtensa_target_feature)),
265+
("dfpaccel", Some(sym::xtensa_target_feature)),
266+
("s32c1i", Some(sym::xtensa_target_feature)),
267+
("threadptr", Some(sym::xtensa_target_feature)),
268+
("extendedl32r", Some(sym::xtensa_target_feature)),
269+
("atomctl", Some(sym::xtensa_target_feature)),
270+
("memctl", Some(sym::xtensa_target_feature)),
271+
("debug", Some(sym::xtensa_target_feature)),
272+
("exception", Some(sym::xtensa_target_feature)),
273+
("highpriinterrupts", Some(sym::xtensa_target_feature)),
274+
("coprocessor", Some(sym::xtensa_target_feature)),
275+
("interrupt", Some(sym::xtensa_target_feature)),
276+
("rvector", Some(sym::xtensa_target_feature)),
277+
("timerint", Some(sym::xtensa_target_feature)),
278+
("prid", Some(sym::xtensa_target_feature)),
279+
("regprotect", Some(sym::xtensa_target_feature)),
280+
("miscsr", Some(sym::xtensa_target_feature)),
281+
];
282+
254283
const BPF_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[("alu32", Some(sym::bpf_target_feature))];
255284

256285
/// When rustdoc is running, provide a list of all known features so that all their respective
@@ -267,6 +296,7 @@ pub fn all_known_features() -> impl Iterator<Item = (&'static str, Option<Symbol
267296
.chain(MIPS_ALLOWED_FEATURES.iter())
268297
.chain(RISCV_ALLOWED_FEATURES.iter())
269298
.chain(WASM_ALLOWED_FEATURES.iter())
299+
.chain(XTENSA_ALLOWED_FEATURES.iter())
270300
.chain(BPF_ALLOWED_FEATURES.iter())
271301
.cloned()
272302
}
@@ -281,6 +311,7 @@ pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Opt
281311
"powerpc" | "powerpc64" => POWERPC_ALLOWED_FEATURES,
282312
"riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES,
283313
"wasm32" | "wasm64" => WASM_ALLOWED_FEATURES,
314+
"xtensa" => XTENSA_ALLOWED_FEATURES,
284315
"bpf" => BPF_ALLOWED_FEATURES,
285316
_ => &[],
286317
}

compiler/rustc_span/src/symbol.rs

+19
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ symbols! {
373373
assume_init,
374374
async_await,
375375
async_closure,
376+
atomctl,
376377
atomic,
377378
atomic_mod,
378379
atomics,
@@ -414,6 +415,7 @@ symbols! {
414415
braced_empty_structs,
415416
branch,
416417
breakpoint,
418+
breg,
417419
bridge,
418420
bswap,
419421
c_str,
@@ -525,6 +527,7 @@ symbols! {
525527
contents,
526528
context,
527529
convert,
530+
coprocessor,
528531
copy,
529532
copy_closures,
530533
copy_nonoverlapping,
@@ -591,6 +594,7 @@ symbols! {
591594
derive_default_enum,
592595
destruct,
593596
destructuring_assignment,
597+
dfpaccel,
594598
diagnostic,
595599
direct,
596600
discriminant_kind,
@@ -648,6 +652,7 @@ symbols! {
648652
ermsb_target_feature,
649653
exact_div,
650654
except,
655+
exception,
651656
exchange_malloc,
652657
exclusive_range_pattern,
653658
exhaustive_integer_patterns,
@@ -663,6 +668,7 @@ symbols! {
663668
export_name,
664669
expr,
665670
extended_key_value_attributes,
671+
extendedl32r,
666672
extern_absolute_paths,
667673
extern_crate_item_prelude,
668674
extern_crate_self,
@@ -757,6 +763,7 @@ symbols! {
757763
hash,
758764
hexagon_target_feature,
759765
hidden,
766+
highpriinterrupts,
760767
homogeneous_aggregate,
761768
html_favicon_url,
762769
html_logo_url,
@@ -804,6 +811,7 @@ symbols! {
804811
integer_: "integer",
805812
integral,
806813
intel,
814+
interrupt,
807815
into_future,
808816
into_iter,
809817
intra_doc_pointers,
@@ -864,6 +872,7 @@ symbols! {
864872
logf64,
865873
loop_break_value,
866874
lt,
875+
mac16,
867876
macro_at_most_once_rep,
868877
macro_attributes_in_derive_output,
869878
macro_escape,
@@ -902,6 +911,7 @@ symbols! {
902911
mem_variant_count,
903912
mem_zeroed,
904913
member_constraints,
914+
memctl,
905915
memory,
906916
memtag,
907917
message,
@@ -919,6 +929,7 @@ symbols! {
919929
mips_target_feature,
920930
miri,
921931
misc,
932+
miscsr,
922933
mmx_reg,
923934
modifiers,
924935
module,
@@ -1071,6 +1082,7 @@ symbols! {
10711082
prelude,
10721083
prelude_import,
10731084
preserves_flags,
1085+
prid,
10741086
primitive,
10751087
print_macro,
10761088
println_macro,
@@ -1255,7 +1267,9 @@ symbols! {
12551267
rustdoc_internals,
12561268
rustfmt,
12571269
rvalue_static_promotion,
1270+
rvector,
12581271
s,
1272+
s32c1i,
12591273
sanitize,
12601274
sanitizer_runtime,
12611275
saturating_add,
@@ -1424,8 +1438,10 @@ symbols! {
14241438
thread,
14251439
thread_local,
14261440
thread_local_macro,
1441+
threadptr,
14271442
thumb2,
14281443
thumb_mode: "thumb-mode",
1444+
timerint,
14291445
tmm_reg,
14301446
todo_macro,
14311447
tool_attributes,
@@ -1548,6 +1564,7 @@ symbols! {
15481564
wasm_target_feature,
15491565
while_let,
15501566
width,
1567+
windowed,
15511568
windows,
15521569
windows_subsystem,
15531570
with_negative_coherence,
@@ -1561,7 +1578,9 @@ symbols! {
15611578
writeln_macro,
15621579
x87_reg,
15631580
xer,
1581+
xloop,
15641582
xmm_reg,
1583+
xtensa_target_feature,
15651584
yeet_desugar_details,
15661585
yeet_expr,
15671586
ymm_reg,

0 commit comments

Comments
 (0)