/*
- * Copyright (C) 2013-2019 Free Software Foundation, Inc.
+ * Copyright (C) 2013-2023 Free Software Foundation, Inc.
*
* This file is part of GNU lightning.
*
*/
static jit_int16_t _szs[jit_code_last_code] = {
#if GET_JIT_SIZE
-# define JIT_INSTR_MAX 256
+# define JIT_INSTR_MAX 1024
#else
# if defined(__i386__) || defined(__x86_64__)
# include "jit_x86-sz.c"
# include "jit_alpha-sz.c"
# elif defined(__riscv)
# include "jit_riscv-sz.c"
+# elif defined(__loongarch__)
+# include "jit_loongarch-sz.c"
# endif
#endif
};
{
jit_word_t size;
jit_node_t *node;
+# if __riscv && __WORDSIZE == 64
+ jit_word_t extra = 0;
+# endif
- for (size = JIT_INSTR_MAX, node = _jitc->head; node; node = node->next)
- size += _szs[node->code];
+ for (size = JIT_INSTR_MAX, node = _jitc->head; node; node = node->next) {
+# if __riscv && __WORDSIZE == 64
+ /* Get estimative of extra memory for constants at end of code. */
+ switch (node->code) {
+ case jit_code_movi:
+ case jit_code_movi_f:
+ case jit_code_movi_d:
+ case jit_code_jmpi:
+ case jit_code_calli:
+ extra += sizeof(jit_word_t);
+ default:
+ break;
+ }
+# endif
+ switch (node->code) {
+ /* The instructions are special because they can be arbitrarily long. */
+ case jit_code_align:
+ case jit_code_skip:
+ size += node->u.w;
+ break;
+ default:
+ size += _szs[node->code];
+ }
+ }
+# if __riscv && __WORDSIZE == 64
+ /* Heuristically only 20% of constants are unique. */
+ size += extra / 5;
+# endif
return size;
}
{
#if GET_JIT_SIZE
FILE *fp;
- jit_word_t offset;
+ int offset;
/* Define a single path */
fp = fopen(JIT_SIZE_PATH, "a");