+if C_LOOP
+ const CalleeSaveRegisterCount = 0
+elsif ARM or ARMv7_TRADITIONAL or ARMv7
+ const CalleeSaveRegisterCount = 7
+elsif ARM64
+ const CalleeSaveRegisterCount = 10
+elsif SH4 or X86_64 or MIPS
+ const CalleeSaveRegisterCount = 5
+elsif X86 or X86_WIN
+ const CalleeSaveRegisterCount = 3
+elsif X86_64_WIN
+ const CalleeSaveRegisterCount = 7
+end
+
+const CalleeRegisterSaveSize = CalleeSaveRegisterCount * PtrSize
+
+# VMEntryTotalFrameSize includes the space for struct VMEntryRecord and the
+# callee save registers rounded up to keep the stack aligned
+const VMEntryTotalFrameSize = (CalleeRegisterSaveSize + sizeof VMEntryRecord + StackAlignment - 1) & ~StackAlignmentMask
+
+macro pushCalleeSaves()
+ if C_LOOP
+ elsif ARM or ARMv7_TRADITIONAL
+ emit "push {r4-r10}"
+ elsif ARMv7
+ emit "push {r4-r6, r8-r11}"
+ elsif ARM64
+ emit "stp x20, x19, [sp, #-16]!"
+ emit "stp x22, x21, [sp, #-16]!"
+ emit "stp x24, x23, [sp, #-16]!"
+ emit "stp x26, x25, [sp, #-16]!"
+ emit "stp x28, x27, [sp, #-16]!"
+ elsif MIPS
+ emit "addiu $sp, $sp, -20"
+ emit "sw $20, 16($sp)"
+ emit "sw $19, 12($sp)"
+ emit "sw $18, 8($sp)"
+ emit "sw $17, 4($sp)"
+ emit "sw $16, 0($sp)"
+ elsif SH4
+ emit "mov.l r13, @-r15"
+ emit "mov.l r11, @-r15"
+ emit "mov.l r10, @-r15"
+ emit "mov.l r9, @-r15"
+ emit "mov.l r8, @-r15"
+ elsif X86
+ emit "push %esi"
+ emit "push %edi"
+ emit "push %ebx"
+ elsif X86_WIN
+ emit "push esi"
+ emit "push edi"
+ emit "push ebx"
+ elsif X86_64
+ emit "push %r12"
+ emit "push %r13"
+ emit "push %r14"
+ emit "push %r15"
+ emit "push %rbx"
+ elsif X86_64_WIN
+ emit "push r12"
+ emit "push r13"
+ emit "push r14"
+ emit "push r15"
+ emit "push rbx"
+ emit "push rdi"
+ emit "push rsi"
+ end
+end
+
+macro popCalleeSaves()
+ if C_LOOP
+ elsif ARM or ARMv7_TRADITIONAL
+ emit "pop {r4-r10}"
+ elsif ARMv7
+ emit "pop {r4-r6, r8-r11}"
+ elsif ARM64
+ emit "ldp x28, x27, [sp], #16"
+ emit "ldp x26, x25, [sp], #16"
+ emit "ldp x24, x23, [sp], #16"
+ emit "ldp x22, x21, [sp], #16"
+ emit "ldp x20, x19, [sp], #16"
+ elsif MIPS
+ emit "lw $16, 0($sp)"
+ emit "lw $17, 4($sp)"
+ emit "lw $18, 8($sp)"
+ emit "lw $19, 12($sp)"
+ emit "lw $20, 16($sp)"
+ emit "addiu $sp, $sp, 20"
+ elsif SH4
+ emit "mov.l @r15+, r8"
+ emit "mov.l @r15+, r9"
+ emit "mov.l @r15+, r10"
+ emit "mov.l @r15+, r11"
+ emit "mov.l @r15+, r13"
+ elsif X86
+ emit "pop %ebx"
+ emit "pop %edi"
+ emit "pop %esi"
+ elsif X86_WIN
+ emit "pop ebx"
+ emit "pop edi"
+ emit "pop esi"
+ elsif X86_64
+ emit "pop %rbx"
+ emit "pop %r15"
+ emit "pop %r14"
+ emit "pop %r13"
+ emit "pop %r12"
+ elsif X86_64_WIN
+ emit "pop rsi"
+ emit "pop rdi"
+ emit "pop rbx"
+ emit "pop r15"
+ emit "pop r14"
+ emit "pop r13"
+ emit "pop r12"
+ end
+end
+