Fixing many clang warnings.

This commit is contained in:
Ben Vanik
2014-08-21 23:10:08 -07:00
parent 7ae303dfa2
commit 6f802c2432
14 changed files with 260 additions and 427 deletions

View File

@@ -89,142 +89,6 @@ static const uint64_t k0 = 0xc3a5c85c97cb3127ULL;
static const uint64_t k1 = 0xb492b66fbe98f273ULL;
static const uint64_t k2 = 0x9ae16a3b2f90404fULL;
// Magic numbers for 32-bit hashing. Copied from Murmur3.
static const uint32_t c1 = 0xcc9e2d51;
static const uint32_t c2 = 0x1b873593;
// A 32-bit to 32-bit integer hash copied from Murmur3.
static uint32_t fmix(uint32_t h) {
h ^= h >> 16;
h *= 0x85ebca6b;
h ^= h >> 13;
h *= 0xc2b2ae35;
h ^= h >> 16;
return h;
}
static uint32_t Rotate32(uint32_t val, int shift) {
// Avoid shifting by 32: doing so yields an undefined result.
return shift == 0 ? val : ((val >> shift) | (val << (32 - shift)));
}
#undef PERMUTE3
#define PERMUTE3(a, b, c) \
do { \
std::swap(a, b); \
std::swap(a, c); \
} while (0)
static uint32_t Mur(uint32_t a, uint32_t h) {
// Helper from Murmur3 for combining two 32-bit values.
a *= c1;
a = Rotate32(a, 17);
a *= c2;
h ^= a;
h = Rotate32(h, 19);
return h * 5 + 0xe6546b64;
}
static uint32_t Hash32Len13to24(const char *s, size_t len) {
uint32_t a = Fetch32(s - 4 + (len >> 1));
uint32_t b = Fetch32(s + 4);
uint32_t c = Fetch32(s + len - 8);
uint32_t d = Fetch32(s + (len >> 1));
uint32_t e = Fetch32(s);
uint32_t f = Fetch32(s + len - 4);
uint32_t h = (uint32_t)len;
return fmix(Mur(f, Mur(e, Mur(d, Mur(c, Mur(b, Mur(a, h)))))));
}
static uint32_t Hash32Len0to4(const char *s, size_t len) {
uint32_t b = 0;
uint32_t c = 9;
for (size_t i = 0; i < len; i++) {
signed char v = s[i];
b = b * c1 + v;
c ^= b;
}
return fmix(Mur(b, Mur((uint32_t)len, c)));
}
static uint32_t Hash32Len5to12(const char *s, size_t len) {
uint32_t a = (uint32_t)len, b = (uint32_t)len * 5, c = 9, d = b;
a += Fetch32(s);
b += Fetch32(s + len - 4);
c += Fetch32(s + ((len >> 1) & 4));
return fmix(Mur(c, Mur(b, Mur(a, d))));
}
uint32_t CityHash32(const char *s, size_t len) {
if (len <= 24) {
return len <= 12
? (len <= 4 ? Hash32Len0to4(s, len) : Hash32Len5to12(s, len))
: Hash32Len13to24(s, len);
}
// len > 24
uint32_t h = (uint32_t)len, g = c1 * (uint32_t)len, f = g;
uint32_t a0 = Rotate32(Fetch32(s + len - 4) * c1, 17) * c2;
uint32_t a1 = Rotate32(Fetch32(s + len - 8) * c1, 17) * c2;
uint32_t a2 = Rotate32(Fetch32(s + len - 16) * c1, 17) * c2;
uint32_t a3 = Rotate32(Fetch32(s + len - 12) * c1, 17) * c2;
uint32_t a4 = Rotate32(Fetch32(s + len - 20) * c1, 17) * c2;
h ^= a0;
h = Rotate32(h, 19);
h = h * 5 + 0xe6546b64;
h ^= a2;
h = Rotate32(h, 19);
h = h * 5 + 0xe6546b64;
g ^= a1;
g = Rotate32(g, 19);
g = g * 5 + 0xe6546b64;
g ^= a3;
g = Rotate32(g, 19);
g = g * 5 + 0xe6546b64;
f += a4;
f = Rotate32(f, 19);
f = f * 5 + 0xe6546b64;
size_t iters = (len - 1) / 20;
do {
uint32_t a0 = Rotate32(Fetch32(s) * c1, 17) * c2;
uint32_t a1 = Fetch32(s + 4);
uint32_t a2 = Rotate32(Fetch32(s + 8) * c1, 17) * c2;
uint32_t a3 = Rotate32(Fetch32(s + 12) * c1, 17) * c2;
uint32_t a4 = Fetch32(s + 16);
h ^= a0;
h = Rotate32(h, 18);
h = h * 5 + 0xe6546b64;
f += a1;
f = Rotate32(f, 19);
f = f * c1;
g += a2;
g = Rotate32(g, 18);
g = g * 5 + 0xe6546b64;
h ^= a3 + a1;
h = Rotate32(h, 19);
h = h * 5 + 0xe6546b64;
g ^= a4;
g = poly::byte_swap(g) * 5;
h += a4 * 5;
h = poly::byte_swap(h);
f += a0;
PERMUTE3(f, h, g);
s += 20;
} while (--iters != 0);
g = Rotate32(g, 11) * c1;
g = Rotate32(g, 17) * c1;
f = Rotate32(f, 11) * c1;
f = Rotate32(f, 17) * c1;
h = Rotate32(h + g, 19);
h = h * 5 + 0xe6546b64;
h = Rotate32(h, 17) * c1;
h = Rotate32(h + f, 19);
h = h * 5 + 0xe6546b64;
h = Rotate32(h, 17) * c1;
return h;
}
// Bitwise right rotate. Normally this will compile to a single
// instruction, especially if the shift is a manifest constant.
static uint64_t Rotate(uint64_t val, int shift) {
@@ -374,4 +238,4 @@ uint64_t hash64(const void *data, size_t length, uint64_t seed) {
return HashLen16(CityHash64((const char *)data, length) - k2, seed);
}
} // namespace xe
} // namespace xe

