Shf32

sm86.sail

SHF of a 32-bit type by an immediate (one game's are nearly all so: SHF.R.U32.HI d, RZ, s, x): (c:a) shifted by s, known when the translator runs, of 32-bit words. Its high word or low word is a word shifted, or two words' bits put together; s 0 and 32 take a word whole (a shift by 32 is out of SPIR-V's range)

function Shf32(right : bool, is_signed : bool, high : bool, s : int) -> unit = {
    if s == 0 then D_write(if high then SrcBits(C) else SrcBits(A))
    else if right & high then {
        let c = SrcBits(C);
        if s == 32 then D_write(if is_signed then ASR(c, 31) else 0x00000000)
        else D_write(if is_signed then ASR(c, s) else c >> s)
    } else if not_bool(right) & not_bool(high) then {
        if s == 32 then D_write(0x00000000) else D_write(SrcBits(A) << s)
    } else if s == 32 then D_write(if high then SrcBits(A) else SrcBits(C))
    else {
        /* the low word of a right shift (a's bits down, c's in from above), or the high word of a left shift (c's
           bits up, a's in from below); a word that reads zero adds nothing */
        let from = if right then 32 - s else s;
        let up = if IsZero(C) then 0x00000000 else SrcBits(C) << from;
        let down = if IsZero(A) then 0x00000000 else SrcBits(A) >> (32 - from);
        if IsZero(A) then D_write(up) else if IsZero(C) then D_write(down) else D_write(up | down)
    }
}

Used by


Made from ScarletNX's Sail at 166ad3910f80. The Sail and the encodings' file are ScarletNX's (GPL-3.0-or-later); its encodings are from Mesa's NAK (sm70_encode.rs, MIT) and CuAssembler's sm_86 records.