-
Notifications
You must be signed in to change notification settings - Fork 65
/
VMJitSimdBytecode.class.st
258 lines (187 loc) · 9.08 KB
/
VMJitSimdBytecode.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
Class {
#name : #VMJitSimdBytecode,
#superclass : #VMStackToRegisterMappingCogitTest,
#category : #'VMMakerTests-JitTests'
}
{ #category : #tests }
VMJitSimdBytecode class >> wordSizeParameters [
^ self wordSize64Parameters
]
{ #category : #running }
VMJitSimdBytecode >> jitOptions [
^ super jitOptions
at: #bytecodeTableInitializer put: #initializeBytecodeTableForSistaV1;
yourself
]
{ #category : #tests }
VMJitSimdBytecode >> testAddVector32CopiesArraySumIntoVectorRegister [
| endInstruction primitiveAddress array register |
arguments := { memory integerObjectOf: 0. array := self new32BitIndexableOfSize: 8. memory integerObjectOf: 4 }.
memory storeFloat32: 0 ofObject: array withValue: 1.0.
memory storeFloat32: 1 ofObject: array withValue: 2.0.
memory storeFloat32: 2 ofObject: array withValue: 3.0.
memory storeFloat32: 3 ofObject: array withValue: 4.0.
memory storeFloat32: 4 ofObject: array withValue: 5.0.
memory storeFloat32: 5 ofObject: array withValue: 6.0.
memory storeFloat32: 6 ofObject: array withValue: 7.0.
memory storeFloat32: 7 ofObject: array withValue: 8.0.
sentSelector := #+.
self buildStackFrame.
primitiveAddress := self compile: [
cogit genPushTemporaryVariable: 0.
cogit genPushTemporaryVariable: 1.
cogit genPushFloat32ArrayToRegister.
cogit genPushTemporaryVariable: 2.
cogit genPushTemporaryVariable: 1.
cogit genPushFloat32ArrayToRegister.
cogit genAddFloat32Vector.
"If the primitive fails it continues, so we need to have an instruction to detect the end"
endInstruction := cogit Stop ].
self runFrom: primitiveAddress until: endInstruction address.
register := machineSimulator vectorRegister0Value.
self assert: (register floatAt: 1) equals: 6.0.
self assert: (register floatAt: 5) equals: 8.0.
self assert: (register floatAt: 9) equals: 10.0.
self assert: (register floatAt: 13) equals: 12.0.
]
{ #category : #tests }
VMJitSimdBytecode >> testAddVectorCopiesArraySumIntoVectorRegister [
| endInstruction primitiveAddress array register |
arguments := { memory integerObjectOf: 0. array := self new64BitIndexableOfSize: 4. memory integerObjectOf: 2 }.
memory storeFloat64: 0 ofObject: array withValue: 1.0.
memory storeFloat64: 1 ofObject: array withValue: 2.0.
memory storeFloat64: 2 ofObject: array withValue: 3.0.
memory storeFloat64: 3 ofObject: array withValue: 4.0.
sentSelector := #+.
self buildStackFrame.
primitiveAddress := self compile: [
cogit genPushTemporaryVariable: 0.
cogit genPushTemporaryVariable: 1.
cogit genPushFloat64ArrayToRegister.
cogit genPushTemporaryVariable: 2.
cogit genPushTemporaryVariable: 1.
cogit genPushFloat64ArrayToRegister.
cogit genAddFloat64Vector.
"If the primitive fails it continues, so we need to have an instruction to detect the end"
endInstruction := cogit Stop ].
self runFrom: primitiveAddress until: endInstruction address.
register := machineSimulator vectorRegister0Value.
self assert: (register doubleAt: 1) equals: 4.0.
self assert: (register doubleAt: 9) equals: 6.0.
]
{ #category : #tests }
VMJitSimdBytecode >> testAddVectorPushesArraySumIntoSimulatedStack [
| endInstruction primitiveAddress array entry |
arguments := { memory integerObjectOf: 0. array := self new64BitIndexableOfSize: 4. memory integerObjectOf: 2 }.
memory storeFloat64: 0 ofObject: array withValue: 1.0.
memory storeFloat64: 1 ofObject: array withValue: 2.0.
memory storeFloat64: 2 ofObject: array withValue: 3.0.
memory storeFloat64: 3 ofObject: array withValue: 4.0.
sentSelector := #+.
self buildStackFrame.
primitiveAddress := self compile: [
cogit genPushTemporaryVariable: 0.
cogit genPushTemporaryVariable: 1.
cogit genPushFloat64ArrayToRegister.
cogit genPushTemporaryVariable: 2.
cogit genPushTemporaryVariable: 1.
cogit genPushFloat64ArrayToRegister.
cogit genAddFloat64Vector.
"If the primitive fails it continues, so we need to have an instruction to detect the end"
endInstruction := cogit Stop ].
self runFrom: primitiveAddress until: endInstruction address.
entry := cogit ssTop.
"The register with the result is the same as the first one"
self assert: (entry type) equals: SSVectorRegister.
self assert: (entry registerr) equals: 0.
]
{ #category : #tests }
VMJitSimdBytecode >> testPushArrayToRegisterCopiesArrayChunkIntoVectorRegister [
| endInstruction primitiveAddress array register |
arguments := { memory integerObjectOf: 2. array := self new64BitIndexableOfSize: 4 }.
memory storeFloat64: 0 ofObject: array withValue: 1.0.
memory storeFloat64: 1 ofObject: array withValue: 2.0.
memory storeFloat64: 2 ofObject: array withValue: 3.0.
memory storeFloat64: 3 ofObject: array withValue: 4.0.
sentSelector := #+.
self buildStackFrame.
primitiveAddress := self compile: [
cogit genPushTemporaryVariable: 0.
cogit genPushTemporaryVariable: 1.
cogit genPushFloat64ArrayToRegister.
"If the primitive fails it continues, so we need to have an instruction to detect the end"
endInstruction := cogit Stop ].
self runFrom: primitiveAddress until: endInstruction address.
register := machineSimulator vectorRegister0Value.
self assert: (register doubleAt: 1) equals: 3.0.
self assert: (register doubleAt: 9) equals: 4.0.
]
{ #category : #tests }
VMJitSimdBytecode >> testPushArrayToRegisterPushesArrayChunkIntoSimulatedStack [
| endInstruction primitiveAddress array entry |
arguments := { memory integerObjectOf: 2. array := self new64BitIndexableOfSize: 4 }.
memory storeFloat64: 0 ofObject: array withValue: 1.0.
memory storeFloat64: 1 ofObject: array withValue: 2.0.
memory storeFloat64: 2 ofObject: array withValue: 3.0.
memory storeFloat64: 3 ofObject: array withValue: 4.0.
sentSelector := #+.
self buildStackFrame.
primitiveAddress := self compile: [
cogit genPushTemporaryVariable: 0.
cogit genPushTemporaryVariable: 1.
cogit genPushFloat64ArrayToRegister.
"If the primitive fails it continues, so we need to have an instruction to detect the end"
endInstruction := cogit Stop ].
self runFrom: primitiveAddress until: endInstruction address.
entry := cogit ssTop.
self assert: (entry type) equals: SSVectorRegister.
self assert: (entry registerr) equals: 0.
]
{ #category : #tests }
VMJitSimdBytecode >> testStoreRegisterIntoArrayReplacesArrayElementsWithRegisterContent [
| endInstruction primitiveAddress array |
arguments := { memory integerObjectOf: 2. array := self new64BitIndexableOfSize: 4. memory integerObjectOf: 0 }.
memory storeFloat64: 0 ofObject: array withValue: 1.0.
memory storeFloat64: 1 ofObject: array withValue: 2.0.
memory storeFloat64: 2 ofObject: array withValue: 3.0.
memory storeFloat64: 3 ofObject: array withValue: 4.0.
sentSelector := #+.
self buildStackFrame.
primitiveAddress := self compile: [
cogit genPushTemporaryVariable: 0.
cogit genPushTemporaryVariable: 1.
cogit genPushFloat64ArrayToRegister.
cogit genPushTemporaryVariable: 2.
cogit genPushTemporaryVariable: 1.
cogit genStoreFloat64RegisterIntoArray.
"If the primitive fails it continues, so we need to have an instruction to detect the end"
endInstruction := cogit Stop ].
self runFrom: primitiveAddress until: endInstruction address.
self assert: (memory fetchFloat64: 0 ofObject: array) equals: 3.0.
self assert: (memory fetchFloat64: 1 ofObject: array) equals: 4.0.
]
{ #category : #tests }
VMJitSimdBytecode >> testSubVectorStoreResultIntoVectorRegister [
| endInstruction primitiveAddress array register |
arguments := { memory integerObjectOf: 0. array := self new64BitIndexableOfSize: 4. memory integerObjectOf: 2 }.
memory storeFloat64: 0 ofObject: array withValue: 5.0.
memory storeFloat64: 1 ofObject: array withValue: 3.0.
memory storeFloat64: 2 ofObject: array withValue: 2.0.
memory storeFloat64: 3 ofObject: array withValue: 1.0.
sentSelector := #-."TODO is this necessary?"
self buildStackFrame.
primitiveAddress := self compile: [
cogit genPushTemporaryVariable: 0.
cogit genPushTemporaryVariable: 1.
cogit genPushFloat64ArrayToRegister.
cogit genPushTemporaryVariable: 2.
cogit genPushTemporaryVariable: 1.
cogit genPushFloat64ArrayToRegister.
cogit genSubFloat64Vector.
"If the primitive fails it continues, so we need to have an instruction to detect the end"
endInstruction := cogit Stop ].
self runFrom: primitiveAddress until: endInstruction address.
register := machineSimulator vectorRegister0Value.
self assert: (register doubleAt: 1) equals: 3.0.
self assert: (register doubleAt: 9) equals: 2.0.
]