asm/AJBaseReg.st
changeset 3 483729eb4432
child 4 f2d0d2859193
equal deleted inserted replaced
2:88445baa732f 3:483729eb4432
       
     1 "{ Package: 'jv:dragonfly/asm' }"
       
     2 
       
     3 "{ NameSpace: Smalltalk }"
       
     4 
       
     5 AJOperand subclass:#AJBaseReg
       
     6 	instanceVariableNames:'size code name'
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'AsmJit-Operands'
       
    10 !
       
    11 
       
    12 AJBaseReg comment:'AJBaseReg  -- abstract superclass of all register operands.
       
    13 
       
    14 Instance Variables:
       
    15 	size	<Number>  Width in bytes (1, 2, 4, 8...)
       
    16 	code	<Integer>  Non-negative integer, encoding varies with subclass. For AJx86GPRegisters, ten bits: xyttttnnnn
       
    17 						where nnnn is the register number 0-15, tttt is the "type", which encodes size as a power of 2. 
       
    18 						Higher types are used in other subclasses.
       
    19 						If y is 1, REX prefix is required to encode this register.
       
    20 						If x is 1, this register cannot be used when any REX prefix is present in the instruction.
       
    21 	name	<Symbol>  Name by which this register may be referenced in instructions'
       
    22 !
       
    23 
       
    24 !AJBaseReg class methodsFor:'instance creation'!
       
    25 
       
    26 code: aRegisterCode name: aSymbol
       
    27     ^ self basicNew initializeWithCode: aRegisterCode name: aSymbol
       
    28 ! !
       
    29 
       
    30 !AJBaseReg methodsFor:'accessing'!
       
    31 
       
    32 annotation: anObject
       
    33     "registers gereally are used as single instances, hence putting
       
    34     an annotation on the default register will change the annotation
       
    35     for all the users. To avoid that, the receiver is copied first"
       
    36     ^ self copy
       
    37         basicAnnotation: anObject;
       
    38         yourself
       
    39 !
       
    40 
       
    41 code
       
    42     "Answer the value of code"
       
    43 
       
    44     ^ code
       
    45 !
       
    46 
       
    47 code: anObject
       
    48     "Set the value of code"
       
    49 
       
    50     code := anObject
       
    51 !
       
    52 
       
    53 description
       
    54     ^ String streamContents: [ :s | self descriptionOn: s ].
       
    55 !
       
    56 
       
    57 index
       
    58     ^ code bitAnd: RegCodeMask
       
    59 !
       
    60 
       
    61 influencingRegisters
       
    62     ^ #()
       
    63 !
       
    64 
       
    65 name
       
    66     ^ name
       
    67 !
       
    68 
       
    69 size
       
    70     ^ size
       
    71 !
       
    72 
       
    73 type
       
    74     ^ code bitAnd: RegTypeMask
       
    75 ! !
       
    76 
       
    77 !AJBaseReg methodsFor:'comparing'!
       
    78 
       
    79 = otherReg
       
    80 
       
    81     ^ (self class == otherReg class) and: [ code = otherReg code ]
       
    82 !
       
    83 
       
    84 hash
       
    85     ^ code hash
       
    86 ! !
       
    87 
       
    88 !AJBaseReg methodsFor:'initialize-release'!
       
    89 
       
    90 initializeWithCode: aRegisterCode name: aSymbol
       
    91     super initialize.
       
    92     self code: aRegisterCode.	"Also sets size"
       
    93     name := aSymbol
       
    94 ! !
       
    95 
       
    96 !AJBaseReg methodsFor:'printing'!
       
    97 
       
    98 descriptionOn: aStream
       
    99     self subclassResponsibility
       
   100 ! !
       
   101 
       
   102 !AJBaseReg methodsFor:'private'!
       
   103 
       
   104 basicAnnotation: anObject
       
   105     "private setter"
       
   106     annotation := anObject
       
   107 ! !
       
   108 
       
   109 !AJBaseReg methodsFor:'testing'!
       
   110 
       
   111 isGeneralPurpose
       
   112     self subclassResponsibility 
       
   113 !
       
   114 
       
   115 isUpperBank
       
   116     "Used for emitting the REX Prefix Byte on 64bit machines"
       
   117     ^ self index > 7
       
   118 !
       
   119 
       
   120 isX86
       
   121     self subclassResponsibility
       
   122 !
       
   123 
       
   124 prohibitsRex
       
   125     "Answer true if this register cannot be used in any instruction that has a REX prefix.
       
   126     Of the general-purpose registers, this is true only of SPL, BPL, SIL, DIL."
       
   127 
       
   128     ^ (code & RegProhibitsRexMask) ~~ 0
       
   129 !
       
   130 
       
   131 requiresRex 
       
   132     "Answer true if use of this register requires that the instruction have a REX prefix.
       
   133     This can be because the register cannot be accessed except with REX (high bank or 64-only low byte)
       
   134     or because the register is 64-bits wide"
       
   135     
       
   136     ^(code & RegRequiresRexMask) ~~ 0
       
   137 ! !
       
   138