OSDN Git Service

Update to current version of Go library.
[pf3gnuchains/gcc-fork.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 "go-type.h"
10
11 /* Typedefs for accesses of different sizes.  */
12
13 typedef int QItype __attribute__ ((mode (QI)));
14 typedef int HItype __attribute__ ((mode (HI)));
15 typedef int SItype __attribute__ ((mode (SI)));
16 typedef int DItype __attribute__ ((mode (DI)));
17
18 /* An identity hash function for a type.  This is used for types where
19    we can simply use the type value itself as a hash code.  This is
20    true of, e.g., integers and pointers.  */
21
22 size_t
23 __go_type_hash_identity (const void *key, size_t key_size)
24 {
25   switch (key_size)
26     {
27     case 1:
28       return *(const QItype *) key;
29     case 2:
30       return *(const HItype *) key;
31     case 3:
32     case 4:
33     case 5:
34     case 6:
35     case 7:
36       return *(const SItype *) key;
37     default:
38       return *(const DItype *) key;
39     }
40 }
41
42 /* An identity equality function for a type.  This is used for types
43    where we can check for equality by checking that the values have
44    the same bits.  */
45
46 _Bool
47 __go_type_equal_identity (const void *k1, const void *k2, size_t key_size)
48 {
49   return __builtin_memcmp (k1, k2, key_size) == 0;
50 }