public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "Cui, Lili" <lili.cui@intel.com>
To: "Beulich, Jan" <JBeulich@suse.com>
Cc: "Lu, Hongjiu" <hongjiu.lu@intel.com>,
	"binutils@sourceware.org" <binutils@sourceware.org>
Subject: RE: [PATCH 2/8] Support APX GPR32 with extend evex prefix
Date: Thu, 19 Oct 2023 11:58:05 +0000	[thread overview]
Message-ID: <SJ0PR11MB5600F9F98FB3FD21CA2DB2939ED4A@SJ0PR11MB5600.namprd11.prod.outlook.com> (raw)
In-Reply-To: <SJ0PR11MB560007040FAF2E8AEC4BCFF79ED5A@SJ0PR11MB5600.namprd11.prod.outlook.com>



> -----Original Message-----
> From: Cui, Lili
> Sent: Wednesday, October 18, 2023 7:31 PM
> To: Jan Beulich <jbeulich@suse.com>
> Cc: Lu, Hongjiu <hongjiu.lu@intel.com>; binutils@sourceware.org
> Subject: RE: [PATCH 2/8] Support APX GPR32 with extend evex prefix
> 
> > >> Subject: Re: [PATCH 2/8] Support APX GPR32 with extend evex prefix
> > >>
> > >> On 18.10.2023 08:31, Cui, Lili wrote:
> > >>>>>> Similary I don't think I can spot anywhere that you would check
> > >>>>>> the other bits which need to be zero in extended EVEX. Nor
> > >>>>>> Improper use of EVEX.x4 in certain pre-existing encodings (S/G
> > >>>>>> insns at least; perhaps all
> > >>>> others are okay).
> > >>>>>
> > >>>>> Sorry, I can't get you here, what are S/G insns, could you
> > >>>>> provide more
> > >>>> details here, thanks.
> > >>>>
> > >>>> S/G is scatter/gather (i.e. AVX2 and AVX512).
> > >>>>
> > >>> I think you mean EVEX.V4, scatter/gather has VSIB which needs to
> > >>> reuse this bit (EVEX.x4 is EVEX.p[10] which is fixed value 1), For
> > >>> our current code
> > >> we will reassign that bit and now I changed it to check the upper
> > >> 16 registers of GPR32 , do you think it is ok?
> > >>>
> > >>> @@ -4252,7 +4252,7 @@ build_apx_evex_prefix (void)
> > >>>    if (i.rex2 & REX_R)
> > >>>      i.vex.bytes[1] &= 0xef;
> > >>>    if (i.vex.register_specifier
> > >>> -      && register_number (i.vex.register_specifier) > 0xf)
> > >>> +      && (i.vex.register_specifier->reg_flags & RegRex2))
> > >>>      i.vex.bytes[3] &= 0xf7;
> > >>>    if (i.rex2 & REX_B)
> > >>>      i.vex.bytes[1] |= 0x08;
> > >>
> > >> First of all my comment was disassembly related; you stripped a
> > >> little too much context for this to remain visible here. And then I
> > >> think I did mean
> > >> EVEX.x4 - as you say it needs to be fixed-1 in e.g. S/G insns, and
> > >> the checking thereof is what I'm missing.
> > >>
> > > Ok ,  I will drop the encoder changes, and add an X4 check when
> > > instruction
> > has vex_vsib* type in decoder.
> >
> > You understand though that I used the S/G insns as example only. I
> > didn't do a proper check whether any others might also be affected. In
> > particular ones not allowing for memory operands might be.
> >
> OK, I'll try to add more checks, and add description for them.
> 

Added some bit checks in the decoder.

--- a/opcodes/i386-dis.c
+++ b/opcodes/i386-dis.c
@@ -11533,6 +11642,13 @@ OP_E_memory (instr_info *ins, int bytemode, int sizeflag)
                abort ();
              if (ins->vex.evex)
                {
+                 /* S/G EVEX insns require EVEX.P[10] == 1 */
+                 if (ins->rex2 & REX_X)
+                   {
+                     oappend (ins, "(bad)");
+                     return true;
+                   }
+
@@ -9003,6 +9003,9 @@ get_valid_dis386 (const struct dis386 *dp, instr_info *ins)
        case 0x4:
          vex_table_index = EVEX_MAP4;
          ins->evex_type = evex_from_legacy;
+         /* EVEX from legacy instrucions require EVEX.P[2:0] must be 0x04.  */
+         if (!((*ins->codep & 0x7) == 0x04))
+           return  &bad_opcode;
          break;
        case 0x5:
          vex_table_index = EVEX_MAP5;
@@ -9063,6 +9066,22 @@ get_valid_dis386 (const struct dis386 *dp, instr_info *ins)
        }

       ins->need_vex = 4;
