diff options
author | Ben Cheng <bccheng@google.com> | 2013-03-28 11:14:20 -0700 |
---|---|---|
committer | Ben Cheng <bccheng@google.com> | 2013-03-28 12:40:33 -0700 |
commit | af0c51ac87ab2a87caa03fa108f0d164987a2764 (patch) | |
tree | 4b8b470f7c5b69642fdab8d0aa1fbc148d02196b /gcc-4.8/libgo/runtime/go-type-identity.c | |
parent | d87cae247d39ebf4f5a6bf25c932a14d2fdb9384 (diff) | |
download | toolchain_gcc-af0c51ac87ab2a87caa03fa108f0d164987a2764.tar.gz toolchain_gcc-af0c51ac87ab2a87caa03fa108f0d164987a2764.tar.bz2 toolchain_gcc-af0c51ac87ab2a87caa03fa108f0d164987a2764.zip |
[GCC 4.8] Initial check-in of GCC 4.8.0
Change-Id: I0719d8a6d0f69b367a6ab6f10eb75622dbf12771
Diffstat (limited to 'gcc-4.8/libgo/runtime/go-type-identity.c')
-rw-r--r-- | gcc-4.8/libgo/runtime/go-type-identity.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/gcc-4.8/libgo/runtime/go-type-identity.c b/gcc-4.8/libgo/runtime/go-type-identity.c new file mode 100644 index 000000000..ed510f75a --- /dev/null +++ b/gcc-4.8/libgo/runtime/go-type-identity.c @@ -0,0 +1,56 @@ +/* go-type-identity.c -- hash and equality identity functions. + + Copyright 2009 The Go Authors. All rights reserved. + Use of this source code is governed by a BSD-style + license that can be found in the LICENSE file. */ + +#include <stddef.h> + +#include "runtime.h" +#include "go-type.h" + +/* An identity hash function for a type. This is used for types where + we can simply use the type value itself as a hash code. This is + true of, e.g., integers and pointers. */ + +uintptr_t +__go_type_hash_identity (const void *key, uintptr_t key_size) +{ + uintptr_t ret; + uintptr_t i; + const unsigned char *p; + + if (key_size <= 8) + { + union + { + uint64 v; + unsigned char a[8]; + } u; + u.v = 0; +#ifdef WORDS_BIGENDIAN + __builtin_memcpy (&u.a[8 - key_size], key, key_size); +#else + __builtin_memcpy (&u.a[0], key, key_size); +#endif + if (sizeof (uintptr_t) >= 8) + return (uintptr_t) u.v; + else + return (uintptr_t) ((u.v >> 32) ^ (u.v & 0xffffffff)); + } + + ret = 5381; + for (i = 0, p = (const unsigned char *) key; i < key_size; i++, p++) + ret = ret * 33 + *p; + return ret; +} + +/* An identity equality function for a type. This is used for types + where we can check for equality by checking that the values have + the same bits. */ + +_Bool +__go_type_equal_identity (const void *k1, const void *k2, uintptr_t key_size) +{ + return __builtin_memcmp (k1, k2, key_size) == 0; +} |