diff mbox

[RFC,v2,02/10] Jhash: add linux kernel jhashtable in qemu

Message ID 1450780978-19123-3-git-send-email-zhangchen.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Zhang Chen Dec. 22, 2015, 10:42 a.m. UTC
From: zhangchen <zhangchen.fnst@cn.fujitsu.com>

Jhash used by colo-proxy to save and lookup
net connection info

Signed-off-by: zhangchen <zhangchen.fnst@cn.fujitsu.com>
Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
---
 include/qemu/jhash.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 include/qemu/jhash.h

Comments

Dr. David Alan Gilbert Jan. 8, 2016, 12:08 p.m. UTC | #1
* Zhang Chen (zhangchen.fnst@cn.fujitsu.com) wrote:
> From: zhangchen <zhangchen.fnst@cn.fujitsu.com>
> 
> Jhash used by colo-proxy to save and lookup
> net connection info
> 
> Signed-off-by: zhangchen <zhangchen.fnst@cn.fujitsu.com>
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> ---
>  include/qemu/jhash.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 61 insertions(+)
>  create mode 100644 include/qemu/jhash.h
> 
> diff --git a/include/qemu/jhash.h b/include/qemu/jhash.h
> new file mode 100644
> index 0000000..5b82d02
> --- /dev/null
> +++ b/include/qemu/jhash.h
> @@ -0,0 +1,61 @@
> +/* jhash.h: Jenkins hash support.
> +  *
> +  * Copyright (C) 2006. Bob Jenkins (bob_jenkins@burtleburtle.net)
> +  *
> +  * http://burtleburtle.net/bob/hash/
> +  *
> +  * These are the credits from Bob's sources:
> +  *
> +  * lookup3.c, by Bob Jenkins, May 2006, Public Domain.
> +  *
> +  * These are functions for producing 32-bit hashes for hash table lookup.
> +  * hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final()
> +  * are externally useful functions.  Routines to test the hash are
> +included
> +  * if SELF_TEST is defined.  You can use this free for any purpose.
> +It's in
> +  * the public domain.  It has no warranty.
> +  *
> +  * Copyright (C) 2009-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
> +  *
> +  * I've modified Bob's hash to be useful in the Linux kernel, and
> +  * any bugs present are my fault.
> +  * Jozsef
> +  */
> +
> +#ifndef QEMU_JHASH_H__
> +#define QEMU_JHASH_H__
> +
> +#include "qemu/bitopt.h"

That does not build, the header in qemu is bitop*s*.h.

Dave

> +
> +/*
> + * hashtable relation copy from linux kernel jhash
> + */
> +
> +/* __jhash_mix -- mix 3 32-bit values reversibly. */
> +#define __jhash_mix(a, b, c)                \
> +{                                           \
> +    a -= c;  a ^= rol32(c, 4);  c += b;     \
> +    b -= a;  b ^= rol32(a, 6);  a += c;     \
> +    c -= b;  c ^= rol32(b, 8);  b += a;     \
> +    a -= c;  a ^= rol32(c, 16); c += b;     \
> +    b -= a;  b ^= rol32(a, 19); a += c;     \
> +    c -= b;  c ^= rol32(b, 4);  b += a;     \
> +}
> +
> +/* __jhash_final - final mixing of 3 32-bit values (a,b,c) into c */
> +#define __jhash_final(a, b, c)  \
> +{                               \
> +    c ^= b; c -= rol32(b, 14);  \
> +    a ^= c; a -= rol32(c, 11);  \
> +    b ^= a; b -= rol32(a, 25);  \
> +    c ^= b; c -= rol32(b, 16);  \
> +    a ^= c; a -= rol32(c, 4);   \
> +    b ^= a; b -= rol32(a, 14);  \
> +    c ^= b; c -= rol32(b, 24);  \
> +}
> +
> +/* An arbitrary initial parameter */
> +#define JHASH_INITVAL           0xdeadbeef
> +
> +#endif /* QEMU_JHASH_H__ */
> -- 
> 1.9.1
> 
> 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
Zhang Chen Jan. 11, 2016, 1:49 a.m. UTC | #2
On 01/08/2016 08:08 PM, Dr. David Alan Gilbert wrote:
> * Zhang Chen (zhangchen.fnst@cn.fujitsu.com) wrote:
>> From: zhangchen <zhangchen.fnst@cn.fujitsu.com>
>>
>> Jhash used by colo-proxy to save and lookup
>> net connection info
>>
>> Signed-off-by: zhangchen <zhangchen.fnst@cn.fujitsu.com>
>> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
>> ---
>>   include/qemu/jhash.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 61 insertions(+)
>>   create mode 100644 include/qemu/jhash.h
>>
>> diff --git a/include/qemu/jhash.h b/include/qemu/jhash.h
>> new file mode 100644
>> index 0000000..5b82d02
>> --- /dev/null
>> +++ b/include/qemu/jhash.h
>> @@ -0,0 +1,61 @@
>> +/* jhash.h: Jenkins hash support.
>> +  *
>> +  * Copyright (C) 2006. Bob Jenkins (bob_jenkins@burtleburtle.net)
>> +  *
>> +  * http://burtleburtle.net/bob/hash/
>> +  *
>> +  * These are the credits from Bob's sources:
>> +  *
>> +  * lookup3.c, by Bob Jenkins, May 2006, Public Domain.
>> +  *
>> +  * These are functions for producing 32-bit hashes for hash table lookup.
>> +  * hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final()
>> +  * are externally useful functions.  Routines to test the hash are
>> +included
>> +  * if SELF_TEST is defined.  You can use this free for any purpose.
>> +It's in
>> +  * the public domain.  It has no warranty.
>> +  *
>> +  * Copyright (C) 2009-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
>> +  *
>> +  * I've modified Bob's hash to be useful in the Linux kernel, and
>> +  * any bugs present are my fault.
>> +  * Jozsef
>> +  */
>> +
>> +#ifndef QEMU_JHASH_H__
>> +#define QEMU_JHASH_H__
>> +
>> +#include "qemu/bitopt.h"
> That does not build, the header in qemu is bitop*s*.h.
>
> Dave

