github.com/primecitizens/pcz/std@v0.2.1/core/reflect/call_wasm.s (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  //
     4  // Copyright 2018 The Go Authors. All rights reserved.
     5  // Use of this source code is governed by a BSD-style
     6  // license that can be found in the LICENSE file.
     7  
     8  //go:build pcz && wasm
     9  
    10  #include "textflag.h"
    11  #include "funcdata.h" // for NO_LOCAL_POINTERS
    12  
    13  #define DISPATCH(NAME, MAXSIZE) \
    14  	Get R0; \
    15  	I64Const $MAXSIZE; \
    16  	I64LeU; \
    17  	If; \
    18  		JMP NAME(SB); \
    19  	End
    20  
    21  TEXT ·Call(SB),NOSPLIT,$0-48
    22  	I64Load fn+8(FP)
    23  	I64Eqz
    24  	If
    25  		CALLNORESUME ·sigpanic<ABIInternal>(SB)
    26  	End
    27  
    28  	MOVW frameSize+32(FP), R0
    29  
    30  	DISPATCH(·call16, 16)
    31  	DISPATCH(·call32, 32)
    32  	DISPATCH(·call64, 64)
    33  	DISPATCH(·call128, 128)
    34  	DISPATCH(·call256, 256)
    35  	DISPATCH(·call512, 512)
    36  	DISPATCH(·call1024, 1024)
    37  	DISPATCH(·call2048, 2048)
    38  	DISPATCH(·call4096, 4096)
    39  	DISPATCH(·call8192, 8192)
    40  	DISPATCH(·call16384, 16384)
    41  	DISPATCH(·call32768, 32768)
    42  	DISPATCH(·call65536, 65536)
    43  	DISPATCH(·call131072, 131072)
    44  	DISPATCH(·call262144, 262144)
    45  	DISPATCH(·call524288, 524288)
    46  	DISPATCH(·call1048576, 1048576)
    47  	DISPATCH(·call2097152, 2097152)
    48  	DISPATCH(·call4194304, 4194304)
    49  	DISPATCH(·call8388608, 8388608)
    50  	DISPATCH(·call16777216, 16777216)
    51  	DISPATCH(·call33554432, 33554432)
    52  	DISPATCH(·call67108864, 67108864)
    53  	DISPATCH(·call134217728, 134217728)
    54  	DISPATCH(·call268435456, 268435456)
    55  	DISPATCH(·call536870912, 536870912)
    56  	DISPATCH(·call1073741824, 1073741824)
    57  	JMP ·badreflectcall(SB)
    58  
    59  #define CALLFN(NAME, MAXSIZE) \
    60  TEXT NAME(SB), WRAPPER, $MAXSIZE-48; \
    61  	NO_LOCAL_POINTERS; \
    62  	MOVW stackArgsSize+24(FP), R0; \
    63  	\
    64  	Get R0; \
    65  	I64Eqz; \
    66  	Not; \
    67  	If; \
    68  		Get SP; \
    69  		I64Load stackArgs+16(FP); \
    70  		I32WrapI64; \
    71  		I64Load stackArgsSize+24(FP); \
    72  		I32WrapI64; \
    73  		MemoryCopy; \
    74  	End; \
    75  	\
    76  	MOVD f+8(FP), CTXT; \
    77  	Get CTXT; \
    78  	I32WrapI64; \
    79  	I64Load $0; \
    80  	CALL; \
    81  	\
    82  	I64LoadUint32U stackRetOffset+28(FP); \
    83  	Set R0; \
    84  	\
    85  	MOVD stackArgsType+0(FP), RET0; \
    86  	\
    87  	I64Load stackArgs+16(FP); \
    88  	Get R0; \
    89  	I64Add; \
    90  	Set RET1; \
    91  	\
    92  	Get SP; \
    93  	I64ExtendI32U; \
    94  	Get R0; \
    95  	I64Add; \
    96  	Set RET2; \
    97  	\
    98  	I64LoadUint32U stackArgsSize+24(FP); \
    99  	Get R0; \
   100  	I64Sub; \
   101  	Set RET3; \
   102  	\
   103  	CALL callRet<>(SB); \
   104  	RET
   105  
   106  // callRet copies return values back at the end of call*. This is a
   107  // separate function so it can allocate stack space for the arguments
   108  // to reflectcallmove. It does not follow the Go ABI; it expects its
   109  // arguments in registers.
   110  TEXT callRet<>(SB), NOSPLIT, $40-0
   111  	NO_LOCAL_POINTERS
   112  	MOVD RET0, 0(SP)
   113  	MOVD RET1, 8(SP)
   114  	MOVD RET2, 16(SP)
   115  	MOVD RET3, 24(SP)
   116  	MOVD $0,   32(SP)
   117  	CALL ·reflectcallmove(SB)
   118  	RET
   119  
   120  CALLFN(·call16, 16)
   121  CALLFN(·call32, 32)
   122  CALLFN(·call64, 64)
   123  CALLFN(·call128, 128)
   124  CALLFN(·call256, 256)
   125  CALLFN(·call512, 512)
   126  CALLFN(·call1024, 1024)
   127  CALLFN(·call2048, 2048)
   128  CALLFN(·call4096, 4096)
   129  CALLFN(·call8192, 8192)
   130  CALLFN(·call16384, 16384)
   131  CALLFN(·call32768, 32768)
   132  CALLFN(·call65536, 65536)
   133  CALLFN(·call131072, 131072)
   134  CALLFN(·call262144, 262144)
   135  CALLFN(·call524288, 524288)
   136  CALLFN(·call1048576, 1048576)
   137  CALLFN(·call2097152, 2097152)
   138  CALLFN(·call4194304, 4194304)
   139  CALLFN(·call8388608, 8388608)
   140  CALLFN(·call16777216, 16777216)
   141  CALLFN(·call33554432, 33554432)
   142  CALLFN(·call67108864, 67108864)
   143  CALLFN(·call134217728, 134217728)
   144  CALLFN(·call268435456, 268435456)
   145  CALLFN(·call536870912, 536870912)
   146  CALLFN(·call1073741824, 1073741824)