github.com/goccy/go-jit@v0.0.0-20200514131505-ff78d45cf6af/internal/ccall/jit-apply-rules.h (about)

     1  /* This file was auto-generated by "gen-apply" - DO NOT EDIT */
     2  
     3  #ifndef _JIT_APPLY_RULES_H
     4  #define _JIT_APPLY_RULES_H
     5  
     6  #define JIT_APPLY_NUM_WORD_REGS 8
     7  #define JIT_APPLY_NUM_FLOAT_REGS 13
     8  #define JIT_APPLY_NUM_DOUBLE_REGS 0
     9  #define JIT_APPLY_NUM_NFLOAT_REGS 0
    10  #define JIT_APPLY_PASS_STACK_FLOAT_AS_DOUBLE 0
    11  #define JIT_APPLY_PASS_STACK_FLOAT_AS_NFLOAT 0
    12  #define JIT_APPLY_PASS_STACK_DOUBLE_AS_NFLOAT 0
    13  #define JIT_APPLY_PASS_STACK_NFLOAT_AS_DOUBLE 1
    14  #define JIT_APPLY_PASS_REG_FLOAT_AS_DOUBLE 1
    15  #define JIT_APPLY_PASS_REG_FLOAT_AS_NFLOAT 0
    16  #define JIT_APPLY_PASS_REG_DOUBLE_AS_NFLOAT 0
    17  #define JIT_APPLY_PASS_REG_NFLOAT_AS_DOUBLE 1
    18  #define JIT_APPLY_RETURN_FLOAT_AS_DOUBLE 1
    19  #define JIT_APPLY_RETURN_FLOAT_AS_NFLOAT 0
    20  #define JIT_APPLY_RETURN_DOUBLE_AS_NFLOAT 0
    21  #define JIT_APPLY_RETURN_NFLOAT_AS_DOUBLE 1
    22  #define JIT_APPLY_FLOATS_IN_WORD_REGS 0
    23  #define JIT_APPLY_DOUBLES_IN_WORD_REGS 0
    24  #define JIT_APPLY_NFLOATS_IN_WORD_REGS 0
    25  #define JIT_APPLY_RETURN_FLOATS_AFTER 8
    26  #define JIT_APPLY_RETURN_DOUBLES_AFTER 0
    27  #define JIT_APPLY_RETURN_NFLOATS_AFTER 0
    28  #define JIT_APPLY_VARARGS_ON_STACK 0
    29  #define JIT_APPLY_STRUCT_RETURN_SPECIAL_REG 0
    30  #define JIT_APPLY_STRUCT_REG_OVERLAPS_WORD_REG 0
    31  #define JIT_APPLY_ALIGN_LONG_REGS 1
    32  #define JIT_APPLY_ALIGN_LONG_STACK 1
    33  #define JIT_APPLY_CAN_SPLIT_LONG 0
    34  #define JIT_APPLY_STRUCT_RETURN_IN_REG_INIT \
    35  	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
    36  #define JIT_APPLY_MAX_STRUCT_IN_REG 0
    37  #define JIT_APPLY_MAX_APPLY_SIZE 184
    38  #define JIT_APPLY_X86_FASTCALL 0
    39  #define JIT_APPLY_PARENT_FRAME_OFFSET 0
    40  #define JIT_APPLY_RETURN_ADDRESS_OFFSET 0
    41  #define JIT_APPLY_BROKEN_FRAME_BUILTINS 1
    42  #define JIT_APPLY_X86_POP_STRUCT_RETURN 0
    43  #define JIT_APPLY_PAD_FLOAT_REGS 1
    44  
    45  typedef union
    46  {
    47  	jit_nint int_value;
    48  	jit_nuint uint_value;
    49  	jit_long long_value;
    50  	jit_ulong ulong_value;
    51  	struct { jit_ubyte pad[8]; double f_value; } float_value;
    52  	struct { double f_value; } double_value;
    53  	struct { double f_value; } nfloat_value;
    54  
    55  } jit_apply_return;
    56  
    57  #define jit_apply_return_get_sbyte(result)	\
    58  	((jit_sbyte)((result)->int_value))
    59  #define jit_apply_return_get_ubyte(result)	\
    60  	((jit_ubyte)((result)->int_value))
    61  #define jit_apply_return_get_short(result)	\
    62  	((jit_short)((result)->int_value))
    63  #define jit_apply_return_get_ushort(result)	\
    64  	((jit_ushort)((result)->int_value))
    65  #define jit_apply_return_get_int(result)	\
    66  	((jit_int)((result)->int_value))
    67  #define jit_apply_return_get_uint(result)	\
    68  	((jit_uint)((result)->uint_value))
    69  #define jit_apply_return_get_nint(result)	\
    70  	((jit_nint)((result)->int_value))
    71  #define jit_apply_return_get_nuint(result)	\
    72  	((jit_nuint)((result)->uint_value))
    73  #define jit_apply_return_get_long(result)	\
    74  	((jit_long)((result)->long_value))
    75  #define jit_apply_return_get_ulong(result)	\
    76  	((jit_ulong)((result)->ulong_value))
    77  #define jit_apply_return_get_float32(result)	\
    78  	((jit_float32)((result)->float_value.f_value))
    79  #define jit_apply_return_get_float64(result)	\
    80  	((jit_float64)((result)->double_value.f_value))
    81  #define jit_apply_return_get_nfloat(result)	\
    82  	((jit_nfloat)((result)->nfloat_value.f_value))
    83  
    84  #define jit_apply_return_set_sbyte(result,value)	\
    85  	(((result)->int_value) = ((jit_nint)(value)))
    86  #define jit_apply_return_set_ubyte(result,value)	\
    87  	(((result)->int_value) = ((jit_nint)(value)))
    88  #define jit_apply_return_set_short(result,value)	\
    89  	(((result)->int_value) = ((jit_nint)(value)))
    90  #define jit_apply_return_set_ushort(result,value)	\
    91  	(((result)->int_value) = ((jit_nint)(value)))
    92  #define jit_apply_return_set_int(result,value)	\
    93  	(((result)->int_value) = ((jit_nint)(value)))
    94  #define jit_apply_return_set_uint(result,value)	\
    95  	(((result)->uint_value) = ((jit_nuint)(value)))
    96  #define jit_apply_return_set_nint(result,value)	\
    97  	(((result)->int_value) = ((jit_nint)(value)))
    98  #define jit_apply_return_set_nuint(result,value)	\
    99  	(((result)->uint_value) = ((jit_nuint)(value)))
   100  #define jit_apply_return_set_long(result,value)	\
   101  	(((result)->long_value) = ((jit_long)(value)))
   102  #define jit_apply_return_set_ulong(result,value)	\
   103  	(((result)->ulong_value) = ((jit_ulong)(value)))
   104  #define jit_apply_return_set_float32(result,value)	\
   105  	(((result)->float_value.f_value) = ((double)(value)))
   106  #define jit_apply_return_set_float64(result,value)	\
   107  	(((result)->double_value.f_value) = ((double)(value)))
   108  #define jit_apply_return_set_nfloat(result,value)	\
   109  	(((result)->nfloat_value.f_value) = ((double)(value)))
   110  
   111  typedef jit_float64 jit_reg_float;
   112  
   113  typedef union
   114  {
   115  	jit_reg_float float_value;
   116  	char __pad[16];
   117  } jit_reg_float_struct;
   118  
   119  typedef struct
   120  {
   121  	unsigned char *stack_args;
   122  	jit_nint word_regs[8];
   123  	jit_nint pad[1];
   124  	jit_reg_float_struct float_regs[13];
   125  
   126  } jit_apply_struct;
   127  
   128  typedef struct
   129  {
   130  	jit_apply_struct *apply_args;
   131  	unsigned int stack_used;
   132  	unsigned int word_used;
   133  	unsigned int float_used;
   134  	void *struct_return;
   135  
   136  } jit_apply_builder;
   137  
   138  #include "jit-apply-func.h"
   139  
   140  void
   141  _jit_builtin_apply_add_struct(jit_apply_builder *builder, void *value, jit_type_t struct_type);
   142  
   143  void
   144  _jit_builtin_apply_get_struct(jit_apply_builder *builder, void *value, jit_type_t struct_type);
   145  
   146  void
   147  _jit_builtin_apply_get_struct_return(jit_apply_builder *builder, void *return_value, jit_apply_return *apply_return, jit_type_t struct_type);
   148  
   149  #define jit_apply_builder_init(builder,type)	\
   150  	do { \
   151  		(builder)->apply_args = (jit_apply_struct *)alloca(sizeof(jit_apply_struct)); \
   152  		jit_memset((builder)->apply_args, 0, 184); \
   153  		(builder)->apply_args->stack_args = (unsigned char *)alloca(jit_type_get_max_arg_size((type))); \
   154  		(builder)->stack_used = 0; \
   155  		(builder)->word_used = 0; \
   156  		(builder)->float_used = 0; \
   157  		(builder)->struct_return = 0; \
   158  	} while (0)
   159  
   160  #define jit_apply_parser_init(builder,type,args)	\
   161  	do { \
   162  		(builder)->apply_args = (jit_apply_struct *)(args); \
   163  		(builder)->stack_used = 0; \
   164  		(builder)->word_used = 0; \
   165  		(builder)->float_used = 0; \
   166  		(builder)->struct_return = 0; \
   167  	} while (0)
   168  
   169  #define jit_apply_builder_add_word(builder,value) \
   170  	do { \
   171  		if((builder)->word_used < 8) \
   172  		{ \
   173  			(builder)->apply_args->word_regs[(builder)->word_used] = (jit_nint)(value); \
   174  			++((builder)->word_used); \
   175  		} \
   176  		else \
   177  		{ \
   178  			*((jit_nint*)((builder)->apply_args->stack_args + (builder)->stack_used)) = (jit_nint)(value); \
   179  			(builder)->stack_used += sizeof(jit_nint); \
   180  		} \
   181  	} while (0)
   182  
   183  #define jit_apply_parser_get_word(builder,type,value) \
   184  	do { \
   185  		if((builder)->word_used < 8) \
   186  		{ \
   187  			(value) = (type)((builder)->apply_args->word_regs[(builder)->word_used]); \
   188  			++((builder)->word_used); \
   189  		} \
   190  		else \
   191  		{ \
   192  			(value) = (type)(*((jit_nint*)((builder)->apply_args->stack_args + (builder)->stack_used))); \
   193  			(builder)->stack_used += sizeof(jit_nint); \
   194  		} \
   195  	} while (0)
   196  
   197  #define jit_apply_builder_align_regs(builder,num_words,align) \
   198  	do { \
   199  		if((align) > sizeof(jit_nint) && (num_words) > 1) \
   200  		{ \
   201  			if(((builder)->word_used % 2) == 1) \
   202  			{ \
   203  				++((builder)->word_used); \
   204  			} \
   205  			if((8 - (builder)->word_used) < (num_words)) \
   206  			{ \
   207  				(builder)->word_used = 8; \
   208  			} \
   209  		} \
   210  	} while (0)
   211  
   212  #define jit_apply_builder_align_stack(builder,num_words,align) \
   213  	do { \
   214  		if((align) > sizeof(jit_nint) && (num_words) > 1) \
   215  		{ \
   216  			if(((builder)->stack_used % 2) == 1) \
   217  			{ \
   218  				++((builder)->stack_used); \
   219  			} \
   220  		} \
   221  	} while (0)
   222  
   223  #define jit_apply_builder_add_large_inner(builder,ptr,size,align) \
   224  	do { \
   225  		unsigned int __num_words = ((size) + sizeof(jit_nint) - 1) / sizeof(jit_nint); \
   226  		jit_apply_builder_align_regs((builder), __num_words, (align)); \
   227  		if((8 - (builder)->word_used) >= __num_words) \
   228  		{ \
   229  			jit_memcpy((builder)->apply_args->word_regs + (builder)->word_used, (ptr), (size)); \
   230  			(builder)->word_used += __num_words; \
   231  		} \
   232  		else if((builder)->word_used < 8) \
   233  		{ \
   234  			unsigned int __split = (8 - (builder)->word_used); \
   235  			jit_memcpy((builder)->apply_args->word_regs + (builder)->word_used, (ptr), __split * sizeof(jit_nint)); \
   236  			jit_memcpy((builder)->apply_args->stack_args, ((jit_nint *)(ptr)) + __split, (size) - __split * sizeof(jit_nint)); \
   237  			(builder)->word_used = 8; \
   238  			(builder)->stack_used = __num_words - __split; \
   239  		} \
   240  		else \
   241  		{ \
   242  			jit_apply_builder_align_stack((builder), __num_words, (align)); \
   243  			jit_memcpy((builder)->apply_args->stack_args + (builder)->stack_used, (ptr), (size)); \
   244  			(builder)->stack_used += __num_words * sizeof(jit_nint); \
   245  			(builder)->word_used = 8; \
   246  		} \
   247  	} while (0)
   248  
   249  #define jit_apply_builder_add_large(builder,type,value) \
   250  	do { \
   251  		type __temp = (type)(value); \
   252  		jit_apply_builder_add_large_inner((builder), &__temp, sizeof(__temp), sizeof(jit_nint)); \
   253  	} while (0)
   254  
   255  #define jit_apply_parser_get_large(builder,type,finaltype,value) \
   256  	do { \
   257  		type __temp; \
   258  		unsigned int __num_words = (sizeof(__temp) + sizeof(jit_nint) - 1) / sizeof(jit_nint); \
   259  		jit_apply_builder_align_regs((builder), __num_words, sizeof(type)); \
   260  		if((8 - (builder)->word_used) >= __num_words) \
   261  		{ \
   262  			jit_memcpy(&__temp, (builder)->apply_args->word_regs + (builder)->word_used, sizeof(__temp)); \
   263  			(builder)->word_used += __num_words; \
   264  		} \
   265  		else if((builder)->word_used < 8) \
   266  		{ \
   267  			unsigned int __split = (8 - (builder)->word_used); \
   268  			jit_memcpy(&__temp, (builder)->apply_args->word_regs + (builder)->word_used, __split * sizeof(jit_nint)); \
   269  			jit_memcpy(((jit_nint *)&__temp) + __split, (builder)->apply_args->stack_args, (__num_words - __split) * sizeof(jit_nint)); \
   270  			(builder)->word_used = 8; \
   271  			(builder)->stack_used = __num_words - __split; \
   272  		} \
   273  		else \
   274  		{ \
   275  			jit_apply_builder_align_stack((builder), __num_words, sizeof(type)); \
   276  			jit_memcpy(&__temp, (builder)->apply_args->stack_args + (builder)->stack_used, sizeof(__temp)); \
   277  			(builder)->stack_used += __num_words * sizeof(jit_nint); \
   278  			(builder)->word_used = 8; \
   279  		} \
   280  		(value) = (finaltype)(__temp); \
   281  	} while (0)
   282  
   283  #define jit_apply_builder_add_large_stack(builder,type,value) \
   284  	do { \
   285  		type __temp = (type)(value); \
   286  		unsigned int __num_words = (sizeof(__temp) + sizeof(jit_nint) - 1) / sizeof(jit_nint); \
   287  		jit_apply_builder_align_stack((builder), __num_words, sizeof(type)); \
   288  		jit_memcpy((builder)->apply_args->stack_args + (builder)->stack_used, &__temp, sizeof(__temp)); \
   289  		(builder)->stack_used += __num_words * sizeof(jit_nint); \
   290  	} while (0)
   291  
   292  #define jit_apply_parser_get_large_stack(builder,type,finaltype,value) \
   293  	do { \
   294  		type __temp; \
   295  		unsigned int __num_words = (sizeof(__temp) + sizeof(jit_nint) - 1) / sizeof(jit_nint); \
   296  		jit_apply_builder_align_stack((builder), __num_words, sizeof(type)); \
   297  		jit_memcpy(&__temp, (builder)->apply_args->stack_args + (builder)->stack_used, sizeof(__temp)); \
   298  		(builder)->stack_used += __num_words * sizeof(jit_nint); \
   299  		(value) = (finaltype)(__temp); \
   300  	} while (0)
   301  
   302  #define jit_apply_builder_add_struct_return(builder,size,return_buf) \
   303  	do { \
   304  		unsigned int __struct_size = (unsigned int)(size); \
   305  		if(__struct_size >= 1 && __struct_size <= 64 && \
   306  		   (_jit_apply_return_in_reg[(__struct_size - 1) / 8] \
   307  		       & (1 << ((__struct_size - 1) % 8))) != 0) \
   308  		{ \
   309  			(builder)->struct_return = 0; \
   310  		} \
   311  		else \
   312  		{ \
   313  			if((return_buf) != 0) \
   314  				(builder)->struct_return = (void *)(return_buf); \
   315  			else \
   316  				(builder)->struct_return = alloca(__struct_size); \
   317  			jit_apply_builder_add_word((builder), (builder)->struct_return); \
   318  		} \
   319  	} while (0)
   320  
   321  #define jit_apply_builder_get_struct_return(builder,size,return_buf,apply_return) \
   322  	do { \
   323  		if(!((builder)->struct_return)) \
   324  		{ \
   325  			jit_memcpy((return_buf), (apply_return), (size)); \
   326  		} \
   327  		else if((builder)->struct_return != (void *)(return_buf)) \
   328  		{ \
   329  			jit_memcpy((return_buf), (builder)->struct_return, (size)); \
   330  		} \
   331  	} while (0)
   332  
   333  #define jit_apply_builder_start_varargs(builder) \
   334  	do { \
   335  	} while (0)
   336  
   337  #define jit_apply_parser_start_varargs(builder) \
   338  	do { \
   339  	} while (0)
   340  
   341  #define jit_apply_builder_add_sbyte(builder,value) \
   342  	jit_apply_builder_add_word((builder), (value));
   343  #define jit_apply_builder_add_ubyte(builder,value) \
   344  	jit_apply_builder_add_word((builder), (value));
   345  #define jit_apply_builder_add_short(builder,value) \
   346  	jit_apply_builder_add_word((builder), (value));
   347  #define jit_apply_builder_add_ushort(builder,value) \
   348  	jit_apply_builder_add_word((builder), (value));
   349  #define jit_apply_builder_add_int(builder,value) \
   350  	jit_apply_builder_add_word((builder), (value));
   351  #define jit_apply_builder_add_uint(builder,value) \
   352  	jit_apply_builder_add_word((builder), (jit_nuint)(value));
   353  #define jit_apply_builder_add_nint(builder,value) \
   354  	jit_apply_builder_add_word((builder), (value));
   355  #define jit_apply_builder_add_nuint(builder,value) \
   356  	jit_apply_builder_add_word((builder), (jit_nuint)(value));
   357  #define jit_apply_builder_add_long(builder,value) \
   358  	jit_apply_builder_add_word((builder), (value));
   359  #define jit_apply_builder_add_ulong(builder,value) \
   360  	jit_apply_builder_add_word((builder), (jit_nuint)(value));
   361  #define jit_apply_builder_add_float32(builder,value) \
   362  	do { \
   363  		if((builder)->float_used < 13) \
   364  		{ \
   365  			(builder)->apply_args->float_regs[(builder)->float_used].float_value = (jit_reg_float)(value); \
   366  			++((builder)->float_used); \
   367  		} \
   368  		else \
   369  		{ \
   370  			jit_float32 __temp = (jit_float32)(value); \
   371  			jit_memcpy((builder)->apply_args->stack_args + (builder)->stack_used, &__temp, sizeof(__temp)); \
   372  			(builder)->stack_used += (sizeof(jit_float32) + sizeof(jit_nint) - 1) & ~(sizeof(jit_nint) - 1); \
   373  		} \
   374  	} while (0)
   375  #define jit_apply_builder_add_float64(builder,value) \
   376  	jit_apply_builder_add_large_stack((builder), jit_float64, (value));
   377  #define jit_apply_builder_add_nfloat(builder,value) \
   378  	jit_apply_builder_add_large_stack((builder), jit_float64, (value));
   379  #define jit_apply_builder_add_struct(builder,value,size,align) \
   380  	do { \
   381  		unsigned int __size = (size); \
   382  		unsigned int __align; __align = (align); \
   383  		jit_apply_builder_add_large_inner((builder), (value), __size, __align); \
   384  	} while (0)
   385  
   386  
   387  #define jit_apply_parser_get_sbyte(builder,value) \
   388  	jit_apply_parser_get_word((builder), jit_sbyte, (value));
   389  #define jit_apply_parser_get_ubyte(builder,value) \
   390  	jit_apply_parser_get_word((builder), jit_ubyte, (value));
   391  #define jit_apply_parser_get_short(builder,value) \
   392  	jit_apply_parser_get_word((builder), jit_short, (value));
   393  #define jit_apply_parser_get_ushort(builder,value) \
   394  	jit_apply_parser_get_word((builder), jit_ushort, (value));
   395  #define jit_apply_parser_get_int(builder,value) \
   396  	jit_apply_parser_get_word((builder), jit_int, (value));
   397  #define jit_apply_parser_get_uint(builder,value) \
   398  	jit_apply_parser_get_word((builder), jit_uint, (value));
   399  #define jit_apply_parser_get_nint(builder,value) \
   400  	jit_apply_parser_get_word((builder), jit_nint, (value));
   401  #define jit_apply_parser_get_nuint(builder,value) \
   402  	jit_apply_parser_get_word((builder), jit_nuint, (value));
   403  #define jit_apply_parser_get_long(builder,value) \
   404  	jit_apply_parser_get_word((builder), jit_long, (value));
   405  #define jit_apply_parser_get_ulong(builder,value) \
   406  	jit_apply_parser_get_word((builder), jit_ulong, (value));
   407  #define jit_apply_parser_get_float32(builder,value) \
   408  	do { \
   409  		if((builder)->float_used < 13) \
   410  		{ \
   411  			(value) = (jit_float32)((builder)->apply_args->float_regs[(builder)->float_used].float_value); \
   412  			++((builder)->float_used); \
   413  		} \
   414  		else \
   415  		{ \
   416  			jit_float32 __temp; \
   417  			jit_memcpy(&__temp, (builder)->apply_args->stack_args + (builder)->stack_used, sizeof(__temp)); \
   418  			(builder)->stack_used += (sizeof(jit_float32) + sizeof(jit_nint) - 1) & ~(sizeof(jit_nint) - 1); \
   419  			(value) = (jit_float32)__temp; \
   420  		} \
   421  	} while (0)
   422  #define jit_apply_parser_get_float64(builder,value) \
   423  	jit_apply_parser_get_large_stack((builder), jit_float64, jit_float64, (value));
   424  #define jit_apply_parser_get_nfloat(builder,value) \
   425  	jit_apply_parser_get_large_stack((builder), jit_float64, jit_nfloat, (value));
   426  #define jit_apply_parser_get_struct_return(builder,value) \
   427  	jit_apply_parser_get_word((builder), void *, (value));
   428  #define jit_apply_parser_get_struct(builder,size,align,value) \
   429  	do { \
   430  		unsigned int __size = (size); \
   431  		unsigned int __num_words = (__size + sizeof(jit_nint) - 1) / sizeof(jit_nint); \
   432  		if((8 - (builder)->word_used) >= __num_words) \
   433  		{ \
   434  			jit_memcpy((value), (builder)->apply_args->word_regs + (builder)->word_used, __size); \
   435  			(builder)->word_used += __num_words; \
   436  		} \
   437  		else \
   438  		{ \
   439  			jit_memcpy((value), (builder)->apply_args->stack_args + (builder)->stack_used, __size); \
   440  			(builder)->stack_used += __num_words * sizeof(jit_nint); \
   441  			(builder)->word_used = 8; \
   442  		} \
   443  	} while (0)
   444  
   445  #endif /* _JIT_APPLY_RULES_H */