Coder Social home page Coder Social logo

opencoff / portable-lib Goto Github PK

View Code? Open in Web Editor NEW
53.0 11.0 16.0 2.79 MB

Portable C, C++ code for hash tables, bloom filters, string-search, string utilities, hash functions, arc4random

License: GNU General Public License v2.0

Makefile 1.29% C 84.87% C++ 8.27% Python 5.48% Shell 0.09%
c c-plus-plus hash-functions hash-tables c-templates cdb mmap string-manipulation bloom-filter templates-in-c

portable-lib's People

Contributors

opencoff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

portable-lib's Issues

Bug: loop counter in ringbuf.h function __store_ring() and __load_ring() is wrong

Both __store_ring() and __load_ring() have a same bug.

function __store_ring:

__store_ring(struct rte_ring *r, uint_fast32_t head, void * const* obj, unsigned n)
{
unsigned i;
unsigned loops = n & 0x3;
unsigned idx = head & r->mask;
// If we know we won't wrap around, we unroll 4 times
if (likely((idx + n) <= r->mask)) {
for (i = 0; i < loops; i += 4, idx += 4) {
r->ring[idx+0] = obj[i+0];
r->ring[idx+1] = obj[i+1];
r->ring[idx+2] = obj[i+2];
r->ring[idx+3] = obj[i+3];
}
// mop up remainder
switch (n & 0x3) {
case 3:
r->ring[idx+0] = obj[i+0];
r->ring[idx+1] = obj[i+1];
r->ring[idx+2] = obj[i+2];
break;
case 2:
r->ring[idx+0] = obj[i+0];
r->ring[idx+1] = obj[i+1];
break;
case 1:
r->ring[idx+0] = obj[i+0];
break;
}
} else {
const uint32_t mask = r->mask;
for (i = 0; i < n; i++, idx++) {
r->ring[idx & mask] = obj[i];
}
}
}

  • Bug: When n=1, function __store_ring(ring, head, elements, n) actually writes 4 elements into the ring.

  • Reason: loop should = n>>2 not n&0x03
    Buggy code is at line 240:

    unsigned loops = n & 0x3;

  • Solution:
    The correct logic should be:

unsigned loop = n & ((unsigned) ~0x3U);

see also https://github.com/DPDK/dpdk/blob/07f08a96f5255a0375dce2683db4fb489bbaa8a0/lib/librte_ring/rte_ring.h#L240-L250

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.