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
2,003 Views
Registered: ‎07-09-2017

SDK int32_t and u32

Jump to solution

Hi,

 

In SDK I set an int32_t data type value to a driver function with u32 parameter data type. The input value is (-2).

I use the getting value driver function and the result is (4095), but not (-2). I am confused how the data type in the driver function is implemented. Why can we give an int32_t type data to an u32 parameter?

 

Regards,

 

0 Kudos
1 Solution

Accepted Solutions
2,984 Views
Registered: ‎03-27-2014

Re: SDK int32_t and u32

Jump to solution

@jianmingli1

 

4095, -2 - I'm pretty sure you meant 4095 & -1, but anyways..

 

they're just the decimal representation (printf("%d")) of two identical numbers but one being declared as signed two's complement & the other unsigned integer. You could see that bitwise (with printf(%x)) they're strictly identical.

 

Keep in mind at the "driver" level, you only deal with bits & bytes, sign bits & arithmetics are just ignored - so be careful at what you do and how you declare stuff.

 

I have to say this is fairly basic

G.W.,
NIST - Time Frequency metrology
0 Kudos
3 Replies
2,985 Views
Registered: ‎03-27-2014

Re: SDK int32_t and u32

Jump to solution

@jianmingli1

 

4095, -2 - I'm pretty sure you meant 4095 & -1, but anyways..

 

they're just the decimal representation (printf("%d")) of two identical numbers but one being declared as signed two's complement & the other unsigned integer. You could see that bitwise (with printf(%x)) they're strictly identical.

 

Keep in mind at the "driver" level, you only deal with bits & bytes, sign bits & arithmetics are just ignored - so be careful at what you do and how you declare stuff.

 

I have to say this is fairly basic

G.W.,
NIST - Time Frequency metrology
0 Kudos
Adventurer
Adventurer
1,975 Views
Registered: ‎07-09-2017

Re: SDK int32_t and u32

Jump to solution

@guillaumebres

 

Hi, friend,

 

thanks for your feedback.

I have one more doubt. If originally the function input data type is float or double, since they have floating point representation. How should I pass it to u32 or other in SDK?

Before I had one example, the input type was ap_fixed<12,1>, so I shifted the value to left with 11 bits, and casted it to int32_t.

 

Regards,

 

0 Kudos
1,962 Views
Registered: ‎03-27-2014

Re: SDK int32_t and u32

Jump to solution
@jianmingli1,

 


@jianmingli1 wrote:

@guillaumebres

 

Hi, friend,

 

thanks for your feedback.

I have one more doubt. If originally the function input data type is float or double, since they have floating point representation. How should I pass it to u32 or other in SDK?

 


it depends what you are trying to do.

 

  • if you want to convert the probably fractional value that is stored in float/double, into the best integer (int32 or uint32) reprensetation of that number: you could see int32 as a signed fixed point number with 31 integer bits and 1 sign bit, so you just need to multiply this value by 2^(31)
  • if you want to have the binary representation of that floating point number, that is not trivial because the floating point number is made of two numbers and printf only deals with its decimal value, the proper way to do this is:
float f = 3.14;
int i = *(int*)&f;
printf("0x%x\n", i);
--> which I think will output 0x00B8F5B4

which involves three steps: & gives you a pointer to that memory location (32 bit storage) of the floating point number. (int*) is a cast of that location into a integer compatible location. The final "*" is the usual "*" to retrieve the value of a memory location.

G.W.,
NIST - Time Frequency metrology