The MASM Forum

Miscellaneous => The Orphanage => Topic started by: SoraK05 on August 19, 2014, 02:17:16 AM

Title: Assistance with private emulator
Post by: SoraK05 on August 19, 2014, 02:17:16 AM
Hello.
There is an emulator I am assisting and I am looking for any individuals with ASM experience to lend some advice considering relatively limited room/speed for this. It is not x86 but can assist with a version and any suggestions for less steps is appreciated and I would prefer to communicate through pm for any details.

Thanks.
Title: Re: Assistance with private emulator
Post by: qWord on August 19, 2014, 03:10:21 AM
Quote from: SoraK05 on August 19, 2014, 02:17:16 AMI would prefer to communicate through pm for any details.
So this is a professional request?
Title: Re: Assistance with private emulator
Post by: SoraK05 on August 19, 2014, 03:26:09 AM
Well it is free work in free time, but i'd prefer to keep its details a bit more private :)
If anyone is interested in assisting with optimizing a current emulator thing and also for contribution towards x86 version can pm me. Emulator is currently quite functional but can do with some speedups.
Title: Re: Assistance with private emulator
Post by: SoraK05 on August 20, 2014, 04:46:20 AM
There is actually something very specific at the moment I'd like to optimize and I know how to do this in c++ but not in ASM.
It is to check specific bits like 'if first bit is 0', then 'if second bit is 1' for example instead of reading an entire byte to confirm contents and spare some steps by looking only at specific bit branches.

I have the general information and ASM instructions, but not sure how to check specific bit branches instead of the whole byte with ASM.
It shouldn't vary too much from x86 and any suggestion is appreciated on how to look at specific bits for a branch and proceed for specific instructions instead of an entire byte (for example if all instructions being checked only start with '0' bit instead of checking an entire 8 bit string for the instruction I am looking at and sparing 7 bit steps worth all round at the core on many instruction checks a second).

Right now a whole register content is checked to confirm a specific instruction when read and I would rather check specific bits suiting what I am checking than read the whole content.
Title: Re: Assistance with private emulator
Post by: qWord on August 20, 2014, 05:20:40 AM
Instead of checking single bits for categorization, it is probably faster to use the opcode byte as index in a table of function pointers and then call the corresponding handler.
Title: Re: Assistance with private emulator
Post by: SoraK05 on August 20, 2014, 06:18:01 AM
If you are checking a 32 bit instruction for example against a few possible opcodes to do something respectively, this means checking the 32 bits multiple times against a few 32 bit opcode options in ifs on every instruction being read.

What I am thinking is something similar to 'if first bit is 0' knowing that all the possible opcodes you want to check all start with 0 then you can stop and not bother with checking that 32 bits multiple times for opcode possiblity ifs on every instruction check.
Title: Re: Assistance with private emulator
Post by: habran on August 20, 2014, 09:04:26 AM


     
    shr eax,1
    .if (CARRY?)
        do something
    .endif
Title: Re: Assistance with private emulator
Post by: Gunther on August 20, 2014, 11:17:15 PM
Good catch, Habran.  :t

Gunther
Title: Re: Assistance with private emulator
Post by: dedndave on August 21, 2014, 02:15:38 AM
or use the BT instruction

honestly, i would be inclined to use a look-up table
it may not be smaller, but it would probably be a heck of a lot faster
Title: Re: Assistance with private emulator
Post by: jj2007 on August 21, 2014, 03:32:46 AM
Quote from: dedndave on August 21, 2014, 02:15:38 AM
honestly, i would be inclined to use a look-up table
it may not be smaller, but it would probably be a heck of a lot faster

Depends on the CPU: if there is a given number of bits or bytes defining the opcode, e.g. 6A = push 8bit value, then it could be fast and easy indeed.
Title: Re: Assistance with private emulator
Post by: dedndave on August 21, 2014, 03:55:05 AM
even if the opcode is multiple byte-length
use a look-up table on the first byte
that would direct you to "some code"
if the first byte dictates, "some code" would do it again on another table with the second byte
Title: Re: Assistance with private emulator
Post by: Tedd on August 21, 2014, 04:40:11 AM
Quote from: SoraK05 on August 20, 2014, 04:46:20 AM
There is actually something very specific at the moment I'd like to optimize and I know how to do this in c++ but not in ASM.
It is to check specific bits like 'if first bit is 0', then 'if second bit is 1' for example instead of reading an entire byte to confirm contents and spare some steps by looking only at specific bit branches.

I have the general information and ASM instructions, but not sure how to check specific bit branches instead of the whole byte with ASM.
It shouldn't vary too much from x86 and any suggestion is appreciated on how to look at specific bits for a branch and proceed for specific instructions instead of an entire byte (for example if all instructions being checked only start with '0' bit instead of checking an entire 8 bit string for the instruction I am looking at and sparing 7 bit steps worth all round at the core on many instruction checks a second).

Right now a whole register content is checked to confirm a specific instruction when read and I would rather check specific bits suiting what I am checking than read the whole content.
Be sensible and use a hash/lookup table.