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:
flatmush 2011-02-25 16:07:39 +00:00
parent 0317f964f4
commit 5dd63f37ce
6 changed files with 11483 additions and 11497 deletions

View File

@ -1,5 +1,5 @@
# depslib dependency file v1.0
1298645188 source:g:\vrfx\libfixmath\fixsingen\main.c
1298649568 source:g:\vrfx\libfixmath\fixsingen\main.c
<stdio.h>
<stdlib.h>
<inttypes.h>
@ -17,6 +17,6 @@
1298453688 g:\vrfx\libfixmath\\libfixmath\fract32.h
<stdint.h>
1298634082 g:\vrfx\libfixmath\\libfixmath\fix16.h
1298648502 g:\vrfx\libfixmath\\libfixmath\fix16.h
<stdint.h>

View File

@ -11,18 +11,27 @@ int main(int argc, char** argv) {
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, "#define __fix16_trig_sin_lut_h__\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;
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)
fprintf(fp, "\n\t");
fix16_t fix16_sin_lut = fix16_from_dbl(sin(fix16_to_dbl(i)));
fprintf(fp, "%"PRIi32", ", fix16_sin_lut);
fprintf(fp, "%"PRIi32", ", fix16_sin_lut[i]);
}
fprintf(fp, "\n\t};\n");

View File

@ -19,7 +19,7 @@
1298453688 g:\vrfx\libfixmath\\libfixmath\fract32.h
<stdint.h>
1298634082 g:\vrfx\libfixmath\\libfixmath\fix16.h
1298648502 g:\vrfx\libfixmath\\libfixmath\fix16.h
<stdint.h>
1298562746 source:g:\vrfx\libfixmath\fixtest\hiclock.c

View File

@ -17,19 +17,27 @@ typedef int32_t fix16_t;
#define fix16_e 178145 /*!< fix16_t value of e */
#define fix16_one 0x00010000 /*!< fix16_t value of 1 */
/*! Coverts a fix16_t to a double and returns the result. */
#define fix16_to_dbl(inVal) ((double)((inVal) / 65536.0))
#ifdef FIXMATH_NO_ROUNDING
/*! Converts a double to a fix16_t and returns the result. */
#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. */
#define fix16_from_float(inVal) ((fix16_t)((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))
#else
/*! 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. */
#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.
extern double fix16_to_dbl(const fix16_t inVal);
extern fix16_t fix16_from_dbl(const double inVal);

View File

@ -26,11 +26,11 @@ fix16_t fix16_sin(fix16_t inAngle) {
tempAngle -= fix16_pi;
if(tempAngle >= (fix16_pi >> 1))
tempAngle = fix16_pi - tempAngle;
tempOut = -_fix16_sin_lut[tempAngle];
tempOut = -(tempAngle >= _fix16_sin_lut_count ? fix16_one : _fix16_sin_lut[tempAngle]);
} else {
if(tempAngle >= (fix16_pi >> 1))
tempAngle = fix16_pi - tempAngle;
tempOut = _fix16_sin_lut[tempAngle];
tempOut = (tempAngle >= _fix16_sin_lut_count ? fix16_one : _fix16_sin_lut[tempAngle]);
}
#else
if(tempAngle > fix16_pi)

File diff suppressed because it is too large Load Diff