We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

## High-Level Synthesis (HLS)

Showing results for
Do you mean

## fixed point type casting issue

Posts: 59
Registered: ‎07-09-2017

# fixed point type casting issue

Hi,

Here I find one issue.

It's like that when I multiply two COMPLEX fixed point numbers, I need to cast the complex multiplicant and multiplicator. But for REAL fixed point numbers, it seems I donnot have to do type casting before multiplication. I have a small example below.

fixed point example:

typedef ap_fixed<4,3> data_in_t;
typedef ap_fixed<8,6> data_out_t;

void fixtest(data_in_t in1,data_in_t in2, data_out_t *out) {
*out = in1 * in2;
}

int main () {

data_in_t in1 = 3.5;
data_in_t in2 = 3.5;
data_out_t out;

fixtest( in1, in2, &out);
cout << out << endl;
return 0;
}

out = 12.25. ( correct, without typecasting )

complex fixed point example:

typedef complex<ap_fixed<4,3> > data_in_t;

typedef complex<ap_fixed<8,6> > data_out_t;

data_in_t in1 = data_in_t(1,3);

data_in_t in2 = data_in_t(2,3);

data_out_t out;

Out = in1 * in2;

-> Out = (1,1) (wrong, without typecasting)

Out =data_out_t( in1) * data_out_t(in2);

-> Out = (-7,9) (correct, with typecasting)

is there anyone who has such experience before?

and for complex fixed point number, if I have to do type casting befor multiply, it will consumes more resources, which is not I expected. How can I avoid this?

For example:

typedef ap_fixed<25,3> in_t;
typedef ap_ufixed<16,8> out_t;

typedef complex<ap_fixed<25,3> > data_in_t;

typedef ap_fixed<50,6> cast_t;

out_t tmp;

tmp = real(complex<cast_t >(in_value) * complex<cast_t >(conj(in_value)));

and in another environment (from Synopsys), type casting for multiplication is even not necessary for SystemC complex fixed data type (sc_fixed), which seems not the same for complex ap_fixed in C++.

In SystemC with sc_fixed:

typedef complex<sc_fixed<4,3> > data_in_t;

typedef complex<sc_fixed<8,6> > data_out_t;

data_in_t in1 = data_in_t(1,3);

data_in_t in2 = data_in_t(2,3);

data_out_t out;

Out = in1 * in2;

-> Out = (-7,9) (right, without typecasting)

Regards

Jim

Teacher
Posts: 5,143
Registered: ‎03-31-2012

## Re: fixed point type casting issue

[ Edited ]

@jianmingli1 It's possible there is a bug in interaction of complex and ap_fixed for Xilinx. Maybe the traits which are generating the output type don't work for templated types.

Give Kudos to a post which you think is helpful and reply oriented.
Posts: 59
Registered: ‎07-09-2017

## Re: fixed point type casting issue

@muzaffer yes, I think for complex fixed point explicit type CONVERSION is not supported for Xilinx yet.

Regards

Moderator
Posts: 1,207
Registered: ‎06-24-2015

## Re: fixed point type casting issue

@jianmingli1

CR has been filed for factory to look into this issue.

Thanks,
Nupur
--------------------------------------------------------------------------------------------
Google your question before posting. If someone's post answers your question, mark the post as answer with "Accept as solution". If you see a particularly good and informative post, consider giving it Kudos (click on the star mark).
Posts: 59
Registered: ‎07-09-2017

## Re: fixed point type casting issue

@nupurs

Hi, friend,

What does CR stand for here?

Regards,

Highlighted
Teacher
Posts: 5,143
Registered: ‎03-31-2012

## Re: fixed point type casting issue

@jianmingli1 Change Request. I opened an SR with the test case I made and now there is a CR to fix it.

Give Kudos to a post which you think is helpful and reply oriented.
Posts: 59
Registered: ‎07-09-2017

## Re: fixed point type casting issue

@nupurs

that is great. Thanks a lot.

Best regards

Moderator
Posts: 1,207
Registered: ‎06-24-2015

## Re: fixed point type casting issue

@jianmingli1

CR stands for Change Request and through CR we intimate the factory that there is a bug in the tool that needs to be fixed.

Thanks,
Nupur
--------------------------------------------------------------------------------------------
Google your question before posting. If someone's post answers your question, mark the post as answer with "Accept as solution". If you see a particularly good and informative post, consider giving it Kudos (click on the star mark).