Skip to content

Commit

Permalink
Test mov to pindirs
Browse files Browse the repository at this point in the history
  • Loading branch information
Grazfather committed Dec 20, 2024
1 parent 93c2f5e commit e806642
Showing 1 changed file with 59 additions and 48 deletions.
107 changes: 59 additions & 48 deletions port/raspberrypi/rp2xxx/src/hal/pio/assembler/tokenizer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1921,59 +1921,70 @@ test "tokenize.instr.pull.ifempty" {
}

test "tokenize.instr.mov" {
inline for (.{
"pins",
"x",
"y",
"null",
"status",
"isr",
"osr",
}) |source| {
const tokens = try bounded_tokenize(.RP2040, comptime std.fmt.comptimePrint("mov x {s}", .{source}));

try expect_instr_mov(.RP2040, .{
.source = @field(Token(.RP2040).Instruction.Mov.Source, source),
.destination = .x,
}, tokens.get(0));
}
inline for (comptime .{ CPU.RP2040, CPU.RP2350 }) |cpu| {
inline for (.{
"pins",
"x",
"y",
"null",
"status",
"isr",
"osr",
}) |source| {
const tokens = try bounded_tokenize(cpu, comptime std.fmt.comptimePrint("mov x {s}", .{source}));

try expect_instr_mov(cpu, .{
.source = @field(Token(cpu).Instruction.Mov.Source, source),
.destination = .x,
}, tokens.get(0));
}

inline for (.{
"pins",
"x",
"y",
"exec",
"pc",
"isr",
"osr",
}) |dest| {
const tokens = try bounded_tokenize(.RP2040, comptime std.fmt.comptimePrint("mov {s} x", .{dest}));
inline for (.{
"pins",
"x",
"y",
"exec",
"pc",
"isr",
"osr",
}) |dest| {
const tokens = try bounded_tokenize(cpu, comptime std.fmt.comptimePrint("mov {s} x", .{dest}));

try expect_instr_mov(cpu, .{
.source = .x,
.destination = @field(Token(cpu).Instruction.Mov.Destination, dest),
}, tokens.get(0));
}
// RP2350 also supports pindirs as dest
{
const tokens = try bounded_tokenize(.RP2350, "mov pindirs x");

try expect_instr_mov(.RP2040, .{
.source = .x,
.destination = @field(Token(.RP2040).Instruction.Mov.Destination, dest),
}, tokens.get(0));
}
try expect_instr_mov(.RP2350, .{
.source = .x,
.destination = @field(Token(.RP2350).Instruction.Mov.Destination, "pindirs"),
}, tokens.get(0));
}

const Operation = Token(.RP2040).Instruction.Mov.Operation;
const operations = std.StaticStringMap(Operation).initComptime(.{
.{ "!", .invert },
.{ "~", .invert },
.{ "::", .bit_reverse },
});
const Operation = Token(cpu).Instruction.Mov.Operation;
const operations = std.StaticStringMap(Operation).initComptime(.{
.{ "!", .invert },
.{ "~", .invert },
.{ "::", .bit_reverse },
});

inline for (.{ "", " " }) |space| {
inline for (comptime operations.keys(), comptime operations.values()) |str, operation| {
const tokens = try bounded_tokenize(.RP2040, comptime std.fmt.comptimePrint("mov x {s}{s}y", .{
str,
space,
}));
inline for (.{ "", " " }) |space| {
inline for (comptime operations.keys(), comptime operations.values()) |str, operation| {
const tokens = try bounded_tokenize(cpu, comptime std.fmt.comptimePrint("mov x {s}{s}y", .{
str,
space,
}));

try expect_instr_mov(.RP2040, .{
.destination = .x,
.operation = operation,
.source = .y,
}, tokens.get(0));
try expect_instr_mov(cpu, .{
.destination = .x,
.operation = operation,
.source = .y,
}, tokens.get(0));
}
}
}
}
Expand Down

0 comments on commit e806642

Please sign in to comment.