guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 333/437: Implement jit_flush


From: Andy Wingo
Subject: [Guile-commits] 333/437: Implement jit_flush
Date: Mon, 2 Jul 2018 05:14:49 -0400 (EDT)

wingo pushed a commit to branch lightning
in repository guile.

commit 7b449aa0638b978c6a551edf35611beefeaf9f14
Author: pcpa <address@hidden>
Date:   Sat Nov 8 19:34:23 2014 -0200

    Implement jit_flush
    
        * include/lightning/jit_private.h, lib/jit_aarch64.c,
        lib/jit_alpha.c, lib/jit_arm.c, lib/jit_hppa.c,
        lib/jit_ia64.c, lib/jit_mips.c, lib/jit_ppc.c,
        lib/jit_s390x.c, lib/jit_sparc.c, lib/jit_x86.c:
        Implement a private jit_flush call, that flushes
        the cache, if applicable, aligning down to the
        previous and up to the next page boundary.
---
 ChangeLog                       | 10 ++++++++++
 include/lightning/jit_private.h |  3 +++
 lib/jit_aarch64.c               | 16 ++++++++++++++--
 lib/jit_alpha.c                 |  7 +++++++
 lib/jit_arm.c                   | 18 ++++++++++++++----
 lib/jit_hppa.c                  | 29 ++++++++++++++++++-----------
 lib/jit_ia64.c                  | 18 ++++++++++++++----
 lib/jit_mips.c                  | 17 ++++++++++++++---
 lib/jit_ppc.c                   | 16 ++++++++++++++--
 lib/jit_s390x.c                 | 16 ++++++++++++++--
 lib/jit_sparc.c                 |  7 +++++++
 lib/jit_x86.c                   |  7 +++++++
 12 files changed, 136 insertions(+), 28 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 49f054d..fc1670d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2014-11-08 Paulo Andrade <address@hidden>
 
+       * include/lightning/jit_private.h, lib/jit_aarch64.c,
+       lib/jit_alpha.c, lib/jit_arm.c, lib/jit_hppa.c,
+       lib/jit_ia64.c, lib/jit_mips.c, lib/jit_ppc.c,
+       lib/jit_s390x.c, lib/jit_sparc.c, lib/jit_x86.c:
+       Implement a private jit_flush call, that flushes
+       the cache, if applicable, aligning down to the
+       previous and up to the next page boundary.
+
+2014-11-08 Paulo Andrade <address@hidden>
+
        * check/ctramp.c: New file. It just repeats the test
        of tramp.tst, but using two jit_state_t, what should
        test possible issues with two contexts, and also validate
diff --git a/include/lightning/jit_private.h b/include/lightning/jit_private.h
index 2a48fec..5148ca6 100644
--- a/include/lightning/jit_private.h
+++ b/include/lightning/jit_private.h
@@ -589,6 +589,9 @@ _jit_regarg_p(jit_state_t*, jit_node_t*, jit_int32_t);
 extern jit_pointer_t
 _emit_code(jit_state_t*);
 
+extern void
+jit_flush(void *fptr, void *tptr);
+
 #define emit_ldxi(r0, r1, i0)  _emit_ldxi(_jit, r0, r1, i0)
 extern void
 _emit_ldxi(jit_state_t*, jit_int32_t, jit_int32_t, jit_word_t);
diff --git a/lib/jit_aarch64.c b/lib/jit_aarch64.c
index a8673ea..77e25b3 100644
--- a/lib/jit_aarch64.c
+++ b/lib/jit_aarch64.c
@@ -1170,8 +1170,7 @@ _emit_code(jit_state_t *_jit)
        patch_at(word, value);
     }
 
-    word = sysconf(_SC_PAGE_SIZE);
-    __clear_cache(_jit->code.ptr, (void *)((_jit->pc.w + word) & -word));
+    jit_flush(_jit->code.ptr, _jit->pc.uc);
 
     return (_jit->code.ptr);
 }
@@ -1182,6 +1181,19 @@ _emit_code(jit_state_t *_jit)
 #undef CODE
 
 void
