\subsection{\index{scan}scan}

SCAN


\begin{tabular}{l}
  {\bf scan[n][r] r2, r1} \\
  {\bf lsb1 r2, r1} \\
  {\bf lsb0 r2, r1} \\
  {\bf msb1 r2, r1} \\
  {\bf msb0 r2, r1} \\
  {\bf slsb1 r2, r1} \\
  {\bf slsb0 r2, r1} \\
  {\bf smsb1 r2, r1} \\
  {\bf smsb0 r2, r1} \\
\end{tabular}


~~~~~~
Computes r1 = scan\_for\_lsb(r2)

~~~~~~
This instruction scans the source operand (r2) for the first set bit, starting
from the LSB, and writes the position of this bit to the destination register 
(r1). If the source is cleared, the result is zero, otherwise the bit \#0 is 
counted as position 1.

~~~~~~
This instruction has options that bit reverse the source and/or complement the
bits, so it can search for the last bit reset for example.

{\bf lsb1} is an alias for {\bf scan}

{\bf lsb0} is an alias for {\bf scann}\\
~~~~~~
This instruction scans the source operand (r2) for the first reset bit,
starting from the LSB, and writes the position of this bit to the destination 
register (r1). If the source is set (all ones), the result is zero, otherwise 
the bit \#0 is counted as position 1.

{\bf msb1} is an alias for {\bf scanr}\\
~~~~~~
This instruction scans the source operand (r2) for the first set bit, starting
from the MSB, and writes the position of this bit to the destination register 
(r1). If the source is cleared, the result is zero, otherwise the bit \#0 is 
counted as position 1.

{\bf msb0} is an alias for {\bf scannr}\\
~~~~~~
This instruction scans the source operand (r2) for the first reset bit, 
starting from the MSB, and writes the position of this bit to the destination 
register (r1). If the source is set (all ones), the result is zero, otherwise 
the bit \#0 is counted as position 1.

\begin{center}

\begin{tabular}{|l|l|l|l|l|l|}
 \hline
\multicolumn{1}{|r| }{size :
} & \multicolumn{1}{c| }{8
} & \multicolumn{1}{c| }{6
} & \multicolumn{1}{c| }{6
} & \multicolumn{1}{c| }{6
} & \multicolumn{1}{c| }{6
 } \\
 \hline
\multicolumn{1}{|r| }{bits :
} & {31 ~ ~ ~ ~ ~ ~ ~ ~ 24
} & {23 ~ ~ ~ ~ ~ ~ 18
} & {17 ~ ~ ~ ~ ~ ~ 12
} & {11 ~ ~ ~ ~ ~ ~ 6
} & {5 ~ ~ ~ ~ ~ ~ 0
 } \\
 \hline
\multicolumn{1}{|r| }{function :
} & \multicolumn{1}{c| }{OP\_SCAN
} & \multicolumn{1}{c| }{Flags
} & \multicolumn{1}{c| }{0
} & \multicolumn{1}{c| }{Reg 2
} & \multicolumn{1}{c| }{Reg 1
}
\\ \hline

\end{tabular}



\begin{tabular}{|l|l|l|l|}
 \hline
\multicolumn{1}{|c| }{~ ~ Flags ~ ~
} & \multicolumn{1}{c| }{Syntax
} & {Values
} & {Function
 } \\
 \hline
\multicolumn{1}{|c| }{23-22
} & {.q, .d or .b postfix
} & {*
} & {Defines the size parameter
 } \\
 \hline
\multicolumn{1}{|c| }{21
} & {s- prefix
} & {1 if set
} & {Defines if the operation is SIMD
 } \\
 \hline
\multicolumn{1}{|c| }{20
} & {(none yet)
} & {0
} & {Reserved
 } \\
 \hline
\multicolumn{1}{|c| }{19
} & {-n postfix
} & {1 if set
} & {Negate the input
 } \\
 \hline
\multicolumn{1}{|c| }{18
} & {-r postfix
} & {1 if set
} & {Bit-Reverse the input
}
\\ \hline

\end{tabular}


{\bf Examples : }
\end{center}

R1 contains 0xFF05891213450100 (in a 64-bit system)

{\tt
{\bf lsb1 r1,r2 }: r2 = 0x9\\
{\bf lsb0 r1,r2 }: r2 = 0x1\\
{\bf msb1 r1,r2 }: r2 = 0x40\\
{\bf msb0 r1,r2 }: r2 = 0x38\\
}

\begin{center}
{\bf Performance (FC0 only) :}
\end{center}


{\em Execution Unit :} Increment Unit\\
{\em Latency :} 1 cycle\\
{\em Throughput :} 1 per cycle per IU.\\

~

\pagebreak


