-
Notifications
You must be signed in to change notification settings - Fork 65
/
VMDivisionInstructionTest.class.st
95 lines (64 loc) · 2.54 KB
/
VMDivisionInstructionTest.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
Class {
#name : #VMDivisionInstructionTest,
#superclass : #VMSimpleStackBasedCogitAbstractTest,
#pools : [
'CogAbstractRegisters',
'CogRTLOpcodes'
],
#category : #'VMMakerTests-JitTests'
}
{ #category : #'as yet unclassified' }
VMDivisionInstructionTest >> testDivide: numerator by: divisor quotient: quotient remainer: remainer [
| expectedQuotient expectedRemainer |
self compile: [
cogit MoveCq: numerator R: ReceiverResultReg.
cogit MoveCq: divisor R: ClassReg.
cogit backend
genDivR: ClassReg
R: ReceiverResultReg
Quo: ReceiverResultReg
Rem: ClassReg ].
self runGeneratedCode.
expectedQuotient := self twoComplementOf: quotient.
expectedRemainer := self twoComplementOf: remainer.
self assert: machineSimulator receiverRegisterValue equals: expectedQuotient.
self assert: machineSimulator classRegisterValue equals: expectedRemainer
]
{ #category : #tests }
VMDivisionInstructionTest >> testDivisionWithNegativeDividentWithRemainerReturnsCorrectQuotientAndRemainder [
self testDivide: -10 by: 7 quotient: -1 remainer: -3.
]
{ #category : #tests }
VMDivisionInstructionTest >> testDivisionWithNegativeDivisorAndDividentWithRemainerReturnsCorrectQuotientAndRemainder [
self testDivide: -10 by: -7 quotient: 1 remainer: -3.
]
{ #category : #tests }
VMDivisionInstructionTest >> testDivisionWithNegativeDivisorWithRemainerReturnsCorrectQuotientAndRemainder [
self testDivide: 10 by: -7 quotient: -1 remainer: 3.
]
{ #category : #tests }
VMDivisionInstructionTest >> testDivisionWithRemainerReturnsCorrectQuotientAndRemainder [
self testDivide: 10 by: 7 quotient: 1 remainer: 3.
]
{ #category : #tests }
VMDivisionInstructionTest >> testIntegerDivisionReturnsCorrectQuotientAndRemainder [
self testDivide: 10 by: 2 quotient: 5 remainer: 0.
]
{ #category : #tests }
VMDivisionInstructionTest >> testIntegerDivisionWithNegativeDivisorReturnsCorrectQuotientAndRemainder [
self testDivide: 10 by: -2 quotient: -5 remainer: 0.
]
{ #category : #tests }
VMDivisionInstructionTest >> testIntegerDivisionWithNegativeNumeratorAndDivisorReturnsCorrectQuotientAndRemainder [
self testDivide: -10 by: -2 quotient: 5 remainer: 0.
]
{ #category : #tests }
VMDivisionInstructionTest >> testIntegerDivisionWithNegativeNumeratorReturnsCorrectQuotientAndRemainder [
self testDivide: -10 by: 2 quotient: -5 remainer: 0.
]
{ #category : #'as yet unclassified' }
VMDivisionInstructionTest >> twoComplementOf: anInteger [
^ self wordSize = 8
ifTrue: [ anInteger twoComplementOfBitSize: 64 ]
ifFalse: [ anInteger twoComplementOfBitSize: 32 ]
]