+jit_flush(void *fptr, void *tptr)
+{
+#if defined(__GNUC__)
+    jit_word_t         f, t, s;
+
+    s = sysconf(_SC_PAGE_SIZE);
+    f = (jit_word_t)fptr & -s;
+    t = (((jit_word_t)tptr) + s - 1) & -s;
+    __clear_cache((void *)f, (void *)t);
+#endif
+}
+
+void
 _emit_ldxi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
     ldxi(rn(r0), rn(r1), i0);
diff --git a/lib/jit_alpha.c b/lib/jit_alpha.c
index 91e2aa1..07b13c5 100644
--- a/lib/jit_alpha.c
+++ b/lib/jit_alpha.c
@@ -1213,6 +1213,8 @@ _emit_code(jit_state_t *_jit)
        patch_at(_jitc->patches.ptr[offset].inst, word);
     }
 
+    jit_flush(_jit->code.ptr, _jit->pc.uc);
+
     return (_jit->code.ptr);
 }
 
@@ -1222,6 +1224,11 @@ _emit_code(jit_state_t *_jit)
 #undef CODE
 
 void
+jit_flush(void *fptr, void *tptr)
+{
+}
+
+void
 _emit_ldxi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
     ldxi(rn(r0), rn(r1), i0);
diff --git a/lib/jit_arm.c b/lib/jit_arm.c
index 1790225..66842ee 100644
--- a/lib/jit_arm.c
+++ b/lib/jit_arm.c
@@ -1589,10 +1589,7 @@ _emit_code(jit_state_t *_jit)
        patch_at(_jitc->patches.ptr[offset].kind & ~arm_patch_node, word, 
value);
     }
 
-#if defined(__GNUC__)
-    word = sysconf(_SC_PAGE_SIZE);
-    __clear_cache(_jit->code.ptr, (void *)((_jit->pc.w + word) & -word));
-#endif
+    jit_flush(_jit->code.ptr, _jit->pc.uc);
 
     return (_jit->code.ptr);
 }
@@ -1604,6 +1601,19 @@ _emit_code(jit_state_t *_jit)
 #undef CODE
 
 void
+jit_flush(void *fptr, void *tptr)
+{
+#if defined(__GNUC__)
+    jit_word_t         f, t, s;
+
+    s = sysconf(_SC_PAGE_SIZE);
+    f = (jit_word_t)fptr & -s;
+    t = (((jit_word_t)tptr) + s - 1) & -s;
+    __clear_cache((void *)f, (void *)t);
+#endif
+}
+
+void
 _emit_ldxi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
     ldxi_i(rn(r0), rn(r1), i0);
diff --git a/lib/jit_hppa.c b/lib/jit_hppa.c
index d3f79d7..92d7001 100644
--- a/lib/jit_hppa.c
+++ b/lib/jit_hppa.c
@@ -1162,6 +1162,23 @@ _emit_code(jit_state_t *_jit)
        patch_at(_jitc->patches.ptr[offset].inst, word);
     }
 
