This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Double-Precision and Mathematical Operations

Other Parts Discussed in Thread: EK-TM4C123GXL

I am attempting to run a DSP algorithm on a TM4C123GXL board using CCS and I have a couple of questions:

1. In the TM4C123G documentation regarding the FPU single-precision support is mentioned, without mentioning double-precision support. Nevertheless, when I try to define a variable of the type "double" and run a code with it, I don't get any noticeable errors or warnings. Also, when I check the code via debug I see that the values received do indeed behave like "double" does (greater precision).

What is the extent of the board's support regarding "double"-type variables? Are double-precision calculations supported?

2. In the same context, when I try to use the "log()" function (which is recognized as a funcion and documented in CCS as getting "double" argument and returning "double" value), I get a fault ISR and I don't understand why (assuming there is support for "double" variables). What could be the problem?

The code I'm testing this with is a small variation on the Lab 9 code in the TM4C123G workshop:

#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/fpu.h"
#include "driverlib/sysctl.h"
#include "driverlib/rom.h"

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define SERIES_LENGTH 100
double gSeriesData[SERIES_LENGTH];
int32_t i32DataCount = 0;

int main(void)
{
	double fRadians;
	FPULazyStackingEnable();
	FPUEnable();
	SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
	fRadians = ((2 * M_PI) / SERIES_LENGTH);
	while(i32DataCount < SERIES_LENGTH)
	{ 
		gSeriesData[i32DataCount] = log(10.0 * fRadians);
		i32DataCount++;
	}
	while(1)
	{
	}
}

Thanks in advance,

Avner.

  • Hello Avner,

    Did you check the FPU Fault Status Register FPSCR and it would show the corresponding bit that is the source of the fault.

    And then this...

    community.arm.com/.../DOC-7544

    Regards
    Amit
  • Hi,

    The math.h file contains also a number of functions with -f suffix, related to floating point processing, like float logf(float x)

    If doing intensive DSP, then it worth to look to CMISIS package, which has a big DSP library/functions, based on SIMD instructions (some of them), although it exist only an unofficial release of CMSIS files for Tiva micros.

  • Avner Lavi said:
    Are double-precision calculations supported?

    The Cortex-4MF has no hardware support for double-precision calculations. double-precision calculations are performed in software, as part of the run-time library supplied with the compiler.

    Avner Lavi said:
    I get a fault ISR and I don't understand why (assuming there is support for "double" variables). What could be the problem?

    I tried the code example on a EK-TM4C123GXL, using TI ARM compiler v5.2.5, and it ran successfully. This was with the stack size of 512 bytes which is the default for a newly created project.

  • Do you actually require double precision?

    I have my doubts that you require the dynamic range and if you need precision then integers are a better choice.

    Robert
  • With single-precision support on the M4F, there is arguably no gain in using integer over float. But that may depend on the operations involved.

    However,  the requirements "double precision" and "speed" are still mutually exclusive.

  • Integer will have higher precision than single-precision floating point on an ARM.

    Robert

    Edit - added single precision qualifier

  • That is likely not important though. The data will seldom justify even 16 bits of precision.

    Robert
  • Under "integer implementation", I do not only understand a kinda "normal" implementation using C language data types, but also tricky algorithms to avoid larger data types, like 11-bit /5-bit algorithms I worked with on a 8-bit PIC controller cr*p.

    Accuracy aside (24-bit float mantissa vs. 32-bit integer), ther is often no performance gain when using integer.