public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: "Cui, Lili" <lili.cui@intel.com>
Cc: "Lu, Hongjiu" <hongjiu.lu@intel.com>,
	"binutils@sourceware.org" <binutils@sourceware.org>
Subject: Re: [PATCH V2 3/8] Support APX GPR32 with extend evex prefix
Date: Tue, 14 Nov 2023 11:29:32 +0100	[thread overview]
Message-ID: <4abc12f2-9508-d769-e42f-296102ad1861@suse.com> (raw)
In-Reply-To: <SJ0PR11MB56000F5EAAF5F296E6918F419EB2A@SJ0PR11MB5600.namprd11.prod.outlook.com>

On 14.11.2023 04:12, Cui, Lili wrote:
>> On 13.11.2023 06:53, Cui, Lili wrote:
>>>>> @@ -5624,19 +5653,42 @@ md_assemble (char *line) [...]
>>>>> -      if (i.tm.opcode_modifier.vex)
>>>>> +      if (is_any_apx_evex_encoding ())
>>>>> +	{
>>>>> +	  if (i.tm.opcode_space == SPACE_EVEXMAP4 &&
>>>> (i.prefix[DATA_PREFIX] != 0))
>>>>> +	    {
>>>>> +	      i.tm.opcode_modifier.opcodeprefix = PREFIX_0X66;
>>>>
>>>> Perhaps better assert that no other embedded prefix was already
>>>> recorded here?
>>>
>>> Added the code as below, I added as_bad instead of assert, I think this is a
>> input error and not a gas internal error, right?  Besides REX_PREFIX?
>>>
>>>       if (check_if_any_vex_is_evex_apx_encoding ())
>>>         {
>>>           if (i.tm.opcode_space == SPACE_EVEXMAP4 &&
>> (i.prefix[DATA_PREFIX] != 0))
>>>             {
>>>
>>>               i.tm.opcode_modifier.opcodeprefix = PREFIX_0X66;
>>>               i.prefix[DATA_PREFIX] = 0;
>>>
>>>               /*  Prefixes other than the rex prefix cannot be used with the data
>> prefix.  */
>>>               const unsigned char *p = i.prefix;
>>>
>>>               for (j = 0; j < ARRAY_SIZE (i.prefix); ++j, ++p)
>>>                 {
>>>                   if (!*p)
>>>                     continue;
>>>
>>>                   switch (j)
>>>                     {
>>>                     case DATA_PREFIX:
>>>                     case REX_PREFIX:
>>>                       break;
>>>                     default:
>>>                       as_bad (_("unexpecting prefix %x together with DATA "
>>>                                 "prefix in front of evex-promoted apx "
>>>                                 "instruction "), *p);
>>>                       return;
>>>                     }
>>>                 }
>>>             }
>>>
>>>           build_apx_evex_prefix ();
>>>       }
>>
>> We already have code refusing most legacy prefixes when ahead of VEX/EVEX,
>> don't we? I'd expect that code to take care of bogus DATA prefixes here as
>> well. Possibly the conversion needs dealing with differently if here we can't
>> tell a user-supplied i.prefix[DATA_PREFIX] from one internally derived from
>> operands which were supplied? E.g. by not having
>> process_suffix() invoke add_prefix() in this particular case at all, but instead
>> modify i.tm accordingly?
>>
> 
> Done.
> 
> -         if (!add_prefix (prefix))
> -           return 0;
> +         /* The DATA PREFIX of EVEX promoted from legacy APX instructions
> +            needs to be adjusted.  */
> +         if (i.tm.opcode_space == SPACE_EVEXMAP4)
> +           i.tm.opcode_modifier.opcodeprefix = PREFIX_0X66;
> +         else
> +           if (!add_prefix (prefix))
> +             return 0;

Except that you want "else" and "if" on the same line, please.

>>>>> @@ -7043,7 +7096,7 @@ VEX_check_encoding (const insn_template *t)
>>>>> static int  check_EgprOperands (const insn_template *t)  {
>>>>> -  if (t->opcode_modifier.noegpr)
>>>>> +  if (t->opcode_modifier.noegpr && !need_evex_encoding())
>>>>>      {
>>>>>        for (unsigned int op = 0; op < i.operands; op++)
>>>>>  	{
>>>>
>>>> What is this change about?
>>>>
>>>
>>> After merging vex and evex, evex exits here early and all evex supports egpr.
>>
>> Yet / hence no EVEX template should ever have NoEgpr set. IOW I still don't
>> follow why this change would be needed.
>>
> 
> After merging VEX and EVEX templates, they shared NoEgpr ==1 , and if !EVEX is not added, It will check for NoEgpr for EVEX instructions, but EVEX supports egpr.  That's why I added the code.
> 
> ldtilecfg, 0x49/0, AMX_TILE&(AMX_TILE|APX_F), Modrm|Vex128|EVex128|Space0F38|VexW0|NoSuf|NoEgpr, { Unspecified|BaseIndex }
> 
> When merging VEX and EVEX templates, it means that VEX +Egpr (illegal) has a corresponding EVEX + Egpr, and we don't need to check whether VEX is illegal (just set NoEgpr =0 ). Then we can remove "!need_evex_encoding()" and the following comments code. IOW merging templates means we cannot differentiate their NoEgpr.

Well, such merged templates necessarily allow Egpr, so they must not have NoEgpr.
For them, use of an extended register simply excludes use of the VEX form of the
insn. This may or may not be what the last paragraph of your reply is intended to
be telling me.

>>>>> @@ -14252,6 +14306,9 @@ static bool check_register (const reg_entry
>>>>> *r)
>>>>>
>>>>>    if (r->reg_flags & RegRex2)
>>>>>      {
>>>>> +      if (is_evex_encoding (current_templates->start))
>>>>> +	i.vec_encoding = vex_encoding_evex;
>>>>
>>>> What if the APX template isn't first in the group?
>>>>
>>>
>>> If apx_f is not supported, it will return false, just after this code. Oh, better
>> to move it to the back. Done.
>>>
>>>   if (r->reg_flags & RegRex2)
>>>     {
>>>       if (current_templates->start->opcode_modifier.evex)
>>>         i.vec_encoding = vex_encoding_evex;
>>>
>>>       if (!cpu_arch_flags.bitfield.cpuapx_f
>>>           || flag_code != CODE_64BIT)
>>>         return false;
>>>     }
>>
>> Hmm, as before there's a use of current_templates here, which I'm afraid isn't
>> appropriate. Whether a register is legitimate to use depends on only the
>> present mode we're assembling in (flag_code + cpu_arch_flags, plus a few
>> other globals for certain special cases). There may not be dependencies on
>> the insn we're processing. Or if at all (yet even that would need a pretty good
>> justification), then only on the collective set of all templates in the chosen
>> template group.
> 
> The code here is need by the upper comments.

I'm afraid I don't understand your reply here. It certainly doesn't address my
comment. Why would setting i.vec_encoding depend on the first template in a
group? I indicated earlier that using vex_encoding_evex may not be feasible
here, because you don't mean to enforce EVEX encoding. You only want to record
the fact that an encoding needs using which is eGPR-capable (i.e. either one
with NoEgpr clear, or an EVEX one). Hence why I further suggested to possibly
introduce vex_encoding_egpr. (The "vex" in the names and the "vec" in the
field name are increasingly misleading, but we can address that later on.)

Jan

  reply	other threads:[~2023-11-14 10:29 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-03 16:50 Cui, Lili
2023-11-06 17:07 ` Jan Beulich
2023-11-13  5:53   ` Cui, Lili
2023-11-13  8:34     ` Jan Beulich
2023-11-14  3:12       ` Cui, Lili
2023-11-14 10:29         ` Jan Beulich [this message]
2023-11-15  8:39           ` Cui, Lili
2023-11-07 13:29 ` Jan Beulich
2023-11-09  8:38   ` Cui, Lili
2023-11-09 11:07     ` Jan Beulich
2023-11-09 11:12     ` Jan Beulich
2023-11-07 14:53 ` Jan Beulich
2023-11-09 12:31   ` Cui, Lili
2023-11-09 13:05     ` Jan Beulich
2023-11-09 14:57       ` Cui, Lili
2023-11-09 15:39         ` Jan Beulich
2023-11-14  7:42   ` Cui, Lili
2023-11-14 10:40     ` Jan Beulich
2023-11-14 14:46       ` Cui, Lili
2023-11-15  6:03   ` Cui, Lili
2023-11-15  9:11     ` Jan Beulich
2023-11-15 11:43       ` Cui, Lili
2023-11-16 13:57         ` Jan Beulich
2023-11-16 15:10           ` Cui, Lili
2023-11-16 15:15             ` Jan Beulich
2023-11-16 16:12           ` Cui, Lili

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=4abc12f2-9508-d769-e42f-296102ad1861@suse.com \
    --to=jbeulich@suse.com \
    --cc=binutils@sourceware.org \
    --cc=hongjiu.lu@intel.com \
    --cc=lili.cui@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).