source: release/1.11/source/level-0/X86/X8632/x8632-hash.lisp

Last change on this file was 16688, checked in by R. Matthew Emerson, 9 years ago

Merge copyright/license header changes to 1.11 release branch.

File size: 4.5 KB
RevLine 
[16688]1;;;
[13067]2;;; Copyright 2009 Clozure Associates
3;;;
[16688]4;;; Licensed under the Apache License, Version 2.0 (the "License");
5;;; you may not use this file except in compliance with the License.
6;;; You may obtain a copy of the License at
[13067]7;;;
[16688]8;;; http://www.apache.org/licenses/LICENSE-2.0
[13067]9;;;
[16688]10;;; Unless required by applicable law or agreed to in writing, software
11;;; distributed under the License is distributed on an "AS IS" BASIS,
12;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13;;; See the License for the specific language governing permissions and
14;;; limitations under the License.
[13067]15
[7986]16(in-package "CCL")
17
18(eval-when (:compile-toplevel :execute)
19 (require "HASHENV" "ccl:xdump;hashenv"))
20
21;;; This should stay in LAP so that it's fast
22;;; Equivalent to cl:mod when both args are positive fixnums
23(defx8632lapfunction fast-mod ((number arg_y) (divisor arg_z))
[10815]24 (xorl (% edx) (% edx)) ;aka temp1
25 (mov (% number) (% imm0))
26 (div (% divisor)) ;boxed remainder goes into edx/temp1
27 (mov (% edx) (% arg_z))
[7986]28 (single-value-return))
29
[10265]30;; Faster mod based on Bruce Hoult's Dylan version, modified to use a
31;; branch-free max.
32(defx8632lapfunction fast-mod-3 ((number 4) #|(ra 0)|# (divisor arg_y) (recip arg_z))
[13447]33 (mark-as-imm temp1)
[10265]34 (let ((imm1 temp1)
35 (n temp0))
36 (movl (@ number (% esp)) (% n))
37 (movl (% n) (% imm0))
[10272]38 (shrl ($ target::fixnumshift) (% imm0)) ;logical shift is intentional
[10265]39 (mov (% recip) (% imm1))
40 (mul (% imm1)) ;; -> hi word in imm1 (unboxed)
41 (mov (% divisor) (% imm0))
42 (mul (% imm1)) ;; -> lo word in imm0 (boxed)
43 (subl (% imm0) (% n))
44 (subl (% divisor) (% n))
45 (mov (% n) (% arg_z))
46 (mov (% n) (% imm0))
47 (sar ($ (1- target::nbits-in-word)) (% imm0))
48 (andl (% imm0) (% divisor))
49 (addl (% divisor) (% arg_z)))
[13447]50 (mark-as-node temp1)
[10265]51 (single-value-return 3))
52
[7986]53(defx8632lapfunction %dfloat-hash ((key arg_z))
54 (movl (@ x8632::double-float.value (% key)) (% imm0))
55 (addl (@ x8632::double-float.val-high (% key)) (% imm0))
56 (box-fixnum imm0 arg_z)
57 (single-value-return))
58
59(defx8632lapfunction %sfloat-hash ((key arg_z))
60 (movl (@ x8632::single-float.value (% key)) (% imm0))
61 (box-fixnum imm0 arg_z)
62 (single-value-return))
63
64(defx8632lapfunction %macptr-hash ((key arg_z))
65 (movl (@ x8632::macptr.address (% key)) (% imm0))
66 (box-fixnum imm0 temp0)
67 (shll ($ (- 24 x8632::fixnumshift)) (% temp0))
68 (addl (% temp0) (% imm0))
69 (movl ($ (lognot x8632::fixnummask)) (% arg_z))
70 (andl (% imm0) (% arg_z))
71 (single-value-return))
72
73(defx8632lapfunction %bignum-hash ((key arg_z))
74 (mark-as-imm temp1)
75 (let ((header imm0)
76 (offset temp1)
77 (ndigits temp0))
78 (getvheader key header)
79 (header-length header ndigits)
80 (xorl (% offset) (% offset))
81 (let ((immhash header))
82 @loop
83 (roll ($ 13) (% immhash))
84 (addl (@ x8632::misc-data-offset (% key) (% offset)) (% immhash))
85 (addl ($ 4) (% offset))
86 (subl ($ '1) (% ndigits))
87 (jne @loop)
88 (box-fixnum immhash arg_z)))
89 (mark-as-node temp1)
90 (single-value-return))
91
92(defx8632lapfunction %get-fwdnum ()
93 (ref-global target::fwdnum arg_z)
94 (single-value-return))
95
96(defx8632lapfunction %get-gc-count ()
97 (ref-global target::gc-count arg_z)
98 (single-value-return))
99
100;;; Setting a key in a hash-table vector needs to
101;;; ensure that the vector header gets memoized as well
102(defx8632lapfunction %set-hash-table-vector-key ((vector 4) #|(ra 0)|# (index arg_y) (value arg_z))
103 (pop (% temp1)) ;return address
104 (pop (% temp0)) ;.SPset-hash-key wants arg in temp0
105 (discard-reserved-frame)
106 (push (% temp1))
107 (jmp-subprim .SPset-hash-key))
108
[10731]109;;; This needs to be done out-of-line, to handle EGC memoization.
110(defx8632lapfunction %set-hash-table-vector-key-conditional ((offset 8)
111 (vector 4)
112 #|(ra 0)|#
113 (old arg_y)
114 (new arg_z))
115 (movl (@ offset (% esp)) (% temp0))
116 (movl (@ vector (% esp)) (% temp1))
117 (save-simple-frame)
118 (call-subprim .SPset-hash-key-conditional)
119 (restore-simple-frame)
120 (single-value-return 4))
121
122
[7986]123;;; Strip the tag bits to turn x into a fixnum
124(defx8632lapfunction strip-tag-to-fixnum ((x arg_z))
[15775]125 (testb ($ target::fixnummask) (%b x))
126 (jz @done)
[15521]127 (andl ($ (lognot target::fulltagmask)) (% x))
128 (shrl ($ (- target::ntagbits target::fixnumshift)) (% arg_z))
[15775]129 @done
[7986]130 (single-value-return))
131
Note: See TracBrowser for help on using the repository browser.