\subsection{\index{popcount}popcount}

\index{population count}
POPulation COUNT


\begin{tabular}{l}
  {\bf popcount (r3,) r2, r1} \\
  {\bf spopcount (r3,) r2, r1} \\
\end{tabular}

~~~~~~
Computes r1 = nb\_bits(r2)-r3 (with saturation)

~~~~~~
{\bf popcount} counts the number of set bits in r2. When the r3 field is 
not zeroed, the contents of the register r3 is substracted to the sum with 
saturation (the result doesn't wrap around if R3 is above the bit sum). The 
result is written to the destination operand (r1). The size flags indicate 
the size of the source operands.


\begin{itemize}
\item The {\bf size }flag indicates that {\bf popcount }performs the
operation on the whole operands or only on a part of the operands.
\item The {\bf SIMD }flag indicates that {\bf popcount }performs
multiple operations on parts of the operand (the size of these
parts is defined by the {\bf size }flags).
\end{itemize}

~~~~~~
{\em Remark :} This instruction is not going to be supported by the first
F-CPU chips because it requires a specialized unit that is not yet designed
and integrated in the FC0. It requires a separate Execution Unit that is a
crossover between the Inc Unit and the Add/Sub Unit, but it does not provide
enough useful instructions (as the Inc Unit does) to justify the high transistor
count in FC0. Anyway, it is going to be implemented at one time or another and 
a lot of algorithms benefit from this instruction so the opcode is reserved 
for the future.

\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\_POPC
} & \multicolumn{1}{c| }{Flags
} & \multicolumn{1}{c| }{Reg 3
} & \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-18
} & {(none yet)
} & {0
} & {Reserved
}
\\ \hline

\end{tabular}


~

{\bf Example : }
\end{center}


R1 contains 0x0123456789ABCDEF

{\tt
{\bf popcount r1,r2 }: r2 = 0x0000000000000020\\
}

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


{\em Execution Unit :} Unknown\\
{\em Latency :} unknown, but it's O(log2(size)) if you wanted to
know (just in case you're not a spook).\\
{\em Throughput :} unknown.\\

~

\pagebreak


