blob: ea1785417e4af2c27441329cf4dc43faba89319c [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_COMPILER_INSTRUCTION_CODES_H_
6#define V8_COMPILER_INSTRUCTION_CODES_H_
7
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008#include <iosfwd>
9
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010#if V8_TARGET_ARCH_ARM
11#include "src/compiler/arm/instruction-codes-arm.h"
12#elif V8_TARGET_ARCH_ARM64
13#include "src/compiler/arm64/instruction-codes-arm64.h"
14#elif V8_TARGET_ARCH_IA32
15#include "src/compiler/ia32/instruction-codes-ia32.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040016#elif V8_TARGET_ARCH_MIPS
17#include "src/compiler/mips/instruction-codes-mips.h"
18#elif V8_TARGET_ARCH_MIPS64
19#include "src/compiler/mips64/instruction-codes-mips64.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000020#elif V8_TARGET_ARCH_X64
21#include "src/compiler/x64/instruction-codes-x64.h"
22#else
23#define TARGET_ARCH_OPCODE_LIST(V)
24#define TARGET_ADDRESSING_MODE_LIST(V)
25#endif
26#include "src/utils.h"
27
28namespace v8 {
29namespace internal {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000030namespace compiler {
31
32// Target-specific opcodes that specify which assembly sequence to emit.
33// Most opcodes specify a single instruction.
34#define ARCH_OPCODE_LIST(V) \
35 V(ArchCallCodeObject) \
36 V(ArchCallJSFunction) \
37 V(ArchJmp) \
38 V(ArchNop) \
39 V(ArchRet) \
Emily Bernierd0a1eb72015-03-24 16:35:39 -040040 V(ArchStackPointer) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000041 V(ArchTruncateDoubleToI) \
Emily Bernierd0a1eb72015-03-24 16:35:39 -040042 V(CheckedLoadInt8) \
43 V(CheckedLoadUint8) \
44 V(CheckedLoadInt16) \
45 V(CheckedLoadUint16) \
46 V(CheckedLoadWord32) \
47 V(CheckedLoadFloat32) \
48 V(CheckedLoadFloat64) \
49 V(CheckedStoreWord8) \
50 V(CheckedStoreWord16) \
51 V(CheckedStoreWord32) \
52 V(CheckedStoreFloat32) \
53 V(CheckedStoreFloat64) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000054 TARGET_ARCH_OPCODE_LIST(V)
55
56enum ArchOpcode {
57#define DECLARE_ARCH_OPCODE(Name) k##Name,
58 ARCH_OPCODE_LIST(DECLARE_ARCH_OPCODE)
59#undef DECLARE_ARCH_OPCODE
60#define COUNT_ARCH_OPCODE(Name) +1
61 kLastArchOpcode = -1 ARCH_OPCODE_LIST(COUNT_ARCH_OPCODE)
62#undef COUNT_ARCH_OPCODE
63};
64
Emily Bernierd0a1eb72015-03-24 16:35:39 -040065std::ostream& operator<<(std::ostream& os, const ArchOpcode& ao);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000066
67// Addressing modes represent the "shape" of inputs to an instruction.
68// Many instructions support multiple addressing modes. Addressing modes
69// are encoded into the InstructionCode of the instruction and tell the
70// code generator after register allocation which assembler method to call.
71#define ADDRESSING_MODE_LIST(V) \
72 V(None) \
73 TARGET_ADDRESSING_MODE_LIST(V)
74
75enum AddressingMode {
76#define DECLARE_ADDRESSING_MODE(Name) kMode_##Name,
77 ADDRESSING_MODE_LIST(DECLARE_ADDRESSING_MODE)
78#undef DECLARE_ADDRESSING_MODE
79#define COUNT_ADDRESSING_MODE(Name) +1
80 kLastAddressingMode = -1 ADDRESSING_MODE_LIST(COUNT_ADDRESSING_MODE)
81#undef COUNT_ADDRESSING_MODE
82};
83
Emily Bernierd0a1eb72015-03-24 16:35:39 -040084std::ostream& operator<<(std::ostream& os, const AddressingMode& am);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000085
86// The mode of the flags continuation (see below).
87enum FlagsMode { kFlags_none = 0, kFlags_branch = 1, kFlags_set = 2 };
88
Emily Bernierd0a1eb72015-03-24 16:35:39 -040089std::ostream& operator<<(std::ostream& os, const FlagsMode& fm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000090
91// The condition of flags continuation (see below).
92enum FlagsCondition {
93 kEqual,
94 kNotEqual,
95 kSignedLessThan,
96 kSignedGreaterThanOrEqual,
97 kSignedLessThanOrEqual,
98 kSignedGreaterThan,
99 kUnsignedLessThan,
100 kUnsignedGreaterThanOrEqual,
101 kUnsignedLessThanOrEqual,
102 kUnsignedGreaterThan,
103 kUnorderedEqual,
104 kUnorderedNotEqual,
105 kUnorderedLessThan,
106 kUnorderedGreaterThanOrEqual,
107 kUnorderedLessThanOrEqual,
108 kUnorderedGreaterThan,
109 kOverflow,
110 kNotOverflow
111};
112
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400113inline FlagsCondition NegateFlagsCondition(FlagsCondition condition) {
114 return static_cast<FlagsCondition>(condition ^ 1);
115}
116
117std::ostream& operator<<(std::ostream& os, const FlagsCondition& fc);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000118
119// The InstructionCode is an opaque, target-specific integer that encodes
120// what code to emit for an instruction in the code generator. It is not
121// interesting to the register allocator, as the inputs and flags on the
122// instructions specify everything of interest.
123typedef int32_t InstructionCode;
124
125// Helpers for encoding / decoding InstructionCode into the fields needed
126// for code generation. We encode the instruction, addressing mode, and flags
127// continuation into a single InstructionCode which is stored as part of
128// the instruction.
129typedef BitField<ArchOpcode, 0, 7> ArchOpcodeField;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400130typedef BitField<AddressingMode, 7, 5> AddressingModeField;
131typedef BitField<FlagsMode, 12, 2> FlagsModeField;
132typedef BitField<FlagsCondition, 14, 5> FlagsConditionField;
133typedef BitField<int, 14, 18> MiscField;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000134
135} // namespace compiler
136} // namespace internal
137} // namespace v8
138
139#endif // V8_COMPILER_INSTRUCTION_CODES_H_