public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: Petter Tomner <tomner@bahnhof.se>, jit@gcc.gnu.org
Subject: Re: [PATCH 1/2] jit: Complex types and loong constants
Date: Tue, 21 Nov 2023 09:43:58 -0500	[thread overview]
Message-ID: <4f908fb2947d419a0260bd17107a353f4f0ab057.camel@redhat.com> (raw)
In-Reply-To: <3c502ba4-ffc1-4faf-8e3f-f7b7367a50e5@bahnhof.se>

On Mon, 2023-11-20 at 23:10 +0100, Petter Tomner wrote:
> This patch fixes support for complex types.
> 
> It adds the entrypoints:
> gcc_jit_context_new_rvalue_from_complex_double
> gcc_jit_context_set_bool_enable_complex_types
> 
> Aswell as the binary operator GCC_JIT_BINARY_OP_COMPLEX, to make
> complex numbers from two real number rvalues.
> 
> Note that the complex types already are in the type enum, so I
> thought the
> cleanest solution is to enable them, rather than to have a
> "get_complex_type"
> function.
> 
> When I wrote the patch originally, the complex enums were not usable
> due to a
> range check, but I think they accidentally were included when int8_t
> etc were added.
> However, casts to complex types segfaults currently and some other
> issues, so I would say
> an explicit enable is the least confusing, since the enums have been
> there since the get go.
> 
> See attachement.

> Subject: [PATCH 1/2] Complex
> 
> Fix support for complex types

Thanks for the patch.

> 
> The patch adds support of complex floating point types to libgccjit.
> A new binary operator 'COMPLEX' is added to create complex values
> from real values. Aswell as a function to create a complex double
> literal.

The patch adds usage of "_Complex" to libgccjit.h.  According to
https://en.cppreference.com/w/c/language/arithmetic_types#Complex_floating_types
this is a C99 feature.

I think libgccjit.h is currently only requiring C89 (but I'm not sure),
so this declaration probably needs some kind of "C99 or later"
preprocessor guard.

Also, this needs to be includeable from C++; I'm not sure what the
precise requirements there are.

> 
> To notify users if a binary linking to libgccjit depends on complex
> types, complex type support most be enabled with a new option function
> since they allready are in the types enum.

I like this approach, but I see that the patch only uses it to guard
gcc_jit_context_get_type.

It seems to me that it should guard every entrypoint that uses an enum
that's expanded by the API, so presumably it should also guard
gcc_jit_context_new_binary_op with op == GCC_JIT_BINARY_OP_COMPLEX. 
Although you'd need a complex type from gcc_jit_context_get_type to get
the result, it's probably easier for the user to understand if we
document and validate the gcc_jit_context_new_binary_op with op ==
GCC_JIT_BINARY_OP_COMPLEX explicitly.

I looked through the rest of the patch and it seems OK, though I'm
nervous about all the tests that are comparing floating point values
for equality; do we always get the precise expected value, on every
target?  Floating point equality comparisons tend to be a nightmare in
unit tests.

Thanks again for the patch
Dave


  reply	other threads:[~2023-11-21 14:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-20 22:02 [PATCH 0/2] " Petter Tomner
2023-11-20 22:10 ` [PATCH 1/2] " Petter Tomner
2023-11-21 14:43   ` David Malcolm [this message]
2023-11-26 23:15     ` Petter Tomner
2023-11-20 22:15 ` [PATCH 2/2] " Petter Tomner
2023-11-21 15:56   ` David Malcolm
2023-11-26 23:15     ` Petter Tomner
2023-12-11 23:35       ` Petter Tomner
  -- strict thread matches above, loose matches on Subject: below --
2021-10-21 13:02 [PATCH 0/2] " Petter Tomner
2021-10-21 13:07 ` [PATCH 1/2] " Petter Tomner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4f908fb2947d419a0260bd17107a353f4f0ab057.camel@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=jit@gcc.gnu.org \
    --cc=tomner@bahnhof.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).