OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [runtime/] [go-type-identity.c] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
/* 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
/* The 64-bit type.  */
12
 
13
typedef unsigned int DItype __attribute__ ((mode (DI)));
14
 
15
/* An identity hash function for a type.  This is used for types where
16
   we can simply use the type value itself as a hash code.  This is
17
   true of, e.g., integers and pointers.  */
18
 
19
uintptr_t
20
__go_type_hash_identity (const void *key, uintptr_t key_size)
21
{
22
  uintptr_t ret;
23
  uintptr_t i;
24
  const unsigned char *p;
25
 
26
  if (key_size <= 8)
27
    {
28
      union
29
      {
30
        DItype v;
31
        unsigned char a[8];
32
      } u;
33
      u.v = 0;
34
      __builtin_memcpy (&u.a, key, key_size);
35
      if (sizeof (uintptr_t) >= 8)
36
        return (uintptr_t) u.v;
37
      else
38
        return (uintptr_t) ((u.v >> 32) ^ (u.v & 0xffffffff));
39
    }
40
 
41
  ret = 5381;
42
  for (i = 0, p = (const unsigned char *) key; i < key_size; i++, p++)
43
    ret = ret * 33 + *p;
44
  return ret;
45
}
46
 
47
/* An identity equality function for a type.  This is used for types
48
   where we can check for equality by checking that the values have
49
   the same bits.  */
50
 
51
_Bool
52
__go_type_equal_identity (const void *k1, const void *k2, uintptr_t key_size)
53
{
54
  return __builtin_memcmp (k1, k2, key_size) == 0;
55
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.