public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Comparison operations in machine description (-1 vs +1)
@ 2019-11-12 18:29 m
  2019-11-12 18:54 ` Jeff Law
  0 siblings, 1 reply; 3+ messages in thread
From: m @ 2019-11-12 18:29 UTC (permalink / raw)
  To: gcc

Hello gcc developers!

I am working on a new back end for my MRISC32 ISA [1], and I'm still very
new to gcc internals. I suspect that I will have more questions further
down the road, but let's start with this topic...

The MRISC32 ISA has instructions for setting a register based on the
outcome of a comparison. For instance:

   slt s1, s2, s3

...which is equal to (in C):

   int s1 = s2 < s3 ? -1 : 0;

Now, these compare instructions set the target register value to -1 (all
bits set to 1), rather than +1 (only LSB set to 1), which is not compatible
with the "lt", "eq" etc operators in gcc (from what I can see). This forces
me to add an extra "and" operation to mask out only the LSB of the result
when implementing the compare operations.

For instance:

(define_insn "*slt"
   [(set (match_operand:SI 0 "register_operand" "=r")
         (lt:SI (match_operand:SI 1 "register_operand" "r")
                (match_operand:SI 2 "register_operand" "r")))]
   ""
   "slt\t%0, %1, %2\;and\t%0, %0, #1")

 From a functional point of view, it should not be necessary to do that mask
operation until the value "1" or "0" is actually needed for an arithmetic
operation (e.g. as is the case in the default implementation of adddi3).
Logical operations (and, or, xor etc) and conditional branches can use the
-1 just as well as the +1.

Question: Is there any way that I can avoid doing the extra "and" operation
in every instantiation of slt? For instance are there other insn:s that I
can define that gcc will recognize and use instead, or a machine
configuration that I can control to get a different behavior?

Best regards,

   Marcus


[1] 
https://github.com/mbitsnbites/gcc-mrisc32/tree/mbitsnbites/mrisc32/gcc/config/mrisc32

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

* Re: Comparison operations in machine description (-1 vs +1)
  2019-11-12 18:29 Comparison operations in machine description (-1 vs +1) m
@ 2019-11-12 18:54 ` Jeff Law
  2019-11-12 20:36   ` m
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff Law @ 2019-11-12 18:54 UTC (permalink / raw)
  To: m, gcc

On 11/12/19 11:29 AM, m wrote:
> Hello gcc developers!
> 
> I am working on a new back end for my MRISC32 ISA [1], and I'm still very
> new to gcc internals. I suspect that I will have more questions further
> down the road, but let's start with this topic...
> 
> The MRISC32 ISA has instructions for setting a register based on the
> outcome of a comparison. For instance:
> 
>   slt s1, s2, s3
> 
> ...which is equal to (in C):
> 
>   int s1 = s2 < s3 ? -1 : 0;
Look at STORE_FLAG_VALUE.  m68k for example works like this.

jeff

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

* Re: Comparison operations in machine description (-1 vs +1)
  2019-11-12 18:54 ` Jeff Law
@ 2019-11-12 20:36   ` m
  0 siblings, 0 replies; 3+ messages in thread
From: m @ 2019-11-12 20:36 UTC (permalink / raw)
  To: Jeff Law, gcc

Den 2019-11-12 kl. 19:54, skrev Jeff Law:
> On 11/12/19 11:29 AM, m wrote:
>> Hello gcc developers!
>>
>> I am working on a new back end for my MRISC32 ISA [1], and I'm still very
>> new to gcc internals. I suspect that I will have more questions further
>> down the road, but let's start with this topic...
>>
>> The MRISC32 ISA has instructions for setting a register based on the
>> outcome of a comparison. For instance:
>>
>>    slt s1, s2, s3
>>
>> ...which is equal to (in C):
>>
>>    int s1 = s2 < s3 ? -1 : 0;
> Look at STORE_FLAG_VALUE.  m68k for example works like this.
>
> jeff
>

Thanks! That did the trick!

/Marcus

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

end of thread, other threads:[~2019-11-12 20:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-12 18:29 Comparison operations in machine description (-1 vs +1) m
2019-11-12 18:54 ` Jeff Law
2019-11-12 20:36   ` m

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