Page 1 of 1

Float and Double for XMOS ?

Posted: Mon Jun 13, 2011 10:23 pm
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.

Re: Float and Double for XMOS ?

Posted: Mon Jun 13, 2011 10:38 pm
by Berni
You can still use float inside of a .c file and call that from a the XC code.

Re: Float and Double for XMOS ?

Posted: Mon Jun 13, 2011 10:54 pm
by Skeksis
Can the chip support floating points then, is it just the compiler which doesn't??

Re: Float and Double for XMOS ?

Posted: Tue Jun 14, 2011 9:46 am
by Bianco
Floating point is not supported by the hardware.
The compiler generates the code to handle the floating point.

Re: Float and Double for XMOS ?

Posted: Tue Jun 14, 2011 10:49 am
by Skeksis
Ah, thanks Bianco. I thought that was probably the case but it's better to be absolutely clear.

Re: Float and Double for XMOS ?

Posted: Sat Jun 16, 2012 2:19 pm
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?

Re: Float and Double for XMOS ?

Posted: Sat Jun 16, 2012 4:02 pm
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