\iffalse

INSTRUCTIONS: (if this is not ps1, use the right file name)

  Clip out the ********* INSERT HERE ********* bits below and insert
appropriate TeX code.  Once you are done with your file, run

  ``latex template.tex''

from the Athena shell.  If your TeX code is clean, the latex will exit
back to a prompt.  Once this is done, run

  ``dvips template.dvi -o template.ps''

which should print your file to the nearest printer.  There will be
residual files called ps1.log, ps1.aux, and ps1.dvi.  All these can be
deleted, but do not delete ps1.tex.

\fi
\documentclass[11pt]{article}
\usepackage{amsfonts}
\usepackage{latexsym}
\setlength{\oddsidemargin}{.25in}
\setlength{\evensidemargin}{.25in}
\setlength{\textwidth}{6in}
\setlength{\topmargin}{-0.4in}
\setlength{\textheight}{8.5in}

\newcommand{\handout}[5]{
   \renewcommand{\thepage}{Ps6-4-\arabic{page}}
   \noindent
   \begin{center}
   \framebox{
      \vbox{
    \hbox to 5.78in { {\bf 6.823 Computer Architecture} \hfill #2 }
       \vspace{4mm}
       \hbox to 5.78in { {\Large \hfill #5  \hfill} }
       \vspace{2mm}
       \hbox to 5.78in { {\it #3 \hfill #4} }
      }
   }
   \end{center}
   \vspace*{4mm}
}

\newcommand{\ho}[5]{\handout{#1}{#2}{Instructor:
#3}{Teaching Assistant: #4}{Handout #1: #5}}
\newcommand{\al}{\alpha}
\newcommand{\Z}{\mathbb Z}

\begin{document}
\handout{P6}{DUE: 5/8/2002}{Problem Set 6}
{Instructors: Krste Asanovic, Srinivas Devadas}
{Group 18: Timothy Danford, Kilian Pohl, Bryan Russell}


% Problem 4
\section*{Problem 4}
Note: For all answeres below, we assume that during the compilingg stage, the address issues are not resolved jet.  
\bigskip 
{\bf (a)} \\
Transfer  PSO into SC: 
\begin{verbatim}
if (Operation == Write) { 
  If (Next Operation is a Read) {
     Insert a Membar_{wr} 
  } else if (Next Operation is a Write) {
     Insert a Membar_{ww} 
  }  
}
\end{verbatim}
Note : we just consider the following operations Read and Write. Other kinds of operations are ignored. \\
\bigskip\noindent
{\bf (b)} \\
Transfer  WO into SC: 
\begin{verbatim}
if (Operation == Write or Operation == Read) {
  x = (Operation == Write ? w:r)
  If (Next Operation is a Read) {
     Insert a $Membar_{xr}$ 
  } else if (Next Operation is a Write) {
     Insert a $Membar_{xw}$ 
  }  
}
\end{verbatim}
Note : we just consider the following operations Read, Write and Synchronized. Other kinds of operations are ignored. \\
\bigskip\noindent
{\bf (c)} \\
Transfer  RC into SC: 

\begin{verbatim}
# Consider only Read, Write, and Acquire operations.
# For this part only, assume membars are placed before the
# current operation.  Initially, w, r, wr, and rw are zero.
Loop {
  if(op == Read) {
    if(w == 1 && wr == 0)
      Membar_{wr}
      wr = 1
    if(r == 1)
      Membar_{rr}
    r = 1
    rw = 0
  }
  if(op == Write) {
    if(w == 1)
      Membar_{ww}
    if(r == 1 && rw == 0)
      Membar_{rw}
      rw = 1
    w = 1
    wr = 0
  }
  if(op == Acquire) {
    w = 0
    r = 0
  }
  op = NextOperation()
}
\end{verbatim}

\end{document}



