Float and Double for XMOS ?

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

Float and Double for XMOS ?

Postby HansWerner » Mon Jun 13, 2011 10:23 pm

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

Postby Berni » Mon Jun 13, 2011 10:38 pm

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

Postby Skeksis » Mon Jun 13, 2011 10:54 pm

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

Postby Bianco » Tue Jun 14, 2011 9:46 am

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

Postby Skeksis » Tue Jun 14, 2011 10:49 am

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

Postby mifay » Sat Jun 16, 2012 2:19 pm

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

Postby Bianco » Sat Jun 16, 2012 4:02 pm

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

Who is online

Users browsing this forum: No registered users and 0 guests