[DEV] add v1.76.0

This commit is contained in:
2021-10-05 21:37:46 +02:00
parent a97e9ae7d4
commit d0115b733d
45133 changed files with 4744437 additions and 1026325 deletions

View File

@@ -0,0 +1,138 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Augmented-CRC Function</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../crc.html" title="Chapter 12. Boost.CRC 1.5">
<link rel="prev" href="crc_function.html" title="CRC Function">
<link rel="next" href="crc_samples.html" title="Pre-Defined CRC Samples">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="crc_function.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="crc_samples.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="crc.acrc_function"></a><a class="link" href="acrc_function.html" title="Augmented-CRC Function">Augmented-CRC Function</a>
</h2></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">cstdint</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span> <span class="comment">// for boost::uintmax_t</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span> <span class="comment">// for boost::uint_t</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">cstddef</span><span class="special">&gt;</span> <span class="comment">// for std::size_t</span>
<span class="keyword">namespace</span> <span class="identifier">boost</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">Bits</span><span class="special">,</span> <span class="identifier">uintmax_t</span> <span class="identifier">TruncPoly</span> <span class="special">&gt;</span>
<span class="keyword">typename</span> <span class="identifier">uint_t</span><span class="special">&lt;</span><span class="identifier">Bits</span><span class="special">&gt;::</span><span class="identifier">fast</span> <span class="identifier">augmented_crc</span><span class="special">(</span> <span class="keyword">void</span> <span class="keyword">const</span> <span class="special">*</span><span class="identifier">buffer</span><span class="special">,</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">byte_count</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">uint_t</span><span class="special">&lt;</span><span class="identifier">Bits</span><span class="special">&gt;::</span><span class="identifier">fast</span> <span class="identifier">initial_remainder</span>
<span class="special">=</span> <span class="number">0u</span> <span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
The <span class="bold"><strong><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">augmented_crc</span></code></strong></span>
function computes the augmented-style CRC of a data block. Like <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">crc</span></code>,
the first two template parameters are the <span class="emphasis"><em>WIDTH</em></span> and <span class="emphasis"><em>POLY</em></span>.
However, the <span class="emphasis"><em>INIT</em></span> has moved to being a function parameter,
after the data block's starting address and byte length, defaulting to zero
if not given.
</p>
<p>
This function uses modulo-2 division at its most raw, and so forfeits the
<span class="emphasis"><em>REFIN</em></span>, <span class="emphasis"><em>REFOUT</em></span>, and <span class="emphasis"><em>XOROUT</em></span>
attributes, setting them to <code class="computeroutput"><span class="number">0</span></code> or
<code class="computeroutput"><span class="keyword">false</span></code>. Another difference from
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">crc</span></code> is that a non-zero <span class="emphasis"><em>INIT</em></span>
has to be skewed when used with this function. (No conversion functions are
currently given.)
</p>
<p>
The <code class="computeroutput"><span class="identifier">augmented_crc</span></code> function
can compute CRCs from distributed data, too:
</p>
<p>
</p>
<pre class="programlisting"><span class="keyword">unsigned</span> <span class="identifier">combined_acrc_16</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">block_count</span><span class="special">,</span> <span class="special">...</span> <span class="special">)</span>
<span class="special">{</span>
<a class="co" name="crc.acrc_function.c0" href="acrc_function.html#crc.acrc_function.c1"><img src="../../../doc/src/images/callouts/1.png" alt="1" border="0"></a><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">std</span><span class="special">;</span>
<span class="identifier">va_list</span> <span class="identifier">ap</span><span class="special">;</span>
<span class="keyword">unsigned</span> <span class="identifier">result</span> <span class="special">=</span> <span class="number">0u</span><span class="special">;</span>
<span class="identifier">va_start</span><span class="special">(</span> <span class="identifier">ap</span><span class="special">,</span> <span class="identifier">block_count</span> <span class="special">);</span>
<span class="keyword">if</span> <span class="special">(</span> <span class="identifier">block_count</span> <span class="special">&lt;=</span> <span class="number">0</span> <span class="special">)</span>
<span class="keyword">goto</span> <span class="identifier">finish</span><span class="special">;</span>
<span class="keyword">void</span> <span class="keyword">const</span> <span class="special">*</span> <span class="identifier">bs</span> <span class="special">=</span> <span class="identifier">va_arg</span><span class="special">(</span> <span class="identifier">ap</span><span class="special">,</span> <span class="keyword">void</span> <span class="keyword">const</span> <span class="special">*</span> <span class="special">);</span>
<span class="identifier">size_t</span> <span class="identifier">bl</span> <span class="special">=</span> <span class="identifier">va_arg</span><span class="special">(</span> <span class="identifier">ap</span><span class="special">,</span> <span class="identifier">size_t</span> <span class="special">);</span>
<a class="co" name="crc.acrc_function.c2" href="acrc_function.html#crc.acrc_function.c3"><img src="../../../doc/src/images/callouts/2.png" alt="2" border="0"></a><span class="identifier">result</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">augmented_crc</span><span class="special">&lt;</span><span class="number">16</span><span class="special">,</span> <span class="number">0x1021u</span><span class="special">&gt;(</span> <span class="identifier">bs</span><span class="special">,</span> <span class="identifier">bl</span> <span class="special">);</span>
<span class="keyword">while</span> <span class="special">(</span> <span class="special">--</span><span class="identifier">block_count</span> <span class="special">)</span>
<span class="special">{</span>
<span class="identifier">bs</span> <span class="special">=</span> <span class="identifier">va_arg</span><span class="special">(</span> <span class="identifier">ap</span><span class="special">,</span> <span class="keyword">void</span> <span class="keyword">const</span> <span class="special">*</span> <span class="special">);</span>
<span class="identifier">bl</span> <span class="special">=</span> <span class="identifier">va_arg</span><span class="special">(</span> <span class="identifier">ap</span><span class="special">,</span> <span class="identifier">size_t</span> <span class="special">);</span>
<span class="identifier">result</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">augmented_crc</span><span class="special">&lt;</span><span class="number">16</span><span class="special">,</span> <span class="number">0x1021u</span><span class="special">&gt;(</span> <span class="identifier">bs</span><span class="special">,</span> <span class="identifier">bl</span><span class="special">,</span> <span class="identifier">result</span> <span class="special">);</span>
<span class="special">}</span>
<span class="identifier">finish</span><span class="special">:</span>
<span class="identifier">va_end</span><span class="special">(</span> <span class="identifier">ap</span> <span class="special">);</span>
<span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
</p>
<p>
No CRC operation throws, so there is no need for extra protection between the
varargs macro calls. Feeding the result from the previous run as the initial
remainder for the next run works easily because there's no output reflection
or XOR mask.
</p>
<div class="calloutlist"><table border="0" summary="Callout list">
<tr>
<td width="5%" valign="top" align="left"><p><a name="crc.acrc_function.c1"></a><a href="#crc.acrc_function.c0"><img src="../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td>
<td valign="top" align="left"><p>
C-style variable-argument routines are or may be macros.
</p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a name="crc.acrc_function.c3"></a><a href="#crc.acrc_function.c2"><img src="../../../doc/src/images/callouts/2.png" alt="2" border="0"></a> </p></td>
<td valign="top" align="left"><p>
The parameters are based on <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">crc_xmodem_t</span></code>.
</p></td>
</tr>
</table></div>
<p>
Since <code class="computeroutput"><span class="identifier">augmented_crc</span></code> doesn't
know when your data ends, you must supply the augment, either <span class="emphasis"><em>WIDTH</em></span>
zero bits or the expected checksum. The augment can be either at the end of
last data block or from an extra call. Remember that if an expected checksum
is used as the augment, its bits must be arranged in big-endian order. Because
<code class="computeroutput"><span class="identifier">augmented_crc</span></code> reads byte-wise,
while augments assume bit-wise reading, augmentations are valid only when
<span class="emphasis"><em>WIDTH</em></span> is a multiple of the bits-per-byte ratio (<code class="computeroutput"><span class="identifier">CHAR_BIT</span></code>).
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001, 2003, 2012 Daryle Walker<p>
Distributed under the Boost Software License, Version 1.0. (See the accompanying
file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="crc_function.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="crc_samples.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

447
doc/html/crc/crc_basic.html Normal file
View File

@@ -0,0 +1,447 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Theoretical CRC Computer</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../crc.html" title="Chapter 12. Boost.CRC 1.5">
<link rel="prev" href="introduction.html" title="Introduction">
<link rel="next" href="crc_optimal.html" title="Optimized CRC Computer">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="introduction.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="crc_optimal.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="crc.crc_basic"></a><a class="link" href="crc_basic.html" title="Theoretical CRC Computer">Theoretical CRC Computer</a>
</h2></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">cstddef</span><span class="special">&gt;</span> <span class="comment">// for std::size_t</span>
<span class="keyword">namespace</span> <span class="identifier">boost</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">Bits</span> <span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">crc_basic</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
The <span class="bold"><strong><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">crc_basic</span></code></strong></span>
class template acts as an unaugmented-CRC processor that can accept input at
the bit-level. It only takes one Rocksoft™ Model CRC Algorithm parameter
as a template parameter, the <span class="emphasis"><em>WIDTH</em></span>, which determines the
built-in unsigned integer type used for division registers. The other Rocksoft™
Model CRC Algorithm parameters can be passed on through the constructor. (Most
of the parameters have defaults.)
</p>
<p>
The integer type used for registers is published as <code class="computeroutput"><span class="identifier">value_type</span></code>,
while the Rocksoft™ Model CRC Algorithm attributes can be discovered
as:
</p>
<div class="table">
<a name="crc.crc_basic.crc_basic_rmca"></a><p class="title"><b>Table 12.1. RMCA Parameters in boost::crc_basic</b></p>
<div class="table-contents"><table class="table" summary="RMCA Parameters in boost::crc_basic">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Parameter
</p>
</th>
<th>
<p>
Member Name
</p>
</th>
<th>
<p>
Kind
</p>
</th>
<th>
<p>
Expression Type
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<span class="emphasis"><em>WIDTH</em></span>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">bit_count</span></code>
</p>
</td>
<td>
<p>
class-static immutable data member
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<span class="emphasis"><em>POLY</em></span>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">get_truncated_polynominal</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="keyword">const</span></code> member function
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">value_type</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<span class="emphasis"><em>INIT</em></span>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">get_initial_remainder</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="keyword">const</span></code> member function
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">value_type</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<span class="emphasis"><em>REFIN</em></span>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">get_reflect_input</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="keyword">const</span></code> member function
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="keyword">bool</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<span class="emphasis"><em>REFOUT</em></span>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">get_reflect_remainder</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="keyword">const</span></code> member function
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="keyword">bool</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<span class="emphasis"><em>XOROUT</em></span>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">get_final_xor_value</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="keyword">const</span></code> member function
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">value_type</span></code>
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>
Since most of the parameters are specified at run-time, you can reuse a single
computer object for separate runs with differing parameters. The type uses
the automatically-defined copy/move/assign and destruction routines.
</p>
<p>
Here's an example of reuse:
</p>
<p>
</p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="keyword">unsigned</span><span class="special">,</span> <span class="keyword">unsigned</span><span class="special">&gt;</span> <span class="identifier">crc_16_and_xmodem</span><span class="special">(</span> <span class="keyword">void</span> <span class="keyword">const</span> <span class="special">*</span><span class="identifier">b</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">l</span> <span class="special">)</span>
<span class="special">{</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="keyword">unsigned</span><span class="special">,</span> <span class="keyword">unsigned</span><span class="special">&gt;</span> <span class="identifier">result</span><span class="special">;</span>
<a class="co" name="crc.crc_basic.c0" href="crc_basic.html#crc.crc_basic.c1"><img src="../../../doc/src/images/callouts/1.png" alt="1" border="0"></a><span class="identifier">boost</span><span class="special">::</span><span class="identifier">crc_basic</span><span class="special">&lt;</span><span class="number">16</span><span class="special">&gt;</span> <span class="identifier">crc1</span><span class="special">(</span> <span class="number">0x8005u</span><span class="special">,</span> <span class="number">0u</span><span class="special">,</span> <span class="number">0u</span><span class="special">,</span> <span class="keyword">true</span><span class="special">,</span> <span class="keyword">true</span> <span class="special">);</span>
<span class="identifier">crc1</span><span class="special">.</span><span class="identifier">process_bytes</span><span class="special">(</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">l</span> <span class="special">);</span>
<span class="identifier">result</span><span class="special">.</span><span class="identifier">first</span> <span class="special">=</span> <span class="identifier">crc1</span><span class="special">.</span><span class="identifier">checksum</span><span class="special">();</span>
<a class="co" name="crc.crc_basic.c2" href="crc_basic.html#crc.crc_basic.c3"><img src="../../../doc/src/images/callouts/2.png" alt="2" border="0"></a><span class="identifier">crc1</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">crc_basic</span><span class="special">&lt;</span><span class="number">16</span><span class="special">&gt;(</span> <span class="number">0x8408u</span><span class="special">,</span> <span class="identifier">crc1</span><span class="special">.</span><span class="identifier">get_initial_remainder</span><span class="special">(),</span>
<span class="identifier">crc1</span><span class="special">.</span><span class="identifier">get_final_xor_value</span><span class="special">(),</span> <span class="identifier">crc1</span><span class="special">.</span><span class="identifier">get_reflect_input</span><span class="special">(),</span>
<span class="identifier">crc1</span><span class="special">.</span><span class="identifier">get_reflect_remainder</span><span class="special">()</span> <span class="special">);</span>
<span class="identifier">crc1</span><span class="special">.</span><span class="identifier">process_bytes</span><span class="special">(</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">l</span> <span class="special">);</span>
<span class="identifier">result</span><span class="special">.</span><span class="identifier">second</span> <span class="special">=</span> <span class="identifier">crc1</span><span class="special">.</span><span class="identifier">checksum</span><span class="special">();</span>
<span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
</p>
<p>
For now, most Rocksoft™ Model CRC Algorithm parameters can only be changed
through assignment to the entire object.
</p>
<div class="calloutlist"><table border="0" summary="Callout list">
<tr>
<td width="5%" valign="top" align="left"><p><a name="crc.crc_basic.c1"></a><a href="#crc.crc_basic.c0"><img src="../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td>
<td valign="top" align="left"><p>
The parameters are based on <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">crc_16_type</span></code>.
</p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a name="crc.crc_basic.c3"></a><a href="#crc.crc_basic.c2"><img src="../../../doc/src/images/callouts/2.png" alt="2" border="0"></a> </p></td>
<td valign="top" align="left"><p>
Change the parameters to match <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">crc_xmodem_type</span></code>.
</p></td>
</tr>
</table></div>
<p>
This example necessarily demonstrates input and output. There is one output
member function, <code class="computeroutput"><span class="identifier">checksum</span></code> that
returns the remainder from the CRC steps plus any post-processing reflection
and/or XOR-masking. There are several options to submit input data for processing:
</p>
<div class="table">
<a name="crc.crc_basic.crc_basic_input"></a><p class="title"><b>Table 12.2. Member Functions for Input in boost::crc_basic</b></p>
<div class="table-contents"><table class="table" summary="Member Functions for Input in boost::crc_basic">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Member Function
</p>
</th>
<th>
<p>
Input Type/Style
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">process_bit</span></code>
</p>
</td>
<td>
<p>
A single bit.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">process_bits</span></code>
</p>
</td>
<td>
<p>
A specified number of bits within the given byte. Reading starts
from the highest-order desired bit.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">process_byte</span></code>
</p>
</td>
<td>
<p>
An entire byte. The bits within the byte are read in an order consistent
with <code class="computeroutput"><span class="identifier">get_reflect_input</span></code>.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">process_block</span></code>
</p>
</td>
<td>
<p>
All bytes in the range. The range is defined by a pointer to the
first byte and another pointer to one (byte) past-the-end.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">process_bytes</span></code>
</p>
</td>
<td>
<p>
All bytes in the range. The range is defined by a pointer to the
first byte and a count of number of bytes to read.
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>
The input functions currently do not return anything.
</p>
<p>
Persistent objects mean that the data doesn't have to be in one block:
</p>
<p>
</p>
<pre class="programlisting"><span class="keyword">unsigned</span> <span class="identifier">combined_crc_16</span><span class="special">(</span> <span class="keyword">unsigned</span> <span class="identifier">block_count</span><span class="special">,</span> <span class="special">...</span> <span class="special">)</span>
<span class="special">{</span>
<a class="co" name="crc.crc_basic.c4" href="crc_basic.html#crc.crc_basic.c5"><img src="../../../doc/src/images/callouts/1.png" alt="1" border="0"></a><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">std</span><span class="special">;</span>
<a class="co" name="crc.crc_basic.c6" href="crc_basic.html#crc.crc_basic.c7"><img src="../../../doc/src/images/callouts/2.png" alt="2" border="0"></a><span class="identifier">boost</span><span class="special">::</span><span class="identifier">crc_basic</span><span class="special">&lt;</span><span class="number">16</span><span class="special">&gt;</span> <span class="identifier">crc1</span><span class="special">(</span> <span class="number">0x8005u</span><span class="special">,</span> <span class="number">0u</span><span class="special">,</span> <span class="number">0u</span><span class="special">,</span> <span class="keyword">true</span><span class="special">,</span> <span class="keyword">true</span> <span class="special">);</span>
<span class="identifier">va_list</span> <span class="identifier">ap</span><span class="special">;</span>
<span class="identifier">va_start</span><span class="special">(</span> <span class="identifier">ap</span><span class="special">,</span> <span class="identifier">block_count</span> <span class="special">);</span>
<span class="keyword">while</span> <span class="special">(</span> <span class="identifier">block_count</span><span class="special">--</span> <span class="special">)</span>
<span class="special">{</span>
<span class="keyword">void</span> <span class="keyword">const</span> <span class="special">*</span> <span class="keyword">const</span> <span class="identifier">bs</span> <span class="special">=</span> <span class="identifier">va_arg</span><span class="special">(</span> <span class="identifier">ap</span><span class="special">,</span> <span class="keyword">void</span> <span class="keyword">const</span> <span class="special">*</span> <span class="special">);</span>
<span class="identifier">size_t</span> <span class="keyword">const</span> <span class="identifier">bl</span> <span class="special">=</span> <span class="identifier">va_arg</span><span class="special">(</span> <span class="identifier">ap</span><span class="special">,</span> <span class="identifier">size_t</span> <span class="special">);</span>
<a class="co" name="crc.crc_basic.c8" href="crc_basic.html#crc.crc_basic.c9"><img src="../../../doc/src/images/callouts/3.png" alt="3" border="0"></a><span class="identifier">crc1</span><span class="special">.</span><span class="identifier">process_bytes</span><span class="special">(</span> <span class="identifier">bs</span><span class="special">,</span> <span class="identifier">bl</span> <span class="special">);</span>
<span class="special">}</span>
<span class="identifier">va_end</span><span class="special">(</span> <span class="identifier">ap</span> <span class="special">);</span>
<span class="keyword">return</span> <span class="identifier">crc1</span><span class="special">.</span><span class="identifier">checksum</span><span class="special">();</span>
<span class="special">}</span>
</pre>
<p>
</p>
<p>
No CRC operation throws, so there is no need for extra protection between the
varargs macro calls.
</p>
<div class="calloutlist"><table border="0" summary="Callout list">
<tr>
<td width="5%" valign="top" align="left"><p><a name="crc.crc_basic.c5"></a><a href="#crc.crc_basic.c4"><img src="../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td>
<td valign="top" align="left"><p>
C-style variable-argument routines are or may be macros.
</p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a name="crc.crc_basic.c7"></a><a href="#crc.crc_basic.c6"><img src="../../../doc/src/images/callouts/2.png" alt="2" border="0"></a> </p></td>
<td valign="top" align="left"><p>
The parameters are based on <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">crc_16_type</span></code>.
</p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a name="crc.crc_basic.c9"></a><a href="#crc.crc_basic.c8"><img src="../../../doc/src/images/callouts/3.png" alt="3" border="0"></a> </p></td>
<td valign="top" align="left"><p>
The <code class="computeroutput"><span class="identifier">va_arg</span></code> calls were within
the <code class="computeroutput"><span class="identifier">process_bytes</span></code> call,
but I remembered that calling order is not guaranteed among function arguments,
so I need explicit object declarations to enforce the extraction order.
</p></td>
</tr>
</table></div>
<p>
The input-influenced state of a computer object may be read with the <code class="computeroutput"><span class="identifier">get_interim_remainder</span></code> member function. An
object may be loaded with the same kind of state with the one-argument version
of the <code class="computeroutput"><span class="identifier">reset</span></code> member function.
The state is the remainder from the CRC operations performed on all the already-entered
input, without any output post-processing.
</p>
<p>
The two functions can be used together to save the state to a persistent medium
and restore it later. Note that the Rocksoft™ Model CRC Algorithm parameters
have to saved/restored via other means, if they're not fixed within a program.
</p>
<p>
Calling <code class="computeroutput"><span class="identifier">reset</span></code> with no arguments
sets the interim remainder to what <span class="emphasis"><em>INIT</em></span> was set at object
construction. This lets one computer object be used for independent runs with
separate data messages using the same CRC standard.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001, 2003, 2012 Daryle Walker<p>
Distributed under the Boost Software License, Version 1.0. (See the accompanying
file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="introduction.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="crc_optimal.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,63 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>CRC Function</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../crc.html" title="Chapter 12. Boost.CRC 1.5">
<link rel="prev" href="crc_optimal.html" title="Optimized CRC Computer">
<link rel="next" href="acrc_function.html" title="Augmented-CRC Function">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="crc_optimal.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="acrc_function.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="crc.crc_function"></a><a class="link" href="crc_function.html" title="CRC Function">CRC Function</a>
</h2></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">cstdint</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span> <span class="comment">// for boost::uintmax_t</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span> <span class="comment">// for boost::uint_t</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">cstddef</span><span class="special">&gt;</span> <span class="comment">// for std::size_t</span>
<span class="keyword">namespace</span> <span class="identifier">boost</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">Bits</span><span class="special">,</span> <span class="identifier">uintmax_t</span> <span class="identifier">TruncPoly</span><span class="special">,</span> <span class="identifier">uintmax_t</span> <span class="identifier">InitRem</span><span class="special">,</span>
<span class="identifier">uintmax_t</span> <span class="identifier">FinalXor</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">ReflectIn</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">ReflectRem</span> <span class="special">&gt;</span>
<span class="keyword">typename</span> <span class="identifier">uint_t</span><span class="special">&lt;</span><span class="identifier">Bits</span><span class="special">&gt;::</span><span class="identifier">fast</span> <span class="identifier">crc</span><span class="special">(</span> <span class="keyword">void</span> <span class="keyword">const</span> <span class="special">*</span><span class="identifier">buffer</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span>
<span class="identifier">byte_count</span> <span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
The <span class="bold"><strong><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">crc</span></code></strong></span>
function template computes the unaugmented CRC of a single data block in one
pass. It has the same template parameter list as <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">crc_optimal</span></code>,
which it uses for implementation. This function saves you the trouble of setting
up and using the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">crc_optimal</span></code> object manually.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001, 2003, 2012 Daryle Walker<p>
Distributed under the Boost Software License, Version 1.0. (See the accompanying
file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="crc_optimal.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="acrc_function.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,213 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Optimized CRC Computer</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../crc.html" title="Chapter 12. Boost.CRC 1.5">
<link rel="prev" href="crc_basic.html" title="Theoretical CRC Computer">
<link rel="next" href="crc_function.html" title="CRC Function">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="crc_basic.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="crc_function.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="crc.crc_optimal"></a><a class="link" href="crc_optimal.html" title="Optimized CRC Computer">Optimized CRC Computer</a>
</h2></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">cstdint</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span> <span class="comment">// for boost::uintmax_t</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">cstddef</span><span class="special">&gt;</span> <span class="comment">// for std::size_t</span>
<span class="keyword">namespace</span> <span class="identifier">boost</span>
<span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">Bits</span><span class="special">,</span> <span class="identifier">uintmax_t</span> <span class="identifier">TruncPoly</span><span class="special">,</span> <span class="identifier">uintmax_t</span> <span class="identifier">InitRem</span><span class="special">,</span>
<span class="identifier">uintmax_t</span> <span class="identifier">FinalXor</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">ReflectIn</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">ReflectRem</span> <span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">crc_optimal</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
The <span class="bold"><strong><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">crc_optimal</span></code></strong></span>
class template acts as an unaugmented-CRC processor that can accept input at
the byte-level. It takes all the Rocksoft™ Model CRC Algorithm parameters
as template parameters. Like in <code class="computeroutput"><span class="identifier">crc_basic</span></code>,
the <span class="emphasis"><em>WIDTH</em></span> stays as the first parameter and determines
the built-in unsigned integer type used for division registers. The other Rocksoft™
Model CRC Algorithm parameters move up to the template parameter field in the
same relative order they were in the <code class="computeroutput"><span class="identifier">crc_basic</span></code>
constructor. (Some parameters have defaults.) Objects based from <code class="computeroutput"><span class="identifier">crc_optimal</span></code> can either be default-constructed,
giving it the same behavior as a <code class="computeroutput"><span class="identifier">crc_basic</span></code>
object with the equivalent settings, or use one parameter, which overrides
the initial remainder value<a href="#ftn.crc.crc_optimal.f0" class="footnote" name="crc.crc_optimal.f0"><sup class="footnote">[3]</sup></a> without permanently affecting the initial-remainder attribute.
</p>
<p>
Besides template parameters and construction, <code class="computeroutput"><span class="identifier">crc_optimal</span></code>
differs from <code class="computeroutput"><span class="identifier">crc_basic</span></code> interface-wise
by:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p class="simpara">
Adding five class-static immutable data members corresponding to the new
template parameters.
</p>
<div class="table">
<a name="crc.crc_optimal.crc_optimal_rmca"></a><p class="title"><b>Table 12.3. Additional RMCA Expressions in boost::crc_optimal</b></p>
<div class="table-contents"><table class="table" summary="Additional RMCA Expressions in boost::crc_optimal">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
New Member
</p>
</th>
<th>
<p>
Equivalent
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">truncated_polynominal</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">get_truncated_polynominal</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">initial_remainder</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">get_initial_remainder</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">reflect_input</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">get_reflect_input</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">reflect_remainder</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">get_reflect_remainder</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">final_xor_value</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">get_final_xor_value</span></code>
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break">
</li>
<li class="listitem">
Removing the <code class="computeroutput"><span class="identifier">process_bit</span></code>
and <code class="computeroutput"><span class="identifier">process_bits</span></code> member
functions.
</li>
<li class="listitem">
Adding two versions of the <code class="computeroutput"><span class="keyword">operator</span>
<span class="special">()</span></code> member function. The single-argument
version forwards to <code class="computeroutput"><span class="identifier">process_byte</span></code>,
making it suitable to STL algorithms that take (and possibly return) function
objects<a href="#ftn.crc.crc_optimal.f1" class="footnote" name="crc.crc_optimal.f1"><sup class="footnote">[4]</sup></a>. The argument-less version forwards to <code class="computeroutput"><span class="identifier">checksum</span></code>,
making it suitable for STL algorithms that expect generator objects<a href="#ftn.crc.crc_optimal.f2" class="footnote" name="crc.crc_optimal.f2"><sup class="footnote">[5]</sup></a>.
</li>
<li class="listitem">
Merging the two <code class="computeroutput"><span class="identifier">reset</span></code> member
functions into one. (It uses a single parameter that can have a default
argument).
</li>
</ul></div>
<p>
The major difference between <code class="computeroutput"><span class="identifier">crc_basic</span></code>
and <code class="computeroutput"><span class="identifier">crc_optimal</span></code> is the internals.
Objects from <code class="computeroutput"><span class="identifier">crc_basic</span></code> run
their CRC algorithm one bit at a time, no matter which unit is used as input.
Objects from <code class="computeroutput"><span class="identifier">crc_optimal</span></code>, when
<span class="emphasis"><em>WIDTH</em></span> is at least <code class="computeroutput"><span class="identifier">CHAR_BIT</span></code><a href="#ftn.crc.crc_optimal.f3" class="footnote" name="crc.crc_optimal.f3"><sup class="footnote">[6]</sup></a>, use a byte-indexed table-driven CRC algorithm which is a <span class="bold"><strong>lot</strong></span> faster than processing individual bits.
</p>
<p>
Since all of the parameters are specified at compile-time, you cannot reuse
a single computer object for separate runs with differing parameters. The type
uses the automatically-defined copy/move/assign and destruction routines.
</p>
<div class="footnotes">
<br><hr style="width:100; text-align:left;margin-left: 0">
<div id="ftn.crc.crc_optimal.f0" class="footnote"><p><a href="#crc.crc_optimal.f0" class="para"><sup class="para">[3] </sup></a>
i.e. The interim-remainder before any input is read.
</p></div>
<div id="ftn.crc.crc_optimal.f1" class="footnote"><p><a href="#crc.crc_optimal.f1" class="para"><sup class="para">[4] </sup></a>
Like <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span></code>.
</p></div>
<div id="ftn.crc.crc_optimal.f2" class="footnote"><p><a href="#crc.crc_optimal.f2" class="para"><sup class="para">[5] </sup></a>
Albeit this object won't change its return value within code that only
uses it as a generator.
</p></div>
<div id="ftn.crc.crc_optimal.f3" class="footnote"><p><a href="#crc.crc_optimal.f3" class="para"><sup class="para">[6] </sup></a>
i.e. The optimizations are suspended if the <span class="emphasis"><em>WIDTH</em></span> only
justifies using part of a single byte.
</p></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001, 2003, 2012 Daryle Walker<p>
Distributed under the Boost Software License, Version 1.0. (See the accompanying
file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="crc_basic.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="crc_function.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,179 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Pre-Defined CRC Samples</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../crc.html" title="Chapter 12. Boost.CRC 1.5">
<link rel="prev" href="acrc_function.html" title="Augmented-CRC Function">
<link rel="next" href="end.html" title="End Matter">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="acrc_function.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="end.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="crc.crc_samples"></a><a class="link" href="crc_samples.html" title="Pre-Defined CRC Samples">Pre-Defined CRC Samples</a>
</h2></div></div></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">crc_optimal</span><span class="special">&lt;</span><span class="number">16</span><span class="special">,</span> <span class="number">0x8005</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="keyword">true</span><span class="special">,</span> <span class="keyword">true</span><span class="special">&gt;</span>
<span class="identifier">crc_16_type</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">crc_optimal</span><span class="special">&lt;</span><span class="number">16</span><span class="special">,</span> <span class="number">0x1021</span><span class="special">,</span> <span class="number">0xFFFF</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="keyword">false</span><span class="special">,</span> <span class="keyword">false</span><span class="special">&gt;</span>
<span class="identifier">crc_ccitt_false_t</span><span class="special">,</span> <span class="identifier">crc_ccitt_type</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">crc_optimal</span><span class="special">&lt;</span><span class="number">16</span><span class="special">,</span> <span class="number">0x1021</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="keyword">true</span><span class="special">,</span> <span class="keyword">true</span><span class="special">&gt;</span> <span class="identifier">crc_ccitt_true_t</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">crc_optimal</span><span class="special">&lt;</span><span class="number">16</span><span class="special">,</span> <span class="number">0x8408</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="keyword">true</span><span class="special">,</span> <span class="keyword">true</span><span class="special">&gt;</span> <span class="identifier">crc_xmodem_type</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">crc_optimal</span><span class="special">&lt;</span><span class="number">16</span><span class="special">,</span> <span class="number">0x1021</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="keyword">false</span><span class="special">,</span> <span class="keyword">false</span><span class="special">&gt;</span> <span class="identifier">crc_xmodem_t</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">crc_optimal</span><span class="special">&lt;</span><span class="number">32</span><span class="special">,</span> <span class="number">0x04C11DB7</span><span class="special">,</span> <span class="number">0xFFFFFFFF</span><span class="special">,</span> <span class="number">0xFFFFFFFF</span><span class="special">,</span> <span class="keyword">true</span><span class="special">,</span> <span class="keyword">true</span><span class="special">&gt;</span>
<span class="identifier">crc_32_type</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
Several sample CRC types are given, representing common CRC algorithms. The
samples have now been checked against the <a href="http://regregex.bbcmicro.net/crc-catalogue.htm" target="_top"><span class="emphasis"><em>Catalogue
of parametrised CRC algorithms</em></span></a>, leading to some new type-aliases
corresponding to the corrected profiles. (Older, incorrect profiles keep their
name for backwards compatibility.) However, this library is primarily concerned
with CRC implementation, and not with determining "good" sets of
CRC parameters.
</p>
<div class="table">
<a name="crc.crc_samples.crc_samples_list"></a><p class="title"><b>Table 12.4. Common CRCs</b></p>
<div class="table-contents"><table class="table" summary="Common CRCs">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Computer Type
</p>
</th>
<th>
<p>
Standard(s)
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">crc_16_type</span></code>
</p>
</td>
<td>
<p>
BISYNCH, ARC, LHA, ZOO
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">crc_ccitt_false_t</span></code>
</p>
</td>
<td>
<p>
Commonly misidentified as the standard by CCITT
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">crc_ccitt_type</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">crc_ccitt_false_t</span></code>
(I made the same mistake.)
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">crc_ccitt_true_t</span></code>
</p>
</td>
<td>
<p>
Designated by CCITT (Comité Consultatif International Télégraphique
et Téléphonique), KERMIT
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">crc_xmodem_type</span></code>
</p>
</td>
<td>
<p>
A mistake I didn't catch in defining <code class="computeroutput"><span class="identifier">crc_xmodem_t</span></code>.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">crc_xmodem_t</span></code>
</p>
</td>
<td>
<p>
XMODEM, ZMODEM, ACORN
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">crc_32_type</span></code>
</p>
</td>
<td>
<p>
ADCCP, PKZip, libPNG, AUTODIN II, Ethernet, FDDI
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break">
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001, 2003, 2012 Daryle Walker<p>
Distributed under the Boost Software License, Version 1.0. (See the accompanying
file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="acrc_function.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="end.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

140
doc/html/crc/end.html Normal file
View File

@@ -0,0 +1,140 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>End Matter</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../crc.html" title="Chapter 12. Boost.CRC 1.5">
<link rel="prev" href="crc_samples.html" title="Pre-Defined CRC Samples">
<link rel="next" href="reference.html" title="Reference">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="crc_samples.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="reference.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="crc.end"></a><a class="link" href="end.html" title="End Matter">End Matter</a>
</h2></div></div></div>
<h4>
<a name="crc.end.h0"></a>
<span class="phrase"><a name="crc.end.references"></a></span><a class="link" href="end.html#crc.end.references">References</a>
</h4>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
The <a href="../../../boost/crc.hpp" target="_top">CRC header</a> itself
</li>
<li class="listitem">
Some <a href="../../../libs/crc/test/crc_test.cpp" target="_top">test code</a> and
some <a href="../../../libs/crc/test/crc_test2.cpp" target="_top">newer tests</a>
that use the <a href="../../../libs/test/index.html" target="_top">Boost test library</a>
</li>
<li class="listitem">
Some <a href="../../../libs/crc/crc_example.cpp" target="_top">example code</a>
</li>
</ul></div>
<div class="variablelist">
<p class="title"><b>History</b></p>
<dl class="variablelist">
<dt><span class="term">Boost 1.49.0</span></dt>
<dd><p>
Refined implementation, testing, and documentation. Some interfaces were
tweaked.
</p></dd>
<dt><span class="term">Boost 1.30.2 (estimated)</span></dt>
<dd><p>
Released an example program.
</p></dd>
<dt><span class="term">Boost 1.22.0</span></dt>
<dd><p>
First public release.
</p></dd>
</dl>
</div>
<h4>
<a name="crc.end.h1"></a>
<span class="phrase"><a name="crc.end.acknowledgments"></a></span><a class="link" href="end.html#crc.end.acknowledgments">Acknowledgments</a>
</h4>
<p>
For giving advice on compiler/C++ compliance, implementation, interface, algorithms,
and bug reports:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Darin Adler
</li>
<li class="listitem">
Beman Dawes
</li>
<li class="listitem">
Doug Gregor
</li>
<li class="listitem">
John Maddock
</li>
<li class="listitem">
Joe Mariadassou
</li>
<li class="listitem">
Jens Maurer
</li>
<li class="listitem">
Vladimir Prus
</li>
<li class="listitem">
Joel Young
</li>
</ul></div>
<div class="variablelist">
<p class="title"><b>Contributors</b></p>
<dl class="variablelist">
<dt><span class="term">Michael Barr <a href="mailto:mbarr%40netrino.com" target="_top">mbarr@netrino.com</a></span></dt>
<dd><p>
Wrote <a href="http://www.netrino.com/Embedded-Systems/How-To/CRC-Calculation-C-Code" target="_top"><span class="quote"><span class="quote">CRC
Implementation Code in C</span></span></a>, a less-confusing guide to implementing
CRC algorithms. (Originally published as <span class="quote"><span class="quote">Slow and Steady Never
Lost the Race</span></span> in the January 2000 issue of <a href="http://www.embedded.com" target="_top"><span class="emphasis"><em>Embedded
Systems Programming</em></span></a>, pages 3746. The web version
used to be known as <a href="http://www.netrino.com/Connecting/2000-01/" target="_top"><span class="emphasis"><em>Easier
Said Than Done</em></span></a>.)
</p></dd>
<dt><span class="term">Daryle Walker</span></dt>
<dd><p>
Started the library and contributed the theoretical and optimal CRC computation
class templates and the CRC computing function template. Contributed
the test and example code.
</p></dd>
<dt><span class="term">Ross N. Williams</span></dt>
<dd><p>
Wrote <a href="http://www.ross.net/crc/crcpaper.html" target="_top"><span class="emphasis"><em>A
Painless Guide to CRC Error Detection Algorithms</em></span></a>,
a definitive source of CRC information.
</p></dd>
</dl>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001, 2003, 2012 Daryle Walker<p>
Distributed under the Boost Software License, Version 1.0. (See the accompanying
file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="crc_samples.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="reference.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,317 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Introduction</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../crc.html" title="Chapter 12. Boost.CRC 1.5">
<link rel="prev" href="../crc.html" title="Chapter 12. Boost.CRC 1.5">
<link rel="next" href="crc_basic.html" title="Theoretical CRC Computer">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../crc.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="crc_basic.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="crc.introduction"></a><a class="link" href="introduction.html" title="Introduction">Introduction</a>
</h2></div></div></div>
<div class="toc"><dl class="toc"><dt><span class="section"><a href="introduction.html#crc.introduction.intro_crcs">CRCs</a></span></dt></dl></div>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
Some of the introductory material is based on <a href="http://www.ross.net/crc/download/crc_v3.txt" target="_top"><span class="emphasis"><em>A
Painless Guide to CRC Error Detection Algorithms</em></span></a> by Ross
N. Williams at his <a href="http://www.ross.net/crc/" target="_top"><span class="bold"><strong>The
CRC Pitstop</strong></span></a> site.
</p></td></tr>
</table></div>
<p>
When binary data is transmitted, usually electronically, there is a chance
that the data gets corrupted. One method to pick up said corruption is to generate
some value that is coded from the original data, send said value to the receiver,
then confirm that the received data generates the same value when it's coded
at the destination.
</p>
<p>
There are several possibilities after the receiver's check:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
The check value matches at both places and the data was transmitted intact.
</li>
<li class="listitem">
The data got corrupted and the check values do not match.
</li>
<li class="listitem">
The data is intact, but the check value got corrupted. This can't the distinguished
from the previous case, but is a (relatively) safe false positive.
</li>
<li class="listitem">
Either the data and/or check value gets corrupted, but such that the results
of the check-coding are still consistent. This is a dangerous false negative!
</li>
</ul></div>
<p>
The way to minimize false negatives is to choose coding algorithms that cause
a lot of churn per input, especially a variable amount.
</p>
<p>
The check values are known as <span class="bold"><strong>checksum</strong></span>s because
they are used to <span class="emphasis"><em>check</em></span> for data consistency and the first
coding algorithms were addition- (i.e. <span class="emphasis"><em>sum</em></span>ming-) based.
</p>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="crc.introduction.intro_crcs"></a><a class="link" href="introduction.html#crc.introduction.intro_crcs" title="CRCs">CRCs</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="introduction.html#crc.introduction.intro_crcs.intro_crcs_impl">CRC Implementation</a></span></dt>
<dt><span class="section"><a href="introduction.html#crc.introduction.intro_crcs.intro_crcs_augment">Message
Augmentation</a></span></dt>
<dt><span class="section"><a href="introduction.html#crc.introduction.intro_crcs.intro_crcs_param">Other
CRC Parameters</a></span></dt>
<dt><span class="section"><a href="introduction.html#crc.introduction.intro_crcs.intro_crcs_rmca">Compact
CRC Parameter Specification</a></span></dt>
</dl></div>
<p>
<span class="bold"><strong>Cyclic Redundancy Codes</strong></span> are a type of consistency
check that treats the message data as a (long) dividend of a modulo-2 polynomial
division. Modulo-2 arithmetic doesn't use carries/borrows when combining
numbers. A specific CRC defines a set number of bits to work on at a time,
where said number is also the degree of a fixed polynomial (with modulo-2
coefficients) used as a divisor.
</p>
<p>
Since ordering doesn't apply to modulo arithmetic, the check between the
current high part of the dividend and the trial partial product (of the divisor
and the trial new quotient coefficient) is done by seeing if the highest-degree
coefficient of the dividend is one. (The highest-degree coefficient of the
divisor must be one by definition, since it's the only non-zero choice.)
The remainder after the division is finished is used as the basis of the
CRC checksum.
</p>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="crc.introduction.intro_crcs.intro_crcs_impl"></a><a class="link" href="introduction.html#crc.introduction.intro_crcs.intro_crcs_impl" title="CRC Implementation">CRC Implementation</a>
</h4></div></div></div>
<p>
For a given degree <span class="emphasis"><em>x</em></span> for the modulo-2 polynomial divisor,
the remainder will have at most <span class="emphasis"><em>x</em></span> terms (from degree
<span class="emphasis"><em>x</em></span> - 1 down to the constant term). The coefficients
are modulo-2, which means that they can be represented by 0's and 1's.
So a remainder can be modeled by an (unsigned) integer of at least <span class="emphasis"><em>x</em></span>
bits in <span class="bold"><strong>width</strong></span>.
</p>
<p>
The divisor must have its <span class="emphasis"><em>x</em></span> degree term be one, which
means it is always known and can be implied instead of having to explicitly
include in representations. Its lower <span class="emphasis"><em>x</em></span> terms must
be specified, so a divisor can be modeled the same way as remainders. With
such a modeling, the divisor representation could be said to be truncated
since the uppermost term's value is implied and not stored.
</p>
<p>
The remainder and <span class="bold"><strong>(truncated) divisor polynomial</strong></span>s
are stored as basic computer integers. This is in contrast to the dividend,
which is modeled from the input stream of data bits, where each new incoming
bit is the next lower term of the dividend polynomial. Long division can
be processed in piecemeal, reading new upper terms as needed. This maps
to reading the data a byte (or bit) at a time, generating updated remainders
just-in-time, without needing to read (and/or store(!)) the entire data
message at once.
</p>
<p>
Long division involves appending new dividend terms after the previous
terms have been processed into the (interim) remainder. So the remainder
it the only thing that has to change during each division step; a new input
byte (or bit) is combined with the remainder to make the interim dividend,
and then combined with the partial product (based on the divisor and top
dividend bit(s)) to become a remainder again.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="crc.introduction.intro_crcs.intro_crcs_augment"></a><a class="link" href="introduction.html#crc.introduction.intro_crcs.intro_crcs_augment" title="Message Augmentation">Message
Augmentation</a>
</h4></div></div></div>
<p>
When all of the input data has been read during division, the last <span class="emphasis"><em>x</em></span>
bits are still stuck in the interim remainder. They have not been pushed
through the division steps; to do so, <span class="emphasis"><em>x</em></span> zero-valued
extra bits must be passed into the system. This ensures all of the message's
data bits get processed. The post-processed remainder is the checksum.
The system requires the message to be <span class="bold"><strong>augmented</strong></span>
with <span class="emphasis"><em>x</em></span> extra bits to get results.
</p>
<p>
Alternatively, if the post-division augmentation bits are the expected
checksum instead, then the remainder will "subtract" the checksum
with itself, giving zero as the final remainder. The remainder will end
up non-zero if bit errors exist in either the data or checksum or both.
This option requires the checksum to be fed from highest-order bit first
on down (i.e. big endian).
</p>
<p>
Exploiting the properties of how the division is carried out, the steps
can be rearranged such that the post-processing zero-valued bits are not
needed; their effect is merged into the start of the process. Such systems
read <span class="bold"><strong>unaugmented</strong></span> messages and expose the
checksum directly from the interim remainder afterwards. (You can't use
the "augment-message-with-checksum-and-zero-check" technique
with this, of course.)
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="crc.introduction.intro_crcs.intro_crcs_param"></a><a class="link" href="introduction.html#crc.introduction.intro_crcs.intro_crcs_param" title="Other CRC Parameters">Other
CRC Parameters</a>
</h4></div></div></div>
<p>
Since long division proceeds from the uppermost terms on down, it's easiest
to treat an incoming byte as the uppermost unprocessed terms, and to read
the bits within that byte as the highest-order bit is the uppermost unprocessed
term and go down. However, some hardware implementations have an easier
time reading each byte from the lowest-order bit and go up. To simulate
those systems in software, the program needs to be flagged that <span class="bold"><strong>input reflection</strong></span> needs to be applied. Reflecting
a built-in integer reverses the order of its bits, such that the lowest-
and highest-order bits swap states, the next-lowest- and next-highest-order
bits swap, etc. The input reflection can be done by reflecting each byte
as it comes in or keeping the bytes unchanged but reflect the other internal
functioning. The latter sounds harder, but what it usually done in the
real world, since it's a one-time cost, unlike reflecting the bytes.
</p>
<p>
Similarly, the final remainder is processed by some hardware in reverse
order, which means software that simulate such systems need to flag that
<span class="bold"><strong>output reflection</strong></span> is in effect.
</p>
<p>
Some CRCs don't return the remainder directly (reflected or not), but add
an extra step complementing the output bits. Complementing turns 1 values
into 0 values and vice versa. This can simulated by using a XOR (exclusive-or)
bit mask of all 1-values (of the same bit length as the remainder). Some
systems use a <span class="bold"><strong>final XOR mask</strong></span> that isn't
all 1-values, for variety. (This mask takes place <span class="emphasis"><em>after</em></span>
any output reflection.)
</p>
<p>
At the other end, the built-in-integer register normally starts at zero
as the first bytes are read. Instead of just doing nothing but load input
bits for <span class="emphasis"><em>x</em></span> steps, some CRC systems use a non-zero
<span class="bold"><strong>initial remainder</strong></span> to add extra processing.
This initial value has to be different for the augmented versus un-augmented
versions of the same system, due to possible incorporation with the zero-valued
augment bits.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="crc.introduction.intro_crcs.intro_crcs_rmca"></a><a class="link" href="introduction.html#crc.introduction.intro_crcs.intro_crcs_rmca" title="Compact CRC Parameter Specification">Compact
CRC Parameter Specification</a>
</h4></div></div></div>
<p>
The Rocksoft™ Model CRC Algorithm, or RMCA for short, was designed
by Ross Williams to describe all the specification points of a given CRC
system (quoted):
</p>
<div class="variablelist">
<p class="title"><b>RMCA Parameters</b></p>
<dl class="variablelist">
<dt><span class="term">WIDTH</span></dt>
<dd><p>
This is the width of the algorithm expressed in bits. This is one
less than the width of the Poly.
</p></dd>
<dt><span class="term">POLY</span></dt>
<dd><p>
This parameter is the poly. This is a binary value that should be
specified as a hexadecimal number. The top bit of the poly should
be omitted. For example, if the poly is 10110, you should specify
06. An important aspect of this parameter is that it represents the
unreflected poly; the bottom bit of this parameter is always the
LSB of the divisor during the division regardless of whether the
algorithm being modelled is reflected.
</p></dd>
<dt><span class="term">INIT</span></dt>
<dd><p>
This parameter specifies the initial value of the register when the
algorithm starts. This is the value that is to be assigned to the
register in the direct table algorithm. In the table algorithm, we
may think of the register always commencing with the value zero,
and this value being XORed into the register after the N'th bit iteration.
This parameter should be specified as a hexadecimal number.
</p></dd>
<dt><span class="term">REFIN</span></dt>
<dd><p>
This is a boolean parameter. If it is FALSE, input bytes are processed
with bit 7 being treated as the most significant bit (MSB) and bit
0 being treated as the least significant bit. If this parameter is
FALSE, each byte is reflected before being processed.
</p></dd>
<dt><span class="term">REFOUT</span></dt>
<dd><p>
This is a boolean parameter. If it is set to FALSE, the final value
in the register is fed into the XOROUT stage directly, otherwise,
if this parameter is TRUE, the final register value is reflected
first.
</p></dd>
<dt><span class="term">XOROUT</span></dt>
<dd><p>
This is an W-bit value that should be specified as a hexadecimal
number. It is XORed to the final register value (after the REFOUT)
stage before the value is returned as the official checksum.
</p></dd>
</dl>
</div>
<p>
His description assumes an octet-sized byte. The <span class="emphasis"><em>POLY</em></span>
is the (truncated) divisor. The <span class="emphasis"><em>INIT</em></span> is the initial
remainder, assuming the unaugmented version of CRC processing is used.
(If you're using an augmented-style CRC, you have to undo the effect of
the built-in zero-augment before initialization.)
</p>
</div>
<p>
The two function templates and two class templates in this library provide
ways to carry out CRC computations. You give the various Rocksoft™
Model CRC Algorithm parameters as template parameters and/or constructor
parameters. You then submit all the message data bytes at once (for the functions)
or piecemeal (for the class objects).
</p>
</div>
<p>
Note that some error-detection techniques merge their checksum results within
the message data, while CRC checksums are either at the end (when augmented,
without either kind of reflection, with a bit-width that's a multiple of byte
size, and no XOR mask) or out-of-band.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001, 2003, 2012 Daryle Walker<p>
Distributed under the Boost Software License, Version 1.0. (See the accompanying
file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../crc.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="crc_basic.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

108
doc/html/crc/reference.html Normal file
View File

@@ -0,0 +1,108 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Reference</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../crc.html" title="Chapter 12. Boost.CRC 1.5">
<link rel="prev" href="end.html" title="End Matter">
<link rel="next" href="../boost/crc_basic.html" title="Class template crc_basic">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="end.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../boost/crc_basic.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="crc.reference"></a>Reference</h2></div></div></div>
<div class="toc"><dl class="toc"><dt><span class="section"><a href="reference.html#header.boost.crc_hpp">Header &lt;boost/crc.hpp&gt;</a></span></dt></dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="header.boost.crc_hpp"></a>Header &lt;<a href="../../../boost/crc.hpp" target="_top">boost/crc.hpp</a>&gt;</h3></div></div></div>
<p>A collection of function templates and class templates that compute various forms of Cyclic Redundancy Codes (CRCs). </p>
<p>Daryle Walker</p>
<p>
</p>
<p>1.5</p>
<p>
</p>
<p>Boost Software License, version 1.0</p>
<p>
Contains the declarations (and definitions) of various kinds of CRC computation functions, function object types, and encapsulated policy types.</p>
<div class="warning"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../doc/src/images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>The sample CRC-computer types were just checked against the <a href="http://regregex.bbcmicro.net/crc-catalogue.htm" target="_top">Catalogue of parametrised CRC algorithms</a>. New type aliases were added where I got a standard wrong. However, the mistaken <code class="computeroutput">typedef</code>s are still there for backwards compatibility. </p></td></tr>
</table></div>
<p>
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>There are references to the <span class="emphasis"><em>Rocksoft<span class="trademark"></span>™ Model CRC Algorithm</em></span>, as described within "A Painless Guide to CRC Error Detection Algorithms," linked from "<a href="http://www.ross.net/crc/crcpaper.html" target="_top">CRC: A Paper On CRCs</a>" by Ross Williams. It will be abbreviated "RMCA" in other documentation blocks. </p></td></tr>
</table></div>
<p>
</p>
<pre class="synopsis">
<a class="link" href="../BOOST_CRC_PARM_TYPE.html" title="Macro BOOST_CRC_PARM_TYPE">BOOST_CRC_PARM_TYPE</a>
<a class="link" href="../BOOST_CRC_OPTIMAL_NAME.html" title="Macro BOOST_CRC_OPTIMAL_NAME">BOOST_CRC_OPTIMAL_NAME</a></pre>
<pre class="synopsis"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> Bits<span class="special">&gt;</span> <span class="keyword">class</span> <a class="link" href="../boost/crc_basic.html" title="Class template crc_basic">crc_basic</a><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> Bits<span class="special">,</span> <span class="keyword">typename</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">uint_t</span><span class="special">&lt;</span> <span class="identifier">Bits</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">fast</span> TruncPoly<span class="special">,</span>
<span class="keyword">typename</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">uint_t</span><span class="special">&lt;</span> <span class="identifier">Bits</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">fast</span> InitRem<span class="special">,</span>
<span class="keyword">typename</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">uint_t</span><span class="special">&lt;</span> <span class="identifier">Bits</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">fast</span> FinalXor<span class="special">,</span> <span class="keyword">bool</span> ReflectIn<span class="special">,</span>
<span class="keyword">bool</span> ReflectRem<span class="special">&gt;</span>
<span class="keyword">class</span> <a class="link" href="../boost/crc_optimal.html" title="Class template crc_optimal">crc_optimal</a><span class="special">;</span>
<span class="keyword">typedef</span> <a class="link" href="../boost/crc_optimal.html" title="Class template crc_optimal">crc_optimal</a><span class="special">&lt;</span> <span class="number">16</span><span class="special">,</span> <span class="number">0x8005</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="keyword">true</span><span class="special">,</span> <span class="keyword">true</span> <span class="special">&gt;</span> <a name="boost.crc_16_type"></a><span class="identifier">crc_16_type</span><span class="special">;</span> <span class="comment">// Computation type for ARC|CRC-16|CRC-IBM|CRC-16/ARC|CRC-16/LHA standard. </span>
<span class="keyword">typedef</span> <a class="link" href="../boost/crc_optimal.html" title="Class template crc_optimal">crc_optimal</a><span class="special">&lt;</span> <span class="number">16</span><span class="special">,</span> <span class="number">0x1021</span><span class="special">,</span> <span class="number">0xFFFF</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="keyword">false</span><span class="special">,</span> <span class="keyword">false</span> <span class="special">&gt;</span> <a name="boost.crc_ccitt_false_t"></a><span class="identifier">crc_ccitt_false_t</span><span class="special">;</span> <span class="comment">// Computation type for CRC-16/CCITT-FALSE standard. </span>
<span class="keyword">typedef</span> <span class="identifier">crc_ccitt_false_t</span> <a name="boost.crc_ccitt_type"></a><span class="identifier">crc_ccitt_type</span><span class="special">;</span> <span class="comment">// Computation type for the CRC mistakenly called the CCITT standard. </span>
<span class="keyword">typedef</span> <a class="link" href="../boost/crc_optimal.html" title="Class template crc_optimal">crc_optimal</a><span class="special">&lt;</span> <span class="number">16</span><span class="special">,</span> <span class="number">0x1021</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="keyword">true</span><span class="special">,</span> <span class="keyword">true</span> <span class="special">&gt;</span> <a class="link" href="../boost/crc_ccitt_true_t.html" title="Type definition crc_ccitt_true_t"><span class="identifier">crc_ccitt_true_t</span></a><span class="special">;</span>
<span class="keyword">typedef</span> <a class="link" href="../boost/crc_optimal.html" title="Class template crc_optimal">crc_optimal</a><span class="special">&lt;</span> <span class="number">16</span><span class="special">,</span> <span class="number">0x8408</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="keyword">true</span><span class="special">,</span> <span class="keyword">true</span> <span class="special">&gt;</span> <a class="link" href="../boost/crc_xmodem_type.html" title="Type definition crc_xmodem_type"><span class="identifier">crc_xmodem_type</span></a><span class="special">;</span>
<span class="keyword">typedef</span> <a class="link" href="../boost/crc_optimal.html" title="Class template crc_optimal">crc_optimal</a><span class="special">&lt;</span> <span class="number">16</span><span class="special">,</span> <span class="number">0x1021</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="keyword">false</span><span class="special">,</span> <span class="keyword">false</span> <span class="special">&gt;</span> <a name="boost.crc_xmodem_t"></a><span class="identifier">crc_xmodem_t</span><span class="special">;</span> <span class="comment">// Computation type for the actual XMODEM|ZMODEM|CRC-16/ACORN standard. </span>
<span class="keyword">typedef</span> <a class="link" href="../boost/crc_optimal.html" title="Class template crc_optimal">crc_optimal</a><span class="special">&lt;</span> <span class="number">32</span><span class="special">,</span> <span class="number">0x04C11DB7</span><span class="special">,</span> <span class="number">0xFFFFFFFF</span><span class="special">,</span> <span class="number">0xFFFFFFFF</span><span class="special">,</span> <span class="keyword">true</span><span class="special">,</span> <span class="keyword">true</span> <span class="special">&gt;</span> <a name="boost.crc_32_type"></a><span class="identifier">crc_32_type</span><span class="special">;</span> <span class="comment">// Computation type for CRC-32|CRC-32/ADCCP|PKZIP standard. </span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> Bits<span class="special">,</span> <span class="keyword">typename</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">uint_t</span><span class="special">&lt;</span> <span class="identifier">Bits</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">fast</span> TruncPoly<span class="special">,</span>
<span class="keyword">typename</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">uint_t</span><span class="special">&lt;</span> <span class="identifier">Bits</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">fast</span> InitRem<span class="special">,</span>
<span class="keyword">typename</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">uint_t</span><span class="special">&lt;</span> <span class="identifier">Bits</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">fast</span> FinalXor<span class="special">,</span> <span class="keyword">bool</span> ReflectIn<span class="special">,</span>
<span class="keyword">bool</span> ReflectRem<span class="special">&gt;</span>
<span class="identifier">uint_t</span><span class="special">&lt;</span> <span class="identifier">Bits</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">fast</span> <a class="link" href="../boost/crc.html" title="Function template crc"><span class="identifier">crc</span></a><span class="special">(</span><span class="keyword">void</span> <span class="keyword">const</span> <span class="special">*</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> Bits<span class="special">,</span> <span class="keyword">typename</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">uint_t</span><span class="special">&lt;</span> <span class="identifier">Bits</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">fast</span> TruncPoly<span class="special">&gt;</span>
<span class="identifier">uint_t</span><span class="special">&lt;</span> <span class="identifier">Bits</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">fast</span>
<a class="link" href="../boost/augmented_crc.html" title="Function template augmented_crc"><span class="identifier">augmented_crc</span></a><span class="special">(</span><span class="keyword">void</span> <span class="keyword">const</span> <span class="special">*</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">,</span>
<span class="keyword">typename</span> <span class="identifier">uint_t</span><span class="special">&lt;</span> <span class="identifier">Bits</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">fast</span> <span class="special">=</span> <span class="number">0u</span><span class="special">)</span><span class="special">;</span>
<span class="special">}</span></pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001, 2003, 2012 Daryle Walker<p>
Distributed under the Boost Software License, Version 1.0. (See the accompanying
file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="end.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../crc.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../boost/crc_basic.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>