+    jit_flush(_jit->code.ptr, _jit->pc.uc);
+
+    return (_jit->code.ptr);
+}
+
+#define CODE                           1
+#  include "jit_hppa-cpu.c"
+#  include "jit_hppa-fpu.c"
+#undef CODE
+
+void
+jit_flush(void *fptr, void *tptr)
+{
+    jit_word_t         f, t, s;
+    s = sysconf(_SC_PAGE_SIZE);
+    f = (jit_word_t)fptr & -s;
+    t = (((jit_word_t)tptr) + s - 1) & -s;
 #if defined(__hppa)
 /* --- parisc2.0.pdf ---
                Programming Note
@@ -1203,9 +1220,7 @@ at most two cachelines.
      * on this software.
      */
     {
-       jit_word_t      f = (jit_word_t)_jit->code.ptr;
        jit_word_t      n = f + 32;
-       jit_word_t      t = f + _jit->code.length;
        register int    u, v;
        for (; f <= t; n = f + 32, f += 64) {
            asm volatile ("fdc 0(0,%0)"
@@ -1234,18 +1249,10 @@ at most two cachelines.
     }
 #else
     /* This is supposed to work but appears to fail on multiprocessor systems 
*/
-    word = sysconf(_SC_PAGE_SIZE);
-    __clear_cache(_jit->code.ptr, (void *)((_jit->pc.w + word) & -word));
+    __clear_cache((void *)f, (void *)t);
 #endif
-
-    return (_jit->code.ptr);
 }
 
-#define CODE                           1
-#  include "jit_hppa-cpu.c"
-#  include "jit_hppa-fpu.c"
-#undef CODE
-
 void
 _emit_ldxi(jit_state_t *_jit, jit_gpr_t r0, jit_gpr_t r1, jit_word_t i0)
 {
diff --git a/lib/jit_ia64.c b/lib/jit_ia64.c
index 6aa4562..46ff5da 100644
--- a/lib/jit_ia64.c
+++ b/lib/jit_ia64.c
@@ -1385,10 +1385,7 @@ _emit_code(jit_state_t *_jit)
        patch_at(node->code, _jitc->patches.ptr[offset].inst, word);
     }
 
-#if defined(__GNUC__)
-    word = sysconf(_SC_PAGE_SIZE);
-    __clear_cache(_jit->code.ptr, (void *)((_jit->pc.w + word) & -word));
-#endif
+    jit_flush(_jit->code.ptr, _jit->pc.uc);
 
     return (_jit->code.ptr);
 }
@@ -1398,6 +1395,19 @@ _emit_code(jit_state_t *_jit)
 #  include "jit_ia64-fpu.c"
 #undef CODE
 
+void
+jit_flush(void *fptr, void *tptr)
+{
+#if defined(__GNUC__)
+    jit_word_t         f, t, s;
+
+    s = sysconf(_SC_PAGE_SIZE);
+    f = (jit_word_t)fptr & -s;
+    t = (((jit_word_t)tptr) + s - 1) & -s;
+    __clear_cache((void *)f, (void *)t);
+#endif
+}
+
 /* Use r2 that is reserved to not require a jit_get_reg call, also note
  * that addil needs a register that first in 2 bits, so, if using a
  * register other than r2 must be less than r8 (or check for a smaller
diff --git a/lib/jit_mips.c b/lib/jit_mips.c
index 71822a0..e871d47 100644
--- a/lib/jit_mips.c
+++ b/lib/jit_mips.c
@@ -1488,9 +1488,7 @@ _emit_code(jit_state_t *_jit)
        patch_at(_jitc->patches.ptr[offset].inst, word);
     }
 
-#if defined(__linux__)
-    _flush_cache((char *)_jit->code.ptr, _jit->pc.uc - _jit->code.ptr, ICACHE);
-#endif
+    jit_flush(_jit->code.ptr, _jit->pc.uc);
 
     return (_jit->code.ptr);
 }
@@ -1501,6 +1499,19 @@ _emit_code(jit_state_t *_jit)
 #undef CODE
 
 void
+jit_flush(void *fptr, void *tptr)
+{
+#if defined(__linux__)
+    jit_word_t         f, t, s;
+
+    s = sysconf(_SC_PAGE_SIZE);
+    f = (jit_word_t)fptr & -s;
+    t = (((jit_word_t)tptr) + s - 1) & -s;
+    _flush_cache((void *)f, t - f, ICACHE);
+#endif
+}
+
+void
 _emit_ldxi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
     ldxi(rn(r0), rn(r1), i0);
diff --git a/lib/jit_ppc.c b/lib/jit_ppc.c
index 2bd92cb..8a75cef 100644
--- a/lib/jit_ppc.c
+++ b/lib/jit_ppc.c
@@ -1372,8 +1372,7 @@ _emit_code(jit_state_t *_jit)
        patch_at(_jitc->patches.ptr[offset].inst, word);
     }
 
-    word = sysconf(_SC_PAGE_SIZE);
-    __clear_cache(_jit->code.ptr, (void *)((_jit->pc.w + word) & -word));
+    jit_flush(_jit->code.ptr, _jit->pc.uc);
 
     return (_jit->code.ptr);
 }
@@ -1384,6 +1383,19 @@ _emit_code(jit_state_t *_jit)
 #undef CODE
 
 void
+jit_flush(void *fptr, void *tptr)
+{
+#if defined(__GNUC__)
+    jit_word_t         f, t, s;
+
+    s = sysconf(_SC_PAGE_SIZE);
+    f = (jit_word_t)fptr & -s;
+    t = (((jit_word_t)tptr) + s - 1) & -s;
+    __clear_cache((void *)f, (void *)t);
+#endif
+}
+
+void
 _emit_ldxi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
 #if __WORDSIZE == 32
diff --git a/lib/jit_s390x.c b/lib/jit_s390x.c
index 98863e7..28abe40 100644
--- a/lib/jit_s390x.c
+++ b/lib/jit_s390x.c
@@ -1154,8 +1154,7 @@ _emit_code(jit_state_t *_jit)
        patch_at(_jitc->patches.ptr[offset].inst, word);
     }
 
-    word = sysconf(_SC_PAGE_SIZE);
-    __clear_cache(_jit->code.ptr, (void *)((_jit->pc.w + word) & -word));
+    jit_flush(_jit->code.ptr, _jit->pc.uc);
 
     return (_jit->code.ptr);
 }
@@ -1166,6 +1165,19 @@ _emit_code(jit_state_t *_jit)
 #undef CODE
 
 void
+jit_flush(void *fptr, void *tptr)
+{
+#if defined(__GNUC__)
+    jit_word_t         f, t, s;
+
+    s = sysconf(_SC_PAGE_SIZE);
+    f = (jit_word_t)fptr & -s;
+    t = (((jit_word_t)tptr) + s - 1) & -s;
+    __clear_cache((void *)f, (void *)t);
+#endif
+}
+
+void
 _emit_ldxi(jit_state_t *_jit, jit_gpr_t r0, jit_gpr_t r1, jit_word_t i0)
 {
     ldxi(rn(r0), rn(r1), i0);
diff --git a/lib/jit_sparc.c b/lib/jit_sparc.c
index 65b4f3f..80e6785 100644
--- a/lib/jit_sparc.c
+++ b/lib/jit_sparc.c
@@ -1156,6 +1156,8 @@ _emit_code(jit_state_t *_jit)
        patch_at(_jitc->patches.ptr[offset].inst, word);
     }
 
+    jit_flush(_jit->code.ptr, _jit->pc.uc);
+
     return (_jit->code.ptr);
 }
 
@@ -1165,6 +1167,11 @@ _emit_code(jit_state_t *_jit)
 #undef CODE
 
 void
+jit_flush(void *fptr, void *tptr)
+{
+}
+
+void
 _emit_ldxi(jit_state_t *_jit, jit_gpr_t r0, jit_gpr_t r1, jit_word_t i0)
 {
     ldxi_i(rn(r0), rn(r1), i0);
diff --git a/lib/jit_x86.c b/lib/jit_x86.c
index c2158d6..0fe01b3 100644
--- a/lib/jit_x86.c
+++ b/lib/jit_x86.c
@@ -1794,6 +1794,8 @@ _emit_code(jit_state_t *_jit)
        patch_at(node, _jitc->patches.ptr[offset].inst, word);
     }
 
+    jit_flush(_jit->code.ptr, _jit->pc.uc);
+
     return (_jit->code.ptr);
 }
 
@@ -1804,6 +1806,11 @@ _emit_code(jit_state_t *_jit)
 #undef CODE
 
 void
+jit_flush(void *fptr, void *tptr)
+{
+}
+
+void
 _emit_ldxi(jit_state_t *_jit, jit_gpr_t r0, jit_gpr_t r1, jit_word_t i0)
 {
     ldxi(rn(r0), rn(r1), i0);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]