
    UHj,                    d   d Z ddlmZ ddlZddlZddlZddlmZ  ee      j                         j                  d   Zedz  Zi 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$g d%d&d'g d(d)d*d+Zd3d,Z	 	 d4	 	 	 	 	 d5d-Zd6d.Zd6d/Zd7d0Zd8d1Zed2k(  r e        yy)9zCDocument the unresolved selector equation for map1_01a -> map2_02d.    )annotationsN)Path   outroutezmap1_01a -> map2_02dwriterVaHex
0x005428bcwriterValueHex
0x00208212readerVaHex
0x00542b0creaderValueHex
0x00209011selectionOffsetHex0x20writerHandlerVaHex
0x0040b55freaderHandlerVaHex
0x0040b4e6activeFlagVaHex
0x00457744primaryBranchStateVaHex
0x0059e370secondaryBranchStateVaHex
0x0059e360selectionBufferContextOffsetHex0xa8writerTablesecondaryBranchStatereaderTablewriterAlgorithm)zIstream+1 is 0x82, so opcode 0x12 uses secondaryBranchState at 0x0059e360.zrIf byte(0x00457744) is set, the search starts from the existing selectionBuffer[0x20]; otherwise it starts from 0.zuThe handler first walks backward through 12 slots with wraparound until it finds a nonzero secondaryBranchState slot.zjIt then walks forward through 12 slots with wraparound until it finds a nonzero secondaryBranchState slot.z9The final slot index is written to selectionBuffer[0x20].readerAlgorithm)zOstream+1 is 0x90, so opcode 0x11 also reads secondaryBranchState at 0x0059e360.z&It reads slot = selectionBuffer[0x20].zJIf secondaryBranchState[slot] == 1, execution falls through to 0x00542b14.zBOtherwise execution jumps to the stream operand target 0x0053f46f.resolvedF)zHruntime contents of secondaryBranchState[0..11] at the 0x005428bc writerz!runtime value of byte(0x00457744)zAprior value of selectionBuffer[0x20] when byte(0x00457744) is setIcontrol-flow proof that 0x005428bc reaches the 0x00542b0c frontier reader5strict source tile coordinate or hotspot for map1_01ablockeda_  The inherited selector is now reduced to a 12-slot secondaryBranchState equation, not a constant transition. The writer can only guarantee a nonzero selected slot; the frontier reader requires that selected slot's value to be exactly 1. Without the runtime secondaryBranchState contents and a strict map1_01a source hotspot, this edge remains blocked.)remainingUnknownspromotionStatus
conclusionc                p    | j                         s|S t        j                  | j                  d            S )Nutf-8encoding)existsjsonloads	read_text)pathfallbacks     M/home/exedev/hwanse/tools/summarize_save_selector_branch_selector_equation.py	load_jsonr5   <   s*    ;;=::dnngn677    c                   | | nt        t        dz  i       } ||nt        t        dz  i       }t        t              }| j	                  d      xs g }| j	                  d      dk(  xrS | j	                  d      dk(  xr= | j	                  d      d	u xr( |j	                  d
      d	u xr |j	                  d      du }|rd	|d<   | j	                  d      | j	                  d      | j	                  d      || j	                  d      d|d<   |j	                  d      |j	                  d
      |j	                  d      d|d<   g d|d<   d|d<   |S d|d<   |S )N+save_selector_predecessor_state_effect.json%save_selector_active_flag_effect.jsonsecondaryBranchStateAfterFillpredecessorSelectorz1:0currentSelectorz2:0allStartsPassReaderTallPredecessorStartsPassApriorSelectionBufferStillPrimaryBlockerUnderPredecessorHypothesisF'equationNarrowedByPredecessorHypothesispredecessorRootHexfillValueHex)r;   rA   rB   r:   r=   predecessorFillHypothesisactiveFlagResolvedStaticDefault)rD   r>   r?   activeFlagEffect)zNprove predecessor 1:0 executes before current selector 2:0 in the normal routez<prove secondaryBranchState persists to 0x005428bc/0x00542b0cr$   r%   z6real selector 2:0 savedata or equivalent runtime tracer'   a&  The 12-slot secondaryBranchState equation is still unresolved as confirmed route proof, but the strongest predecessor-fill hypothesis narrows the value side: if selector 1:0 leaves secondaryBranchState as [1,1,0..], every active-flag/start-slot case selects a slot whose value is 1. Under that hypothesis, the prior selectionBuffer[0x20] value is no longer the primary blocker. Promotion remains blocked on proving 1:0 executes before 2:0, proving the state persists through the gated path to 0x00542b0c, and finding a strict map1_01a source hotspot.r)   )r5   OUTdictSUMMARYget)predecessor_state_effectactive_flag_effectsummarypredecessor_tablepredecessor_narrows_equations        r4   build_summaryrO   B   s    $/ 	!sJJBO  ) 	sDDbI  7mG0445TU[Y[ $$%:;uD 	q$(():;uD	q$(()>?4G	q ""#=>$F	q ""#fgkpp ! $=A9:#;#?#?@U#V":">">?S"T488H->#;#?#?@U#V0
+, 0B/E/EFg/h(:(>(>?Y(ZQcQgQgSR'
"#(
#$. 	 N >C9:Nr6   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g}|j                  d | d   D               |j                  g d       |j                  d | d    D               | j                  d!      r| j                  d"      xs i }| j                  d#      xs i }|j                  dd$dd%|j                  d&       d'|j                  d(       dd)|j                  d*       d+|j                  d,       dd-|j                  d.       d/|j                  d0       d1|j                  d2       g       |j                  g d3       |j                  d4 | d5   D               |j                  d       d6j                  |      S )7Nz(# Save Selector Branch Selector Equation z	- route: r   z- writer: `r   z` `r
   z` via `r   `z- reader: `r   r   r   z- selection offset: `r   z- writer table: `r   r   z- reader table: `r    z- promotion status: r(   z- conclusion: r)   z## Writer Algorithmc              3  &   K   | ]	  }d |   ywz- N .0items     r4   	<genexpr>zmarkdown.<locals>.<genexpr>        D2dVD   r!   )rQ   z## Reader AlgorithmrQ   c              3  &   K   | ]	  }d |   ywrT   rU   rV   s     r4   rY   zmarkdown.<locals>.<genexpr>   rZ   r[   r"   r@   rC   rE   z## Predecessor-Fill Narrowingz- predecessor: `r;   z` root `rA   z	- fill: `rB   z` -> `r:   z- all starts pass reader: r=   z - active flag default resolved: rD   z/- prior selectionBuffer still primary blocker: r?   )rQ   z## Remaining UnknownsrQ   c              3  &   K   | ]	  }d |   ywrT   rU   rV   s     r4   rY   zmarkdown.<locals>.<genexpr>   s     F2dVFr[   r'   
)extendrI   appendjoin)rL   linespredecessoractive_flags       r4   markdownre   ~   se   2

GG$%&
gm,-S9I1J0K7SZ[oSpRqqrs
gm,-S9I1J0K7SZ[oSpRqqrs
(< =>a@
GM233w?Z7[6\\]^
GM233w?Z7[6\\]^
w'89:;
./0

E 
LLD1B)CDD	LL01	LLD1B)CDD{{<=kk"=>D"kk"45;+{/DEFh{_sOtNuuvw78{On?o>ppqr(9N)O(PQ.{?`/a.bc=koo  OR  ?S  >T  U	
 		 
LL23	LLF1D)EFF	LL99Ur6   c                T   d.d}dj                  ddddt        j                  | d          dd	| d
    d| d    d| d    dd| d    d| d    d| d    ddt        j                  | d          dd || d         d || d         g| j                  d      rd |d| j                  di       j                  d       d| j                  di       j                  d        d!| j                  di       j                  d"       d#| j                  di       j                  d$       d%| j                  di       j                  d&       d'| j                  d(i       j                  d)       d*| j                  d(i       j                  d+       g      gng d, || d-               S )/Nc                >    ddj                  d | D              z   dz   S )Nz<ul>rQ   c              3  N   K   | ]  }d t        j                  |       d  yw)z<li>z</li>N)htmlescaperV   s     r4   rY   z(html_page.<locals>.ul.<locals>.<genexpr>   s#     RD$t{{4'8&9 ?Rs   #%z</ul>)ra   )itemss    r4   ulzhtml_page.<locals>.ul   s"    RERRRU\\\r6   r^   zZ<!doctype html><meta charset="utf-8"><title>Save Selector Branch Selector Equation</title>z<style>body{font-family:system-ui,sans-serif;background:#111;color:#eee;max-width:1100px;margin:24px auto;line-height:1.45}code{color:#9bd4ff}</style>z/<h1>Save Selector Branch Selector Equation</h1>z<p><strong>Route:</strong> r   z</p>z"<p><strong>Writer:</strong> <code>r   z</code> <code>r
   z</code> via <code>r   z</code></p>z"<p><strong>Reader:</strong> <code>r   r   r   z <p><strong>Conclusion:</strong> r)   z<h2>Writer Algorithm</h2>r!   z<h2>Reader Algorithm</h2>r"   r@   z#<h2>Predecessor-Fill Narrowing</h2>zpredecessor rC   r;   z root rA   zfill rB   z -> r:   zall starts pass reader: r=   zactive flag default resolved: rE   rD   z-prior selectionBuffer still primary blocker: r?   z<h2>Remaining Unknowns</h2>r'   )rk   z	list[str]returnstr)ra   ri   rj   rI   )rL   rl   s     r4   	html_pagero      s   ] 99f 	a9
%dkk''2B&C%DDI
,W]-C,DNSZ[kSlRmm  AH  I]  A^  @_  _j  	k
,W]-C,DNSZ[kSlRmm  AH  I]  A^  @_  _j  	k
*4;;w|7L+M*NdS#
7$%&#
7$%&. {{DE 6"7;;/JB#O#S#STi#j"kkqryr}r}  Z  \^  s_  sc  sc  dx  sy  rz  {GKK(CRHLL^\]]abibmbm  oJ  LN  cO  cS  cS  Ts  ct  bu  v.w{{;VXZ/[/_/_`u/v.wx4W[[ASUW5X5\5\]~5  5A  BCGKKPbdfDgDkDk  mp  Eq  Dr  s 	 14 	&56 	7&'(7  r6   c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       |d
z  j                  t	        |       d	       y )NT)parentsexist_okz+save_selector_branch_selector_equation.jsonF   )ensure_asciiindentr^   r+   r,   +save_selector_branch_selector_equation.html)mkdir
write_textr/   dumpsro   )rL   out_dirs     r4   write_outputsr{      sf    MM$M.<<HH

7q9D@ I  <<HHSZI[fmHnr6   c                    t        j                         } | j                  dt        t               | j                  dt        t        dz         | j                  dt        t        dz         | j                         }t        t        |j                  i       t        |j                  i             }t        ||j                         t        d|j                  dz          y )	Nz	--out-dir)typedefaultz--predecessor-state-effectr8   z--active-flag-effectr9   z"wrote branch selector equation -> rv   )argparseArgumentParseradd_argumentr   rF   
parse_argsrO   r5   rJ   rK   r{   rz   print)parserargsrL   s      r4   mainr      s    $$&F
$<
44O|I|}
.T3IpCpqD$//4$))2.G '4<<(	.t||>k/k.l
mnr6   __main__)r2   r   r3   rG   rm   rG   )NN)rJ   dict | NonerK   r   rm   rG   )rL   rG   rm   rn   )rL   rG   rz   r   rm   None)rm   r   )__doc__
__future__r   r   ri   r/   pathlibr   __file__resolverq   ROOTrF   rH   r5   rO   re   ro   r{   r   __name__rU   r6   r4   <module>r      s   I "     H~''*
Ul*#*<* l* <	*
 l* &* ,* ,* |* |*  * &v* )* )*  *,  -*8 9*: !	}M*Z8 -1&*9)9#9 
9x#L Foo zF r6   