shithub: sl

Download patch

ref: be64464f816097083ea2dd347c90665e56883be8
parent: 4cada3c3b25f318dd1691ce92fb8283bae9f2bbf
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sun Feb 16 23:44:19 EST 2025

vm: most probable subcases first

--- a/src/vm.inc
+++ b/src/vm.inc
@@ -1,3 +1,4 @@
+
 #define fixnum_neg(x) ( \
 	i64 = -(int64_t)(numval(x)), \
 	i64 == INT64_MIN \
@@ -9,22 +10,22 @@
 	PUSH(FL(stack)[bp]);
 	NEXT_OP;
 
-OP(OP_TCALLL) {
-	tail = true;
+OP(OP_CALL) {
+	tail = false;
 	if(0){
-OP(OP_CALLL)
-		tail = false;
+OP(OP_TCALL)
+		tail = true;
 	}
-	n = GET_INT32(ip);
-	ip += 4;
+	n = *ip++;  // nargs
 	if(0){
-OP(OP_TCALL)
+OP(OP_TCALLL)
 		tail = true;
 		if(0){
-OP(OP_CALL)
+OP(OP_CALLL)
 			tail = false;
 		}
-		n = *ip++;  // nargs
+		n = GET_INT32(ip);
+		ip += 4;
 	}
 LABEL(do_call):
 	FL(stack)[ipd] = (uintptr_t)ip;
@@ -126,16 +127,16 @@
 	ip += POP() == FL_nil ? GET_INT16(ip) : 2;
 	NEXT_OP;
 
-OP(OP_LOADGL) {
+OP(OP_LOADG) {
 	value_t v = fn_vals(FL(stack)[bp-1]);
-	v = vector_elt(v, GET_INT32(ip));
-	ip += 4;
+	assert(*ip < vector_size(v));
+	v = vector_elt(v, *ip);
+	ip++;
 	if(0){
-OP(OP_LOADG)
+OP(OP_LOADGL)
 		v = fn_vals(FL(stack)[bp-1]);
-		assert(*ip < vector_size(v));
-		v = vector_elt(v, *ip);
-		ip++;
+		v = vector_elt(v, GET_INT32(ip));
+		ip += 4;
 	}
 	assert(issymbol(v));
 	symbol_t *sym = ptr(v);
@@ -195,20 +196,18 @@
 		int64_t i64;
 		FL(stack)[FL(sp)-1] = isfixnum(v) ? fixnum_neg(v) : fl_neg(v);
 	}
-	{
-		value_t a, b, q;
-		a = FL(stack)[FL(sp)-2];
-		b = FL(stack)[FL(sp)-1];
-		if(bothfixnums(a, b) && !sadd_overflow(numval(a), numval(b), &q) && fits_fixnum(q)){
-			v = fixnum(q);
-		}else{
-			v = fl_add_any(&FL(stack)[FL(sp)-2], 2);
-		}
-	}
+	value_t a, b, q;
+	a = FL(stack)[FL(sp)-2];
+	b = FL(stack)[FL(sp)-1];
+	if(bothfixnums(a, b) && !sadd_overflow(numval(a), numval(b), &q) && fits_fixnum(q))
+		v = fixnum(q);
+	else
+		v = fl_add_any(&FL(stack)[FL(sp)-2], 2);
 	POPN(1);
 	FL(stack)[FL(sp)-1] = v;
 	NEXT_OP;
 }
+
 OP(OP_LOADI8)
 	PUSH(fixnum((int8_t)*ip++));
 	NEXT_OP;