Skip to content

Commit

Permalink
fix: Add (even more) #[avr_skip] for floats
Browse files Browse the repository at this point in the history
Tale as old as the world - there's an ABI mismatch:
#527

Fortunately, newest GCCs (from v11, it seems) actually provide most of
those intrinsics (even for f64!), so that's pretty cool.

(the only intrinsics not provided by GCC are `__powisf2` & `__powidf2`,
but our codegen for AVR doesn't emit those anyway.)

Fixes rust-lang/rust#118079.
  • Loading branch information
Patryk27 committed Nov 26, 2023
1 parent 2a331a2 commit cfbf9c1
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/float/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,11 +902,13 @@ where
}

intrinsics! {
#[avr_skip]
#[arm_aeabi_alias = __aeabi_fdiv]
pub extern "C" fn __divsf3(a: f32, b: f32) -> f32 {
div32(a, b)
}

#[avr_skip]
#[arm_aeabi_alias = __aeabi_ddiv]
pub extern "C" fn __divdf3(a: f64, b: f64) -> f64 {
div64(a, b)
Expand Down
1 change: 1 addition & 0 deletions src/float/extend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ where
}

intrinsics! {
#[avr_skip]
#[aapcs_on_arm]
#[arm_aeabi_alias = __aeabi_f2d]
pub extern "C" fn __extendsfdf2(a: f32) -> f64 {
Expand Down
2 changes: 2 additions & 0 deletions src/float/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,14 @@ where
}

intrinsics! {
#[avr_skip]
#[aapcs_on_arm]
#[arm_aeabi_alias = __aeabi_fmul]
pub extern "C" fn __mulsf3(a: f32, b: f32) -> f32 {
mul(a, b)
}

#[avr_skip]
#[aapcs_on_arm]
#[arm_aeabi_alias = __aeabi_dmul]
pub extern "C" fn __muldf3(a: f64, b: f64) -> f64 {
Expand Down
2 changes: 2 additions & 0 deletions src/float/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ fn pow<F: Float>(a: F, b: i32) -> F {
}

intrinsics! {
#[avr_skip]
pub extern "C" fn __powisf2(a: f32, b: i32) -> f32 {
pow(a, b)
}

#[avr_skip]
pub extern "C" fn __powidf2(a: f64, b: i32) -> f64 {
pow(a, b)
}
Expand Down
2 changes: 2 additions & 0 deletions src/float/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use crate::float::add::__addsf3;
use crate::float::Float;

intrinsics! {
#[avr_skip]
#[arm_aeabi_alias = __aeabi_fsub]
pub extern "C" fn __subsf3(a: f32, b: f32) -> f32 {
__addsf3(a, f32::from_repr(b.repr() ^ f32::SIGN_MASK))
}

#[avr_skip]
#[arm_aeabi_alias = __aeabi_dsub]
pub extern "C" fn __subdf3(a: f64, b: f64) -> f64 {
__adddf3(a, f64::from_repr(b.repr() ^ f64::SIGN_MASK))
Expand Down
1 change: 1 addition & 0 deletions src/float/trunc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ where
}

intrinsics! {
#[avr_skip]
#[aapcs_on_arm]
#[arm_aeabi_alias = __aeabi_d2f]
pub extern "C" fn __truncdfsf2(a: f64) -> f32 {
Expand Down

0 comments on commit cfbf9c1

Please sign in to comment.