Levente Uzonyi uploaded a new version of System to project The Trunk:
http://source.squeak.org/trunk/System-ul.720.mcz ==================== Summary ==================== Name: System-ul.720 Author: ul Time: 11 April 2015, 4:55:06.206 am UUID: 1aa19753-6581-491d-a289-4d29c9797997 Ancestors: System-mt.719 Added left and right shifts, multiplication, load from register, and comparision operators to ThirtyTwoBitRegister. Also implmenented #hash, and added #asSignedInteger. =============== Diff against System-mt.719 =============== Item was added: + ----- Method: ThirtyTwoBitRegister>>*= (in category 'accumulator ops') ----- + *= aThirtTwoBitRegister + "Replace my contents with the product of the given register and my current contents." + + | otherLow otherHi mul newLow newHi | + otherLow := aThirtTwoBitRegister low. + otherHi := aThirtTwoBitRegister hi. + "Multiply low with otherLow. Process the two highest bits of low separately if necessary to avoid LargeInteger operations." + (low bitShift: -8) * (otherLow bitShift: -8) > 16r3FFF + ifTrue: [ + mul := (low bitAnd: 16r3FFF) * otherLow. "Without the two most significant bits of low." + newLow := (mul bitAnd: 16rFFFF). + newHi := (mul bitShift: -16). + mul := (low bitShift: -14) * otherLow. "The two most significant bits of low" + newLow := newLow + ((mul bitAnd: 16r3) bitShift: 14). + newHi := newHi + (mul bitShift: -2) + (newLow bitShift: -16) "Carry from newLow" ] + ifFalse: [ + newLow := low * otherLow. "We'll trim newLow at the end of the method." + newHi := newLow bitShift: -16 ]. + "Multiply hi with otherLow." + (hi bitShift: -8) * (otherLow bitShift: -8) > 16r3FFF + ifTrue: [ + newHi := newHi + + ((hi bitAnd: 16r3FFF) * otherLow bitAnd: 16rFFFF) + + (((hi bitShift: -14) * otherLow bitAnd: 16r3) bitShift: 14) ] + ifFalse: [ newHi := newHi + (hi * otherLow bitAnd: 16rFFFF) ]. + "Multiply low with otherHi." + (low bitShift: -8) * (otherHi bitShift: -8) > 16r3FFF + ifTrue: [ + newHi := newHi + + ((low bitAnd: 16r3FFF) * otherHi bitAnd: 16rFFFF) + + (((low bitShift: -14) * otherHi bitAnd: 16r3) bitShift: 14) ] + ifFalse: [ newHi := newHi + (low * otherHi bitAnd: 16rFFFF) ]. + "Truncate and store the results." + hi := newHi bitAnd: 16rFFFF. + low := newLow bitAnd: 16rFFFF + ! Item was added: + ----- Method: ThirtyTwoBitRegister>>< (in category 'comparing') ----- + < aThirtyTwoBitRegister + + ^hi < aThirtyTwoBitRegister hi or: [ + hi = aThirtyTwoBitRegister hi and: [ + low < aThirtyTwoBitRegister low ] ]! Item was added: + ----- Method: ThirtyTwoBitRegister>><< (in category 'accumulator ops') ----- + << anInteger + "Unsigned left shift." + + | bitCount | + bitCount := anInteger. + bitCount >= 32 ifTrue: [ + hi := low := 0. + ^self ]. + bitCount >= 16 ifTrue: [ + hi := low. + low := 0. + bitCount := bitCount - 16 ]. + bitCount >= 15 ifTrue: [ + hi := ((hi bitAnd: 1) bitShift: 15) bitOr: (low bitShift: -1). + low := (low bitAnd: 1) bitShift: 15. + ^self ]. + bitCount >= 1 ifTrue: [ + hi := ((hi bitShift: bitCount) bitAnd: 16rFFFF) bitOr: (low bitShift: bitCount - 16). + low := (low bitShift: bitCount) bitAnd: 16rFFFF ]! Item was added: + ----- Method: ThirtyTwoBitRegister>><= (in category 'comparing') ----- + <= aThirtyTwoBitRegister + + ^hi < aThirtyTwoBitRegister hi or: [ + hi = aThirtyTwoBitRegister hi and: [ + low <= aThirtyTwoBitRegister low ] ]! Item was added: + ----- Method: ThirtyTwoBitRegister>>= (in category 'comparing') ----- + = anObject + + ^self class == anObject class + and: [ anObject low = low + and: [ anObject hi = hi ] ]! Item was added: + ----- Method: ThirtyTwoBitRegister>>> (in category 'comparing') ----- + > aThirtyTwoBitRegister + + ^hi > aThirtyTwoBitRegister hi or: [ + hi = aThirtyTwoBitRegister hi and: [ + low > aThirtyTwoBitRegister low ] ]! Item was added: + ----- Method: ThirtyTwoBitRegister>>>= (in category 'comparing') ----- + >= aThirtyTwoBitRegister + + ^hi > aThirtyTwoBitRegister hi or: [ + hi = aThirtyTwoBitRegister hi and: [ + low >= aThirtyTwoBitRegister low ] ]! Item was added: + ----- Method: ThirtyTwoBitRegister>>>> (in category 'accumulator ops') ----- + >> anInteger + "Unsigned right shift." + + | bitCount shift | + bitCount := anInteger. + bitCount >= 32 ifTrue: [ + hi := low := 0. + ^self ]. + bitCount >= 16 ifTrue: [ + low := hi. + hi := 0. + bitCount := bitCount - 16 ]. + bitCount >= 2 ifTrue: [ + shift := 0 - bitCount. + low := (low bitShift: shift) bitOr: ((hi bitShift: shift + 16) bitAnd: 16rFFFF). + hi := hi bitShift: shift. + ^self ]. + bitCount >= 1 ifTrue: [ + low := (low bitShift: -1) bitOr: ((hi bitAnd: 16r1) bitShift: 15). + hi := hi bitShift: -1 ]! Item was changed: + ----- Method: ThirtyTwoBitRegister>>asInteger (in category 'converting') ----- - ----- Method: ThirtyTwoBitRegister>>asInteger (in category 'accessing') ----- asInteger "Answer the integer value of my current contents." ^ (hi bitShift: 16) + low ! Item was added: + ----- Method: ThirtyTwoBitRegister>>asSignedInteger (in category 'converting') ----- + asSignedInteger + "Answer the signed integer value of my current contents." + + hi >= 16r8000 ifFalse: [ ^(hi bitShift: 16) + low ]. + ^-1 - (low bitXor: 16rFFFF) - ((hi bitXor: 16rFFFF) bitShift: 16) + + + ! Item was added: + ----- Method: ThirtyTwoBitRegister>>hash (in category 'comparing') ----- + hash + + ^((hi bitShift: 14) bitXor: low) hashMultiply! Item was added: + ----- Method: ThirtyTwoBitRegister>>loadFrom: (in category 'accessing') ----- + loadFrom: aThirtyTwoBitRegister + "Set my contents from the given ThirtyTwoBitRegister." + + hi := aThirtyTwoBitRegister hi. + low := aThirtyTwoBitRegister low + ! |
Free forum by Nabble | Edit this page |