diff options
| author | Koakuma <koachan@protonmail.com> | 2022-03-13 21:00:16 +0700 |
|---|---|---|
| committer | Koakuma <koachan@protonmail.com> | 2022-03-16 21:38:42 +0700 |
| commit | 048035ea555864ff994cee872d5be050d53be38f (patch) | |
| tree | b90b8b2fa4adb297e2049f1be66921dcf98c8d5b /src | |
| parent | 92c262aa9361589dbe6176dbbb8c32a172bdc96c (diff) | |
| download | zig-048035ea555864ff994cee872d5be050d53be38f.tar.gz zig-048035ea555864ff994cee872d5be050d53be38f.zip | |
stage2 sparcv9: Add Format 1 encoder
Diffstat (limited to 'src')
| -rw-r--r-- | src/arch/sparcv9/bits.zig | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/arch/sparcv9/bits.zig b/src/arch/sparcv9/bits.zig index adf8ab1810..00739ad2f6 100644 --- a/src/arch/sparcv9/bits.zig +++ b/src/arch/sparcv9/bits.zig @@ -1,5 +1,6 @@ const std = @import("std"); const DW = std.dwarf; +const assert = std.debug.assert; const testing = std.testing; /// General purpose registers in the SPARCv9 instruction set @@ -448,4 +449,15 @@ pub const Instruction = union(enum) { pub fn toU32(self: Instruction) u32 { return @bitCast(u32, self); } + + fn format1(disp: i32) Instruction { + // In SPARC, branch target needs to be aligned to 4 bytes. + assert(disp % 4 == 0); + + // Discard the last two bits since those are implicitly zero. + const udisp = @truncate(u30, @bitCast(u32, disp) >> 2); + return Instruction{ .format_1 = .{ + .disp30 = udisp, + } }; + } }; |
