UPGRADE YOUR BROWSER

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!

cancel
Showing results for 
Search instead for 
Did you mean: 
Adventurer
Adventurer
941 Views
Registered: ‎07-09-2017

fixed point type casting for SystemC and C++

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.

 

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 )

 

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++.

 

Regards

 

Jim

0 Kudos
3 Replies
Teacher muzaffer
Teacher
868 Views
Registered: ‎03-31-2012

Re: fixed point type casting for SystemC and C++

@jianmingli1 can you show what happens if you just do:

 

complex<ap_fixed<10, 5> > a, b, c;

 

c = a * b;

 

?

 

 

- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
Teacher muzaffer
Teacher
864 Views
Registered: ‎03-31-2012

Re: fixed point type casting for SystemC and C++

@jianmingli1 tried the following code and it works as expected (you can try to comment out real/imag lines and see with initializations)

#include <ap_fixed.h>
#include <complex>

int main(void) {
        std::complex<ap_fixed<15, 5> > a(2, 0);
        std::complex<ap_fixed<15, 5> > b(4, 0);
        std::complex<ap_fixed<15, 5> > c;

        a.real(0);
        a.imag(1);
        b.real(0);
        b.imag(1);
        c = a * b;
        std::cout << "a:" << a << " b:" << b << " c: " << c;
}
- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
Adventurer
Adventurer
833 Views
Registered: ‎07-09-2017

Re: fixed point type casting for SystemC and C++

@muzaffer

 

Hi friend,

 

thanks for the feedback.

I see you set both input and output data type as complex<ap_fixed<15,5> >, and the test data with a small value. Could you try with a big value, which makes the multiplication with a possible overflow, like a(10, 1), b(12, 2), then the output should be set with a different word and integer length. And I think without typecasting this will not work as expected.

 

Regards


std::complex<ap_fixed<15, 5> > a(2, 0); std::complex<ap_fixed<15, 5> > b(4, 0); std::complex<ap_fixed<15, 5> > c;

 

0 Kudos