
    UHjr.                       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dZdd	Zdd
Z	 	 	 d	 	 	 	 	 	 	 ddZddZddZddZddZedk(  r e        yy)z@Combine active-flag evidence with the current selector equation.    )annotationsN)Path)Any   outc                p    | j                         s|S t        j                  | j                  d            S )Nutf-8encoding)existsjsonloads	read_text)pathfallbacks     G/home/exedev/hwanse/tools/summarize_save_selector_active_flag_effect.py	load_jsonr      s*    ;;=::dnngn677    c                    |dz  }t        d      D ]  }|r|dz
  nd}| |   s n t        d      D ]  }|dz   dk\  rdn|dz   }| |   s |S  |S )N      r      r   )range)tablestartslot_s       r   simulate_opcode12_selected_slotr      sv    4<D2Y taxT; 2Y 1H$q$(;K	 Kr   c           
         g }t        d      D ]/  }t        | |      }|j                  dd||| |   | |   dk(  d       1 t        | d      }|j                  ddd|| |   | |   dk(  d       |S )Nr   r   zprior selectionBuffer[0x20])
activeFlagstartSource	startSlotselectedSlotselectedValuereaderFallsThroughr   zforced zero)r   r   append)r   rowsr   selecteds       r   predecessor_table_outcomesr)   #   s    Dr 	25%@8$"8_"'/Q"6
 		 /ua8HKK$ x#Ho2  Kr   c                   | | nt        t        dz  i       } ||nt        t        dz  i       }||nt        t        dz  i       }|j                  d      xs ddgdgdz  z   }t        |      }dgdgd	z  z   dt	        dgdgd	z  z   d      dd
ddddgdgdz  z   dt	        ddgdgdz  z   d      dd
ddg}t        d |D              }d}i ddddd|j                  dd      d|j                  dd      d| j                  dd      d| j                  d      d| j                  d      xs i j                  d      d| j                  d      d | j                  d!      d"| j                  d#      d$|j                  d$d%      d&|j                  d&d'      d(|j                  d)d*      d+|d,|d-|d.|d
d/g d0|d1S )2Nz&save_selector_active_flag_sources.jsonz+save_selector_predecessor_state_effect.jsonz+save_selector_branch_selector_equation.jsonsecondaryBranchStateAfterFillr   r   
      r   FzVopcode 0x12 can select a nonzero state value that is not the reader's required value 1)
stateTabler"   r#   r$   r%   meaningzbthe active flag can change the search start, but it cannot convert state value 2 into pass value 1c              3  &   K   | ]	  }|d      yw)r%   N .0rows     r   	<genexpr>z build_summary.<locals>.<genexpr>b   s     %TCc*>&?%T   aI  The active-selection flag evidence removes one static unknown from the 0x005428bc writer: the EXE/startup default for 0x00457744 is 1, so opcode 0x12 normally starts from the prior selectionBuffer[0x20] value. However, 0x00457744 is also save offset 0x006c and can be overwritten by a loaded save. More importantly, the prior start slot is not the decisive blocker under the strongest predecessor-fill hypothesis: if 1:0 leaves secondaryBranchState as [1,1,0..], both activeFlag=1 for every possible prior slot and activeFlag=0 from zero select a passing slot. Without that predecessor/runtime table proof, opcode 0x12 still only selects a nonzero state, and state value 2 would fail the 0x00542b0c reader. Promotion therefore remains blocked on predecessor execution/state persistence, the gated control path, and a strict map1_01a hotspot.sourcemap1_01atargetmap2_02dwriterVaHex
0x005428bcreaderVaHex
0x00542b0cactiveFlagVaHex
0x00457744activeFlagStaticInitialByteHexactiveFlagSaveOffsetHexactiveFlagSaveSourcesaveOffsetHexactiveFlagResolvedStaticDefaultresolvedStaticDefaultactiveFlagStartupInitVaHexstartupInitVaHexactiveFlagStartupInitCallCountstartupInitCallCountpredecessorSelectorz1:0predecessorRootHex
0x00478364predecessorFillValueHexfillValueHex
0x00000210(secondaryBranchStateAfterPredecessorFilloutcomesallPredecessorStartsPassarbitraryStateCounterexamplesblocked)zNprove predecessor 1:0 executes before current selector 2:0 in the normal routez<prove secondaryBranchState persists to 0x005428bc/0x00542b0czCprove the gated control path reaches the 0x00542b0c frontier readerz1find strict map1_01a source coordinate or hotspot)ApriorSelectionBufferStillPrimaryBlockerUnderPredecessorHypothesispromotionStatusremainingBlockers
conclusion)r   OUTgetr)   r   all)active_flag_sourcespredecessor_state_effectbranch_selector_equationr   rR   arbitrary_state_counterexamplesall_predecessor_starts_passrY   s           r   build_summaryrb   ;   s   
 2E1P-V_66
