General > General Technical Chat
ASM programming is FASCINATING!
<< < (11/24) > >>
mfro:

--- Quote from: Brumby on July 30, 2020, 01:52:34 am ---Doing this requires great care.  If you have any conceivable element of luck in your approach or risk assessment - don't.  It WILL blow up on you.

My advice is - DO NOT do this.

--- End quote ---

It will not even work (out even) for basically all modern CPUs. A dirty trick of the past.
BravoV:

--- Quote from: Brumby on July 30, 2020, 01:52:34 am ---If you are into swinging on monkey bars with 11KV 3 phase on adjacent rungs, then you'll enjoy this...

--- Quote from: peter-h on July 29, 2020, 03:14:17 pm ---- Self modifying code. This is pretty dirty but a great technique for some very fast stuff. Normally one doesn't modify opcodes but modifies the data fields in an instruction. It can speed up code several times.

--- End quote ---
Doing this requires great care.  If you have any conceivable element of luck in your approach or risk assessment - don't.  It WILL blow up on you.

My advice is - DO NOT do this.  Look for a more conventional approach - BUT if you absolutely have to resort to something like this - DOCUMENT THE HELL OUT OF IT!!

--- End quote ---

Its the bread & butter for malware I guess.
tggzzz:

--- Quote from: mfro on July 30, 2020, 06:07:36 am ---
--- Quote from: Brumby on July 30, 2020, 01:52:34 am ---Doing this requires great care.  If you have any conceivable element of luck in your approach or risk assessment - don't.  It WILL blow up on you.

My advice is - DO NOT do this.

--- End quote ---

It will not even work (out even) for basically all modern CPUs. A dirty trick of the past.

--- End quote ---

In that case, how do JIT optimisers for modern language runtimes work? They create code fragments on the fly at runtime, then execute them.

You do, of course have to ensure that there are the necessary memory barrier instructions in the JITter.
mfro:

--- Quote from: tggzzz on July 30, 2020, 06:19:22 am ---
--- Quote from: mfro on July 30, 2020, 06:07:36 am ---
--- Quote from: Brumby on July 30, 2020, 01:52:34 am ---Doing this requires great care.  If you have any conceivable element of luck in your approach or risk assessment - don't.  It WILL blow up on you.

My advice is - DO NOT do this.

--- End quote ---

It will not even work (out even) for basically all modern CPUs. A dirty trick of the past.

--- End quote ---

In that case, how do JIT optimisers for modern language runtimes work? They create code fragments on the fly at runtime.

--- End quote ---

They either have to do (ineffective) cache flushes or use other means to ensure that the icache doesn't contain old code (like executing a sufficient amount of other code first).
Berni:

--- Quote from: mfro on July 30, 2020, 06:07:36 am ---
--- Quote from: Brumby on July 30, 2020, 01:52:34 am ---Doing this requires great care.  If you have any conceivable element of luck in your approach or risk assessment - don't.  It WILL blow up on you.

My advice is - DO NOT do this.

--- End quote ---

It will not even work (out even) for basically all modern CPUs. A dirty trick of the past.

--- End quote ---

It does work on modern CPUs.

It indeed does not make sense to use it for the things that self modifying code was used on 8 bit computers of speeding up things. Doing that on a modern CPU will in most cases just confuse the heck out of its long pipeline.

But JIT interpreters found a new use for this. The program looks at its uncompiled (ie. JavaScipt) or bytecode compiled code(ie .Net) and translates that into machine code instructions, then jumps into those machine instructions and executes them until reaching a part that has not yet been compiled where a jump back into the JIT interpreter is placed, making it compile up some more machine code and jump back in to continue running. This makes for a massive speed boost compared to the oldschool emulation based interpreters.

Another use for self modifying code on modern PCs is game console emulators. Sometimes PCs are too slow to emulate the consoles CPU or GPU in real time, so the emulator works a lot like JIT to translate say PowerPC instructions into x86 instructions on the fly.
Navigation
Message Index
Next page
Previous page
There was an error while thanking
Thanking...

Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod