..
[sb-simd.git] / cpuid-vop.lisp
blob2f79c70c98dc249fc47034243785d189d4c03e9e
1 (in-package :sb-c)
2 (ignore-errors (defknown cl-user::%read-cpu (unsigned-byte-32 simple-array-unsigned-byte-16) nil))
4 (in-package :sb-vm)
6 (defmacro vect-ea (vect idx)
7 `(make-ea :dword :base ,vect :index ,idx
8 :disp (- (* vector-data-offset n-word-bytes) other-pointer-lowtag)))
10 (define-vop (%read-cpu/x86)
11 (:translate cl-user::%read-cpu)
12 (:policy :fast)
14 (:args (n :scs (unsigned-reg) :target eax)
15 (result :scs (descriptor-reg)))
16 (:arg-types unsigned-byte-32 simple-array-unsigned-byte-16)
18 (:temporary (:sc unsigned-reg :offset eax-offset :from (:argument 0)) eax)
19 (:temporary (:sc unsigned-reg :offset ebx-offset) ebx)
20 (:temporary (:sc unsigned-reg :offset ecx-offset) ecx)
21 (:temporary (:sc unsigned-reg :offset edx-offset) edx)
22 (:temporary (:sc unsigned-reg) index)
24 (:generator 10
26 (inst xor index index)
28 (inst mov eax n)
30 ;; zero regs
31 (inst xor ebx ebx)
32 (inst xor ecx ecx)
33 (inst xor edx edx)
35 ;; cpuid
36 (inst cpuid)
38 (inst push edx)
40 ;; EAX
41 (inst mov edx eax)
42 (inst shr edx 16)
43 (inst and edx #xFFFF)
44 (inst mov (vect-ea result index) edx)
45 (inst add index 2)
47 (inst mov edx eax)
48 (inst and edx #xFFFF)
49 (inst mov (vect-ea result index) edx)
50 (inst add index 2)
52 (inst pop edx)
54 ;; EBX
56 (inst mov eax ebx)
57 (inst shr eax 16)
58 (inst and eax #xFFFF)
59 (inst mov (vect-ea result index) eax)
60 (inst add index 2)
62 (inst mov eax ebx)
63 (inst and eax #xFFFF)
64 (inst mov (vect-ea result index) eax)
65 (inst add index 2)
67 ;; ECX
69 (inst mov eax ecx)
70 (inst shr eax 16)
71 (inst and eax #xFFFF)
72 (inst mov (vect-ea result index) eax)
73 (inst add index 2)
75 (inst mov eax ecx)
76 (inst and eax #xFFFF)
77 (inst mov (vect-ea result index) eax)
78 (inst add index 2)
80 ;; EDX
81 (inst mov eax edx)
82 (inst shr eax 16)
83 (inst and eax #xFFFF)
84 (inst mov (vect-ea result index) eax)
85 (inst add index 2)
87 (inst mov eax edx)
88 (inst and eax #xFFFF)
89 (inst mov (vect-ea result index) eax)
90 (inst add index 2)