| ... | ... | @@ -460,4 +460,72 @@ pub const Instruction = union(enum) { |
| 460 | 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 | }; |