fix: scf_inst_data_same() master
authoryu.dongliang <18588496441@163.com>
Mon, 11 Nov 2024 07:53:22 +0000 (15:53 +0800)
committeryu.dongliang <18588496441@163.com>
Mon, 11 Nov 2024 07:53:22 +0000 (15:53 +0800)
examples/coroutine_fmt.c [new file with mode: 0644]
native/scf_native.h
native/x64/scf_x64.c

diff --git a/examples/coroutine_fmt.c b/examples/coroutine_fmt.c
new file mode 100644 (file)
index 0000000..fa24b04
--- /dev/null
@@ -0,0 +1,13 @@
+int printf(const char* fmt, ...);
+
+int scf_async(uintptr_t funcptr, const char* fmt, ...)
+{
+       printf("fmt: %s\n", fmt);
+       return 0;
+}
+
+int main()
+{
+       async printf("hello world, %d\n", 1, 2, 3, 4, 5, 6, 7, 8);
+       return 0;
+}
index 74f68ae9676efc870bc9be9ce55abc18a163d9e0..f09571750b31e50f0036da476dd92f48001b6616 100644 (file)
@@ -6,7 +6,8 @@
 
 typedef struct scf_native_ops_s scf_native_ops_t;
 
-struct scf_register_s {
+struct scf_register_s
+{
        uint32_t                id;
        int                             bytes;
        char*                   name;
@@ -18,8 +19,10 @@ struct scf_register_s {
        uint32_t        updated;
        uint32_t        used;
 };
+#define SCF_COLOR_CONFLICT(c0, c1)   ((c0) >> 16 == (c1) >> 16 && (c0) & (c1) & 0xffff)
 
-struct scf_OpCode_s {
+struct scf_OpCode_s
+{
        int                             type;
        char*                   name;
 };
@@ -34,7 +37,6 @@ typedef struct {
 } scf_sib_t;
 
 typedef struct {
-
        scf_register_t* base;
        scf_register_t* index;
        int             scale;
@@ -47,7 +49,6 @@ typedef struct {
 } scf_inst_data_t;
 
 typedef struct {
-
        scf_3ac_code_t* c;
 
        scf_OpCode_t*   OpCode;
@@ -244,14 +245,20 @@ static inline int scf_inst_data_same(scf_inst_data_t* id0, scf_inst_data_t* id1)
        if ((id0->flag && !id0->base) || (id1->flag && !id1->base))
                return 0;
 
-       if (id0->base == id1->base
-                       && id0->scale == id1->scale
-                       && id0->index == id1->index
+       if (id0->scale == id1->scale
                        && id0->disp  == id1->disp
                        && id0->flag  == id1->flag
                        && id0->imm   == id1->imm
-                       && id0->imm_size == id1->imm_size)
-               return 1;
+                       && id0->imm_size == id1->imm_size) {
+
+               if (id0->base == id1->base
+               || (id0->base && id1->base && SCF_COLOR_CONFLICT(id0->base->color, id1->base->color))) {
+
+                       if (id0->index == id1->index
+                       || (id0->index && id1->index && SCF_COLOR_CONFLICT(id0->index->color, id1->index->color)))
+                               return 1;
+               }
+       }
        return 0;
 }
 
index 42cd47fd3dff917b09b5af195d436815f6654582..5ebd0629e29a4e0f197aca121b220d63cf2313ad 100644 (file)
@@ -1091,7 +1091,7 @@ int       _scf_x64_select_inst(scf_native_t* ctx)
                                return ret;
                }
        }
-#if 0
+#if 1
        if (x64_optimize_peephole(ctx, f) < 0) {
                scf_loge("\n");
                return -1;