How does an AVR perform floating point Arithmetic

后端 未结 3 1507
失恋的感觉
失恋的感觉 2021-01-01 02:09

I\'m trying to implement a support for double and float and corresponding basic arithmetic on a CPU without an FPU.

I know that it is possi

相关标签:
3条回答
  • 2021-01-01 02:19

    Here are AVR related links with explanations and examples for implementing soft double:

    1. You will find one double floating point lib here.
    2. Another one can be found it in the last message here.
    3. Double is very slow, so if speed is in concern, you might opt for fixed point math. Just read my messages in this thread:
    0 讨论(0)
  • 2021-01-01 02:28

    This post may be interesting for you: Floating point calculations in a processor with no FPU

    As stated:

    Your compiler may provide support, or you may need to roll your own. There are freely-available implementations, too.

    If it's for an ATmega, you probably don't have to write anything yourself. All the already available libraries are probably already optimized much further than you possible can do yourself. If you need more performance, you could consider to convert the floating points to fixed points. You should consider this anyway. If you can get the job done in fixed point, you should stay away from floating point.

    0 讨论(0)
  • 2021-01-01 02:34

    Avr uses AVR Libc, which you can download and examine.

    There is a math library, but that is not what you are looking for. That contains the standard functions defined in math.h.

    Instead, you need functions that perform multiplication and things like like that. These are also in Libc, under fplib and written in assembly language. But the user doesn't call them directly. Instead, when the compiler comes across a multiplication involving floats, the compiler will choose the correct function to insert.

    You can browse through the AVR fplib to get an idea of what to do, but you are going to have to write your own assembly or bit-twiddling code for your processor.

    You need to find out what standard your processor and language are using for floating point. IEEE, perhaps? And you'll also need to know if the system is little-endian or big-endian.

    I am assuming you system doesn't have a C compiler already. Otherwise, all the floating point operations would already be implemented. That "twice()" function (actually square()) would work just fine as it is.

    0 讨论(0)
提交回复
热议问题