Skip to content

KZT, fix: Change int64_t to int32_t for signature 'i' and uint64_t to uint32_t for 'u'#295

Merged
luzeng87 merged 1 commit into
lat-opensource:masterfrom
xiangzhai:wrapper
May 21, 2026
Merged

KZT, fix: Change int64_t to int32_t for signature 'i' and uint64_t to uint32_t for 'u'#295
luzeng87 merged 1 commit into
lat-opensource:masterfrom
xiangzhai:wrapper

Conversation

@xiangzhai
Copy link
Copy Markdown
Contributor

Hi,

Please review my patch.

Thanks,
Leslie Zhai

… uint32_t for 'u'

Co-authored-by: sunguoyun <sunguoyun@loongson.cn>
Copy link
Copy Markdown
Contributor

@luzeng87 luzeng87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

审查总结

将 KZT wrapper 中签名字母 i(int)对应的 int64_tint32_tu(unsigned)对应的 uint64_tuint32_t

x86/x86_64 ABI 中 int = 32-bit,unsigned int = 32-bit。旧代码错用 64-bit 类型,导致参数传递和返回值语义偏差。修复正确。

逐项检查

类型定义(8 个 typedef):

  • iFippi_tiFippp_t:返回值和 int 参数全部 int64_t→int32_t ✅
  • vFpppi_tvFppiip_tvFppiiip_tvFppii_t:int 参数 int64_t→int32_t ✅
  • vFpppuuuu_t:unsigned 参数 uint64_t→uint32_t ✅
  • pFppiiiiiip_t:6 个 int 参数 int64_t→int32_t ✅

调用实现(8 个函数体):

  • R_RDI/R_RSI/R_RDX/R_RCX/R_R8/R_R9 的 cast 全部 (int64_t)(int32_t) / (uint64_t)(uint32_t)
  • 栈参数 *(int64_t*)*(int32_t*) / *(uint64_t*)*(uint32_t*)
  • 栈参数偏移 +8+16 未变 — x86_64 栈槽仍为 8 字节对齐,指针算术正确 ✅
  • 返回值 cast (int64_t)(int32_t) — 匹配 int32 返回语义 ✅
  • 未涉及的 vFEpFppL('L'=long)保持不变 ✅

未发现问题

  • 符号扩展:(int32_t)R_RDI 仅取低 32 位,x86_64 ABI 中 int 参数高位未定义,无损失
  • 栈读取:*(int32_t*)(R_RSP + 8) 从 8 字节栈槽读 4 字节,取低 32 位正确
  • 与现有其他 wrapper(pFppL_t 仍用 int64_t/uintptr_t)一致

结论

通过。 正确的 ABI 修复,变更范围精确,无副作用。

@luzeng87 luzeng87 merged commit e644cb4 into lat-opensource:master May 21, 2026
10 checks passed
@xiangzhai xiangzhai deleted the wrapper branch May 21, 2026 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants