authorgravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2022-03-13 21:00:16+07:00
committergravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2022-03-16 21:38:42+07:00
log048035ea555864ff994cee872d5be050d53be38f
treeb90b8b2fa4adb297e2049f1be66921dcf98c8d5b
parent92c262aa9361589dbe6176dbbb8c32a172bdc96c

stage2 sparcv9: Add Format 1 encoder


1 files changed, 12 insertions(+), 0 deletions(-)

src/arch/sparcv9/bits.zig+12
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const DW = std.dwarf;2const DW = std.dwarf;
3const assert = std.debug.assert;
3const testing = std.testing;4const testing = std.testing;
45
5/// General purpose registers in the SPARCv9 instruction set6/// General purpose registers in the SPARCv9 instruction set
...@@ -448,4 +449,15 @@ pub const Instruction = union(enum) {...@@ -448,4 +449,15 @@ pub const Instruction = union(enum) {
448 pub fn toU32(self: Instruction) u32 {449 pub fn toU32(self: Instruction) u32 {
449 return @bitCast(u32, self);450 return @bitCast(u32, self);
450 }451 }
452
453 fn format1(disp: i32) Instruction {
454 // In SPARC, branch target needs to be aligned to 4 bytes.
455 assert(disp % 4 == 0);
456
457 // Discard the last two bits since those are implicitly zero.
458 const udisp = @truncate(u30, @bitCast(u32, disp) >> 2);
459 return Instruction{ .format_1 = .{
460 .disp30 = udisp,
461 } };
462 }
451};463};