Skip to content

Commit

Permalink
Adapt quad lib to RIOT coding conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
Kijewski committed Feb 11, 2014
1 parent 3dff8ed commit 0054d4b
Show file tree
Hide file tree
Showing 27 changed files with 805 additions and 733 deletions.
19 changes: 9 additions & 10 deletions sys/quad_math/adddi3.c
@@ -1,7 +1,7 @@
/* $OpenBSD: adddi3.c,v 1.6 2005/08/08 08:05:35 espie Exp $ */
/* $OpenBSD: adddi3.c,v 1.6 2005/08/08 08:05:35 espie Exp $ */
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
Expand Down Expand Up @@ -39,14 +39,13 @@
* u_int addition x+y occurs if and only if the sum x+y is less than
* either x or y (the choice to compare with x or y is arbitrary).
*/
quad_t
__adddi3(quad_t a, quad_t b)
quad_t __adddi3(quad_t a, quad_t b)
{
union uu aa, bb, sum;
union uu aa, bb, sum;

aa.q = a;
bb.q = b;
sum.ul[L] = aa.ul[L] + bb.ul[L];
sum.ul[H] = aa.ul[H] + bb.ul[H] + (sum.ul[L] < bb.ul[L]);
return (sum.q);
aa.q = a;
bb.q = b;
sum.ul[L] = aa.ul[L] + bb.ul[L];
sum.ul[H] = aa.ul[H] + bb.ul[H] + (sum.ul[L] < bb.ul[L]);
return sum.q;
}
19 changes: 9 additions & 10 deletions sys/quad_math/anddi3.c
@@ -1,7 +1,7 @@
/* $OpenBSD: anddi3.c,v 1.5 2005/08/08 08:05:35 espie Exp $ */
/* $OpenBSD: anddi3.c,v 1.5 2005/08/08 08:05:35 espie Exp $ */
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
Expand Down Expand Up @@ -37,14 +37,13 @@
/*
* Return a & b, in quad.
*/
quad_t
__anddi3(quad_t a, quad_t b)
quad_t __anddi3(quad_t a, quad_t b)
{
union uu aa, bb;
union uu aa, bb;

aa.q = a;
bb.q = b;
aa.ul[0] &= bb.ul[0];
aa.ul[1] &= bb.ul[1];
return (aa.q);
aa.q = a;
bb.q = b;
aa.ul[0] &= bb.ul[0];
aa.ul[1] &= bb.ul[1];
return aa.q;
}
36 changes: 19 additions & 17 deletions sys/quad_math/ashldi3.c
@@ -1,7 +1,7 @@
/* $OpenBSD: ashldi3.c,v 1.6 2005/08/08 08:05:35 espie Exp $ */
/* $OpenBSD: ashldi3.c,v 1.6 2005/08/08 08:05:35 espie Exp $ */
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
Expand Down Expand Up @@ -38,21 +38,23 @@
* Shift a (signed) quad value left (arithmetic shift left).
* This is the same as logical shift left!
*/
quad_t
__ashldi3(quad_t a, qshift_t shift)
quad_t __ashldi3(quad_t a, qshift_t shift)
{
union uu aa;
union uu aa;

if (shift == 0)
return(a);
aa.q = a;
if (shift >= INT_BITS) {
aa.ul[H] = aa.ul[L] << (shift - INT_BITS);
aa.ul[L] = 0;
} else {
aa.ul[H] = (aa.ul[H] << shift) |
(aa.ul[L] >> (INT_BITS - shift));
aa.ul[L] <<= shift;
}
return (aa.q);
if (shift == 0) {
return a;
}

aa.q = a;

if (shift >= INT_BITS) {
aa.ul[H] = aa.ul[L] << (shift - INT_BITS);
aa.ul[L] = 0;
} else {
aa.ul[H] = (aa.ul[H] << shift) | (aa.ul[L] >> (INT_BITS - shift));
aa.ul[L] <<= shift;
}

return aa.q;
}
58 changes: 29 additions & 29 deletions sys/quad_math/ashrdi3.c
@@ -1,7 +1,7 @@
/* $OpenBSD: ashrdi3.c,v 1.6 2005/08/08 08:05:35 espie Exp $ */
/* $OpenBSD: ashrdi3.c,v 1.6 2005/08/08 08:05:35 espie Exp $ */
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
Expand Down Expand Up @@ -37,34 +37,34 @@
/*
* Shift a (signed) quad value right (arithmetic shift right).
*/
quad_t
__ashrdi3(quad_t a, qshift_t shift)
quad_t __ashrdi3(quad_t a, qshift_t shift)
{
union uu aa;
union uu aa;

if (shift == 0)
return(a);
aa.q = a;
if (shift >= INT_BITS) {
int s;
if (shift == 0) {
return a;
}

/*
* Smear bits rightward using the machine's right-shift
* method, whether that is sign extension or zero fill,
* to get the `sign word' s. Note that shifting by
* INT_BITS is undefined, so we shift (INT_BITS-1),
* then 1 more, to get our answer.
*/
/* LINTED inherits machine dependency */
s = (aa.sl[H] >> (INT_BITS - 1)) >> 1;
/* LINTED inherits machine dependency*/
aa.ul[L] = aa.sl[H] >> (shift - INT_BITS);
aa.ul[H] = s;
} else {
aa.ul[L] = (aa.ul[L] >> shift) |
(aa.ul[H] << (INT_BITS - shift));
/* LINTED inherits machine dependency */
aa.sl[H] >>= shift;
}
return (aa.q);
aa.q = a;

if (shift >= INT_BITS) {
/*
* Smear bits rightward using the machine's right-shift
* method, whether that is sign extension or zero fill,
* to get the `sign word' s. Note that shifting by
* INT_BITS is undefined, so we shift (INT_BITS-1),
* then 1 more, to get our answer.
*/
/* LINTED inherits machine dependency */
int s = (aa.sl[H] >> (INT_BITS - 1)) >> 1;
/* LINTED inherits machine dependency*/
aa.ul[L] = aa.sl[H] >> (shift - INT_BITS);
aa.ul[H] = s;
} else {
aa.ul[L] = (aa.ul[L] >> shift) | (aa.ul[H] << (INT_BITS - shift));
/* LINTED inherits machine dependency */
aa.sl[H] >>= shift;
}

return aa.q;
}
20 changes: 11 additions & 9 deletions sys/quad_math/cmpdi2.c
@@ -1,7 +1,7 @@
/* $OpenBSD: cmpdi2.c,v 1.5 2005/08/08 08:05:35 espie Exp $ */
/* $OpenBSD: cmpdi2.c,v 1.5 2005/08/08 08:05:35 espie Exp $ */
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
Expand Down Expand Up @@ -39,13 +39,15 @@
* Both a and b are considered signed---which means only the high word is
* signed.
*/
int
__cmpdi2(quad_t a, quad_t b)
int __cmpdi2(quad_t a, quad_t b)
{
union uu aa, bb;
union uu aa, bb;

aa.q = a;
bb.q = b;
return (aa.sl[H] < bb.sl[H] ? 0 : aa.sl[H] > bb.sl[H] ? 2 :
aa.ul[L] < bb.ul[L] ? 0 : aa.ul[L] > bb.ul[L] ? 2 : 1);
aa.q = a;
bb.q = b;
return aa.sl[H] < bb.sl[H] ? 0
: aa.sl[H] > bb.sl[H] ? 2
: aa.ul[L] < bb.ul[L] ? 0
: aa.ul[L] > bb.ul[L] ? 2
: 1;
}
39 changes: 23 additions & 16 deletions sys/quad_math/divdi3.c
@@ -1,7 +1,7 @@
/* $OpenBSD: divdi3.c,v 1.6 2005/08/08 08:05:35 espie Exp $ */
/* $OpenBSD: divdi3.c,v 1.6 2005/08/08 08:05:35 espie Exp $ */
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
Expand Down Expand Up @@ -38,22 +38,29 @@
* Divide two signed quads.
* ??? if -1/2 should produce -1 on this machine, this code is wrong
*/
quad_t
__divdi3(quad_t a, quad_t b)
quad_t __divdi3(quad_t a, quad_t b)
{
u_quad_t ua, ub, uq;
int neg = 0;
u_quad_t ua, ub, uq;
int neg = 0;

ua = a;
ub = b;
ua = a;
ub = b;

if (a < 0)
ua = -ua, neg ^= 1;
if (b < 0)
ub = -ub, neg ^= 1;
if (a < 0) {
ua = -ua;
neg = !neg;
}

uq = __qdivrem(ua, ub, (u_quad_t *)0);
if (neg)
uq = - uq;
return uq;
if (b < 0) {
ub = -ub;
neg = !neg;
}

uq = __qdivrem(ua, ub, NULL);

if (neg) {
uq = -uq;
}

return uq;
}
30 changes: 16 additions & 14 deletions sys/quad_math/fixdfdi.c
@@ -1,7 +1,7 @@
/* $OpenBSD: fixdfdi.c,v 1.5 2005/08/08 08:05:35 espie Exp $ */
/* $OpenBSD: fixdfdi.c,v 1.5 2005/08/08 08:05:35 espie Exp $ */
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
Expand Down Expand Up @@ -38,17 +38,19 @@
* Convert double to (signed) quad.
* We clamp anything that is out of range.
*/
quad_t
__fixdfdi(double x)
quad_t __fixdfdi(double x)
{
if (x < 0)
if (x <= QUAD_MIN)
return (QUAD_MIN);
else
return ((quad_t)-(u_quad_t)-x);
else
if (x >= QUAD_MAX)
return (QUAD_MAX);
else
return ((quad_t)(u_quad_t)x);
if (x < 0) {
if (x <= QUAD_MIN) {
return QUAD_MIN;
} else {
return (quad_t) -(u_quad_t) -x;
}
} else {
if (x >= QUAD_MAX) {
return QUAD_MAX;
} else {
return (quad_t) (u_quad_t) x;
}
}
}
28 changes: 15 additions & 13 deletions sys/quad_math/fixsfdi.c
@@ -1,4 +1,4 @@
/* $OpenBSD: fixsfdi.c,v 1.6 2005/08/08 08:05:35 espie Exp $ */
/* $OpenBSD: fixsfdi.c,v 1.6 2005/08/08 08:05:35 espie Exp $ */
/*-
* Copyright (c) 1992 The Regents of the University of California.
* All rights reserved.
Expand Down Expand Up @@ -40,17 +40,19 @@
*
* N.B.: must use new ANSI syntax (sorry).
*/
quad_t
__fixsfdi(float x)
quad_t __fixsfdi(float x)
{
if (x < 0)
if (x <= QUAD_MIN)
return (QUAD_MIN);
else
return ((quad_t)-(u_quad_t)-x);
else
if (x >= QUAD_MAX)
return (QUAD_MAX);
else
return ((quad_t)(u_quad_t)x);
if (x < 0) {
if (x <= QUAD_MIN) {
return QUAD_MIN;
} else {
return (quad_t) -(u_quad_t) -x;
}
} else {
if (x >= QUAD_MAX) {
return QUAD_MAX;
} else {
return (quad_t) (u_quad_t) x;
}
}
}

0 comments on commit 0054d4b

Please sign in to comment.