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

[LoongArch64] Part-2:Add runtime assembly code (*.S) files in nativeaot. #104084

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sunlijun-610
Copy link
Contributor

This PR is the second part adding nativeaot support on LoongArch64.
It adds runtime assembly code (*.S) files.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 27, 2024
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

@jkotas
Copy link
Member

jkotas commented Jun 27, 2024

@shushanhf @huoyaoyuan Could you please review and signoff on this PR?

Copy link
Member

@huoyaoyuan huoyaoyuan left a comment

Choose a reason for hiding this comment

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

I have limited knowledge on LA64 asm. Here are some points I don't understand or can be improved for consistency.

// Preserve the MethodTable in s0
ori $s0, $a0, 0

addi.w $a2, $zero, 0 // numElements
Copy link
Member

Choose a reason for hiding this comment

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

Why does here use addi.w to clear $a2, instead of ori? I'm seeing ori $zero, 0 more in other places.

// Compute overall allocation size (align(base size + (element size * elements), 8)).
addi.w $a2, $zero, STRING_COMPONENT_SIZE
ori $a3, $zero, 29 // STRING_BASE_SIZE + 7
mulw.d.w $a2, $a1, $a2
Copy link
Member

Choose a reason for hiding this comment

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

Nit: STRING_COMPONENT_SIZE is power of 2, so this can be a shift instead.
ARM also uses MUL here.

Comment on lines +119 to +120
addi.w $a2, $zero, STRING_COMPONENT_SIZE
ori $a3, $zero, 29 // STRING_BASE_SIZE + 7
Copy link
Member

Choose a reason for hiding this comment

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

Any difference between addi.w and ori here?

Comment on lines +123 to +124
srli.d $a2, $a2, 3
slli.d $a2, $a2, 3
Copy link
Member

Choose a reason for hiding this comment

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

Note for myself: andi on LA zero-extends the imm12, so unlike arm, & -8 can't be performed in a single instruction.

Comment on lines +29 to +30
ori $t0, $sp, 0
st.d $t0, $a0, OFFSETOF__PInvokeTransitionFrame__m_PreservedRegs
Copy link
Member

Choose a reason for hiding this comment

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

Can this st.d operate on $sp directly?

Comment on lines +50 to +51
ori $t1, $zero, 0
st.d $t1, $t0, OFFSETOF__Thread__m_pTransitionFrame
Copy link
Member

Choose a reason for hiding this comment

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

Can $zero be used directly in the st?


// If g_GCShadow is 0, don't perform the check.
PREPARE_EXTERNAL_VAR_INDIRECT g_GCShadow, $t3
beq $t3, $zero, 1f
Copy link
Member

Choose a reason for hiding this comment

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

Can the branch instructions use a label?

Comment on lines +114 to +115
lu12i.w $a2, 0x3ffff // (MAX_STRING_LENGTH >> 12) & 0xFFFFF
ori $a2, $a2, 0xfdf // MAX_STRING_LENGTH & 0xFFF
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
lu12i.w $a2, 0x3ffff // (MAX_STRING_LENGTH >> 12) & 0xFFFFF
ori $a2, $a2, 0xfdf // MAX_STRING_LENGTH & 0xFFF
lu12i.w $a2, ((MAX_STRING_LENGTH >> 12) & 0xfffff)
ori $a2, $a2, (MAX_STRING_LENGTH & 0xfff)

Use constants like UPDATE_GC_SHADOW macro.


// Compute overall allocation size (align(base size + (element size * elements), 8)).
addi.w $a2, $zero, STRING_COMPONENT_SIZE
ori $a3, $zero, 29 // STRING_BASE_SIZE + 7
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ori $a3, $zero, 29 // STRING_BASE_SIZE + 7
ori $a3, $zero, (STRING_BASE_SIZE + 7)

Comment on lines +298 to +300
beq $t0, $t1, 12
ori $t1, $t0, 0
b 8
Copy link
Member

Choose a reason for hiding this comment

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

Use label for the branches

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-loongarch64 area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants