home *** CD-ROM | disk | FTP | other *** search
/ Dream 55 / Amiga_Dream_55.iso / RISCOS / MAGAZINE / NEWS / PCE021.ZIP / Pce021 / Src / cpu / hdr / TempRegs < prev    next >
Text File  |  1998-05-27  |  4KB  |  153 lines

  1. ; TempRegs.h
  2. ; ----------
  3. ;
  4. ; Temporary registers are set up using the TEMPORARY macro, eg to set aside r0 and
  5. ; r3 as temporary registers, the following would be used:
  6. ;   TEMPORARY r0
  7. ;   TEMPORARY r3
  8. ; They can then be allocated and freed using the NEW and DELETE macros. Both
  9. ; require a string parameter, eg:
  10. ;   GBLS reg
  11. ;   MACRO
  12. ;   example $val
  13. ;    NEW reg
  14. ;    mov $reg, #5
  15. ;    mul $val, $reg, $val
  16. ;    DELETE reg
  17. ;   MEND
  18. ; If a routine is called that may corrupt the contents of the temporary registers,
  19. ; the current contents can be saved on the stack using PUSH, and restored using
  20. ; POP. If no temporary registers are currently allocated then the macros will
  21. ; produce no code. The IGNORE macro can be used to stop an allocated register from
  22. ; being stored if needed.  Both PUSH and POP can be supplied with an optional
  23. ; condition code, eg:
  24. ;   PUSH "eq"
  25. ;   POP "lt"
  26.  
  27.  
  28.  GBLA tempregs_list
  29.  GBLA tempregs_used
  30.  GBLA tempregs_store
  31.  
  32.  
  33.  MACRO
  34.  TEMPORARY $tr_arg
  35. tempregs_list SETA tempregs_list :OR: (1 << $tr_arg)
  36.  MEND
  37.  
  38.  MACRO
  39.  ENSURE_UNUSED $tr_arg
  40.   ASSERT (tempregs_used :AND: (1 << $tr_arg)) = 0
  41.  MEND
  42.  
  43.  MACRO
  44.  NEW $tr_arg
  45.   LCLA tr_counter
  46.   LCLA tr_chosen
  47. tr_chosen SETA 255
  48.   WHILE (tr_counter < 32) :LAND: (tr_chosen = 255)
  49.    IF ((tempregs_list :AND: (1 << tr_counter)) /= 0) :LAND: ((tempregs_used :AND: (1 << tr_counter)) = 0)
  50. tr_chosen SETA tr_counter
  51.    ENDIF
  52. tr_counter SETA tr_counter + 1
  53.   WEND
  54.   ASSERT tr_chosen /= 255
  55. tempregs_used SETA tempregs_used :OR: (1 << tr_chosen)
  56. tempregs_store SETA tempregs_store :OR: (1 << tr_chosen)
  57.   IF tr_chosen < 10
  58. $tr_arg SETS "r":CC:("$tr_chosen":RIGHT:1)
  59.   ELSE
  60. tr_chosen SETA tr_chosen - 10
  61. $tr_arg SETS "r1":CC:("$tr_chosen":RIGHT:1)
  62.   ENDIF
  63.  MEND
  64.  
  65.  MACRO
  66.  NEW2 $tr_arg1, $tr_arg2
  67.   ASSERT ((tempregs_list :AND: (1 << $tr_arg2)) /= 0) :LAND: ((tempregs_used :AND: (1 << $tr_arg2)) = 0)
  68. tempregs_used SETA tempregs_used :OR: (1 << $tr_arg2)
  69. tempregs_store SETA tempregs_store :OR: (1 << $tr_arg2)
  70.   IF $tr_arg2 < 10
  71. $tr_arg1 SETS "r":CC:(:STR:($tr_arg2):RIGHT:1)
  72.   ELSE
  73. $tr_arg1 SETS "r":CC:(:STR:(0x$tr_arg2 - 10):RIGHT:1)
  74.   ENDIF
  75.  MEND
  76.  
  77.  MACRO
  78.  DELETE $tr_arg
  79. tempregs_used SETA tempregs_used :AND: :NOT: (1 << $$$tr_arg)
  80. tempregs_store SETA tempregs_store :AND: :NOT: (1 << $$$tr_arg)
  81. $tr_arg SETS "r999"
  82.  MEND
  83.  
  84.  MACRO
  85.  IGNORE $tr_arg
  86. tempregs_store SETA tempregs_store :AND: :NOT: (1 << $$$tr_arg)
  87.  MEND
  88.  
  89.  MACRO
  90.  PUSH $cc
  91.   LCLS push_list
  92.   LCLA tr_counter
  93.   WHILE (tr_counter < 32)
  94.    IF (tempregs_store :AND: (1 << tr_counter)) /= 0
  95.     IF "$push_list" /= ""
  96. push_list SETS "$push_list,"
  97.     ENDIF
  98.     IF tr_counter < 10
  99. push_list SETS "$push_list r":CC:(:STR:($tr_counter):RIGHT:1)
  100.     ELSE
  101. push_list SETS "$push_list r1":CC:(:STR:(0x$tr_counter - 10):RIGHT:1)
  102.     ENDIF
  103.    ENDIF
  104. tr_counter SETA tr_counter + 1
  105.   WEND
  106.   IF "$push_list" /= ""
  107.    stm$cc.fd r13!, {$push_list}
  108.   ENDIF
  109.  MEND
  110.  
  111.  MACRO
  112.  PUSH_EXCEPT $tr_arg, $cc
  113.   LCLA tr_store
  114. tr_store SETA tempregs_store
  115. tempregs_store SETA tempregs_store :AND: :NOT: (1 << $tr_arg)
  116.   PUSH $cc
  117. tempregs_store SETA tr_store
  118.  MEND
  119.  
  120.  MACRO
  121.  POP $cc
  122.   LCLS pop_list
  123.   LCLA tr_counter
  124.   WHILE (tr_counter < 32)
  125.    IF (tempregs_store :AND: (1 << tr_counter)) /= 0
  126.     IF "$pop_list" /= ""
  127. pop_list SETS "$pop_list,"
  128.     ENDIF
  129.     IF tr_counter < 10
  130. pop_list SETS "$pop_list r":CC:(:STR:($tr_counter):RIGHT:1)
  131.     ELSE
  132. pop_list SETS "$pop_list r1":CC:(:STR:(0x$tr_counter - 10):RIGHT:1)
  133.     ENDIF
  134.    ENDIF
  135. tr_counter SETA tr_counter + 1
  136.   WEND
  137.   IF "$pop_list" /= ""
  138.    ldm$cc.fd r13!, {$pop_list}
  139.   ENDIF
  140.  MEND
  141.  
  142.  MACRO
  143.  POP_EXCEPT $tr_arg, $cc
  144.   LCLA tr_store
  145. tr_store SETA tempregs_store
  146. tempregs_store SETA tempregs_store :AND: :NOT: (1 << $tr_arg)
  147.   POP $cc
  148. tempregs_store SETA tr_store
  149.  MEND
  150.  
  151.  
  152.     END
  153.