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
execution time of log() function (natural logarithm of math.
-
- New User
- Posts: 3
- Joined: Tue Mar 04, 2014 10:23 pm
execution time of log() function (natural logarithm of math.
You do not have the required permissions to view the files attached to this post.
-
- XCore Expert
- Posts: 589
- Joined: Wed Feb 29, 2012 10:03 am
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
XCC_FLAGS_Debug = -O3 -g
-
- New User
- Posts: 3
- Joined: Tue Mar 04, 2014 10:23 pm
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
Hello XMOS!
ln( e)=1.000000 duration=80740ns
float1 * float2 =8.381021 duration=1550ns
-
- Respected Member
- Posts: 318
- Joined: Tue Dec 15, 2009 12:46 am
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
https://github.com/xcore/sc_lib_fixed_point
-
- XCore Expert
- Posts: 956
- Joined: Fri Dec 11, 2009 3:53 am
- Location: Sweden, Eskilstuna
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|
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.