github.com/primecitizens/pcz/std@v0.2.1/core/reflect/call_mips64x.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 && (mips64 || mips64le)
     9  
    10  #include "textflag.h"
    11  #include "funcdata.h" // for NO_LOCAL_POINTERS
    12  
    13  // reflectcall: call a function with the given argument list
    14  // func call(stackArgsType *_type, f *FuncVal, stackArgs *byte, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs).
    15  // we don't have variable-sized frames, so we use a small number
    16  // of constant-sized-frame functions to encode a few bits of size in the pc.
    17  // Caution: ugly multiline assembly macros in your future!
    18  
    19  #define DISPATCH(NAME,MAXSIZE)		\
    20  	MOVV $MAXSIZE, R23;		\
    21  	SGTU R1, R23, R23;		\
    22  	BNE R23, 3(PC);			\
    23  	MOVV $NAME(SB), R4;	\
    24  	JMP (R4)
    25  // Note: can't just "BR NAME(SB)" - bad inlining results.
    26  
    27  TEXT ·Call(SB), NOSPLIT|NOFRAME, $0-48
    28  	MOVWU frameSize+32(FP), R1
    29  	DISPATCH(·call16, 16)
    30  	DISPATCH(·call32, 32)
    31  	DISPATCH(·call64, 64)
    32  	DISPATCH(·call128, 128)
    33  	DISPATCH(·call256, 256)
    34  	DISPATCH(·call512, 512)
    35  	DISPATCH(·call1024, 1024)
    36  	DISPATCH(·call2048, 2048)
    37  	DISPATCH(·call4096, 4096)
    38  	DISPATCH(·call8192, 8192)
    39  	DISPATCH(·call16384, 16384)
    40  	DISPATCH(·call32768, 32768)
    41  	DISPATCH(·call65536, 65536)
    42  	DISPATCH(·call131072, 131072)
    43  	DISPATCH(·call262144, 262144)
    44  	DISPATCH(·call524288, 524288)
    45  	DISPATCH(·call1048576, 1048576)
    46  	DISPATCH(·call2097152, 2097152)
    47  	DISPATCH(·call4194304, 4194304)
    48  	DISPATCH(·call8388608, 8388608)
    49  	DISPATCH(·call16777216, 16777216)
    50  	DISPATCH(·call33554432, 33554432)
    51  	DISPATCH(·call67108864, 67108864)
    52  	DISPATCH(·call134217728, 134217728)
    53  	DISPATCH(·call268435456, 268435456)
    54  	DISPATCH(·call536870912, 536870912)
    55  	DISPATCH(·call1073741824, 1073741824)
    56  	MOVV $·badreflectcall(SB), R4
    57  	JMP (R4)
    58  
    59  #define CALLFN(NAME,MAXSIZE)			\
    60  TEXT NAME(SB), WRAPPER, $MAXSIZE-48;		\
    61  	NO_LOCAL_POINTERS;			\
    62  	/* copy arguments to stack */		\
    63  	MOVV stackArgs+16(FP), R1;			\
    64  	MOVWU stackArgsSize+24(FP), R2;			\
    65  	MOVV R29, R3;				\
    66  	ADDV $8, R3;			\
    67  	ADDV R3, R2;				\
    68  	BEQ R3, R2, 6(PC);				\
    69  	MOVBU (R1), R4;			\
    70  	ADDV $1, R1;			\
    71  	MOVBU R4, (R3);			\
    72  	ADDV $1, R3;			\
    73  	JMP -5(PC);				\
    74  	/* call function */			\
    75  	MOVV f+8(FP), REGCTXT;			\
    76  	MOVV (REGCTXT), R4;			\
    77  	PCDATA  $PCDATA_StackMapIndex, $0;	\
    78  	JAL (R4);				\
    79  	/* copy return values back */		\
    80  	MOVV stackArgsType+0(FP), R5;		\
    81  	MOVV stackArgs+16(FP), R1;			\
    82  	MOVWU stackArgsSize+24(FP), R2;			\
    83  	MOVWU stackRetOffset+28(FP), R4;		\
    84  	ADDV $8, R29, R3;				\
    85  	ADDV R4, R3; 			\
    86  	ADDV R4, R1;				\
    87  	SUBVU R4, R2;				\
    88  	JAL callRet<>(SB);			\
    89  	RET
    90  
    91  // callRet copies return values back at the end of call*. This is a
    92  // separate function so it can allocate stack space for the arguments
    93  // to reflectcallmove. It does not follow the Go ABI; it expects its
    94  // arguments in registers.
    95  TEXT callRet<>(SB), NOSPLIT, $40-0
    96  	MOVV R5, 8(R29)
    97  	MOVV R1, 16(R29)
    98  	MOVV R3, 24(R29)
    99  	MOVV R2, 32(R29)
   100  	MOVV $0, 40(R29)
   101  	JAL ·reflectcallmove(SB)
   102  	RET
   103  
   104  CALLFN(·call16, 16)
   105  CALLFN(·call32, 32)
   106  CALLFN(·call64, 64)
   107  CALLFN(·call128, 128)
   108  CALLFN(·call256, 256)
   109  CALLFN(·call512, 512)
   110  CALLFN(·call1024, 1024)
   111  CALLFN(·call2048, 2048)
   112  CALLFN(·call4096, 4096)
   113  CALLFN(·call8192, 8192)
   114  CALLFN(·call16384, 16384)
   115  CALLFN(·call32768, 32768)
   116  CALLFN(·call65536, 65536)
   117  CALLFN(·call131072, 131072)
   118  CALLFN(·call262144, 262144)
   119  CALLFN(·call524288, 524288)
   120  CALLFN(·call1048576, 1048576)
   121  CALLFN(·call2097152, 2097152)
   122  CALLFN(·call4194304, 4194304)
   123  CALLFN(·call8388608, 8388608)
   124  CALLFN(·call16777216, 16777216)
   125  CALLFN(·call33554432, 33554432)
   126  CALLFN(·call67108864, 67108864)
   127  CALLFN(·call134217728, 134217728)
   128  CALLFN(·call268435456, 268435456)
   129  CALLFN(·call536870912, 536870912)
   130  CALLFN(·call1073741824, 1073741824)