Section 6.8. Language Constraints for Hardware Processes

6.8. Language Constraints for Hardware Processes

Impulse C is compatible with standard ANSI C and allows you to take full advantage of C language (and third-party C libraries) for describing the software elements of your application. For those parts of your application that will target hardware, however, many constraints are placed on your ability to write and compile general-purpose C code. Some of these constraints are are obvious in the context of hardware generation (it doesn't really make sense to support recursive function calls, for example), while other constraints are more specific to the Impulse C hardware compiler. Some of the following constraints, in fact, are specific to the tools that were available as of this writing and may no longer be constraints when you read this. Check with Impulse Accelerated Technologies at for the latest updates.

No Support for Hardware Function Calls

Impulse C processes are intended to be created at compile time and exist statically (as persistent objects) at runtime. As such, it is not feasible to call an Impulse C process as a remote procedure (with argument lists and return values) as is normally done in traditional C programming. Similarly, it is not possible for an Impulse C process that will be compiled to hardware to call other functions or processes in the usual manner. The one exception to this is inline functions, which are resolved at compile time and do not require any special hardware (such as a stack) in order to be implemented.

Integer Math Operations

For integer datatypes, the standard C arithmetic operations +, -, *, ++ are supported as single-cycle operations. Division using the / operation results in a multicycle implementation requiring one cycle for each bit in the result. The algorithm is designed to be low in area and delay, with the goal of reducing the overall system fMax.

Shift Operations

Shift operations are limited to constant values for the shift operand. For example, the following loop:

 iFlags = 0; for(i = 0; i < 8; i++) {     if(afCubeVal[i] <= FTARGETVALUE)         iFlags |= 1 << i;    // Not supported in hardware compilation } 

should be rewritten as:

 iFlags = 0; bit = 1; for(i = 0; i < 8; i++) {     if(afCubeVal[i] <= FTARGETVALUE)         iFlags |= bit;     bit = bit << 1; } 

Support for Datatypes Is Limited

As of this writing there is no support in the Impulse C compiler for complex datatypes such as structs and unions, although support for these datatypes is expected in a later release of the compiler. Floating-point types are also not supported at this writing.

Limited Support for Pointers

The use of pointers to reference array data in your Impulse C hardware processes is supported, but with some major limitations. Fundamentally, all uses of pointers must be resolvable at compile time to static references to specific memory locations. Therefore, pointer support in Impulse C hardware processes is limited to the following situations:

  1. <pointer> = & <array element>

    For example:

     p = &(a[4]);   // Assign address of fifth element 

  2. <pointer> ++

    For example:

     p++;   // Increment pointer 

  3. <pointer> = <pointer> + <integer expression>

    For example:

     p = p + 2;    // Pointer addition 

Also, pointers may not point to more than one array. The following, however, is allowed:

 p = &(a[2]);  ... p = &(a[3]); 

The second assignment in the following is not okay:

 p = &(a[2]); // This is OK  … p = &(b[3]); // This is not OK. Can't re-use the pointer for b 

Using Pointers with Multidimensional Arrays

Rather than using nested loops to iterate through a two-dimensional array, it is more efficient to write the following:

 p = &(a[0][0]); for (i=0; i<4*5; i++) {    ... // Access the array elements using p   p++; } 

    Practical FPGA Programming in C
    Practical FPGA Programming in C
    ISBN: 0131543180
    EAN: 2147483647
    Year: 2005
    Pages: 208 © 2008-2017.
    If you may any questions please contact us: