Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.34 KB | None | 0 0
  1. /**************************************************************************
  2. *
  3. * Departamento de Informática de Sistema y Computadores (DISCA)
  4. * Universidad Politécnica de Valencia.
  5. *
  6. * Author: Sergio Sáez (ssaez@disca.upv.es)
  7. *
  8. * File: f_lanzamiento.c
  9. *
  10. * Description:
  11. * Contiene la fase de lanzamiento de instrucciones del algoritmo de
  12. * Tomasulo con especulación
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. *************************************************************************/
  20.  
  21.  
  22. #define f_lanzamiento_alum_C
  23.  
  24. /***** Includes ***********************************************/
  25.  
  26. #include <stddef.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29.  
  30. #include "main.h"
  31. #include "instrucciones.h"
  32. #include "prediccion.h"
  33. #include "presentacion.h"
  34. #include "algoritmo.h"
  35. #include "tipos.h"
  36.  
  37. /***************************************************************
  38. *
  39. * Func: fase_ISS
  40. *
  41. **************************************************************/
  42.  
  43. void fase_ISS_alum() {
  44. /*************************************/
  45. /* Variables locales */
  46. /*************************************/
  47.  
  48. int s;
  49. marca_t b;
  50.  
  51. /*************************************/
  52. /* Cuerpo función */
  53. /*************************************/
  54.  
  55. /* Decodificación */
  56.  
  57. #define I_OP IF_ISS_2.IR.codop
  58. #define I_S1 IF_ISS_2.IR.Rfuente1
  59. #define I_S2 IF_ISS_2.IR.Rfuente2
  60. #define I_D IF_ISS_2.IR.Rdestino
  61. #define I_INM IF_ISS_2.IR.inmediato
  62. #define I_ETIQ IF_ISS_2.IR.etiqueta
  63. #define I_PC IF_ISS_2.PC
  64. #define I_ORDEN IF_ISS_2.orden
  65. #define I_EXC IF_ISS_2.excepcion
  66. #define I_PRED IF_ISS_2.prediccion
  67.  
  68.  
  69. /*** VISUALIZACIÓN ****/
  70. PC_ISS = I_PC;
  71. /**********************/
  72.  
  73. /*** Si no sale correctamente hay que parar */
  74.  
  75. if (Control_2.Cancelar || IF_ISS_2.ignorar) {
  76. Control_1.Parar = NO;
  77. return;
  78. } else if (Control_1.Cancelar || IF_ISS_2.cancelar) { /* Este ciclo está cancelado */
  79. /*** VISUALIZACIÓN ****/
  80. muestra_fase("X", I_ORDEN);
  81. /**********************/
  82. return;
  83. } else if (Control_1.Parar || Control_1.Excepcion) {
  84. /*** VISUALIZACIÓN ****/
  85. muestra_fase("i", I_ORDEN);
  86. /**********************/
  87.  
  88. Control_1.Parar = SI;
  89.  
  90. /* Si la instrucción anterior del mismo grupo se ha parado o
  91. * hay una excepción en el reorder buffer
  92. * entonces esta instrucción ni siquiera se intenta */
  93.  
  94. return;
  95. } /* endif */
  96.  
  97. /*** VISUALIZACIÓN ****/
  98. muestra_fase("I", I_ORDEN);
  99. /**********************/
  100.  
  101. Control_1.Parar = SI;
  102.  
  103. /*** Busca un hueco en la cola */
  104.  
  105. if (RB_long < TAM_REORDER) {
  106. b = RB_fin;
  107. } else {
  108. return; /* No hay huecos en el ROB */
  109. }
  110.  
  111. RB[b].excepcion = I_EXC;
  112. RB[b].prediccion = I_PRED;
  113.  
  114. /*** Lanza la instruccion */
  115.  
  116. switch (I_OP) {
  117. case OP_FP_L_D:
  118. /*** Busca un hueco en el tampón de lectura */
  119. for (s = INICIO_TAMPON_LECT; s <= FIN_TAMPON_LECT; s++)
  120. if (!TL[s].ocupado) break;
  121.  
  122. if (s > FIN_TAMPON_LECT) return;
  123. /* No hay sitio en la estación de reserva */
  124.  
  125. /*** Reserva el tampón de lectura */
  126. TL[s].ocupado = SI;
  127. TL[s].OP = I_OP;
  128. TL[s].rob = b;
  129.  
  130. /*** Operando 1 (en Rint) ***/
  131. if (Rint[I_S1].rob == MARCA_NULA) {
  132. TL[s].Vj = Rint[I_S1].valor;
  133. TL[s].Qj = MARCA_NULA;
  134. } else if (RB[Rint[I_S1].rob].estado == WB) {
  135. TL[s].Vj = RB[Rint[I_S1].rob].valor;
  136. TL[s].Qj = MARCA_NULA;
  137. } else {
  138. TL[s].Qj = Rint[I_S1].rob;
  139. } /* endif */
  140.  
  141. /*** Operando 2 ***/
  142. TL[s].Qk = MARCA_NULA;
  143.  
  144. /*** Desplazamiento */
  145. TL[s].desplazamiento = I_INM;
  146.  
  147. /*** Reserva la entrada del ROB */
  148. RB[b].ocupado = SI;
  149. RB[b].OP = I_OP;
  150. RB[b].dest = I_D;
  151.  
  152. /*** Reserva del registro destino */
  153. if (inst_int(I_OP))
  154. Rint[I_D].rob = b; // OP_LD
  155. else
  156. Rfp[I_D].rob = b; // OP_FP_LD
  157.  
  158. /*** VISUALIZACION ***/
  159. TL[s].estado = PENDIENTE;
  160. TL[s].orden = I_ORDEN;
  161. TL[s].PC = I_PC;
  162. sprintf(TL[s].etiqueta, "%s", I_ETIQ);
  163. RB[b].orden = I_ORDEN;
  164. RB[b].PC = I_PC;
  165. RB[b].estado = EX;
  166.  
  167. break;
  168. case OP_FP_S_D:
  169. /*** Busca un hueco en el tampón de escritura */
  170.  
  171. /* INSERTAR CÓDIGO */
  172. int s = INICIO_TAMPON_ESCR, pos;
  173. for(s; s < FIN_TAMPON_ESCR; s++)
  174. {
  175. if(TE[s].ocupado == NO) break;
  176. }
  177.  
  178.  
  179. /*** Reserva el tampón de escritura */
  180.  
  181. /* INSERTAR CÓDIGO */
  182. TE[s].ocupado = SI;
  183. TE[s].OP = I_OP;
  184.  
  185. /*** Operando 1 (en Rint) ***/
  186.  
  187. /* INSERTAR CÓDIGO */
  188. if (Rint[I_S1].rob == MARCA_NULA) {
  189. RS[s].Vj = Rint[I_S1].valor;
  190. RS[s].Qj = MARCA_NULA;
  191. } else {
  192. if (RB[Rint[I_S1].rob].estado == WB) {
  193. RS[s].Vj = RB[Rint[I_S1].rob].valor;
  194. RS[s].Qj = MARCA_NULA;
  195. } else {
  196. RS[s].Qj = Rint[I_S1].rob;
  197. } /* endif */
  198. }
  199.  
  200. /*** Operando 2 (en Rfp) ***/
  201.  
  202. /* INSERTAR CÓDIGO */
  203. if (Rfp[I_S2].rob == MARCA_NULA) {
  204. TE[s].Vk = Rfp[I_S2].valor;
  205. TE[s].Qk = MARCA_NULA;
  206. } else {
  207. if (RB[Rfp[I_S2].rob].estado == WB) {
  208. TE[s].Vk = Rfp[I_S2].valor;
  209. TE[s].Qk = MARCA_NULA;
  210. } else {
  211. TE[s].Qk = Rfp[I_S2].rob;
  212. } /* endif */
  213. }
  214.  
  215. /*** Desplazamiento */
  216.  
  217. /* INSERTAR CÓDIGO */
  218. TE[s].disp = I_INM;
  219.  
  220. /*** Reserva la entrada del ROB */
  221.  
  222. /* INSERTAR CÓDIGO */
  223. RB[b].ocupado = SI;
  224. RB[b].op = I_OP;
  225. RB[b].dest = s;
  226.  
  227. /*** VISUALIZACION ***/
  228. TE[s].estado = PENDIENTE;
  229. TE[s].orden = I_ORDEN;
  230. TE[s].PC = I_PC;
  231. sprintf(TE[s].etiqueta, "%s", I_ETIQ);
  232. /*** La instrucción de escritura se debe confirmar */
  233. TE[s].confirm = NO;
  234. TE[s].rob = b; /* En teoría, no hace falta para las stores. Se queda aquí por si es necesario en el simulador. */
  235. RB[b].orden = I_ORDEN;
  236. RB[b].PC = I_PC;
  237. RB[b].estado = EX; /* TE */
  238.  
  239. break;
  240. case OP_FP_ADD_D:
  241. case OP_FP_SUB_D:
  242. /*** Busca un hueco en la estación de reserva */
  243.  
  244. /* INSERTAR CÓDIGO */
  245. int s = INICIO_RS_ENTEROS; pos;
  246. for(s; s < FIN_RS_ENTEROS; s++)
  247. {
  248. if(TE[s].ocupado == NO) break;
  249. }
  250.  
  251. /*** Reserva la estación de reserva */
  252.  
  253. /* INSERTAR CÓDIGO */
  254. RS[s].ocupado = SI;
  255. RS[s].OP = I_OP;
  256. RS[s].rob = b;
  257.  
  258.  
  259. /*** Operando 1 (en Rfp) ***/
  260.  
  261. /* INSERTAR CÓDIGO */
  262. if (Rfp[I_S1].rob == MARCA_NULA) {
  263. RS[s].Vj = Rfp[I_S1].valor;
  264. RS[s].Qj = MARCA_NULA;
  265. } else {
  266. if (RB[Rfp[I_S1].rob].estado == WB) {
  267. RS[s].Vj = RB[Rfp[I_S1].rob].valor;
  268. RS[s].Qj = MARCA_NULA;
  269. } else {
  270. RS[s].Qj = Rfp[I_S1].rob;
  271. } /* endif */
  272. }
  273.  
  274.  
  275. /*** Operando 2 (en Rfp) ***/
  276.  
  277. /* INSERTAR CÓDIGO */
  278. if (Rfp[I_S2].rob == MARCA_NULA) {
  279. RS[s].Vk = Rfp[I_S2].valor;
  280. RS[s].Qk = MARCA_NULA;
  281. } else {
  282. if (RB[Rfp[I_S2].rob].estado == WB) {
  283. RS[s].Vk = Rfp[I_S2].valor;
  284. RS[s].Qk = MARCA_NULA;
  285. } else {
  286. RS[s].Qk = Rfp[I_S2].rob;
  287. } /* endif */
  288. }
  289.  
  290. /*** Reserva la entrada del ROB */
  291.  
  292. /* INSERTAR CÓDIGO */
  293. RB[b].ocupado = SI;
  294. RB[b].op = I_OP;
  295. RB[b].dest = I_D;
  296.  
  297. /*** Reserva del registro destino */
  298.  
  299. /* INSERTAR CÓDIGO */
  300. Rfp[I_D].rob=b;
  301.  
  302.  
  303. /*** VISUALIZACION ***/
  304. RS[s].estado = PENDIENTE;
  305. RS[s].orden = I_ORDEN;
  306. RS[s].PC = I_PC;
  307. RB[b].orden = I_ORDEN;
  308. RB[b].PC = I_PC;
  309. RB[b].estado = EX;
  310.  
  311. break;
  312. case OP_FP_MUL_D:
  313. case OP_FP_DIV_D:
  314. /*** Busca un hueco en la estación de reserva */
  315.  
  316. /* INSERTAR CÓDIGO */
  317.  
  318.  
  319. /*** Reserva el operador virtual */
  320.  
  321. /* INSERTAR CÓDIGO */
  322.  
  323.  
  324. /*** Operando 1 ***/
  325.  
  326. /* INSERTAR CÓDIGO */
  327.  
  328.  
  329. /*** Operando 2 ***/
  330.  
  331. /* INSERTAR CÓDIGO */
  332.  
  333.  
  334. /*** Reserva la entrada del ROB */
  335.  
  336. /* INSERTAR CÓDIGO */
  337.  
  338.  
  339. /*** Reserva del registro destino */
  340.  
  341. /* INSERTAR CÓDIGO */
  342.  
  343.  
  344. /*** VISUALIZACION ***/
  345. RS[s].estado = PENDIENTE;
  346. RS[s].orden = I_ORDEN;
  347. RS[s].PC = I_PC;
  348. RB[b].orden = I_ORDEN;
  349. RB[b].PC = I_PC;
  350. RB[b].estado = EX;
  351.  
  352. break;
  353. default:
  354. fprintf(stderr, "ERROR (%s:%d): Operacion no implementada\n", __FILE__, __LINE__);
  355. exit(1);
  356. break;
  357. } /* endswitch */
  358.  
  359. /*** La instrucción se ha lanzado correctamente */
  360.  
  361. Control_1.Parar = NO;
  362. RB_fin = (RB_fin + 1) % TAM_REORDER;
  363. RB_long++;
  364.  
  365. return;
  366.  
  367. } /* end fase_ISS */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement