public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/110656] New: Floating point to char/short or bitfield conversions
@ 2023-07-13 12:41 jakub at gcc dot gnu.org
  2023-07-13 14:32 ` [Bug c/110656] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-07-13 12:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110656

            Bug ID: 110656
           Summary: Floating point to char/short or bitfield conversions
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

While implementing floating point to _BitInt convertions, I'm wondering if it
is correct that we implement say float -> signed char conversion effectively as
float -> int -> signed char.
signed char foo (float x) { return x; }
with foo (512.0f).
ISO C17 has in F.4 says
"or if the integral part of the floating value
exceeds the range of the integer type, then the “invalid” floating-point
exception is raised and the resulting value is unspecified."
but we even with -ftrapping-math trigger invalid say for 8589934592.0f (when it
doesn't fit into int), but the above just does
        cvttss2sil      %xmm0, %eax
        movsbl  %al, %eax
on x86_64.
In the scope of _BitInt, I wonder if I should care, i.e. whether I should call
say a library routine for floating point to _BitInt(N)/unsigned _BitInt(N)
conversions when
N is smaller than bit width of __int128 (if it exists, long long otherwise) and
is not equal to width of int, long or long long, or if I can implement those
like it is implemented for char/short and bitfields.
I guess for now I'll try to implement the library side so that it handles
correctly all valid Ns and we can decide on the compiler side later.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/110656] Floating point to char/short or bitfield conversions
  2023-07-13 12:41 [Bug c/110656] New: Floating point to char/short or bitfield conversions jakub at gcc dot gnu.org
@ 2023-07-13 14:32 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-13 14:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110656

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=27682

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
See pr 27682 for the non trapping question.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-07-13 14:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-13 12:41 [Bug c/110656] New: Floating point to char/short or bitfield conversions jakub at gcc dot gnu.org
2023-07-13 14:32 ` [Bug c/110656] " pinskia at gcc dot gnu.org

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).