View File

@@ -9,11 +9,15 @@
#include <xenia/core/socket.h>
#include <fcntl.h>
#include <poll.h>
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <netinet/tcp.h>
#include <poll.h>
#include <sys/socket.h>
#include <unistd.h>
#include <poly/math.h>
void xe_socket_init() {
// No-op.
@@ -81,7 +85,7 @@ int xe_socket_bind_loopback(socket_t socket) {
socket_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
socket_addr.sin_port = htons(0);
int r = bind(socket, (struct sockaddr*)&socket_addr, sizeof(socket_addr));
if (r == SOCKET_ERROR) {
if (r == -1) {
return 1;
}
return 0;
@@ -108,7 +112,7 @@ int xe_socket_accept(socket_t socket, xe_socket_connection_t* out_client_info) {
int client_ip = client_addr.sin_addr.s_addr;
inet_ntop(AF_INET, &client_ip, out_client_info->addr,
XECOUNT(out_client_info->addr));
poly::countof(out_client_info->addr));
return 0;
}
@@ -177,7 +181,7 @@ int xe_socket_loop_poll(xe_socket_loop_t* loop, bool check_read,
// Poll.
int r;
while ((r = poll(loop->events, XECOUNT(loop->events), -1)) == -1 &&
while ((r = poll(loop->events, poly::countof(loop->events), -1)) == -1 &&
errno == EINTR)
;
if (r == -1) {
@@ -193,7 +197,7 @@ int xe_socket_loop_poll(xe_socket_loop_t* loop, bool check_read,
loop->pending_queued_write = loop->events[1].revents != 0;
if (loop->pending_queued_write) {
uint8_t dummy;
XEIGNORE(recv(loop->notify_rd_id, &dummy, 1, 0));
recv(loop->notify_rd_id, &dummy, 1, 0);
}
loop->events[1].revents = 0;
loop->events[1].events = POLLIN;