-
Notifications
You must be signed in to change notification settings - Fork 65
/
VMCogitHelpersTest.class.st
127 lines (96 loc) · 3.53 KB
/
VMCogitHelpersTest.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
Class {
#name : #VMCogitHelpersTest,
#superclass : #VMSimpleStackBasedCogitAbstractTest,
#instVars : [
'checkIsSmallInteger',
'checkNotSmallInteger'
],
#pools : [
'CogAbstractRegisters',
'CogRTLOpcodes'
],
#category : #'VMMakerTests-JitTests'
}
{ #category : #'as yet unclassified' }
VMCogitHelpersTest >> assertIsInSmallIntegerRange: anInteger [
machineSimulator classRegisterValue: anInteger.
self runUntilReturnFrom: checkIsSmallInteger.
self assert: machineSimulator classRegisterValue equals: 0
]
{ #category : #'as yet unclassified' }
VMCogitHelpersTest >> assertNotInSmallIntegerRange: anInteger [
machineSimulator classRegisterValue: anInteger.
self runUntilReturnFrom: checkNotSmallInteger.
self assert: machineSimulator classRegisterValue equals: 0
]
{ #category : #'as yet unclassified' }
VMCogitHelpersTest >> denyIsInSmallIntegerRange: anInteger [
machineSimulator classRegisterValue: anInteger.
self runUntilReturnFrom: checkIsSmallInteger.
self assert: machineSimulator classRegisterValue equals: 1
]
{ #category : #'as yet unclassified' }
VMCogitHelpersTest >> denyIsNotInSmallIntegerRange: anInteger [
machineSimulator classRegisterValue: anInteger.
self runUntilReturnFrom: checkNotSmallInteger.
self assert: machineSimulator classRegisterValue equals: 1
]
{ #category : #'as yet unclassified' }
VMCogitHelpersTest >> runUntilReturnFrom: anAddress [
self prepareCall.
super runUntilReturnFrom: anAddress
]
{ #category : #'as yet unclassified' }
VMCogitHelpersTest >> setUp [
super setUp.
"Compile a simple routine that checks if the Class register has a small integer or not.
Puts 0 in the class register if ok, puts 1 if not"
checkIsSmallInteger := self compile: [ | jump |
jump := cogit objectRepresentation genJumpIsSmallIntegerValue: ClassReg scratch: ReceiverResultReg.
"If not integer"
cogit MoveCq: 1 R: ClassReg.
cogit RetN: 0.
"if integer"
jump jmpTarget: cogit Label.
cogit MoveCq: 0 R: ClassReg.
cogit RetN: 0
].
"Compile a simple routine that checks if the Class register has not small integer.
Puts 0 in the class register if ok, puts 1 if not"
checkNotSmallInteger := self compile: [ | jump |
jump := cogit objectRepresentation genJumpNotSmallIntegerValue: ClassReg scratch: ReceiverResultReg.
"If not integer"
cogit MoveCq: 1 R: ClassReg.
cogit RetN: 0.
"if integer"
jump jmpTarget: cogit Label.
cogit MoveCq: 0 R: ClassReg.
cogit RetN: 0
].
]
{ #category : #'as yet unclassified' }
VMCogitHelpersTest >> testCheckNotSmallIntegerWithNonValidSmallIntegers [
self assertNotInSmallIntegerRange: memory maxSmallInteger + 1.
"In 32 bits check shifting only by one, in 64 bits by 1, 2 and 3"
1 to: memory numSmallIntegerTagBits do: [ :i |
self assertNotInSmallIntegerRange: memory maxSmallInteger << i.
]
]
{ #category : #'as yet unclassified' }
VMCogitHelpersTest >> testCheckNotSmallIntegerWithValidSmallIntegers [
self denyIsNotInSmallIntegerRange: 0.
self denyIsNotInSmallIntegerRange: memory maxSmallInteger.
]
{ #category : #'as yet unclassified' }
VMCogitHelpersTest >> testCheckSmallIntegerWithNonValidSmallIntegers [
self denyIsInSmallIntegerRange: memory maxSmallInteger + 1.
"In 32 bits check shifting only by one, in 64 bits by 1, 2 and 3"
1 to: memory numSmallIntegerTagBits do: [ :i |
self denyIsInSmallIntegerRange: memory maxSmallInteger << i.
]
]
{ #category : #'as yet unclassified' }
VMCogitHelpersTest >> testCheckSmallIntegerWithValidSmallIntegers [
self assertIsInSmallIntegerRange: 0.
self assertIsInSmallIntegerRange: memory maxSmallInteger
]