Code fixes for test-matrix.
[sb-simd.git] / cpuid-vop.lisp
blob41a20dd870b09f499f73beaa28717d0deda87a42
1 #|
2 Copyright (c) 2005 Risto Laakso
3 All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 (in-package :sb-c)
28 (ignore-errors (defknown cl-user::%read-cpu (unsigned-byte-32 simple-array-unsigned-byte-16) nil))
30 (in-package :sb-vm)
32 (defmacro vect-ea (vect idx)
33 `(make-ea :dword :base ,vect :index ,idx
34 :disp (- (* vector-data-offset n-word-bytes) other-pointer-lowtag)))
36 (define-vop (%read-cpu/x86)
37 (:translate cl-user::%read-cpu)
38 (:policy :fast)
40 (:args (n :scs (unsigned-reg) :target eax)
41 (result :scs (descriptor-reg)))
42 (:arg-types unsigned-byte-32 simple-array-unsigned-byte-16)
44 (:temporary (:sc unsigned-reg :offset eax-offset :from (:argument 0)) eax)
45 (:temporary (:sc unsigned-reg :offset ebx-offset) ebx)
46 (:temporary (:sc unsigned-reg :offset ecx-offset) ecx)
47 (:temporary (:sc unsigned-reg :offset edx-offset) edx)
48 (:temporary (:sc unsigned-reg) index)
50 (:generator 10
52 (inst xor index index)
54 (inst mov eax n)
56 ;; zero regs
57 (inst xor ebx ebx)
58 (inst xor ecx ecx)
59 (inst xor edx edx)
61 ;; cpuid
62 (inst cpuid)
64 (inst push edx)
66 ;; EAX
67 (inst mov edx eax)
68 (inst shr edx 16)
69 (inst and edx #xFFFF)
70 (inst mov (vect-ea result index) edx)
71 (inst add index 2)
73 (inst mov edx eax)
74 (inst and edx #xFFFF)
75 (inst mov (vect-ea result index) edx)
76 (inst add index 2)
78 (inst pop edx)
80 ;; EBX
82 (inst mov eax ebx)
83 (inst shr eax 16)
84 (inst and eax #xFFFF)
85 (inst mov (vect-ea result index) eax)
86 (inst add index 2)
88 (inst mov eax ebx)
89 (inst and eax #xFFFF)
90 (inst mov (vect-ea result index) eax)
91 (inst add index 2)
93 ;; ECX
95 (inst mov eax ecx)
96 (inst shr eax 16)
97 (inst and eax #xFFFF)
98 (inst mov (vect-ea result index) eax)
99 (inst add index 2)
101 (inst mov eax ecx)
102 (inst and eax #xFFFF)
103 (inst mov (vect-ea result index) eax)
104 (inst add index 2)
106 ;; EDX
107 (inst mov eax edx)
108 (inst shr eax 16)
109 (inst and eax #xFFFF)
110 (inst mov (vect-ea result index) eax)
111 (inst add index 2)
113 (inst mov eax edx)
114 (inst and eax #xFFFF)
115 (inst mov (vect-ea result index) eax)
116 (inst add index 2)