graph LR subgraph "Input" X["x (N-bit signed)"] end subgraph "Shift Stage" S7["x <<< 7"] S4["x <<< 4"] S1["x <<< 1"] end subgraph "Add/Sub Stage" A1["-"] A2["+"] end subgraph "Output" Y["result = 114x"] end X --> S7 X --> S4 X --> S1 S7 --> A1 S4 --> A1 A1 --> A2 S1 --> A2 A2 --> Y style Y fill:#e8f5e9,stroke:#2e7d32,stroke-width:3px style S7 fill:#bbdefb,stroke:#1565c0 style S4 fill:#bbdefb,stroke:#1565c0 style S1 fill:#bbdefb,stroke:#1565c0
graph LR subgraph "Without LCSRe (4 adders)" F1["x_shift7 - x_shift5 + x_shift3 - x_shift1"] end subgraph "With LCSRe (2 adders + 1 shift)" O1["wire _pat = x_shift7 - x_shift5;"] O2["assign result = _pat + (_pat >>> 4);"] end style F1 fill:#ffcdd2,stroke:#c62828 style O1 fill:#e8f5e9,stroke:#2e7d32 style O2 fill:#e8f5e9,stroke:#2e7d32,stroke-width:3px
graph TD A["CSD string:\n+0-0+0-0"] --> B["LCSRe:\nfind longest\nrepeated pattern"] B --> C["Pattern '+0-0'\nat positions 0, 4"] C --> D{"NNZ โฅ 2\nand โฅ 2\noccurrences?"} D -- Yes --> E["Generate _pat wire\nx_shift7 - x_shift5"] D -- No --> F["Fall back to\nflat generation"] E --> G["For each occurrence:\n_pat or (_pat >>> shift)"] G --> H["assign result =\n_pat + (_pat >>> 4)"] F --> I["assign result =\nx_shift7 - x_shift5 +\nx_shift3 - x_shift1"] style D fill:#fff9c4,stroke:#f9a825,stroke-width:2px style H fill:#e8f5e9,stroke:#2e7d32,stroke-width:3px style I fill:#ffcdd2,stroke:#c62828
graph LR subgraph "Flat โ" FLAT["6 adders\nno sharing"] end subgraph "LCSRe Optimized โ " OPT["_pat wire (2 adders)\n+ (>>>4)\n+ (>>>8)"] end FLAT -->|"67% fewer adders"| OPT style FLAT fill:#ffcdd2,stroke:#c62828 style OPT fill:#e8f5e9,stroke:#2e7d32,stroke-width:3px
graph LR subgraph "FIR Filter (Direct Form)" XN["x[n]"] --> D0["zโปยน"] D0 --> D1["zโปยน"] D1 --> D2["zโปยน"] D2 --> D3["โฏ"] XN --> H0["ร h[0]"] D0 --> H1["ร h[1]"] D1 --> H2["ร h[2]"] D2 --> H3["ร h[3]"] H0 --> SUM["+"] H1 --> SUM H2 --> SUM H3 --> SUM SUM --> YN["y[n]"] end style H0 fill:#bbdefb,stroke:#1565c0 style H1 fill:#bbdefb,stroke:#1565c0 style H2 fill:#bbdefb,stroke:#1565c0 style H3 fill:#bbdefb,stroke:#1565c0 style SUM fill:#e8f5e9,stroke:#2e7d32,stroke-width:3px
graph LR subgraph "Coefficient Bank" H0["h0: 0000+0-0+0-0"] H1["h1: +0-0+0-0+0-0"] H2["h2: 0+00-00+00-0"] end subgraph "Pattern Scanner" SCAN["Find substrings\nwith NNZ โฅ 2\nin โฅ 2 coefficients"] end subgraph "Best Pattern" PAT["'+0-0+0-0' (score 6)\n4 non-zero digits\n3 occurrences\nacross h0, h1"] end subgraph "Generated Hardware" CSE["shared wire\n_cse_0"] U0["h0 = (_cse_0 >>> 4)"] U1["h1 = _cse_0 + ..."] U2["h2 = flat expr"] end H0 --> SCAN H1 --> SCAN H2 --> SCAN SCAN --> PAT PAT --> CSE CSE --> U0 CSE --> U1 CSE -.-> U2 style CSE fill:#e8f5e9,stroke:#2e7d32,stroke-width:3px style PAT fill:#fff9c4,stroke:#f9a825,stroke-width:2px
graph TD subgraph "Single coefficient" A1["CSD string"] --> B["Validate"] B --> C["LCSRe intra-CSD"] C --> D{"Pattern\nโฅ2ร ?"} D -- Yes --> E["_pat wire +\nshifted refs"] D -- No --> F["Flat expression"] end subgraph "Multiple coefficients" A2["List of CSD strings"] --> G["Cross-CSE scan"] G --> H{"Common\npattern found?"} H -- Yes --> I["Shared _cse wire +\nshifted refs per coeff"] H -- No --> J["Flat per coeff"] end E --> K["Wrap in\nVerilog module"] F --> K I --> K J --> K K --> OUT["โ Verilog output"] style H fill:#fff9c4,stroke:#f9a825,stroke-width:2px style OUT fill:#e8f5e9,stroke:#2e7d32,stroke-width:3px
graph LR COEFF["Filter Coefficients\nh[0..K-1]"] --> CSD["CSD Encoding"] CSD --> LCSRE["LCSRe Pattern\nDetection"] LCSRE --> GEN["Verilog\nGeneration"] GEN --> SYNTH["Logic Synthesis"] SYNTH --> AREA["Area/Power\nReport"] SYNTH --> TIMING["Timing\nAnalysis"] AREA --> CSD TIMING --> CSD style COEFF fill:#bbdefb,stroke:#1565c0 style GEN fill:#e8f5e9,stroke:#2e7d32,stroke-width:3px style SYNTH fill:#fff9c4,stroke:#f9a825,stroke-width:2px