<commit_before>%
% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
%
% $Id: Costs.lhs,v 1.21 2000/03/23 17:45:17 simonpj Exp $
%
% Only needed in a GranSim setup -- HWL
% ---------------------------------------------------------------------------

\section[Costs]{Evaluating the costs of computing some abstract C code}

This module   provides all necessary  functions for   computing for a given
abstract~C Program the costs of executing that program. This is done by the
exported function:

\begin{quote}
 {\verb type CostRes = (Int, Int, Int, Int, Int)}
 {\verb costs :: AbstractC -> CostRes }
\end{quote}

The meaning of the result tuple is:
\begin{itemize}
 \item The first component ({\tt i}) counts the number of integer,
   arithmetic and bit-manipulating instructions.
 \item The second component ({\tt b}) counts the number of branches (direct
   branches as well as indirect ones).
 \item The third component ({\tt l}) counts the number of load instructions.
 \item The fourth component ({\tt s}) counts the number of store
   instructions.
 \item The fifth component ({\tt f}) counts the number of floating point
   instructions.
\end{itemize}

This function is needed in GranSim for costing pieces of abstract C.

These are first suggestions for scaling the costs. But, this scaling should
be done in the RTS rather than the compiler (this really should be
tunable!):

\begin{pseudocode}

#define LOAD_COSTS		2
#define STORE_COSTS		2
#define INT_ARITHM_COSTS	1
#define GMP_ARITHM_COSTS	3 {- any clue for GMP costs ? -}
#define FLOAT_ARITHM_COSTS	3 {- any clue for float costs ? -}
#define BRANCH_COSTS		2

\end{pseudocode}

\begin{code}
#define ACCUM_COSTS(i,b,l,s,f)	(i+b+l+s+f)

#define NUM_REGS		10 {- PprAbsCSyn.lhs -}	      {- runtime/c-as-asm/CallWrap_C.lc -}
#define RESTORE_COSTS		(Cost (0, 0, NUM_REGS, 0, 0)  :: CostRes)
#define SAVE_COSTS		(Cost (0, 0, 0, NUM_REGS, 0)  :: CostRes)
#define CCALL_COSTS_GUESS	(Cost (50, 0, 0, 0, 0)	      :: CostRes)

module Costs( costs,
	      addrModeCosts, CostRes(Cost), nullCosts, Side(..)
    ) where

#include "HsVersions.h"

import AbsCSyn
import PrimOp		( primOpNeedsWrapper, PrimOp(..) )
import Panic		( trace )

-- --------------------------------------------------------------------------
data CostRes = Cost (Int, Int, Int, Int, Int)
	       deriving (Text)
<commit_msg>[project @ 2000-04-10 13:59:17 by simonmar] Text => Show<commit_after>%
% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
%
% $Id: Costs.lhs,v 1.22 2000/04/10 13:59:17 simonmar Exp $
%
% Only needed in a GranSim setup -- HWL
% ---------------------------------------------------------------------------

\section[Costs]{Evaluating the costs of computing some abstract C code}

This module   provides all necessary  functions for   computing for a given
abstract~C Program the costs of executing that program. This is done by the
exported function:

\begin{quote}
 {\verb type CostRes = (Int, Int, Int, Int, Int)}
 {\verb costs :: AbstractC -> CostRes }
\end{quote}

The meaning of the result tuple is:
\begin{itemize}
 \item The first component ({\tt i}) counts the number of integer,
   arithmetic and bit-manipulating instructions.
 \item The second component ({\tt b}) counts the number of branches (direct
   branches as well as indirect ones).
 \item The third component ({\tt l}) counts the number of load instructions.
 \item The fourth component ({\tt s}) counts the number of store
   instructions.
 \item The fifth component ({\tt f}) counts the number of floating point
   instructions.
\end{itemize}

This function is needed in GranSim for costing pieces of abstract C.

These are first suggestions for scaling the costs. But, this scaling should
be done in the RTS rather than the compiler (this really should be
tunable!):

\begin{pseudocode}

#define LOAD_COSTS		2
#define STORE_COSTS		2
#define INT_ARITHM_COSTS	1
#define GMP_ARITHM_COSTS	3 {- any clue for GMP costs ? -}
#define FLOAT_ARITHM_COSTS	3 {- any clue for float costs ? -}
#define BRANCH_COSTS		2

\end{pseudocode}

\begin{code}
#define ACCUM_COSTS(i,b,l,s,f)	(i+b+l+s+f)

#define NUM_REGS		10 {- PprAbsCSyn.lhs -}	      {- runtime/c-as-asm/CallWrap_C.lc -}
#define RESTORE_COSTS		(Cost (0, 0, NUM_REGS, 0, 0)  :: CostRes)
#define SAVE_COSTS		(Cost (0, 0, 0, NUM_REGS, 0)  :: CostRes)
#define CCALL_COSTS_GUESS	(Cost (50, 0, 0, 0, 0)	      :: CostRes)

module Costs( costs,
	      addrModeCosts, CostRes(Cost), nullCosts, Side(..)
    ) where

#include "HsVersions.h"

import AbsCSyn
import PrimOp		( primOpNeedsWrapper, PrimOp(..) )
import Panic		( trace )

-- --------------------------------------------------------------------------
data CostRes = Cost (Int, Int, Int, Int, Int)
	       deriving (Show)

{'fraction_non_alphanumeric': 0.16336424957841483, 'fraction_numerical': 0.022765598650927487, 'mean_word_length': 2.8861588861588863, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2737484', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1540, 'n_words': 572}