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
)
36 || __builtin_isnanf (cfr
) || __builtin_isnanf (cfi
))
39 /* Avoid negative zero. */
40 if (cfr
== 0 && cfi
== 0)
49 else if (key_size
== 16)
61 __builtin_memcpy (ucd
.a
, vkey
, 16);
63 cdr
= __builtin_crealf (cd
);
64 cdi
= __builtin_cimagf (cd
);
65 if (__builtin_isinf (cdr
) || __builtin_isinf (cdi
)
66 || __builtin_isnan (cdr
) || __builtin_isnan (cdi
))
69 /* Avoid negative zero. */
70 if (cdr
== 0 && cdi
== 0)
77 return ucd
.adi
[0] ^ ucd
.adi
[1];
80 runtime_throw ("__go_type_hash_complex: invalid complex size");
83 /* Equality function for complex types. */
86 __go_type_equal_complex (const void *vk1
, const void *vk2
, uintptr_t key_size
)
98 __builtin_memcpy (ucf
.a
, vk1
, 8);
100 __builtin_memcpy (ucf
.a
, vk2
, 8);
104 else if (key_size
== 16)
111 __complex
double cd1
;
112 __complex
double cd2
;
114 __builtin_memcpy (ucd
.a
, vk1
, 16);
116 __builtin_memcpy (ucd
.a
, vk2
, 16);
121 runtime_throw ("__go_type_equal_complex: invalid complex size");