Skip to content

Commit 9e3b44b

Browse files
dcharkescommit-bot@chromium.org
authored andcommitted
[vm/ffi] SimDBC on Arm64 Android
Bug: #35773 Change-Id: I6f1f85239b0ffe5c310b9aeea4a4edcd97362bca 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/+/104565 Reviewed-by: Samir Jindel <[email protected]> Commit-Queue: Samir Jindel <[email protected]> Commit-Queue: Daco Harkes <[email protected]>
1 parent 603293f commit 9e3b44b

File tree

5 files changed

+77
-6
lines changed

5 files changed

+77
-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: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#if defined(__aarch64__) /* HOST_ARCH_ARM64 */
2+
3+
.text
4+
.global FfiTrampolineCall
5+
.type FfiTrampolineCall, %function
6+
FfiTrampolineCall:
7+
8+
/* Save argument in scratch register. */
9+
stp x19, x20, [sp, #-16]! /* Push x19 and x20, we use x19 as scratch. */
10+
mov x19, x0 /* Save argument in scratch register. */
11+
12+
/* Enter frame. */
13+
stp fp, lr, [sp, #-16]!
14+
mov fp, sp
15+
16+
/* Reserve framespace for arguments. */
17+
ldr x9, [x19, #(8*18)] /* Load number of stack arguments. */
18+
lsl x9, x9, #3 /* Multiply by size (8 bytes). */
19+
sub sp, sp, x9 /* Reserve num_stack_args stack slots. */
20+
21+
/* Stack alignment. */
22+
ldr x10, [x19, #(8*17)] /* Load stack alignment mask. */
23+
mov x11, sp
24+
and x11, x11, x10 /* Align stack. */
25+
mov sp, x11
26+
27+
/* Copy stack arguments. */
28+
cmp x9, #0 /* Check if number of stack arguments is 0. */
29+
beq .done /* Skip loop if no stack arguments. */
30+
add x19, x19, #(8*19) /* Offset r19 to point to stack arguments. */
31+
.loop: /* Copy stack arguments loop. */
32+
sub x9, x9, #8 /* Decrement stack argument iterator. */
33+
ldr x10, [x19, x9] /* Load value from ffi_marshalled_args. */
34+
str x10, [sp, x9] /* Store value on stack. */
35+
cmp x9, #0 /* Compare iterator with 0 */
36+
bne .loop /* Loop while iterator is not 0 */
37+
sub x19, x19, #(8*19) /* Restore r19 to original value. */
38+
.done: /* End stack arguments loop. */
39+
40+
/* Copy registers and fpu registers. */
41+
ldp x0, x1, [x19, #(8*1)] /* and #(8*2) */
42+
ldp x2, x3, [x19, #(8*3)] /* and #(8*4) */
43+
ldp x4, x5, [x19, #(8*5)] /* ... */
44+
ldp x6, x7, [x19, #(8*7)]
45+
ldp d0, d1, [x19, #(8*9)]
46+
ldp d2, d3, [x19, #(8*11)]
47+
ldp d4, d5, [x19, #(8*13)]
48+
ldp d6, d7, [x19, #(8*15)]
49+
50+
/* Do call. */
51+
ldr x9, [x19] /* Load function address. */
52+
blr x9 /* Call the function. */
53+
54+
/* Copy results back. */
55+
str x0, [x19, #(8*0)] /* Move integer result in kOffsetIntResult. */
56+
str d0, [x19, #(8*1)] /* Move double result in kOffsetDoubleResult. */
57+
58+
/* Leave frame. */
59+
mov sp, fp
60+
ldp fp, lr, [sp], #16
61+
62+
/* Restore caller saved register. */
63+
ldp x19, x20, [sp], #16 /* Pop x19 and x20. */
64+
ret
65+
66+
#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
@@ -26,7 +26,7 @@ function_callbacks_test/03: Skip
2626
[ $arch == arm && $system != android ]
2727
*: Skip # "hardfp" calling convention is not yet supported (iOS is also supported but not tested): dartbug.com/36309
2828

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

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

0 commit comments

Comments
 (0)