ObjFW  Check-in [573f1ca9aa]

Overview
Comment:forwardingTargetForSelector: for LoongArch 64/ELF
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 573f1ca9aa0bc6cad2768249cd88eea14a835c5a696dbd3001a08d77a0044989
User & Date: js on 2024-07-27 23:33:30
Other Links: manifest | tags
References
2024-07-27
23:34 Fixed ticket [fafe525b8a]: Write assembly for forwardingTargetForSelector: on LoongArch 64 plus 4 other changes artifact: 2d77983ba8 user: js
Context
2024-07-27
23:48
platform.h: Add SuperH check-in: 43af96a7c8 user: js tags: trunk
23:33
forwardingTargetForSelector: for LoongArch 64/ELF check-in: 573f1ca9aa user: js tags: trunk
16:16
LoongArch 64/ELF assembly lookup implementation check-in: 6099526435 user: js tags: trunk
Changes

Modified PLATFORMS.md from [798ae85dd1] to [af0e683b2f].

264
265
266
267
268
269
270

271
272
273
274
275
276
277
architecture, executable format and calling convention, it is only available
for the following platforms (except resolveClassMethod: and
resolveInstanceMethod:, which are always available):

  * AMD64 (SysV/ELF, Apple/Mach-O, Mach-O, Win64/PE)
  * ARM (EABI/ELF, Apple/Mach-O)
  * ARM64 (ARM64/ELF, Apple/Mach-O)

  * MIPS (O32/ELF, EABI/ELF)
  * MIPS64 (N64/ELF)
  * PowerPC (SysV/ELF, EABI/ELF, Apple/Mach-O)
  * RISC-V 64 (SysV/ELF)
  * SPARC (SysV/ELF)
  * SPARC64 (SysV/ELF)
  * x86 (SysV/ELF, Apple/Mach-O, Win32/PE)







>







264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
architecture, executable format and calling convention, it is only available
for the following platforms (except resolveClassMethod: and
resolveInstanceMethod:, which are always available):

  * AMD64 (SysV/ELF, Apple/Mach-O, Mach-O, Win64/PE)
  * ARM (EABI/ELF, Apple/Mach-O)
  * ARM64 (ARM64/ELF, Apple/Mach-O)
  * LoongArch 64 (SysV/ELF)
  * MIPS (O32/ELF, EABI/ELF)
  * MIPS64 (N64/ELF)
  * PowerPC (SysV/ELF, EABI/ELF, Apple/Mach-O)
  * RISC-V 64 (SysV/ELF)
  * SPARC (SysV/ELF)
  * SPARC64 (SysV/ELF)
  * x86 (SysV/ELF, Apple/Mach-O, Win32/PE)

Added src/forwarding/forwarding-loongarch64-elf.S version [54c3f35928].























































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
 *
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3.0 only,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * version 3.0 for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3.0 along with this program. If not, see
 * <https://www.gnu.org/licenses/>.
 */

#include "config.h"

#include "platform.h"

.globl OFForward
.globl OFForward_stret

.section .text
OFForward:
	addi.d	$sp, $sp, -144
	st.d	$ra, $sp, 0

	st.d	$a0, $sp, 8
	st.d	$a1, $sp, 16
	st.d	$a2, $sp, 24
	st.d	$a3, $sp, 32
	st.d	$a4, $sp, 40
	st.d	$a5, $sp, 48
	st.d	$a6, $sp, 56
	st.d	$a7, $sp, 64

	fst.d	$fa0, $sp, 72
	fst.d	$fa1, $sp, 80
	fst.d	$fa2, $sp, 88
	fst.d	$fa3, $sp, 96
	fst.d	$fa4, $sp, 104
	fst.d	$fa5, $sp, 112
	fst.d	$fa6, $sp, 120
	fst.d	$fa7, $sp, 128

	bl	%plt(object_getClass)

	la.local $a1, .Lsel_forwardingTargetForSelector_
	bl	%plt(class_respondsToSelector)
	beqz	$a0, 0f

	ld.d	$a0, $sp, 8
	la.local $a1, .Lsel_forwardingTargetForSelector_
	bl	%plt(objc_msg_lookup)
	move	$t0, $a0

	ld.d	$a0, $sp, 8
	la.local $a1, .Lsel_forwardingTargetForSelector_
	ld.d	$a2, $sp, 16
	jirl	$ra, $t0, 0

	beqz	$a0, 0f
	ld.d	$t0, $sp, 8
	beq	$t0, $a0, 0f

	st.d	$a0, $sp, 8

	ld.d	$a1, $sp, 16
	bl	%plt(objc_msg_lookup)
	move	$t0, $a0

	fld.d	$fa7, $sp, 128
	fld.d	$fa6, $sp, 120
	fld.d	$fa5, $sp, 112
	fld.d	$fa4, $sp, 104
	fld.d	$fa3, $sp, 96
	fld.d	$fa2, $sp, 88
	fld.d	$fa1, $sp, 80
	fld.d	$fa0, $sp, 72

	ld.d	$a7, $sp, 64
	ld.d	$a6, $sp, 56
	ld.d	$a5, $sp, 48
	ld.d	$a4, $sp, 40
	ld.d	$a3, $sp, 32
	ld.d	$a2, $sp, 24
	ld.d	$a1, $sp, 16
	ld.d	$a0, $sp, 8

	ld.d	$ra, $sp, 0
	addi.d	$sp, $sp, 144

	jr	$t0

