-
Notifications
You must be signed in to change notification settings - Fork 71
/
Spur64BitMMLESimulatorFor64Bits.class.st
99 lines (90 loc) · 3.39 KB
/
Spur64BitMMLESimulatorFor64Bits.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
Class {
#name : #Spur64BitMMLESimulatorFor64Bits,
#superclass : #Spur64BitMMLESimulator,
#category : #'VMMaker-SpurMemoryManagerSimulation'
}
{ #category : #'memory access' }
Spur64BitMMLESimulatorFor64Bits >> byteAt: byteAddress [
| lowBits long64 |
lowBits := byteAddress bitAnd: 7.
long64 := self long64At: byteAddress - lowBits.
^(long64 bitShift: -8 * lowBits) bitAnd: 16rFF
]
{ #category : #'memory access' }
Spur64BitMMLESimulatorFor64Bits >> byteAt: byteAddress put: byte [
| lowBits long64 longAddress mask value |
lowBits := byteAddress bitAnd: 7.
longAddress := byteAddress - lowBits.
long64 := self long64At: longAddress.
mask := (16rFF bitShift: 8 * lowBits) bitInvert.
value := byte bitShift: 8 * lowBits.
self long64At: longAddress put: ((long64 bitAnd: mask) bitOr: value).
^byte
]
{ #category : #'memory access' }
Spur64BitMMLESimulatorFor64Bits >> long32At: byteAddress [
"Answer the 32-bit word at byteAddress which must be a multiple of four."
| lowBits long |
lowBits := byteAddress bitAnd: 4.
long := self long64At: byteAddress - lowBits.
^lowBits = 4
ifTrue: [long bitShift: -32]
ifFalse: [long bitAnd: 16rFFFFFFFF]
]
{ #category : #'memory access' }
Spur64BitMMLESimulatorFor64Bits >> long32At: byteAddress put: a32BitValue [
"Store the 32-bit word at byteAddress which must be a multiple of four."
| lowBits long longAddress |
a32BitValue < 0 ifTrue:
[self long32At: byteAddress put: (a32BitValue bitAnd: 16rFFFFFFFF).
^a32BitValue].
lowBits := byteAddress bitAnd: 4.
lowBits = 0
ifTrue: "storing into LS word"
[long := self long64At: byteAddress.
self long64At: byteAddress
put: ((long bitAnd: 16rFFFFFFFF00000000) bitOr: a32BitValue)]
ifFalse: "storing into MS word"
[longAddress := byteAddress - 4.
long := self long64At: longAddress.
self long64At: longAddress
put: ((long bitAnd: 16rFFFFFFFF) bitOr: (a32BitValue bitShift: 32))].
^a32BitValue
]
{ #category : #'memory access' }
Spur64BitMMLESimulatorFor64Bits >> long64At: byteAddress [
"memory is a DoubleWordArray, a 64-bit indexable array of bits"
byteAddress \\ 8 ~= 0 ifTrue: [self unalignedAccessError].
^memory at: byteAddress // 8 + 1
]
{ #category : #'memory access' }
Spur64BitMMLESimulatorFor64Bits >> long64At: byteAddress put: a64BitValue [
"memory is a DoubleWordArray, a 64-bit indexable array of bits"
byteAddress \\ 8 ~= 0 ifTrue: [self unalignedAccessError].
^memory at: byteAddress // 8 + 1 put: a64BitValue
]
{ #category : #simulation }
Spur64BitMMLESimulatorFor64Bits >> memoryClass [
"Answer the class to use for the memory inst var in simulation.
Answer nil if a suitable class isn't available. This version uses a 64-bit element class if available."
<doNotGenerate>
^Smalltalk classNamed: #DoubleWordArray
]
{ #category : #'memory access' }
Spur64BitMMLESimulatorFor64Bits >> shortAt: byteAddress [
| lowBits long64 |
lowBits := byteAddress bitAnd: 6.
long64 := self long64At: byteAddress - lowBits.
^(long64 bitShift: -8 * lowBits) bitAnd: 16rFFFF
]
{ #category : #'memory access' }
Spur64BitMMLESimulatorFor64Bits >> shortAt: byteAddress put: short [
| lowBits long64 longAddress mask value |
lowBits := byteAddress bitAnd: 6.
longAddress := byteAddress - lowBits.
long64 := self long64At: longAddress.
mask := (16rFFFF bitShift: 8 * lowBits) bitInvert.
value := short bitShift: 8 * lowBits.
self long64At: longAddress put: ((long64 bitAnd: mask) bitOr: value).
^short
]