> On Oct 26, 2020, at 11:13 AM, Uros Bizjak <ubiz...@gmail.com> wrote:
>
> On Mon, Oct 26, 2020 at 3:45 PM Qing Zhao <qing.z...@oracle.com
> <mailto:qing.z...@oracle.com>> wrote:
>>
>>
>> +/* Generate insns to zero all st/mm registers together.
>> + Return true when zeroing instructions are generated.
>> + Assume the number of st registers that are zeroed is num_of_st,
>> + we will emit the following sequence to zero them together:
>> + fldz; \
>> + fldz; \
>> + ...
>> + fldz; \
>> + fstp %%st(0); \
>> + fstp %%st(0); \
>> + ...
>> + fstp %%st(0);
>> + i.e., num_of_st fldz followed by num_of_st fstp to clear the stack
>> + mark stack slots empty. */
>> +
>> +static bool
>> +zero_all_st_mm_registers (HARD_REG_SET need_zeroed_hardregs)
>> +{
>> + unsigned int num_of_st = 0;
>> + for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
>> + if (STACK_REGNO_P (regno)
>> + && TEST_HARD_REG_BIT (need_zeroed_hardregs, regno)
>> + /* When the corresponding mm register also need to be cleared too.
>> */
>> + && TEST_HARD_REG_BIT (need_zeroed_hardregs,
>> + (regno - FIRST_STACK_REG + FIRST_MMX_REG)))
>> + num_of_st++;
>>
>>
>> I don't think the above logic is correct. It should go like this:
>>
>> - If the function is returning an MMX register,
>>
>>
>> How to check on this? Is the following correct?
>>
>> If (GET_CODE(crtl->return_rtx) == REG
>> && (MMX_REG_P (REGNO (crtl->return_rtx)))
>
> Yes, but please use
>
> if (MMX_REG_P (crtl->return_rtx))
Okay.
>
>>
>> The function is returning an MMX register.
>>
>>
>> then the function
>> exits in MMX mode, and MMX registers should be cleared in the same way
>> as XMM registers.
>>
>>
>> When clearing XMM registers, we used V4SFmode, what’s the mode we should use
>> to clearing
>> mmx registers?
>
> It doesn't matter that much, any 8byte vector mode will do (including
> DImode). Let's use V4HImode.
Okay.
>
>> Otherwise the ABI specifies that the function exits
>> in x87 mode and x87 stack should be cleared (but see below).
>>
>> - There is no direct mapping of stack registers to hard register
>> numbers. If a stack register is used, we don't know where in the stack
>> the value remains. So, if _any_ stack register is touched, the whole
>> stack should be cleared (value, returning in x87 stack register should
>> obviously be excluded).
>>
>>
>> Then, how to exclude the x87 stack register that returns the function return
>> value when we need to
>> Clear the whole stack?
>> I am a little confused here? Could you explain a little more details?
>
> x87 returns in the top (two for complex values) register, so simply
> load 7 zeros (and 7 corresponding pops). This will preserve the return
> value but clear the whole remaining stack.
I see.
>
>> - There is no x87 argument register. 32bit targets use MMX0-3 argument
>> registers and return value in the XMM register. Please also note that
>> complex values take two stack slots in x87 stack.
>>
>>
>> You mean the complex return value will be returned in two x87 registers?
>
> Yes, please see ix86_class_max_nregs. Please note that in case of
> complex return value, only 6 zeros should be loaded to avoid
> clobbering the complex return value.
Okay, I see.
thanks.
Qing
>
> Uros.