Ticket #8830: crc_polynomial.patch
File crc_polynomial.patch, 19.2 KB (added by , 9 years ago) |
---|
-
boost/crc.hpp
198 198 199 199 // Internal Operations 200 200 //! Return the (truncated) polynomial divisor 201 value_type get_truncated_polynomi nal() const;201 value_type get_truncated_polynomial() const; 202 202 //! Return what the polynomial remainder was set to during construction 203 203 value_type get_initial_remainder() const; 204 204 //! Return the XOR-mask used during output processing … … 284 284 //! \copydoc boost::crc_basic::bit_count 285 285 BOOST_STATIC_CONSTANT( std::size_t, bit_count = Bits ); 286 286 //! A copy of \a TruncPoly provided for meta-programming purposes 287 BOOST_STATIC_CONSTANT( value_type, truncated_polynomi nal = TruncPoly );287 BOOST_STATIC_CONSTANT( value_type, truncated_polynomial = TruncPoly ); 288 288 //! A copy of \a InitRem provided for meta-programming purposes 289 289 BOOST_STATIC_CONSTANT( value_type, initial_remainder = InitRem ); 290 290 //! A copy of \a FinalXor provided for meta-programming purposes … … 299 299 explicit crc_optimal( value_type init_rem = initial_remainder ); 300 300 301 301 // Internal Operations 302 //! \copybrief boost::crc_basic::get_truncated_polynomi nal303 value_type get_truncated_polynomi nal() const;302 //! \copybrief boost::crc_basic::get_truncated_polynomial 303 value_type get_truncated_polynomial() const; 304 304 //! \copybrief boost::crc_basic::get_initial_remainder 305 305 value_type get_initial_remainder() const; 306 306 //! \copybrief boost::crc_basic::get_final_xor_value … … 1568 1568 the RMCA) 1569 1569 1570 1570 \post <code><var>truncated_polynomial</var> == 1571 this->get_truncated_polynomi nal()</code>1571 this->get_truncated_polynomial()</code> 1572 1572 \post <code><var>initial_remainder</var> == 1573 1573 this->get_initial_remainder()</code> 1574 1574 \post <code><var>final_xor_value</var> == … … 1611 1611 template < std::size_t Bits > 1612 1612 inline 1613 1613 typename crc_basic<Bits>::value_type 1614 crc_basic<Bits>::get_truncated_polynomi nal1614 crc_basic<Bits>::get_truncated_polynomial 1615 1615 ( 1616 1616 ) const 1617 1617 { … … 1941 1941 \param[in] init_rem The (unaugmented) initial state of the polynomial 1942 1942 remainder. Defaults to #initial_remainder if omitted. 1943 1943 1944 \post <code>#truncated_polynomi nal ==1945 this->get_truncated_polynomi nal()</code>1944 \post <code>#truncated_polynomial == 1945 this->get_truncated_polynomial()</code> 1946 1946 \post <code>#initial_remainder == this->get_initial_remainder()</code> 1947 1947 \post <code>#final_xor_value == this->get_final_xor_value()</code> 1948 1948 \post <code>#reflect_input == this->get_reflect_input()</code> … … 1963 1963 { 1964 1964 } 1965 1965 1966 //! \copydetails boost::crc_basic::get_truncated_polynomi nal1966 //! \copydetails boost::crc_basic::get_truncated_polynomial 1967 1967 template < std::size_t Bits, BOOST_CRC_PARM_TYPE TruncPoly, 1968 1968 BOOST_CRC_PARM_TYPE InitRem, BOOST_CRC_PARM_TYPE FinalXor, 1969 1969 bool ReflectIn, bool ReflectRem > 1970 1970 inline 1971 1971 typename BOOST_CRC_OPTIMAL_NAME::value_type 1972 BOOST_CRC_OPTIMAL_NAME::get_truncated_polynomi nal1972 BOOST_CRC_OPTIMAL_NAME::get_truncated_polynomial 1973 1973 ( 1974 1974 ) const 1975 1975 { 1976 return truncated_polynomi nal;1976 return truncated_polynomial; 1977 1977 } 1978 1978 1979 1979 //! \copydetails boost::crc_basic::get_initial_remainder -
libs/crc/crc.html
102 102 103 103 <h2><a name="background">Background</a></h2> 104 104 105 <p>CRCs work by computing the remainder of a modulo-2 polynomi nal105 <p>CRCs work by computing the remainder of a modulo-2 polynomial 106 106 division. The message is treated as the (binary) coefficents of a long 107 polynomi nal for the dividend, with the earlier bits of the message fed108 first as the polynomi nal's highest coefficents. A particular CRC109 algorithm has another polynomi nal associated with it to be used as the107 polynomial for the dividend, with the earlier bits of the message fed 108 first as the polynomial's highest coefficents. A particular CRC 109 algorithm has another polynomial associated with it to be used as the 110 110 divisor. The quotient is ignored. The remainder of the division 111 111 considered the checksum. However, the division uses modulo-2 rules (no 112 112 carries) for the coefficents.</p> … … 120 120 <h3><a name="parameters">CRC Parameters</a></h3> 121 121 122 122 <dl> 123 <dt>Truncated polynomi nal124 <dd>The divisor polynomi nal has a degree one bit larger than the123 <dt>Truncated polynomial 124 <dd>The divisor polynomial has a degree one bit larger than the 125 125 checksum (remainder) size. That highest bit is always one, so 126 126 it is ignored when describing a particular CRC type. Excluding 127 127 this bit makes the divisor fit in the same data type as the … … 145 145 <dt>Reflected input 146 146 <dd>A message's bits are usually fed a byte at a time, with the 147 147 highest bits of the byte treated as the higher bits of the 148 dividend polynomi nal. Some CRCs reflect the bits (about the148 dividend polynomial. Some CRCs reflect the bits (about the 149 149 byte's center, so the first and last bits are switched, 150 150 <i>etc.</i>) before feeding. 151 151 … … 167 167 static std::size_t const bit_count = Bits; 168 168 169 169 // Constructor 170 explicit crc_basic( value_type truncated_polynomi nal,170 explicit crc_basic( value_type truncated_polynomial, 171 171 value_type initial_remainder = 0, value_type final_xor_value = 0, 172 172 bool reflect_input = false, bool reflect_remainder = false ); 173 173 174 174 // Internal Operations 175 value_type get_truncated_polynomi nal() const;175 value_type get_truncated_polynomial() const; 176 176 value_type get_initial_remainder() const; 177 177 value_type get_final_xor_value() const; 178 178 bool get_reflect_input() const; … … 218 218 219 219 // Constants reflecting template parameters 220 220 static std::size_t const bit_count = Bits; 221 static value_type const truncated_polynomi nal = TruncPoly;221 static value_type const truncated_polynomial = TruncPoly; 222 222 static value_type const initial_remainder = InitRem; 223 223 static value_type const final_xor_value = FinalXor; 224 224 static bool const reflect_input = ReflectIn; … … 228 228 explicit crc_optimal( value_type init_rem = InitRem ); 229 229 230 230 // Internal Operations 231 value_type get_truncated_polynomi nal() const;231 value_type get_truncated_polynomial() const; 232 232 value_type get_initial_remainder() const; 233 233 value_type get_final_xor_value() const; 234 234 bool get_reflect_input() const; … … 264 264 template parameters. No individual bits are considered; only whole 265 265 bytes are passed. A table of interim CRC values versus byte values is 266 266 pre-computed when the first object using a particular bit size, 267 truncated polynomi nal, and input reflection state is processed.</p>267 truncated polynomial, and input reflection state is processed.</p> 268 268 269 269 <h2><a name="usage">Computer Usage</a></h2> 270 270 … … 278 278 default-constructed.</p> 279 279 280 280 <p>The CRC parameters can be inspected at run-time with the following 281 member functions: <code>get_truncated_polynomi nal</code>,281 member functions: <code>get_truncated_polynomial</code>, 282 282 <code>get_initial_remainder</code>, <code>get_final_xor_value</code>, 283 283 <code>get_reflect_input</code>, and <code>get_reflect_remainder</code>. 284 284 The fast computer also provides compile-time constants for its CRC … … 449 449 as the register size) after the message bits.</p> 450 450 451 451 <p>The template parameters of the function template are 452 the CRC's bit size (<code>Bits</code>) and the truncated polynomi nal452 the CRC's bit size (<code>Bits</code>) and the truncated polynomial 453 453 (<code>TruncPoly</code>). The function parameters are the starting address of 454 454 the data block to be worked on (<var>buffer</var>), the number of bytes in that 455 455 data block (<var>byte_count</var>), and the incoming value of the remainder … … 473 473 <var>initial_remainder</var> when calling <code>augmented_crc</code> on 474 474 the next data block. Remember that the actual CRC can only be 475 475 determined after feeding the augmented bytes. Since this method uses 476 modulo-2 polynomi nal division at its most raw, neither final XOR values476 modulo-2 polynomial division at its most raw, neither final XOR values 477 477 nor reflection can be used.</p> 478 478 479 479 <p>Note that for the same CRC system, the initial remainder for -
libs/crc/doc/crc.qbk
241 241 [table:crc_basic_rmca RMCA Parameters in boost::crc_basic 242 242 [[Parameter] [Member Name] [Kind] [Expression Type]] 243 243 [[['WIDTH]] [`bit_count`] [class-static immutable data member] [`std::size_t`]] 244 [[['POLY]] [`get_truncated_polynomi nal`] [`const` member function] [`value_type`]]244 [[['POLY]] [`get_truncated_polynomial`] [`const` member function] [`value_type`]] 245 245 [[['INIT]] [`get_initial_remainder`] [`const` member function] [`value_type`]] 246 246 [[['REFIN]] [`get_reflect_input`] [`const` member function] [`bool`]] 247 247 [[['REFOUT]] [`get_reflect_remainder`] [`const` member function] [`bool`]] … … 323 323 template parameters. 324 324 [table:crc_optimal_rmca Additional RMCA Expressions in boost::crc_optimal 325 325 [[New Member] [Equivalent]] 326 [[`truncated_polynomi nal`] [`get_truncated_polynominal`]]326 [[`truncated_polynomial`] [`get_truncated_polynomial`]] 327 327 [[`initial_remainder`] [`get_initial_remainder`]] 328 328 [[`reflect_input`] [`get_reflect_input`]] 329 329 [[`reflect_remainder`] [`get_reflect_remainder`]] -
libs/crc/test/crc_test.cpp
8 8 // See <http://www.boost.org/libs/crc/> for the library's home page. 9 9 10 10 // Revision History 11 // 28 Aug 2004 Added CRC tests for polynomi nals shorter than 8 bits11 // 28 Aug 2004 Added CRC tests for polynomials shorter than 8 bits 12 12 // (Daryle Walker, by patch from Bert Klaps) 13 13 // 23 Aug 2003 Adjust to updated Test framework (Daryle Walker) 14 14 // 14 May 2001 Initial version (Daryle Walker) … … 138 138 139 139 // Process the first half of the data (also test accessors) 140 140 optimal_crc_type fast_crc1; 141 basic_crc_type slow_crc1( fast_crc1.get_truncated_polynomi nal(),141 basic_crc_type slow_crc1( fast_crc1.get_truncated_polynomial(), 142 142 fast_crc1.get_initial_remainder(), fast_crc1.get_final_xor_value(), 143 143 fast_crc1.get_reflect_input(), fast_crc1.get_reflect_remainder() ); 144 144 … … 154 154 155 155 // Process the second half of the data (also test accessors) 156 156 boost::crc_optimal<optimal_crc_type::bit_count, 157 optimal_crc_type::truncated_polynomi nal, optimal_crc_type::initial_remainder,157 optimal_crc_type::truncated_polynomial, optimal_crc_type::initial_remainder, 158 158 optimal_crc_type::final_xor_value, optimal_crc_type::reflect_input, 159 159 optimal_crc_type::reflect_remainder> 160 160 fast_crc2( fast_crc1.get_interim_remainder() ); 161 161 boost::crc_basic<basic_crc_type::bit_count> slow_crc2( 162 slow_crc1.get_truncated_polynomi nal(), slow_crc1.get_interim_remainder(),162 slow_crc1.get_truncated_polynomial(), slow_crc1.get_interim_remainder(), 163 163 slow_crc1.get_final_xor_value(), slow_crc1.get_reflect_input(), 164 164 slow_crc1.get_reflect_remainder() ); 165 165 … … 180 180 { 181 181 PRIVATE_DECLARE_BOOST( uint32_t ); 182 182 183 // A single-bit error is ensured to be detected if the polynomi nal183 // A single-bit error is ensured to be detected if the polynomial 184 184 // has at least two bits set. The highest bit is what is removed 185 // to give the truncated polynomi nal, and it is always set. This186 // means that the truncated polynomi nal needs at least one of its185 // to give the truncated polynomial, and it is always set. This 186 // means that the truncated polynomial needs at least one of its 187 187 // bits set, which implies that it cannot be zero. 188 188 if ( !(TrPo & boost::detail::low_bits_mask_c<Bits>::value) ) 189 189 { … … 744 744 small_crc_test1(); 745 745 small_crc_test2(); 746 746 747 // Try a CRC based on the (x + 1) polynomi nal, which is a factor in748 // many real-life polynomi nals and doesn't fit evenly in a byte.749 cout << "Doing one-bit polynomi nal CRC test." << endl;747 // Try a CRC based on the (x + 1) polynomial, which is a factor in 748 // many real-life polynomials and doesn't fit evenly in a byte. 749 cout << "Doing one-bit polynomial CRC test." << endl; 750 750 boost::crc_basic<1> crc_1( 1 ); 751 751 crc_1.process_bytes( std_data, std_data_len ); 752 752 BOOST_CHECK( crc_1.checksum() == 1 ); -
libs/crc/test/crc_test2.cpp
101 101 typedef typename boost::uint_t<Bits>::fast register_type; 102 102 typedef boost::crc_basic<Bits> computer_type; 103 103 104 register_type divisor_polynomi nal;104 register_type divisor_polynomial; 105 105 register_type initial_remainder; 106 106 bool reflect_input_byte; 107 107 bool reflect_output_remainder; 108 108 register_type final_xor_mask; 109 109 110 110 computer_type make_crc_basic() const 111 { return computer_type(divisor_polynomi nal, initial_remainder,111 { return computer_type(divisor_polynomial, initial_remainder, 112 112 final_xor_mask, reflect_input_byte, reflect_output_remainder); } 113 113 }; 114 114 … … 125 125 126 126 typedef boost::mpl::size_t<Bits> register_length_c; 127 127 typedef boost::mpl::integral_c<register_type, DivisorPolynominal> 128 divisor_polynomi nal_c;128 divisor_polynomial_c; 129 129 typedef boost::mpl::integral_c<register_type, InitialRemainder> 130 130 initial_remainder_c; 131 131 typedef boost::mpl::bool_<ReflectInputBytes> reflect_input_byte_c; … … 136 136 137 137 operator rt_adaptor_type() const 138 138 { 139 rt_adaptor_type const result = { divisor_polynomi nal_c::value,139 rt_adaptor_type const result = { divisor_polynomial_c::value, 140 140 initial_remainder_c::value, reflect_input_byte_c::value, 141 141 reflect_output_remainder_c::value, final_xor_mask_c::value }; 142 142 … … 145 145 146 146 static computer_type make_crc_optimal() 147 147 { return boost::crc_optimal<register_length_c::value, 148 divisor_polynomi nal_c::value, initial_remainder_c::value,148 divisor_polynomial_c::value, initial_remainder_c::value, 149 149 final_xor_mask_c::value, reflect_input_byte_c::value, 150 150 reflect_output_remainder_c::value>(); } 151 151 }; … … 165 165 166 166 typedef boost::mpl::size_t<Bits> register_length_c; 167 167 typedef boost::mpl::integral_c<register_type, DivisorPolynominal> 168 divisor_polynomi nal_c;168 divisor_polynomial_c; 169 169 typedef boost::mpl::integral_c<register_type, InitialRemainder> 170 170 initial_remainder_c; 171 171 typedef boost::mpl::bool_<ReflectInputBytes> reflect_input_byte_c; … … 239 239 BOOST_AUTO( crc_s, CRCPolicy::make_crc_basic() ); 240 240 typename CRCPolicy::register_type const func_result 241 241 = boost::crc<CRCPolicy::register_length_c::value, 242 CRCPolicy::divisor_polynomi nal_c::value,242 CRCPolicy::divisor_polynomial_c::value, 243 243 CRCPolicy::initial_remainder_c::value, 244 244 CRCPolicy::final_xor_mask_c::value, 245 245 CRCPolicy::reflect_input_byte_c::value, … … 264 264 265 265 // Test accessors 266 266 optimal_crc_type faster_crc1; 267 basic_crc_type slower_crc1( faster_crc1.get_truncated_polynomi nal(),267 basic_crc_type slower_crc1( faster_crc1.get_truncated_polynomial(), 268 268 faster_crc1.get_initial_remainder(), faster_crc1.get_final_xor_value(), 269 269 faster_crc1.get_reflect_input(), faster_crc1.get_reflect_remainder() ); 270 270 … … 282 282 // Process the second half of the standard data, testing more accessors 283 283 unsigned char const * const std_data_end = std_data + std_data_len; 284 284 boost::crc_optimal<optimal_crc_type::bit_count, 285 optimal_crc_type::truncated_polynomi nal,285 optimal_crc_type::truncated_polynomial, 286 286 optimal_crc_type::initial_remainder, optimal_crc_type::final_xor_value, 287 287 optimal_crc_type::reflect_input, optimal_crc_type::reflect_remainder> 288 288 faster_crc2( faster_crc1.get_interim_remainder() ); 289 289 boost::crc_basic<basic_crc_type::bit_count> slower_crc2( 290 slower_crc1.get_truncated_polynomi nal(),290 slower_crc1.get_truncated_polynomial(), 291 291 slower_crc1.get_interim_remainder(), slower_crc1.get_final_xor_value(), 292 292 slower_crc1.get_reflect_input(), slower_crc1.get_reflect_remainder() ); 293 293 … … 308 308 // modulo-2 polynomial divisor has at least two non-zero coefficients. The 309 309 // implicit highest coefficient is always one, so that leaves an explicit 310 310 // coefficient, i.e. at least one of the polynomial's bits is set. 311 BOOST_REQUIRE( CRCPolicy::divisor_polynomi nal_c::value &311 BOOST_REQUIRE( CRCPolicy::divisor_polynomial_c::value & 312 312 low_bits_mask_c<CRCPolicy::register_length_c::value>::value ); 313 313 314 314 // Create a random block of data … … 481 481 return boost::crc<3u, 0x03u, 0u, 0u, false, false>( buffer, byte_count ); 482 482 } 483 483 484 BOOST_AUTO_TEST_CASE( sub_nybble_polynomi nal_test )484 BOOST_AUTO_TEST_CASE( sub_nybble_polynomial_test ) 485 485 { 486 486 // The CRC standard is a SDH/SONET Low Order LCAS control word with CRC-3 487 487 // taken from ITU-T G.707 (12/03) XIII.2. … … 529 529 return boost::crc<7u, 0x09u, 0u, 0u, false, false>( buffer, byte_count ); 530 530 } 531 531 532 BOOST_AUTO_TEST_CASE( sub_octet_polynomi nal_test )532 BOOST_AUTO_TEST_CASE( sub_octet_polynomial_test ) 533 533 { 534 534 // The CRC standard is a SDH/SONET J0/J1/J2/N1/N2/TR TTI (trace message) 535 535 // with CRC-7, o.a. ITU-T G.707 Annex B, G.832 Annex A. … … 564 564 // byte-wise, so the register size needs to be a multiple of CHAR_BIT.) 565 565 } 566 566 567 BOOST_AUTO_TEST_CASE( one_bit_polynomi nal_test )567 BOOST_AUTO_TEST_CASE( one_bit_polynomial_test ) 568 568 { 569 // Try a CRC based on the (x + 1) polynomi nal, which is a factor in570 // many real-life polynomi nals and doesn't fit evenly in a byte.569 // Try a CRC based on the (x + 1) polynomial, which is a factor in 570 // many real-life polynomials and doesn't fit evenly in a byte. 571 571 boost::crc_basic<1u> crc_1( 1u ); 572 572 573 573 crc_1.process_bytes( std_data, std_data_len ); -
libs/math/test/common_factor_test.cpp
31 31 32 32 namespace { 33 33 34 // TODO: add polynomi nal/non-real type; especially after any switch to the34 // TODO: add polynomial/non-real type; especially after any switch to the 35 35 // binary-GCD algorithm for built-in types 36 36 37 37 // Custom integer class (template) … … 363 363 } 364 364 365 365 // TODO: non-built-in signed and unsigned integer tests, with and without 366 // numeric_limits specialization; polynomi nal tests; note any changes if366 // numeric_limits specialization; polynomial tests; note any changes if 367 367 // built-ins switch to binary-GCD algorithm 368 368 369 369 BOOST_AUTO_TEST_SUITE_END()