No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

40 líneas
1.6KB

  1. import sys, os, random
  2. sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
  3. from helpertest import *
  4. from objfmt import Obj
  5. def make(objfile, base=0x6000):
  6. o = Obj.parse(open(objfile, 'rb').read())
  7. return Helper(o, base, {'C$HIGHMEM': 0xC000, 'C$ERROR': 0xFFF0})
  8. def setup(seed, cpu):
  9. rnd = random.Random(seed)
  10. for i in range(0x0000, 0x0800): cpu.m[i] = rnd.randrange(256)
  11. for i in range(0x8000, 0x8400): cpu.m[i] = rnd.randrange(256)
  12. cpu.m[0xC000] = 0x00; cpu.m[0xC001] = 0xC0 # HIGHMEM = $C000
  13. fp = 0x8000 + rnd.randrange(0, 0x100) # $14/15 frame pointer
  14. cpu.m[0x14] = fp & 255; cpu.m[0x15] = fp >> 8
  15. sp1 = 0x9000 + rnd.randrange(1, 0x100)
  16. cpu.m[0x1A] = sp1 & 255; cpu.m[0x1B] = sp1 >> 8
  17. cpu.m[sp1 - 1] = rnd.randrange(0, 8) * 2 # popped byte $FC
  18. cpu.m[0xFB] = rnd.choice([0, 2, 4, 6, 8, 10])
  19. cpu.sp = 0xF0
  20. cpu.a = rnd.choice([0, 2, 4, 6, 8, 12, 20]) # locals
  21. cpu.x = rnd.choice([0, 2, 4, 10]); cpu.y = rnd.choice([0, 0, 1]) # frame size
  22. return rnd
  23. if __name__ == '__main__':
  24. f = sys.argv[1]
  25. h = make(f)
  26. tot_p = tot_e = 0; N = 200
  27. for seed in range(N):
  28. cpu = CPU(); h.install(cpu); setup(seed, cpu)
  29. a0,x0,y0=cpu.a,cpu.x,cpu.y
  30. c = cpu.call(h.addr('C$105'))
  31. tot_p += c
  32. # epilogue: A = locals, X,Y = frame size as in prolog (caller passes the same numbers)
  33. cpu.a, cpu.x, cpu.y = a0, x0, y0
  34. c2 = cpu.call(h.addr('C$106'))
  35. tot_e += c2
  36. print('prolog avg cycles %.0f epilogue avg cycles %.0f' % (tot_p / N, tot_e / N))

Powered by TurnKey Linux.