This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Xiongzhi Gao
Recipients Xiongzhi Gao, paul.moore, steve.dower, tim.golden, zach.ware
Date 2016-01-02.08:49:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1451724578.62.0.704000687465.issue25993@psf.upfronthosting.co.za>
In-reply-to
Content
The version of windows is Windows 7 Service Pack 1.
The version of Python is 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32.
The version of compiler in visual studio 10 is 16.00.40219.01 for 80x86.

I try to use SWIG to port a function that use _mm_xor_si64 like this:

packed_sse.i

> %module packed_sse
> %{
> extern long long _packed_mm_xor_si64(long long m1, long long m2);
> %}
> extern long long _packed_mm_xor_si64(long long m1, long long m2);

packed_sse.c

> #include <mmintrin.h>
> 
> __inline __m64 int64_to_m64 (const long long i) {
>     union {
>         long long i;
>         __m64 v;
>     } u;
>     u.i = i;
>     return u.v;
> }
> 
> __inline long long m64_to_int64 (const __m64 v) {
>     union {
>         long long i;
>         __m64 v;
>     } u;
>     u.v = v;
>     return u.i;
> }
> 
> long long _packed_mm_xor_si64(long long m1, long long m2) {
>     __m64 m64_m1 = int64_to_m64(m1), m64_m2 = int64_to_m64(m2);
>     __m64 m64_result = _mm_xor_si64(m64_m1, m64_m2);
>     return m64_to_int64(m64_result);

I use swig and compiler to port C to Python.
    
I try to test like this, it works:

test_swig.py

> # -*- coding: utf-8 -*-
> # !/bin/env python2
> 
> import random
> 
> import packed_sse
> 
> 
> if __name__ == "__main__":
>     for i in range(100000):
>         a, b = random.getrandbits(20), random.getrandbits(20)
>         _ = packed_sse._packed_mm_xor_si64(
>             a, b
>         )
>         assert a ^ b == _        

But when I try to profile the function like this, the output of first `print time.time() - _beg` is `nan` and Python crashed when run into second `print time.time() - _beg`:
    
profile_swig.py

> # -*- coding: utf-8 -*-
> # !/bin/env python2
> 
> import random
> import time
> 
> import packed_sse
> 
> 
> if __name__ == "__main__":
>     _beg = time.time()
>     for i in range(100000):
>         _ = packed_sse._packed_mm_xor_si64(
>             random.getrandbits(20), random.getrandbits(20)
>         )
>     print time.time() - _beg  # First
>     _beg = time.time()
>     for i in range(100000):
>         _ = random.getrandbits(20) ^ random.getrandbits(20)
>     print time.time() - _beg  # Second

I try to use `gdb` on MingGW to debug it, it said:
    
> (gdb) stop
> (gdb) c
> Continuing.
> 
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 7172.0xadc]
> 0x534fbe6c in python27!_Py_dg_dtoa () from C:\Windows\system32\python27.dll
History
Date User Action Args
2016-01-02 08:49:38Xiongzhi Gaosetrecipients: + Xiongzhi Gao, paul.moore, tim.golden, zach.ware, steve.dower
2016-01-02 08:49:38Xiongzhi Gaosetmessageid: <1451724578.62.0.704000687465.issue25993@psf.upfronthosting.co.za>
2016-01-02 08:49:38Xiongzhi Gaolinkissue25993 messages
2016-01-02 08:49:37Xiongzhi Gaocreate