summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2007-10-12 23:47:25 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2007-10-12 23:47:25 (GMT)
commit8f848d2d33b206a521bfaa910fab1f37b0138907 (patch)
tree7237027e416b65ca617c03663550e8c7d120646a
parentaf492b3c6ece9c9c1fa6b9b3bd2d61904d25cd26 (diff)
downloadpbn-8f848d2d33b206a521bfaa910fab1f37b0138907.zip
pbn-8f848d2d33b206a521bfaa910fab1f37b0138907.tar.gz
pbn-8f848d2d33b206a521bfaa910fab1f37b0138907.tar.bz2
pbn-8f848d2d33b206a521bfaa910fab1f37b0138907.tar.xz
Fix the zero cases for logical operations; handle sign
- Fix the various zero cases for the logical operations - Do something semi-sane with the sign for the logical ops
-rw-r--r--pbn_and.c8
-rw-r--r--pbn_or.c8
-rw-r--r--pbn_xor.c8
3 files changed, 19 insertions, 5 deletions
diff --git a/pbn_and.c b/pbn_and.c
index 9e282e0..795c05c 100644
--- a/pbn_and.c
+++ b/pbn_and.c
@@ -23,11 +23,11 @@ struct pbn *pbn_and(struct pbn *s1, struct pbn *s2)
int i, len;
if (s1->bits == 0) {
- pbn_free(s1);
- return s2;
- } else if (s2->bits == 0) {
pbn_free(s2);
return s1;
+ } else if (s2->bits == 0) {
+ pbn_free(s1);
+ return s2;
}
if (s1->ref > s2->ref) {
@@ -46,6 +46,8 @@ struct pbn *pbn_and(struct pbn *s1, struct pbn *s2)
for (i = 0; i < d->len; i++)
d->num[i] &= s2->num[len];
+ d->minus &= s2->minus;
+
pbn_free(s2);
return pbn_adjust_bits(d);
}
diff --git a/pbn_or.c b/pbn_or.c
index 387dbc8..672e82a 100644
--- a/pbn_or.c
+++ b/pbn_or.c
@@ -21,7 +21,11 @@ struct pbn *pbn_or(struct pbn *s1, struct pbn *s2)
struct pbn *d;
int i, len, bits, lx;
- if (s1->bits == 0 && s2->bits == 0) {
+ if (s1->bits == 0) {
+ pbn_free(s1);
+ return s2;
+ }
+ if (s2->bits == 0) {
pbn_free(s2);
return s1;
}
@@ -47,6 +51,8 @@ struct pbn *pbn_or(struct pbn *s1, struct pbn *s2)
for (i = 0; i < lx; i++)
d->num[i] |= s2->num[len];
+ d->minus |= s2->minus;
+
pbn_free(s2);
return d;
}
diff --git a/pbn_xor.c b/pbn_xor.c
index f5f0ff3..7c03607 100644
--- a/pbn_xor.c
+++ b/pbn_xor.c
@@ -21,7 +21,11 @@ struct pbn *pbn_xor(struct pbn *s1, struct pbn *s2)
struct pbn *d;
int i, len, bits, lx;
- if (s1->bits == 0 && s2->bits == 0) {
+ if (s1->bits == 0) {
+ pbn_free(s1);
+ return s2;
+ }
+ if (s2->bits == 0) {
pbn_free(s2);
return s1;
}
@@ -43,6 +47,8 @@ struct pbn *pbn_xor(struct pbn *s1, struct pbn *s2)
for (i = 0; i < lx; i++)
d->num[i] ^= s2->num[len];
+ d->minus ^= s2->minus;
+
pbn_free(s2);
return pbn_adjust_bits(d);
}