On Tue, Sep 29, 2015 at 5:23 PM, Mike Stump <mikest...@comcast.net> wrote: > On Sep 29, 2015, at 3:40 PM, H.J. Lu <hjl.to...@gmail.com> wrote: >> How about adding a "no_caller_saved_registers" attribute? > > You can save all call clobbered registers with 3 instructions? Really? I’m > skeptical. Anyway, if you do this by turning off great swaths of registers, > then, I guess that doesn’t surprise me. I try and not turn any off in mine.
We need one instruction to save one register. > Now, if you turn off great swaths of registers, then you can’t actually make > any calls to an abi that supports those registers as call clobbered: We don't need to save and restore any registers when calling a function marked with "no_caller_saved_registers" attribute except for registers used to pass parameters. Maybe "no_caller_saved_registers" isn't a good name. >> + if (cfun->machine->is_interrupt) >> + return ((df_regs_ever_live_p (regno) >> + || (call_used_regs[regno] && cfun->machine->make_calls)) >> + && !fixed_regs[regno] >> + && !STACK_REGNO_P (regno) >> + && !MMX_REGNO_P (regno) >> + && regno != BP_REG >> + && regno != SP_REG >> + && (regno <= ST7_REG || regno >= XMM0_REG)); > > So, any calls to a function that uses any excluded register won’t work, if > that register is not fixed and is call clobbered. If you call such a > function, you _must_ save and restore all those registers. Code like: We save all changed registers as well as all caller-saved registers if we make any function call. Shouldn't it be sufficient? >> + if (cfun->machine->is_interrupt && VALID_MMX_REG_MODE (mode)) >> + { >> + error ("MMX/3Dnow instructions aren't allowed in %s service routine", >> + (cfun->machine->is_exception ? "exception" : "interrupt")); >> + return; >> + } > > Does not save your from the obligation of saving such registers, if you > support function calls inside an interrupt routine. Once you add that > support to make function calls work, then, you might as well lift this > restriction, cause it would already just work? Due to the way how MMX/x87 registers work, we don't support using MMX/x87 registers in interrupt handler. People have to write assembly codes if they have to use them. > If you really can save everything in 3 instructions, then there is no point > to trying to enhance it more on your port. 3 instructions execute so fast as > to not matter. > > Now, if you ask me how I know all this, I had to debug a failure to save 1 > register class in the prologue from large multi core instruction trace, and > that class was the second most important class for general code gen right > after the gprs. Turns out that I killed a live variable in that class from a > packet handler interrupt routine cause it failed to save/restore. After > that, I tested every register class and fixed all the issues. We include one testcase for each register class in x86, including MMX and x87, which gives an error. -- H.J.