3 +----------------------------------------------------------------------+
5 +----------------------------------------------------------------------+
6 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
7 +----------------------------------------------------------------------+
8 | This source file is subject to version 3.01 of the PHP license, |
9 | that is bundled with this package in the file LICENSE, and is |
10 | available through the world-wide-web at the following url: |
11 | http://www.php.net/license/3_01.txt |
12 | If you did not receive a copy of the PHP license and are unable to |
13 | obtain it through the world-wide-web, please send a note to |
14 | license@php.net so we can mail you a copy immediately. |
15 +----------------------------------------------------------------------+
20 * Generate the ABI wrapper functions for HPHP::Native::NativeFuncCaller
22 * The NativeFuncCaller class relies on specifics of the amd64 and ARMv8 ABIs
23 * to reshuffle the order of certain arguments and reduce the number of
24 * possible combinations (by a lot).
26 * If you don't understand how NativeFuncCaller works, don't use this script.
27 * If you do, then adjust NUM_GP_ARGS/NUM_SIMD_ARGS as needed and pipe the
28 * output of this script to runtime/vm/native-func-caller.h
30 * I solemnly swear that I am up to no good.
32 const NUM_GP_ARGS
= 32; // Must match kMaxBuiltinArgs
33 const NUM_SIMD_ARGS
= 8; // Must match CPU's ABI definition for SIMD usage
35 function go($name, $ret) {
36 $callerArgs = 'NativeFunction f, int64_t* GP, int GP_count, '.
37 'double* SIMD, int SIMD_count';
39 fwrite(STDOUT
, "{$ret} callFunc{$name}Impl({$callerArgs}) {\n");
40 fwrite(STDOUT
, " switch (GP_count) {\n");
42 for ($gp = 0; $gp <= NUM_GP_ARGS
; ++
$gp) {
43 fwrite(STDOUT
, " case {$gp}:\n");
44 fwrite(STDOUT
, " switch (SIMD_count) {\n");
46 for ($simd = 0; $simd <= NUM_SIMD_ARGS
; ++
$simd) {
47 $argsD = implode(',', array_merge($gpargs, $simdargs));
49 for ($i = 0; $i < $gp; ++
$i) {
52 for ($i = 0; $i < $simd; ++
$i) {
53 $argsC[] = "SIMD[$i]";
55 $argsC = implode(',', $argsC);
56 fwrite(STDOUT
, " case {$simd}:\n");
57 fwrite(STDOUT
, " return (({$ret} (*)({$argsD}))f)({$argsC});\n");
58 $simdargs[] = 'double';
60 fwrite(STDOUT
, " default: not_reached();\n");
61 fwrite(STDOUT
, " }\n");
62 $gpargs[] = 'int64_t';
64 fwrite(STDOUT
, " default: not_reached();\n");
65 fwrite(STDOUT
, " }\n");
66 fwrite(STDOUT
, "}\n\n");
71 fwrite(STDOUT
, "// @"."generated by hphp/tools/make_native-func-caller.php\n\n");
73 fwrite(STDOUT
, "static_assert(kMaxBuiltinArgs == " . NUM_GP_ARGS
.
74 ",\"Regenerate native-func-caller.h for updated ".
75 "kMaxBuiltinArgs\");\n\n");
77 fwrite(STDOUT
, "static_assert(kNumSIMDRegs == " . NUM_SIMD_ARGS
.
78 ",\"Regenerate native-func-caller.h for updated ".
79 "kNumSIMDRegs\");\n\n");
81 go('Double', 'double');
82 go('Int64', 'int64_t');
83 go('TV', 'TypedValue');
84 fwrite(STDOUT
, "template<class IndirectRet>\n");
85 go('Indirect', 'IndirectRet');