User manual
PAL tutorial
DsmInstance *Instance;
DsmPortS2H *DataOutPort;
DsmPortS2H *PatternOutPort;
DsmPortH2S *MatchInPort;
int DsmTutorial (DsmInterface Interface, void *InterfaceData)
{
DsmWord Data[MAX_DATA_LENGTH_WORDS];
DsmWord Pattern;
int i, DataLengthWords;
DsmSetDefaultErrorHandler ();
DsmInit (Interface, InterfaceData, H2S_COUNT, S2H_COUNT,
&Instance);
DsmPortS2HOpen (Instance, DATA_S2H_PORT, &DataOutPort);
DsmPortS2HOpen (Instance, PATTERN_S2H_PORT, &PatternOutPort);
DsmPortH2SOpen (Instance, MATCH_H2S_PORT, &MatchInPort);
// Send pattern.
// Send data stream.
DsmPortS2HClose (DataOutPort);
DsmPortS2HClose (PatternOutPort);
DsmPortH2SClose (MatchInPort);
DsmExit (Instance);
}
Again, reading and writing is done using
DsmRead() and DsmWrite().
2.1.4 Part 3 of the tutorial
Part 3 of the DSM pattern matching tutorial implements a best-case matching algorithm, which finds the
closest match in a stream of data to a pattern (fuzzy matching). This is then performed in software and
the speed of the software implementation and the hardware implementation is compared.
The algorithm used in Part3 of the tutorial example is a simple XNOR of the pattern as it is shifted
through a series of shift registers. The resulting pattern is fed into a population count algorithm, which
results in a count of the number of matching bits.
When the population count is deduced, the best case population count is compared with the current
population count, and if the new count is better, then the offset of the count is stored in the best case
count register.
When the stream is complete, the best-case count is returned to the host, along with the offset where it
occurred.
The DSM framework is the same as in Part 2 of this tutorial.
Depending on the platform, the speed-up of using a hardware/software co-design for this algorithm is
upwards of two orders of magnitude compared to a purely software implementation. In addition, the
co-design implementation runs in the same number of clock cycles as the pattern length increases,
giving an asymptotic improvement in complexity, O(1) instead of O(n).
www.celoxica.com
Page 17