emin_int11

Enjoyyyyyy code redundancy (0x00000)

Aug 12th, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. linking +compile time optimization-generasiya eyni mnemonic instrukturasiyalarin ferqli opcodelarini genersiya ede biler.
  2. Hemcinin bildirdiyiniz state-de COMPILER misprediction-larin yaxud code redundancy ve s. kimi heller ucun fergli opcode-lar genersiya ede biler. Elece NASM, FASM, MASM kimi assemblerlarda.
  3.  
  4. e.g code redundancy (only memory mapping: code models, PIC, GOT blah blah)
  5.  
  6. instruction (format) encoding ---->
  7.  
  8. opcode ModR/M --- SIB - Disp - Imm
  9. 1 byte 1-4 byte 1-4 byte
  10.  
  11.  
  12. 0x3
  13. ADD - Gv, Ev
  14. reg,reg/m32
  15. eax,ebx
  16. 03C3
  17.  
  18. ardiyca
  19.  
  20. add eax,ebx
  21. 0x1 - executable fayldaki opcode.
  22. ADD - Ev, Gv
  23. reg/m32, reg
  24. eax, ebx
  25. 01D8
  26.  
  27. Compiler/Assembler terefinden opcode her iki halda generasiya ede biler ve edirde bezi assembler-lar 03C3 opkodunu bezileride 01D8 opkodunu istifade edir.
  28.  
  29. Hemcinin bu yaxinlarda meqalelerin birinde qarsiladigim alternativ encoding.
  30. Immediate byte operandi ile instruksiyalar ucun alternativ opcode:
  31. add byte[eax],0
  32. 8000 00
  33. add byte[eax],0 (meqale deyir 2ci opcode 64 bit mod ucun invalid sayilir.)
  34. 8200 00
  35.  
  36. 2ci terefden adice Nt kernel-in Wow64 subsystemi uzerinde segment switching ucun 32 --- > 64
  37. FAR calling 2 special segment vasitesi ile edilirdi. Bu halda da Segment selektorlarinin manipulasiyasi mumkundur.
  38.  
  39. Esas meselemiz olan Branch Prediction optimizasiyasi ucun compiler terefinden istifade edilen metodlara baxaq.
  40. Intel terefinden bildirilir performans penalty qarhisinin alinmasi ucun (mispred) ) 'spin-wait loops' texnikasi istifade edilmelidir. Ancaq AMD optimization guide da qeyd etdiyi kimi branch penalty-lerin qarshisinin alinmasi ucun "decoding bandwidth" azaldilmasi ucun 'nop' evezine 'rep' prefixi istifade edilmelidir.
  41. spin-wait loop triggering ucunde 'rep nop' instruksiyasi istifade edilirdi daha sonra Intel eyni opcode ferqli mnemonic elave etdi 'PAUSE'
  42. Ancaq sonradan da `execution time` yaxud `mispred` kimi problemlere gore programmer-ler terefinden secimler ferqlendirildi.
  43. Intel reference: (rep nop)
  44. NOP instruction can be between 0.4-0.5 clocks and PAUSE instruction can consume 38-40 clocks.
  45.  
  46. yaxud ikinci metod Static prediction yeni performans penalty-leri ve yaxud mispred-lari (misal olara Branch Target Buffer uzerinde branch state olmadigi halda) minuimuma endirmek ucun branch states statik hesablanmalidir.
  47.  
  48. Compiler/Assembler optimizasiyasi cox uzun ve derin movzudur men sadece bir nece misal getirdim.
  49.  
  50. e.g unconditional branches:
  51.  
  52. 83 7d 8c 01 cmp DWORD PTR [rbp-0x74],0x1
  53. encoding operand
  54. 75 0f jne 4005e4 <main+0x47>
  55. conditional state
  56.  
  57. 83 7d 8c 00 cmp DWORD PTR [rbp-0x74],0x0
  58. encoding operand
  59. 74 0f je 4005f9 <main+0x5c>
  60. conditional state
Add Comment
Please, Sign In to add comment