+
+      /* EVEX from legacy requrie EVEX.P[17:16] must be 0, EVEX.P[23:21] must
+        be 0.
+        EVEX from evex requrie EVEX.P[17:16] must be 0. EVEX.P[23:22] must
+        be 0, EVEX.P[20] must be 0.  */
+      if (ins->evex_type == evex_from_legacy || ins->evex_type == evex_from_vex)
+       {
+         if (!((*ins->codep & 0x3) == 0)
+             || !((*ins->codep >> 6 & 0x3) == 0)
+             || (ins->evex_type == evex_from_legacy
+                 && !((*ins->codep >> 5 & 0x1) == 0))
+             || (ins->evex_type == evex_from_vex
+                 && !ins->vex.b))
+           return &bad_opcode;

Corresponding testcase

        #VSIB vpgatherqq 0x7b(%rbp,%zmm17,8),%zmm16{%k1} set EVEX.P[10] == 0(illegal value).
        .byte 0x62, 0xe2, 0xf9, 0x41, 0x91, 0x84, 0xcd, 0x7b, 0x00, 0x00, 0x00
        .byte 0xff
        #EVEX_MAP4 adox %r25d,%edx set EVEX.P[2:0] == 1 (illegal value).
        .byte 0x62, 0xdd, 0x7e, 0x08, 0x66, 0xd1
        .byte 0xff
        #EVEX_MAP4 adox %r25d,%edx set EVEX.P[17:16] == 1 (illegal value).
        .byte 0x62, 0xdc, 0x7e, 0x09, 0x66, 0xd1
        #EVEX_MAP4 adox %r25d,%edx set EVEX.P[23:21] == 1 (illegal value).
        .byte 0x62, 0xdc, 0x7e, 0x18, 0x66, 0xd1
        #EVEX from VEX enqcmd 0x123(%r31,%rax,4),%r31 EVEX.P[17:16] == 1 (illegal value).
        .byte 0x62, 0x4c, 0x7f, 0x09, 0xf8, 0xbc, 0x87, 0x23, 0x01, 0x00, 0x00
        .byte 0xff
        #EVEX from VEX enqcmd 0x123(%r31,%rax,4),%r31 EVEX.P[23:22] == 1 (illegal value).
        .byte 0x62, 0x4c, 0x7f, 0x18, 0xf8, 0xbc, 0x87, 0x23, 0x01, 0x00, 0x00

Lili.

  reply	other threads:[~2023-10-19 11:58 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-19 15:25 [PATCH 0/8] [RFC] Support Intel APX EGPR Cui, Lili
2023-09-19 15:25 ` [PATCH 1/8] Support APX GPR32 with rex2 prefix Cui, Lili
2023-09-21 15:27   ` Jan Beulich
2023-09-27 15:57     ` Cui, Lili
2023-09-21 15:51   ` Jan Beulich
2023-09-27 15:59     ` Cui, Lili
2023-09-28  8:02       ` Jan Beulich
2023-10-07  3:27         ` Cui, Lili
2023-09-19 15:25 ` [PATCH 2/8] Support APX GPR32 with extend evex prefix Cui, Lili
2023-09-22 10:12   ` Jan Beulich
2023-10-17 15:48     ` Cui, Lili
2023-10-18  6:40       ` Jan Beulich
2023-10-18 10:44         ` Cui, Lili
2023-10-18 10:50           ` Jan Beulich
2023-09-22 10:50   ` Jan Beulich
2023-10-17 15:50     ` Cui, Lili
2023-10-17 16:11       ` Jan Beulich
2023-10-18  2:02         ` Cui, Lili
2023-10-18  6:10           ` Jan Beulich
2023-09-25  6:03   ` Jan Beulich
2023-10-17 15:52     ` Cui, Lili
2023-10-17 16:12       ` Jan Beulich
2023-10-18  6:31         ` Cui, Lili
2023-10-18  6:47           ` Jan Beulich
2023-10-18  7:52             ` Cui, Lili
2023-10-18  8:21               ` Jan Beulich
2023-10-18 11:30                 ` Cui, Lili
2023-10-19 11:58                   ` Cui, Lili [this message]
2023-10-19 15:24                     ` Jan Beulich
2023-10-19 16:38                       ` Cui, Lili
2023-10-20  6:25                         ` Jan Beulich
2023-10-22 14:33                           ` Cui, Lili
2023-09-19 15:25 ` [PATCH 3/8] Add tests for " Cui, Lili
2023-09-27 13:11   ` Jan Beulich
2023-10-17 15:53     ` FW: " Cui, Lili
2023-10-17 16:19       ` Jan Beulich
2023-10-18  2:32         ` Cui, Lili
2023-10-18  6:05           ` Jan Beulich
2023-10-18  7:16             ` Cui, Lili
2023-10-18  8:05               ` Jan Beulich
2023-10-18 11:26                 ` Cui, Lili
2023-10-18 12:06                   ` Jan Beulich
2023-10-25 16:03                     ` Cui, Lili
2023-09-27 13:19   ` Jan Beulich
2023-09-19 15:25 ` [PATCH 4/8] Support APX NDD Cui, Lili
2023-09-27 14:44   ` Jan Beulich
2023-10-22 14:05     ` Cui, Lili
2023-10-23  7:12       ` Jan Beulich
2023-10-25  8:10         ` Cui, Lili
2023-10-25  8:47           ` Jan Beulich
2023-10-25 15:49             ` Cui, Lili
2023-10-25 15:59               ` Jan Beulich
2023-09-28  7:57   ` Jan Beulich
2023-10-22 14:57     ` Cui, Lili
2023-10-24 11:39     ` Cui, Lili
2023-10-24 11:58       ` Jan Beulich
2023-10-25 15:29         ` Cui, Lili
2023-09-19 15:25 ` [PATCH 5/8] Support APX NDD optimized encoding Cui, Lili
2023-09-28  9:29   ` Jan Beulich
2023-10-23  2:57     ` Hu, Lin1
2023-10-23  7:23       ` Jan Beulich
2023-10-23  7:50         ` Hu, Lin1
2023-10-23  8:15           ` Jan Beulich
2023-10-24  1:40             ` Hu, Lin1
2023-10-24  6:03               ` Jan Beulich
2023-10-24  6:08                 ` Hu, Lin1
2023-10-23  3:07     ` [PATCH-V2] " Hu, Lin1
2023-10-23  3:30     ` [PATCH 5/8] [v2] " Hu, Lin1
2023-10-23  7:26       ` Jan Beulich
2023-09-19 15:25 ` [PATCH 6/8] Support APX Push2/Pop2 Cui, Lili
2023-09-28 11:37   ` Jan Beulich
2023-10-30 15:21     ` Cui, Lili
2023-10-30 15:31       ` Jan Beulich
2023-11-20 13:05         ` Cui, Lili
2023-09-19 15:25 ` [PATCH 7/8] Support APX NF Cui, Lili
2023-09-25  6:07   ` Jan Beulich
2023-09-28 12:42   ` Jan Beulich
2023-11-02 10:15     ` Cui, Lili
2023-11-02 10:23       ` Jan Beulich
2023-11-02 10:46         ` Cui, Lili
2023-12-12  2:59           ` H.J. Lu
2023-09-19 15:25 ` [PATCH 8/8] Support APX JMPABS Cui, Lili
2023-09-28 13:11   ` Jan Beulich
2023-11-02  2:32     ` Hu, Lin1

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=SJ0PR11MB5600F9F98FB3FD21CA2DB2939ED4A@SJ0PR11MB5600.namprd11.prod.outlook.com \
    --to=lili.cui@intel.com \
    --cc=JBeulich@suse.com \
    --cc=binutils@sourceware.org \
    --cc=hongjiu.lu@intel.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).