W <T;_7en;;
f <T;_7en;;
f
 %(()HI^aQRVWXVY\^V^M^E)%0H #b.;QC1#(NAN"'o	
 a&A38+;QFaS2X<MqQ"'{	
'#& #&%T8%T"T	} ** 	/33M<P 	/33M<P	
 	.223DlS 	)*=*A*ABb*c 	"$7$;$;<R$S$YWY#^#^_n#o 	*+>+B+BCZ+[ 	%&9&=&=>P&Q 	)*=*A*ABX*Y 	7;;<QSXY 	6::;OQ]^ 	"#;#?#?P\#] 	3E 	H  	#$?!" 	()H#$ NS$
 !5 r   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%g}| d&   D ]<  }|j                  d'|d(    d)|d*    d)|d+    d)|d,    d)|d-    d)|d.   rd/nd0 d1       > |j                  g d2       | d3   D ]6  }|j                  d'|d+    d)|d,    d)|d-    d)|d.   rd/nd0 d)|d4    d1       8 |j                  g d5       |j                  d6 | d7   D               |j                  d       d8j                  |      S )9Nz"# Save Selector Active Flag Effect z	- route: r7   z -> r9   z- writer/reader: `r;   z` / `r=   `z- active flag: `r?   z
` static `rA   z` save offset `rB   z- startup init: `rG   z` calls rI   z- predecessor: `rK   z` root `rL   z` fill `rN   z- all predecessor starts pass: rS   zL- prior selectionBuffer still primary blocker under predecessor hypothesis: rV   z- promotion status: `rW   rY   z## Predecessor-Fill Outcomeszc| active flag | start source | start slot | selected slot | selected value | reader falls through |z)| ---: | --- | ---: | ---: | ---: | --- |rR   z| r    z | r!   r"   r#   r$   r%   yesnoz |)rd   z2## Counterexamples Without Predecessor Table Proofrd   zP| start slot | selected slot | selected value | reader falls through | meaning |z"| ---: | ---: | ---: | --- | --- |rT   r/   )rd   z## Remaining Blockersrd   c              3  &   K   | ]	  }d |   yw)z- Nr1   r3   items     r   r5   zmarkdown.<locals>.<genexpr>   s     F2dVFr6   rX   
)r&   extendjoin)summarylinesr4   s      r   markdownrp      s   ,

