-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add built-in complex number types for C ABI compatibility #793
Comments
A possible implementation strategy is a new |
As far as I could understand it can and should be represented as an array of 2 floats or doubles to be C99-compatible. struct<T: f32 or f64> Complex<T>{
data: [T; 2]
} https://gist.github.com/258c1bfdc80970642dd1 seems to work at least on play.rust-lang.org. |
I don't think playground is using x86, which was the platform with noticeable breakage. |
Looks like playground is is using x86_64. |
Why is x86 behaving differently? |
@nagisa, see this comment; we need a new compiler feature for this. |
@bluss I saw how it is different. I’m asking why it is different… i.e. is it specified anywhere in the C standard or x86/Sys V ABI (I admit, I have hard time reading and searching these most of the time) or is it just C compilers doing C things? |
@nagisa the C standard doesn't specify any calling conventions. SysV ABI for i386 (at least this version) specifies the use of registers for returning Not sure if all systems follow that ABI (anyone know what windows does?) |
@jmesmon great! To be more precise (for people who have as much trouble searching for things as me) it is table 2.4 on page 14. It could still be hacked around without (much) language support by doing something along the lines of #[cfg(target_Cabi="SysVx86")] // replace with the relevant target_os and target_arch combinations
#[repr(C)]
struct<T: f32> Complex<T>{ // probably will need to give up parametricity because different representations are necessary for `Complex<f32>` and `Complex<f64>`
data: i64
} EDIT: it probably wants to be a newtyped alias instead or perhaps an EDIT2: My primary goal is to understand as much as possible about the problem before agreeing or disagreeing with this course of action (adding language level things). This requires at least details on C ABIs used on all platforms we support. Short summary so far:
|
Shouldn't some form of specialization allow us to keep Complex parameterized? |
VC does not support C On x64, the Something to also consider is that once we implement something for |
Workaround in action: https://github.com/cubehub/doppler/blob/master/src/dsp.rs |
Issue by thestinger
Friday Nov 15, 2013 at 06:15 GMT
For earlier discussion, see rust-lang/rust#10500
This issue was labelled with: I-enhancement in the Rust repository
These are sadly not just treated as a simple
struct
on various platforms and have ABI requirements. I think support for the existing C math library is important because this isn't something we want to recreate on every platform.The text was updated successfully, but these errors were encountered: