
    UHjB/                       d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	  ee
      j                         j                  d   Zedz  ZdZd	Zd
ZddZddZddZddZdddZddZddZefddZddZedk(  r e        yy)zCClassify post-gate opcode 0x10 rows near the current route blocker.    )annotationsN)Path)Any   outmap1_01amap2_02d
0x0040b49ec                p    | j                         s|S t        j                  | j                  d            S )Nutf-8encoding)existsjsonloads	read_text)pathfallbacks     O/home/exedev/hwanse/tools/summarize_save_selector_post_gate_reset_candidates.py	load_jsonr      s*    ;;=::dnngn677    c                t    t        | xs dd      }|dz	  dz  }|dz	  dz  }d|dd|d|dk(  rdnd	|d
k  dS )N0         0x02xr   primaryBranchStatesecondaryBranchState   )streamPlus1HexhelperArgumentHex
stateTablehelperDispatchValid)int)	value_hexvaluestream_plus_1
helper_args       r   decode_op10r+      si    	 S"%EaZ4'M2+%J}S12!*S!12.;q.@*F\)T1	 r   c                (    t        d | D        i       S )Nc              3     K   | ]6  }|j                  d       t        k(  r|j                  d      t        k(  r| 8 yw)sourcetargetN)getSOURCETARGET).0rows     r   	<genexpr>z"route_gate_path.<locals>.<genexpr>'   s9      	
wwx F*swwx/@F/J 	
s   <>)next)
gate_pathss    r   route_gate_pathr8   %   s!    	
%	
 	 r   c                    | j                  d      xs g D ci c]%  }|j                  d      r|j                  d      |' c}S c c}w )N
candidatesvaHex)r0   )secondary_sourcesr4   s     r   secondary_candidate_by_var=   /   sN     %((6<"777 	#  s   *Ac                   | | nt        t        dz  g       } ||nt        t        dz  i       }t        |       }t        |      }|j	                  d      xs g }g }|D ]%  }|j	                  d      dk7  rt        |j	                  d            }|j	                  |j	                  d            xs i }|j	                  d|d         }	|j	                  d	|d	         }
|j                  |j	                  d      |j	                  d      |j	                  d
      |j	                  d|d         |j	                  d|d         |
|	|j	                  d      |j	                  d      xs |	sdnd|
dk(  xr t        |	      d
       ( |D cg c]	  }|d   r| }}d}i dt        dt        d|j	                  d      d|j	                  d      d|r|d   xs i j	                  d      nd d|j	                  d      xs i j	                  d      d|j	                  d      d|j	                  d      d |j	                  d       d!|j	                  d!      d"t        |      d#t        |      d$t        |      t        |      z
  d%|d&|j	                  d'      d(|j	                  d)      d*|j	                  d+      xs g d,d-d-|d.S c c}w )/Nsave_selector_gate_paths.json*save_selector_secondary_state_sources.jsonpostGateTrace	opcodeHex0x10valueHexr;   r%   r$   handlerVaHexr"   r#   beforeFrontierReaderrouteRelevancez?post-gate opcode 0x10 row does not dispatch a valid helper casez8post-gate opcode 0x10 row dispatches a valid helper caser    )
r;   rD   rE   r"   r#   r$   r%   rF   rG   canResetSecondaryBranchStaterH   a  The two opcode 0x10 rows immediately after the current gates are secondary-table shaped, but their helper arguments are 0xe6 and 0xe7, outside the valid helper jump-table range 0x00..0x0b. They therefore do not prove a post-gate secondaryBranchState reset or fill. The path still stops at the opcode 0x24/0xe8 data-descriptor boundary before any proven route to the 0x00542b0c frontier reader.r.   r/   nearestWriterVaHexfrontierReaderVaHexpostGateTraceStartHexr   opcode24BoundaryVaHexopcode24BoundaryopcodeVaHexdispatchStopVaHexdispatchStopOpcodeHexdispatchStopHandlerSectionhelperValidCaseRangeHexpostGateOpcode10RowCount validPostGateSecondaryResetCountinvalidPostGateOpcode10RowCountpostGateOpcode10Rows#currentRootValidBeforeFrontierCountvalidBeforeFrontierCount"currentRootValidAfterFrontierCountvalidAfterFrontierCountvalidAfterFrontierRowsvalidAfterFrontierFblocked)postGateRowsPromoteRoutecontrolPathProofStatuspromotionStatus
conclusion)r   OUTr8   r=   r0   r+   appendboolr1   r2   len)r7   r<   	gate_pathcandidates_by_vapost_gate_tracepost_gate_opcode10_rowsr4   decodedsecondary_candidatehelper_validstate_tablevalid_post_gate_resetsra   s                r   build_summaryro   7   s~   )59SKjEjln;oJ->-J)PY::
Q  
+I01BCmmO4:O  77;6)cggj12.2237773CDJ*../DgNcFde)--lGL<QR&&WWW%
+GGN31556FP`Hab!4!8!89LgViNj!k%#/$7$;$;<R$S1556FG # RO,7;Q,Q,hVZ[gVh(
 	0 /-. 	 
	c && 	imm,@A 	y}}-BC	
 	 O/!"4":!?!?!Hae 	 )--0B"C"Ir!N!N}!] 	Y]]+>? 	 /F!G 	%imm4P&Q 	"#4#8#89R#S 	#C(?$@ 	+C0F,G 	*3/F+G#NdJe+e 	 7 	./@/D/DE_/`  	-.?.C.CD].^!" 	!"3"7"78L"M"SQS#$ %*"+$ + s   Kc                   ddd| d    d| d    d| d    d	d
| d    d	d| d    d	d| d    d	d| d    d| d    d| d    d| d    d	d| d    d| d    d| d    d| d    d | d!    d	d| d"   dd#dd$d%g}| d&   D ]D  }|j                  d'|d(    d)|d*    d)|d+    d)|d,    d-|d.    d/|d0    d/|d1    d/|d2    d3       F |j                  g d4       | d5   D ]\  }|j                  d'|j                  d(       d)|j                  d*       d)|j                  d,       d-|j                  d2       d3	       ^ |j                  d       d6j                  |      S )7Nz*# Save Selector Post-Gate Reset Candidates z	- route: r.   z -> r/   z- nearest writer: `rI   `z- frontier reader: `rJ   z- post-gate trace start: `rK   z- opcode 0x24 boundary: `rL   z- dispatch stop: `rO   z
` opcode `rP   z` in rQ   z- helper valid cases: `rR   z- post-gate opcode 0x10 rows: rS   z$- valid post-gate secondary resets: rT   z1- current valid before-frontier secondary fills: rW   z - post-gate rows promote route: r^   z- promotion status: `r`   ra   z## Post-Gate Opcode 0x10 Rowsz_| va | value | stream+1 | helper arg | table | helper valid | can reset secondary | relevance |z1| --- | --- | --- | --- | --- | --- | --- | --- |rV   z| `r;   z` | `rD   r"   r#   z` | r$   z | r%   rH   rG   z |)rq   z## Valid After-Frontier Rowsrq   z'| va | value | helper arg | relevance |z| --- | --- | --- | --- |r[   
)rc   extendr0   join)summarylinesr4   s      r   markdownrx   {   sk   4

GH%&d78+<*=>
g&:;<A>
w'<=>a@
$W-D%E$FaH
#G,C$D#EQG
W%89:*WMdEeDffkls  uQ  mR  lS  	T
!'*C"D!EQG
(1K)L(MN
.w7Y/Z.[\
;GDi<j;kl
*73M+N*OP
(9 :;1=

'
i;+E. -. 
#g,uS_$5U3?O;P:Q R'()c,.?-@CH]D^C__b1233s;K7L6MRQ	

 
LL   /0 
#'''"#5)<(=U377K^C_B``dww'()-	


 
LL99Ur   c                   g }| d   D ]  }|j                  dt        j                  |d          dt        j                  |d          dt        j                  |d          dt        j                  |d          dt        j                  |d	          d
|d    d
|d    d
t        j                  |d          d        g }| d   D ]  }|j                  dt        j                  |j                  d      xs d       dt        j                  |j                  d      xs d       dt        j                  |j                  d      xs d       dt        j                  |j                  d      xs d       d	        dj	                  g ddddddddddddddd d!d"d#d$d%d&t        j                  | d'          d(t        j                  | d)          d*| d+    d,| d-    d.t        j                  | d/          d0d1t        j                  | d2   xs d       d3t        j                  | d4   xs d       d5| d6    d7d8t        j                  | d9          d:d;d<|d=d>d?|d=d@dAdB      S )CNrV   z<tr><td><code>r;   z</code></td><td><code>rD   r"   r#   z</code></td><td>r$   z	</td><td>r%   rH   rG   z
</td></tr>r[   -rs   z<!doctype html>z<html lang="en">z<head>z  <meta charset="utf-8">zF  <meta name="viewport" content="width=device-width, initial-scale=1">z9  <title>Save Selector Post-Gate Reset Candidates</title>z	  <style>zg    :root { color-scheme: dark; font-family: system-ui, sans-serif; background: #101010; color: #eee; }z&    body { margin: 0; padding: 24px; }z,    h1 { margin: 0 0 8px; font-size: 24px; }z/    h2 { margin: 24px 0 8px; font-size: 18px; }z<    p { max-width: 1120px; color: #bbb; line-height: 1.45; }z[    table { width: 100%; border-collapse: collapse; margin: 12px 0 20px; font-size: 13px; }zi    th, td { border-bottom: 1px solid #303030; padding: 7px 8px; text-align: left; vertical-align: top; }zF    th { position: sticky; top: 0; background: #181818; color: #ddd; }z    code { color: #d7f0ff; }z
  </style>z</head>z<body>z3  <h1>Save Selector Post-Gate Reset Candidates</h1>z  <p>route r.   z -&gt; r/   z; post-gate opcode 0x10 rows rS   z#; valid post-gate secondary resets rT   z; promotion status <code>r`   z</code>.</p>z   <p>opcode 0x24 boundary <code>rL   z</code>; dispatch stop <code>rO   z&</code>; post-gate rows promote route r^   z.</p>z  <p>ra   z</p>z%  <h2>Post-Gate Opcode 0x10 Rows</h2>z  <table><thead><tr><th>va</th><th>value</th><th>stream+1</th><th>helper arg</th><th>table</th><th>helper valid</th><th>can reset secondary</th><th>relevance</th></tr></thead><tbody>z  </tbody></table>z$  <h2>Valid After-Frontier Rows</h2>zf  <table><thead><tr><th>va</th><th>value</th><th>helper arg</th><th>relevance</th></tr></thead><tbody>z</body>z</html>rq   )rc   htmlescaper0   ru   )rv   	post_rowsr4   
after_rowss       r   	html_pager      s   I-. 
S\23 4S_56 7S)9%:;< =S)<%=>? @;;s<012 3,-. /567 8;;s#3456 7		

 J/0 
SWWW%5%<=> ?SWWZ%8%?C@A BSWW-@%A%HSIJ K;;sww'78?C@A B		

 99 ### 	# 	#	#
 	Q# 	D# 	# 	r# 	1# 	7# 	:# 	G# 	f# 	t# 	Q#  	'!#" 	##$ 	%#& 	'#( 	>)#* dkk'("345WT[[QYIZ=[<\\y  {B  C]  {^  z_  _B  CJ  Km  Cn  Bo  oH  IM  IT  IT  U\  ]n  Uo  Ip  Hq  q}  	~+#, +4;;w?V7W7^[^+_*``}  C  J  J  KR  Sf  Kg  Kn  kn  o  ~p  pV  W^  _y  Wz  V{  {@  	A-#. GL12348/#0 	01#2 	A3#4 
5#6 	7#8 	/9#: 	q;#< 
=#> 	?#@ 	A#B 	C#D 	E# # #r   c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       y )
NT)parentsexist_ok-save_selector_post_gate_reset_candidates.jsonF   )ensure_asciiindentrs   r   r   )mkdir
write_textr   dumps)rv   out_dirs     r   write_outputsr      sD    MM$M.>>JJ

7q9D@ K r   c                    t        j                  t              } | j                  dt        t
        dz         | j                  dt        t
        dz         | j                  dt        t
               | j                         }t        t        |j                  g       t        |j                  i             }t        ||j                         t        d|j                  d	z          y )
N)descriptionz--gate-pathsr?   )typedefaultz--secondary-sourcesr@   z	--out-dirz2wrote save selector post-gate reset candidates -> r   )argparseArgumentParser__doc__add_argumentr   rb   
parse_argsro   r   r7   r<   r   r   print)parserargsrv   s      r   mainr      s    $$9F
T3A`;`a
-D#HtBtu
$<D$//2&$(("-G '4<<(	<<<II
J	Lr   __main__)r   r   r   r   returnr   )r'   z
str | Noner   dict)r7   z
list[dict]r   r   )r<   r   r   zdict[str, dict])NN)r7   zlist[dict] | Noner<   zdict | Noner   r   )rv   r   r   str)rv   r   r   r   r   None)r   r   )r   
__future__r   r   r{   r   pathlibr   typingr   __file__resolver   ROOTrb   r1   r2   OPCODE10_HANDLERr   r+   r8   r=   ro   rx   r   r   r   __name__ r   r   <module>r      s    I "      H~''*
Ul		 8	AH+\<~ 25 " zF r   