Created
May 29, 2023 10:37
-
-
Save AngelicosPhosphoros/2a5e4e633b149cc65e5a61806f7b180a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(no_core)] | |
#![no_core] | |
#![crate_type="rlib"] | |
#![feature(rustc_attrs)] | |
#![feature(fundamental)] | |
#![feature(lang_items)] | |
#![feature(intrinsics)] | |
#![feature(auto_traits)] | |
#![allow(non_camel_case_types)] | |
//! How to compile with gcc | |
//! ``` | |
//! export LIBRARY_PATH="/home/angel/gcc-build/gcc:/home/angel/rust/build/x86_64-unknown-linux-gnu/stage2/lib/" | |
//! export LD_LIBRARY_PATH="/home/angel/gcc-build/gcc:/home/angel/rust/build/x86_64-unknown-linux-gnu/stage2/lib/" | |
//! rustc +stage2 -Copt-level=3 \ | |
//! -Z force-unstable-if-unmarked -Zcodegen-backend=/home/angel/rust/compiler/rustc_codegen_gcc/target/debug/librustc_codegen_gcc.so \ | |
//! --sysroot /home/angel/rust/compiler/rustc_codegen_gcc/build_sysroot/sysroot \ | |
//! test_many_swaps.rs --emit=asm | |
//! ``` | |
//! | |
#[repr(align(64))] | |
pub struct BigButHighlyAligned([u8; 192]); | |
#[no_mangle] | |
pub fn swap_BigButHighlyAligned(a: &mut BigButHighlyAligned, b: &mut BigButHighlyAligned){ | |
swap_nonoverlapping(a, b); | |
} | |
pub struct A_0([u8; 0]); | |
pub struct A_1([u8; 1]); | |
pub struct A_2([u8; 2]); | |
pub struct A_3([u8; 3]); | |
pub struct A_4([u8; 4]); | |
pub struct A_5([u8; 5]); | |
pub struct A_6([u8; 6]); | |
pub struct A_7([u8; 7]); | |
pub struct A_8([u8; 8]); | |
pub struct A_9([u8; 9]); | |
pub struct A_10([u8; 10]); | |
pub struct A_11([u8; 11]); | |
pub struct A_12([u8; 12]); | |
pub struct A_13([u8; 13]); | |
pub struct A_14([u8; 14]); | |
pub struct A_15([u8; 15]); | |
pub struct A_16([u8; 16]); | |
#[no_mangle] | |
pub fn swap_a_0(a: &mut A_0, b: &mut A_0){ | |
swap_nonoverlapping(a, b); | |
} | |
#[no_mangle] | |
pub fn swap_a_1(a: &mut A_1, b: &mut A_1){ | |
swap_nonoverlapping(a, b); | |
} | |
#[no_mangle] | |
pub fn swap_a_2(a: &mut A_2, b: &mut A_2){ | |
swap_nonoverlapping(a, b); | |
} | |
#[no_mangle] | |
pub fn swap_a_3(a: &mut A_3, b: &mut A_3){ | |
swap_nonoverlapping(a, b); | |
} | |
#[no_mangle] | |
pub fn swap_a_4(a: &mut A_4, b: &mut A_4){ | |
swap_nonoverlapping(a, b); | |
} | |
#[no_mangle] | |
pub fn swap_a_5(a: &mut A_5, b: &mut A_5){ | |
swap_nonoverlapping(a, b); | |
} | |
#[no_mangle] | |
pub fn swap_a_6(a: &mut A_6, b: &mut A_6){ | |
swap_nonoverlapping(a, b); | |
} | |
#[no_mangle] | |
pub fn swap_a_7(a: &mut A_7, b: &mut A_7){ | |
swap_nonoverlapping(a, b); | |
} | |
#[no_mangle] | |
pub fn swap_a_8(a: &mut A_8, b: &mut A_8){ | |
swap_nonoverlapping(a, b); | |
} | |
#[no_mangle] | |
pub fn swap_a_9(a: &mut A_9, b: &mut A_9){ | |
swap_nonoverlapping(a, b); | |
} | |
#[no_mangle] | |
pub fn swap_a_10(a: &mut A_10, b: &mut A_10){ | |
swap_nonoverlapping(a, b); | |
} | |
#[no_mangle] | |
pub fn swap_a_11(a: &mut A_11, b: &mut A_11){ | |
swap_nonoverlapping(a, b); | |
} | |
#[no_mangle] | |
pub fn swap_a_12(a: &mut A_12, b: &mut A_12){ | |
swap_nonoverlapping(a, b); | |
} | |
#[no_mangle] | |
pub fn swap_a_13(a: &mut A_13, b: &mut A_13){ | |
swap_nonoverlapping(a, b); | |
} | |
#[no_mangle] | |
pub fn swap_a_14(a: &mut A_14, b: &mut A_14){ | |
swap_nonoverlapping(a, b); | |
} | |
#[no_mangle] | |
pub fn swap_a_15(a: &mut A_15, b: &mut A_15){ | |
swap_nonoverlapping(a, b); | |
} | |
#[no_mangle] | |
pub fn swap_a_16(a: &mut A_16, b: &mut A_16){ | |
swap_nonoverlapping(a, b); | |
} | |
#[doc(alias = "?", alias = "?Sized")] | |
#[lang = "sized"] | |
#[rustc_on_unimplemented( | |
message = "the size for values of type `{Self}` cannot be known at compilation time", | |
label = "doesn't have a size known at compile-time" | |
)] | |
#[fundamental] | |
#[rustc_specialization_trait] | |
#[rustc_deny_explicit_impl] | |
#[rustc_coinductive] | |
pub trait Sized { | |
// Empty. | |
} | |
#[lang = "copy"] | |
#[rustc_unsafe_specialization_marker] | |
#[rustc_diagnostic_item = "Copy"] | |
pub trait Copy: Clone { | |
// Empty. | |
} | |
#[lang = "clone"] | |
#[rustc_diagnostic_item = "Clone"] | |
#[rustc_trivial_field_reads] | |
pub trait Clone: Sized {} | |
#[inline] | |
#[rustc_nounwind] | |
pub fn swap_nonoverlapping<T: Sized>(x: &mut T, y: &mut T) { | |
extern "rust-intrinsic" { | |
#[rustc_nounwind] | |
fn swap_nonoverlapping_single<T: Sized>(x: *mut T, y: *mut T); | |
} | |
unsafe { | |
swap_nonoverlapping_single(x as *mut T, y as *mut T); | |
} | |
} | |
#[rustc_on_unimplemented( | |
note = "consider using the `pin!` macro\nconsider using `Box::pin` if you need to access the pinned value outside of the current scope", | |
message = "`{Self}` cannot be unpinned" | |
)] | |
#[lang = "unpin"] | |
pub auto trait Unpin {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment