Skip to content

Draft implementation of real(16), imag(16), complex(32) #27010

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

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

bradcray
Copy link
Member

@bradcray bradcray commented Mar 28, 2025

This PR represents a work in progress to try and add support for 16-bit floats, such as real(16), imag(16), and complex(32) for platforms and back-end compilers that support _Float16.

TODO:

  • add support for the ability to build on a system that doesn't support _Float16 (like our CI's compiler, apparently)

Sufficient to compile

```chapel
var pi16: real(16) = 3.14159265;

writeln(pi16);
```

using the C back-end

---
Signed-off-by: Brad Chamberlain <[email protected]>
It seems lack of these broke some tests... maybe we do some automatic
conversions between enums s.t. missing the corresponding COMPLEX enums
broke things?

---
Signed-off-by: Brad Chamberlain <[email protected]>
---
Signed-off-by: Brad Chamberlain <[email protected]>
Also add --ignore-errors for pass to the *-1.chpl version since only
locking in the first error makes it equivalent to the *-2.chpl version
matching its .bad file.

---
Signed-off-by: Brad Chamberlain <[email protected]>
@bradcray bradcray changed the title Float16 Draft implementation of real(16), imag(16), complex(32) Mar 28, 2025
The main thing I'm aware of that's completely busted currently is
that my casts to complex rely on .re and .im which themselves
currently rely on casts in order to use chpl_crealf() implemented
in terms of __builtin_crealf, as I haven't found a 16-bit equivalent.
This results in an infinite recursion in the compiler.  I think
the way to break it is to enable something like the commented-out
code in chpl_anycomplex.re/.im

I think there are also updates needed to the CPP_IS_LAME macros
in frontend/lib/immediates/num.h, but I don't quite follow the
second of these yet.

---
Signed-off-by: Brad Chamberlain <[email protected]>
@bradcray
Copy link
Member Author

A place where this PR is currently failing comes up with a simple test case like:

var c32: complex(32);
var r = c32.re;

Specifically, my current implementation implements the .re queries by upcasting c32 to a complex(64), using the normal .re method on it, and then downcasting the result. However, the cast-to-complex(64) that I'm currently using relies on .re, so I end up with a circularity in the implementation. The most logical way to break this cycle would be to implement a chpl_realh() to mirror chpl_realf() and chpl_real(), but it seems that LLVM/gcc/etc. don't have a built-in for that case, which is how we typically implement these routines.

Thanks to Jade for the tip about __builtin_crealf() working for
complex(32) (though I have no intuition as to why that would be...)

---
Signed-off-by: Brad Chamberlain <[email protected]>
---
Signed-off-by: Brad Chamberlain <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant