"Radu Hobincu" <radu.hobi...@arh.pub.ro> writes:

> I have another, quick question: I have dedicated logical instructions in
> my RISC machine (lt - less than, gt - greater than, ult - unsigned less
> than, etc.). I'm also working on adding instructions for logical OR, AND,
> NOT, XOR. While reading GCC internals, I've stumbled on this:
>
> "Except when they appear in the condition operand of a COND_EXPR, logical
> ‘and’ and ‘or’ operators are simplified as follows: a = b && c becomes
> T1 = (bool)b;
> if (T1)
>   T1 = (bool)c;
> a = T1;"
>
> I really, really don't want this. Is there any way I can define the
> instructions in the .md file so the compiler generates code for computing
> a boolean expression without using branches (using these dedicated insns)?

That is the only correct way to implement && and || in C, C++, and other
similar languages.  The question you should be asking is whether gcc
will be able to put simple cases without side effects back together
again.  The answer is that, yes, it should be able to do that.

You should not worry about this level of things when it comes to writing
your backend port.  Language level details like this are handled by the
frontend, not the backend.  When your port is working, come back to this
and make sure that you get the kind of code you want.

Ian

Reply via email to