You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
resize_memory, memory_size, page_size: opcodes or intrinsic functions? #362
Is there a reason for these to being special opcodes vs just being functions imported from some implementation-provided intrinsic module? I think there are three things to trade off here:
It's simpler in my implementation, and I imagine most others to add an intrinsic function.
A dedicated opcode is more efficient for encoding frequently used operations.
It's simpler to dispatch dedicated opcodes if you want to generate machine code that's not just a call.
I think all three of these opcodes (resize_memory, memory_size, and page_size) could all be intrinsic functions with very little effect on size or speed, so I don't think it's worth having dedicated opcodes for these.
2 of the 3 bullet points in the original post here favor dedicated opcodes, and for the third, it's not clear why intrinsic functions would be easier to implement. And, it keeps the overall system simpler if we don't have multiple kinds of things (operators and intrinsics) that serve the same purpose.
wasm does have intrinsic functions, they're just not called that. stdio.print in the spec interpreter is an example of what I mean by "intrinsic function". It's just a function that's imported from a module defined by the implementation. So a resize_memory intrinsic would look something like this:
stdio.print is a host function, rather than being part of the main wasm spec, and we can have fairly clear criteria for what's a host function and what's not: host functions just do eg. I/O and don't need to interact with core semantics in any special way. resize_memory affects sandboxing, so it is something that many consumers will need to be aware of.
Operations resizing and otherwise manipulating the linear memory are
fundamental to the engine's operation, so I think they make the most sense
as opcodes.
On Mon, Sep 21, 2015 at 6:11 AM, Dan Gohman [email protected]
wrote:
stdio.print is a host function, rather than being part of the main wasm
spec, and we can have fairly clear criteria for what's a host function and
what's not: host functions just do eg. I/O and don't need to interact with
core semantics in any special way. resize_memory affects sandboxing, so it
is something that many consumers will need to be aware of.
—
Reply to this email directly or view it on GitHub #362 (comment).
Why does "fundamental to the engine's operation" mean it needs to be an opcode? We'll eventually have things like dlopen, mmap, and create_thread that are "fundamental to the engine's operation", but they don't need to be opcodes any more than resize_memory does. It can work either way, but I think defining another 20 opcodes for such things would be very unwieldy.
It removes their implementation from the lexer, the parser, the type checker, and the evaluator. Instead, the import matching is extended to call Intrinsics.match_import if the import module is "wasm_intrinsics", and those functions are defined in the spec/intrinsics module. That module is distinct from the host/builtins module to make it clear that they are an integral part of the spec and not something host-specific.
I hope you can see that in this branch adding e.g. a get_external_time function to the Intrinsics module would be pretty simple compared to adding an opcode for it.
On Mon, Sep 21, 2015 at 4:11 PM, Andrew Scheidecker < [email protected]> wrote:
Why does "fundamental to the engine's operation" mean it needs to be an
opcode? We'll eventually have things like dlopen, mmap, and create_thread
that are "fundamental to the engine's operation", but they don't need to be
opcodes any more than resize_memory does. It can work either way, but I
think defining another 20 opcodes for such things would be very unwieldy.
Why exactly would that be unwieldy? Why define a different kind of animal
(i.e. an intrinsic function) that is somehow shaped differently than an
opcode, but is just as mandatory, has a well-defined signature and
well-defined semantics, etc?
It removes their implementation from the lexer, the parser, the type
checker, and the evaluator. Instead, the import matching is extended to
call Intrinsics.match_import if the import module is "wasm_intrinsics",
and those functions are defined in the spec/intrinsics module. That module
is distinct from the host/builtins module to make it clear that they are
an integral part of the spec and not something host-specific.
I hope you can see that in this branch adding e.g. a get_external_time
function to the Intrinsics module would be pretty simple compared to
adding an opcode for it.
I don't see timekeeping and clocks as fundamental to the operation of the
engine in the same was as memory and threads are, but maybe that's just
perspective. In some sense, I'd see clocks and time as optional foreign
functions that don't need to be spec'd. They can be provided by an embedder
of the engine, like printing and IO, and don't really fundamentally alter
the semantics of the state stored in the engine, namely the memory and the
threads running.
I'd propose that operations that cannot be reasonably implemented by the
embedder outside the engine should be considered for opcode status. Along
those lines, altering the size of memory and creating new threads that run
inside the engine seem to fall into consideration for opcode status.
—
Reply to this email directly or view it on GitHub #362 (comment).
Why exactly would that be unwieldy? Why define a different kind of animal
(i.e. an intrinsic function) that is somehow shaped differently than an
opcode, but is just as mandatory, has a well-defined signature and
well-defined semantics, etc?
The advantage is that it uses the machinery already there to declare and call functions defined outside of the WebAssembly module with a verified signature. You don't have to define its syntax or its encoding, just a signature and semantics.
I don't see timekeeping and clocks as fundamental to the operation of the
engine in the same was as memory and threads are, but maybe that's just
perspective. In some sense, I'd see clocks and time as optional foreign
functions that don't need to be spec'd.
It's true that clocks aren't coupled to the operation of the engine, but they're a pretty fundamental component of the execution environment. It would be tragic if WebAssembly didn't standardize them.
I can understand not including I/O in the base standard, but even in that case I think it would be better to define a standard write_debug_output function similar to Windows OutputDebugString or JavaScript console.log.
On Mon, Sep 21, 2015 at 5:29 PM, Andrew Scheidecker < [email protected]> wrote:
Why exactly would that be unwieldy? Why define a different kind of animal
(i.e. an intrinsic function) that is somehow shaped differently than an
opcode, but is just as mandatory, has a well-defined signature and
well-defined semantics, etc?
The advantage is that it uses the machinery already there to declare and
call functions defined outside of the WebAssembly module with a verified
signature. You don't have to define its syntax or its encoding, just a
signature and semantics.
Pick almost any data-only opcode and you could argue the same thing. They
all have a signature in terms of local types. E.g. we discussed for a long
time whether some floating point opcodes like f64_sqrt should be opcodes or
not. There's no reason why would couldn't, e.g. make all the floating point
opcodes into intrinsics.
So what guiding principle do we use to select what's an opcode and what's
an intrinsic function?
I don't see timekeeping and clocks as fundamental to the operation of the
engine in the same was as memory and threads are, but maybe that's just
perspective. In some sense, I'd see clocks and time as optional foreign
functions that don't need to be spec'd.
It's true that clocks aren't coupled to the operation of the engine, but
they're a pretty fundamental component of the execution environment. It
would be tragic if WebAssembly didn't standardize them.
I can understand not including I/O in the base standard, but even in that
case I think it would be better to define a standard write_debug_output
function similar to Windows OutputDebugString or JavaScript console.log.
—
Reply to this email directly or view it on GitHub #362 (comment).
Pick almost any data-only opcode and you could argue the same thing.
It's possible to turn almost anything into calls, but there's a tradeoff:
So what guiding principle do we use to select what's an opcode and what's
an intrinsic function?
I touched on this in my first post, but it's a tradeoff between encoding size and complexity. Opcodes will be more efficient in terms of encoded size and encode/decode speed (to the extent there aren't too many opcodes), and are simpler to match if you're doing something special for them in your code generator or some other AST transform. But I don't think that tradeoff is worthwhile for resize_memory, and maybe not for memory_size and page_size, though that's more questionable.
I tend to prefer representing basic capabilities as functions, or rather syscalls, and not as opcodes. I do think we want to have some nice namespacing, and it would be nice if it all looked like it came from the embedder. For reference, NaCl has a few syscalls.
It's easy to express this in a header file, as a function with usual type signatures. I'm not sure how opcodes would be used from developer's code (inline asm?).
The criteria for what's a host function and what's not is can be pretty clear.
What's missing here are criteria for what would distinguish an "intrinsic" from a builtin operation. The binary encoding has an opcode translation table, so there should be no encoding size or encode/decode speed advantage to making things intrinsics instead of opcodes.
It's pretty easy to expose opcodes to developers, even without inline asm.
I don't think it makes sense for things like mmap or sqrt or resize_memory to be opcodes. It eats up valuable opcode index space and requires decoders, disassemblers, etc to implement them individually. If we make them functions we're eliminating most of those problems.
Because of the opcode translation table, these opcodes don't actually take up any opcode index space. Consumers will have to know their type, but this would be true of intrinsics too, since we'd want to verify that recognized intrinsics match their expected type signatures. Concerning specific functions named above:
sqrt: is an opcode, because it is a single fast instruction on most CPUs. Despite the fact that many programming language syntaxes use call syntax for it instead of giving it its own character, in practice it often serves as a basic floating point operation next to +, -, *, and /.
resize_memory: is an opcode because it changes the semantics of subsequent load and store operations, which is pretty fundamental to wasm implementations.
I think, that every instruction, that can directly be converted to machine-code should be opcode and every instruction, that is OS/Engine-dependent should be an intrinsic-function.
If I understand correctly how (jit-)compilers for wasm are supposed to work, then this seperation will eventually be made if you reuse the same wasm-compiler for different OS/engines of the same architecture: You only have to change the host-specific implementations and leave the architecture-specific stuff alone. If you make this seperation in the language you could have a nice symmetry there: The opcodes are implemented for each architecture; the intrinsics are implemented for each engine.
Because of the opcode translation table, these opcodes don't actually take up any opcode index space.
This isn't true. If a module uses mmap or resize_memory once, those opcodes consume index space in the entire module. An smart encoder (as described in my proposals from a while back) can shift them to the back of the index space to minimize the impact, but this still matters if we end up with dozens of special opcodes.
Consumers will have to know their type, but this would be true of intrinsics too, since we'd want to verify that recognized intrinsics match their expected type signatures.
This is already part of the contract for imports, so I'm not sure what your point is here. My argument was that the opcode itself will have a specific layout, preventing generic decoding, while function calls and imports can be decoded generically. If we introduce a new opcode for every one of these operations, it will break decoding in older wasm implementations.
Also: Making operations like mmap or resize_memory a function instead of an opcode opens up some opportunities for instrumentation and debugging tools, because it's possible to shim those by importing from a new module that forwards to the underlying implementation.
mmap: probably won't be an opcode, because the current thinking is leaning toward having finer-grained opcodes rather than doing everything through a single interface.
This seems to route around my question. Are you saying that it would be an opcode in the sense that we will have a dozen opcodes to do various page-related things?
resize_memory: is an opcode because it changes the semantics of subsequent load and store operations, which is pretty fundamental to wasm implementations.
A callee could invoke the resize_memory opcode though, so I don't see how you avoid any hard work by making it an opcode instead of an intrinsic function.
I think, that every instruction, that can directly be converted to machine-code should be opcode and every instruction, that is OS/Engine-dependent should be an intrinsic-function.
It turns out that sandboxing performance is important enough that JITs can be expected to do architecture-specific things to implement it. OdinMonkey, for example, does different things on each hardware architecture, and the memory-resizing operation needs to be aware of this. Consequently, this distinction isn't as clear as it initially seems.
This isn't true. If a module uses mmap or resize_memory once, those opcodes consume index space in the entire module. An smart encoder (as described in my proposals from a while back) can shift them to the back of the index space to minimize the impact, but this still matters if we end up with dozens of special opcodes.
As you say, lesser-used opcodes can be sorted to the back; this takes them out of the valuable low range. Consequently, even if we do have dozens of lesser-used opcodes, a modest producer can sort them to the back and the more-frequently-used opcodes will be unencumbered.
This is already part of the contract for imports, so I'm not sure what your point is here. My argument was that the opcode itself will have a specific layout, preventing generic decoding, while function calls and imports can be decoded generically. If we introduce a new opcode for every one of these operations, it will break decoding in older wasm implementations.
Some strategies for this are discussed here; there's more design work to be done here, but ultimately: we're surely going to want to add some new opcodes in the future, so we'll need a good solution for this regardless.
Also: Making operations like mmap or resize_memory a function instead of an opcode opens up some opportunities for instrumentation and debugging tools, because it's possible to shim those by importing from a new module that forwards to the underlying implementation.
map_file and resize_memory aren't the only things one can imagine wanting to shim. One might want to instrument loads, stores, or calls too. I am hoping we'll see ideas like these and these become well-supported ways to hook into WebAssembly for debugging, instrumentation, and numerous other purposes.
This seems to route around my question. Are you saying that it would be an opcode in the sense that we will have a dozen opcodes to do various page-related things?
This is FutureFeatures territory and not fully explored yet, but that is the current direction. I pointed it out to emphasize that we're aiming for the builtin operations to be simple primitives that each do one thing, rather than mmap which is fairly complex.
A callee could invoke the resize_memory opcode though, so I don't see how you avoid any hard work by making it an opcode instead of an intrinsic function.
Some embedders may restrict access to the linear memory so that code outside wasm can't access it directly ("If allowed by the module [...]"). In this case, the only way a memory resize can happen is through a resize_memory operator.
I was going to say that I thought putting sqrt into opcodes was a bad idea but then remember my GCC days and it was there and worked well there.
I think it really depends, from what I understand it really will depend on what you want to do in the BE of the compiler. Both systems won't change that much but perhaps we could do testing at some point of binary sizes and performance of both systems.
I feel that the intrinsics will lengthen a bit compile time but the opcodes will augment the binary size (though to be honest, you need to have the call for the intrinsic in place and that encoding might actually outweigh the opcode system).
On the other hand, adding the opcodes means adding more code to the compilers with probably little gains compared to intrinsics if we are going to have that anyway. By writing these lines, I admit I'd lean more towards in putting them in intrinsics :)
Intrinsics vs opcodes ends up being a mess in almost every VM/language that
I've seen, especially when intrinsics are introduced to work around a lack
of extensibility in a binary format, e.g. Java bytecode. Then JITs get into
the game of recognizing and swapping out certain library functions for
inline code. In that situation it's really hard to see what is the "surface
area" of direct support in the engine versus what is "user" or "library"
code. I think we need to keep the line between what is in the engine and
outside the engine very clear.
Having two different mechanisms for specifying an engine-supplied operation
is a burden on both producers and consumers, so an easy way to avoid that
is that the engine has no intrinsic functions--i.e. all engine-supplied
operations are bytecodes. Standard libraries, APIs, and embedders add
functions, but the engine itself doesn't need to recognize any special ones.
We'll need to have a solid story for extensible bytecode anyway, since we
already envision SIMD, threads, and a GC'd heap as extensions beyond 1.0. I
don't think that anyone is suggesting here that those extensions be
expressed purely in terms of new intrinsic functions--some probably
couldn't anyway.
I was going to say that I thought putting sqrt into opcodes was a bad idea
but then remember my GCC days and it was there and worked well there.
I think it really depends, from what I understand it really will depend on
what you want to do in the BE of the compiler. Both systems won't change
that much but perhaps we could do testing at some point of binary sizes and
performance of both systems.
I feel that the intrinsics will lengthen a bit compile time but the
opcodes will augment the binary size (though to be honest, you need to have
the call for the intrinsic in place and that encoding might actually
outweigh the opcode system).
On the other hand, adding the opcodes means adding more code to the
compilers with probably little gains compared to intrinsics if we are going
to have that anyway. By writing these lines, I admit I'd lean more towards
in putting them in intrinsics :)
—
Reply to this email directly or view it on GitHub #362 (comment).
On Mon, Sep 21, 2015 at 10:23 PM, Patrick Uftring [email protected]
wrote:
I think, that every instruction, that can directly be converted to
machine-code should be opcode and every instruction, that is
OS/Engine-dependent should be an intrinsic-function.
If I understand correctly how (jit-)compilers for wasm are supposed to
work, then this seperation will eventually be made if you reuse the same
wasm-compiler for different OS/engines of the same architecture: You only
have to change the host-specific implementations and leave the
architecture-specific stuff alone. If you make this seperation in the
language you could have a nice symmetry there: The opcodes are implemented
for each architecture; the intrinsics are implemented for each engine.
Bounds checking loads and stores will likely be implemented quite
differently on different engines, so I'm not sure this distinction makes
sense. We wouldn't want loads and stores to be calls to intrinsic
functions, because it'd be too slow. JITs can be considered a key part of a
wasm engine and I'm not sure an engine-independent JIT would be the right
boundary for which to design an interface.
—
Reply to this email directly or view it on GitHub #362 (comment).
I also don't see any advantage to segregating between "opcodes" and "builtin functions"; module-local index tables should entirely avoid any index space problems. So +1 for only having 1 thing, not 2.
Activity
jfbastien commentedon Sep 19, 2015
ASTSemantics isn't very clear on whether they're opcodes or intrinsics! I'd been assuming that they were intrinsics as that seems more natural.
AndrewScheidecker commentedon Sep 19, 2015
ASTSemantics says "builtin operation", which is a little ambiguous, but to
me means a special type of AST node with a dedicated opcode.
sunfishcode commentedon Sep 20, 2015
Presently, wasm has no intrinsic functions.
2 of the 3 bullet points in the original post here favor dedicated opcodes, and for the third, it's not clear why intrinsic functions would be easier to implement. And, it keeps the overall system simpler if we don't have multiple kinds of things (operators and intrinsics) that serve the same purpose.
AndrewScheidecker commentedon Sep 20, 2015
wasm does have intrinsic functions, they're just not called that.
stdio.printin the spec interpreter is an example of what I mean by "intrinsic function". It's just a function that's imported from a module defined by the implementation. So a resize_memory intrinsic would look something like this:It's easier to implement such a function because most consumers of the AST don't need to know anything about it.
sunfishcode commentedon Sep 21, 2015
stdio.print is a host function, rather than being part of the main wasm spec, and we can have fairly clear criteria for what's a host function and what's not: host functions just do eg. I/O and don't need to interact with core semantics in any special way. resize_memory affects sandboxing, so it is something that many consumers will need to be aware of.
titzer commentedon Sep 21, 2015
Operations resizing and otherwise manipulating the linear memory are
fundamental to the engine's operation, so I think they make the most sense
as opcodes.
On Mon, Sep 21, 2015 at 6:11 AM, Dan Gohman [email protected]
wrote:
AndrewScheidecker commentedon Sep 21, 2015
Why does "fundamental to the engine's operation" mean it needs to be an opcode? We'll eventually have things like
dlopen,mmap, andcreate_threadthat are "fundamental to the engine's operation", but they don't need to be opcodes any more thanresize_memorydoes. It can work either way, but I think defining another 20 opcodes for such things would be very unwieldy.I made a branch of the spec interpreter with these implemented as intrinsic functions instead of opcodes: AndrewScheidecker/WebAssembly-spec@74c1cfc
It removes their implementation from the lexer, the parser, the type checker, and the evaluator. Instead, the import matching is extended to call
Intrinsics.match_importif the import module is"wasm_intrinsics", and those functions are defined in the spec/intrinsics module. That module is distinct from thehost/builtinsmodule to make it clear that they are an integral part of the spec and not something host-specific.I hope you can see that in this branch adding e.g. a
get_external_timefunction to theIntrinsicsmodule would be pretty simple compared to adding an opcode for it.titzer commentedon Sep 21, 2015
On Mon, Sep 21, 2015 at 4:11 PM, Andrew Scheidecker <
[email protected]> wrote:
Why exactly would that be unwieldy? Why define a different kind of animal
(i.e. an intrinsic function) that is somehow shaped differently than an
opcode, but is just as mandatory, has a well-defined signature and
well-defined semantics, etc?
I'd propose that operations that cannot be reasonably implemented by the
embedder outside the engine should be considered for opcode status. Along
those lines, altering the size of memory and creating new threads that run
inside the engine seem to fall into consideration for opcode status.
AndrewScheidecker commentedon Sep 21, 2015
The advantage is that it uses the machinery already there to declare and call functions defined outside of the WebAssembly module with a verified signature. You don't have to define its syntax or its encoding, just a signature and semantics.
It's true that clocks aren't coupled to the operation of the engine, but they're a pretty fundamental component of the execution environment. It would be tragic if WebAssembly didn't standardize them.
I can understand not including I/O in the base standard, but even in that case I think it would be better to define a standard
write_debug_outputfunction similar to WindowsOutputDebugStringor JavaScriptconsole.log.titzer commentedon Sep 21, 2015
On Mon, Sep 21, 2015 at 5:29 PM, Andrew Scheidecker <
[email protected]> wrote:
So what guiding principle do we use to select what's an opcode and what's
an intrinsic function?
AndrewScheidecker commentedon Sep 21, 2015
It's possible to turn almost anything into calls, but there's a tradeoff:
I touched on this in my first post, but it's a tradeoff between encoding size and complexity. Opcodes will be more efficient in terms of encoded size and encode/decode speed (to the extent there aren't too many opcodes), and are simpler to match if you're doing something special for them in your code generator or some other AST transform. But I don't think that tradeoff is worthwhile for
resize_memory, and maybe not formemory_sizeandpage_size, though that's more questionable.jfbastien commentedon Sep 21, 2015
I tend to prefer representing basic capabilities as functions, or rather syscalls, and not as opcodes. I do think we want to have some nice namespacing, and it would be nice if it all looked like it came from the embedder. For reference, NaCl has a few syscalls.
It's easy to express this in a header file, as a function with usual type signatures. I'm not sure how opcodes would be used from developer's code (inline asm?).
sunfishcode commentedon Sep 21, 2015
The criteria for what's a host function and what's not is can be pretty clear.
What's missing here are criteria for what would distinguish an "intrinsic" from a builtin operation. The binary encoding has an opcode translation table, so there should be no encoding size or encode/decode speed advantage to making things intrinsics instead of opcodes.
It's pretty easy to expose opcodes to developers, even without inline asm.
kg commentedon Sep 21, 2015
I don't think it makes sense for things like mmap or sqrt or resize_memory to be opcodes. It eats up valuable opcode index space and requires decoders, disassemblers, etc to implement them individually. If we make them functions we're eliminating most of those problems.
What's the advantage to making them opcodes?
sunfishcode commentedon Sep 21, 2015
Because of the opcode translation table, these opcodes don't actually take up any opcode index space. Consumers will have to know their type, but this would be true of intrinsics too, since we'd want to verify that recognized intrinsics match their expected type signatures. Concerning specific functions named above:
mmap: probably won't be an opcode, because the current thinking is leaning toward having finer-grained opcodes rather than doing everything through a single interface.
sqrt: is an opcode, because it is a single fast instruction on most CPUs. Despite the fact that many programming language syntaxes use call syntax for it instead of giving it its own character, in practice it often serves as a basic floating point operation next to +, -, *, and /.
resize_memory: is an opcode because it changes the semantics of subsequent load and store operations, which is pretty fundamental to wasm implementations.
pjuftring commentedon Sep 21, 2015
I think, that every instruction, that can directly be converted to machine-code should be opcode and every instruction, that is OS/Engine-dependent should be an intrinsic-function.
If I understand correctly how (jit-)compilers for wasm are supposed to work, then this seperation will eventually be made if you reuse the same wasm-compiler for different OS/engines of the same architecture: You only have to change the host-specific implementations and leave the architecture-specific stuff alone. If you make this seperation in the language you could have a nice symmetry there: The opcodes are implemented for each architecture; the intrinsics are implemented for each engine.
kg commentedon Sep 21, 2015
This isn't true. If a module uses mmap or resize_memory once, those opcodes consume index space in the entire module. An smart encoder (as described in my proposals from a while back) can shift them to the back of the index space to minimize the impact, but this still matters if we end up with dozens of special opcodes.
This is already part of the contract for imports, so I'm not sure what your point is here. My argument was that the opcode itself will have a specific layout, preventing generic decoding, while function calls and imports can be decoded generically. If we introduce a new opcode for every one of these operations, it will break decoding in older wasm implementations.
Also: Making operations like mmap or resize_memory a function instead of an opcode opens up some opportunities for instrumentation and debugging tools, because it's possible to shim those by importing from a new module that forwards to the underlying implementation.
This seems to route around my question. Are you saying that it would be an opcode in the sense that we will have a dozen opcodes to do various page-related things?
A callee could invoke the resize_memory opcode though, so I don't see how you avoid any hard work by making it an opcode instead of an intrinsic function.
sunfishcode commentedon Sep 21, 2015
@pjuftring
It turns out that sandboxing performance is important enough that JITs can be expected to do architecture-specific things to implement it. OdinMonkey, for example, does different things on each hardware architecture, and the memory-resizing operation needs to be aware of this. Consequently, this distinction isn't as clear as it initially seems.
@kg
As you say, lesser-used opcodes can be sorted to the back; this takes them out of the valuable low range. Consequently, even if we do have dozens of lesser-used opcodes, a modest producer can sort them to the back and the more-frequently-used opcodes will be unencumbered.
Some strategies for this are discussed here; there's more design work to be done here, but ultimately: we're surely going to want to add some new opcodes in the future, so we'll need a good solution for this regardless.
map_file and resize_memory aren't the only things one can imagine wanting to shim. One might want to instrument loads, stores, or calls too. I am hoping we'll see ideas like these and these become well-supported ways to hook into WebAssembly for debugging, instrumentation, and numerous other purposes.
This is FutureFeatures territory and not fully explored yet, but that is the current direction. I pointed it out to emphasize that we're aiming for the builtin operations to be simple primitives that each do one thing, rather than mmap which is fairly complex.
Some embedders may restrict access to the linear memory so that code outside wasm can't access it directly ("If allowed by the module [...]"). In this case, the only way a memory resize can happen is through a resize_memory operator.
jcbeyler commentedon Sep 21, 2015
I was going to say that I thought putting sqrt into opcodes was a bad idea but then remember my GCC days and it was there and worked well there.
I think it really depends, from what I understand it really will depend on what you want to do in the BE of the compiler. Both systems won't change that much but perhaps we could do testing at some point of binary sizes and performance of both systems.
I feel that the intrinsics will lengthen a bit compile time but the opcodes will augment the binary size (though to be honest, you need to have the call for the intrinsic in place and that encoding might actually outweigh the opcode system).
On the other hand, adding the opcodes means adding more code to the compilers with probably little gains compared to intrinsics if we are going to have that anyway. By writing these lines, I admit I'd lean more towards in putting them in intrinsics :)
titzer commentedon Sep 22, 2015
Intrinsics vs opcodes ends up being a mess in almost every VM/language that
I've seen, especially when intrinsics are introduced to work around a lack
of extensibility in a binary format, e.g. Java bytecode. Then JITs get into
the game of recognizing and swapping out certain library functions for
inline code. In that situation it's really hard to see what is the "surface
area" of direct support in the engine versus what is "user" or "library"
code. I think we need to keep the line between what is in the engine and
outside the engine very clear.
Having two different mechanisms for specifying an engine-supplied operation
is a burden on both producers and consumers, so an easy way to avoid that
is that the engine has no intrinsic functions--i.e. all engine-supplied
operations are bytecodes. Standard libraries, APIs, and embedders add
functions, but the engine itself doesn't need to recognize any special ones.
We'll need to have a solid story for extensible bytecode anyway, since we
already envision SIMD, threads, and a GC'd heap as extensions beyond 1.0. I
don't think that anyone is suggesting here that those extensions be
expressed purely in terms of new intrinsic functions--some probably
couldn't anyway.
On Tue, Sep 22, 2015 at 12:19 AM, jcbeyler [email protected] wrote:
titzer commentedon Sep 22, 2015
On Mon, Sep 21, 2015 at 10:23 PM, Patrick Uftring [email protected]
wrote:
lukewagner commentedon Sep 22, 2015
I also don't see any advantage to segregating between "opcodes" and "builtin functions"; module-local index tables should entirely avoid any index space problems. So +1 for only having 1 thing, not 2.
sunfishcode commentedon Oct 9, 2015
I believe there's a sufficiently strong consensus here to avoid making a distinction between opcodes and intrinsic functions.
AndrewScheidecker commentedon Oct 12, 2015
FYI there are some references to
sbrkanddlopenbeing intrinsic functions in NonWeb you might want to change.sunfishcode commentedon Oct 13, 2015
I created #405 to update those references. Thanks!