public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: HAO CHEN GUI <guihaoc@linux.ibm.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>, David <dje.gcc@gmail.com>,
	"Kewen.Lin" <linkw@linux.ibm.com>,
	Peter Bergner <bergner@linux.ibm.com>
Subject: Re: [PATCH, rs6000] Use CC for BCD operations [PR100736]
Date: Thu, 16 Jun 2022 06:24:21 -0500	[thread overview]
Message-ID: <20220616112421.GE25951@gate.crashing.org> (raw)
In-Reply-To: <887ce9bb-3a34-b880-41b1-4ac2cfb743eb@linux.ibm.com>

Hi!

On Thu, Jun 16, 2022 at 02:36:53PM +0800, HAO CHEN GUI wrote:
>   This patch uses CC instead of CCFP for all BCD operations. Thus, infinite
> math flag has no impact on BCD operations. To support BCD overflow and
> invalid coding, ordered and unordered are added into CC mode.

This is wrong.  Unordered is an FP concept.  What the BCD insns do is
write to bit 3 in a CR field, which for FP comparisons is the
"unordered" comparison result (FP comparisons result in one of four
options: lt, gt, eq, or un).  For integer comparisons there are only
three possible comparison results (lt, gt, and eq), and bit 3 is set to
a copy of XER[SO], the "summary overflow" bit.

The BCD insns have the one-out-of-three comparison result as well, and
they set bit 3 if overflow happened.  There is the extra gotcha that it
sets the four condition field bits to 0001 if there is an invalidly
coded input, but we can ignore that: it is not supposed to happen.

There is no normal way to get at bit 3 of a CR field.  We can use some
unspec though, which is total cheating but it does work, and it is
safe, albeit sometimes suboptimal.

> With CC,
> "ge" and "le" are converted to reverse comparison. So the invalid coding
> needs to be tested separately.

Bit 3 has no meaning in integer comparisons, in GCC, it is not modeled.
We handle this with some unspec usually.  We need to for vector insns
that set a CR field for example: they can set more than one bit to 1, or
all bits to 0, neither of which is valid in any MODE_CC we have.

We should add proper CC modes for all the ways that instructions can set
the CR field bits.  But this is much less trivial than it may seem, so
I'd like the PR to be fixed in a simple way first (a way that can be
backported, too!)

> 	* config/rs6000/altivec.md (bcd<bcd_add_sub>_<mode>): Replace CCFP with
> 	CC

Sentences end in a full stop.  I'd say
	....................................................: Replace CCFP
	with CC.
so that it doesn't look as silly / strange :-)

> +  rtx cr6 = gen_rtx_REG (CCmode, CR6_REGNO);
> +  rtx condition_rtx = gen_rtx_<CODE> (SImode, cr6, const0_rtx);
> +  rtx_code cond_code = GET_CODE (condition_rtx);

That GET_CODE always would return <CODE>, fwiw.

You shouldn't need anything like this, bcdinvalid will work just fine if
written as bcdadd_ov (with vector of 0 as the second op)?


Segher

  reply	other threads:[~2022-06-16 11:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-16  6:36 HAO CHEN GUI
2022-06-16 11:24 ` Segher Boessenkool [this message]
2022-06-17  8:19   ` HAO CHEN GUI
2022-06-17 18:08     ` Segher Boessenkool

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=20220616112421.GE25951@gate.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=bergner@linux.ibm.com \
    --cc=dje.gcc@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=guihaoc@linux.ibm.com \
    --cc=linkw@linux.ibm.com \
    /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).