|
|
|
|
|
by immibis
317 days ago
|
|
Typically a dynamic language JIT handles this by observing what actual types the operation acts on, then hardcoding fast paths for the one type that's actually used (in most cases) or a few different types. When the type is different each time, it has to actually do the lookup each time - but that's very rare. i.e. if(a->type != int_type || b->type != int_type) abort_to_interpreter(); result = ((intval*)a)->val + ((intval*)b)->val; The CPU does have to execute both lines, but it does them in parallel so it's not as bad as you'd expect. Unless you abort to the interpreter, of course. |
|