Skip to content
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

Open
wants to merge 1 commit into
base: pharo-12
Choose a base branch
from

Conversation

jordanmontt
Copy link
Member

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

…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
@jordanmontt
Copy link
Member Author

jordanmontt commented Oct 1, 2024

Done in the Vm Dojo with @PalumboN @guillep @fouziray @iglosiggio @FedeLoch

Comment on lines +10291 to +10303
{ #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
]
Copy link

@iglosiggio iglosiggio Oct 2, 2024

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:

Suggested change
{ #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.
]

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants