EmbeddedRelated.com
Forums

Need C source for 64 bit integer math (have 32bit limit on my compiler)

Started by Andrew September 23, 2009
Jon Kirwan wrote:
> On Sun, 27 Sep 2009 00:16:09 -0700 (PDT), -jg > <jim.granville@gmail.com> wrote: > >> On Sep 27, 7:59 am, Jon Kirwan <j...@infinitefactors.org> wrote: >>> There are. But well-healed ones are pretty big and do a lot more than >>> you are initially asking. You still haven't described speed, code >>> size, or how often these functions are required relative to the >>> overall application. So I can't even offer some thoughts. >>> >>> Well, best of luck. Maybe someone else understands exactly what you >>> need and where to find it. >> Maybe I'm missing something, but this is AVR ? - and WinAVR has 64 bit >> integer support, and is open source ? >> >> - so that suggests a number of solutions ? > > Sounds like it might. Apparently, the OP is using something called > the CodeVision C compiler. So... there may be an issue or two, but > yes. Might be worth a look. I haven't used an AVR in some time, so > I'll leave this to the OP to figure out. >
avr-gcc handles 64-bit "long long int", and has all the necessary library routines for arithmetic on long longs. It's not always very efficient - they are rarely used, and thus code quality for 64-bit ints is not a priority for avr-gcc development. But they work correctly, which is the most important thing, and it's probably still more efficient than doing things manually.
-jg wrote:
> On Sep 27, 7:59 am, Jon Kirwan <j...@infinitefactors.org> wrote: >> There are. But well-healed ones are pretty big and do a lot more than >> you are initially asking. You still haven't described speed, code >> size, or how often these functions are required relative to the >> overall application. So I can't even offer some thoughts. >> >> Well, best of luck. Maybe someone else understands exactly what you >> need and where to find it. > > Maybe I'm missing something, but this is AVR ? - and WinAVR has 64 bit > integer support, and is open source ? > > - so that suggests a number of solutions ? > > -jg >
Yes AVR, but have code in CodeVision, not WinAVR GCC. Porting code is not an option. speed and code size is not important.
Andrew wrote:

> > Yes AVR, but have code in CodeVision, not WinAVR GCC. > Porting code is not an option. > > speed and code size is not important.
Find some info (google) on shift and add, shift and subtract for multiply and divide in assembler. Then work out the calling standard for your C compiler so you know which registers the args appear in on entry to your functions. If the docs don't specify this, write some code that calls a dummy function that you can break / single step on on to examine the code and also look at the assembler output if the args are pushed onto the stack rather than being passed in registers. You need to range check and trap error cases like divide by zero as well, but you can do that in the first line or two of a divide function. It's good practice and quite fun when it all works as intended. Not rocket science and you should know how to do this sort of thing in any case :-)... Regards, Chris