Updated sin lut to use ~200KiB for it's table with the same accuracy, the lookup table implementation tends to run at about 33-36% of the speed of sinf on my machine (Intel T5500).
Fixed a bug in the sin lut code so that the results are always accurate. Changed fixsingen tool to generate tables correctly for the new implementation.
This commit is contained in:
parent
0317f964f4
commit
5dd63f37ce
|
@ -1,5 +1,5 @@
|
||||||
# depslib dependency file v1.0
|
# depslib dependency file v1.0
|
||||||
1298645188 source:g:\vrfx\libfixmath\fixsingen\main.c
|
1298649568 source:g:\vrfx\libfixmath\fixsingen\main.c
|
||||||
<stdio.h>
|
<stdio.h>
|
||||||
<stdlib.h>
|
<stdlib.h>
|
||||||
<inttypes.h>
|
<inttypes.h>
|
||||||
|
@ -17,6 +17,6 @@
|
||||||
1298453688 g:\vrfx\libfixmath\\libfixmath\fract32.h
|
1298453688 g:\vrfx\libfixmath\\libfixmath\fract32.h
|
||||||
<stdint.h>
|
<stdint.h>
|
||||||
|
|
||||||
1298634082 g:\vrfx\libfixmath\\libfixmath\fix16.h
|
1298648502 g:\vrfx\libfixmath\\libfixmath\fix16.h
|
||||||
<stdint.h>
|
<stdint.h>
|
||||||
|
|
||||||
|
|
|
@ -11,18 +11,27 @@ int main(int argc, char** argv) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO - Store as uint16_t with a count to determine the end and return 1.
|
||||||
|
|
||||||
fprintf(fp, "#ifndef __fix16_trig_sin_lut_h__\n");
|
fprintf(fp, "#ifndef __fix16_trig_sin_lut_h__\n");
|
||||||
fprintf(fp, "#define __fix16_trig_sin_lut_h__\n");
|
fprintf(fp, "#define __fix16_trig_sin_lut_h__\n");
|
||||||
fprintf(fp, "\n");
|
fprintf(fp, "\n");
|
||||||
|
|
||||||
fprintf(fp, "static fix16_t _fix16_sin_lut[%"PRIi32"] = {", (fix16_pi >> 1));
|
fix16_t fix16_sin_lut_count = (fix16_pi >> 1);
|
||||||
|
fix16_t fix16_sin_lut[fix16_sin_lut_count];
|
||||||
|
|
||||||
uintptr_t i;
|
uintptr_t i;
|
||||||
for(i = 0; i < (fix16_pi >> 1); i++) {
|
for(i = 0; i < fix16_sin_lut_count; i++)
|
||||||
|
fix16_sin_lut[i] = fix16_from_dbl(sin(fix16_to_dbl(i)));
|
||||||
|
for(i--; fix16_sin_lut[i] == fix16_one; i--, fix16_sin_lut_count--);
|
||||||
|
|
||||||
|
fprintf(fp, "static const uint32_t _fix16_sin_lut_count = %"PRIi32";\n", fix16_sin_lut_count);
|
||||||
|
fprintf(fp, "static uint16_t _fix16_sin_lut[%"PRIi32"] = {", fix16_sin_lut_count);
|
||||||
|
|
||||||
|
for(i = 0; i < fix16_sin_lut_count; i++) {
|
||||||
if((i & 7) == 0)
|
if((i & 7) == 0)
|
||||||
fprintf(fp, "\n\t");
|
fprintf(fp, "\n\t");
|
||||||
fix16_t fix16_sin_lut = fix16_from_dbl(sin(fix16_to_dbl(i)));
|
fprintf(fp, "%"PRIi32", ", fix16_sin_lut[i]);
|
||||||
fprintf(fp, "%"PRIi32", ", fix16_sin_lut);
|
|
||||||
}
|
}
|
||||||
fprintf(fp, "\n\t};\n");
|
fprintf(fp, "\n\t};\n");
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
1298453688 g:\vrfx\libfixmath\\libfixmath\fract32.h
|
1298453688 g:\vrfx\libfixmath\\libfixmath\fract32.h
|
||||||
<stdint.h>
|
<stdint.h>
|
||||||
|
|
||||||
1298634082 g:\vrfx\libfixmath\\libfixmath\fix16.h
|
1298648502 g:\vrfx\libfixmath\\libfixmath\fix16.h
|
||||||
<stdint.h>
|
<stdint.h>
|
||||||
|
|
||||||
1298562746 source:g:\vrfx\libfixmath\fixtest\hiclock.c
|
1298562746 source:g:\vrfx\libfixmath\fixtest\hiclock.c
|
||||||
|
|
|
@ -17,19 +17,27 @@ typedef int32_t fix16_t;
|
||||||
#define fix16_e 178145 /*!< fix16_t value of e */
|
#define fix16_e 178145 /*!< fix16_t value of e */
|
||||||
#define fix16_one 0x00010000 /*!< fix16_t value of 1 */
|
#define fix16_one 0x00010000 /*!< fix16_t value of 1 */
|
||||||
|
|
||||||
/*! Coverts a fix16_t to a double and returns the result. */
|
#ifdef FIXMATH_NO_ROUNDING
|
||||||
#define fix16_to_dbl(inVal) ((double)((inVal) / 65536.0))
|
|
||||||
/*! Converts a double to a fix16_t and returns the result. */
|
/*! Converts a double to a fix16_t and returns the result. */
|
||||||
#define fix16_from_dbl(inVal) ((fix16_t)((inVal) * 65536.0))
|
#define fix16_from_dbl(inVal) ((fix16_t)((inVal) * 65536.0))
|
||||||
/*! Converts a fix16_t to a float and returns the result. */
|
|
||||||
#define fix16_to_float(inVal) ((float)((inVal) / 65536.0f))
|
|
||||||
/*! Converts a float to a fix16_t and returns the result. */
|
/*! Converts a float to a fix16_t and returns the result. */
|
||||||
#define fix16_from_float(inVal) ((fix16_t)((inVal) * 65536.0f))
|
#define fix16_from_float(inVal) ((fix16_t)((inVal) * 65536.0f))
|
||||||
/*! Converts a fix16_t to a signed integer and returns the result. */
|
#else
|
||||||
#define fix16_to_int(inVal) ((int32_t)(((inVal) + (fix16_one >> 1)) >> 16))
|
/*! Converts a double to a fix16_t and returns the result. */
|
||||||
|
#define fix16_from_dbl(inVal) ((fix16_t)(((inVal) * 65536.0) + 0.5))
|
||||||
|
/*! Converts a float to a fix16_t and returns the result. */
|
||||||
|
#define fix16_from_float(inVal) ((fix16_t)(((inVal) * 65536.0f) + 0.5f))
|
||||||
|
#endif
|
||||||
/*! Converts a signed integer to a fix16_t and returns the result. */
|
/*! Converts a signed integer to a fix16_t and returns the result. */
|
||||||
#define fix16_from_int(inVal) ((fix16_t)((inVal) << 16))
|
#define fix16_from_int(inVal) ((fix16_t)((inVal) << 16))
|
||||||
|
|
||||||
|
/*! Coverts a fix16_t to a double and returns the result. */
|
||||||
|
#define fix16_to_dbl(inVal) ((double)((inVal) / 65536.0))
|
||||||
|
/*! Converts a fix16_t to a float and returns the result. */
|
||||||
|
#define fix16_to_float(inVal) ((float)((inVal) / 65536.0f))
|
||||||
|
/*! Converts a fix16_t to a signed integer and returns the result. */
|
||||||
|
#define fix16_to_int(inVal) ((int32_t)(((inVal) + (fix16_one >> 1)) >> 16))
|
||||||
|
|
||||||
/* Replaced with macros, uncomment if symbols are needed by old code.
|
/* Replaced with macros, uncomment if symbols are needed by old code.
|
||||||
extern double fix16_to_dbl(const fix16_t inVal);
|
extern double fix16_to_dbl(const fix16_t inVal);
|
||||||
extern fix16_t fix16_from_dbl(const double inVal);
|
extern fix16_t fix16_from_dbl(const double inVal);
|
||||||
|
|
|
@ -26,11 +26,11 @@ fix16_t fix16_sin(fix16_t inAngle) {
|
||||||
tempAngle -= fix16_pi;
|
tempAngle -= fix16_pi;
|
||||||
if(tempAngle >= (fix16_pi >> 1))
|
if(tempAngle >= (fix16_pi >> 1))
|
||||||
tempAngle = fix16_pi - tempAngle;
|
tempAngle = fix16_pi - tempAngle;
|
||||||
tempOut = -_fix16_sin_lut[tempAngle];
|
tempOut = -(tempAngle >= _fix16_sin_lut_count ? fix16_one : _fix16_sin_lut[tempAngle]);
|
||||||
} else {
|
} else {
|
||||||
if(tempAngle >= (fix16_pi >> 1))
|
if(tempAngle >= (fix16_pi >> 1))
|
||||||
tempAngle = fix16_pi - tempAngle;
|
tempAngle = fix16_pi - tempAngle;
|
||||||
tempOut = _fix16_sin_lut[tempAngle];
|
tempOut = (tempAngle >= _fix16_sin_lut_count ? fix16_one : _fix16_sin_lut[tempAngle]);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if(tempAngle > fix16_pi)
|
if(tempAngle > fix16_pi)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue