Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  Index 2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019 
<== Date ==> <== Thread ==>

Subject: Re: 64 bit integers (aka. long or long long)
From: Benjamin Franksen <benjamin.franksen@helmholtz-berlin.de>
To: <core-talk@aps.anl.gov>
Date: Mon, 20 Jun 2011 10:59:17 +0200
On Saturday, June 18, 2011, Andrew Johnson wrote:
> Hi Michael,
>
> On 2011-06-17 Michael Davidsaver wrote:
> > I'd like to add a standard 64-bit integer type to epicsTypes.h.
> > Currently this is only available when compiling with the C99 extensions
> > enabled.
> >
> > Attached are two proposed patches.  The first adds sanity checks of the
> > existing type sizes.  The second defines epicsUInt64 and epicsInt64.
> >
> > The C primitive used (either long or long long) is chosen by testing
> > the size of LONG_MAX.  I think this should work for all toolchains
> > which actually provide a 64-bit integer type.  The question is, are
> > there any which don't and need to be supported?
>
> There were issues with using long long on some vxWorks
> versions/architectures, although from what I can see they were only in
> vxWorks 5.3.x releases and the later releases apparently do provide full
> support.  I believe there were some support routines that gcc calls
> implicitly which the OS relegated to an external libgcc.a library rather
> than building them into the OS image.

VxWorks 5.4.2 (or rather, the glibc shipped with it) does not fully support
64 bit integers on mv162. I needed division and modulo at some time and got
linker errors about missing __div64 etc functions. So I just copied the
attached file from some glibc version to the support module that needed the
operations and this stuff is running on our mv162 ever since w/o problems.

Cheers
Ben

________________________________

Helmholtz-Zentrum Berlin für Materialien und Energie GmbH

Mitglied der Hermann von Helmholtz-Gemeinschaft Deutscher Forschungszentren e.V.

Aufsichtsrat: Vorsitzender Prof. Dr. Dr. h.c. mult. Joachim Treusch, stv. Vorsitzende Dr. Beatrix Vierkorn-Rudolph
Geschäftsführer: Prof. Dr. Anke Rita Kaysser-Pyzalla, Dr. Ulrich Breuer

Sitz Berlin, AG Charlottenburg, 89 HRB 5583

Postadresse:
Hahn-Meitner-Platz 1
D-14109 Berlin

http://www.helmholtz-berlin.de
#if 0
/* __div64: 
   Division of signed long long 's

   Contributed by Gert Ohme (ohme@dialeasy.de)

   Copyright (C) 2001 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

long long __div64(long long x, long long y)
{
    unsigned long long a = (x < 0) ? -x : x;
    unsigned long long b = (y < 0) ? -y : y;
    unsigned long long res = 0, d = 1;

    if (b > 0)
        while (b < a)
            b <<= 1, d <<= 1;

    do {
        if (a >= b)
            a -= b, res += d;
        b >>= 1;
        d >>= 1;
    } while (d);

    return (((x ^ y) & (1ll << 63)) == 0) ? res : -(long long)res;
}

/* __rem64: 
   Remainder of a division of signed long long 's

   Contributed by Gert Ohme (ohme@dialeasy.de)

   Copyright (C) 2001 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

long long __rem64(long long x, long long y)
{
    unsigned long long a = (x < 0) ? -x : x;
    unsigned long long b = (y < 0) ? -y : y;
    unsigned long long d = 1;

    if (b > 0)
        while (b < a)
            b <<= 1, d <<= 1;

    do {
        if (a >= b)
            a -= b;
        b >>= 1;
        d >>= 1;
    } while (d);

    return ((x & (1ll << 63)) == 0) ? a : -(long long)a;
}
#endif
/* __udivdi3: 
   Division of unsigned long long 's

   Contributed by Gert Ohme (ohme@dialeasy.de)

   Copyright (C) 2001 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

unsigned long long __udivdi3(unsigned long long x, unsigned long long y)
{
    unsigned long long res = 0, d = 1;
    unsigned long long e = 1ll << 63;

    if (x == 0)
        return (0);

    while ((x & e) == 0)
        e >>= 1;

    if (y > 0)
        while (y < e)
            y <<= 1, d <<= 1;

    do {
        if (x >= y)
            x -= y, res += d;
        y >>= 1;
        d >>= 1;
    } while (d);

    return res;
}

/* __umoddi3: 
   Remainder of a division of unsigned long long 's

   Contributed by Gert Ohme (ohme@dialeasy.de)

   Copyright (C) 2001 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

unsigned long long __umoddi3(unsigned long long x, unsigned long long y)
{
    unsigned long long d = 1;
    unsigned long long e = 1ll << 63;

    if (x == 0)
        return (0);

    while ((x & e) == 0)
        e >>= 1;

    if (y > 0)
        while (y < e)
            y <<= 1, d <<= 1;

    do {
        if (x >= y)
            x -= y;
        y >>= 1;
        d >>= 1;
    } while (d);

    return x;
}

References:
64 bit integers (aka. long or long long) Michael Davidsaver
Re: 64 bit integers (aka. long or long long) Andrew Johnson

Navigate by Date:
Prev: Re: 64 bit integers (aka. long or long long) Michael Davidsaver
Next: Re: 64 bit integers (aka. long or long long) Andrew Johnson
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019 
Navigate by Thread:
Prev: Re: 64 bit integers (aka. long or long long) Andrew Johnson
Next: epicsThreadExitMain in softIoc program Benjamin Franksen
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019 
ANJ, 02 Feb 2012 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·