Float and Double for XMOS ?

Non-technical related questions should go here.
Post Reply
HansWerner
Member
Posts: 8
Joined: Mon Jun 13, 2011 9:51 pm

Float and Double for XMOS ?

Post by HansWerner »

I have just registered and did some reading about the project.
Will XMOS support floating point arithmetic in the near future ?
As I have read this is not the case at the moment.


User avatar
Berni
Respected Member
Posts: 363
Joined: Thu Dec 10, 2009 10:17 pm
Contact:

Post by Berni »

You can still use float inside of a .c file and call that from a the XC code.
User avatar
Skeksis
Active Member
Posts: 61
Joined: Sat May 28, 2011 9:42 pm
Location: England
Contact:

Post by Skeksis »

Can the chip support floating points then, is it just the compiler which doesn't??
"Time is an illusion. Lunch-time doubly so." - Douglas Adams
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm
Contact:

Post by Bianco »

Floating point is not supported by the hardware.
The compiler generates the code to handle the floating point.
User avatar
Skeksis
Active Member
Posts: 61
Joined: Sat May 28, 2011 9:42 pm
Location: England
Contact:

Post by Skeksis »

Ah, thanks Bianco. I thought that was probably the case but it's better to be absolutely clear.
"Time is an illusion. Lunch-time doubly so." - Douglas Adams
User avatar
mifay
Member++
Posts: 29
Joined: Wed Dec 28, 2011 4:15 pm

Post by mifay »

Berni wrote:You can still use float inside of a .c file and call that from a the XC code.
I've tried doing that, but the compiler still didn't allow me to use floating points. Do you have a dummy example code for me to use. Maybe I missed something.
Bianco wrote:Floating point is not supported by the hardware.
The compiler generates the code to handle the floating point.
Does that mean the hardware supports the compiled handling of floating points?
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm
Contact:

Post by Bianco »

mifay wrote:
Berni wrote:You can still use float inside of a .c file and call that from a the XC code.
I've tried doing that, but the compiler still didn't allow me to use floating points. Do you have a dummy example code for me to use. Maybe I missed something.
Bianco wrote:Floating point is not supported by the hardware.
The compiler generates the code to handle the floating point.
Does that mean the hardware supports the compiled handling of floating points?
You can't transfer the result of the floating point calculation as a float back to XC.
You will need to keep all floating point in the C files.

Floating point in C on XMOS is emulated using integer operations. This abandons the need of a FPU but it is significantly slower than having specialized instructions to handle floating points.

Code: Select all

#include <stdio.h>

int main (void)
{
  float f;
  
  f = 1.0/3.0;
  
  printf("float: %f\n", f);
    
  return 0;
}

Save and compile as a C file:

Code: Select all

C:\Users\Bianco\Desktop\xmos_doc\float_test>xcc -o test.xe -target=XK-1A test.c

C:\Users\Bianco\Desktop\xmos_doc\float_test>xsim test.xe
float: 0.333333
Post Reply