1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  * vim: set ts=8 sts=4 et sw=4 tw=99:
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef jit_MoveEmitter_x86_shared_h
8 #define jit_MoveEmitter_x86_shared_h
9 
10 #include "jit/MacroAssembler.h"
11 #include "jit/MoveResolver.h"
12 
13 namespace js {
14 namespace jit {
15 
16 class MoveEmitterX86 {
17   bool inCycle_;
18   MacroAssembler& masm;
19 
20   // Original stack push value.
21   uint32_t pushedAtStart_;
22 
23   // This is a store stack offset for the cycle-break spill slot, snapshotting
24   // codegen->framePushed_ at the time it is allocated. -1 if not allocated.
25   int32_t pushedAtCycle_;
26 
27 #ifdef JS_CODEGEN_X86
28   // Optional scratch register for performing moves.
29   mozilla::Maybe<Register> scratchRegister_;
30 #endif
31 
32   void assertDone();
33   Address cycleSlot();
34   Address toAddress(const MoveOperand& operand) const;
35   Operand toOperand(const MoveOperand& operand) const;
36   Operand toPopOperand(const MoveOperand& operand) const;
37 
38   size_t characterizeCycle(const MoveResolver& moves, size_t i,
39                            bool* allGeneralRegs, bool* allFloatRegs);
40   bool maybeEmitOptimizedCycle(const MoveResolver& moves, size_t i,
41                                bool allGeneralRegs, bool allFloatRegs,
42                                size_t swapCount);
43   void emitInt32Move(const MoveOperand& from, const MoveOperand& to,
44                      const MoveResolver& moves, size_t i);
45   void emitGeneralMove(const MoveOperand& from, const MoveOperand& to,
46                        const MoveResolver& moves, size_t i);
47   void emitFloat32Move(const MoveOperand& from, const MoveOperand& to);
48   void emitDoubleMove(const MoveOperand& from, const MoveOperand& to);
49   void emitSimd128FloatMove(const MoveOperand& from, const MoveOperand& to);
50   void emitSimd128IntMove(const MoveOperand& from, const MoveOperand& to);
51   void breakCycle(const MoveOperand& to, MoveOp::Type type);
52   void completeCycle(const MoveOperand& to, MoveOp::Type type);
53 
54  public:
55   explicit MoveEmitterX86(MacroAssembler& masm);
56   ~MoveEmitterX86();
57   void emit(const MoveResolver& moves);
58   void finish();
59 
setScratchRegister(Register reg)60   void setScratchRegister(Register reg) {
61 #ifdef JS_CODEGEN_X86
62     scratchRegister_.emplace(reg);
63 #endif
64   }
65 
66   mozilla::Maybe<Register> findScratchRegister(const MoveResolver& moves,
67                                                size_t i);
68 };
69 
70 typedef MoveEmitterX86 MoveEmitter;
71 
72 }  // namespace jit
73 }  // namespace js
74 
75 #endif /* jit_MoveEmitter_x86_shared_h */
76