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.

CCS/TMS320F28377D: Using functions in standard math library throws ILLEGAL_ISR

Part Number: TMS320F28377D

Tool/software: Code Composer Studio

Hi,

I want to make a time-analysis for math operation between CPU and CLA. I want to use exponential function for this analysis.

I can successfully run exponantial function on CLA, it takes around 67 SYSCLK cycles. However when I try to use exp function in standard maht libray on CPU (not CLA) it throws ILLEGAL_ISR.

The line where this exception occurs in file e_expf.c on line 101. I copy whole function below.

My code is simple: 

float NumDen;
double temp;

NumDen = -1.56f;

temp = exp(NumDen); // Exception occurs

float expf(float x) function in e_expf.c

float
expf(float x)
{
	float y,hi=0.0,lo=0.0,c,t,twopk;
	int32_t k=0,xsb;
	uint32_t hx;

	GET_FLOAT_WORD(hx,x);
	xsb = (hx>>31)&1;		/* sign bit of x */
	hx &= 0x7fffffff;		/* high word of |x| */

    /* filter out non-finite argument */
	if(hx >= 0x42b17218) {			/* if |x|>=88.721... */
	    if(hx>0x7f800000)
		 return x+x;	 		/* NaN */
            if(hx==0x7f800000)
		return (xsb==0)? x:0.0;		/* exp(+-inf)={inf,0} */
	    if(x > o_threshold)
            {
                __raise_overflow();
                return INFINITY;
            }
	    if(x < u_threshold)
            {
                __raise_underflow();
                return 0;
            }
	}

    /* argument reduction */
	if(hx > 0x3eb17218) {		/* if  |x| > 0.5 ln2 */
	    if(hx < 0x3F851592) {	/* and |x| < 1.5 ln2 */
		hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb;
	    } else {
		k  = invln2*x+halF[xsb];
		t  = k;
		hi = x - t*ln2HI[0];	/* t*ln2HI is exact here */
		lo = t*ln2LO[0];
	    }
	    STRICT_ASSIGN(float, x, hi - lo);
	}
	else if(hx < 0x39000000)  {	/* when |x|<2**-14 */
	    if(huge+x>one) return one+x;/* trigger inexact */
	}
	else k = 0;

    /* x is now in primary range */
	t  = x*x;
	if(k >= -125)
	    SET_FLOAT_WORD(twopk,0x3f800000+(k<<23));
	else
	    SET_FLOAT_WORD(twopk,0x3f800000+((k+100)<<23));
	c  = x - t*(P1+t*P2);
	if(k==0) 	return one-((x*c)/(c-(float)2.0)-x);
	else 		y = one-((lo-(x*c)/((float)2.0-c))-hi);
	if(k >= -125) {
	    if(k==128) return y*2.0F*0x1p127F; // LINE 101: ERROR OCCURS HERE
	    return y*twopk;
	} else {
	    return y*twopk*twom100;
	}
}

I suspect some overflow? How can I run it succesfully?

Thanks and merry christmas.

  • Hi Mubin,

    I'll look into this issue and get back to you by Wednesday Dec 26.

    Thanks,
    Sira
  • Mubin,

    Please help me understand your issue a little better.

    1. Is the function expf() your code (i.e. user code) or is it TI code?
    2. I imagine this is a runtime exception? Are there any warnings generated by the compiler?
    3. Does it always throw this exception i.e. irrespective of the value x passed?
    4. In addition to the above, you could try modifying/simplifying the code in line 101 to see if it fixed the issue.
    5. I don't know if you've already done this, but there are many e2e posts pertaining to ILLEGAL_ISR and their causes. Some examples are - errors in the linker command file, overflows, etc. You can also refer to this link. So maybe if you rule out other causes, you'll have to look into the .cmd and .map files for hints.

    processors.wiki.ti.com/.../Interrupt_FAQ_for_C2000

    Please let me know what you find.

    Thanks,
    Sira
  • Hi, thanks for answer.

    1. No it is not my code. It is a library code (C:\ti\ccsv7\tools\compiler\ti-cgt-c2000_16.9.6.LTS\lib\src\e_expf.c)

    2. Yes it is a runtime exception, there is no compiler warning.

    3. I tested with the values of 2,1,0,-1,-2.. It work only for the value of 0, it doesn't throw exception.

    4. The code itself is too complicated.

    5. OK

  • Mubin,

    If standard TI library code itself is not working properly, then I strongly suspect something wrong at an application level, most likely the linker command file of your project.

    Is your code executing from RAM or FLASH? If running from RAM, is the program properly copied from FLASH to RAM? Also, is there sufficient space (you can check the memory allocation view in CCS)?

    Thanks,
    Sira
  • Mubin,

    For added clarification, I am asking to check whether there might be stack/heap overflow at runtime in your application. These are the issues the linker will not be able to catch at build time.

    Thanks,
    Sira
  • Mubin,

    Any updates? If my suggestions helped and your issue is resolved, please click Verified Answer to my reply.

    Thanks,
    Sira