Skip to content

Commit fb95fb4

Browse files
committed
Add abi_properties
1 parent a2b570a commit fb95fb4

File tree

5 files changed

+93
-34
lines changed

5 files changed

+93
-34
lines changed

xlang/xlang_targets/src/properties.rs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,25 @@ pub enum ArchiverFlavor {
3737
MsLib,
3838
}
3939

40-
/// The (default) format (and size) of the C long double type on the target
41-
#[repr(i32)]
40+
/// The Format for floating-point types
41+
#[repr(i16)]
4242
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
43-
pub enum LongDoubleFormat {
44-
/// IEEE 754, double precision (same as double)
45-
IEEE64,
46-
/// IEEE 754, quad precision
47-
IEEE128,
48-
/// Intel x87, double extended precision
49-
X87,
50-
/// Double-double precision (used by PowerPC )
51-
PowerPCDoubleDouble,
43+
pub enum FloatFormat {
44+
/// An IEEE754 floating-point value (width)
45+
Ieee754(u16),
46+
/// A 10-byte (x87) double-extended precision value
47+
X87DoubleExtended,
48+
/// Ibm128/double-double precisiion used by PowerPC
49+
Ieee64x2,
5250
}
5351

54-
impl LongDoubleFormat {
55-
/// Obtains the size needed to store the format
56-
/// Note: This does not necessarily match `float(long)`, and must be rounded to alignment size
57-
pub const fn size(self) -> u16 {
52+
impl FloatFormat {
53+
/// The size (in bytes) of the value, before applying alignment
54+
pub fn size(&self) -> u16 {
5855
match self {
59-
LongDoubleFormat::IEEE64 => 8,
60-
LongDoubleFormat::IEEE128 => 16,
61-
LongDoubleFormat::X87 => 10,
62-
LongDoubleFormat::PowerPCDoubleDouble => 16,
56+
Self::Ieee754(val) => (*val).saturating_add(7) >> 3,
57+
Self::X87DoubleExtended => 10,
58+
Self::Ieee64x2 => 16,
6359
}
6460
}
6561
}
@@ -114,6 +110,20 @@ pub struct AsmProperties<'a> {
114110
/// Properties about builtin functions on a target
115111
pub mod builtins;
116112

113+
/// Properties about types that may require specific target features available to compile to
114+
#[repr(C)]
115+
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
116+
pub struct AbiProperties<'a> {
117+
/// Which feature vector types to each size
118+
pub vector_width_features: Span<'a, Pair<u16, StringView<'a>>>,
119+
/// Which feature is required to enable all unmentioned vector types
120+
pub vector_default_feature: StringView<'a>,
121+
/// Which feature each floating-point format requires,
122+
pub float_format_features: Span<'a, Pair<FloatFormat, StringView<'a>>>,
123+
/// Which feature is required to enable all unmentioned floating-point types
124+
pub float_default_features: StringView<'a>,
125+
}
126+
117127
///
118128
/// Properties about the architecture, shared between targets that use this architecture
119129
#[repr(C)]
@@ -146,6 +156,9 @@ pub struct ArchProperties<'a> {
146156

147157
/// Width of the architecture: Used by backends to differentiate between supported targets
148158
pub width: u16,
159+
160+
/// Abi Limits of the target
161+
pub abi_properties: Option<&'a AbiProperties<'a>>,
149162
}
150163

151164
///
@@ -258,7 +271,7 @@ pub struct PrimitiveProperties {
258271
/// While `long double` does not use `max_align`, `max_align` should be at least this value to match the definition of the C/C++ typedef `align_max_t`.
259272
pub ldbl_align: u16,
260273
/// The format (and size) of the C `long double` type on this target
261-
pub ldbl_format: LongDoubleFormat,
274+
pub ldbl_format: FloatFormat,
262275
}
263276

264277
/// Properties about a particular target, which includes an architecture and an operating system

xlang/xlang_targets/src/properties/clever.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use xlang_abi::{const_sv, pair::Pair, span, span::Span, string::StringView};
22

3-
use super::{ArchProperties, AsmProperties, MachineProperties, PrimitiveProperties};
3+
use super::{AbiProperties, ArchProperties, AsmProperties, MachineProperties, PrimitiveProperties};
44

55
macro_rules! clever_machines{
66
{
@@ -257,6 +257,13 @@ pub static CLEVER_ASM: AsmProperties = AsmProperties {
257257
classes: CLEVER_ASM_CLASSES,
258258
};
259259

260+
pub static CLEVER_ABI: AbiProperties = AbiProperties {
261+
vector_default_feature: const_sv!("main"),
262+
vector_width_features: span![],
263+
float_default_features: const_sv!("float"),
264+
float_format_features: span![Pair(super::FloatFormat::Ieee754(128), const_sv!("main"))],
265+
};
266+
260267
pub static CLEVER: ArchProperties = ArchProperties {
261268
lock_free_atomic_masks: 0xff,
262269
builtins: CLEVER_BUILTINS,
@@ -268,6 +275,7 @@ pub static CLEVER: ArchProperties = ArchProperties {
268275
asm_propreties: &CLEVER_ASM,
269276
tag_names: span![const_sv!("C")],
270277
width: 64,
278+
abi_properties: Some(&CLEVER_ABI),
271279
};
272280

273281
pub static CLEVER_PRIMITIVES: PrimitiveProperties = PrimitiveProperties {
@@ -284,7 +292,7 @@ pub static CLEVER_PRIMITIVES: PrimitiveProperties = PrimitiveProperties {
284292
sizebits: 64,
285293
lock_free_atomic_mask: 0xff,
286294
ldbl_align: 8,
287-
ldbl_format: super::LongDoubleFormat::IEEE64,
295+
ldbl_format: super::FloatFormat::Ieee754(64),
288296
max_atomic_align: 16,
289297
};
290298

@@ -302,6 +310,6 @@ pub static CLEVERILP32_PRIMITIVES: PrimitiveProperties = PrimitiveProperties {
302310
sizebits: 32,
303311
lock_free_atomic_mask: 0xff,
304312
ldbl_align: 8,
305-
ldbl_format: super::LongDoubleFormat::IEEE64,
313+
ldbl_format: super::FloatFormat::Ieee754(64),
306314
max_atomic_align: 16,
307315
};

xlang/xlang_targets/src/properties/holeybytes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub static PRIMITIVES: PrimitiveProperties = PrimitiveProperties {
3737
lock_free_atomic_mask: 0xff,
3838
max_atomic_align: 16,
3939
ldbl_align: 16,
40-
ldbl_format: super::LongDoubleFormat::IEEE128,
40+
ldbl_format: super::FloatFormat::Ieee754(128),
4141
};
4242

4343
pub static MACHINE_GENERIC: MachineProperties = MachineProperties {
@@ -88,4 +88,5 @@ pub static HOLEYBYTES: ArchProperties = ArchProperties {
8888
asm_propreties: &ASM,
8989
tag_names: span![const_sv!("C")],
9090
width: 64,
91+
abi_properties: None,
9192
};

xlang/xlang_targets/src/properties/w65.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use super::{
99
asm::AsmScalar,
1010
asm::AsmScalarKind::{ClobberOnly, Float, Integer},
1111
builtins::BuiltinSignature,
12-
ArchProperties, AsmProperties, LongDoubleFormat, MachineProperties, PrimitiveProperties,
12+
ArchProperties, AsmProperties, MachineProperties, PrimitiveProperties,
1313
};
1414

1515
macro_rules! w65_machines{
@@ -142,6 +142,7 @@ pub static W65: ArchProperties = ArchProperties {
142142
asm_propreties: &W65_ASSEMBLY,
143143
tag_names: span![const_sv!("C"), const_sv!("w65-interrupt")],
144144
width: 16,
145+
abi_properties: None,
145146
};
146147

147148
pub static W65_PRIMITIVES: PrimitiveProperties = PrimitiveProperties {
@@ -158,6 +159,6 @@ pub static W65_PRIMITIVES: PrimitiveProperties = PrimitiveProperties {
158159
lock_free_atomic_mask: 0x3,
159160
sizebits: 16,
160161
ldbl_align: 4,
161-
ldbl_format: LongDoubleFormat::IEEE64,
162+
ldbl_format: super::FloatFormat::Ieee754(64),
162163
max_atomic_align: 2,
163164
};

xlang/xlang_targets/src/properties/x86.rs

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::{
66
asm::AsmScalar,
77
asm::AsmScalarKind::{Float, Integer, Vector},
88
builtins::BuiltinSignature,
9-
ArchProperties, AsmProperties, LongDoubleFormat, PrimitiveProperties,
9+
AbiProperties, ArchProperties, AsmProperties, FloatFormat, PrimitiveProperties,
1010
};
1111

1212
macro_rules! x86_machines{
@@ -564,6 +564,33 @@ pub const X86_16_TAG_NAMES: Span<StringView> = span![
564564
const_sv!("fastcall")
565565
];
566566

567+
pub const X86_VECTOR_ABI_FEATURES: Span<Pair<u16, StringView>> = span![
568+
Pair(8, const_sv!("mmx")),
569+
Pair(16, const_sv!("sse")),
570+
Pair(32, const_sv!("avx")),
571+
Pair(64, const_sv!("avx512f")),
572+
Pair(1024, const_sv!("amx-tile"))
573+
];
574+
pub const X86_FLOAT_ABI_FEATURES: Span<Pair<super::FloatFormat, StringView>> = span![Pair(
575+
super::FloatFormat::X87DoubleExtended,
576+
const_sv!("x87")
577+
),];
578+
579+
pub static X86_64_ABI_PROPERTIES: AbiProperties = AbiProperties {
580+
vector_default_feature: const_sv!(""), // An empty string will never be settable with `-m`
581+
vector_width_features: X86_VECTOR_ABI_FEATURES,
582+
float_format_features: X86_FLOAT_ABI_FEATURES,
583+
float_default_features: const_sv!("sse"),
584+
};
585+
586+
// x86-64 vs. IA-32 and IA-16 only differs in requiring sse vs. x87 for floats.
587+
pub static X86_ABI_PROPERTIES: AbiProperties = AbiProperties {
588+
vector_default_feature: const_sv!(""), // An empty string will never be settable with `-m`
589+
vector_width_features: X86_VECTOR_ABI_FEATURES,
590+
float_format_features: X86_FLOAT_ABI_FEATURES,
591+
float_default_features: const_sv!("x87"),
592+
};
593+
567594
pub static X86_64: ArchProperties = ArchProperties {
568595
lock_free_atomic_masks: 0xFF,
569596
builtins: X86_BUILTINS,
@@ -575,6 +602,7 @@ pub static X86_64: ArchProperties = ArchProperties {
575602
asm_propreties: &X86_64_ASM_PROPERTIES,
576603
tag_names: X86_64_TAG_NAMES,
577604
width: 64,
605+
abi_properties: Some(&X86_64_ABI_PROPERTIES),
578606
};
579607

580608
pub static X86_64_V2: ArchProperties = ArchProperties {
@@ -588,6 +616,7 @@ pub static X86_64_V2: ArchProperties = ArchProperties {
588616
asm_propreties: &X86_64_ASM_PROPERTIES,
589617
tag_names: X86_64_TAG_NAMES,
590618
width: 64,
619+
abi_properties: Some(&X86_64_ABI_PROPERTIES),
591620
};
592621

593622
pub static X86_64_V3: ArchProperties = ArchProperties {
@@ -601,6 +630,7 @@ pub static X86_64_V3: ArchProperties = ArchProperties {
601630
asm_propreties: &X86_64_ASM_PROPERTIES,
602631
tag_names: X86_64_TAG_NAMES,
603632
width: 64,
633+
abi_properties: Some(&X86_64_ABI_PROPERTIES),
604634
};
605635

606636
pub static X86_64_V4: ArchProperties = ArchProperties {
@@ -614,6 +644,7 @@ pub static X86_64_V4: ArchProperties = ArchProperties {
614644
asm_propreties: &X86_64_ASM_PROPERTIES,
615645
tag_names: X86_64_TAG_NAMES,
616646
width: 64,
647+
abi_properties: Some(&X86_64_ABI_PROPERTIES),
617648
};
618649

619650
pub static I386: ArchProperties = ArchProperties {
@@ -627,6 +658,7 @@ pub static I386: ArchProperties = ArchProperties {
627658
asm_propreties: &X86_32_ASM_PROPERTIES,
628659
tag_names: X86_32_TAG_NAMES,
629660
width: 32,
661+
abi_properties: Some(&X86_ABI_PROPERTIES),
630662
};
631663

632664
pub static I486: ArchProperties = ArchProperties {
@@ -640,6 +672,7 @@ pub static I486: ArchProperties = ArchProperties {
640672
asm_propreties: &X86_32_ASM_PROPERTIES,
641673
tag_names: X86_32_TAG_NAMES,
642674
width: 32,
675+
abi_properties: Some(&X86_ABI_PROPERTIES),
643676
};
644677
pub static I586: ArchProperties = ArchProperties {
645678
lock_free_atomic_masks: 0xF,
@@ -652,6 +685,7 @@ pub static I586: ArchProperties = ArchProperties {
652685
asm_propreties: &X86_32_ASM_PROPERTIES,
653686
tag_names: X86_32_TAG_NAMES,
654687
width: 32,
688+
abi_properties: Some(&X86_ABI_PROPERTIES),
655689
};
656690

657691
pub static I686: ArchProperties = ArchProperties {
@@ -665,6 +699,7 @@ pub static I686: ArchProperties = ArchProperties {
665699
asm_propreties: &X86_32_ASM_PROPERTIES,
666700
tag_names: X86_32_TAG_NAMES,
667701
width: 32,
702+
abi_properties: Some(&X86_ABI_PROPERTIES),
668703
};
669704

670705
pub static I86: ArchProperties = ArchProperties {
@@ -678,6 +713,7 @@ pub static I86: ArchProperties = ArchProperties {
678713
asm_propreties: &X86_16_ASM_PROPERTIES,
679714
tag_names: X86_16_TAG_NAMES,
680715
width: 16,
716+
abi_properties: Some(&X86_ABI_PROPERTIES),
681717
};
682718

683719
pub static X86_64_PRIMITIVES: PrimitiveProperties = PrimitiveProperties {
@@ -694,7 +730,7 @@ pub static X86_64_PRIMITIVES: PrimitiveProperties = PrimitiveProperties {
694730
sizebits: 64,
695731
lock_free_atomic_mask: 0xffff,
696732
ldbl_align: 16,
697-
ldbl_format: super::LongDoubleFormat::X87,
733+
ldbl_format: FloatFormat::X87DoubleExtended,
698734
max_atomic_align: 16,
699735
};
700736

@@ -712,7 +748,7 @@ pub static X32_PRIMITIVES: PrimitiveProperties = PrimitiveProperties {
712748
sizebits: 32,
713749
lock_free_atomic_mask: 0xffff,
714750
ldbl_align: 16,
715-
ldbl_format: super::LongDoubleFormat::X87,
751+
ldbl_format: FloatFormat::X87DoubleExtended,
716752
max_atomic_align: 16,
717753
};
718754

@@ -730,7 +766,7 @@ pub static X86_32_PRIMITIVES: PrimitiveProperties = PrimitiveProperties {
730766
lock_free_atomic_mask: 0xf,
731767
sizebits: 32,
732768
ldbl_align: 4,
733-
ldbl_format: LongDoubleFormat::X87,
769+
ldbl_format: FloatFormat::X87DoubleExtended,
734770
max_atomic_align: 4,
735771
};
736772

@@ -748,7 +784,7 @@ pub static X86_16_NEAR_PRIMITIVES: PrimitiveProperties = PrimitiveProperties {
748784
lock_free_atomic_mask: 0x3,
749785
sizebits: 16,
750786
ldbl_align: 4,
751-
ldbl_format: LongDoubleFormat::X87,
787+
ldbl_format: FloatFormat::X87DoubleExtended,
752788
max_atomic_align: 2,
753789
};
754790

@@ -766,7 +802,7 @@ pub static X86_16_FAR_PRIMITIVES: PrimitiveProperties = PrimitiveProperties {
766802
lock_free_atomic_mask: 0x3,
767803
sizebits: 16,
768804
ldbl_align: 4,
769-
ldbl_format: LongDoubleFormat::X87,
805+
ldbl_format: FloatFormat::X87DoubleExtended,
770806
max_atomic_align: 2,
771807
};
772808

@@ -784,7 +820,7 @@ pub static X86_16_NEAR_DATA_FAR_FN_PRIMITIVES: PrimitiveProperties = PrimitivePr
784820
lock_free_atomic_mask: 0x3,
785821
sizebits: 16,
786822
ldbl_align: 4,
787-
ldbl_format: LongDoubleFormat::X87,
823+
ldbl_format: FloatFormat::X87DoubleExtended,
788824
max_atomic_align: 2,
789825
};
790826

@@ -802,6 +838,6 @@ pub static X86_16_FAR_DATA_NEAR_FN_PRIMITIVES: PrimitiveProperties = PrimitivePr
802838
lock_free_atomic_mask: 0x3,
803839
sizebits: 16,
804840
ldbl_align: 4,
805-
ldbl_format: LongDoubleFormat::X87,
841+
ldbl_format: FloatFormat::X87DoubleExtended,
806842
max_atomic_align: 2,
807843
};

0 commit comments

Comments
 (0)