Skip to content

Commit 833a8e6

Browse files
basilisk-devdavidchisnall
authored andcommitted
Implement objc_msgSend function for the LoongArch CPU architecture
1 parent ecef7f1 commit 833a8e6

4 files changed

Lines changed: 139 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ if (WIN32 AND NOT MINGW)
213213
COMMAND echo ${ASSEMBLER} ${ASM_TARGET} -c "${CMAKE_SOURCE_DIR}/objc_msgSend.S" -o "${CMAKE_BINARY_DIR}/objc_msgSend.obj"
214214
COMMAND ${ASSEMBLER} ${ASM_TARGET} -c "${CMAKE_SOURCE_DIR}/objc_msgSend.S" -o "${CMAKE_BINARY_DIR}/objc_msgSend.obj"
215215
MAIN_DEPENDENCY objc_msgSend.S
216-
DEPENDS objc_msgSend.aarch64.S objc_msgSend.arm.S objc_msgSend.mips.S objc_msgSend.x86-32.S objc_msgSend.x86-64.S
216+
DEPENDS objc_msgSend.aarch64.S objc_msgSend.arm.S objc_msgSend.loongarch64.S objc_msgSend.mips.S objc_msgSend.x86-32.S objc_msgSend.x86-64.S
217217
)
218218
set(libobjc_ASM_OBJS block_trampolines.obj objc_msgSend.obj)
219219
endif()

objc/message.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#if defined(__x86_64) || defined(__i386) || defined(__arm__) || \
1010
defined(__mips_n64) || defined(__mips_n32) || \
1111
defined(__ARM_ARCH_ISA_A64) || \
12+
(defined(__loongarch__) && defined(__loongarch_lp64) && \
13+
defined(__loongarch_double_float)) || \
1214
(defined(__riscv) && __riscv_xlen == 64 && \
1315
defined(__riscv_float_abi_double))
1416

objc_msgSend.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "objc_msgSend.aarch64.S"
1111
#elif defined(__riscv) && (__riscv_xlen == 64) && defined(__riscv_float_abi_double)
1212
#include "objc_msgSend.riscv64.S"
13+
#elif defined(__loongarch__) && defined(__loongarch_lp64) && defined(__loongarch_double_float)
14+
#include "objc_msgSend.loongarch64.S"
1315
#elif defined(__mips_n64) || defined(__mips_n32)
1416
#include "objc_msgSend.mips.S"
1517
#else

