Count trailing zeros for card bit position

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Fix cflags passing to parser compilation

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Reduce popcount width to minimum required

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Fix c++ detection makefile rules

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Add support for CPPFLAGS

CPPFLAGS will be passed for both c and c++ compilers. That is the
easiest way to modify both so -march=native default is set using CPPFLAGS.

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Move binaries to subdirectory where sources are

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Use pattern substitute to avoid unwanted substring matches

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Move optimization flags before CPPFLAGS to allow overriding

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Add support for multi-versioned objects

Multi-versioned objects allow runtime selection between different
optimizations allowing dealer to use popcount instruction even when
system defaults compiler options don't allow use of the instruction.

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Fix some compiler warnings generated by -Wextra

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Use ctz instead of popcount for permutation

ctz is better supported instruction than popcnt that makes it better
choice for calculating number of lowest set bits.

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Make analyze run a bit faster

Removing unused members from handstat should make remaining fit better
to L0 cache. Another improvement is removing memset because those
positions are overwritten soon in any case.

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Simplify bit permutation code

It is a bit simpler to do lexicographical next bit permutation if
starting from all lowest bits set.

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Calculate hcp only on demand

Calculating hcp is fairly expensive operation involving 4 popcnt and
imul instructions per suit. But rarely all of those would be required so
we can avoid expensive calculation if values are calculated only on
demand and then cached.

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Calculate controls only on demand

Calculating controls isn't as expensive as hcp but it still involves
quite heavy operations. Those are mostly useless calculations for most
of input making on demand calculation and caching more efficient strategy.

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Calculate losers on demand

Loser calculation needs quite many complex operations but it is unlikely
to be required for all suits in input. That makes it more suitable for
on demand calculation and caching.

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Calculate suit length and distribution bit on demand

Suit length calculation is fairly cheap operation so cost of caching it
becomes higher than calculating it again each time. But distribution bit
calculation involves more operations and shape function in input is
likely to be used many times making caching profitable.

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Store per cache value generation to avoid reseting whole cache

Tracking per cache value generation next to actual value is very CPU
cache friendly operation and avoids reseting all unused cached values
for each generated board.

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Allow selecting the initial order of pack

Always starting from same pack order limits possible start orders to the
size of initial seed that is far less than all possible pack orders. But
simple option to allow specifying the order of initial pack allows shuffle
to generate all possible boards in first try.

The initial pack order is kept in order to keep dealer operation
backward compatible.

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>
Import SFMT19937 random number generator

Signed-off-by: Pauli Nieminen <suokkos@gmail.com>