next up previous contents
Next: Accessing the mask from Up: Accessing the mask from Previous: Setting and checking mask   Contents

Faster bitwise operators

The above mentioned functions for checking and setting the mask are rather inefficient, since they require strings to be compared at each point. A set of faster macros are provided which operate on the mask by performing bit operations directly. In order to use these functions, the bitmasks corresponding to the desired type and it's states need to be obtained using the following functions:

$\textstyle \parbox{\linewidth}{
\vspace{\baselineskip}\noindent\texttt{
CCTK\_I...
...name}] The type for which the bitmask is to be
determined.
\end{description}}}$

$\textstyle \parbox{\linewidth}{
\vspace{\baselineskip}\noindent\texttt{
CCTK\_I...
...{state\_name}] The state whose bitmask is to be determined.
\end{description}}}$

Each of these functions returns a CCTK_INT8 which holds the bitmask corresponding to the given type or state. For example, if a given type uses three bits of the mask, the returned value could be the integer corresponding to the bitfield $001110000$..., where the location of $1$s indicates the bits which have been allocated to the given type. A return value of $0$ indicates that the bitmask could not be determined for some reason (for example, the requested state was not previously registered).

All of the state masks allocated for a given type can be retrieved using the following function:

$\textstyle \parbox{\linewidth}{
\vspace{\baselineskip}\noindent\texttt{
CCTK\_I...
...name}] The type for which the bitmask is to be
determined.
\end{description}}}$

The return value is a list of integers, with a length corresponding to the number of states of the given type. Each of the entries is a bitmask which identifies the state. List entries are returned in the order in which they were originally assigned. This allows for a simple correspondence between states and integers (given by the index of the list entry). A fortran wrapper does not currently exist for this functionality.

The following macros have been defined for fast setting and checking of the mask by direct bitwise operations:

$\textstyle \parbox{\linewidth}{
\vspace{\baselineskip}\noindent\texttt{
void Sp...
...te\_bits}] The bitmask corrsponding to the required
state;
\end{description}}}$

$\textstyle \parbox{\linewidth}{
\vspace{\baselineskip}\noindent\texttt{
int Spa...
...te\_bits}] The bitmask corrsponding to the required
state;
\end{description}}}$

The latter macro returns a 1 if the given state has been set, a 0 otherwise. The type_bits and state_bits can be obtained using the SpaceMask_Get*Bits functions, described above.


next up previous contents
Next: Accessing the mask from Up: Accessing the mask from Previous: Setting and checking mask   Contents