I'm very sorry for it, fix it to

#include "qemu/bitopts.h"

Thanks
zhangchen


>> +
>> +/*
>> + * hashtable relation copy from linux kernel jhash
>> + */
>> +
>> +/* __jhash_mix -- mix 3 32-bit values reversibly. */
>> +#define __jhash_mix(a, b, c)                \
>> +{                                           \
>> +    a -= c;  a ^= rol32(c, 4);  c += b;     \
>> +    b -= a;  b ^= rol32(a, 6);  a += c;     \
>> +    c -= b;  c ^= rol32(b, 8);  b += a;     \
>> +    a -= c;  a ^= rol32(c, 16); c += b;     \
>> +    b -= a;  b ^= rol32(a, 19); a += c;     \
>> +    c -= b;  c ^= rol32(b, 4);  b += a;     \
>> +}
>> +
>> +/* __jhash_final - final mixing of 3 32-bit values (a,b,c) into c */
>> +#define __jhash_final(a, b, c)  \
>> +{                               \
>> +    c ^= b; c -= rol32(b, 14);  \
>> +    a ^= c; a -= rol32(c, 11);  \
>> +    b ^= a; b -= rol32(a, 25);  \
>> +    c ^= b; c -= rol32(b, 16);  \
>> +    a ^= c; a -= rol32(c, 4);   \
>> +    b ^= a; b -= rol32(a, 14);  \
>> +    c ^= b; c -= rol32(b, 24);  \
>> +}
>> +
>> +/* An arbitrary initial parameter */
>> +#define JHASH_INITVAL           0xdeadbeef
>> +
>> +#endif /* QEMU_JHASH_H__ */
>> -- 
>> 1.9.1
>>
>>
>>
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
>
>
> .
>
Dr. David Alan Gilbert Jan. 11, 2016, 12:50 p.m. UTC | #3
* Zhang Chen (zhangchen.fnst@cn.fujitsu.com) wrote:
> 
> 
> On 01/08/2016 08:08 PM, Dr. David Alan Gilbert wrote:
> >* Zhang Chen (zhangchen.fnst@cn.fujitsu.com) wrote:
> >>From: zhangchen <zhangchen.fnst@cn.fujitsu.com>
> >>
> >>Jhash used by colo-proxy to save and lookup
> >>net connection info
> >>
> >>Signed-off-by: zhangchen <zhangchen.fnst@cn.fujitsu.com>
> >>Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> >>---
> >>  include/qemu/jhash.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> >>  1 file changed, 61 insertions(+)
> >>  create mode 100644 include/qemu/jhash.h
> >>
> >>diff --git a/include/qemu/jhash.h b/include/qemu/jhash.h
> >>new file mode 100644
> >>index 0000000..5b82d02
> >>--- /dev/null
> >>+++ b/include/qemu/jhash.h
> >>@@ -0,0 +1,61 @@
> >>+/* jhash.h: Jenkins hash support.
> >>+  *
> >>+  * Copyright (C) 2006. Bob Jenkins (bob_jenkins@burtleburtle.net)
> >>+  *
> >>+  * http://burtleburtle.net/bob/hash/
> >>+  *
> >>+  * These are the credits from Bob's sources:
> >>+  *
> >>+  * lookup3.c, by Bob Jenkins, May 2006, Public Domain.
> >>+  *
> >>+  * These are functions for producing 32-bit hashes for hash table lookup.
> >>+  * hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final()
> >>+  * are externally useful functions.  Routines to test the hash are
> >>+included
> >>+  * if SELF_TEST is defined.  You can use this free for any purpose.
> >>+It's in
> >>+  * the public domain.  It has no warranty.
> >>+  *
> >>+  * Copyright (C) 2009-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
> >>+  *
> >>+  * I've modified Bob's hash to be useful in the Linux kernel, and
> >>+  * any bugs present are my fault.
> >>+  * Jozsef
> >>+  */
> >>+
> >>+#ifndef QEMU_JHASH_H__
> >>+#define QEMU_JHASH_H__
> >>+
> >>+#include "qemu/bitopt.h"
> >That does not build, the header in qemu is bitop*s*.h.
> >
> >Dave
> 
> I'm very sorry for it, fix it to
> 
> #include "qemu/bitopts.h"

