authorgravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2022-03-13 21:54:44+07:00
committergravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2022-03-16 21:38:42+07:00
logfbcea863334bebdd6bb465c84b97122e78f19d5d
treee1b2ed0041583929e4724339ddf901109f56d30f
parent048035ea555864ff994cee872d5be050d53be38f

stage2 sparcv9: Add Format 2 encoder


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

src/arch/sparcv9/bits.zig+68
...@@ -460,4 +460,72 @@ pub const Instruction = union(enum) {...@@ -460,4 +460,72 @@ pub const Instruction = union(enum) {
460 .disp30 = udisp,460 .disp30 = udisp,
461 } };461 } };
462 }462 }
463
464 fn format2a(rd: Register, op2: u3, imm: i22) Instruction {
465 const umm = @bitCast(u22, imm);
466 return Instruction{
467 .format_2a = .{
468 .rd = rd.enc(),
469 .op2 = op2,
470 .imm22 = umm,
471 },
472 };
473 }
474
475 fn format2b(a: u1, cond: u4, op2: u3, disp: i24) Instruction {
476 // In SPARC, branch target needs to be aligned to 4 bytes.
477 assert(disp % 4 == 0);
478
479 // Discard the last two bits since those are implicitly zero.
480 const udisp = @truncate(u22, @bitCast(u24, disp) >> 2);
481 return Instruction{
482 .format_2b = .{
483 .a = a,
484 .cond = cond,
485 .op2 = op2,
486 .disp22 = udisp,
487 },
488 };
489 }
490
491 fn format2c(a: u1, cond: u4, op2: u3, cc1: u1, cc0: u1, p: u1, disp: i21) Instruction {
492 // In SPARC, branch target needs to be aligned to 4 bytes.
493 assert(disp % 4 == 0);
494
495 // Discard the last two bits since those are implicitly zero.
496 const udisp = @truncate(u19, @bitCast(u21, disp) >> 2);
497 return Instruction{
498 .format_2c = .{
499 .a = a,
500 .cond = cond,
501 .op2 = op2,
502 .cc1 = cc1,
503 .cc0 = cc0,
504 .p = p,
505 .disp19 = udisp,
506 },
507 };
508 }
509
510 fn format2d(a: u1, rcond: u3, op2: u3, p: u1, rs1: Register, disp: i18) Instruction {
511 // In SPARC, branch target needs to be aligned to 4 bytes.
512 assert(disp % 4 == 0);
513
514 // Discard the last two bits since those are implicitly zero,
515 // and split it into low and high parts.
516 const udisp = @truncate(u16, @bitCast(u18, disp) >> 2);
517 const udisp_hi = @truncate(u2, (udisp & 0b1100_0000_0000_0000) >> 14);
518 const udisp_lo = @truncate(u14, udisp & 0b0011_1111_1111_1111);
519 return Instruction{
520 .format_2a = .{
521 .a = a,
522 .rcond = rcond,
523 .op2 = op2,
524 .p = p,
525 .rs1 = rs1.enc(),
526 .d16hi = udisp_hi,
527 .d16lo = udisp_lo,
528 },
529 };
530 }
463};531};