Skip to content

add built-in complex number types for C ABI compatibility #10500

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

Closed
thestinger opened this issue Nov 15, 2013 · 4 comments
Closed

add built-in complex number types for C ABI compatibility #10500

thestinger opened this issue Nov 15, 2013 · 4 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@thestinger
Copy link
Contributor

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.

@nikomatsakis
Copy link
Contributor

On Thu, Nov 14, 2013 at 10:15:43PM -0800, Daniel Micay wrote:

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.

By "built-in", do you mean lang items? I'd imagine that is sufficient.

@thestinger
Copy link
Contributor Author

@nikomatsakis: Yeah, language items would work.

(In fact, it would be nice to move to language items for all built-in types in order to allow defining methods on them. The constant expression evaluation and syntax wouldn't have to change.)

@huonw
Copy link
Member

huonw commented Nov 17, 2014

Example of this in C:

#include<complex.h>

struct test {
    float x, y;
};
struct test s() {
    struct test ret = { 1.0, 2.0 };
    return ret;
}

float complex c() {
    return 1.0 + 2.0 * I;
}

Compiled with clang -S complex.c -O --target=i686-unknown-linux gives, respectively:

s:                                      # @s
# BB#0:
    movl    4(%esp), %eax
    movl    $1073741824, 4(%eax)    # imm = 0x40000000
    movl    $1065353216, (%eax)     # imm = 0x3F800000
    retl    $4

c:                                      # @c
# BB#0:
    movl    $1065353216, %eax       # imm = 0x3F800000
    movl    $1073741824, %edx       # imm = 0x40000000
    retl

i.e. the struct (equivalent to num::Complex<f32>) is returned on the stack but _Complex is returned in registers.

@steveklabnik
Copy link
Member

I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized.

This issue has been moved to the RFCs repo: rust-lang/rfcs#793

flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 24, 2023
Fix documentation for `derived_hash_with_manual_eq`

changelog: fix documentation for `derived_hash_with_manual_eq`

The documentation retained "vice versa" from the previous incarnation of the lint but the lint itself no longer lints against manual `Hash` implementations with a derived `PartialEq`.

I also adjusted the documentation for `PartialOrd`-`Ord` lint as "vice versa" seemed a little confusing to me there (as to what it was refering to exactly.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

4 participants