""" Step 3: CMD_DECODE -- control lines -> DDR command. A DDR command is a truth table over the control pins (CS_n, ACT_n, and the RAS_n/CAS_n/WE_n multiplexed lines). It is a finite function -> N/N verifiable. (DDR5 uses a multi-cycle CA encoding; the table here is a compact, self-consistent DDR4-style decode that the same unit shape can be retrained to for DDR5.) """ from __future__ import annotations import torch from .common import bits_of, int_of, pm IN, OUT = 5, 4 CMDS = {"DESELECT": 0, "ACTIVATE": 1, "NOP": 2, "READ": 3, "WRITE": 4, "PRECHARGE": 5, "REFRESH": 6, "MRS": 7, "ZQ": 8} NAME = {v: k for k, v in CMDS.items()} def golden_cmd(v: int) -> int: cs, act, ras, cas, we = bits_of(v, 5) # bit0=CS_n .. bit4=WE_n if cs == 1: return CMDS["DESELECT"] if act == 0: return CMDS["ACTIVATE"] table = {(1, 1, 1): "NOP", (1, 1, 0): "NOP", (1, 0, 1): "READ", (1, 0, 0): "WRITE", (0, 1, 1): "PRECHARGE", (0, 1, 0): "REFRESH", (0, 0, 1): "MRS", (0, 0, 0): "ZQ"} return CMDS[table[(ras, cas, we)]] def domain(): X = torch.stack([pm(bits_of(v, IN)) for v in range(2 ** IN)]) Y = torch.tensor([[float(b) for b in bits_of(golden_cmd(v), OUT)] for v in range(2 ** IN)]) return X, Y def run(net, v: int) -> int: return int_of((net(pm(bits_of(v, IN)).unsqueeze(0))[0] > 0).int().tolist())