Dynamic core optimization

Developer's Forum, for discussion of bugs, code, and other developmental aspects of DOSBox.

Dynamic core optimization

Postby awgamer » 2018-3-29 @ 01:19

I'm still blocked with the issue. Anyway, the point was to do some optimizations to the dynamic recompilation(risc_x86.h,) less bloated in cache and fewer instructions processed, see attached. Optimizations here would diminish cpu spikes, smooth things out, and help in possible thrashing corner cases. There are some spots in decoder.h that could be tightened up as well in the same way like the dyn_read/write_x, which get touched a lot.
Attachments
dosboxcodoptimization.txt
(9.45 KiB) Downloaded 42 times
awgamer
Member
 
Posts: 424
Joined: 2014-7-26 @ 07:42

Re: DOSBox Compilation Guides

Postby Qbix » 2018-3-29 @ 13:51

Interesting, I would have assumed that the compiler did some of these on its own (given the inline and the greater picture)
but I checked the dynrec core x64 and noticed that for smaller functions it is "smart", but for the more complex things (gen_function_raw and such, which is inlined itself), it really starts doing one byte at the time and increase the pointer through a move, increase, move back operation.
Water flows down the stream
How to ask questions the smart way!
User avatar
Qbix
DOSBox Author
 
Posts: 10555
Joined: 2002-11-27 @ 14:50
Location: Fryslan

Re: DOSBox Compilation Guides

Postby awgamer » 2018-3-29 @ 14:34

Yeah, my intent was/is to do the gcc option of spitting out its assembly step to see the difference or not in the code it generates, know for sure at that point. Sounds like this is how you checked?
awgamer
Member
 
Posts: 424
Joined: 2014-7-26 @ 07:42

Re: DOSBox Compilation Guides

Postby Qbix » 2018-3-29 @ 15:31

yeah, I used
Code: Select all
objdump -Mintel -dS core_dynrec.o > test.asm


But it is a bit messy to read due to the optimized code.
I could have used that gcc option to output it directly, but this is easier given that the object files are in my tree normally
Water flows down the stream
How to ask questions the smart way!
User avatar
Qbix
DOSBox Author
 
Posts: 10555
Joined: 2002-11-27 @ 14:50
Location: Fryslan

Re: DOSBox Compilation Guides

Postby awgamer » 2018-3-29 @ 16:19

Yeah, gcc asm output is cryptic but a before and after compare is enough, mostly, for me to follow along. Hopefully I'll work out this annoying permissions issue to play with this myself. Speaking of cryptic, I find some of the changes I did more readable/less spaghetti, shorter than the original, but maybe that's just me:)
awgamer
Member
 
Posts: 424
Joined: 2014-7-26 @ 07:42

Re: DOSBox Compilation Guides

Postby Qbix » 2018-3-29 @ 16:41

It's easier to read with the -Mintel, but the interlinked source (the S) is sometimes a bit off.
Water flows down the stream
How to ask questions the smart way!
User avatar
Qbix
DOSBox Author
 
Posts: 10555
Joined: 2002-11-27 @ 14:50
Location: Fryslan

Re: DOSBox Compilation Guides

Postby awgamer » 2018-3-29 @ 17:24

Another tweak, can pull "if (!dsr2 && (ddr==dsr1) && !imm_size) return;" into the "if (!imm && (gsr1->index!=0x5))" path, no need to do the check for imm_size 1 & 4.

Code: Select all
static void gen_lea(DynReg * ddr,DynReg * dsr1,DynReg * dsr2,Bitu scale,Bits imm) {
   GenReg * gdr=FindDynReg(ddr);
   Bitu imm_size;
   Bit8u rm_base=(gdr->index << 3);
   Bit8u index;
   if (dsr1) {
      GenReg * gsr1=FindDynReg(dsr1);
      if (!imm && (gsr1->index!=0x5)) {
         if (!dsr2 && (ddr==dsr1)) return;      
         imm_size=0;   rm_base+=0x0;         //no imm            
      } else if ((imm>=-128 && imm<=127)) {
         imm_size=1;rm_base+=0x40;         //Signed byte imm
      } else {
         imm_size=4;rm_base+=0x80;         //Signed dword imm
      }   
      index=gsr1->index;   
   } else {
     imm_size=4;
     index=5;
   }   
   if (dsr2) {
      GenReg * gsr2=FindDynReg(dsr2);         
      cache_addw(0x8d|(rm_base+0x4)<<8);   //0x8d=LEA | The sib indicator
      Bit8u sib=(index+(gsr2->index<<3)+(scale<<6)); 
      cache_addb(sib);         
   } else {         
      cache_addw(0x8d|(rm_base+index)<<8);   //LEA | dword imm         
   }   
   switch (imm_size) {
   case 0:   break;
   case 1:cache_addb(imm);break;
   case 4:cache_addd(imm);break;
   }
   ddr->flags|=DYNFLG_CHANGED;
}
awgamer
Member
 
Posts: 424
Joined: 2014-7-26 @ 07:42

Re: DOSBox Compilation Guides

Postby awgamer » 2018-3-29 @ 21:30

cinched up decoder.h
Attachments
decoderoptimization.txt
(12.92 KiB) Downloaded 40 times
awgamer
Member
 
Posts: 424
Joined: 2014-7-26 @ 07:42


Return to DOSBox Development

Who is online

Users browsing this forum: Stiletto and 0 guests