- 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