authorgravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2022-03-16 22:30:48+07:00
committergravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2022-03-16 22:30:48+07:00
logd9c33a610e2f081b6e8d64bfe34f6cb8be61a5b4
treee996db7548f86ecc1709c06bb6491d2b76fe3acd
parent1cea8b271e8c1e7888dc6102014ee69bf2fcbe47

stage2 sparcv9: Fix branch format asserts


1 files changed, 18 insertions(+), 11 deletions(-)

src/arch/sparcv9/bits.zig+18-11
......@@ -513,14 +513,16 @@ pub const Instruction = union(enum) {
513513 }
514514
515515 fn format1(disp: i32) Instruction {
516 const udisp = @bitCast(u32, disp);
517
516518 // In SPARC, branch target needs to be aligned to 4 bytes.
517 assert(disp % 4 == 0);
519 assert(udisp % 4 == 0);
518520
519521 // Discard the last two bits since those are implicitly zero.
520 const udisp = @truncate(u30, @bitCast(u32, disp) >> 2);
522 const udisp_truncated = @truncate(u30, udisp >> 2);
521523 return Instruction{
522524 .format_1 = .{
523 .disp30 = udisp,
525 .disp30 = udisp_truncated,
524526 },
525527 };
526528 }
......@@ -536,27 +538,31 @@ pub const Instruction = union(enum) {
536538 }
537539
538540 fn format2b(op2: u3, cond: Condition, annul: bool, disp: i24) Instruction {
541 const udisp = @bitCast(u24, disp);
542
539543 // In SPARC, branch target needs to be aligned to 4 bytes.
540 assert(disp % 4 == 0);
544 assert(udisp % 4 == 0);
541545
542546 // Discard the last two bits since those are implicitly zero.
543 const udisp = @truncate(u22, @bitCast(u24, disp) >> 2);
547 const udisp_truncated = @truncate(u22, udisp >> 2);
544548 return Instruction{
545549 .format_2b = .{
546550 .a = @boolToInt(annul),
547551 .cond = cond,
548552 .op2 = op2,
549 .disp22 = udisp,
553 .disp22 = udisp_truncated,
550554 },
551555 };
552556 }
553557
554558 fn format2c(op2: u3, cond: Condition, annul: bool, pt: bool, ccr: CCR, disp: i21) Instruction {
559 const udisp = @bitCast(u21, disp);
560
555561 // In SPARC, branch target needs to be aligned to 4 bytes.
556 assert(disp % 4 == 0);
562 assert(udisp % 4 == 0);
557563
558564 // Discard the last two bits since those are implicitly zero.
559 const udisp = @truncate(u19, @bitCast(u21, disp) >> 2);
565 const udisp_truncated = @truncate(u19, udisp >> 2);
560566
561567 const ccr_cc1 = @truncate(u1, @enumToInt(ccr) >> 1);
562568 const ccr_cc0 = @truncate(u1, @enumToInt(ccr));
......@@ -568,18 +574,19 @@ pub const Instruction = union(enum) {
568574 .cc1 = ccr_cc1,
569575 .cc0 = ccr_cc0,
570576 .p = @boolToInt(pt),
571 .disp19 = udisp,
577 .disp19 = udisp_truncated,
572578 },
573579 };
574580 }
575581
576582 fn format2d(op2: u3, rcond: RCondition, annul: bool, pt: bool, rs1: Register, disp: i18) Instruction {
583 const udisp = @truncate(u16, @bitCast(u18, disp) >> 2);
584
577585 // In SPARC, branch target needs to be aligned to 4 bytes.
578 assert(disp % 4 == 0);
586 assert(udisp % 4 == 0);
579587
580588 // Discard the last two bits since those are implicitly zero,
581589 // and split it into low and high parts.
582 const udisp = @truncate(u16, @bitCast(u18, disp) >> 2);
583590 const udisp_hi = @truncate(u2, (udisp & 0b1100_0000_0000_0000) >> 14);
584591 const udisp_lo = @truncate(u14, udisp & 0b0011_1111_1111_1111);
585592 return Instruction{