~ubuntu-branches/ubuntu/vivid/kmod/vivid

« back to all changes in this revision

Viewing changes to libkmod/libkmod-hash.c

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2012-09-21 16:05:32 UTC
  • mfrom: (4.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120921160532-bdsxhmpj5og2ru5h
Tags: 9-2ubuntu1
* Sync with Debian unstable; remaining Ubuntu changes:
  - Ubuntu-specific depmod.d and modprobe.d contents.
  - Mark module-init-tools Multi-Arch: foreign.
  - Don't install Debian's extra/aliases.conf file.
  - Install upstart job instead of the sysvinit script.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "libkmod.h"
22
22
#include "libkmod-hash.h"
23
23
 
 
24
#include "libkmod-util.h"
24
25
#include <stdlib.h>
25
26
#include <string.h>
26
27
#include <errno.h>
83
84
        free(hash);
84
85
}
85
86
 
86
 
struct unaligned_short {
87
 
    unsigned short v;
88
 
} __attribute__((packed));
89
 
 
90
 
static inline unsigned short get16bits(const char *ptr)
91
 
{
92
 
    return ((struct unaligned_short *)ptr)->v;
93
 
}
94
 
 
95
87
static inline unsigned int hash_superfast(const char *key, unsigned int len)
96
88
{
97
89
        /* Paul Hsieh (http://www.azillionmonkeys.com/qed/hash.html)
104
96
 
105
97
        /* Main loop */
106
98
        for (; len > 0; len--) {
107
 
                hash += get16bits(key);
108
 
                tmp = (get16bits(key + 2) << 11) ^ hash;
 
99
                hash += get_unaligned((uint16_t *) key);
 
100
                tmp = (get_unaligned((uint16_t *)(key + 2)) << 11) ^ hash;
109
101
                hash = (hash << 16) ^ tmp;
110
102
                key += 4;
111
103
                hash += hash >> 11;
114
106
        /* Handle end cases */
115
107
        switch (rem) {
116
108
        case 3:
117
 
                hash += get16bits(key);
 
109
                hash += get_unaligned((uint16_t *) key);
118
110
                hash ^= hash << 16;
119
111
                hash ^= key[2] << 18;
120
112
                hash += hash >> 11;
121
113
                break;
122
114
 
123
115
        case 2:
124
 
                hash += get16bits(key);
 
116
                hash += get_unaligned((uint16_t *) key);
125
117
                hash ^= hash << 11;
126
118
                hash += hash >> 17;
127
119
                break;