Skip to content

Commit c239a78

Browse files
authored
Merge pull request #153 from zyantific/reorder-fields
Minor improvements
2 parents 916f28f + 3dff4c7 commit c239a78

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

tests/src/tests/tests.program.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <gtest/gtest.h>
2+
#include <zasm/testdata/x86/instructions.hpp>
23
#include <zasm/zasm.hpp>
34

45
namespace zasm::tests
@@ -369,4 +370,23 @@ namespace zasm::tests
369370
ASSERT_EQ(data, nullptr);
370371
}
371372

373+
// Test to ensure that we stay under 4 GiB of memory with a large number of instructions.
374+
TEST(ProgramTests, Test1MillionInstructions)
375+
{
376+
Program program(MachineMode::AMD64);
377+
378+
x86::Assembler assembler(program);
379+
380+
constexpr auto kMaxInstructions = 1'000'000;
381+
382+
for (size_t i = 0; i < kMaxInstructions; i++)
383+
{
384+
const auto& instrEntry = data::Instructions[i % std::size(data::Instructions)];
385+
386+
ASSERT_EQ(instrEntry.emitter(assembler), ErrorCode::None) << instrEntry.instrBytes << ", " << instrEntry.operation;
387+
}
388+
389+
ASSERT_EQ(program.size(), kMaxInstructions);
390+
}
391+
372392
} // namespace zasm::tests

zasm/include/zasm/base/instruction.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ namespace zasm
4141

4242
protected:
4343
Attribs _attribs{};
44-
OperandCount _opCount{};
4544
Mnemonic _mnemonic{};
45+
OperandCount _opCount{};
4646
Type _type{};
4747

4848
protected:

zasm/include/zasm/base/memory.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ namespace zasm
1414
{
1515
using RegisterPack = Packed<std::uint32_t, Reg::Id, 10>;
1616

17-
BitSize _bitSize{};
18-
RegisterPack _segBaseIndex{};
19-
std::uint8_t _scale{};
2017
std::int64_t _disp{};
18+
RegisterPack _segBaseIndex{};
2119
Label::Id _label{ Label::Id::Invalid };
20+
std::uint8_t _scale{};
21+
BitSize _bitSize{};
2222

2323
public:
2424
constexpr explicit Mem(
2525
BitSize bitSize, const Reg& seg, const Reg& base, const Reg& index, std::int32_t scale, std::int64_t disp) noexcept
26-
: _bitSize{ bitSize }
26+
: _disp{ disp }
2727
, _segBaseIndex{ seg.getId(), base.getId(), index.getId() }
2828
, _scale{ static_cast<std::uint8_t>(scale) }
29-
, _disp{ disp }
29+
, _bitSize{ bitSize }
3030
{
3131
}
3232

3333
constexpr explicit Mem(
3434
BitSize bitSize, const Reg& seg, const Label& label, const Reg& base, const Reg& index, std::int32_t scale,
3535
std::int64_t disp) noexcept
36-
: _bitSize{ bitSize }
36+
: _disp{ disp }
3737
, _segBaseIndex{ seg.getId(), base.getId(), index.getId() }
38-
, _scale{ static_cast<std::uint8_t>(scale) }
39-
, _disp{ disp }
4038
, _label{ label.getId() }
39+
, _scale{ static_cast<std::uint8_t>(scale) }
40+
, _bitSize{ bitSize }
4141
{
4242
}
4343

0 commit comments

Comments
 (0)