execution time of log() function (natural logarithm of math.

If you have a simple question and just want an answer.
BernhardG
New User
Posts: 3
Joined: Tue Mar 04, 2014 10:23 pm

execution time of log() function (natural logarithm of math.

Post by BernhardG »

I want to know the execution time of the log() function.

Therefore, I wrote a small test progam that measures the execution time of the log() function.
I used the XMOS startKIT hardware and the xTIMEComposer Version: Community_13.0.2 (build 11621, Jan-16-2014) for the test.

As a result of my test program the measured execution time for the log() function is approx. 80.75usec.
(for a float*float calculation the execution time is approx. 1.6usec)

Is it possible to speed up the execution time of the log() function?

source code of the test program log-test.xc:

/*
 * log-test.xc
 *
 *  Created on: 02.03.2014
 *      Author: bernhard
 */
#include <stdio.h>
#include <math.h>
 
int main(void) {
    timer t;
    int starttime;
    int stoptime;
    float ln = exp( 1);
    float f1 = 1.2345;
    float f2 = 6.789;
 
    printf( "Hello XMOS!\n");
 
    t :> starttime;
    ln = log( ln);
    t :> stoptime;
 
    printf( "ln( e)=%f duration=%dns\n", ln, ( stoptime - starttime) * 10);
 
    t :> starttime;
    f2 = f1 * f2;
    t :> stoptime;
 
    printf( "float1 * float2 =%f duration=%dns\n", f2, ( stoptime - starttime) * 10);
 
    return 0;
}

The console output of the test program is:

Hello XMOS!
ln( e)=1.000000 duration=80750ns
float1 * float2 =8.381021 duration=1550ns


Thanks in advance for your help.

Regards
Bernhard
You do not have the required permissions to view the files attached to this post.


User avatar
sethu_jangala
XCore Expert
Posts: 589
Joined: Wed Feb 29, 2012 10:03 am

Post by sethu_jangala »

Can you try changing the optimisation level as O2 or O3. You can do this by changing the application Makefile as below:

XCC_FLAGS_Debug = -O3 -g

 
BernhardG
New User
Posts: 3
Joined: Tue Mar 04, 2014 10:23 pm

Post by BernhardG »

Yes, I did the test with -O3 -g with the same result!

Hello XMOS!
ln( e)=1.000000 duration=80740ns
float1 * float2 =8.381021 duration=1550ns
 

richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

Since the xCORE doesn't have hardware support for floating point it must be emulated in software which slows things down. Maybe you could use fixed point instead? There is an implementation of log in "8.24" fixed point format in the following repository:

https://github.com/xcore/sc_lib_fixed_point

User avatar
lilltroll
XCore Expert
Posts: 956
Joined: Fri Dec 11, 2009 3:53 am
Location: Sweden, Eskilstuna

Post by lilltroll »

log(a*10^b) = log10(a*10^b) / log10(e) = (b + log10(a) ) / log10(e)

This means that if you have a number in base 10, and you have a table-lookup with interpolation for log10(a), a is in the interval |1 10|,  you can calculate the natural log with

const double c = 1/log10(e) => 

ans = (b+table_lookup(a))*c

OTP memory could be considered for the table.

 

or if the float is stored in the base 2

log(a*2^b) = (b + log2(a)) / log2(e)  ... you need a table-lookup for the interval |1 2|

 

Probably not the most confused programmer anymore on the XCORE forum.
BernhardG
New User
Posts: 3
Joined: Tue Mar 04, 2014 10:23 pm

Post by BernhardG »

Hello richard, hello lilltrol,
thank you very much for your suggestions. I will test it and post the results.
Regards
Bernhard