B 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. .In
  2. .SH
  3. B. IMPLEMENTATION
  4. .SH
  5. B.1. Excerpts from the non-optimized EM_table
  6. .PP
  7. Even though the non-optimized version of the EM_table is relatively
  8. straight-forward, examples have never hurt anybody.
  9. One of the simplest instructions is the \*(Siloc\*(So, which appears in
  10. our EM_table as follows:
  11. .DS
  12. \f6
  13. .TA 8 16 24 32 40 48 56 64
  14. C_loc ==> "set $1, T1";
  15. "dec 4, SP";
  16. "st T1, [SP]".
  17. \f1
  18. .DE
  19. Just as \*(SiSP\*(So is an alias for \*(Si%l0\*(So, \*(SiT1\*(So is
  20. an alias for \*(Si%g1\*(So.
  21. A little more complex is the \*(Siadi\*(So which performs integer
  22. addition.
  23. .DS
  24. \f6
  25. C_adi ==> "ld [SP], T1";
  26. "ld [SP+4], T2";
  27. "add T1, T2, T3";
  28. "st T3, [SP+4];
  29. "inc 4, SP".
  30. \f1
  31. .DE
  32. We could go on with even more complex instructions, but since that would
  33. not contribute to anything the reader is referred to the implementation
  34. for more details.
  35. .SH
  36. B.2. Excerpts from the optimized EM_table
  37. .PP
  38. The optimized EM_table uses the cache primitives mentioned in chapter 4.
  39. This means that the \*(Siloc\*(So this time appears as
  40. .DS
  41. \f6
  42. C_loc ==> push_const($1).
  43. \f1
  44. .DE
  45. The \*(Silol\*(So can now be written as
  46. .DS
  47. \f6
  48. C_lol ==> push_reg(LB);
  49. inc_tos($1);
  50. push_const(4);
  51. C_los(4).
  52. \f1
  53. .DE
  54. Due to the law of conservation of misery somebody has to do the dirty work.
  55. In this case, it is the \*(Silos\*(So. To show just a small part of
  56. the implementation of the \*(Silos\*(So:
  57. .DS
  58. \f6
  59. C_los $1 == 4 ==>
  60. if (type_of_tos() == T_cst) {
  61. arith size;
  62. const_str_t n;
  63. size= pop_const();
  64. if (size <= 4) {
  65. reg_t a;
  66. reg_t a;
  67. char *LD;
  68. switch (size) {
  69. case 1: LD = "ldub"; break;
  70. case 2: LD = "lduh"; break;
  71. case 4: LD = "ld"; break;
  72. default: arg_error("C_los", size);
  73. }
  74. a = pop_reg_c13(n);
  75. b = alloc_reg();
  76. "$LD [$a+$n], $b";
  77. push_reg(b);
  78. free_reg(a);
  79. } else ...
  80. \f1
  81. .DE
  82. For the full implementation, the reader is again referred to the actual
  83. implementation. Just to show how other instructions are affected
  84. by the optimization we will show that implementation of the \*(Sitge\*(So
  85. instruction:
  86. .DS
  87. \f6
  88. C_tge ==> {
  89. reg_t a;
  90. reg_t b;
  91. a = pop_reg();
  92. b = alloc_reg();
  93. " tst $a";
  94. " bge,a 1f";
  95. " mov 1, $b"; /* delay slot */
  96. " set 0, $b";
  97. "1:";
  98. free_reg(a);
  99. push_reg(b);
  100. }.
  101. \f1
  102. .DE
  103. .SH
  104. .bp
  105. CREDITS
  106. .PP
  107. In order of appearance:
  108. .TS
  109. center;
  110. r c l.
  111. Original idea - Dick Grune
  112. Design & implementation - Philip Homburg
  113. - Raymond Michiels
  114. Tutor - Dick Grune
  115. Assistant Tutor - Ceriel Jacobs
  116. Proofreading - Dick Grune
  117. - Hans van Eck
  118. .TE
  119. .SH
  120. REFERENCES
  121. .PP
  122. .[
  123. $LIST$
  124. .]