runtime: runtime.Caller should succeed even without debug info.
[gcc.git] / libgo / runtime / go-type-identity.c
1 /* go-type-identity.c -- hash and equality identity functions.
2
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
6
7 #include <stddef.h>
8
9 #include "config.h"
10 #include "go-type.h"
11
12 /* The 64-bit type. */
13
14 typedef unsigned int DItype __attribute__ ((mode (DI)));
15
16 /* An identity hash function for a type. This is used for types where
17 we can simply use the type value itself as a hash code. This is
18 true of, e.g., integers and pointers. */
19
20 uintptr_t
21 __go_type_hash_identity (const void *key, uintptr_t key_size)
22 {
23 uintptr_t ret;
24 uintptr_t i;
25 const unsigned char *p;
26
27 if (key_size <= 8)
28 {
29 union
30 {
31 DItype v;
32 unsigned char a[8];
33 } u;
34 u.v = 0;
35 #ifdef WORDS_BIGENDIAN
36 __builtin_memcpy (&u.a[8 - key_size], key, key_size);
37 #else
38 __builtin_memcpy (&u.a[0], key, key_size);
39 #endif
40 if (sizeof (uintptr_t) >= 8)
41 return (uintptr_t) u.v;
42 else
43 return (uintptr_t) ((u.v >> 32) ^ (u.v & 0xffffffff));
44 }
45
46 ret = 5381;
47 for (i = 0, p = (const unsigned char *) key; i < key_size; i++, p++)
48 ret = ret * 33 + *p;
49 return ret;
50 }
51
52 /* An identity equality function for a type. This is used for types
53 where we can check for equality by checking that the values have
54 the same bits. */
55
56 _Bool
57 __go_type_equal_identity (const void *k1, const void *k2, uintptr_t key_size)
58 {
59 return __builtin_memcmp (k1, k2, key_size) == 0;
60 }