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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specialize primitive at #647

Open
wants to merge 4 commits into
base: pharo-12
Choose a base branch
from
Open

Specialize primitive at #647

wants to merge 4 commits into from

Conversation

PalumboN
Copy link
Collaborator

Made in a dojo with many people :)

Adding two specialised versions of primitiveAt.

  • primitiveAtByteArray for bytearrays
  • primitiveAtPointerArray for normal arrays
  • Includes jitted version built by Druid 馃槑

This PR is related to #638, but needs more work (I left some comments).
We should merge both together.

@PalumboN PalumboN added the dojo Things developed on VM Dojos label Jul 12, 2023
Copy link
Member

@guillep guillep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments with ideas

jump1 := cogit JumpNonZero: 0.
cogit MoveR: Arg0Reg R: TempReg.
cogit ArithmeticShiftRightCq: 3 R: TempReg.
cogit MoveM64: 0 r: ReceiverResultReg R: ClassReg.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see why you're looking at customisation, this could be checked statically

cogit AndCq: 255 R: SendNumArgsReg.
cogit CmpCq: 255 R: SendNumArgsReg.
jump3 := cogit JumpZero: 0.
jump4 := cogit Jump: 0.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern could be simplified if we do a better way to sort basic blocks

cogit MoveR: ReceiverResultReg R: SendNumArgsReg.
cogit AddR: SendNumArgsReg R: TempReg.
cogit AddCq: -1 R: TempReg.
cogit MoveMb: 8 r: TempReg R: SendNumArgsReg.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be also simplifiable

cogit AddR: SendNumArgsReg R: TempReg.
cogit AddCq: -1 R: TempReg.
cogit MoveMb: 8 r: TempReg R: SendNumArgsReg.
cogit AndCq: 255 R: SendNumArgsReg.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could avoid this instruction if the backend automatically zero extends the reads only when required...

jump4 := cogit JumpLess: 0.
cogit CmpR: ClassReg R: TempReg.
jump3 := cogit JumpGreater: 0.
cogit SubCq: 1 R: TempReg.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An interesting not here is that we know we cannot fail anymore. So here we should be able to use the Receiver register and override it as soon as it is not used anymore.
This

cogit SubCq: 1 R: TempReg.
	cogit LogicalShiftLeftCq: 3 R: TempReg.
	cogit MoveR: ReceiverResultReg R: ClassReg.
	cogit AddR: ClassReg R: TempReg.
	cogit MoveM64: 8 r: TempReg R: ClassReg.
	cogit MoveR: ClassReg R: ReceiverResultReg.

could eventually be compiled as

        cogit SubCq: 1 R: TempReg.
	cogit LogicalShiftLeftCq: 3 R: TempReg.
	cogit AddR: ReceiverResultReg. R: TempReg.
	cogit MoveM64: 8 r: TempReg R: ReceiverResultReg.

cogit TstCq: 7 R: ReceiverResultReg.
jump1 := cogit JumpNonZero: 0.
cogit MoveR: Arg0Reg R: TempReg.
cogit ArithmeticShiftRightCq: 3 R: TempReg.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not validating that the argument is an integer!

| jump3 jump1 currentBlock jump4 jump2 |
cogit TstCq: 7 R: ReceiverResultReg.
jump1 := cogit JumpNonZero: 0.
cogit MoveR: Arg0Reg R: TempReg.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, there is no validation on the argument!

<accessorDepth: 0>
<numberOfArguments: 1>
self commonAtWith: [ :array :index |
self stPointerArray: array at: index ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the conciseness :)

We can even refactor the original one to look like this.

@guillep
Copy link
Member

guillep commented Jul 12, 2023

We should merge both together.

I agree

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

Successfully merging this pull request may close these issues.

None yet

2 participants