[pypy-commit] pypy vmprof2: Remove usage of "uintptr_t" and use "unsigned long", which is more like

arigo noreply at buildbot.pypy.org
Fri Apr 24 10:33:37 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: vmprof2
Changeset: r76916:79023f7a715e
Date: 2015-04-24 10:33 +0200
http://bitbucket.org/pypy/pypy/changeset/79023f7a715e/

Log:	Remove usage of "uintptr_t" and use "unsigned long", which is more
	like the rest of the code. Avoid calling __sync_lock_test_and_set
	on Windows and directly call the "proper" functions.

diff --git a/rpython/jit/backend/llsupport/codemap.py b/rpython/jit/backend/llsupport/codemap.py
--- a/rpython/jit/backend/llsupport/codemap.py
+++ b/rpython/jit/backend/llsupport/codemap.py
@@ -26,29 +26,19 @@
 srcdir = os.path.join(os.path.dirname(__file__), 'src')
 
 eci = ExternalCompilationInfo(post_include_bits=["""
-#if defined _MSC_VER && _MSC_VER < 1600
-#ifdef _WIN32
-typedef unsigned int uintptr_t;
-#else
-typedef usigned long uintptr_t;
-#endif
-#else
-#include <stdint.h>
-#endif
-
-RPY_EXTERN long pypy_jit_codemap_add(uintptr_t addr,
+RPY_EXTERN long pypy_jit_codemap_add(unsigned long addr,
                                      unsigned int machine_code_size,
                                      long *bytecode_info,
                                      unsigned int bytecode_info_size);
-RPY_EXTERN long *pypy_jit_codemap_del(uintptr_t addr, unsigned int size);
-RPY_EXTERN uintptr_t pypy_jit_codemap_firstkey(void);
+RPY_EXTERN long *pypy_jit_codemap_del(unsigned long addr, unsigned int size);
+RPY_EXTERN unsigned long pypy_jit_codemap_firstkey(void);
 RPY_EXTERN void *pypy_find_codemap_at_addr(long addr, long* start_addr);
 RPY_EXTERN long pypy_yield_codemap_at_addr(void *codemap_raw, long addr,
                                            long *current_pos_addr);
 
-RPY_EXTERN long pypy_jit_depthmap_add(uintptr_t addr, unsigned int size,
+RPY_EXTERN long pypy_jit_depthmap_add(unsigned long addr, unsigned int size,
                                       unsigned int stackdepth);
-RPY_EXTERN void pypy_jit_depthmap_clear(uintptr_t addr, unsigned int size);
+RPY_EXTERN void pypy_jit_depthmap_clear(unsigned long addr, unsigned int size);
 
 """], separate_module_sources=[
     open(os.path.join(srcdir, 'skiplist.c'), 'r').read() +
diff --git a/rpython/jit/backend/llsupport/src/codemap.c b/rpython/jit/backend/llsupport/src/codemap.c
--- a/rpython/jit/backend/llsupport/src/codemap.c
+++ b/rpython/jit/backend/llsupport/src/codemap.c
@@ -9,10 +9,15 @@
 
 void pypy_codemap_invalid_set(int value)
 {
+#ifndef _MSC_VER
     if (value)
         __sync_lock_test_and_set(&pypy_codemap_currently_invalid, 1);
     else
         __sync_lock_release(&pypy_codemap_currently_invalid);
+#else
+    InterlockedExchange((long volatile *)&pypy_codemap_currently_invalid,
+                        (long)value);
+#endif
 }
 
 
@@ -31,7 +36,7 @@
 /*** interface used from codemap.py ***/
 
 RPY_EXTERN
-long pypy_jit_codemap_add(uintptr_t addr, unsigned int machine_code_size,
+long pypy_jit_codemap_add(unsigned long addr, unsigned int machine_code_size,
                           long *bytecode_info, unsigned int bytecode_info_size)
 {
     skipnode_t *new = skiplist_malloc(sizeof(codemap_data_t));
@@ -52,9 +57,9 @@
 }
 
 RPY_EXTERN
-long *pypy_jit_codemap_del(uintptr_t addr, unsigned int size)
+long *pypy_jit_codemap_del(unsigned long addr, unsigned int size)
 {
-    uintptr_t search_key = addr + size - 1;
+    unsigned long search_key = addr + size - 1;
     long *result;
     skipnode_t *node;
 
@@ -78,7 +83,7 @@
 }
 
 RPY_EXTERN
-uintptr_t pypy_jit_codemap_firstkey(void)
+unsigned long pypy_jit_codemap_firstkey(void)
 {
     return skiplist_firstkey(&jit_codemap_head);
 }
@@ -90,7 +95,7 @@
 {
     skipnode_t *codemap = skiplist_search(&jit_codemap_head, addr);
     codemap_data_t *data;
-    uintptr_t rel_addr;
+    unsigned long rel_addr;
 
     if (codemap == &jit_codemap_head) {
         if (start_addr)
@@ -98,7 +103,7 @@
         return NULL;
     }
 
-    rel_addr = (uintptr_t)addr - codemap->key;
+    rel_addr = (unsigned long)addr - codemap->key;
     data = (codemap_data_t *)codemap->data;
     if (rel_addr >= data->machine_code_size) {
         if (start_addr)
@@ -153,7 +158,7 @@
 /*** interface used from codemap.py ***/
 
 RPY_EXTERN
-long pypy_jit_depthmap_add(uintptr_t addr, unsigned int size,
+long pypy_jit_depthmap_add(unsigned long addr, unsigned int size,
                            unsigned int stackdepth)
 {
     skipnode_t *new = skiplist_malloc(sizeof(depthmap_data_t));
@@ -173,9 +178,9 @@
 }
 
 RPY_EXTERN
-void pypy_jit_depthmap_clear(uintptr_t addr, unsigned int size)
+void pypy_jit_depthmap_clear(unsigned long addr, unsigned int size)
 {
-    uintptr_t search_key = addr + size - 1;
+    unsigned long search_key = addr + size - 1;
     if (size == 0)
         return;
 
@@ -196,14 +201,15 @@
 RPY_EXTERN
 long pypy_jit_stack_depth_at_loc(long loc)
 {
-    skipnode_t *depthmap = skiplist_search(&jit_depthmap_head, (uintptr_t)loc);
+    skipnode_t *depthmap = skiplist_search(&jit_depthmap_head,
+                                           (unsigned long)loc);
     depthmap_data_t *data;
-    uintptr_t rel_addr;
+    unsigned long rel_addr;
 
     if (depthmap == &jit_depthmap_head)
         return -1;
 
-    rel_addr = (uintptr_t)loc - depthmap->key;
+    rel_addr = (unsigned long)loc - depthmap->key;
     data = (depthmap_data_t *)depthmap->data;
     if (rel_addr >= data->block_size)
         return -1;
diff --git a/rpython/jit/backend/llsupport/src/skiplist.c b/rpython/jit/backend/llsupport/src/skiplist.c
--- a/rpython/jit/backend/llsupport/src/skiplist.c
+++ b/rpython/jit/backend/llsupport/src/skiplist.c
@@ -1,40 +1,19 @@
 #include <stdlib.h>
-#if defined _MSC_VER
- #include <intrin.h>
- int __sync_lock_test_and_set(int * i, int j)
- {
-   return _interlockedbittestandreset(i, j);
- }
- int __sync_lock_release(int *i)
- {
-   return _interlockedbittestandreset(i, 0);
- }
- #if _MSC_VER < 1600
-  #ifdef _WIN32
-   typedef unsigned int uintptr_t;
-  #else
-   typedef usigned long uintptr_t;
-  #endif
- #endif
-#else
-#include <stdint.h>
-#endif
-
 
 #define HAS_SKIPLIST
 #define SKIPLIST_HEIGHT   8
 
 typedef struct skipnode_s {
-    uintptr_t key;
+    unsigned long key;
     char *data;
     struct skipnode_s *next[SKIPLIST_HEIGHT];   /* may be smaller */
 } skipnode_t;
 
-static skipnode_t *skiplist_malloc(uintptr_t datasize)
+static skipnode_t *skiplist_malloc(unsigned long datasize)
 {
     char *result;
-    uintptr_t basesize;
-    uintptr_t length = 1;
+    unsigned long basesize;
+    unsigned long length = 1;
     while (length < SKIPLIST_HEIGHT && (rand() & 3) == 0)
         length++;
     basesize = sizeof(skipnode_t) -
@@ -46,12 +25,12 @@
     return (skipnode_t *)result;
 }
 
-static skipnode_t *skiplist_search(skipnode_t *head, uintptr_t searchkey)
+static skipnode_t *skiplist_search(skipnode_t *head, unsigned long searchkey)
 {
     /* Returns the skipnode with key closest (but <=) searchkey.
        Note that if there is no item with key <= searchkey in the list,
        this will return the head node. */
-    uintptr_t level = SKIPLIST_HEIGHT - 1;
+    unsigned long level = SKIPLIST_HEIGHT - 1;
     while (1) {
         skipnode_t *next = head->next[level];
         if (next != NULL && next->key <= searchkey) {
@@ -68,13 +47,13 @@
 
 static void skiplist_insert(skipnode_t *head, skipnode_t *new)
 {
-    uintptr_t size0 = sizeof(skipnode_t) -
-                      SKIPLIST_HEIGHT * sizeof(skipnode_t *);
-    uintptr_t height_of_new = (new->data - ((char *)new + size0)) /
-                              sizeof(skipnode_t *);
+    unsigned long size0 = sizeof(skipnode_t) -
+                          SKIPLIST_HEIGHT * sizeof(skipnode_t *);
+    unsigned long height_of_new = (new->data - ((char *)new + size0)) /
+                                  sizeof(skipnode_t *);
 
-    uintptr_t level = SKIPLIST_HEIGHT - 1;
-    uintptr_t searchkey = new->key;
+    unsigned long level = SKIPLIST_HEIGHT - 1;
+    unsigned long searchkey = new->key;
     while (1) {
         skipnode_t *next = head->next[level];
         if (next != NULL && next->key <= searchkey) {
@@ -92,9 +71,9 @@
     }
 }
 
-static skipnode_t *skiplist_remove(skipnode_t *head, uintptr_t exact_key)
+static skipnode_t *skiplist_remove(skipnode_t *head, unsigned long exact_key)
 {
-    uintptr_t level = SKIPLIST_HEIGHT - 1;
+    unsigned long level = SKIPLIST_HEIGHT - 1;
     while (1) {
         skipnode_t *next = head->next[level];
         if (next != NULL && next->key <= exact_key) {
@@ -115,7 +94,7 @@
     }
 }
 
-static uintptr_t skiplist_firstkey(skipnode_t *head)
+static unsigned long skiplist_firstkey(skipnode_t *head)
 {
     if (head->next[0] == NULL)
         return 0;
diff --git a/rpython/jit/backend/llsupport/test/test_skiplist.py b/rpython/jit/backend/llsupport/test/test_skiplist.py
--- a/rpython/jit/backend/llsupport/test/test_skiplist.py
+++ b/rpython/jit/backend/llsupport/test/test_skiplist.py
@@ -5,16 +5,16 @@
 
 ffi.cdef("""
 typedef struct {
-    uintptr_t key;
+    unsigned long key;
     char *data;
     ...;
 } skipnode_t;
 
-skipnode_t *skiplist_malloc(uintptr_t datasize);
-skipnode_t *skiplist_search(skipnode_t *head, uintptr_t searchkey);
+skipnode_t *skiplist_malloc(unsigned long datasize);
+skipnode_t *skiplist_search(skipnode_t *head, unsigned long searchkey);
 void skiplist_insert(skipnode_t *head, skipnode_t *new);
-skipnode_t *skiplist_remove(skipnode_t *head, uintptr_t exact_key);
-uintptr_t skiplist_firstkey(skipnode_t *head);
+skipnode_t *skiplist_remove(skipnode_t *head, unsigned long exact_key);
+unsigned long skiplist_firstkey(skipnode_t *head);
 """)
 
 filename = os.path.join(os.path.dirname(__file__), '..', 'src', 'skiplist.c')


More information about the pypy-commit mailing list