Skip to content

Comments

Add pre-processor error when trying to synthesize mgc_floor#16

Open
gabeusse wants to merge 1 commit intohlslibs:masterfrom
gabeusse:master
Open

Add pre-processor error when trying to synthesize mgc_floor#16
gabeusse wants to merge 1 commit intohlslibs:masterfrom
gabeusse:master

Conversation

@gabeusse
Copy link

@gabeusse gabeusse commented Mar 12, 2021

During synthesis, the calls to mgc_floor are stubbed to return 0.0, which can also be observed in the generated HDL. This change guards against unintended (indirect) uses of the function in code that is supposed to be translated into hardware. A basic test case to validate the change is:

#include <ac_int.h>
#include <iostream>

double t(double A[5], double inc) {
  for(int h = 0; h < 5; h++) {
    A[h] =  ac_private::mgc_floor(A[h] + inc);
  }
}

int main()
{   
  double A[5] = {1.2, 2.3, 3.4, 4.5, 5.6};
  t(A, 2.1);
  for(int h = 0; h < 5; h++)
    std::cout << "A[" << h << "] = " << A[h] << std::endl;
  return 0;
}

Where the output for simulation can be obtained with:

$ g++ -I/usr/local/bin/Mentor_Graphics/Catapult_Synthesis_10.6-912629/Mgc_home/shared/include t.cpp -o test_mgc
$ ./test_mgc 

A[0] = 3
A[1] = 4
A[2] = 5
A[3] = 6
A[4] = 7

And the behavior for synthesis (when SYNTHESIS is defined) is:

$ g++ -D__SYNTHESIS__ -I/usr/local/bin/Mentor_Graphics/Catapult_Synthesis_10.6-912629/Mgc_home/shared/include t.cpp -o test_mgc
In file included from t.cpp:331:0:
/usr/local/bin/Mentor_Graphics/Catapult_Synthesis_10.6-912629/Mgc_home/shared/include/ac_int.h:163:6: error: #error "mgc_floor on floating point types is not allowed for synthesis"
     #error "mgc_floor on floating point types is not allowed for synthesis"
      ^~~~~

Compilation was performed with g++ 7.5.0

@nkkav
Copy link

nkkav commented Mar 12, 2021

Can you include ac_int.h from the forked repository instead? I know that there is no test folder in ac_types so no good place to place your testcase.

I think you can also drop the f suffix from the float literals as you are using a double storage and the tested function uses double arguments (otherwise promotion will happen of course).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants