\documentclass[11pt]{article}

\usepackage[utf8]{inputenc}

\usepackage{geometry}
\geometry{a4paper}

\usepackage{verbatim}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{mathpartir}
\usepackage{semantic}

\title{HW2 -- Operational Memory Models}
\author{CS 554, Fall 2026\\ Due Sep. 25}
\date{}

\begin{document}
\maketitle
\section{Rules}
\subsection{SC operational model}
\begin{mathpar}
\inference[store]{\sigma_i = (\texttt{store}\ \ell\ v; \sigma_i')}{(\sigma_1 \parallel ... \ \sigma_i \ ... \parallel \sigma_n, m) \rightarrow (\sigma_1 \parallel ... \  \sigma_i' \ ... \parallel \sigma_n, m[\ell \mapsto v])}

\inference[load]{\sigma_i = (r\ \texttt{=}\ \texttt{load}\ \ell; \sigma_i')}{(\sigma_1 \parallel ... \ \sigma_i \ ... \parallel \sigma_n, m) \xrightarrow{R\;r\;m(\ell)} (\sigma_1 \parallel ... \  \sigma_i' \ ... \parallel \sigma_n, m)}
\end{mathpar}

\subsection{TSO operational model}
\begin{mathpar}
\inference[store]{\sigma_i = (\texttt{store}\ \ell\ v; s, b) \and \sigma_i' = (s, b; \ell \mapsto v)}{(\sigma_1 \parallel ... \ \sigma_i \ ... \parallel \sigma_n, m) \rightarrow (\sigma_1 \parallel ... \  \sigma_i' \ ... \parallel \sigma_n, m)}

\inference[propagate]{\sigma_i = (s, ell\mapsto v; b) \and \sigma_i' = (s, b)}{(\sigma_1 \parallel ... \ \sigma_i \ ... \parallel \sigma_n, m) \rightarrow (\sigma_1 \parallel ... \  \sigma_i' \ ... \parallel \sigma_n, m[\ell \mapsto v])}

\inference[load-mem]{\sigma_i = (r\ \texttt{=}\ \texttt{load}\ \ell; s, b) \and \ell \not\in b \and \sigma_i' = (s, b)}{(\sigma_1 \parallel ... \ \sigma_i \ ... \parallel \sigma_n, m) \xrightarrow{R\;r\;m(\ell)} (\sigma_1 \parallel ... \  \sigma_i' \ ... \parallel \sigma_n, m)}

\inference[load-buf]{\sigma_i = (r\ \texttt{=}\ \texttt{load}\ \ell; s, b) \and \text{last }\ell\text{ in }b\text{ is }\ell \mapsto v \and \sigma_i' = (s, b)}{(\sigma_1 \parallel ... \ \sigma_i \ ... \parallel \sigma_n, m) \xrightarrow{R\;r\;v} (\sigma_1 \parallel ... \  \sigma_i' \ ... \parallel \sigma_n, m)}

\inference[fence]{\sigma_i = (\texttt{fence}; s, \cdot) \and \sigma_i' = (s, \cdot)}{(\sigma_1 \parallel ... \ \sigma_i \ ... \parallel \sigma_n, m) \rightarrow (\sigma_1 \parallel ... \  \sigma_i' \ ... \parallel \sigma_n, m)}
\end{mathpar}
Note that $\cdot$ means an empty list.

\subsection{SRA operational model}
\begin{mathpar}
\inference[store]{\sigma_i = (\texttt{store}\ \ell\ v; s, V) \and V(\ell) < t \and (\ell, t) \not\in m \and V' = V[\ell \mapsto t] \and \sigma_i' = (s, V')}{(\sigma_1 \parallel ... \ \sigma_i \ ... \parallel \sigma_n, m) \rightarrow (\sigma_1 \parallel ... \  \sigma_i' \ ... \parallel \sigma_n, m \uplus (\ell, v, t, V'))}

\inference[load]{\sigma_i = (r\ \texttt{=}\ \texttt{load}\ \ell; s, V) \and V(\ell) \leq t \and (\ell, v, t, V') \in m \and \sigma_i' = (s, V \sqcup V')}{(\sigma_1 \parallel ... \ \sigma_i \ ... \parallel \sigma_n, m) \xrightarrow{R\;r\;v} (\sigma_1 \parallel ... \  \sigma_i' \ ... \parallel \sigma_n, m)}
\end{mathpar}

\section{Problems}
This is a written homework with 3 problems, each of which has multiple parts.

\begin{enumerate}
\item Consider the following program:

\begin{tabular}{l || l}
\texttt{store(x, 1)} &\ \texttt{store(y, 1)} \\
\texttt{r1 = load(y)} &\  \texttt{r2 = load(x)}
\end{tabular}

\begin{enumerate}
\item Show a sequence of steps this program can take in the operational SC memory model, producing the outcome where \texttt{r1} is 0 and \texttt{r2} is 1.

\vspace{10em}

\item Show a sequence of steps this program can take in the operational TSO memory model, producing the outcome where \texttt{r1} is 0 and \texttt{r2} is 1.
\vspace{10em}

\item Show a sequence of steps this program can take in the operational TSO memory model, producing the outcome where \texttt{r1} is 0 and \texttt{r2} is 0.

\vspace{10em}

\item Show a sequence of steps this program can take in the operational SRA memory model, producing the outcome where \texttt{r1} is 0 and \texttt{r2} is 0.

\vspace{10em}

\end{enumerate}

\newpage
\item Suppose we changed the operational TSO model's load-mem rule to remove the requirement $\ell \not\in b$.
\begin{enumerate}
\item Intuitively, how would this change the behavior of the machine?

\vspace{12em}

\item Write a concrete program where this change would be visible---i.e., one that can have an outcome under the changed model that isn't possible under the real TSO model.

\vspace{12em}

\end{enumerate}

\newpage
\item Consider the following program:

\begin{tabular}{l || l}
\texttt{store(x, 1)} &\ \texttt{r1 = load(x)} \\
\texttt{store(x, 2)} &\  \texttt{r2 = load(x)}
\end{tabular}

\begin{enumerate}
\item Prove that the outcome where \texttt{r1} is 2 and \texttt{r2} is 1 is impossible in the SRA memory model.

\vspace{12em}

\item Write a modified version of one of the SRA rules that would make the above outcome possible. Show an execution that uses your modified rule to lead to the outcome where \texttt{r1} is 2 and \texttt{r2} is 1.

\vspace{12em}

\item Is there a sequential program that would behave differently in your modified model than in regular SRA? If so, give an example of such a program and the behavior your model allows for it.
\end{enumerate}

\end{enumerate}

\end{document}