No! It's:

#include "qemu/bitops.h"

Please at least build test this code!

Dave

> 
> Thanks
> zhangchen
> 
> 
> >>+
> >>+/*
> >>+ * hashtable relation copy from linux kernel jhash
> >>+ */
> >>+
> >>+/* __jhash_mix -- mix 3 32-bit values reversibly. */
> >>+#define __jhash_mix(a, b, c)                \
> >>+{                                           \
> >>+    a -= c;  a ^= rol32(c, 4);  c += b;     \
> >>+    b -= a;  b ^= rol32(a, 6);  a += c;     \
> >>+    c -= b;  c ^= rol32(b, 8);  b += a;     \
> >>+    a -= c;  a ^= rol32(c, 16); c += b;     \
> >>+    b -= a;  b ^= rol32(a, 19); a += c;     \
> >>+    c -= b;  c ^= rol32(b, 4);  b += a;     \
> >>+}
> >>+
> >>+/* __jhash_final - final mixing of 3 32-bit values (a,b,c) into c */
> >>+#define __jhash_final(a, b, c)  \
> >>+{                               \
> >>+    c ^= b; c -= rol32(b, 14);  \
> >>+    a ^= c; a -= rol32(c, 11);  \
> >>+    b ^= a; b -= rol32(a, 25);  \
> >>+    c ^= b; c -= rol32(b, 16);  \
> >>+    a ^= c; a -= rol32(c, 4);   \
> >>+    b ^= a; b -= rol32(a, 14);  \
> >>+    c ^= b; c -= rol32(b, 24);  \
> >>+}
> >>+
> >>+/* An arbitrary initial parameter */
> >>+#define JHASH_INITVAL           0xdeadbeef
> >>+
> >>+#endif /* QEMU_JHASH_H__ */
> >>-- 
> >>1.9.1
> >>
> >>
> >>
> >--
> >Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> >
> >
> >.
> >
> 
> -- 
> Thanks
> zhangchen
> 
> 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
Zhang Chen Jan. 12, 2016, 1:58 a.m. UTC | #4
On 01/11/2016 08:50 PM, Dr. David Alan Gilbert wrote:
> * Zhang Chen (zhangchen.fnst@cn.fujitsu.com) wrote:
>>
>> On 01/08/2016 08:08 PM, Dr. David Alan Gilbert wrote:
>>> * Zhang Chen (zhangchen.fnst@cn.fujitsu.com) wrote:
>>>> From: zhangchen <zhangchen.fnst@cn.fujitsu.com>
>>>>
>>>> Jhash used by colo-proxy to save and lookup
>>>> net connection info
>>>>
>>>> Signed-off-by: zhangchen <zhangchen.fnst@cn.fujitsu.com>
>>>> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
>>>> ---
>>>>   include/qemu/jhash.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>>>>   1 file changed, 61 insertions(+)
>>>>   create mode 100644 include/qemu/jhash.h
>>>>
>>>> diff --git a/include/qemu/jhash.h b/include/qemu/jhash.h
>>>> new file mode 100644
>>>> index 0000000..5b82d02
>>>> --- /dev/null
>>>> +++ b/include/qemu/jhash.h
>>>> @@ -0,0 +1,61 @@
>>>> +/* jhash.h: Jenkins hash support.
>>>> +  *
>>>> +  * Copyright (C) 2006. Bob Jenkins (bob_jenkins@burtleburtle.net)
>>>> +  *
>>>> +  * http://burtleburtle.net/bob/hash/
>>>> +  *
>>>> +  * These are the credits from Bob's sources:
>>>> +  *
>>>> +  * lookup3.c, by Bob Jenkins, May 2006, Public Domain.
>>>> +  *
>>>> +  * These are functions for producing 32-bit hashes for hash table lookup.
>>>> +  * hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final()
>>>> +  * are externally useful functions.  Routines to test the hash are
>>>> +included
>>>> +  * if SELF_TEST is defined.  You can use this free for any purpose.
>>>> +It's in
>>>> +  * the public domain.  It has no warranty.
>>>> +  *
>>>> +  * Copyright (C) 2009-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
>>>> +  *
>>>> +  * I've modified Bob's hash to be useful in the Linux kernel, and
>>>> +  * any bugs present are my fault.
>>>> +  * Jozsef
>>>> +  */
>>>> +
>>>> +#ifndef QEMU_JHASH_H__
>>>> +#define QEMU_JHASH_H__
>>>> +
>>>> +#include "qemu/bitopt.h"
>>> That does not build, the header in qemu is bitop*s*.h.
>>>
>>> Dave
>> I'm very sorry for it, fix it to
>>
>> #include "qemu/bitopts.h"
> No! It's:
>
> #include "qemu/bitops.h"
>
> Please at least build test this code!
>
> Dave

