- subi(_SP_REGNO, _SP_REGNO, stack_framesize);
- stxi(0, _SP_REGNO, _RA_REGNO);
- stxi(8, _SP_REGNO, _FP_REGNO);
- if (jit_regset_tstbit(&_jitc->function->regset, _S0))
- stxi(16, _SP_REGNO, rn(_S0));
- if (jit_regset_tstbit(&_jitc->function->regset, _S1))
- stxi(24, _SP_REGNO, rn(_S1));
- if (jit_regset_tstbit(&_jitc->function->regset, _S2))
- stxi(32, _SP_REGNO, rn(_S2));
- if (jit_regset_tstbit(&_jitc->function->regset, _S3))
- stxi(40, _SP_REGNO, rn(_S3));
- if (jit_regset_tstbit(&_jitc->function->regset, _S4))
- stxi(48, _SP_REGNO, rn(_S4));
- if (jit_regset_tstbit(&_jitc->function->regset, _S5))
- stxi(56, _SP_REGNO, rn(_S5));
- if (jit_regset_tstbit(&_jitc->function->regset, _S6))
- stxi(64, _SP_REGNO, rn(_S6));
- if (jit_regset_tstbit(&_jitc->function->regset, _S7))
- stxi(72, _SP_REGNO, rn(_S7));
- if (jit_regset_tstbit(&_jitc->function->regset, _S8))
- stxi(80, _SP_REGNO, rn(_S8));
- if (jit_regset_tstbit(&_jitc->function->regset, _FS0))
- stxi_d(88, _SP_REGNO, rn(_FS0));
- if (jit_regset_tstbit(&_jitc->function->regset, _FS1))
- stxi_d(96, _SP_REGNO, rn(_FS1));
- if (jit_regset_tstbit(&_jitc->function->regset, _FS2))
- stxi_d(104, _SP_REGNO, rn(_FS2));
- if (jit_regset_tstbit(&_jitc->function->regset, _FS3))
- stxi_d(112, _SP_REGNO, rn(_FS3));
- if (jit_regset_tstbit(&_jitc->function->regset, _FS4))
- stxi_d(120, _SP_REGNO, rn(_FS4));
- if (jit_regset_tstbit(&_jitc->function->regset, _FS5))
- stxi_d(128, _SP_REGNO, rn(_FS5));
- if (jit_regset_tstbit(&_jitc->function->regset, _FS6))
- stxi_d(136, _SP_REGNO, rn(_FS6));
- if (jit_regset_tstbit(&_jitc->function->regset, _FS7))
- stxi_d(144, _SP_REGNO, rn(_FS7));
- movr(_FP_REGNO, _SP_REGNO);
+
+ if (_jitc->function->stack)
+ _jitc->function->need_stack = 1;
+ if (!_jitc->function->need_frame && !_jitc->function->need_stack) {
+ /* check if any callee save register needs to be saved */
+ for (reg = 0; reg < _jitc->reglen; ++reg)
+ if (jit_regset_tstbit(&_jitc->function->regset, reg) &&
+ (_rvs[reg].spec & jit_class_sav)) {
+ _jitc->function->need_stack = 1;
+ break;
+ }
+ }
+
+ if (_jitc->function->need_frame || _jitc->function->need_stack)
+ subi(_SP_REGNO, _SP_REGNO, jit_framesize());
+ if (_jitc->function->need_frame) {
+ stxi(0, _SP_REGNO, _RA_REGNO);
+ stxi(8, _SP_REGNO, _FP_REGNO);
+ }
+ /* callee save registers */
+ for (reg = 0, offs = 16; reg < jit_size(iregs); reg++) {
+ if (jit_regset_tstbit(&_jitc->function->regset, iregs[reg])) {
+ stxi(offs, _SP_REGNO, rn(iregs[reg]));
+ offs += sizeof(jit_word_t);
+ }
+ }
+ for (reg = 0; reg < jit_size(fregs); reg++) {
+ if (jit_regset_tstbit(&_jitc->function->regset, fregs[reg])) {
+ stxi_d(offs, _SP_REGNO, rn(fregs[reg]));
+ offs += sizeof(jit_float64_t);
+ }
+ }
+
+ if (_jitc->function->need_frame)
+ movr(_FP_REGNO, _SP_REGNO);