summaryrefslogtreecommitdiffstats
path: root/js/src/jit/x86-shared/MoveEmitter-x86-shared.h
blob: bba1256ee50a40f1cafed9428647a686467d50d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef jit_MoveEmitter_x86_shared_h
#define jit_MoveEmitter_x86_shared_h

#include "jit/MacroAssembler.h"
#include "jit/MoveResolver.h"

namespace js {
namespace jit {

class MoveEmitterX86
{
    bool inCycle_;
    MacroAssembler& masm;

    // Original stack push value.
    uint32_t pushedAtStart_;

    // This is a store stack offset for the cycle-break spill slot, snapshotting
    // codegen->framePushed_ at the time it is allocated. -1 if not allocated.
    int32_t pushedAtCycle_;

#ifdef JS_CODEGEN_X86
    // Optional scratch register for performing moves.
    mozilla::Maybe<Register> scratchRegister_;
#endif

    void assertDone();
    Address cycleSlot();
    Address toAddress(const MoveOperand& operand) const;
    Operand toOperand(const MoveOperand& operand) const;
    Operand toPopOperand(const MoveOperand& operand) const;

    size_t characterizeCycle(const MoveResolver& moves, size_t i,
                             bool* allGeneralRegs, bool* allFloatRegs);
    bool maybeEmitOptimizedCycle(const MoveResolver& moves, size_t i,
                                 bool allGeneralRegs, bool allFloatRegs, size_t swapCount);
    void emitInt32Move(const MoveOperand& from, const MoveOperand& to,
                       const MoveResolver& moves, size_t i);
    void emitGeneralMove(const MoveOperand& from, const MoveOperand& to,
                         const MoveResolver& moves, size_t i);
    void emitFloat32Move(const MoveOperand& from, const MoveOperand& to);
    void emitDoubleMove(const MoveOperand& from, const MoveOperand& to);
    void emitSimd128FloatMove(const MoveOperand& from, const MoveOperand& to);
    void emitSimd128IntMove(const MoveOperand& from, const MoveOperand& to);
    void breakCycle(const MoveOperand& to, MoveOp::Type type);
    void completeCycle(const MoveOperand& to, MoveOp::Type type);

  public:
    explicit MoveEmitterX86(MacroAssembler& masm);
    ~MoveEmitterX86();
    void emit(const MoveResolver& moves);
    void finish();

    void setScratchRegister(Register reg) {
#ifdef JS_CODEGEN_X86
        scratchRegister_.emplace(reg);
#endif
    }

    mozilla::Maybe<Register> findScratchRegister(const MoveResolver& moves, size_t i);
};

typedef MoveEmitterX86 MoveEmitter;

} // namespace jit
} // namespace js

#endif /* jit_MoveEmitter_x86_shared_h */