[Libre-soc-bugs] [Bug 980] Implement C-based Power ISA pseudocode compiler

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Fri Jan 12 20:27:21 GMT 2024


https://bugs.libre-soc.org/show_bug.cgi?id=980

--- Comment #82 from Dmitry Selyutin <ghostmansd at gmail.com> ---
Many recent commits on oppc branch (too many to list them separately) bring
support for more expressions and statements. With these, the following
pseudocode...


src <- [0]*64
src[64-XLEN:63] <- (RS)
result <- [0]*64
do i = 0 to 1
    n <- i * 32
    result[n+0:n+7] <- 0
    result[n+8:n+19] <- DPD_TO_BCD(src[n+12:n+21])
    result[n+20:n+31] <- DPD_TO_BCD(src[n+22:n+31])
RA <- result[64-XLEN:63]
RA <- (C ? A : B)
if a < b then RT <- (RA)
else          RT <- (RB)


...get converted to this C code:


void
oppc_cdtbcd(void) {
    uint64_t src;
    uint64_t result;
    uint64_t i;
    uint64_t n;
    uint64_t C;
    uint64_t A;
    uint64_t B;
    uint64_t a;
    uint64_t b;
    src = oppc_repeat(UINT64_C(0x0), UINT64_C(0x40));
    oppc_range_subscript_assign(&src, (UINT64_C(0x40) - ctx->XLEN),
UINT64_C(0x3f), ctx->gpr[OPPC_GPR_RS]);
    result = oppc_repeat(UINT64_C(0x0), UINT64_C(0x40));
    for (i = UINT64_C(0x0); i != (UINT64_C(0x1) + 1); ++i) {
        n = (i * UINT64_C(0x20));
        oppc_range_subscript_assign(&result, (n + UINT64_C(0x0)), (n +
UINT64_C(0x7)), UINT64_C(0x0));
        oppc_range_subscript_assign(&result, (n + UINT64_C(0x8)), (n +
UINT64_C(0x13)), DPD_TO_BCD(oppc_range_subscript(src, (n + UINT64_C(0xc)), (n +
UINT64_C(0x15)))));
        oppc_range_subscript_assign(&result, (n + UINT64_C(0x14)), (n +
UINT64_C(0x1f)), DPD_TO_BCD(oppc_range_subscript(src, (n + UINT64_C(0x16)), (n
+ UINT64_C(0x1f)))));
    }
    ctx->gpr[OPPC_GPR_RA] = oppc_range_subscript(result, (UINT64_C(0x40) -
ctx->XLEN), UINT64_C(0x3f));
    ctx->gpr[OPPC_GPR_RA] = C ? A : B;
    if (a < b) {
        ctx->gpr[OPPC_GPR_RT] = ctx->gpr[OPPC_GPR_RA];
    } else {
        ctx->gpr[OPPC_GPR_RT] = ctx->gpr[OPPC_GPR_RB];
    }
}


I haven't yet touched the function signature to make it return bool or expand
what ctx is, I'd like to deal with the nodes first. But I think this should be
sufficient to get the overall idea.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the libre-soc-bugs mailing list