\documentclass[11pt]{article}

\usepackage[utf8]{inputenc}

\usepackage{geometry}
\geometry{a4paper}

\usepackage{verbatim}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{mathpartir}
\usepackage{semantic}

\title{HW3 -- Axiomatic Memory Models}
\author{CS 554, Fall 2026\\ Due Oct. 9}
\date{}

\begin{document}
\maketitle
\section{Rules}
\subsection{SC axiomatic model}
\begin{enumerate}
\item There is a total order $\mathsf{to}$ on all operations, consistent with $\mathsf{po}$.
\item Each read $R\ \ell\ v$ has the same value as the immediately preceding write to $\ell$ in $\mathsf{to}$.
\end{enumerate}

\subsection{TSO axiomatic model}
\begin{enumerate}
\item The \emph{preserved program order} ($\mathsf{ppo}$) includes all $\mathsf{po}$ edges \emph{except} those from write operations to read operations.
\item There is a total order $\mathsf{tso}$ on all write operations, consistent with $\mathsf{ppo}$.
\item There is a partial read-from order $\mathsf{rf}$ that orders a write $W\, \ell\ v$ before any reads \emph{in other threads} that read its value. Each read either receives such an $\mathsf{rf}$ edge, or reads the value of the preceding write to the same location in the same thread.
Furthermore, for each pair of a write $W\, \ell\ v$ and a read $R\ \ell\ v$ that reads from it, there must not be another write to the same location ($W\,\ell\ v'$) ordered between them, or ordered after $W\, \ell\ v$ and earlier in the same thread as $R\ \ell\ v$. Equivalently, we can draw a reads-before edge ($\mathsf{rb}$) from each read to the $\mathsf{tso}$-next write to the same location, and there are no cycles in the order $\mathsf{po}_\ell \cup \mathsf{tso} \cup \mathsf{rf} \cup \mathsf{rb}$ (where $\mathsf{po}_\ell$ orders all operations on $\ell$ within the same thread, \emph{including} writes to reads).
\item $\mathsf{hb} := \mathsf{ppo} \cup \mathsf{tso} \cup \mathsf{rf} \cup \mathsf{rb}$ is acyclic.
\end{enumerate}

\subsection{RA axiomatic model}
\begin{enumerate}
\item There is a read-from $\mathsf{rf}$ edge to each read from the write it reads from (i.e., a write to the same location with the same value).
\item $\mathsf{hb} := \mathsf{po} \cup \mathsf{rf}$ is acyclic.
\item ``No intervening writes'': For each location $\ell$, there is a modification order $\mathsf{mo}_\ell$ that is a total order on writes to $\ell$. If $w_1 \xrightarrow{\mathsf{rf}} r$ and $w_1 <_{\mathsf{mo}_\ell} w_2$, then $w_2 \not<_{\mathsf{hb} \cup \mathsf{mo}_\ell} r$. Equivalently, there is a reads-before order $\mathsf{rb}_\ell$ such that if $w_1 \xrightarrow{\mathsf{rf}} r$ and $w_1 \xrightarrow{\mathsf{mo}_\ell} w_2$ then $r \xrightarrow{\mathsf{rb}_\ell} w_2$, and $\mathsf{hb} \cup \mathsf{mo}_\ell \cup \mathsf{rb}_\ell$ is acyclic for each $\ell$.
\end{enumerate}

\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 Draw an execution graph for the axiomatic SC model that justifies the outcome where \texttt{r1} is 0 and \texttt{r2} is 1. Clearly indicate the total order on the operations.

\vspace{20em}

\item Draw an execution graph for the axiomatic TSO model that justifies the outcome where \texttt{r1} is 0 and \texttt{r2} is 1. Clearly indicate the edges that are included in $\mathsf{hb}$.

\vspace{18em}

\item Draw an execution graph for the axiomatic RA model that justifies the outcome where \texttt{r1} is 0 and \texttt{r2} is 1. Clearly indicate the edges that are included in $\mathsf{hb}$.

\vspace{18em}

\end{enumerate}

\newpage
\item Consider the following program:

\begin{tabular}{l || l || l || l}
\texttt{store x 1} &\ \texttt{store y 2} &\ \texttt{r1 = load x} &\ \texttt{r3 = load y}\\
& &\ \texttt{r2 = load y} &\ \texttt{r4 = load x}
\end{tabular}

\begin{enumerate}
\item Prove that the outcome \texttt{r1 = 1}, \texttt{r2 = 0}, \texttt{r3 = 2}, \texttt{r4 = 0} is \textbf{impossible} in the axiomatic TSO model.

\vspace{15em}

\item Prove that the outcome \texttt{r1 = 1}, \texttt{r2 = 0}, \texttt{r3 = 2}, \texttt{r4 = 0} is \textbf{possible} in the axiomatic RA model.

\vspace{15em}

\item What is the key difference between the TSO rules and the RA rules that makes the outcome possible in one but not the other?

\vspace{13em}

\end{enumerate}

\item Consider the following program:

\begin{tabular}{l || l}
\texttt{r1 = load x} &\ \texttt{r2 = load y}\\
\texttt{store y 1} &\ \texttt{store x 1}
\end{tabular}

\begin{enumerate}
\item Prove that the outcome \texttt{r1 = 1}, \texttt{r2 = 1} is \textbf{impossible} in the axiomatic RA model.

\vspace{12em}

\item Let the ``Relaxed'' model be the memory model we get by removing rule 2 from the RA model (so, $\mathsf{hb} := \mathsf{po} \cup \mathsf{rf}$ no longer has to be acyclic). Is the outcome \texttt{r1 = 1}, \texttt{r2 = 1} possible in the Relaxed model? Draw an execution graph that supports your answer.

\vspace{12em}

\item Consider this variation of the program:

\begin{tabular}{l || l}
\texttt{r1 = load x} &\ \texttt{r2 = load y}\\
\texttt{store y r1} &\ \texttt{store x r2}
\end{tabular}

What are the possible outcomes of this program under the Relaxed model? (This is a bit of a trick question, so give it your best shot; it will be graded generously.)

\vspace{13em}

\end{enumerate}

\end{enumerate}

\end{document}
