github.com/goplus/reflectx@v1.2.2/internal/icall512/icall_regabi.go (about)

     1  //go:build ((go1.17 && goexperiment.regabireflect) || (go1.19 && goexperiment.regabiargs) || (go1.18 && amd64) || (go1.19 && arm64) || (go1.19 && ppc64) || (go1.19 && ppc64le) || (go1.20 && riscv64)) && (!js || (js && wasm))
     2  // +build go1.17,goexperiment.regabireflect go1.19,goexperiment.regabiargs go1.18,amd64 go1.19,arm64 go1.19,ppc64 go1.19,ppc64le go1.20,riscv64
     3  // +build !js js,wasm
     4  
     5  package icall
     6  
     7  import (
     8  	"reflect"
     9  	"unsafe"
    10  
    11  	"github.com/goplus/reflectx/abi"
    12  )
    13  
    14  const capacity = 512
    15  
    16  type methodUsed struct {
    17  	fun reflect.Value
    18  	ptr unsafe.Pointer
    19  }
    20  
    21  type provider struct {
    22  	used map[int]*methodUsed
    23  }
    24  
    25  //go:linkname callReflect reflect.callReflect
    26  func callReflect(ctxt unsafe.Pointer, frame unsafe.Pointer, retValid *bool, r unsafe.Pointer)
    27  
    28  //go:linkname moveMakeFuncArgPtrs reflect.moveMakeFuncArgPtrs
    29  func moveMakeFuncArgPtrs(ctx unsafe.Pointer, r unsafe.Pointer)
    30  
    31  func i_x(c unsafe.Pointer, frame unsafe.Pointer, retValid *bool, r unsafe.Pointer, index int) {
    32  	ptr := mp.used[index].ptr
    33  	moveMakeFuncArgPtrs(ptr, r)
    34  	callReflect(ptr, frame, retValid, r)
    35  }
    36  
    37  func spillArgs()
    38  func unspillArgs()
    39  
    40  func (p *provider) Insert(info *abi.MethodInfo) (unsafe.Pointer, int) {
    41  	var index = -1
    42  	for i := 0; i < capacity; i++ {
    43  		if _, ok := p.used[i]; !ok {
    44  			index = i
    45  			break
    46  		}
    47  	}
    48  	if index == -1 {
    49  		return nil, -1
    50  	}
    51  	var fn reflect.Value
    52  	if (!info.Pointer && !info.OnePtr) || info.Indirect {
    53  		ftyp := info.Func.Type()
    54  		numIn := ftyp.NumIn()
    55  		numOut := ftyp.NumOut()
    56  		in := make([]reflect.Type, numIn, numIn)
    57  		out := make([]reflect.Type, numOut, numOut)
    58  		in[0] = reflect.PtrTo(info.Type)
    59  		for i := 1; i < numIn; i++ {
    60  			in[i] = ftyp.In(i)
    61  		}
    62  		for i := 0; i < numOut; i++ {
    63  			out[i] = ftyp.Out(i)
    64  		}
    65  		ftyp = reflect.FuncOf(in, out, info.Variadic)
    66  		if info.Variadic {
    67  			fn = reflect.MakeFunc(ftyp, func(args []reflect.Value) []reflect.Value {
    68  				args[0] = args[0].Elem()
    69  				return info.Func.CallSlice(args)
    70  			})
    71  		} else {
    72  			fn = reflect.MakeFunc(ftyp, func(args []reflect.Value) []reflect.Value {
    73  				args[0] = args[0].Elem()
    74  				return info.Func.Call(args)
    75  			})
    76  		}
    77  	} else {
    78  		fn = info.Func
    79  	}
    80  	p.used[index] = &methodUsed{
    81  		fun: fn,
    82  		ptr: (*struct{ typ, ptr unsafe.Pointer })(unsafe.Pointer(&fn)).ptr,
    83  	}
    84  	icall := icall_fn[index]
    85  	return unsafe.Pointer(reflect.ValueOf(icall).Pointer()), index
    86  }
    87  
    88  func (p *provider) Remove(indexs []int) {
    89  	for _, n := range indexs {
    90  		delete(p.used, n)
    91  	}
    92  }
    93  
    94  func (p *provider) Available() int {
    95  	return capacity - len(p.used)
    96  }
    97  
    98  func (p *provider) Used() int {
    99  	return len(p.used)
   100  }
   101  
   102  func (p *provider) Cap() int {
   103  	return capacity
   104  }
   105  
   106  func (p *provider) Clear() {
   107  	p.used = make(map[int]*methodUsed)
   108  }
   109  
   110  var (
   111  	mp = &provider{
   112  		used: make(map[int]*methodUsed),
   113  	}
   114  )
   115  
   116  func init() {
   117  	abi.AddMethodProvider(mp)
   118  }
   119  
   120  func f0()
   121  func f1()
   122  func f2()
   123  func f3()
   124  func f4()
   125  func f5()
   126  func f6()
   127  func f7()
   128  func f8()
   129  func f9()
   130  func f10()
   131  func f11()
   132  func f12()
   133  func f13()
   134  func f14()
   135  func f15()
   136  func f16()
   137  func f17()
   138  func f18()
   139  func f19()
   140  func f20()
   141  func f21()
   142  func f22()
   143  func f23()
   144  func f24()
   145  func f25()
   146  func f26()
   147  func f27()
   148  func f28()
   149  func f29()
   150  func f30()
   151  func f31()
   152  func f32()
   153  func f33()
   154  func f34()
   155  func f35()
   156  func f36()
   157  func f37()
   158  func f38()
   159  func f39()
   160  func f40()
   161  func f41()
   162  func f42()
   163  func f43()
   164  func f44()
   165  func f45()
   166  func f46()
   167  func f47()
   168  func f48()
   169  func f49()
   170  func f50()
   171  func f51()
   172  func f52()
   173  func f53()
   174  func f54()
   175  func f55()
   176  func f56()
   177  func f57()
   178  func f58()
   179  func f59()
   180  func f60()
   181  func f61()
   182  func f62()
   183  func f63()
   184  func f64()
   185  func f65()
   186  func f66()
   187  func f67()
   188  func f68()
   189  func f69()
   190  func f70()
   191  func f71()
   192  func f72()
   193  func f73()
   194  func f74()
   195  func f75()
   196  func f76()
   197  func f77()
   198  func f78()
   199  func f79()
   200  func f80()
   201  func f81()
   202  func f82()
   203  func f83()
   204  func f84()
   205  func f85()
   206  func f86()
   207  func f87()
   208  func f88()
   209  func f89()
   210  func f90()
   211  func f91()
   212  func f92()
   213  func f93()
   214  func f94()
   215  func f95()
   216  func f96()
   217  func f97()
   218  func f98()
   219  func f99()
   220  func f100()
   221  func f101()
   222  func f102()
   223  func f103()
   224  func f104()
   225  func f105()
   226  func f106()
   227  func f107()
   228  func f108()
   229  func f109()
   230  func f110()
   231  func f111()
   232  func f112()
   233  func f113()
   234  func f114()
   235  func f115()
   236  func f116()
   237  func f117()
   238  func f118()
   239  func f119()
   240  func f120()
   241  func f121()
   242  func f122()
   243  func f123()
   244  func f124()
   245  func f125()
   246  func f126()
   247  func f127()
   248  func f128()
   249  func f129()
   250  func f130()
   251  func f131()
   252  func f132()
   253  func f133()
   254  func f134()
   255  func f135()
   256  func f136()
   257  func f137()
   258  func f138()
   259  func f139()
   260  func f140()
   261  func f141()
   262  func f142()
   263  func f143()
   264  func f144()
   265  func f145()
   266  func f146()
   267  func f147()
   268  func f148()
   269  func f149()
   270  func f150()
   271  func f151()
   272  func f152()
   273  func f153()
   274  func f154()
   275  func f155()
   276  func f156()
   277  func f157()
   278  func f158()
   279  func f159()
   280  func f160()
   281  func f161()
   282  func f162()
   283  func f163()
   284  func f164()
   285  func f165()
   286  func f166()
   287  func f167()
   288  func f168()
   289  func f169()
   290  func f170()
   291  func f171()
   292  func f172()
   293  func f173()
   294  func f174()
   295  func f175()
   296  func f176()
   297  func f177()
   298  func f178()
   299  func f179()
   300  func f180()
   301  func f181()
   302  func f182()
   303  func f183()
   304  func f184()
   305  func f185()
   306  func f186()
   307  func f187()
   308  func f188()
   309  func f189()
   310  func f190()
   311  func f191()
   312  func f192()
   313  func f193()
   314  func f194()
   315  func f195()
   316  func f196()
   317  func f197()
   318  func f198()
   319  func f199()
   320  func f200()
   321  func f201()
   322  func f202()
   323  func f203()
   324  func f204()
   325  func f205()
   326  func f206()
   327  func f207()
   328  func f208()
   329  func f209()
   330  func f210()
   331  func f211()
   332  func f212()
   333  func f213()
   334  func f214()
   335  func f215()
   336  func f216()
   337  func f217()
   338  func f218()
   339  func f219()
   340  func f220()
   341  func f221()
   342  func f222()
   343  func f223()
   344  func f224()
   345  func f225()
   346  func f226()
   347  func f227()
   348  func f228()
   349  func f229()
   350  func f230()
   351  func f231()
   352  func f232()
   353  func f233()
   354  func f234()
   355  func f235()
   356  func f236()
   357  func f237()
   358  func f238()
   359  func f239()
   360  func f240()
   361  func f241()
   362  func f242()
   363  func f243()
   364  func f244()
   365  func f245()
   366  func f246()
   367  func f247()
   368  func f248()
   369  func f249()
   370  func f250()
   371  func f251()
   372  func f252()
   373  func f253()
   374  func f254()
   375  func f255()
   376  func f256()
   377  func f257()
   378  func f258()
   379  func f259()
   380  func f260()
   381  func f261()
   382  func f262()
   383  func f263()
   384  func f264()
   385  func f265()
   386  func f266()
   387  func f267()
   388  func f268()
   389  func f269()
   390  func f270()
   391  func f271()
   392  func f272()
   393  func f273()
   394  func f274()
   395  func f275()
   396  func f276()
   397  func f277()
   398  func f278()
   399  func f279()
   400  func f280()
   401  func f281()
   402  func f282()
   403  func f283()
   404  func f284()
   405  func f285()
   406  func f286()
   407  func f287()
   408  func f288()
   409  func f289()
   410  func f290()
   411  func f291()
   412  func f292()
   413  func f293()
   414  func f294()
   415  func f295()
   416  func f296()
   417  func f297()
   418  func f298()
   419  func f299()
   420  func f300()
   421  func f301()
   422  func f302()
   423  func f303()
   424  func f304()
   425  func f305()
   426  func f306()
   427  func f307()
   428  func f308()
   429  func f309()
   430  func f310()
   431  func f311()
   432  func f312()
   433  func f313()
   434  func f314()
   435  func f315()
   436  func f316()
   437  func f317()
   438  func f318()
   439  func f319()
   440  func f320()
   441  func f321()
   442  func f322()
   443  func f323()
   444  func f324()
   445  func f325()
   446  func f326()
   447  func f327()
   448  func f328()
   449  func f329()
   450  func f330()
   451  func f331()
   452  func f332()
   453  func f333()
   454  func f334()
   455  func f335()
   456  func f336()
   457  func f337()
   458  func f338()
   459  func f339()
   460  func f340()
   461  func f341()
   462  func f342()
   463  func f343()
   464  func f344()
   465  func f345()
   466  func f346()
   467  func f347()
   468  func f348()
   469  func f349()
   470  func f350()
   471  func f351()
   472  func f352()
   473  func f353()
   474  func f354()
   475  func f355()
   476  func f356()
   477  func f357()
   478  func f358()
   479  func f359()
   480  func f360()
   481  func f361()
   482  func f362()
   483  func f363()
   484  func f364()
   485  func f365()
   486  func f366()
   487  func f367()
   488  func f368()
   489  func f369()
   490  func f370()
   491  func f371()
   492  func f372()
   493  func f373()
   494  func f374()
   495  func f375()
   496  func f376()
   497  func f377()
   498  func f378()
   499  func f379()
   500  func f380()
   501  func f381()
   502  func f382()
   503  func f383()
   504  func f384()
   505  func f385()
   506  func f386()
   507  func f387()
   508  func f388()
   509  func f389()
   510  func f390()
   511  func f391()
   512  func f392()
   513  func f393()
   514  func f394()
   515  func f395()
   516  func f396()
   517  func f397()
   518  func f398()
   519  func f399()
   520  func f400()
   521  func f401()
   522  func f402()
   523  func f403()
   524  func f404()
   525  func f405()
   526  func f406()
   527  func f407()
   528  func f408()
   529  func f409()
   530  func f410()
   531  func f411()
   532  func f412()
   533  func f413()
   534  func f414()
   535  func f415()
   536  func f416()
   537  func f417()
   538  func f418()
   539  func f419()
   540  func f420()
   541  func f421()
   542  func f422()
   543  func f423()
   544  func f424()
   545  func f425()
   546  func f426()
   547  func f427()
   548  func f428()
   549  func f429()
   550  func f430()
   551  func f431()
   552  func f432()
   553  func f433()
   554  func f434()
   555  func f435()
   556  func f436()
   557  func f437()
   558  func f438()
   559  func f439()
   560  func f440()
   561  func f441()
   562  func f442()
   563  func f443()
   564  func f444()
   565  func f445()
   566  func f446()
   567  func f447()
   568  func f448()
   569  func f449()
   570  func f450()
   571  func f451()
   572  func f452()
   573  func f453()
   574  func f454()
   575  func f455()
   576  func f456()
   577  func f457()
   578  func f458()
   579  func f459()
   580  func f460()
   581  func f461()
   582  func f462()
   583  func f463()
   584  func f464()
   585  func f465()
   586  func f466()
   587  func f467()
   588  func f468()
   589  func f469()
   590  func f470()
   591  func f471()
   592  func f472()
   593  func f473()
   594  func f474()
   595  func f475()
   596  func f476()
   597  func f477()
   598  func f478()
   599  func f479()
   600  func f480()
   601  func f481()
   602  func f482()
   603  func f483()
   604  func f484()
   605  func f485()
   606  func f486()
   607  func f487()
   608  func f488()
   609  func f489()
   610  func f490()
   611  func f491()
   612  func f492()
   613  func f493()
   614  func f494()
   615  func f495()
   616  func f496()
   617  func f497()
   618  func f498()
   619  func f499()
   620  func f500()
   621  func f501()
   622  func f502()
   623  func f503()
   624  func f504()
   625  func f505()
   626  func f506()
   627  func f507()
   628  func f508()
   629  func f509()
   630  func f510()
   631  func f511()
   632  
   633  var (
   634  	icall_fn = []func(){f0,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,f25,f26,f27,f28,f29,f30,f31,f32,f33,f34,f35,f36,f37,f38,f39,f40,f41,f42,f43,f44,f45,f46,f47,f48,f49,f50,f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f62,f63,f64,f65,f66,f67,f68,f69,f70,f71,f72,f73,f74,f75,f76,f77,f78,f79,f80,f81,f82,f83,f84,f85,f86,f87,f88,f89,f90,f91,f92,f93,f94,f95,f96,f97,f98,f99,f100,f101,f102,f103,f104,f105,f106,f107,f108,f109,f110,f111,f112,f113,f114,f115,f116,f117,f118,f119,f120,f121,f122,f123,f124,f125,f126,f127,f128,f129,f130,f131,f132,f133,f134,f135,f136,f137,f138,f139,f140,f141,f142,f143,f144,f145,f146,f147,f148,f149,f150,f151,f152,f153,f154,f155,f156,f157,f158,f159,f160,f161,f162,f163,f164,f165,f166,f167,f168,f169,f170,f171,f172,f173,f174,f175,f176,f177,f178,f179,f180,f181,f182,f183,f184,f185,f186,f187,f188,f189,f190,f191,f192,f193,f194,f195,f196,f197,f198,f199,f200,f201,f202,f203,f204,f205,f206,f207,f208,f209,f210,f211,f212,f213,f214,f215,f216,f217,f218,f219,f220,f221,f222,f223,f224,f225,f226,f227,f228,f229,f230,f231,f232,f233,f234,f235,f236,f237,f238,f239,f240,f241,f242,f243,f244,f245,f246,f247,f248,f249,f250,f251,f252,f253,f254,f255,f256,f257,f258,f259,f260,f261,f262,f263,f264,f265,f266,f267,f268,f269,f270,f271,f272,f273,f274,f275,f276,f277,f278,f279,f280,f281,f282,f283,f284,f285,f286,f287,f288,f289,f290,f291,f292,f293,f294,f295,f296,f297,f298,f299,f300,f301,f302,f303,f304,f305,f306,f307,f308,f309,f310,f311,f312,f313,f314,f315,f316,f317,f318,f319,f320,f321,f322,f323,f324,f325,f326,f327,f328,f329,f330,f331,f332,f333,f334,f335,f336,f337,f338,f339,f340,f341,f342,f343,f344,f345,f346,f347,f348,f349,f350,f351,f352,f353,f354,f355,f356,f357,f358,f359,f360,f361,f362,f363,f364,f365,f366,f367,f368,f369,f370,f371,f372,f373,f374,f375,f376,f377,f378,f379,f380,f381,f382,f383,f384,f385,f386,f387,f388,f389,f390,f391,f392,f393,f394,f395,f396,f397,f398,f399,f400,f401,f402,f403,f404,f405,f406,f407,f408,f409,f410,f411,f412,f413,f414,f415,f416,f417,f418,f419,f420,f421,f422,f423,f424,f425,f426,f427,f428,f429,f430,f431,f432,f433,f434,f435,f436,f437,f438,f439,f440,f441,f442,f443,f444,f445,f446,f447,f448,f449,f450,f451,f452,f453,f454,f455,f456,f457,f458,f459,f460,f461,f462,f463,f464,f465,f466,f467,f468,f469,f470,f471,f472,f473,f474,f475,f476,f477,f478,f479,f480,f481,f482,f483,f484,f485,f486,f487,f488,f489,f490,f491,f492,f493,f494,f495,f496,f497,f498,f499,f500,f501,f502,f503,f504,f505,f506,f507,f508,f509,f510,f511}
   635  )