opstats.rs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. use codegen::gen_increment_mem32;
  2. use global_pointers;
  3. use wasmgen::module_init::WasmBuilder;
  4. pub fn gen_opstats(builder: &mut WasmBuilder, mut instruction: u32) {
  5. if !cfg!(debug_assertions) {
  6. return;
  7. }
  8. let mut is_0f = false;
  9. for _ in 0..4 {
  10. let opcode = instruction & 0xFF;
  11. instruction >>= 8;
  12. // TODO:
  13. // - If instruction depends on middle bits of modrm_byte, split
  14. // - Split depending on memory or register variant
  15. // - If the instruction uses 4 or more prefixes, only the prefixes will be counted
  16. if is_0f {
  17. gen_increment_mem32(builder, global_pointers::OPSTATS_BUFFER_0F + 4 * opcode);
  18. break;
  19. }
  20. else {
  21. gen_increment_mem32(builder, global_pointers::OPSTATS_BUFFER + 4 * opcode);
  22. if opcode == 0x0F {
  23. is_0f = true;
  24. }
  25. else if opcode == 0x26
  26. || opcode == 0x2E
  27. || opcode == 0x36
  28. || opcode == 0x3E
  29. || opcode == 0x64
  30. || opcode == 0x65
  31. || opcode == 0x66
  32. || opcode == 0x67
  33. || opcode == 0xF0
  34. || opcode == 0xF2
  35. || opcode == 0xF3
  36. {
  37. // prefix
  38. }
  39. else {
  40. break;
  41. }
  42. }
  43. }
  44. }