From: Ben Gras Date: Thu, 15 Jul 2010 23:48:56 +0000 (+0000) Subject: 64-bit bitwise manipulation functions, by Gautam Tirumala. X-Git-Tag: v3.1.8~223 X-Git-Url: http://zhaoyanbai.com/repos/man.rndc.html?a=commitdiff_plain;h=6c66933f90852d19f20002ec2bd34bc995708225;p=minix.git 64-bit bitwise manipulation functions, by Gautam Tirumala. --- diff --git a/include/minix/u64.h b/include/minix/u64.h index 1d5dace32..910d77c28 100644 --- a/include/minix/u64.h +++ b/include/minix/u64.h @@ -34,6 +34,11 @@ int cmp64ul(u64_t i, unsigned long j); unsigned long ex64lo(u64_t i); unsigned long ex64hi(u64_t i); u64_t make64(unsigned long lo, unsigned long hi); +u64_t rrotate64(u64_t x, unsigned short b); +u64_t rshift64(u64_t x, unsigned short b); +u64_t xor64(u64_t a, u64_t b); +u64_t and64(u64_t a, u64_t b); +u64_t not64(u64_t a); #define is_zero64(i) ((i).lo == 0 && (i).hi == 0) #define make_zero64(i) do { (i).lo = (i).hi = 0; } while(0) diff --git a/lib/libc/other/u64util.c b/lib/libc/other/u64util.c new file mode 100644 index 000000000..40bfd6469 --- /dev/null +++ b/lib/libc/other/u64util.c @@ -0,0 +1,76 @@ +/* Few u64 utils implemented in C + * Author: Gautam BT + */ +#include + +u64_t rrotate64(u64_t x, unsigned short b) +{ + u64_t r, t; + + b %= 64; + + if(b == 32) { + r.lo = x.hi; + r.hi = x.lo; + return r; + }else if(b < 32) { + r.lo = (x.lo >> b) | (x.hi << (32 - b)); + r.hi = (x.hi >> b) | (x.lo << (32 - b)); + return r; + }else { + /* Rotate by 32 bits first then rotate by remaining */ + t.lo = x.hi; + t.hi = x.lo; + b = b - 32; + r.lo = (t.lo >> b) | (t.hi << (32 - b)); + r.hi = (t.hi >> b) | (t.lo << (32 - b)); + return r; + } +} + +u64_t rshift64(u64_t x, unsigned short b) +{ + u64_t r; + + if(b >= 64) + return make64(0,0); + + if(b >= 32) { + r.hi = 0; + r.lo = x.hi >> (b - 32); + }else { + r.lo = (x.lo >> b) | (x.hi << (32 - b)); + r.hi = (x.hi >> b); + } + return r; +} + +u64_t xor64(u64_t a, u64_t b) +{ + u64_t r; + r.hi = a.hi ^ b.hi; + r.lo = a.lo ^ b.lo; + + return r; +} + +u64_t and64(u64_t a, u64_t b) +{ + u64_t r; + r.hi = a.hi & b.hi; + r.lo = a.lo & b.lo; + + return r; +} + +u64_t not64(u64_t a) +{ + u64_t r; + + r.hi = ~a.hi; + r.lo = ~a.lo; + + return r; +} + + diff --git a/man/man3/int64.3 b/man/man3/int64.3 index f0f63ffa4..fe6167b86 100644 --- a/man/man3/int64.3 +++ b/man/man3/int64.3 @@ -31,6 +31,11 @@ int cmp64ul(u64_t \fIi\fP, unsigned long \fIj\fP) unsigned long ex64lo(u64_t \fIi\fP) unsigned long ex64hi(u64_t \fIi\fP) u64_t make64(unsigned long \fIlo\fP, unsigned long \fIhi\fP) +u64_t rrotate64(u64_t \fIi\fP, unsigned short \fIb\fP) +u64_t rshift64(u64_t \fIi\fP, unsigned short \fIb\fP) +u64_t xor64(u64_t \fIi\fP, u64_t \fIj\fP) +u64_t and64(u64_t \fIi\fP, u64_t \fIj\fP) +u64_t not64(u64_t \fIi\fP) .fi .ft P .SH DESCRIPTION @@ -186,9 +191,33 @@ if .I i > .IR j . + +.TP +.B "u64_t rrotate64(u64_t \fIi\fP, unsigned short \fIb\fP)" +Rotate first 64-bit argument to the right by \fIb\fP bits and +return the result. + +.TP +.B "u64_t rshift64(u64_t \fIi\fP, unsigned short \fIb\fP)" +Shift first 64-bit argument to the right by \fIb\fP bits and +return the result. + +.TP +.B "u64_t xor64(u64_t \fIi\fP, u64_t \fIj\fP)" +Return the 64-bit bitwise xor of the 64-bit \fIi\fP and \fIj\fP arguments. + +.TP +.B "u64_t and64(u64_t \fIi\fP, u64_t \fIj\fP)" +Return the 64-bit bitwise and of the 64-bit \fIi\fP and \fIj\fP arguments. + +.TP +.B "u64_t not64(u64_t \fIi\fP)" +Return the 64-bit bitwise not of the 64-bit \fIi\fP argument. + .TP .B "int cmp64u(u64_t \fIi\fP, unsigned \fIj\fP)" Likewise compare a 64 bit number with an unsigned. + .TP .B "int cmp64ul(u64_t \fIi\fP, unsigned long \fIj\fP)" Likewise compare a 64 bit number with an unsigned long.