-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removing duplicated code #857
base: pharo-12
Are you sure you want to change the base?
Removing duplicated code #857
Conversation
f7bcd58
to
daf4e3a
Compare
…ed hook methods to specialize in the subclasses (#defaultCallerSavedIP, #getCallerIPFromFP:callerFP:). Moved #genPushRegisterArgsForAbortMissNumArgs: to the new super class CogX86Compiler. Moved #changeClassOf:to: method to the super class and rewrote it in terms of the word size. Added a new test class VMPrimitiveChangeClassParametrizedTest
daf4e3a
to
2355086
Compare
Done in the Vm Dojo with @PalumboN @guillep @fouziray @iglosiggio @FedeLoch |
{ #category : 'interpreter access' } | ||
SpurMemoryManager >> paddingForFormatInstBytes: instBytes forElementBytes: elementSizeInBytes shiftForElement: shiftForElement [ | ||
|
||
"This method is doing the same as below but using bit arithmetic. | ||
shiftForElement SHOULD be log 2 of element size in bytes. We don't do the log2 because 1) is slow 2) it can return floats | ||
|
||
slotsPerWord := (wordSize / elementSize). | ||
trailingBytes := instBytes \\ wordSize. | ||
trailingSlots := trailingBytes / elementSize. | ||
^ slotsPerWord - trailingSlots. " | ||
|
||
^ self wordSize // elementSizeInBytes - (instBytes >> shiftForElement) bitAnd: self wordSize // elementSizeInBytes - 1 | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can do better:
{ #category : 'interpreter access' } | |
SpurMemoryManager >> paddingForFormatInstBytes: instBytes forElementBytes: elementSizeInBytes shiftForElement: shiftForElement [ | |
"This method is doing the same as below but using bit arithmetic. | |
shiftForElement SHOULD be log 2 of element size in bytes. We don't do the log2 because 1) is slow 2) it can return floats | |
slotsPerWord := (wordSize / elementSize). | |
trailingBytes := instBytes \\ wordSize. | |
trailingSlots := trailingBytes / elementSize. | |
^ slotsPerWord - trailingSlots. " | |
^ self wordSize // elementSizeInBytes - (instBytes >> shiftForElement) bitAnd: self wordSize // elementSizeInBytes - 1 | |
] | |
{ #category : 'interpreter access' } | |
SpurMemoryManager >> paddingForFormatInstBytes: instBytes shiftForElement: shiftForElement [ | |
"NOTE: shiftForElement is elementSizeInBytes log: 2. | |
This means elementSizeInBytes should be a power of two." | |
| trailingBytes paddingBytes | | |
"Cheap way to do instBytes \\ self wordSize (assumes self wordSize is a power of two)" | |
trailingBytes := instBytes bitAnd: self wordSize - 1. | |
paddingBytes := self wordSize - trailingBytes. | |
"self wordSize - 0 is self wordSize, but we want to say 'there is no padding' in that case" | |
paddingBytes := paddingBytes bitAnd: self wordSize - 1. | |
"Cheap way to do paddingBytes // elementSizeInBytes" | |
^ paddingBytes >> shiftForElement. | |
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: this change removes the elementBytes parameter :P
trailingSlots := trailingBytes / elementSize. | ||
^ slotsPerWord - trailingSlots. " | ||
|
||
^ self wordSize // elementSizeInBytes - (instBytes >> shiftForElement) bitAnd: self wordSize // elementSizeInBytes - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a bug here when self wordSize < elementSizeInBytes
(in those cases we never have padding).
The ugly fix is to add an if returning zero on that case.
Moved #moveFramesIn:through:toPage: method to the super class and added hook methods to specialize in the subclasses (#defaultCallerSavedIP, #getCallerIPFromFP:callerFP:).
Moved #genPushRegisterArgsForAbortMissNumArgs: to the new super class CogX86Compiler.
Moved #changeClassOf:to: method to the super class and rewrote it in terms of the word size.
Added a new test class VMPrimitiveChangeClassParametrizedTest