Ticket #13352: trac_13352-bitcount-in-c.patch

File trac_13352-bitcount-in-c.patch, 2.0 KB (added by dcoudert, 9 years ago)

trials not working

  • module_list.py

    # HG changeset patch
    # User dcoudert <david.coudert@inria.fr>
    # Date 1344500797 -7200
    # Node ID 58e6cb67b43b1d657ee25512fcbba6f247d94c4b
    # Parent  a3a5bdf1e8c8c9f17f141150bf07043c8115ec4b
    trac #13352 -- use builtin functions to count bits in integers
    
    diff --git a/module_list.py b/module_list.py
    a b  
    10561056    Extension('sage.misc.allocator',
    10571057              sources = ['sage/misc/allocator.pyx']),
    10581058
     1059    Extension('sage.misc.bitcount',
     1060              sources = ['sage/misc/bitcount.c'],
     1061              extra_compile_args = ['-mpopcnt']),
     1062
    10591063    Extension('sage.misc.bitset',
    1060               sources = ['sage/misc/bitset.pyx']),
     1064              sources = ['sage/misc/bitset.pyx'],
     1065              extra_compile_args = ['-mpopcnt', '-msse4.2']),
    10611066
    10621067    Extension('sage.misc.cachefunc',
    10631068              sources = ['sage/misc/cachefunc.pyx']),
  • new file sage/misc/bitcount.c

    diff --git a/sage/misc/bitcount.c b/sage/misc/bitcount.c
    new file mode 100644
    - +  
     1#include <stdio.h>
     2#include <stdlib.h>
     3int popcount32(int i){ return __builtin_popcount(i); }
     4int popcount64(unsigned long long i){ return __builtin_popcountll(i); }
  • new file sage/misc/bitcount.pxd

    diff --git a/sage/misc/bitcount.pxd b/sage/misc/bitcount.pxd
    new file mode 100644
    - +  
     1
     2cdef extern from "bitcount.c":
     3    int popcount32(int i)
     4    int popcount64(unsigned long long i)
  • sage/misc/bitset.pxi

    diff --git a/sage/misc/bitset.pxi b/sage/misc/bitset.pxi
    a b  
    402402    return -1
    403403
    404404
    405 
     405from sage.misc.bitcount import popcount64
    406406cdef inline long bitset_len(bitset_t bits):
    407407    """
    408408    Calculate the number of items in the set (i.e., the number of nonzero bits).
    409409    """
    410410    cdef long len = 0
    411     cdef long i = bitset_first(bits)
    412     while i>=0:
    413         len += 1
    414         i=bitset_next(bits, i+1)
     411    cdef long i
     412    for i from 0 <= i < bits.limbs:
     413        len += popcount64(bits.bits[i])
    415414    return len
    416415
    417416cdef inline long bitset_hash(bitset_t bits):