WebAssembly:是否可以使用 2x i32.store 而不是一个 i64.store?
WebAssembly: Is it possible to use 2x i32.store instead of one i64.store?
如果栈上有一个i64,是否可以使用两个i32.store
到后续的内存索引将i64写入内存?或者这不再是一个有效的模块?
==i32==|==i32==
======i64======
两个后续的 i32.store 操作是有效的,只要你在堆栈上有两个值。但最终结果将与 i64.store 不同。您将需要执行移位操作来存储低位字节然后是高位字节。
;; the value to store
i64.const 0x11223344556677
;; storage offset
i32.const 0
;; store
i32.store
;; load the value again
i64.const 0x11223344556677
;; the number of bits to shift by
i32.const 32
;; shift
i32.shr_u
;; storage offset
i32.const 4
;; store
i32.store
您可能会使用本地来避免加载相同的号码两次。
不,您不能假设堆栈操作数位于连续的内存中——或者根本不在内存中,因为实际上它们通常位于单独的 CPU 寄存器中。因此,隐式 "merging" 操作数堆栈中的两个 i32 操作数就好像它们是单个 i64 是不可能的。您需要将它们分开存放。同样,反过来。
如果栈上有一个i64,是否可以使用两个i32.store
到后续的内存索引将i64写入内存?或者这不再是一个有效的模块?
==i32==|==i32==
======i64======
两个后续的 i32.store 操作是有效的,只要你在堆栈上有两个值。但最终结果将与 i64.store 不同。您将需要执行移位操作来存储低位字节然后是高位字节。
;; the value to store
i64.const 0x11223344556677
;; storage offset
i32.const 0
;; store
i32.store
;; load the value again
i64.const 0x11223344556677
;; the number of bits to shift by
i32.const 32
;; shift
i32.shr_u
;; storage offset
i32.const 4
;; store
i32.store
您可能会使用本地来避免加载相同的号码两次。
不,您不能假设堆栈操作数位于连续的内存中——或者根本不在内存中,因为实际上它们通常位于单独的 CPU 寄存器中。因此,隐式 "merging" 操作数堆栈中的两个 i32 操作数就好像它们是单个 i64 是不可能的。您需要将它们分开存放。同样,反过来。