Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to compute 64-bit division on a 32-bit processor(VxWorks)

592 views
Skip to first unread message

Naidu K S

unread,
Jun 8, 2000, 3:00:00 AM6/8/00
to
Hi ,
The following function which is written in C-language computes a division
of 64-bit variables on a PowerPC(MPC850) target. The MPC850 is a 32-bit
processor.
Would you give some idea as to how this 64-bit division is performed on
PPC850. I don't have any library to do this 64-bit division operation. Any
source code or algorithm to do this operation is most useful.

int DivDoubleLong (int wh, int wl, int divisor)
{
union {
unsigned __int64 l;
struct {
#if BIG_ENDIAN
int wh;
int wl;
#else
int wl;
int wh;
#endif
} w;
} a, b;

a.w.wl = wl;
a.w.wh = wh;
b.w.wl = divisor;
b.w.wh = 0;
return (int)(a.l / b.l);
}

Thank you.

Naidu

Dmitry Pogrebinsky

unread,
Jun 8, 2000, 3:00:00 AM6/8/00
to
> Would you give some idea as to how this 64-bit division is
> performed on PPC850.

You can write an algorithm that we learned in the school.
Try to remind how will you divide 347624 on 65 without calculator.
If you manage, then writing this algorithm on C is a meter of technique.

_____

Dmitry Pogrebinsky, Software engineer, Broadband Voice BU
Terayon Communications Systems, http://www.terayon.com
<http://www.terayon.com/>
Tel: +972-3-5384613, Email: dmi...@terayon.com
<mailto:dmi...@terayon.com>
Fax: +972-3-5335877, Haplada St. 7, 60218 Or-Yehuda, Israel
ICQ: 69304286. HomePage: http://www.cs.biu.ac.il/~dpogrebi
<http://www.cs.biu.ac.il/~dpogrebi>

David Laight

unread,
Jun 8, 2000, 3:00:00 AM6/8/00
to
> > Would you give some idea as to how this 64-bit division is
> > performed on PPC850.
>
> You can write an algorithm that we learned in the school.
> Try to remind how will you divide 347624 on 65 without calculator.
> If you manage, then writing this algorithm on C is a meter of technique.
>

For instance (untested):

unsigned int
div_ulong( uint wh, uint wl, uint d )
{
uint result = 0;
uint bit;
uint t;

if (!wh)
return wl / d;

if (wh >= d)
/* overflow */
return ~0;

for (bit = 1 << 31; bit; bit >>= 1) {
wh <<= 1;
t = wl << 1;
if (t < wl)
wh |= 1;
wl = t;
if (wh < d)
continue;
result |= bit;
wh -= d;
}

return result;
}

The signed division is a little harder.
There are also MUCH faster algorithms - you can do two (or more) bits at a time.
Using the systems divide instruction (if it has one) will also help.

Of course the PPC probably has a 64 by 64 divide as an instruction!
Find it, and add an assembler call in (say) the wxWorks sysALib.s.

David

----------------------------------------------------------------
David Laight email: d...@tadpole.co.uk
Tadpole Technology plc phone: +44 1223 428 232
Cambridge, UK fax: +44 1223 428 201


Erick Gonzalez

unread,
Jun 8, 2000, 3:00:00 AM6/8/00
to
I had to deal with a similar problem , on the Pentium though. I had an algorythm
that tried to divide unsigned long longs, and it compiled fine (using GCC.2.95.2),
but I ended up with an undefined reference to __udivdi3. Obviously this is the
function in the GNU C library that handles this type of operation. I was able to get
away with it by yanking out the object module from the library, and adding it to the
vxWorks system library. No one has complained so far... might not something similar
happen if you try to do this on the PPC?

I agree that if this doesn't work for you then just write your own divide routine.
No biggie.

Erick

Gerard Kerkhofs

unread,
Jun 13, 2000, 3:00:00 AM6/13/00
to
Hi everyone,

WRS knows this problem as TSR 124264.

The solution is to inlude an extra library (which is, stange enough, located
in the 'host' tree) in your build. To do this, change the LIB macro in the
build settings and add the extra LIB_INT64 macro:

LIB_INT64=C:/TORNADO2/host/x86-win32/lib/gcc-lib/i960-wrs-vxworks5.3/cygnus-
2.7.2-960126/libgcc.a

LIBS=...original setting... $(LIB_INT64)

You may need to change some directory names depending on your installation.
Also note that the extra library is included AFTER the normal libraries.

Hope this helps,

Gerard Kerkhofs
Nicolet Technologies B.V.

Erick Gonzalez <erick.g...@remove.nospam.marconi.com> wrote in message
news:393FA320...@remove.nospam.marconi.com...

0 new messages