From: Paul Stoffregen <paul@pj...>  20040727 22:29:58

>I am developing a small GIS application, and I need to use only the SQRTF() >and ASINF() functions. The hardware is an AT89S51 (4KB FLASH ROM),but if I >include the full math library, it uses near 3.5KB, so there is no room for >my program. I need to build a smaller math library (ideally with only these >two functions) but I do not know how to do it. > If you look at the sqrtf code, you'll see that it makes several floating point comparisions (implemented as library calls by the compiler). Then it calls frexpf() and does both addition and multipilication to make the initial guess. Then the Newton method uses division and ldexpf(), resulting in more library functions being needed. Inside _fsmul() are three 32 bit integer multiplications, which are implemented by another library function, just like every floating point operation. Likewise, asinf() calls to asinconf(), which uses lots of additions, subtractions, multiplications, divisions and comparisions... all resulting in library code required to implment them. On top of a call to sqrtf(), it also calls fabsf() and ldexpf(). The linker is only including the necessary functions... but a single call to asinf() requires many other functions from the library to be included, because the complex functions call many of the simpler ones and use lots of the "primitive" operations. But it is not including the whole library. There's lots of other functions in the library (_fs2uint, atanf, ceif) that aren't being included by the linker. > I can build my own libraries >(.LIB) and link .REL files, but I would like to know what is the minimun to >add to build a math library with these two functions. Thanks in advance for >your help > Staying with floating point calculations, the only real hope to make the library smaller is to rewrite it... in hand optimized assembly language. I've actually done some work to rewrite some of the floating point functions in assembly (eventually to be included in the library). However, most of this code is currently untested and probably has bugs. Using just a small handful of assembly coded functions (fsadd, fssub, fsmul, fseq, ldexpf, fabsf, ldexpf), a program calling only asinf() became 1342 bytes smaller in small memory model. The large model, the savings are much greater. It's probably faster. Some functions like addition are not much different (maybe 1.5x to 2x faster), but others like multiplication are a LOT faster in assembly. If anyone wants to "beta test" some of these assemblycoded floating point functions, contact me offlist (don't put [sdccuser] in the subject....) Of course, there's probably some way to accomplish your task using fixed point math. But fixed point requires a lot of careful attention, and I don't know of any SDCCusable libraries with arc sine computation in fixed point. Perhaps a lookup table could be used if you have a limited range of input values and you can tolerate some error by picking the nearest table entry or a simple interpolation between the 2 nearest ones. Paul 