fix(viperc): 位宽探测循环改为固定 64 次上界,修主编译器死循环
- 现象:Phase1 编译到 viperlib.vp 时卡死,栈顶停在 ExprGenOps.vp:1362(我新加的位宽探测 while)
- 原因:`while t != 0 { t = t >> 1 }`(t 为 int64)在生成代码里不收敛(疑似 i64 移位/比较被按窄宽度处理)→ 死循环;改为 `while i < 64 and t > 0` 的固定上界写法,两处(ExprGenOps 运行期常量折叠 / AssignGenMixin 静态求值)一起改
- 遗留待查:该 while 为何不收敛(i64 >> / != 0 的代码生成),属同类“最小宽度”问题面
This commit is contained in:
1 parent
d09b79995d
commit
7da9d7cb0d
2 files changed
+10
-2
No files matched your search
@@ -121,9 +121,13 @@ novirtual class AssignGenMixin:
|
||||
t: int64 = res
|
||||
if res < 0: t = res ^ int64(-1)
|
||||
vw: int = 1 # 符号位
|
||||
while t != 0:
|
||||
# 固定 64 次上界(i64 最多 64 位):不用 `while t != 0` —— 某些代码生成下
|
||||
# i64 的移位/比较不收敛,会死循环。
|
||||
bi: int = 0
|
||||
while bi < 64 and t > 0:
|
||||
vw += 1
|
||||
t = t >> 1
|
||||
bi += 1
|
||||
if vw > w: w = vw
|
||||
if w > 0:
|
||||
if w <= 8: bits_out[0] = 8
|
||||
|
||||
@@ -1358,9 +1358,13 @@ novirtual class ExprGenOps(ExprGenBase.ExprGenBase):
|
||||
t_cf: int64 = cf_v
|
||||
if cf_v < 0: t_cf = cf_v ^ int64(-1)
|
||||
vw_cf: int = 1 # 符号位
|
||||
while t_cf != 0:
|
||||
# 固定 64 次上界(i64 最多 64 位):不用 `while t != 0` —— 某些代码生成下
|
||||
# i64 的移位/比较不收敛,会死循环(现场:主编译器卡死在 ExprGenOps 死循环里)。
|
||||
bi_cf: int = 0
|
||||
while bi_cf < 64 and t_cf > 0:
|
||||
vw_cf += 1
|
||||
t_cf = t_cf >> 1
|
||||
bi_cf += 1
|
||||
if vw_cf > cf_w: cf_w = vw_cf
|
||||
if cf_w <= 8: cf_w = 8
|
||||
elif cf_w <= 16: cf_w = 16
|
||||
|
||||
Reference in new issue
Block a user