0:
	ld.d	$a1, $sp, 16
	ld.d	$a0, $sp, 8

	ld.d	$ra, $sp, 0
	addi.d	$sp, $sp, 144

	b	%plt(OFMethodNotFound)
.type OFForward, @function
.size OFForward, .-OFForward

OFForward_stret:
	addi.d	$sp, $sp, -144
	st.d	$ra, $sp, 0

	st.d	$a0, $sp, 8
	st.d	$a1, $sp, 16
	st.d	$a2, $sp, 24
	st.d	$a3, $sp, 32
	st.d	$a4, $sp, 40
	st.d	$a5, $sp, 48
	st.d	$a6, $sp, 56
	st.d	$a7, $sp, 64

	fst.d	$fa0, $sp, 72
	fst.d	$fa1, $sp, 80
	fst.d	$fa2, $sp, 88
	fst.d	$fa3, $sp, 96
	fst.d	$fa4, $sp, 104
	fst.d	$fa5, $sp, 112
	fst.d	$fa6, $sp, 120
	fst.d	$fa7, $sp, 128

	move	$a0, $a1
	bl	%plt(object_getClass)

	la.local $a1, .Lsel_forwardingTargetForSelector_
	bl	%plt(class_respondsToSelector)
	beqz	$a0, 0f

	ld.d	$a0, $sp, 16
	la.local $a1, .Lsel_forwardingTargetForSelector_
	bl	%plt(objc_msg_lookup)
	move	$t0, $a0

	ld.d	$a0, $sp, 16
	la.local $a1, .Lsel_forwardingTargetForSelector_
	ld.d	$a2, $sp, 24
	jirl	$ra, $t0, 0

	beqz	$a0, 0f
	ld.d	$t0, $sp, 16
	beq	$t0, $a0, 0f

	st.d	$a0, $sp, 16

	ld.d	$a1, $sp, 24
	bl	%plt(objc_msg_lookup_stret)
	move	$t0, $a0

	fld.d	$fa7, $sp, 128
	fld.d	$fa6, $sp, 120
	fld.d	$fa5, $sp, 112
	fld.d	$fa4, $sp, 104
	fld.d	$fa3, $sp, 96
	fld.d	$fa2, $sp, 88
	fld.d	$fa1, $sp, 80
	fld.d	$fa0, $sp, 72

	ld.d	$a7, $sp, 64
	ld.d	$a6, $sp, 56
	ld.d	$a5, $sp, 48
	ld.d	$a4, $sp, 40
	ld.d	$a3, $sp, 32
	ld.d	$a2, $sp, 24
	ld.d	$a1, $sp, 16
	ld.d	$a0, $sp, 8

	ld.d	$ra, $sp, 0
	addi.d	$sp, $sp, 144

	jr	$t0

0:
	ld.d	$a2, $sp, 24
	ld.d	$a1, $sp, 16
	ld.d	$a0, $sp, 8

	ld.d	$ra, $sp, 0
	addi.d	$sp, $sp, 144

	b	%plt(OFMethodNotFound_stret)
.type OFForward_stret, @function
.size OFForward_stret, .-OFForward_stret

.Linit:
	la.local $a0, .Lmodule
	b	%plt(__objc_exec_class)

.section .init_array, "aw"
	.quad .Linit

.section .rodata
.Lstr_forwardingTargetForSelector_:
	.asciz "forwardingTargetForSelector:"

.section .data
.Lsel_forwardingTargetForSelector_:
	.quad .Lstr_forwardingTargetForSelector_, 0
	.quad 0, 0
.Lsymtab:
	.quad 0, .Lsel_forwardingTargetForSelector_
	.short 0, 0
	.long 0
	.quad 0
.Lmodule:
	.quad 8, 32, 0, .Lsymtab

#if defined(OF_LINUX) || defined(OF_HAIKU) || defined(OF_HURD)
.section .note.GNU-stack, "", @progbits
#endif

Modified src/forwarding/forwarding.S from [fb23108c9e] to [ab4fbfbdfb].

51
52
53
54
55
56
57


58
59
60
61
62
63
64
#   include "forwarding-mips-elf.S"
#  elif defined(OF_SPARC64)
#   include "forwarding-sparc64-elf.S"
#  elif defined(OF_SPARC)
#   include "forwarding-sparc-elf.S"
#  elif defined(OF_RISCV64)
#   include "forwarding-riscv64-elf.S"


