On Mon, Oct 26, 2020 at 8:10 PM Qing Zhao <qing.z...@oracle.com> wrote: > > > > > On Oct 26, 2020, at 1:42 PM, Uros Bizjak <ubiz...@gmail.com> wrote: > > > > On Mon, Oct 26, 2020 at 6:30 PM Qing Zhao <qing.z...@oracle.com> wrote: > >> > >> > >> The following is the current change in i386.c, could you check whether the > >> logic is good? > > > > x87 handling looks good to me. > > > > One remaining question: If the function uses MMX regs (either > > internally or as an argument register), but exits in x87 mode, does > > your logic clear the x87 stack? > > Yes but not completely yes. > > FIRST, As following: > > /* Then, decide which mode (MMX mode or x87 mode) the function exit with. > In order to decide whether we need to clear the MMX registers or the > stack registers. */ > bool exit_with_mmx_mode = false; > > exit_with_mmx_mode = ((GET_CODE (crtl->return_rtx) == REG) > && (MMX_REG_P (crtl->return_rtx))); > > /* then, let's see whether we can zero all st registers togeter. */ > if (!exit_with_mmx_mode) > st_zeroed = zero_all_st_registers (need_zeroed_hardregs); > > > We first check whether this routine exit with mmx mode, if Not then it’s X87 > mode > (at exit, “EMMS” should already been called per ABI), then > The st/mm registers will be cleared as x87 stack registers. > > However, within the routine “zero_all_st_registers”: > > static bool > zero_all_st_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)) > { > num_of_st++; > break; > } > > if (num_of_st == 0) > return false; > > > In the above, I currently only check whether any “Stack” registers need to be > zeroed or not. > But looks like we should also check any “MMX” register need to be zeroed or > not too. If there is any > “MMX” register need to be zeroed, we still need to clear the whole X87 stack?
I think so, but I have to check the details > BTW, is it convenient for you to provide me 3 small testing cases for the > following situation: > > 1. Return with MMX register; > 2. Return with x87 stack register; > 3. Return with 2 x87 stack register (i.e the complex value). > > Then it will be much easy for me to verify my implementation is good or not > at my side. --cut here-- typedef int __v2si __attribute__ ((vector_size (8))); __v2si ret_mmx (void) { return (__v2si) { 123, 345 }; } long double ret_x87 (void) { return 1.1L; } _Complex long double ret_x87_cplx (void) { return 1.1L + 1.2iL; } --cut here-- Please compile this with "-m32 -mmmx". ret_mmx returns value in MMX register. ret_x87 returns value in x87 register. ret_x87_cplx returns value in memory. "-m64" ret_mmx returns value in XMM register. ret_x87 returns value in x87 register. ret_x87_cplx returns value in two x87 registers. Uros.