• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5<title>Optimized CRC Computer</title>
6<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
8<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
9<link rel="up" href="../crc.html" title="Chapter 12. Boost.CRC 1.5">
10<link rel="prev" href="crc_basic.html" title="Theoretical CRC Computer">
11<link rel="next" href="crc_function.html" title="CRC Function">
12</head>
13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
14<table cellpadding="2" width="100%"><tr>
15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
16<td align="center"><a href="../../../index.html">Home</a></td>
17<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
20<td align="center"><a href="../../../more/index.htm">More</a></td>
21</tr></table>
22<hr>
23<div class="spirit-nav">
24<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>
25</div>
26<div class="section">
27<div class="titlepage"><div><div><h2 class="title" style="clear: both">
28<a name="crc.crc_optimal"></a><a class="link" href="crc_optimal.html" title="Optimized CRC Computer">Optimized CRC Computer</a>
29</h2></div></div></div>
30<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>
31<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>
32
33<span class="keyword">namespace</span> <span class="identifier">boost</span>
34<span class="special">{</span>
35    <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>
36     <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>
37    <span class="keyword">class</span> <span class="identifier">crc_optimal</span><span class="special">;</span>
38<span class="special">}</span>
39</pre>
40<p>
41      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>
42      class template acts as an unaugmented-CRC processor that can accept input at
43      the byte-level. It takes all the Rocksoft™ Model CRC Algorithm parameters
44      as template parameters. Like in <code class="computeroutput"><span class="identifier">crc_basic</span></code>,
45      the <span class="emphasis"><em>WIDTH</em></span> stays as the first parameter and determines
46      the built-in unsigned integer type used for division registers. The other Rocksoft™
47      Model CRC Algorithm parameters move up to the template parameter field in the
48      same relative order they were in the <code class="computeroutput"><span class="identifier">crc_basic</span></code>
49      constructor. (Some parameters have defaults.) Objects based from <code class="computeroutput"><span class="identifier">crc_optimal</span></code> can either be default-constructed,
50      giving it the same behavior as a <code class="computeroutput"><span class="identifier">crc_basic</span></code>
51      object with the equivalent settings, or use one parameter, which overrides
52      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.
53    </p>
54<p>
55      Besides template parameters and construction, <code class="computeroutput"><span class="identifier">crc_optimal</span></code>
56      differs from <code class="computeroutput"><span class="identifier">crc_basic</span></code> interface-wise
57      by:
58    </p>
59<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
60<li class="listitem">
61<p class="simpara">
62          Adding five class-static immutable data members corresponding to the new
63          template parameters.
64        </p>
65<div class="table">
66<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>
67<div class="table-contents"><table class="table" summary="Additional RMCA Expressions in boost::crc_optimal">
68<colgroup>
69<col>
70<col>
71</colgroup>
72<thead><tr>
73<th>
74                  <p>
75                    New Member
76                  </p>
77                </th>
78<th>
79                  <p>
80                    Equivalent
81                  </p>
82                </th>
83</tr></thead>
84<tbody>
85<tr>
86<td>
87                  <p>
88                    <code class="computeroutput"><span class="identifier">truncated_polynominal</span></code>
89                  </p>
90                </td>
91<td>
92                  <p>
93                    <code class="computeroutput"><span class="identifier">get_truncated_polynominal</span></code>
94                  </p>
95                </td>
96</tr>
97<tr>
98<td>
99                  <p>
100                    <code class="computeroutput"><span class="identifier">initial_remainder</span></code>
101                  </p>
102                </td>
103<td>
104                  <p>
105                    <code class="computeroutput"><span class="identifier">get_initial_remainder</span></code>
106                  </p>
107                </td>
108</tr>
109<tr>
110<td>
111                  <p>
112                    <code class="computeroutput"><span class="identifier">reflect_input</span></code>
113                  </p>
114                </td>
115<td>
116                  <p>
117                    <code class="computeroutput"><span class="identifier">get_reflect_input</span></code>
118                  </p>
119                </td>
120</tr>
121<tr>
122<td>
123                  <p>
124                    <code class="computeroutput"><span class="identifier">reflect_remainder</span></code>
125                  </p>
126                </td>
127<td>
128                  <p>
129                    <code class="computeroutput"><span class="identifier">get_reflect_remainder</span></code>
130                  </p>
131                </td>
132</tr>
133<tr>
134<td>
135                  <p>
136                    <code class="computeroutput"><span class="identifier">final_xor_value</span></code>
137                  </p>
138                </td>
139<td>
140                  <p>
141                    <code class="computeroutput"><span class="identifier">get_final_xor_value</span></code>
142                  </p>
143                </td>
144</tr>
145</tbody>
146</table></div>
147</div>
148<br class="table-break">
149</li>
150<li class="listitem">
151          Removing the <code class="computeroutput"><span class="identifier">process_bit</span></code>
152          and <code class="computeroutput"><span class="identifier">process_bits</span></code> member
153          functions.
154        </li>
155<li class="listitem">
156          Adding two versions of the <code class="computeroutput"><span class="keyword">operator</span>
157          <span class="special">()</span></code> member function. The single-argument
158          version forwards to <code class="computeroutput"><span class="identifier">process_byte</span></code>,
159          making it suitable to STL algorithms that take (and possibly return) function
160          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>,
161          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>.
162        </li>
163<li class="listitem">
164          Merging the two <code class="computeroutput"><span class="identifier">reset</span></code> member
165          functions into one. (It uses a single parameter that can have a default
166          argument).
167        </li>
168</ul></div>
169<p>
170      The major difference between <code class="computeroutput"><span class="identifier">crc_basic</span></code>
171      and <code class="computeroutput"><span class="identifier">crc_optimal</span></code> is the internals.
172      Objects from <code class="computeroutput"><span class="identifier">crc_basic</span></code> run
173      their CRC algorithm one bit at a time, no matter which unit is used as input.
174      Objects from <code class="computeroutput"><span class="identifier">crc_optimal</span></code>, when
175      <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.
176    </p>
177<p>
178      Since all of the parameters are specified at compile-time, you cannot reuse
179      a single computer object for separate runs with differing parameters. The type
180      uses the automatically-defined copy/move/assign and destruction routines.
181    </p>
182<div class="footnotes">
183<br><hr style="width:100; text-align:left;margin-left: 0">
184<div id="ftn.crc.crc_optimal.f0" class="footnote"><p><a href="#crc.crc_optimal.f0" class="para"><sup class="para">[3] </sup></a>
185        i.e. The interim-remainder before any input is read.
186      </p></div>
187<div id="ftn.crc.crc_optimal.f1" class="footnote"><p><a href="#crc.crc_optimal.f1" class="para"><sup class="para">[4] </sup></a>
188            Like <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span></code>.
189          </p></div>
190<div id="ftn.crc.crc_optimal.f2" class="footnote"><p><a href="#crc.crc_optimal.f2" class="para"><sup class="para">[5] </sup></a>
191            Albeit this object won't change its return value within code that only
192            uses it as a generator.
193          </p></div>
194<div id="ftn.crc.crc_optimal.f3" class="footnote"><p><a href="#crc.crc_optimal.f3" class="para"><sup class="para">[6] </sup></a>
195        i.e. The optimizations are suspended if the <span class="emphasis"><em>WIDTH</em></span> only
196        justifies using part of a single byte.
197      </p></div>
198</div>
199</div>
200<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
201<td align="left"></td>
202<td align="right"><div class="copyright-footer">Copyright © 2001, 2003, 2012 Daryle Walker<p>
203        Distributed under the Boost Software License, Version 1.0. (See the accompanying
204        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>)
205      </p>
206</div></td>
207</tr></table>
208<hr>
209<div class="spirit-nav">
210<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>
211</div>
212</body>
213</html>
214