Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jvXXh-0003XJ-1d for mharc-qemu-riscv@gnu.org; Tue, 14 Jul 2020 22:53:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jvXXe-0003WC-FF; Tue, 14 Jul 2020 22:53:06 -0400 Received: from smtp2200-217.mail.aliyun.com ([121.197.200.217]:33097) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jvXXZ-0001zp-TL; Tue, 14 Jul 2020 22:53:06 -0400 X-Alimail-AntiSpam: AC=CONTINUE; BC=0.07516912|-1; CH=green; DM=|CONTINUE|false|; DS=CONTINUE|ham_regular_dialog|0.0747618-0.0105898-0.914648; FP=0|0|0|0|0|-1|-1|-1; HT=e02c03306; MF=zhiwei_liu@c-sky.com; NM=1; PH=DS; RN=8; RT=8; SR=0; TI=SMTPD_---.I1rnTxH_1594781569; Received: from 30.225.208.24(mailfrom:zhiwei_liu@c-sky.com fp:SMTPD_---.I1rnTxH_1594781569) by smtp.aliyun-inc.com(10.147.41.178); Wed, 15 Jul 2020 10:52:49 +0800 Subject: Re: [RFC 05/65] target/riscv: remove vsll.vi, vsrl.vi, vsra.vi insns from using gvec To: Frank Chang , Richard Henderson Cc: "qemu-devel@nongnu.org Developers" , "open list:RISC-V" , Palmer Dabbelt , Alistair Francis , Sagar Karandikar , Bastian Koppelmann References: <20200710104920.13550-1-frank.chang@sifive.com> <20200710104920.13550-6-frank.chang@sifive.com> <452e8bc7-4622-77c2-ec81-9aa6f25705fc@linaro.org> <0ccc7311-02f4-821f-6272-73ab600a8cda@linaro.org> From: LIU Zhiwei Message-ID: <5e56bedb-b404-19f9-4dbf-dfd675aee383@c-sky.com> Date: Wed, 15 Jul 2020 10:52:49 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------8C543CA8B571EB653508EBBC" Content-Language: en-US Received-SPF: none client-ip=121.197.200.217; envelope-from=zhiwei_liu@c-sky.com; helo=smtp2200-217.mail.aliyun.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/14 22:52:51 X-ACL-Warn: Detected OS = Linux 3.x [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, HTML_MESSAGE=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, UNPARSEABLE_RELAY=0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-riscv@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jul 2020 02:53:06 -0000 This is a multi-part message in MIME format. --------------8C543CA8B571EB653508EBBC Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 2020/7/14 21:59, Frank Chang wrote: > On Tue, Jul 14, 2020 at 9:21 PM Richard Henderson > > > wrote: > > On 7/13/20 7:59 PM, Frank Chang wrote: > > The latest spec specified: > > > > Only the low *lg2(SEW) bits* are read to obtain the shift amount > from a > > *register value*. > > The *immediate* is treated as an *unsigned shift amount*, with a > *maximum shift > > amount of 31*. > > Which, I hope you will agree is underspecified, and should be > reported as a bug > in the manual. > > > Yes, you're correct. > I found out I missed the MASK part in GEN_VEXT_SHIFT_VV() macro, > which this macro is shared between OPIVV and OPIVI format of instructions. > So the same masking methodology should be applied to shift amounts > coming from both register and immediate value. > Spike also does something like: > /vs2 >> (zimm5 & (sew - 1) & 0x1f);/ for SEW = 8. > > I think spec is kind of misleading to the reader by the way it expresses. > > > > Looks like the shift amount in the immediate value is not > relevant with SEW > > setting. > > How can it not be?  It is when the value comes from a register... > > > If so, is it better to just use do_opivi_gvec() and implement > the logic by our > > own rather than using gvec IR? > > No, it is not.  What is the logic you would apply on your own?  > There should be > a right answer. > > > I was talking about just calling GEN_OPIVI_TRANS() to generate the > helper functions > defined in vector_helper.c as what I'm doing in the original patch. > But as long as the immediate value should also apply *lg2(SEW) bits* > truncating, > I think I should update GEN_OPIVI_GVEC_TRANS() to utilize gvec IR. > > > If the answer is that out-of-range shift produces zero, which some > architectures use, then you can look at the immediate value, see > that you must > supply zero, and then fill the vector with zeros from translate.  > You need not > call a helper to perform N shifts when you know the result a-priori. > > If the answer is that shift values are truncated, which riscv uses > *everywhere > else*, then you should truncate the immediate value during translate. > > > I think vsll.vi , vsrl.vi and vsra.vi > truncate the out-of-range shift as other riscv > instructions. > I will double confirm that, thanks for the advice. > Perhaps the reason is that the assembler can't identify if an imm is legal according to log(SEW), because the assembler can't get the SEW. To make more compliance with assembler directly users'  intuition, just let the imm encoding to insn as itself(truncate to 31) and work as itself. Zhiwei > Frank Chang > > > > r~ > --------------8C543CA8B571EB653508EBBC Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

On 2020/7/14 21:59, Frank Chang wrote:
On Tue, Jul 14, 2020 at 9:21 PM Richard Henderson <richard.henderson@linaro.org> wrote:
On 7/13/20 7:59 PM, Frank Chang wrote:
> The latest spec specified:
>
> Only the low *lg2(SEW) bits* are read to obtain the shift amount from a
> *register value*.
> The *immediate* is treated as an *unsigned shift amount*, with a *maximum shift
> amount of 31*.

Which, I hope you will agree is underspecified, and should be reported as a bug
in the manual.

Yes, you're correct.
I found out I missed the MASK part in GEN_VEXT_SHIFT_VV() macro,
which this macro is shared between OPIVV and OPIVI format of instructions.
So the same masking methodology should be applied to shift amounts coming from both register and immediate value.
Spike also does something like:
vs2 >> (zimm5 & (sew - 1) & 0x1f); for SEW = 8.

I think spec is kind of misleading to the reader by the way it expresses.
 

> Looks like the shift amount in the immediate value is not relevant with SEW
> setting.

How can it not be?  It is when the value comes from a register...

> If so, is it better to just use do_opivi_gvec() and implement the logic by our
> own rather than using gvec IR?

No, it is not.  What is the logic you would apply on your own?  There should be
a right answer.

I was talking about just calling GEN_OPIVI_TRANS() to generate the helper functions
defined in vector_helper.c as what I'm doing in the original patch.
But as long as the immediate value should also apply *lg2(SEW) bits* truncating,
I think I should update GEN_OPIVI_GVEC_TRANS() to utilize gvec IR.
 

If the answer is that out-of-range shift produces zero, which some
architectures use, then you can look at the immediate value, see that you must
supply zero, and then fill the vector with zeros from translate.  You need not
call a helper to perform N shifts when you know the result a-priori.

If the answer is that shift values are truncated, which riscv uses *everywhere
else*, then you should truncate the immediate value during translate.

I think vsll.vi, vsrl.vi and vsra.vi truncate the out-of-range shift as other riscv instructions.
I will double confirm that, thanks for the advice.

Perhaps the reason is that the assembler can't identify if an imm is legal according to log(SEW),
because the assembler can't get the SEW.

To make more compliance with assembler directly users'  intuition, just let the imm encoding to insn as itself(truncate to 31)
and work as itself.

Zhiwei
Frank Chang
 


r~

--------------8C543CA8B571EB653508EBBC--