Dynamic code generation? Yay or nay? RRS feed

  • Question

  • I've a project here that simulates some electronic components, that the user can randomly hook up together. Internally, it is represented by a list of tuples that contain a function and a state, and some other things. The simulator code repeatedly runs a loop over that list, calling these functions.

    The issue is, there's a decent amount of overhead, because the calls are inherently indirect calls, and given enough different functions to call, they make the branch predictor of the CPU pretty upset. Given the high frequency rate it runs at, there's plenty of CPU power being wasted on this. As an optimization, I'm looking into generating some simple machine code (whenever the graph changes) that calls the functions directly (more or less pretty much emitting a lot of CALL statements with the direct function addresses). Like this, the branch predictor wouldn't flip its shit and keeps the CPU pipeline filled.

    Would something like this be A-OK with Windows Store certification?

    Thursday, July 4, 2013 1:39 PM


  • I've found the answer to my own question.

    It's "Nay", because there's no way to allocate executable memory (i.e. VirtualAlloc).


    Thursday, July 4, 2013 2:50 PM