GH%&d78+<*=>
W]34E'-:P9QQRS
7#456jIiAj@kkz  |C  D]  |^  {_  _`  	a
G$@AB(7SsKtJuv
7#89:(7K_C`Baaijq  sL  kM  jN  NO  	P
)'2L*M)NO
VW^  `c  Xd  We  	f
(9 :;1=

&
m3#E& z" 
\"#3s='9&:#c+>N=Os>"#3s?';&<CMaIbhl?mmoq	


 
LL   67 
[!"#c.&9%:#c/>R=SSV01ut<CI?OrS	


 
LL23	LLF1D)EFF	LL99Ur   c                   dj                  d | d   D              }dj                  d | d   D              }dj                  d | d   D              }dj                  d	d
ddt        j                  | d          dt        j                  | d          d| 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%d&d'|d(d)d*|d(d+d,| d-g      S ).Nrk   c              3     K   | ]B  }d |d    dt        j                  |d          d|d    d|d    d|d    d|d   rdnd	 d
 D yw)<tr><td>r    	</td><td>r!   r"   r#   r$   r%   rf   rg   
</td></tr>Nhtmlescaper2   s     r   r5   zhtml_page.<locals>.<genexpr>   s      
 	< ! "{{3}-./ 0;  !>"# $?#$ %01ut< =	
s   AA
rR   c              3     K   | ]<  }d |d    d|d    d|d    d|d   rdnd dt        j                  |d          d	 > y
w)rs   r"   rt   r#   r$   r%   rf   rg   r/   ru   Nrv   r2   s     r   r5   zhtml_page.<locals>.<genexpr>   s|      	 	;  !>"# $?#$ %01ut< ={{3y>*+ ,		s   AArT   rd   c              3  N   K   | ]  }d t        j                  |       d  yw)z<li>z</li>Nrv   ri   s     r   r5   zhtml_page.<locals>.<genexpr>   s#     `4dkk$/06`s   #%rX   zT<!doctype html><meta charset="utf-8"><title>Save Selector Active Flag Effect</title>a(  <style>body{font-family:system-ui,sans-serif;background:#111;color:#eee;max-width:1120px;margin:24px auto;line-height:1.45}table{border-collapse:collapse;width:100%;margin:16px 0 28px}td,th{border:1px solid #444;padding:6px 8px;vertical-align:top}th{background:#202020}code{color:#9bd4ff}</style>z)<h1>Save Selector Active Flag Effect</h1>z
<p>route: r7   z -&gt; r9   z; writer <code>r;   z</code>; reader <code>r=   z</code>.</p>z<p>active flag <code>r?   z</code>; static <code>rA   z</code>; save offset <code>rB   z</code>; startup init <code>rG   z <p>all predecessor starts pass: rS   zL; prior selectionBuffer still primary blocker under predecessor hypothesis: rV   z; promotion status <code>rW   z<p>rY   z</p>z"<h2>Predecessor-Fill Outcomes</h2>z<table><thead><tr><th>active flag</th><th>start source</th><th>start slot</th><th>selected slot</th><th>selected value</th><th>reader falls through</th></tr></thead><tbody>z</tbody></table>z8<h2>Counterexamples Without Predecessor Table Proof</h2>z<table><thead><tr><th>start slot</th><th>selected slot</th><th>selected value</th><th>reader falls through</th><th>meaning</th></tr></thead><tbody>z<h2>Remaining Blockers</h2>z<ul>z</ul>)rm   rw   rx   )rn   outcome_rowscounter_rowsblockerss       r   	html_pager~      s   99 
 :&
 
L 99 	 :;	 	L ww`7K^C_``H99` 	s3
T[[!234GDKKPXHY<Z;[[jkr  tA  lB  kC  CY  Za  bo  Zp  Yq  q}  	~
(9 :;;QRYZzR{Q|  }X  Y`  az  Y{  X|  |X  Y`  a}  Y~  X  K  	L
*73M+N*O  P\  ]d  eh  ]i  \j  jC  DK  L]  D^  C_  _k  	l
dkk',/016, 	wB 	^%
xj#  r   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_active_flag_effect.jsonFr-   )ensure_asciiindentrk   r	   r
   %save_selector_active_flag_effect.html)mkdir
write_textr   dumpsr~   )rn   out_dirs     r   write_outputsr      se    MM$M.66BB

7q9D@ C  66BB9WCU`gBhr   c                     t        j                         } | j                  dt        t               | j                         }t               }t        ||j                         t        d|j                  dz          y )Nz	--out-dir)typedefaultz*wrote save selector active flag effect -> r   )
argparseArgumentParseradd_argumentr   rZ   
parse_argsrb   r   r   print)parserargsrn   s      r   mainr      sc    $$&F
$<DoG'4<<(	6t||Fm7m6n
opr   __main__)r   r   r   r   returnr   )r   	list[int]r   intr   r   )r   r   r   z
list[dict])NNN)r]   dict | Noner^   r   r_   r   r   dict)rn   r   r   str)rn   r   r   r   r   None)r   r   )__doc__
__future__r   r   rw   r   pathlibr   typingr   __file__resolver   ROOTrZ   r   r   r)   rb   rp   r~   r   r   __name__r1   r   r   <module>r      s    F "      H~''*
Ul8
2 (,,0,0M$M)M *M 
	M`(V)Xiq zF r   