public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* RISC-V: Replace unspec with bitreverse in riscv_brev8_<mode> insn
@ 2023-07-26  7:54 Jivan Hakobyan
  2023-07-26  8:21 ` Kito Cheng
  0 siblings, 1 reply; 3+ messages in thread
From: Jivan Hakobyan @ 2023-07-26  7:54 UTC (permalink / raw)
  To: gcc-patches


[-- Attachment #1.1: Type: text/plain, Size: 252 bytes --]

This small patch replaces unspec opcode with bitreverse in
riscv_brev8_<mode> insn.

gcc/ChangeLog:
        * config/riscv/crypto.md (UNSPEC_BREV8): Remov.
        (riscv_brev8_<mode>): Use bitreverse opcode.


-- 
With the best regards
Jivan Hakobyan

[-- Attachment #2: remove_unspec_brev8.diff --]
[-- Type: text/x-patch, Size: 671 bytes --]

diff --git a/gcc/config/riscv/crypto.md b/gcc/config/riscv/crypto.md
index e4b7f0190df..d40e108b10d 100644
--- a/gcc/config/riscv/crypto.md
+++ b/gcc/config/riscv/crypto.md
@@ -19,7 +19,6 @@
 
 (define_c_enum "unspec" [
     ;; Zbkb unspecs
-    UNSPEC_BREV8
     UNSPEC_ZIP
     UNSPEC_UNZIP
     UNSPEC_PACK
@@ -73,8 +72,7 @@
 ;; ZBKB extension
 (define_insn "riscv_brev8_<mode>"
   [(set (match_operand:X 0 "register_operand" "=r")
-        (unspec:X [(match_operand:X 1 "register_operand" "r")]
-                  UNSPEC_BREV8))]
+        (bitreverse:X (match_operand:X 1 "register_operand" "r")))]
   "TARGET_ZBKB"
   "brev8\t%0,%1"
   [(set_attr "type" "crypto")])

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

* Re: RISC-V: Replace unspec with bitreverse in riscv_brev8_<mode> insn
  2023-07-26  7:54 RISC-V: Replace unspec with bitreverse in riscv_brev8_<mode> insn Jivan Hakobyan
@ 2023-07-26  8:21 ` Kito Cheng
  2023-07-26 16:23   ` Jeff Law
  0 siblings, 1 reply; 3+ messages in thread
From: Kito Cheng @ 2023-07-26  8:21 UTC (permalink / raw)
  To: Jivan Hakobyan; +Cc: gcc-patches

My understanding is the semantic is slightly different, brev8 is only
the bit reverse within each byte, but bitreverse means did bit reverse
for the whole content of the mode, e.g. riscv_brev8_si will bit
reserved within 32 bit.

Using RV32 as example:
UNSPEC_BREV8:
rd[0...7]  = rs[7...0]
rd[8...15]  = rs[15...8]
rd[16...23]  = rs[23...16]
rd[16...23]  = rs[31...24]

bitreverse:
rd[0...31] = rs[31...0]

On Wed, Jul 26, 2023 at 3:55 PM Jivan Hakobyan via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> This small patch replaces unspec opcode with bitreverse in
> riscv_brev8_<mode> insn.
>
> gcc/ChangeLog:
>         * config/riscv/crypto.md (UNSPEC_BREV8): Remov.
>         (riscv_brev8_<mode>): Use bitreverse opcode.
>
>
> --
> With the best regards
> Jivan Hakobyan

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

* Re: RISC-V: Replace unspec with bitreverse in riscv_brev8_<mode> insn
  2023-07-26  8:21 ` Kito Cheng
@ 2023-07-26 16:23   ` Jeff Law
  0 siblings, 0 replies; 3+ messages in thread
From: Jeff Law @ 2023-07-26 16:23 UTC (permalink / raw)
  To: Kito Cheng, Jivan Hakobyan; +Cc: gcc-patches



On 7/26/23 02:21, Kito Cheng via Gcc-patches wrote:
> My understanding is the semantic is slightly different, brev8 is only
> the bit reverse within each byte, but bitreverse means did bit reverse
> for the whole content of the mode, e.g. riscv_brev8_si will bit
> reserved within 32 bit.
> 
> Using RV32 as example:
> UNSPEC_BREV8:
> rd[0...7]  = rs[7...0]
> rd[8...15]  = rs[15...8]
> rd[16...23]  = rs[23...16]
> rd[16...23]  = rs[31...24]
> 
> bitreverse:
> rd[0...31] = rs[31...0]
Yea, I think you're right Kito.  Goof on our side.

Jivan, I think this explains why it's not working for all of Mariam's 
cases -- odds are the cases where it is working are for the reversed crc8.

Let's drop this since it doesn't match the semantics of GCC's bitreverse.

Mariam's call on whether or not to utilize brev8 for the crc8 cases 
where it's likely faster than other sequences to reverse bits.

jeff

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

end of thread, other threads:[~2023-07-26 16:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-26  7:54 RISC-V: Replace unspec with bitreverse in riscv_brev8_<mode> insn Jivan Hakobyan
2023-07-26  8:21 ` Kito Cheng
2023-07-26 16:23   ` Jeff Law

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