webassembly emitted from emscripten is 32bit and it can be 64bit. The target device for emscripten is Browsers. Why will it even depend on 32bit ,64bit architectures , as the browser interacts with the OS(which interacts with the CPU). Why do we require 32bit 64bit?
Explain
The target device for emscripten is Browsers.
The target is the WASM "runtime", which either interprets the bytecode or does JIT-compiling to transform it to CPU instructions.
as the browser interacts with the OS(which interacts with the CPU)
The browser interacts with the OS to use its APIs to display windows and request memory, but it also interacts directly with the CPU and other hardware.
Why will it even depend on 32bit ,64bit architectures
To be performant, the bytecode will not be interpreted but JIT-compiled for the CPU it is running on. So generally, byte-code generated for a 32-bit environment will run fine on 64-bit systems. Bytecode generated for 64-bit might also run on 32-bit systems but might perform poorly.
WASM is a bytecode representation that can run on any architecture.
WebAssembly’s binary format is designed to be executable efficiently on a variety of [...] instruction set architectures [...].
Execution environments which, despite limited, local, nondeterminism, don’t offer the following characteristics may be able to execute WebAssembly modules nonetheless. In some cases they may have to emulate behavior that the host hardware or operating system don’t offer so that WebAssembly modules execute as-if the behavior were supported. This sometimes will lead to poor performance.
Why have wasm32 and wasm64, instead of just using 8 bytes for storing pointers?
A great number of applications don’t ever need as much as 4 GiB of memory. Forcing all these applications to use 8 bytes for every pointer they store would significantly increase the amount of memory they require, and decrease their effective utilization of important hardware resources such as cache and memory bandwidth. The motivations and performance effects here should be essentially the same as those that motivated the development of the x32 ABI for Linux.