Use arbitrary bit width in the C + + algorithm design

Source: Internet
Author: User
Tags filter arithmetic

When developing fixed-point (fixed-point) algorithms, it is generally necessary to strike a balance between design functionality, digital precision modeling, and verification (simulation) speed. Now, a new data class simplifies this process, resulting in simpler and more accurate modeling precision, better refinement of numbers, and faster verification cycles, while ANSI C + + is the best language for developing this digital refinement algorithm.

This algorithm is inherently suitable for manipulating integers, or those ideal real numbers (such as the coefficients of digital filters), and they may also use floating-point or fixed-point types. In general, in the early stages of algorithmic development, the C-language float or double floating-point type is often used because they provide a very large dynamic range of data and are applicable to most programs. See Figure 1:

Modeling a FIR filter using the float type built into C

Algorithms can be refined digitally to use fixed-point arithmetic to reduce the complexity of final hardware or software implementations. In hardware, the integer or fixed-point arithmetic is limited to the minimum bit width, which can satisfy the requirement of performance, space and energy consumption in essence, if the DSP processor is used in the implementation, the algorithm can be used as the cheapest processor for a particular program if it is limited to integer or fixed-point arithmetic.

The modeling of fixed-point arithmetic can be done by means of floating-point or integer types built into the C language. To do this, you need to explicitly encode and be limited to the maximum number of floating-point numbers and integers in C: 64-bit integers or 53-bit mantissa; These all impose more restrictions on the bit width of the operand, for example, by multiplying the number of 2 33 digits, will exceed the range of 64-bit C integers that can be represented. Figure 2 illustrates an example of a FIR filter, but the TEMP variable is limited to 15-bit fixed-point precision, where 10 bits are used for integer digits. In this implementation, the right part of the LSB is discarded (the truncation of the quantization model), and the left part of the MSB is discarded (the wrapper overflow model), and it should be realized that the model using float (or double) is limited in precision and cannot be synthesized again (synthesis). Similarly, because the strict bit precision of the rounding model is defined first, and because the rounding of the built-in floating-point type will be applied first, it is very difficult to implement for operations such as division.

Using float to model fixed-point behavior

When many algorithms can rely on the precision of the local C data type to write, to support arbitrary length of the integer and fixed-point algorithm, we will have great expectations, and hardware description Language (HDL), such as VHDL, walk is the same path. As C + + is increasingly being used in the advanced Synthesis and verification tool (high-level synthesis and verification tools), it is also proven that the language has essentially a data type library sufficient to meet current and future applications. Support for any length type can also have a uniform definition of the behavior of the data type, while the unified semantics avoids some limitations on human implementation.

Algorithm C data type

The algorithm C data type is a class based C + + library, it implements an arbitrary length of integers and fixed-point types, and these freely accessible types have a range of benefits, including uniform and well-defined semantics, as well as running speeds comparable to the C/h + + built-in data types, compared to the corresponding types in SystemC, Its operating speed is also more than 10 times times. These data types can be used in any program that conforms to the C + + or SYSTEMC specification and have highly synthetic semantics.

Semantic

The unity and consistency of semantics is the key to avoiding functional errors in the algorithm, as illustrated by the following examples:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.