1 /* go-type-complex.c -- hash and equality complex functions.
3 Copyright 2012 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. */
10 /* The 64-bit type. */
12 typedef unsigned int DItype
__attribute__ ((mode (DI
)));
14 /* Hash function for float types. */
17 __go_type_hash_complex (const void *vkey
, uintptr_t key_size
)
31 __builtin_memcpy (ucf
.a
, vkey
, 8);
33 cfr
= __builtin_crealf (cf
);
34 cfi
= __builtin_cimagf (cf
);
35 if (__builtin_isinff (cfr
) || __builtin_isinff (cfi
))
38 /* NaN != NaN, so the hash code of a NaN is irrelevant. Make it
39 random so that not all NaNs wind up in the same place. */
40 if (__builtin_isnanf (cfr
) || __builtin_isnanf (cfi
))
41 return runtime_fastrand1 ();
43 /* Avoid negative zero. */
44 if (cfr
== 0 && cfi
== 0)
53 else if (key_size
== 16)
65 __builtin_memcpy (ucd
.a
, vkey
, 16);
67 cdr
= __builtin_crealf (cd
);
68 cdi
= __builtin_cimagf (cd
);
69 if (__builtin_isinf (cdr
) || __builtin_isinf (cdi
))
72 if (__builtin_isnan (cdr
) || __builtin_isnan (cdi
))
73 return runtime_fastrand1 ();
75 /* Avoid negative zero. */
76 if (cdr
== 0 && cdi
== 0)
83 return ucd
.adi
[0] ^ ucd
.adi
[1];
86 runtime_throw ("__go_type_hash_complex: invalid complex size");
89 /* Equality function for complex types. */
92 __go_type_equal_complex (const void *vk1
, const void *vk2
, uintptr_t key_size
)
104 __builtin_memcpy (ucf
.a
, vk1
, 8);
106 __builtin_memcpy (ucf
.a
, vk2
, 8);
110 else if (key_size
== 16)
117 __complex
double cd1
;
118 __complex
double cd2
;
120 __builtin_memcpy (ucd
.a
, vk1
, 16);
122 __builtin_memcpy (ucd
.a
, vk2
, 16);
127 runtime_throw ("__go_type_equal_complex: invalid complex size");