Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove no-op OP_swap+OP_swap bytecode sequence #143

Merged
merged 1 commit into from
Nov 26, 2023

Conversation

bnoordhuis
Copy link
Contributor

Observed in generated code for static initializers. We could in theory track and correct it in js_parse_class() but doing it as a peephole optimization is both easier and more general.

Observed in generated code for static initializers. We could in theory
track and correct it in js_parse_class() but doing it as a peephole
optimization is both easier and more general.
@saghul
Copy link
Contributor

saghul commented Nov 26, 2023

Out of curiosity how are you digging these things up?

@bnoordhuis
Copy link
Contributor Author

puts() and patience basically :-)

diff --git a/quickjs.c b/quickjs.c
index e9f5197..e9cd759 100644
--- a/quickjs.c
+++ b/quickjs.c
@@ -14170,7 +14170,12 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
 #include "quickjs-opcode.h"
         [ OP_COUNT ... 255 ] = &&case_default
     };
-#define SWITCH(pc)      goto *dispatch_table[opcode = *pc++];
+    static const char * const opnames[] = {
+#undef DEF
+#define DEF(id, size, n_pop, n_push, f) #id,
+#include "quickjs-opcode.h"
+    };
+#define SWITCH(pc)      puts(opnames[*pc]); goto *dispatch_table[opcode = *pc++];
 #define CASE(op)        case_ ## op
 #define DEFAULT         case_default
 #define BREAK           SWITCH(pc)

@bnoordhuis bnoordhuis merged commit 51633af into quickjs-ng:master Nov 26, 2023
21 checks passed
@bnoordhuis bnoordhuis deleted the swap-swap branch November 26, 2023 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants