[M68K][Fixed-Point] gcc expand & insn for the comparisons

Jean-Paul Mari djipi.mari@gmail.com
Fri Oct 17 06:01:51 GMT 2025


Hi,

Thanks for the feedback. There is also an old gcc wiki with information on the fixed-point integration.
https://gcc.gnu.org/wiki/FixedPointArithmetic

gcc has also a list of Arithmetic, Comparison, Conversion functions to handle the fixed-point with the norm _Fract and _Accum with variations (short, unsigned, etc.) & _Sat.
I would like to avoid the need to adapt C source codes, to let gcc handling the fixed-point; either to create the necessary subroutines or try to set the equivalent with expand & insn.

I have also found an additional issue with the m68k fixed-point internal, need to dig it before to add this in the gcc bugzillia.

________________________________
From: Segher Boessenkool <segher@kernel.crashing.org>
Sent: Thursday, October 16, 2025 14:08
To: Georg-Johann Lay <avr@gjlay.de>
Cc: Jean-Paul Mari <djipi.mari@gmail.com>; gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: [M68K][Fixed-Point] gcc expand & insn for the comparisons

Hi!

On Thu, Oct 16, 2025 at 07:01:43PM +0200, Georg-Johann Lay via Gcc-help wrote:
> Am 11.10.25 um 05:09 schrieb Jean-Paul Mari via Gcc-help:
> > I have followed the Stefan's code sample; modified the m68k.md using the mode iterators to add the fixed-point for the additions, subtractions and negations but I'm stuck on the comparisons. I think I need to handle the cc register, but I do not understand yet how to use it.
> >
> > Thanks in advance for your help and guidance.
>
> I don't know nothing about m68k, but wouldn't fixed-point comparison
> take the same route like comparing (un)signed integers of the same
> size?  Moving the decimal point is just a multiplication by a
> positive constant, and that doesn't change any of the <, <= etc.
> relations.  So a good point to start is the cbranch<mode>4 patterns
> for the modes.

Fixed point comparisons might want their own CCmode, depending on what
the machine does and what the compiler does internally for that.  But it
might alse be that plain CCmode works fine for you?

What hardware flag registers are set by fixed-point compares, how does
that compare to integer comparison insns, etc.

> What I also don't know is how gcc behaves when no fixed-point
> compare patterns are provided; the reasonable default behavior would
> be to just emit respective integer comparisons.  Though some of the
> fixed-point parts in the middle-end received less attention than
> more common types did.

There is a fixed_compare function (in fixed-value.cc) that probably is
called in such cases?

If your "fixed" values are just scaled integer values in some way, you
can just do an integer comparison and that will be just what you need.
The big twist with GCC's "fixed point" things is they can do saturation
as well, but that is not an issue here AFAICS :-)


Segher


More information about the Gcc-help mailing list