objc_msgSend.loongarch64.S

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#define ARGUMENT_SPILL_SIZE (10*8 + 8*8)
2+
3+
.macro MSGSEND receiver, sel
4+
.cfi_startproc
5+
beqz \receiver, 3f // Skip everything if receiver is nil
6+
7+
andi $t0, \receiver, SMALLOBJ_MASK
8+
bnez $t0, 5f
9+
10+
ld.d $t0, \receiver, 0 // Load class into t0
11+
0:
12+
ld.d $t0, $t0, DTABLE_OFFSET // dtable -> t0
13+
ld.d $t1, \sel, 0 // selector->index -> t1
14+
ld.w $t2, $t0, SHIFT_OFFSET // dtable->shift -> t2
15+
16+
addi.d $t3, $zero, 8
17+
beq $t2, $t3, 1f
18+
beqz $t2, 2f
19+
20+
srli.d $t2, $t1, 13 // Extract byte 3 of sel index and multiply by 2^3
21+
andi $t2, $t2, 0x7f8
22+
add.d $t2, $t0, $t2
23+
ld.d $t0, $t2, DATA_OFFSET
24+
1:
25+
srli.d $t2, $t1, 5 // Extract byte 2 of sel index and multiply by 2^3
26+
andi $t2, $t2, 0x7f8
27+
add.d $t2, $t0, $t2
28+
ld.d $t0, $t2, DATA_OFFSET
29+
2:
30+
slli.d $t2, $t1, 3 // Multiply by 2^3
31+
andi $t2, $t2, 0x7f8
32+
add.d $t2, $t0, $t2
33+
ld.d $t0, $t2, DATA_OFFSET // Slot pointer is now in t0
34+
35+
beqz $t0, 4f // If the slot is nil, go to the C path
36+
37+
ld.d $t0, $t0, SLOT_OFFSET // Load the method from the slot
38+
jr $t0 // Tail-call the method
39+
40+
3:
41+
move \receiver, $zero
42+
move \sel, $zero
43+
movgr2fr.d $fa0, $zero
44+
movgr2fr.d $fa1, $zero
45+
ret
46+
47+
4:
48+
addi.d $sp, $sp, -ARGUMENT_SPILL_SIZE
49+
50+
// Spill function arguments.
51+
st.d $a0, $sp, 0
52+
st.d $a1, $sp, 8
53+
st.d $a2, $sp, 16
54+
st.d $a3, $sp, 24
55+
st.d $a4, $sp, 32
56+
st.d $a5, $sp, 40
57+
st.d $a6, $sp, 48
58+
st.d $a7, $sp, 56
59+
60+
// Spill FP arguments.
61+
fst.d $fa0, $sp, 64
62+
fst.d $fa1, $sp, 72
63+
fst.d $fa2, $sp, 80
64+
fst.d $fa3, $sp, 88
65+
fst.d $fa4, $sp, 96
66+
fst.d $fa5, $sp, 104
67+
fst.d $fa6, $sp, 112
68+
fst.d $fa7, $sp, 120
69+
70+
st.d $fp, $sp, 128
71+
st.d $ra, $sp, 136
72+
73+
addi.d $fp, $sp, 128
74+
addi.d $sp, $sp, -16
75+
st.d \receiver, $sp, 0 // Keep &self at sp for slowMsgLookup
76+
77+
.cfi_def_cfa fp, 16
78+
.cfi_offset fp, -16
79+
.cfi_offset ra, -8
80+
81+
move $a0, $sp // &self in first argument
82+
move $a1, \sel
83+
pcaddu18i $ra, %call36(CDECL(slowMsgLookup))
84+
jirl $ra, $ra, 0
85+
86+
move $t0, $a0 // IMP -> t0
87+
88+
ld.d $a0, $sp, 16
89+
ld.d $a1, $sp, 24
90+
ld.d $a2, $sp, 32
91+
ld.d $a3, $sp, 40
92+
ld.d $a4, $sp, 48
93+
ld.d $a5, $sp, 56
94+
ld.d $a6, $sp, 64
95+
ld.d $a7, $sp, 72
96+
97+
fld.d $fa0, $sp, 80
98+
fld.d $fa1, $sp, 88
99+
fld.d $fa2, $sp, 96
100+
fld.d $fa3, $sp, 104
101+
fld.d $fa4, $sp, 112
102+
fld.d $fa5, $sp, 120
103+
fld.d $fa6, $sp, 128
104+
fld.d $fa7, $sp, 136
105+
106+
ld.d $fp, $sp, 144
107+
ld.d $ra, $sp, 152
108+
ld.d \receiver, $sp, 0
109+
110+
addi.d $sp, $sp, ARGUMENT_SPILL_SIZE
111+
addi.d $sp, $sp, 16
112+
113+
jr $t0 // Tail-call the method
114+
115+
5:
116+
pcalau12i $t1, %got_pc_hi20(CDECL(SmallObjectClasses))
117+
ld.d $t1, $t1, %got_pc_lo12(CDECL(SmallObjectClasses))
118+
slli.d $t0, $t0, 3
119+
ldx.d $t0, $t1, $t0
120+
b 0b
121+
.cfi_endproc
122+
.endm
123+
124+
.globl CDECL(objc_msgSend_fpret)
125+
TYPE_DIRECTIVE(CDECL(objc_msgSend_fpret), %function)
126+
.globl CDECL(objc_msgSend)
127+
TYPE_DIRECTIVE(CDECL(objc_msgSend), %function)
128+
.globl CDECL(objc_msgSend_stret)
129+
TYPE_DIRECTIVE(CDECL(objc_msgSend_stret), %function)
130+
CDECL(objc_msgSend):
131+
CDECL(objc_msgSend_fpret):
132+
MSGSEND $a0, $a1
133+
CDECL(objc_msgSend_stret):
134+
MSGSEND $a1, $a2 // Pointer to stack frame in a0

0 commit comments

Comments
 (0)