Clean up irgen.h a bit
[hiphop-php.git] / hphp / runtime / vm / jit / phys-reg-saver.cpp
blob63b1f7d675b7ede0759092e4a7156a3bff06544f
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2016 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/runtime/vm/jit/phys-reg-saver.h"
19 #include "hphp/runtime/vm/jit/abi.h"
20 #include "hphp/runtime/vm/jit/phys-reg.h"
21 #include "hphp/runtime/vm/jit/vasm-gen.h"
22 #include "hphp/runtime/vm/jit/vasm-instr.h"
24 namespace HPHP { namespace jit {
26 ///////////////////////////////////////////////////////////////////////////////
28 PhysRegSaver::PhysRegSaver(Vout& v, RegSet regs)
29 : m_v(v)
30 , m_regs(regs)
32 auto gpr = m_regs & abi().gp();
33 auto xmm = m_regs & abi().simd();
34 auto const sp = rsp();
36 m_adjust = gpr.size() & 0x1 ? 8 : 0;
38 if (!xmm.empty()) {
39 v << lea{sp[-16 * xmm.size()], sp};
41 int offset = 0;
42 xmm.forEach([&] (PhysReg r) {
43 v << storeups{r, sp[offset]};
44 offset += 16;
45 });
48 gpr.forEach([&] (PhysReg r) {
49 v << push{r};
50 });
52 if (m_adjust) {
53 v << lea{sp[-m_adjust], sp};
57 PhysRegSaver::~PhysRegSaver() {
58 auto& v = m_v;
59 auto const sp = rsp();
61 if (m_adjust) {
62 v << lea{sp[m_adjust], sp};
65 auto gpr = m_regs & abi().gp();
66 auto xmm = m_regs & abi().simd();
68 gpr.forEachR([&] (PhysReg r) {
69 v << pop{r};
70 });
72 if (!xmm.empty()) {
73 int offset = 0;
74 xmm.forEach([&] (PhysReg r) {
75 v << loadups{sp[offset], r};
76 offset += 16;
77 });
78 v << lea{sp[offset], sp};
82 size_t PhysRegSaver::rspAdjustment() const {
83 return m_adjust;
86 size_t PhysRegSaver::dwordsPushed() const {
87 assertx((m_adjust % sizeof(int64_t)) == 0);
88 return m_regs.size() + m_adjust / sizeof(int64_t);
91 ///////////////////////////////////////////////////////////////////////////////