view Paper/memo.txt @ 86:a6135031ce35 default tip

modify
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Sat, 07 Jan 2012 17:43:09 +0900
parents 6e50f1c7f914
children
line wrap: on
line source

\begin{figure}
\begin{footnotesize}
\lstinputlisting[language=c]{source/factorial.cbc}
\caption{階上を計算する CbC プログラムの例}
\label{fig:factorial}
\end{footnotesize}
\end{figure}



\begin{figure}[h]
  \begin{minipage}[b]{.45\textwidth}
    \begin{lstlisting}[caption=CbCコード例,label=code:CbC-example]
__code print_factorial(int prod)
{
  printf("factorial = %d\n",prod);
  exit(0);
}
__code factorial0(int prod, int x)
{
  if ( x >= 1) {
    goto factorial0(prod*x, x-1);
  }else{
    goto print_factorial(prod);
  }
}
__code factorial(int x)
{
  goto factorial0(1, x);
}
    \end{lstlisting}
  \end{minipage}
  \hfill
\end{figure}

\begin{table}[htpb]
  \centering
  \begin{tabular}{|c|c|c|c|c|} \hline
    \multirow{2}{*}{ \backslashbox{CPU/OS}{コンパイラ}  }
              & \multicolumn{3}{c|}{GCC-4.4} & \multirow{2}{*}{micro-c} \\ \cline{2-4}
              &最適化なし&速度最適化&サイズ最適化&  \\ \hline
    x86/Linux & 7.378 & 3.252 &       & 2.890 \\ \hline
   i386/OS X  & 3.890 & 1.827 &       & 2.288 \\ \hline
 x86\_64/OS X  & 4.078 & 1.101 &       &       \\ \hline
  \end{tabular}
  \caption{アーキテクチャ毎のGCCとmicro-cの速度比較(単位: 秒)}
  \label{tab:speed-mc-vs-gcc-4.4}
\end{table}

\begin{table}[htpb]
  \centering
  \begin{tabular}{|c|c|c|c|c|} \hline
    \multirow{2}{*}{ \backslashbox{CPU/OS}{コンパイラ}  }
              & \multicolumn{3}{c|}{GCC-4.6} & \multirow{2}{*}{micro-c} \\ \cline{2-4}
              &最適化なし&速度最適化&サイズ最適化&  \\ \hline
    x86/Linux & 0.829 & 1.768 &       & 2.890 \\ \hline
   i386/OS X  & 0.38 & 0.934 &       & 2.288 \\ \hline
 x86\_64/OS X  & 0.45 8 & 2.896 &       &       \\ \hline
  \end{tabular}
  \caption{アーキテクチャ毎のGCCとmicro-cの速度比較(単位: 秒)}
  \label{tab:speed-mc-vs-gcc-4.6}
\end{table}


\begin{figure}[h]
%\begin{footnotesize}
  \begin{minipage}[b]{.45\textwidth}
    \begin{lstlisting}[caption=スタックの上書きが起こる継続の例,label=code:cs_prog]
__code cs_a(int a, int b) {
        goto cs_b(b, a)
}
    \end{lstlisting}
  \end{minipage}
  \hfill
%\end{footnotesize}
\end{figure}

\begin{verbatim}
__code c1(__code ret(int,void *),void *env) {
    goto ret(1,env);
}

int main() {
    goto c1(__return, __environment);
}
\end{verbatim}

\begin{figure}[h]
\begin{footnotesize}
  \begin{minipage}[b]{.45\textwidth}
    \begin{lstlisting}[caption=環境付き継続を行うコード,label=code:_ret_val]
__label__ _cbc_exit0;
static int retval;
   void _cbc_internal_return(int retval_,
                            void *_envp){
  retval = retval_;
  goto _cbc_exit0;
}
if (0) {
 _cbc_exit0:
  return retval;
 }
_cbc_internal_return;
    \end{lstlisting}
  \end{minipage}
  \hfill
\end{footnotesize}
\end{figure}


\begin{figure}[h]
  \begin{minipage}[b]{.45\textwidth}
    \begin{lstlisting}[caption=typedefrecの例,label=code:typedefrec]
typedefrec void *funcA(int, funcA);

typedefrec struct {
  NODE left;
  NODE right;
} *NODE;
    \end{lstlisting}
  \end{minipage}
  \hfill
\end{figure}




また,比較を行うプログラムは最適化(-O0 オプション)を行わないものと,
速度最適化(-O2 -fomit-frame-pointer)を行うものの2つ,
それと -m32 オプションと -m64 オプションをつけたものそれぞれで行う.

表\ref{tab:speed-mc-vs-gcc-nonopt}が最適化無し,
表\ref{tab:speed-mc-vs-gcc-opt}が速度最適化有りとなる.


\begin{table}[htpb]
  \centering
  \small
  \begin{tabular}{|c|c|c|c|} \hline
      CPU/OS      &GCC-4.4& GCC-4.6 &Micro-C  \\ \hline
%    x86/Linux     & 7.378 & 0.833 & 2.923 \\ \hline
    x86/Linux     & 7.378 &  & 2.923 \\ \hline
% x86\_64/OS X(-m32)& 5.951 & 0.507 &  2.871\\ \hline
 x86\_64/OS X(-m32)& 5.951 &  &  2.871\\ \hline
% x86\_64/OS X      & 6.420 & 0.621 &        \\ \hline
 x86\_64/OS X(-m64)  & 6.420 &  &        \\ \hline
  \end{tabular}
  \caption{アーキテクチャ毎のGCCとmicro-cの速度比較(単位: 秒)(最適化無し)}
  \label{tab:speed-mc-vs-gcc-nonopt}
\end{table}



\section{評価}
今回実装を行った GCC-4.6 ベースのコンパイラを GCC-4.4 ベース,
Micro-C コンパイラとそれぞれ比較を行った.
比較を行うのはクイックソートのプログラムである.
%クイックソートは再帰的にプログラムされる為 CbC に向いている
%プログラムだと言える.
クイックソートは再帰的なプログラムな為スタック操作が行われる為テストに向いている.
比較を行うのは以下のアーキテクチャと OS になる.

%\begin{description}
\begin{itemize}
  \item x86/Linux
  \item x86/OS X
\end{itemize}
%\end{description}


\begin{table}[htpb]
  \centering
  \small
  \begin{tabular}{|c|c|c|c|} \hline
      CPU/OS      &GCC-4.4& GCC-4.6 &Micro-C  \\ \hline
    x86/Linux     & 3.253 & 2.906 & 2.71 \\ \hline
 x86\_64/OS X(-m32)& 2.726 & 2.418 &  2.857\\ \hline
 x86\_64/OS X(-m64) & 1.390 &  1.509 &        \\ \hline
  \end{tabular}
  \caption{アーキテクチャ毎のGCCとmicro-cの速度比較(単位: 秒)(速度最適化)}
  \label{tab:speed-mc-vs-gcc-opt}
\end{table}

GCC-4.6 バージョンの最適化無しは, 末尾最適化が強制的に行われる為
除外している.
最適化有りと無しの比較が 4.6 でも行えないのは残念だが, 最適化の効果はでている
ように思われる.GCC-4.4 では最適化により 2 倍以上の性能がでている.
また 64bit 版の最適化有りは 32bit 版に比べてどちらも 1.6 倍以上の速度がでている
のが確認できた.
Micro-C と比較では GCC の 32bit 版が若干早く, 64bit 版は 2 倍の差がでているのが
確認できた.