Initial revision
[sbcl.git] / src / code / sxhash.lisp
1 ;;;; that part of SXHASH logic which runs not only in the target Lisp but
2 ;;;; in the cross-compilation host Lisp
3
4 ;;;; This software is part of the SBCL system. See the README file for
5 ;;;; more information.
6 ;;;;
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
12
13 (in-package "SB!C")
14
15 (sb!xc:define-modify-macro mixf (y) mix)
16
17 ;;; SXHASH of FLOAT values is defined directly in terms of DEFTRANSFORM in
18 ;;; order to avoid boxing.
19 (deftransform sxhash ((x) (single-float))
20   '(let ((bits (single-float-bits x)))
21      (logxor 66194023
22              (sxhash (the fixnum
23                           (logand most-positive-fixnum
24                                   (logxor bits
25                                           (ash bits -7))))))))
26 (deftransform sxhash ((x) (double-float))
27   '(let* ((val x)
28           (hi (double-float-high-bits val))
29           (lo (double-float-low-bits val))
30           (hilo (logxor hi lo)))
31      (logxor 475038542
32              (sxhash (the fixnum
33                           (logand most-positive-fixnum
34                                   (logxor hilo
35                                           (ash hilo -7))))))))
36
37 ;;; SXHASH of FIXNUM values is defined as a DEFTRANSFORM because it's so
38 ;;; simple.
39 (deftransform sxhash ((x) (fixnum))
40   '(logand most-positive-fixnum
41            (logxor x
42                    (ash x -3) ; to get sign bit into hash
43                    361475658)))
44
45 ;;;; Some other common SXHASH cases are defined as DEFTRANSFORMs in order to
46 ;;;; avoid having to do TYPECASE at runtime.
47 (deftransform sxhash ((x) (simple-string))
48   '(%sxhash-simple-string x))
49 (deftransform sxhash ((x) (symbol))
50   '(%sxhash-simple-string (symbol-name x)))