Skip to content

Commit 2541f27

Browse files
Tomasz Miąskotmiasko
Tomasz Miąsko
andauthored
Place intrinsics in individual object files (#349)
Co-authored-by: Tomasz Miąsko <[email protected]>
1 parent 72526f3 commit 2541f27

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

src/macros.rs

+33-16
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,12 @@ macro_rules! intrinsics {
173173

174174
#[cfg(all(windows, target_arch = "x86_64"))]
175175
pub mod $name {
176-
177-
intrinsics! {
178-
pub extern $abi fn $name( $($argname: $ty),* )
179-
-> ::macros::win64_128bit_abi_hack::U64x2
180-
{
181-
let e: $ret = super::$name($($argname),*);
182-
::macros::win64_128bit_abi_hack::U64x2::from(e)
183-
}
176+
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
177+
pub extern $abi fn $name( $($argname: $ty),* )
178+
-> ::macros::win64_128bit_abi_hack::U64x2
179+
{
180+
let e: $ret = super::$name($($argname),*);
181+
::macros::win64_128bit_abi_hack::U64x2::from(e)
184182
}
185183
}
186184

@@ -209,17 +207,23 @@ macro_rules! intrinsics {
209207
$($rest:tt)*
210208
) => (
211209
#[cfg(target_arch = "arm")]
212-
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
213210
pub extern $abi fn $name( $($argname: $ty),* ) -> $ret {
214211
$($body)*
215212
}
216213

217214
#[cfg(target_arch = "arm")]
218215
pub mod $name {
219-
intrinsics! {
220-
pub extern "aapcs" fn $alias( $($argname: $ty),* ) -> $ret {
221-
super::$name($($argname),*)
222-
}
216+
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
217+
pub extern $abi fn $name( $($argname: $ty),* ) -> $ret {
218+
super::$name($($argname),*)
219+
}
220+
}
221+
222+
#[cfg(target_arch = "arm")]
223+
pub mod $alias {
224+
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
225+
pub extern "aapcs" fn $alias( $($argname: $ty),* ) -> $ret {
226+
super::$name($($argname),*)
223227
}
224228
}
225229

@@ -234,9 +238,15 @@ macro_rules! intrinsics {
234238
intrinsics!($($rest)*);
235239
);
236240

237-
// This is the final catch-all rule. At this point we just generate an
241+
// This is the final catch-all rule. At this point we generate an
238242
// intrinsic with a conditional `#[no_mangle]` directive to avoid
239-
// interfereing with duplicate symbols and whatnot during testing.
243+
// interfering with duplicate symbols and whatnot during testing.
244+
//
245+
// The implementation is placed in a separate module, to take advantage
246+
// of the fact that rustc partitions functions into code generation
247+
// units based on module they are defined in. As a result we will have
248+
// a separate object file for each intrinsic. For further details see
249+
// corresponding PR in rustc https://github.com/rust-lang/rust/pull/70846
240250
//
241251
// After the intrinsic is defined we just continue with the rest of the
242252
// input we were given.
@@ -249,11 +259,18 @@ macro_rules! intrinsics {
249259
$($rest:tt)*
250260
) => (
251261
$(#[$($attr)*])*
252-
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
253262
pub extern $abi fn $name( $($argname: $ty),* ) -> $ret {
254263
$($body)*
255264
}
256265

266+
pub mod $name {
267+
$(#[$($attr)*])*
268+
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
269+
pub extern $abi fn $name( $($argname: $ty),* ) -> $ret {
270+
super::$name($($argname),*)
271+
}
272+
}
273+
257274
intrinsics!($($rest)*);
258275
);
259276
}

0 commit comments

Comments
 (0)