1 /* go-type-float.c -- hash and equality float 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 32-bit and 64-bit types. */
12 typedef unsigned int SItype
__attribute__ ((mode (SI
)));
13 typedef unsigned int DItype
__attribute__ ((mode (DI
)));
15 /* Hash function for float types. */
18 __go_type_hash_float (const void *vkey
, uintptr_t key_size
)
30 __builtin_memcpy (uf
.a
, vkey
, 4);
32 if (__builtin_isinff (f
) || f
== 0)
35 /* NaN != NaN, so the hash code of a NaN is irrelevant. Make it
36 random so that not all NaNs wind up in the same place. */
37 if (__builtin_isnanf (f
))
38 return runtime_fastrand1 ();
40 return (uintptr_t) uf
.si
;
42 else if (key_size
== 8)
52 __builtin_memcpy (ud
.a
, vkey
, 8);
54 if (__builtin_isinf (d
) || d
== 0)
57 if (__builtin_isnan (d
))
58 return runtime_fastrand1 ();
60 return (uintptr_t) ud
.di
;
63 runtime_throw ("__go_type_hash_float: invalid float size");
66 /* Equality function for float types. */
69 __go_type_equal_float (const void *vk1
, const void *vk2
, uintptr_t key_size
)
81 __builtin_memcpy (uf
.a
, vk1
, 4);
83 __builtin_memcpy (uf
.a
, vk2
, 4);
87 else if (key_size
== 8)
98 __builtin_memcpy (ud
.a
, vk1
, 8);
100 __builtin_memcpy (ud
.a
, vk2
, 8);
105 runtime_throw ("__go_type_equal_float: invalid float size");