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!

AR# 20848

9.2i EDK - Assigning a "double" type data does not generate the correct data


I am using an EDK supplied compiler to compile my code for PPC405 on a Virtex-II Pro target device. 


I try to write a 64-bit data into int RAM: 


eg : *(double *)0x0 = 0x1122334455667788; 


When I see the disassembly of the code, the stw data is not as I programmed; it is 0x43B1223344556678 instead of 0x1122334455667788 in assembly language. 


Why does this occur?


Most likely you are trying to store an 8 bytes value to memory. Instead of using double, you should use "volatile unsigned long long" or "volatile Xuint64": 


*(volatile unsigned long long *) 0x30 = 0x1122334455667788; 


The "volatile" guarantees that the compiler does not optimize the assignment away if optimizations are turned on. 


In the example below, the compiler is performing correctly. It takes an unsigned long constant, converts it to double precision floating point in IEEE format, and stores it to address location 0x30. You can verify the compiler is performing correctly by changing the program a bit and printing the value (you can also compile and run the program on a Windows/Linux/Solaris machine): 


 #include <stdio.h> 


int main() 

double a; 

a = 0x1122334455667788ULL; 

printf("%lld, %f\n", 0x1122334455667788, a); 

return 0; 


Running this prints: 


1234605616436508552, 1234605616436508672.000000 


This is the correct decimal value for the hexadecimal 0x1122334455667788. 


When you look at the disassembly of this program, 0x43b1223344556678 is the double precision IEEE representation of the same value.

AR# 20848
日付 05/19/2014
ステータス アーカイブ
種類 一般