Self-modifying code! The real kind!
Era Scarecrow via Digitalmars-d
digitalmars-d at puremagic.com
Fri Apr 7 13:50:10 PDT 2017
On Friday, 7 April 2017 at 20:43:52 UTC, Stefan Koch wrote:
> On Thursday, 6 April 2017 at 05:36:52 UTC, Swoorup Joshi wrote:
>> Self-modifying might be the answer to all sorts of performance
>> problems due to branching.
>
> No it's not! You are throwing away your i-cache AND mess up the
> branch prediction.
From the opening statement it looks and sounds more like loading
and unloading DLL files... rather than self-modifying code.
Self modifying code isn't really that practical anymore, the
best example working is compressed executables (UPX and similar),
but those only expand optimized code from a compressed cache and
then changes the block to executable, it doesn't really modify
the code at all.
Perhaps an actual use case for self-modifying code would be to
give you a quick & dirty compile for a function, and then work on
optimizing it, then switch the calls appropriately to the new
function once it's optimized, which is more useful to for say JIT
circumstances and emulation, and less in statically known source
code.
More information about the Digitalmars-d
mailing list