Skip to content

Commit 9bccb7b

Browse files
dcharkescommit-bot@chromium.org
authored andcommitted
Rereland "[vm/ffi] SimDBC on Arm64 Android"
Fixed iOS Flutter build. Change-Id: Id585dea5286e776bb0f333296ac99ef634d61e7d Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try, app-kernel-linux-debug-x64-try, vm-kernel-linux-debug-simdbc64-try,vm-kernel-mac-debug-simdbc64-try,vm-kernel-reload-mac-debug-simdbc64-try,vm-kernel-linux-debug-ia32-try,vm-dartkb-linux-debug-simarm64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108262 Reviewed-by: Samir Jindel <[email protected]> Commit-Queue: Daco Harkes <[email protected]>
1 parent 0b1ec2d commit 9bccb7b

File tree

5 files changed

+87
-6
lines changed

5 files changed

+87
-6
lines changed

runtime/vm/compiler/compiler_sources.gni

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,12 @@ compiler_sources = [
152152
#
153153
# Not that this diverges from our convention to build every file on every OS
154154
# but have ifdef guards which make the files empty on some configurations.
155-
if (is_linux || is_mac) {
155+
if (!is_win) {
156156
# MASM on Windows does not support c preproccesor style flags.
157-
compiler_sources += [ "ffi_dbc_trampoline_x64_linux_mac.S" ]
157+
compiler_sources += [
158+
"ffi_dbc_trampoline_arm64.S",
159+
"ffi_dbc_trampoline_x64_linux_mac.S",
160+
]
158161
}
159162

160163
compiler_sources_tests = [

runtime/vm/compiler/ffi_dbc_trampoline.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
namespace dart {
1111

12-
#if defined(HOST_ARCH_X64) && !defined(HOST_OS_WINDOWS)
12+
#if !defined(HOST_OS_WINDOWS) && \
13+
(defined(HOST_ARCH_X64) || defined(HOST_ARCH_ARM64))
1314

1415
// Generic Trampoline for DBC dart:ffi calls. Argument needs to be layed out as
1516
// a FfiMarshalledArguments.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#if defined(__aarch64__) /* HOST_ARCH_ARM64 */
2+
3+
.text
4+
5+
#if defined(__ANDROID__) || defined(__linux__) || defined(__FreeBSD__)
6+
/* HOST_OS_ANDROID || HOST_OS_LINUX */
7+
.global FfiTrampolineCall
8+
.align 2
9+
FfiTrampolineCall:
10+
#else /* HOST_OS_MACOS */
11+
.global _FfiTrampolineCall
12+
.align 2
13+
_FfiTrampolineCall:
14+
#endif
15+
16+
/* Save argument in scratch register. */
17+
stp x19, x20, [sp, #-16]! /* Push x19 and x20, we use x19 as scratch. */
18+
mov x19, x0 /* Save argument in scratch register. */
19+
20+
/* Enter frame. */
21+
stp fp, lr, [sp, #-16]!
22+
mov fp, sp
23+
24+
/* Reserve framespace for arguments. */
25+
ldr x9, [x19, #(8*18)] /* Load number of stack arguments. */
26+
lsl x9, x9, #3 /* Multiply by size (8 bytes). */
27+
sub sp, sp, x9 /* Reserve num_stack_args stack slots. */
28+
29+
/* Stack alignment. */
30+
ldr x10, [x19, #(8*17)] /* Load stack alignment mask. */
31+
mov x11, sp
32+
and x11, x11, x10 /* Align stack. */
33+
mov sp, x11
34+
35+
/* Copy stack arguments. */
36+
cmp x9, #0 /* Check if number of stack arguments is 0. */
37+
beq .done /* Skip loop if no stack arguments. */
38+
add x19, x19, #(8*19) /* Offset r19 to point to stack arguments. */
39+
.align 2
40+
.loop: /* Copy stack arguments loop. */
41+
sub x9, x9, #8 /* Decrement stack argument iterator. */
42+
ldr x10, [x19, x9] /* Load value from ffi_marshalled_args. */
43+
str x10, [sp, x9] /* Store value on stack. */
44+
cmp x9, #0 /* Compare iterator with 0 */
45+
bne .loop /* Loop while iterator is not 0 */
46+
sub x19, x19, #(8*19) /* Restore r19 to original value. */
47+
.align 2
48+
.done: /* End stack arguments loop. */
49+
50+
/* Copy registers and fpu registers. */
51+
ldp x0, x1, [x19, #(8*1)] /* and #(8*2) */
52+
ldp x2, x3, [x19, #(8*3)] /* and #(8*4) */
53+
ldp x4, x5, [x19, #(8*5)] /* ... */
54+
ldp x6, x7, [x19, #(8*7)]
55+
ldp d0, d1, [x19, #(8*9)]
56+
ldp d2, d3, [x19, #(8*11)]
57+
ldp d4, d5, [x19, #(8*13)]
58+
ldp d6, d7, [x19, #(8*15)]
59+
60+
/* Do call. */
61+
ldr x9, [x19] /* Load function address. */
62+
blr x9 /* Call the function. */
63+
64+
/* Copy results back. */
65+
str x0, [x19, #(8*0)] /* Move integer result in kOffsetIntResult. */
66+
str d0, [x19, #(8*1)] /* Move double result in kOffsetDoubleResult. */
67+
68+
/* Leave frame. */
69+
mov sp, fp
70+
ldp fp, lr, [sp], #16
71+
72+
/* Restore caller saved register. */
73+
ldp x19, x20, [sp], #16 /* Pop x19 and x20. */
74+
ret
75+
76+
#endif /* HOST_ARCH_ARM64 */

runtime/vm/dart_api_impl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,9 @@ class Api : AllStatic {
300300
#if defined(TARGET_ARCH_DBC) && !defined(ARCH_IS_64_BIT)
301301
// TODO(36809): Support SimDBC32.
302302
return false;
303-
#elif defined(TARGET_ARCH_DBC) && !defined(HOST_ARCH_X64)
304-
// TODO(35773): Support ia32, arm64, and arm.
303+
#elif defined(TARGET_ARCH_DBC) && \
304+
!(defined(HOST_ARCH_X64) || defined(HOST_ARCH_ARM64))
305+
// TODO(36809): Support ia32 and arm.
305306
return false;
306307
#elif defined(TARGET_ARCH_DBC) && defined(HOST_ARCH_X64) && \
307308
defined(HOST_OS_WINDOWS)

tests/ffi/ffi.status

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function_callbacks_test/03: Skip
2424
[ $arch == arm && $system != android ]
2525
*: Skip # "hardfp" calling convention is not yet supported (iOS is also supported but not tested): dartbug.com/36309
2626

27-
[ $arch == simdbc64 && $system != linux && $system != macos ]
27+
[ $arch == simdbc64 && $system != android && $system != linux && $system != macos ]
2828
*: Skip # FFI not yet supported outside x64 Linux: dartbug.com/36809
2929

3030
[ $runtime != dart_precompiled && $runtime != vm ]

0 commit comments

Comments
 (0)