source: branches/working-0711/ccl/level-0/X86/x86-hash.lisp @ 9930

Last change on this file since 9930 was 9930, checked in by gz, 12 years ago

Faster version of mod in hashing code (based on Bruce Hoult's Dylan version, plus a branch-free max).

On the machine I'm using this seems to speed up the no-locking no-collision no-address case of EQ GETHASH by about 20%.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1;;; -*- Mode: Lisp; Package: CCL -*-
2;;;
3;;;   Copyright (C) 2006, Clozure Associates and contributors
4;;;   This file is part of OpenMCL. 
5;;;
6;;;   OpenMCL is licensed under the terms of the Lisp Lesser GNU Public
7;;;   License , known as the LLGPL and distributed with OpenMCL as the
8;;;   file "LICENSE".  The LLGPL consists of a preamble and the LGPL,
9;;;   which is distributed with OpenMCL as the file "LGPL".  Where these
10;;;   conflict, the preamble takes precedence. 
11;;;
12;;;   OpenMCL is referenced in the preamble as the "LIBRARY."
13;;;
14;;;   The LLGPL is also available online at
15;;;   http://opensource.franz.com/preamble.html
16
17;;; level-0;ppc;ppc-hash.lisp
18
19
20(in-package "CCL")
21
22(eval-when (:compile-toplevel :execute)
23  (require "HASHENV" "ccl:xdump;hashenv"))
24
25
26
27
28;;; This should stay in LAP so that it's fast
29;;; Equivalent to cl:mod when both args are positive fixnums
30
31
32(defx86lapfunction fast-mod ((number arg_y) (divisor arg_z))
33  (xorq (% imm1) (% imm1))
34  (mov (% number) (% imm0))
35  (div (% divisor))
36  (mov (% imm1) (% arg_z))
37  (single-value-return))
38
39
40;; Faster mod based on Bruce Hoult's Dylan version, modified to use a branch-free max.
41(defx86lapfunction fast-mod-3 ((number arg_x) (divisor arg_y) (recip arg_z))
42  (mov (% number) (% imm0))
43  (shrq ($ target::fixnumshift) (% imm0))
44  (mov (% recip) (% imm1))
45  (mul (% imm1)) ;; -> hi word in imm1 (unboxed)
46  (mov (% divisor) (% imm0))
47  (mul (% imm1)) ;; -> lo word in imm0 (boxed)
48  (subq (% imm0) (% number))
49  (subq (% divisor) (% number))
50  (mov (% number) (% arg_z))
51  (sar ($ (- target::nbits-in-word target::fixnumshift)) (% number))
52  (andq (% divisor) (% number))
53  (addq (% number) (% arg_z))
54  (single-value-return))
55
56(defx86lapfunction %dfloat-hash ((key arg_z))
57  (movq (@ x8664::double-float.value (% key)) (% imm0))
58  (box-fixnum imm0 arg_z)
59  (single-value-return))
60
61(defx86lapfunction %sfloat-hash ((key arg_z))
62  (mov (% key) (% imm1))
63  (movl ($ #x-80000000) (%l imm0))
64  (shr ($ 32) (% imm1))
65  (xorq (% arg_y) (% arg_y))
66  (shr ($ (- 32 x8664::fixnumshift)) (% key))
67  (rcmp (%l imm0) (%l imm1))
68  (cmoveq (% arg_y) (% arg_z))
69  (single-value-return))
70
71(defx86lapfunction %macptr-hash ((key arg_z))
72  (movq (@ target::macptr.address (% key)) (% imm0))
73  (movq (% imm0) (% imm1))
74  (shlq ($ 24) (% imm1))
75  (addq (% imm1) (% imm0))
76  (movq ($ (lognot target::fixnummask)) (% arg_z))
77  (andq (% imm0) (% arg_z))
78  (single-value-return))
79
80
81(defx86lapfunction %bignum-hash ((key arg_z))
82  (let ((header imm0)
83        (offset imm1)
84        (ndigits temp0))
85    (getvheader key header)
86    (header-length header ndigits)
87    (xorq (% offset) (% offset))
88    (let ((immhash header))
89      @loop
90      (rolq ($ 13) (% immhash))
91      (addl (@ x8664::misc-data-offset (% key) (% offset)) (%l immhash))
92      (addq ($ 4) (% offset))
93      (subq ($ '1) (% ndigits))
94      (jne  @loop)
95      (box-fixnum immhash arg_z))
96    (single-value-return)))
97
98
99(defx86lapfunction %get-fwdnum ()
100  (ref-global target::fwdnum arg_z)
101  (single-value-return))
102
103
104(defx86lapfunction %get-gc-count ()
105  (ref-global target::gc-count arg_z)
106  (single-value-return))
107
108
109;;; Setting a key in a hash-table vector needs to
110;;; ensure that the vector header gets memoized as well
111(defx86lapfunction %set-hash-table-vector-key ((vector arg_x) (index arg_y) (value arg_z))
112  (jmp-subprim .SPset-hash-key))
113
114;;; Strip the tag bits to turn x into a fixnum
115(defx86lapfunction strip-tag-to-fixnum ((x arg_z))
116  (andb ($ (lognot x8664::fixnummask)) (%b x))
117  (single-value-return))
118
119;;; end of x86-hash.lisp
Note: See TracBrowser for help on using the repository browser.