Fix it to #include "qemu/bitops.h"
I have rebuild this code,but qemu makefile did't check the .h
I don't know whether it is a qemu bug.
you can try change it to #include "qemu/bitops.h" and make.
then change it to #include "qemu/bitopts.h" and make.
repeat it twice, now, you can change it to #include "everything"
in jhash.h. gcc don't check the .h and report error.////


Thanks
zhangchen


>> Thanks
>> zhangchen
>>
>>
>>>> +
>>>> +/*
>>>> + * hashtable relation copy from linux kernel jhash
>>>> + */
>>>> +
>>>> +/* __jhash_mix -- mix 3 32-bit values reversibly. */
>>>> +#define __jhash_mix(a, b, c)                \
>>>> +{                                           \
>>>> +    a -= c;  a ^= rol32(c, 4);  c += b;     \
>>>> +    b -= a;  b ^= rol32(a, 6);  a += c;     \
>>>> +    c -= b;  c ^= rol32(b, 8);  b += a;     \
>>>> +    a -= c;  a ^= rol32(c, 16); c += b;     \
>>>> +    b -= a;  b ^= rol32(a, 19); a += c;     \
>>>> +    c -= b;  c ^= rol32(b, 4);  b += a;     \
>>>> +}
>>>> +
>>>> +/* __jhash_final - final mixing of 3 32-bit values (a,b,c) into c */
>>>> +#define __jhash_final(a, b, c)  \
>>>> +{                               \
>>>> +    c ^= b; c -= rol32(b, 14);  \
>>>> +    a ^= c; a -= rol32(c, 11);  \
>>>> +    b ^= a; b -= rol32(a, 25);  \
>>>> +    c ^= b; c -= rol32(b, 16);  \
>>>> +    a ^= c; a -= rol32(c, 4);   \
>>>> +    b ^= a; b -= rol32(a, 14);  \
>>>> +    c ^= b; c -= rol32(b, 24);  \
>>>> +}
>>>> +
>>>> +/* An arbitrary initial parameter */
>>>> +#define JHASH_INITVAL           0xdeadbeef
>>>> +
>>>> +#endif /* QEMU_JHASH_H__ */
>>>> -- 
>>>> 1.9.1
>>>>
>>>>
>>>>
>>> --
>>> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
>>>
>>>
>>> .
>>>
>> -- 
>> Thanks
>> zhangchen
>>
>>
>>
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
>
>
> .
>
Dr. David Alan Gilbert Jan. 12, 2016, 8:58 a.m. UTC | #5
* Zhang Chen (zhangchen.fnst@cn.fujitsu.com) wrote:
> 
> 
> On 01/11/2016 08:50 PM, Dr. David Alan Gilbert wrote:
> >* Zhang Chen (zhangchen.fnst@cn.fujitsu.com) wrote:
> >>
> >>On 01/08/2016 08:08 PM, Dr. David Alan Gilbert wrote:
> >>>* Zhang Chen (zhangchen.fnst@cn.fujitsu.com) wrote:
> >>>>From: zhangchen <zhangchen.fnst@cn.fujitsu.com>
> >>>>
> >>>>Jhash used by colo-proxy to save and lookup
> >>>>net connection info
> >>>>
> >>>>Signed-off-by: zhangchen <zhangchen.fnst@cn.fujitsu.com>
> >>>>Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> >>>>---
> >>>>  include/qemu/jhash.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> >>>>  1 file changed, 61 insertions(+)
> >>>>  create mode 100644 include/qemu/jhash.h
> >>>>
> >>>>diff --git a/include/qemu/jhash.h b/include/qemu/jhash.h
> >>>>new file mode 100644
> >>>>index 0000000..5b82d02
> >>>>--- /dev/null
> >>>>+++ b/include/qemu/jhash.h
> >>>>@@ -0,0 +1,61 @@
> >>>>+/* jhash.h: Jenkins hash support.
> >>>>+  *
> >>>>+  * Copyright (C) 2006. Bob Jenkins (bob_jenkins@burtleburtle.net)
> >>>>+  *
> >>>>+  * http://burtleburtle.net/bob/hash/
> >>>>+  *
> >>>>+  * These are the credits from Bob's sources:
> >>>>+  *
> >>>>+  * lookup3.c, by Bob Jenkins, May 2006, Public Domain.
> >>>>+  *
> >>>>+  * These are functions for producing 32-bit hashes for hash table lookup.
> >>>>+  * hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final()
> >>>>+  * are externally useful functions.  Routines to test the hash are
> >>>>+included
> >>>>+  * if SELF_TEST is defined.  You can use this free for any purpose.
> >>>>+It's in
> >>>>+  * the public domain.  It has no warranty.
> >>>>+  *
> >>>>+  * Copyright (C) 2009-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
> >>>>+  *
> >>>>+  * I've modified Bob's hash to be useful in the Linux kernel, and
> >>>>+  * any bugs present are my fault.
> >>>>+  * Jozsef
> >>>>+  */
> >>>>+
> >>>>+#ifndef QEMU_JHASH_H__
> >>>>+#define QEMU_JHASH_H__
> >>>>+
> >>>>+#include "qemu/bitopt.h"
> >>>That does not build, the header in qemu is bitop*s*.h.
> >>>
> >>>Dave
> >>I'm very sorry for it, fix it to
> >>
> >>#include "qemu/bitopts.h"
> >No! It's:
> >
> >#include "qemu/bitops.h"
> >
> >Please at least build test this code!
> >
> >Dave
> 
> Fix it to #include "qemu/bitops.h"
> I have rebuild this code,but qemu makefile did't check the .h
> I don't know whether it is a qemu bug.
> you can try change it to #include "qemu/bitops.h" and make.
> then change it to #include "qemu/bitopts.h" and make.
> repeat it twice, now, you can change it to #include "everything"
> in jhash.h. gcc don't check the .h and report error.////

gcc/makefile don't check these things; it's when you include the
next patch in your series, that #include "qemu/jhash.h" in colo-proxy.c
which is where it will break.

Dave

> 
> 
> Thanks
> zhangchen
> 
> 
> >>Thanks
> >>zhangchen
> >>
> >>
> >>>>+
> >>>>+/*
> >>>>+ * hashtable relation copy from linux kernel jhash
> >>>>+ */
> >>>>+
> >>>>+/* __jhash_mix -- mix 3 32-bit values reversibly. */
> >>>>+#define __jhash_mix(a, b, c)                \
> >>>>+{                                           \
> >>>>+    a -= c;  a ^= rol32(c, 4);  c += b;     \
> >>>>+    b -= a;  b ^= rol32(a, 6);  a += c;     \
> >>>>+    c -= b;  c ^= rol32(b, 8);  b += a;     \
> >>>>+    a -= c;  a ^= rol32(c, 16); c += b;     \
> >>>>+    b -= a;  b ^= rol32(a, 19); a += c;     \
> >>>>+    c -= b;  c ^= rol32(b, 4);  b += a;     \
> >>>>+}
> >>>>+
> >>>>+/* __jhash_final - final mixing of 3 32-bit values (a,b,c) into c */
> >>>>+#define __jhash_final(a, b, c)  \
> >>>>+{                               \
> >>>>+    c ^= b; c -= rol32(b, 14);  \
> >>>>+    a ^= c; a -= rol32(c, 11);  \
> >>>>+    b ^= a; b -= rol32(a, 25);  \
> >>>>+    c ^= b; c -= rol32(b, 16);  \
> >>>>+    a ^= c; a -= rol32(c, 4);   \
> >>>>+    b ^= a; b -= rol32(a, 14);  \
> >>>>+    c ^= b; c -= rol32(b, 24);  \
> >>>>+}
> >>>>+
> >>>>+/* An arbitrary initial parameter */
> >>>>+#define JHASH_INITVAL           0xdeadbeef
> >>>>+
> >>>>+#endif /* QEMU_JHASH_H__ */
> >>>>-- 
> >>>>1.9.1
> >>>>
> >>>>
> >>>>
> >>>--
> >>>Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> >>>
> >>>
> >>>.
> >>>
> >>-- 
> >>Thanks
> >>zhangchen
> >>
> >>
> >>
> >--
> >Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> >
> >
> >.
> >
> 
> -- 
> Thanks
> zhangchen
> 
> 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
diff mbox

