-
Notifications
You must be signed in to change notification settings - Fork 69
/
CogObjectRepresentation.class.st
1872 lines (1656 loc) · 63.7 KB
/
CogObjectRepresentation.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"
I am an abstract superclass for object representations whose job it is to generate abstract instructions for accessing objects. It is hoped that this level of indirection between the Cogit code generator and object access makes it easier to adapt the code generator to different garbage collectors, object representations and languages.
"
Class {
#name : #CogObjectRepresentation,
#superclass : #CogClass,
#instVars : [
'cogit',
'methodZone',
'objectMemory',
'coInterpreter',
'ceStoreCheckTrampoline',
'ceByteSizeOfTrampoline',
'ceInstantiateClassTrampoline',
'ceInstantiateClassIndexableSizeTrampoline',
'ceFloatObjectOfTrampoline',
'ceFloatValueOfTrampoline',
'ceSigned64BitIntegerTrampoline',
'ceSigned64BitValueOfTrampoline',
'cePositive64BitIntegerTrampoline',
'cePositive64BitValueOfTrampoline'
],
#pools : [
'CogAbstractRegisters',
'CogCompilationConstants',
'CogMethodConstants',
'CogRTLOpcodes',
'VMBasicConstants',
'VMClassIndices',
'VMObjectIndices',
'VMStackFrameOffsets'
],
#category : #'VMMaker-JIT'
}
{ #category : #'instance creation' }
CogObjectRepresentation class >> forCogit: aCogit methodZone: methodZone [
^self new setCogit: aCogit methodZone: methodZone
]
{ #category : #translation }
CogObjectRepresentation class >> implicitReturnTypeFor: aSelector [
"Answer the return type for methods that don't have an explicit return."
^#void
]
{ #category : #initialization }
CogObjectRepresentation class >> initializeMiscConstants [
"Override to avoid inheriting (and hence repeating) VMClass class>>initializeMiscConstants.
Subclasses that have misc constants to initialize will override further."
]
{ #category : #accessing }
CogObjectRepresentation class >> numTrampolines [
^1 "ceStoreCheckTrampoline"
]
{ #category : #translation }
CogObjectRepresentation class >> typeForSelf [
^#implicit
]
{ #category : #accessing }
CogObjectRepresentation class >> wordSize [
^4
]
{ #category : #'garbage collection' }
CogObjectRepresentation >> allYoungObjectsAgeInFullGC [
^self subclassResponsibility
]
{ #category : #'sista support' }
CogObjectRepresentation >> allocateCounters: nCounters [
self subclassResponsibility
]
{ #category : #testing }
CogObjectRepresentation >> canPinObjects [
"Answer if the memory manager supports pinned objects."
^false
]
{ #category : #accessing }
CogObjectRepresentation >> ceStoreCheckTrampoline: anAddress [
<doNotGenerate>
ceStoreCheckTrampoline := anAddress
]
{ #category : #'garbage collection' }
CogObjectRepresentation >> checkValidObjectReference: anOop [
^(objectMemory isImmediate: anOop) not
and: [(objectMemory heapMapAtWord: (self pointerForOop: anOop)) ~= 0]
]
{ #category : #'in-line cacheing' }
CogObjectRepresentation >> classForInlineCacheTag: classIndex [
^self subclassResponsibility
]
{ #category : #'bytecode generator support' }
CogObjectRepresentation >> createsArraysInline [
"Answer if the object representation allocates arrays inline. By
default answer false. Better code can be generated when creating
arrays inline if values are /not/ flushed to the stack."
^false
]
{ #category : #'bytecode generator support' }
CogObjectRepresentation >> createsClosuresInline [
"Answer if the object representation allocates closures inline. By
default answer false. Better code can be generated when creating
closures inline if copied values are /not/ flushed to the stack."
^false
]
{ #category : #compilation }
CogObjectRepresentation >> ensureNoForwardedLiteralsIn: aMethodObj [
"Ensure there are no forwarded literals in the argument.
By default this is a noop. Subclasses redefine as necessary."
<inline: true>
]
{ #category : #'sista support' }
CogObjectRepresentation >> freeCounters: theCounters [
<var: #theCounters type: #usqInt>
self subclassResponsibility
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genClearAndSetSmallIntegerTagsIn: scratchReg [
"Set the SmallInteger tag bits when the tag bits may be filled with garbage."
self subclassResponsibility
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genCmpClassFloatCompactIndexR: reg [
^cogit CmpCq: ClassFloatCompactIndex R: reg
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genCmpClassMethodContextCompactIndexR: reg [
^cogit CmpCq: ClassMethodContextCompactIndex R: reg
]
{ #category : #'sista support' }
CogObjectRepresentation >> genConvertSmallFloatToSmallFloatHashAsIntegerInReg: reg scratch: scratch [
^EncounteredUnknownBytecode
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genConvertSmallIntegerToIntegerInReg: aRegister [
self subclassResponsibility
]
{ #category : #'bytecode generator support' }
CogObjectRepresentation >> genCreateClosureAt: bcpc numArgs: numArgs numCopied: numCopied contextNumArgs: ctxtNumArgs large: isLargeCtxt inBlock: isInBlock [
"Create a closure with the given startpc, numArgs and numCopied
within a context with ctxtNumArgs, large if isLargeCtxt that is in a
block if isInBlock. If numCopied > 0 pop those values off the stack."
self subclassResponsibility
]
{ #category : #'bytecode generator support' }
CogObjectRepresentation >> genCreateFullClosure: compiledBlock numArgs: numArgs numCopied: numCopied ignoreContext: ignoreContext contextNumArgs: contextNumArgs large: contextIsLarge inBlock: contextIsBlock [
"Create a full closure"
self subclassResponsibility
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genDoubleArithmetic: arithmeticOperator preOpCheck: preOpCheckOrNil [
<option: #DPFPReg0>
<var: #preOpCheckOrNil declareC: 'AbstractInstruction *(*preOpCheckOrNil)(int rcvrReg, int argReg)'>
| jumpFailClass jumpFailAlloc jumpFailCheck jumpImmediate jumpNonInt doOp |
<var: #jumpFailClass type: #'AbstractInstruction *'>
<var: #jumpFailAlloc type: #'AbstractInstruction *'>
<var: #jumpImmediate type: #'AbstractInstruction *'>
<var: #jumpNonInt type: #'AbstractInstruction *'>
<var: #jumpFailCheck type: #'AbstractInstruction *'>
<var: #doOp type: #'AbstractInstruction *'>
cogit processorHasDoublePrecisionFloatingPointSupport ifFalse:
[^UnimplementedPrimitive].
cogit genLoadArgAtDepth: 0 into: Arg0Reg.
self genGetDoubleValueOf: ReceiverResultReg into: DPFPReg0.
cogit MoveR: Arg0Reg R: ClassReg.
jumpImmediate := self genJumpImmediate: Arg0Reg.
self genGetCompactClassIndexNonImmOf: Arg0Reg into: SendNumArgsReg.
self genCmpClassFloatCompactIndexR: SendNumArgsReg.
jumpFailClass := cogit JumpNonZero: 0.
self genGetDoubleValueOf: Arg0Reg into: DPFPReg1.
doOp := cogit Label.
preOpCheckOrNil ifNotNil:
[jumpFailCheck := cogit perform: preOpCheckOrNil with: DPFPReg0 with: DPFPReg1].
cogit gen: arithmeticOperator operand: DPFPReg1 operand: DPFPReg0.
jumpFailAlloc := self
genAllocFloatValue: DPFPReg0
into: SendNumArgsReg
scratchReg: ClassReg
scratchReg: TempReg.
cogit MoveR: SendNumArgsReg R: ReceiverResultReg.
cogit genPrimReturn.
jumpImmediate jmpTarget: cogit Label.
self maybeGenConvertIfSmallFloatIn: Arg0Reg scratchReg: TempReg into: DPFPReg1 andJumpTo: doOp.
self smallIntegerIsOnlyImmediateType ifFalse:
[jumpNonInt := self genJumpNotSmallInteger: Arg0Reg scratchReg: TempReg].
self genConvertSmallIntegerToIntegerInReg: ClassReg.
cogit ConvertR: ClassReg Rd: DPFPReg1.
cogit Jump: doOp.
jumpFailAlloc jmpTarget: (jumpFailClass jmpTarget: cogit Label).
self smallIntegerIsOnlyImmediateType ifFalse:
[jumpNonInt jmpTarget: jumpFailClass getJmpTarget].
preOpCheckOrNil ifNotNil:
[jumpFailCheck jmpTarget: jumpFailClass getJmpTarget].
^0
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genDoubleComparison: jumpOpcodeGenerator invert: invertComparison [
<option: #DPFPReg0>
<var: #jumpOpcodeGenerator declareC: 'AbstractInstruction * NoDbgRegParms (*jumpOpcodeGenerator)(void *)'>
| jumpFail jumpImmediate jumpNonInt jumpCond compare |
<var: #jumpImmediate type: #'AbstractInstruction *'>
<var: #jumpNonInt type: #'AbstractInstruction *'>
<var: #jumpCond type: #'AbstractInstruction *'>
<var: #compare type: #'AbstractInstruction *'>
<var: #jumpFail type: #'AbstractInstruction *'>
cogit processorHasDoublePrecisionFloatingPointSupport ifFalse:
[^UnimplementedPrimitive].
cogit genLoadArgAtDepth: 0 into: Arg0Reg.
self genGetDoubleValueOf: ReceiverResultReg into: DPFPReg0.
jumpImmediate := self genJumpImmediate: Arg0Reg.
self genGetCompactClassIndexNonImmOf: Arg0Reg into: SendNumArgsReg.
self genCmpClassFloatCompactIndexR: SendNumArgsReg.
jumpFail := cogit JumpNonZero: 0.
self genGetDoubleValueOf: Arg0Reg into: DPFPReg1.
invertComparison "May need to invert for NaNs"
ifTrue: [compare := cogit CmpRd: DPFPReg0 Rd: DPFPReg1]
ifFalse: [compare := cogit CmpRd: DPFPReg1 Rd: DPFPReg0].
jumpCond := cogit perform: jumpOpcodeGenerator with: 0. "FP jumps are a little weird"
cogit genMoveFalseR: ReceiverResultReg.
cogit genPrimReturn.
jumpCond jmpTarget: (cogit genMoveTrueR: ReceiverResultReg).
cogit genPrimReturn.
jumpImmediate jmpTarget: cogit Label.
self maybeGenConvertIfSmallFloatIn: Arg0Reg scratchReg: TempReg into: DPFPReg1 andJumpTo: compare.
self smallIntegerIsOnlyImmediateType ifFalse:
[jumpNonInt := self genJumpNotSmallInteger: Arg0Reg scratchReg: TempReg].
self genConvertSmallIntegerToIntegerInReg: Arg0Reg.
cogit ConvertR: Arg0Reg Rd: DPFPReg1.
cogit Jump: compare.
jumpFail jmpTarget: cogit Label.
self smallIntegerIsOnlyImmediateType ifFalse:
[jumpNonInt jmpTarget: jumpFail getJmpTarget].
^CompletePrimitive
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genEnsureObjInRegNotForwarded: reg scratchReg: scratch [
"Make sure that the object in reg is not forwarded. By default there is
nothing to do. Subclasses for memory managers that forward will override."
<inline: true>
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genEnsureOopInRegNotForwarded: reg scratchReg: scratch [
"Make sure that the oop in reg is not forwarded. By default there is
nothing to do. Subclasses for memory managers that forward will override."
<inline: true>
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genEnsureOopInRegNotForwarded: reg scratchReg: scratch ifForwarder: fwdJumpTarget ifNotForwarder: nonFwdJumpTargetOrZero [
"Make sure that the oop in reg is not forwarded. By default there is
nothing to do. Subclasses for memory managers that forward will override."
<inline: true>
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genEnsureOopInRegNotForwarded: reg scratchReg: scratch jumpBackTo: instruction [
"Make sure that the oop in reg is not forwarded. By default there is
nothing to do. Subclasses for memory managers that forward will override."
<var: #instruction type: #'AbstractInstruction *'>
<inline: true>
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genEnsureOopInRegNotForwarded: reg scratchReg: scratch updatingMw: offset r: baseReg [
"Make sure that the oop in reg is not forwarded, updating the field at offset from baseReg.
By default there is nothing to do. Subclasses for memory managers that forward will override."
<inline: true>
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genEnsureOopInRegNotForwarded: reg scratchReg: scratch updatingSlot: index in: objReg [
"Make sure that the oop in reg is not forwarded, updating the slot in objReg with the value."
<inline: true>
self flag: 'not safe unless there''s also a store check!!'.
self assert: false.
^self genEnsureOopInRegNotForwarded: reg
scratchReg: scratch
updatingMw: index * objectMemory wordSize + objectMemory baseHeaderSize
r: objReg
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genFastPrimFail [
<doNotGenerate>
^cogit genFastPrimFail
]
{ #category : #'bytecode generator support' }
CogObjectRepresentation >> genGetActiveContextNumArgs: numArgs large: isLargeContext inBlock: isInBlock [
"Get the active context into ReceiverResultReg, creating it if necessary."
self subclassResponsibility
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genGetFormatOf: srcReg into: destReg [
"Get the format field of the object in srcReg into destReg.
srcReg may equal destReg."
self subclassResponsibility
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genGetInlineCacheClassTagFrom: sourceReg into: destReg forEntry: forEntry [
"Extract the inline cache tag for the object in sourceReg into destReg. The inline cache tag
for a given object is the value loaded in inline caches to distinguish objects of different
classes. If forEntry is true answer the entry label at which control is to enter (cmEntryOffset).
If forEntry is false, control enters at the start."
<returnTypeC: #'AbstractInstruction *'>
self subclassResponsibility
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genGetMethodHeaderOf: methodReg into: headerReg scratch: scratchReg [
"Get the method header (first word) of a CompiledMethod into headerReg.
Deal with the method possibly being cogged."
| jumpNotCogged |
<var: #jumpNotCogged type: #'AbstractInstruction *'>
cogit MoveMw: objectMemory baseHeaderSize r: methodReg R: headerReg.
jumpNotCogged := self genJumpSmallInteger: headerReg scratchReg: scratchReg.
cogit MoveMw: (cogit offset: CogMethod of: #methodHeader) r: headerReg R: headerReg.
jumpNotCogged jmpTarget: cogit Label.
^0
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genGetNumSlotsOf: srcReg into: destReg [
"Get the size in word-sized slots of the object in srcReg into destReg.
srcReg may equal destReg."
self subclassResponsibility
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genJumpImmediate: aRegister [
"Generate a compare and branch to test if aRegister contains an immediate.
Answer the jump."
<returnTypeC: #'AbstractInstruction *'>
self subclassResponsibility
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genJumpIsSmallIntegerValue: aRegister scratch: scratchReg [
"Generate a test for aRegister containing an integer value in the SmallInteger range, and a jump if so, answering the jump."
<returnTypeC: #'AbstractInstruction *'>
self subclassResponsibility
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genJumpNotImmediate: aRegister [
"Generate a compare and branch to test if aRegister contains a non-immediate.
Answer the jump."
<returnTypeC: #'AbstractInstruction *'>
self subclassResponsibility
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genJumpNotSmallInteger: aRegister [
"Generate a compare and branch to test if aRegister contains other than a SmallInteger.
Answer the jump, or UnimplementedOperation if this cannot be done with a single register."
<returnTypeC: #'AbstractInstruction *'>
<inline: true>
^cogit cCoerceSimple: UnimplementedOperation to: #'AbstractInstruction *'
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genJumpNotSmallInteger: aRegister scratchReg: scratch [
"Generate a compare and branch to test if aRegister contains other than a SmallInteger.
Answer the jump. Use scratch if required. Subclasses will override if scratch is needed."
<inline: true>
^self genJumpNotSmallInteger: aRegister
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genJumpNotSmallIntegerInScratchReg: aRegister [
"Generate a test for aRegister containing an integer value outside the SmallInteger range, and a jump if so, answering the jump."
<returnTypeC: #'AbstractInstruction *'>
self subclassResponsibility
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genJumpNotSmallIntegerValue: aRegister scratch: scratchReg [
"Generate a test for aRegister containing an integer value outside the SmallInteger range, and a jump if so, answering the jump."
<returnTypeC: #'AbstractInstruction *'>
self subclassResponsibility
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genJumpNotSmallIntegersIn: aRegister and: bRegister scratch: scratchRegister [
"Generate a compare and branch to test if aRegister and bRegister contains other than SmallIntegers,
i.e. don't branch if both aRegister and bRegister contain SmallIntegers.
Answer the jump. Destroy scratchRegister if required."
<returnTypeC: #'AbstractInstruction *'>
<inline: true>
cogit
MoveR: aRegister R: scratchRegister;
AndR: bRegister R: scratchRegister.
^self genJumpNotSmallIntegerInScratchReg: scratchRegister
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genJumpSmallInteger: aRegister [
"Generate a compare and branch to test if aRegister contains a SmallInteger.
Answer the jump, or UnimplementedOperation if this cannot be done with
a single register."
<returnTypeC: #'AbstractInstruction *'>
<inline: true>
^cogit cCoerceSimple: UnimplementedOperation to: #'AbstractInstruction *'
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genJumpSmallInteger: aRegister scratchReg: scratch [
"Generate a compare and branch to test if aRegister contains a SmallInteger.
Answer the jump. Use scratch if required. Subclasses will override if scratch is needed."
<inline: true>
^self genJumpSmallInteger: aRegister
]
{ #category : #'compile abstract instructions' }
CogObjectRepresentation >> genLoadSlot: index sourceReg: sourceReg destReg: destReg [
cogit
MoveMw: index * objectMemory wordSize + objectMemory baseHeaderSize
r: sourceReg
R: destReg.
^0
]
{ #category : #'bytecode generator support' }
CogObjectRepresentation >> genNewArrayOfSize: size initialized: initialized [
"Generate a call to code that allocates a new Array of size.
The Array should be initialized with nils iff initialized is true.
The size arg is passed in SendNumArgsReg, the result
must come back in ReceiverResultReg."
self subclassResponsibility
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genNonImplementedPrimitive [
"Primitive generator used to mark primitives that have no machine code implementation
This works as a null pattern.
Then primitive generation will just compile a call to the interpreter-version of the primitive
"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveAdd [
| jumpNotSI jumpOvfl |
<var: #jumpNotSI type: #'AbstractInstruction *'>
<var: #jumpOvfl type: #'AbstractInstruction *'>
cogit mclassIsSmallInteger ifFalse:
[^UnimplementedPrimitive].
cogit genLoadArgAtDepth: 0 into: Arg0Reg.
cogit MoveR: Arg0Reg R: ClassReg.
jumpNotSI := self genJumpNotSmallInteger: Arg0Reg scratchReg: TempReg.
self genRemoveSmallIntegerTagsInScratchReg: ClassReg.
cogit AddR: ReceiverResultReg R: ClassReg.
jumpOvfl := cogit JumpOverflow: 0.
cogit MoveR: ClassReg R: ReceiverResultReg.
cogit genPrimReturn.
jumpOvfl jmpTarget: (jumpNotSI jmpTarget: cogit Label).
^CompletePrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveAsCharacter [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveAsFloat [
<option: #DPFPReg0>
| jumpFailAlloc |
<var: #jumpFailAlloc type: #'AbstractInstruction *'>
cogit mclassIsSmallInteger ifFalse:
[^UnimplementedPrimitive].
cogit processorHasDoublePrecisionFloatingPointSupport ifFalse:
[^UnimplementedPrimitive].
cogit MoveR: ReceiverResultReg R: TempReg.
self genConvertSmallIntegerToIntegerInReg: TempReg.
cogit ConvertR: TempReg Rd: DPFPReg0.
jumpFailAlloc := self
genAllocFloatValue: DPFPReg0
into: SendNumArgsReg
scratchReg: ClassReg
scratchReg: TempReg.
cogit MoveR: SendNumArgsReg R: ReceiverResultReg.
cogit genPrimReturn.
jumpFailAlloc jmpTarget: cogit Label.
"This primitive is not complete. If the eden is full, it will fail.
We need to handle that in the C primitive or in the image.
We decided to handle it in the C primitive. "
^ 0
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveAt [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveAtPut [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveBitAnd [
| jumpNotSI |
<var: #jumpNotSI type: #'AbstractInstruction *'>
cogit mclassIsSmallInteger ifFalse:
[^UnimplementedPrimitive].
cogit genLoadArgAtDepth: 0 into: Arg0Reg.
jumpNotSI := self genJumpNotSmallInteger: Arg0Reg scratchReg: TempReg.
"Whether the SmallInteger tags are zero or non-zero, anding them together will preserve them."
cogit AndR: Arg0Reg R: ReceiverResultReg.
cogit genPrimReturn.
jumpNotSI jmpTarget: cogit Label.
^CompletePrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveBitOr [
| jumpNotSI |
<var: #jumpNotSI type: #'AbstractInstruction *'>
cogit mclassIsSmallInteger ifFalse:
[^UnimplementedPrimitive].
cogit genLoadArgAtDepth: 0 into: Arg0Reg.
jumpNotSI := self genJumpNotSmallInteger: Arg0Reg scratchReg: TempReg.
"Whether the SmallInteger tags are zero or non-zero, oring them together will preserve them."
cogit OrR: Arg0Reg R: ReceiverResultReg.
cogit genPrimReturn.
jumpNotSI jmpTarget: cogit Label.
^CompletePrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveBitShift [
"rTemp := rArg0
rClass := tTemp
rTemp := rTemp & 1
jz nonInt
rClass >>= 1
cmp 0,rClass
jge neg
cmp 31,rClass // numSmallIntegerBits, jge for sign
jge tooBig
rTemp := rReceiver
rTemp <<= rClass
rTemp >>= rClass (arithmetic)
cmp rTemp,rReceiver
jnz ovfl
rReceiver := rReceiver - 1
rReceiver := rReceiver <<= rClass
rReceiver := rReceiver + 1
ret
neg:
rClass := 0 - rClass
cmp 31,rClass // numSmallIntegerBits
jge inRange
rClass := 31
inRange
rReceiver := rReceiver >>= rClass.
rReceiver := rReceiver | smallIntegerTags.
ret
ovfl
tooBig
nonInt:
fail"
| jumpNotSI jumpOvfl jumpNegative jumpTooBig jumpInRange |
<var: #jumpNotSI type: #'AbstractInstruction *'>
<var: #jumpOvfl type: #'AbstractInstruction *'>
<var: #jumpNegative type: #'AbstractInstruction *'>
<var: #jumpTooBig type: #'AbstractInstruction *'>
<var: #jumpInRange type: #'AbstractInstruction *'>
cogit mclassIsSmallInteger ifFalse:
[^UnimplementedPrimitive].
cogit genLoadArgAtDepth: 0 into: Arg0Reg.
cogit MoveR: Arg0Reg R: ClassReg.
jumpNotSI := self genJumpNotSmallInteger: Arg0Reg scratchReg: TempReg.
self genConvertSmallIntegerToIntegerInReg: ClassReg.
(cogit lastOpcode setsConditionCodesFor: JumpNegative) ifFalse:
[cogit CmpCq: 0 R: ClassReg]. "N.B. FLAGS := ClassReg - 0"
jumpNegative := cogit JumpNegative: 0.
cogit CmpCq: self numSmallIntegerBits R: ClassReg. "N.B. FLAGS := ClassReg - numSmallIntegerBits"
jumpTooBig := cogit JumpGreaterOrEqual: 0.
cogit MoveR: ReceiverResultReg R: TempReg.
cogit LogicalShiftLeftR: ClassReg R: TempReg.
cogit ArithmeticShiftRightR: ClassReg R: TempReg.
cogit CmpR: TempReg R: ReceiverResultReg. "N.B. FLAGS := RRReg - TempReg"
jumpOvfl := cogit JumpNonZero: 0.
self genRemoveSmallIntegerTagsInScratchReg: ReceiverResultReg.
cogit LogicalShiftLeftR: ClassReg R: ReceiverResultReg.
self genAddSmallIntegerTagsTo: ReceiverResultReg.
cogit genPrimReturn.
jumpNegative jmpTarget: (cogit NegateR: ClassReg).
cogit CmpCq: self numSmallIntegerBits R: ClassReg. "N.B. FLAGS := ClassReg - numSmallIntegerBits"
jumpInRange := cogit JumpLessOrEqual: 0.
cogit MoveCq: self numSmallIntegerBits R: ClassReg.
jumpInRange jmpTarget: (cogit ArithmeticShiftRightR: ClassReg R: ReceiverResultReg).
self genClearAndSetSmallIntegerTagsIn: ReceiverResultReg.
cogit genPrimReturn.
jumpNotSI jmpTarget: (jumpTooBig jmpTarget: (jumpOvfl jmpTarget: cogit Label)).
^CompletePrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveBitXor [
| jumpNotSI |
<var: #jumpNotSI type: #'AbstractInstruction *'>
cogit mclassIsSmallInteger ifFalse:
[^UnimplementedPrimitive].
cogit genLoadArgAtDepth: 0 into: Arg0Reg.
jumpNotSI := self genJumpNotSmallInteger: Arg0Reg scratchReg: TempReg.
"Clear one or the other tag so that xoring will preserve them."
self genRemoveSmallIntegerTagsInScratchReg: Arg0Reg.
cogit XorR: Arg0Reg R: ReceiverResultReg.
cogit genPrimReturn.
jumpNotSI jmpTarget: cogit Label.
^CompletePrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveClass [
| reg |
reg := ReceiverResultReg.
cogit methodNumArgs > 0 ifTrue:
[cogit methodNumArgs > 1 ifTrue:
[^UnimplementedPrimitive].
cogit genLoadArgAtDepth: 0 into: (reg := Arg0Reg)].
(self
genGetClassObjectOf: reg
into: ReceiverResultReg
scratchReg: TempReg
instRegIsReceiver: reg = ReceiverResultReg) = BadRegisterSet ifTrue:
[self
genGetClassObjectOf: reg
into: ClassReg
scratchReg: TempReg
instRegIsReceiver: reg = ReceiverResultReg.
cogit MoveR: ClassReg R: ReceiverResultReg].
cogit genPrimReturn.
^UnfailingPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveDiv [
| jumpNotSI jumpIsSI jumpZero jumpExact jumpSameSign convert |
<var: #convert type: #'AbstractInstruction *'>
<var: #jumpIsSI type: #'AbstractInstruction *'>
<var: #jumpZero type: #'AbstractInstruction *'>
<var: #jumpNotSI type: #'AbstractInstruction *'>
<var: #jumpExact type: #'AbstractInstruction *'>
<var: #jumpSameSign type: #'AbstractInstruction *'>
cogit processorHasDivQuoRemAndMClassIsSmallInteger ifFalse:
[^UnimplementedPrimitive].
cogit genLoadArgAtDepth: 0 into: Arg0Reg.
cogit MoveR: Arg0Reg R: ClassReg.
cogit MoveR: Arg0Reg R: Arg1Reg.
jumpNotSI := self genJumpNotSmallInteger: Arg0Reg scratchReg: TempReg.
"We must shift away the tags, not just subtract them, so that the
overflow case doesn't actually overflow the machine instruction."
self genConvertSmallIntegerToIntegerInReg: ClassReg.
(cogit lastOpcode setsConditionCodesFor: JumpZero) ifFalse:
[cogit CmpCq: 0 R: ClassReg].
jumpZero := cogit JumpZero: 0.
cogit MoveR: ReceiverResultReg R: TempReg.
self genConvertSmallIntegerToIntegerInReg: TempReg.
cogit DivR: ClassReg R: TempReg Quo: TempReg Rem: ClassReg.
"If remainder is zero we must check for overflow."
cogit CmpCq: 0 R: ClassReg.
jumpExact := cogit JumpZero: 0.
"If arg and remainder signs are different we must round down."
cogit XorR: ClassReg R: Arg1Reg.
(cogit lastOpcode setsConditionCodesFor: JumpZero) ifFalse:
[cogit CmpCq: 0 R: Arg1Reg].
jumpSameSign := cogit JumpGreaterOrEqual: 0.
cogit SubCq: 1 R: TempReg.
jumpSameSign jmpTarget: (convert := cogit Label).
self genConvertIntegerToSmallIntegerInReg: TempReg.
cogit MoveR: TempReg R: ReceiverResultReg.
cogit genPrimReturn.
"test for overflow; the only case is SmallInteger minVal // -1"
jumpExact jmpTarget: cogit Label.
jumpIsSI := self genJumpIsSmallIntegerValue: TempReg scratch: Arg1Reg.
jumpIsSI jmpTarget: convert.
jumpZero jmpTarget: (jumpNotSI jmpTarget: cogit Label).
^CompletePrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveDivide [
| jumpNotSI jumpZero jumpInexact jumpOverflow |
<var: #jumpNotSI type: #'AbstractInstruction *'>
<var: #jumpZero type: #'AbstractInstruction *'>
<var: #jumpInexact type: #'AbstractInstruction *'>
<var: #jumpOverflow type: #'AbstractInstruction *'>
cogit processorHasDivQuoRemAndMClassIsSmallInteger ifFalse:
[^UnimplementedPrimitive].
cogit genLoadArgAtDepth: 0 into: Arg0Reg.
cogit MoveR: Arg0Reg R: ClassReg.
jumpNotSI := self genJumpNotSmallInteger: Arg0Reg scratchReg: TempReg.
"We must shift away the tags, not just subtract them, so that the
overflow case doesn't actually overflow the machine instruction."
self genConvertSmallIntegerToIntegerInReg: ClassReg.
jumpZero := cogit JumpZero: 0.
cogit MoveR: ReceiverResultReg R: TempReg.
self genConvertSmallIntegerToIntegerInReg: TempReg.
cogit DivR: ClassReg R: TempReg Quo: TempReg Rem: ClassReg.
"If remainder is non-zero fail."
cogit CmpCq: 0 R: ClassReg.
jumpInexact := cogit JumpNonZero: 0.
"test for overflow; the only case is SmallInteger minVal / -1"
jumpOverflow := self genJumpNotSmallIntegerValue: TempReg scratch: Arg1Reg.
self genConvertIntegerToSmallIntegerInReg: TempReg.
cogit MoveR: TempReg R: ReceiverResultReg.
cogit genPrimReturn.
jumpOverflow jmpTarget: (jumpInexact jmpTarget: (jumpZero jmpTarget: (jumpNotSI jmpTarget: cogit Label))).
^CompletePrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveEqual [
^self
genSmallIntegerComparison: JumpZero
orDoubleComparison: #JumpFPEqual:
invert: false
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveFloatAdd [
<option: #DPFPReg0>
^self genDoubleArithmetic: AddRdRd preOpCheck: nil
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveFloatDivide [
<option: #DPFPReg0>
^self
genDoubleArithmetic: DivRdRd
preOpCheck: #genDoubleFailIfZeroArgRcvr:arg:
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveFloatEqual [
<option: #DPFPReg0>
^self genDoubleComparison: #JumpFPEqual: invert: false
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveFloatGreaterOrEqual [
<option: #DPFPReg0>
^self genDoubleComparison: #JumpFPGreaterOrEqual: invert: false
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveFloatGreaterThan [
<option: #DPFPReg0>
^self genDoubleComparison: #JumpFPGreater: invert: false
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveFloatLessOrEqual [
<option: #DPFPReg0>
^self genDoubleComparison: #JumpFPGreaterOrEqual: invert: true
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveFloatLessThan [
<option: #DPFPReg0>
^self genDoubleComparison: #JumpFPGreater: invert: true
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveFloatMultiply [
<option: #DPFPReg0>
^self genDoubleArithmetic: MulRdRd preOpCheck: nil
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveFloatNotEqual [
<option: #DPFPReg0>
^self genDoubleComparison: #JumpFPNotEqual: invert: false
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveFloatSquareRoot [
<option: #DPFPReg0>
| jumpFailAlloc |
<var: #jumpFailAlloc type: #'AbstractInstruction *'>
cogit processorHasDoublePrecisionFloatingPointSupport ifFalse:
[^UnimplementedPrimitive].
self genGetDoubleValueOf: ReceiverResultReg into: DPFPReg0.
cogit SqrtRd: DPFPReg0.
jumpFailAlloc := self
genAllocFloatValue: DPFPReg0
into: SendNumArgsReg
scratchReg: ClassReg
scratchReg: TempReg.
cogit MoveR: SendNumArgsReg R: ReceiverResultReg.
cogit genPrimReturn.
jumpFailAlloc jmpTarget: cogit Label.
^0
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveFloatSubtract [
<option: #DPFPReg0>
^self genDoubleArithmetic: SubRdRd preOpCheck: nil
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveFullClosureValue [
"Defer to the cogit for this one, to match the split for genPrimitiveClosureValue."
<doNotGenerate>
<option: #SistaV1BytecodeSet>
^cogit genPrimitiveFullClosureValue
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveGreaterOrEqual [
^self
genSmallIntegerComparison: JumpGreaterOrEqual
orDoubleComparison: #JumpFPGreaterOrEqual:
invert: false
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveGreaterThan [
^self
genSmallIntegerComparison: JumpGreater
orDoubleComparison: #JumpFPGreater:
invert: false
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveHashMultiply [
<doNotGenerate>
^cogit genPrimitiveHashMultiply
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveIdentical [
^self genPrimitiveIdenticalOrNotIf: false
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveImmediateAsInteger [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveIntegerAt [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveIntegerAtPut [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveLessOrEqual [
^self
genSmallIntegerComparison: JumpLessOrEqual
orDoubleComparison: #JumpFPGreaterOrEqual:
invert: true
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveLessThan [
^self
genSmallIntegerComparison: JumpLess
orDoubleComparison: #JumpFPGreater:
invert: true
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveLoadBoolean8FromBytes [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveLoadBoolean8FromExternalAddress [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveLoadChar16FromBytes [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveLoadChar16FromExternalAddress [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveLoadChar32FromBytes [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveLoadChar32FromExternalAddress [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveLoadChar8FromBytes [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveLoadChar8FromExternalAddress [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveLoadFloat32FromBytes [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveLoadFloat32FromExternalAddress [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveLoadFloat64FromBytes [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveLoadFloat64FromExternalAddress [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveLoadInt16FromBytes [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveLoadInt16FromExternalAddress [
"subclasses override if they can"
^UnimplementedPrimitive
]
{ #category : #'primitive generators' }
CogObjectRepresentation >> genPrimitiveLoadInt32FromBytes [
"subclasses override if they can"
^UnimplementedPrimitive
]