Self-Modifying code for user settings optimization

Rikki Cattermole via Digitalmars-d digitalmars-d at puremagic.com
Sat Jan 9 03:38:06 PST 2016


On 10/01/16 12:32 AM, Jason Jeffory wrote:
> On Saturday, 9 January 2016 at 10:41:23 UTC, Rikki Cattermole wrote:
>> I've been looking into this issue for web routing.
>> Over all its definitely more performant.
>>
>> But:
>> - You need some way to generate code
>> - ABI compatibility
>> - Host binary compatibility (not the same as ABI)
>> - Front end for the "language" to specify what to generate
>>
>> I'm either going sljit way or my own.
>> ATM I'm looking at building a c frontend to help with porting of sljit
>> and for the future AOT generation of binaries.
>>
>> Most of the work to get x86 done for sljit has been done, about 2-3k
>> left.
>> https://github.com/rikkimax/sljitd
>>
>> Regarding if CPU's allow for JIT'ing code, yup they do allow it still.
>> If they didn't, that CPU would be next to useless.
>>
>> However, an OS is not required to expose this. But if you're dealing
>> with Windows and *nix. Don't worry about it.
>>
>> If you're interested in working on helping to port sljit please do.
>> Just note that it isn't a very optimized JIT but it is fairly small
>> and easy to use. Important to me is that it can be fully ported to D
>> without much worries unlike LLVM, which is a pain to compile anyway.
>
> Well, I wasn't thinking of interpreted/JIT code but native.
>
> I suppose D could possibly do it with CTFE? (Create the CTFE to keep
> track of the the addresses, if possible, of where the variables are at
> in memory, so they can be updated).
>
> e.g.,
>
> DoSomething(Settings!"Width"); // Somehow puts in a dummy variable and
> keeps track of it's address
>
> x = Settings!Width; // similar but different behavior. Basically turn an
> complex call(dictionary look up or something similar) to a mov x, const
> instruction, etc..
>
> Mainly I'm thinking about switches like
>
> If (Settings["FastCode"])
> {
>
> }
>
> but want to remove the lookup.
>
> Hence maybe something like
>
> if (volatile bool x = TRUE) { }
>
> But then somehow capture x's address(not sure if we could accomplish
> that in D?) which we easily change it's value outside the time critical
> code when needed.
>
>
> Sorry, I can't help with sljit... have way to many things on my plate,
> at some point I might if stuff changes. I'll look into it a little though.
>
> Thanks

What I think you're wanting is a little to 'magical' for compilers 
especially dmd to do.

I would recommend using enum's and static if or just go ahead and set it 
to a global variable.
Enums are free and global variables may have cache misses issue, but it 
will be better then doing an AA lookup every time.


More information about the Digitalmars-d mailing list