File size: 1,660 Bytes
198fb2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
"""Decide which detected memories are idiomatic as ASAP7 SRAM macros.

A memory below these floors is cheaper as flip-flops than as an SRAM
macro (the macro pays a fixed control/decode/sense-amp floor), and a
memory with too many ports has no single-macro implementation in
ordinary SRAM compilers. Rejected memories keep `idiomatic: false` plus
a reason in memories.json and synthesize as flops.

The thresholds are deliberately simple, first-pass policy. Banking and
multi-port decomposition (splitting a too-wide/too-ported memory across
several macros) are not handled — a future extension. A user who wants
a rejected memory converted anyway overrides it via a `.memories` file
listed in ADDITIONAL_MEMORIES.
"""

from __future__ import annotations

import schema

MIN_ROWS = 16
MIN_BITS_TOTAL = 256
MAX_TOTAL_PORTS = 4


def judge(mem: schema.Memory) -> tuple[bool, str]:
    """Return (idiomatic, reason)."""
    if mem.bits < 1:
        return False, "no data pins"
    if mem.rows < MIN_ROWS:
        return False, f"depth {mem.rows} below macro floor {MIN_ROWS}"
    total_bits = mem.rows * mem.bits
    if total_bits < MIN_BITS_TOTAL:
        return (
            False,
            f"capacity {total_bits} bits below macro floor " f"{MIN_BITS_TOTAL}",
        )
    if mem.total_ports() > MAX_TOTAL_PORTS:
        return (
            False,
            f"{mem.total_ports()} ports exceeds single-macro "
            f"limit {MAX_TOTAL_PORTS}",
        )
    return True, "meets ASAP7 macro floors"


def apply(memories: list[schema.Memory]) -> None:
    for mem in memories:
        mem.idiomatic, mem.reason = judge(mem)