Patch

diff --git a/include/qemu/jhash.h b/include/qemu/jhash.h
new file mode 100644
index 0000000..5b82d02
--- /dev/null
+++ b/include/qemu/jhash.h
@@ -0,0 +1,61 @@ 
+/* jhash.h: Jenkins hash support.
+  *
+  * Copyright (C) 2006. Bob Jenkins (bob_jenkins@burtleburtle.net)
+  *
+  * http://burtleburtle.net/bob/hash/
+  *
+  * These are the credits from Bob's sources:
+  *
+  * lookup3.c, by Bob Jenkins, May 2006, Public Domain.
+  *
+  * These are functions for producing 32-bit hashes for hash table lookup.
+  * hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final()
+  * are externally useful functions.  Routines to test the hash are
+included
+  * if SELF_TEST is defined.  You can use this free for any purpose.
+It's in
+  * the public domain.  It has no warranty.
+  *
+  * Copyright (C) 2009-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
+  *
+  * I've modified Bob's hash to be useful in the Linux kernel, and
+  * any bugs present are my fault.
+  * Jozsef
+  */
+
+#ifndef QEMU_JHASH_H__
+#define QEMU_JHASH_H__
+
+#include "qemu/bitopt.h"
+
+/*
+ * hashtable relation copy from linux kernel jhash
+ */
+
+/* __jhash_mix -- mix 3 32-bit values reversibly. */
+#define __jhash_mix(a, b, c)                \
+{                                           \
+    a -= c;  a ^= rol32(c, 4);  c += b;     \
+    b -= a;  b ^= rol32(a, 6);  a += c;     \
+    c -= b;  c ^= rol32(b, 8);  b += a;     \
+    a -= c;  a ^= rol32(c, 16); c += b;     \
+    b -= a;  b ^= rol32(a, 19); a += c;     \
+    c -= b;  c ^= rol32(b, 4);  b += a;     \
+}
+
+/* __jhash_final - final mixing of 3 32-bit values (a,b,c) into c */
+#define __jhash_final(a, b, c)  \
+{                               \
+    c ^= b; c -= rol32(b, 14);  \
+    a ^= c; a -= rol32(c, 11);  \
+    b ^= a; b -= rol32(a, 25);  \
+    c ^= b; c -= rol32(b, 16);  \
+    a ^= c; a -= rol32(c, 4);   \
+    b ^= a; b -= rol32(a, 14);  \
+    c ^= b; c -= rol32(b, 24);  \
+}
+
+/* An arbitrary initial parameter */
+#define JHASH_INITVAL           0xdeadbeef
+
+#endif /* QEMU_JHASH_H__ */