{"slug":"readable-verilog-compact","title":"readable-verilog-compact","summary":"Use whenever writing or revising Verilog RTL or testbenches, including if/else chains, case items, task calls, loop bodies and nested control flow.","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-12-03T17:18:08.307859Z","repo":{"url":"https://github.com/Eriemon/verilog-generator","stars":348,"forks":23,"license":"Apache-2.0","updatedAt":"2026-12-03T15:34:41Z"},"bodyHtml":"<hr>\n<h2>name: readable-verilog-compact\ndescription: Use whenever writing or revising Verilog RTL or testbenches, including if/else chains, case items, task calls, loop bodies and nested control flow.</h2>\n<h1>Verilog 过程语句紧凑写法</h1>\n<p>开始撰写或修改 Verilog 时与主责技能同轮读取。逐个检查过程体，将每个分支、case 项或循环体的直接子语句按语法计数。只有一条赋值、task 调用或系统任务调用的普通无名块可以省去包装，条件与受控语句写在同一行。任一分支有两条以上语句，该分支保留 <code>begin/end</code>，其他分支可以独立收紧。保留 <code>always</code> 的外层块、具名块、局部声明、属性、宏边界和依附于块的注释。</p>\n<p><strong>普通条件链。</strong> 同样适用于组合逻辑、时序逻辑、task/function 内的过程和测试台。<code>else begin if (…) … end</code> 只有在该块仅含这个 <code>if</code>、去块后所有 <code>else</code> 仍与原来的 <code>if</code> 配对时，才展开为 <code>else if</code>。保留判定顺序、四态下的未命中路径、调用次数及副作用。两个独立的 <code>if</code> 仍可同拍执行。</p>\n<pre><code>// 测试台：前两臂各调用一次 task，最后一臂还要登记应答数。\nif(i_abort)cancel_transfer;\nelse if(i_retry)retry_transfer;\nelse begin\n\trecord_response(i_data);\n\tresponse_count = response_count + 1;\nend\n</code></pre>\n<p><strong>case 与循环。</strong> 简单 case 项可以写为 <code>ST_READ:read_word;</code>。逐项保留标签顺序、匹配类型和 default 行为。过程循环如 <code>for(i = 0; i &lt; 8; i = i + 1)check_lane(i);</code>、<code>repeat(2)sample_bus;</code> 和 <code>while(has_data)read_word;</code> 也按循环体的语句数处理。保留循环边界、迭代条件、时序控制和采样次数。generate 循环的命名层次仍按原结构处理。</p>\n<p><strong>时序赋值。</strong> 两个分支各写一次片选寄存器，可以直接收紧。</p>\n<pre><code>always@(posedge i_clk)begin\n\tif(!i_rst_n)reg_cs_n &lt;= 1'b1;\n\telse reg_cs_n &lt;= (state_next == ST_IDLE) || (state_next == ST_RESP);\nend\n</code></pre>\n<p><strong>嵌套使能。</strong> 外层命中后，即使内层条件为假，也已经跳过外层的其他分支。下例保留空闲分支的块，让最后的 <code>else if</code> 仍与外层条件配对。</p>\n<pre><code>always@(posedge i_clk)begin\n\tif(!i_rst_n)reg_sclk &lt;= 1'b0;\n\telse if(state_current == ST_IDLE)begin\n\t\tif(i_cmd_valid)reg_sclk &lt;= i_cfg_cpol;\n\tend else if(edge_pulse)reg_sclk &lt;= ~reg_sclk;\nend\n</code></pre>\n<p>复位释放、空闲、命令无效且 <code>edge_pulse=1</code> 时，原块保持时钟。若直接把空闲与命令有效合成首个条件，尾部分支会翻转时钟。只有证明每条落选路径（含 X/Z）行为相同，才可展平。对于两层均无 <code>else</code> 的 <code>if(A)begin if(B)q &lt;= d; end</code>，若 A、B 均为无副作用的判断，可写为 <code>if((A) &amp;&amp; (B))q &lt;= d;</code>。</p>\n<p><strong>状态机。</strong> 保留次态默认值、每个状态的说明和显式保持。状态项里有条件选择时保留该项的块，单赋值的 <code>default</code> 可直接跟在冒号后。</p>\n<pre><code>always@(*)begin\n\tstate_next = state_current;\n\tcase(state_current)\n\t\t// 空闲时等待命令。\n\t\tST_IDLE:begin\n\t\t\tif(i_cmd_valid)state_next = ST_SETUP;\n\t\t\telse state_next = ST_IDLE;\n\t\tend\n\t\t// 片选建立期结束后开始传输。\n\t\tST_SETUP:begin\n\t\t\tif(half_last)state_next = ST_ACTIVE;\n\t\t\telse state_next = ST_SETUP;\n\t\tend\n\t\t// 末位的尾沿结束传输。\n\t\tST_ACTIVE:begin\n\t\t\tif(edge_trail &amp;&amp; bit_last)state_next = ST_HOLD;\n\t\t\telse state_next = ST_ACTIVE;\n\t\tend\n\t\t// 片选保持期结束后发出应答。\n\t\tST_HOLD:begin\n\t\t\tif(half_last)state_next = ST_RESP;\n\t\t\telse state_next = ST_HOLD;\n\t\tend\n\t\t// 应答被接收后回到空闲。\n\t\tST_RESP:begin\n\t\t\tif(i_rsp_ready)state_next = ST_IDLE;\n\t\t\telse state_next = ST_RESP;\n\t\tend\n\t\t// 非法编码恢复为空闲。\n\t\tdefault:state_next = ST_IDLE;\n\tendcase\nend\n</code></pre>\n<p>交付前重新解析并核对每个 <code>else</code> 的归属。对改变条件结构的候选，比较更新与保持路径，覆盖外层真而内层假、竞争输入和未知值。仅需缩短版式时保留逻辑分支；合并不同分支体属于<a href=\"../readable-verilog-branch-simplify/SKILL.md\">分支化简</a>。</p>\n","files":[{"path":"SKILL.md","sizeBytes":4093,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-12-03T17:19:30.843243Z","sha256":"DBF2526629F7ABBB75B3FA2BE25C1111D804F340D37F749EE8F0A03D06A5B3AC","sizeBytes":2447},"review":null,"source":{"repositoryUrl":"https://github.com/Eriemon/verilog-generator","path":"skills/readable-verilog-compact","license":"Apache-2.0","commit":"4738a3c74a2b8a4fec46e6abef7abf66f3eaebea","subtreeSha":"A6C1856B8BDBCDEDD4AAFBD2D714C1A84E5659C9428F4DACD130FAF7AA218BB7","lastSyncedAt":"2026-12-03T17:18:07.377421Z"},"reviewedAt":"2026-12-03T17:22:34.73315Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/Eriemon/verilog-generator/tree/main/skills/readable-verilog-compact"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install eriemon-verilog-generator@llmmart"},{"target":"git","command":"git clone https://github.com/Eriemon/verilog-generator.git"}]}