#  endif
# elif defined(OF_MACH_O)
#  if defined(OF_AMD64)
#   include "forwarding-amd64-macho.S"
#  endif
# elif defined(OF_WINDOWS)
#  if defined(OF_AMD64)







>
>







51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#   include "forwarding-mips-elf.S"
#  elif defined(OF_SPARC64)
#   include "forwarding-sparc64-elf.S"
#  elif defined(OF_SPARC)
#   include "forwarding-sparc-elf.S"
#  elif defined(OF_RISCV64)
#   include "forwarding-riscv64-elf.S"
#  elif defined(OF_LOONGARCH64)
#   include "forwarding-loongarch64-elf.S"
#  endif
# elif defined(OF_MACH_O)
#  if defined(OF_AMD64)
#   include "forwarding-amd64-macho.S"
#  endif
# elif defined(OF_WINDOWS)
#  if defined(OF_AMD64)

Modified src/macros.h from [279bb31779] to [e8d271f2ea].

348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# endif
#else
# if defined(OF_ELF)
#  if defined(OF_AMD64) || defined(OF_X86) || \
    defined(OF_ARM64) || defined(OF_ARM) || defined(OF_POWERPC) || \
    defined(OF_MIPS64_N64) || defined(OF_MIPS) || \
    defined(OF_SPARC64) || defined(OF_SPARC) || \
    defined(OF_RISCV64)
#   define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
#   if __OBJFW_RUNTIME_ABI__ >= 800
#    define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET
#   endif
#  endif
# elif defined(OF_MACH_O)
#  if defined(OF_AMD64)







|







348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# endif
#else
# if defined(OF_ELF)
#  if defined(OF_AMD64) || defined(OF_X86) || \
    defined(OF_ARM64) || defined(OF_ARM) || defined(OF_POWERPC) || \
    defined(OF_MIPS64_N64) || defined(OF_MIPS) || \
    defined(OF_SPARC64) || defined(OF_SPARC) || \
    defined(OF_RISCV64) || defined(OF_LOONGARCH64)
#   define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
#   if __OBJFW_RUNTIME_ABI__ >= 800
#    define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET
#   endif
#  endif
# elif defined(OF_MACH_O)
#  if defined(OF_AMD64)

Modified src/runtime/lookup-asm/lookup-asm-loongarch64-elf.S from [cb61c5a810] to [697db5824e].

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
.macro GENERATE_LOOKUP name notFound
\name:
	beqz	$a0, .LreturnNilMethod

	andi	$t0, $a0, 1
	bnez	$t0, .LtaggedPointer_\name

	ld.d	$t0, $a0, 0
	ld.d	$t0, $t0, 64

.Lmain_\name:
#ifdef OF_SELUID24
	ld.bu	$t1, $a1, 2
	slli.d	$t1, $t1, 3
#endif
	ld.bu	$t2, $a1, 1







|
|







30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
.macro GENERATE_LOOKUP name notFound
\name:
	beqz	$a0, .LreturnNilMethod

	andi	$t0, $a0, 1
	bnez	$t0, .LtaggedPointer_\name

	ldptr.d	$t0, $a0, 0
	ldptr.d	$t0, $t0, 64

.Lmain_\name:
#ifdef OF_SELUID24
	ld.bu	$t1, $a1, 2
	slli.d	$t1, $t1, 3
#endif
	ld.bu	$t2, $a1, 1
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
	ldptr.d	$t1, $t1, 0
	xor	$t1, $a0, $t1
	andi	$t1, $t1, 0xE
	slli.d	$t1, $t1, 2

	la.global $t0, objc_taggedPointerClasses
	ldx.d	$t0, $t0, $t1
	ld.d	$t0, $t0, 64

	b	.Lmain_\name
.type \name, %function
.size \name, .-\name
.endm

.macro GENERATE_LOOKUP_SUPER name lookup
\name:
	move	$t0, $a0
	ld.d	$a0, $a0, 0
	beqz	$a0, .LreturnNilMethod

	ld.d	$t0, $t0, 8
	ld.d	$t0, $t0, 64

	b	.Lmain_\lookup
.type \name, %function
.size \name, .-\name
.endm

GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound







|









|


|
|







66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
	ldptr.d	$t1, $t1, 0
	xor	$t1, $a0, $t1
	andi	$t1, $t1, 0xE
	slli.d	$t1, $t1, 2

	la.global $t0, objc_taggedPointerClasses
	ldx.d	$t0, $t0, $t1
	ldptr.d	$t0, $t0, 64

	b	.Lmain_\name
.type \name, %function
.size \name, .-\name
.endm

.macro GENERATE_LOOKUP_SUPER name lookup
\name:
	move	$t0, $a0
	ldptr.d	$a0, $a0, 0
	beqz	$a0, .LreturnNilMethod

	ldptr.d	$t0, $t0, 8
	ldptr.d	$t0, $t0, 64

	b	.Lmain_\lookup
.type \name, %function
.size \name, .-\name
.endm

GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound