← Înapoi la Urmăritori

Cel mai recent articol

Ultima verificare

Urmăritori 0 urmăritori
Articole: 174
  1. Not everything in AVX2 is 256-bit

    AVX2 has added support for 256-bit arguments for many operations on packed integers, although not all.

  2. Introduction Informal specification: __m128i mask_lower(const unsigned n) { assert(n < 16); /* __m128i result = 0; for (unsigned int i=0; i < n; i++) { result.byte[i] = 0xff; } */ switch (n) {…

  3. Introduction SSE procedure can convert 16- and 32-digits inputs producing 8- and 16-bytes results.

  4. Parsing decimal numbers --- part 2: SSE

    PMADDWD details This instruction is specialized and I guess isn't often used.

  5. Parsing decimal numbers --- part 1: SWAR

    Introduction Naive parsing of unsigned decimal numbers can be coded as: uint32_t parse(char* s) { uint32_t result = 0; while (*s) { const uint8_t digit = *s++; result = result * 10 + (digit - '0'); } return result; } T…

  6. Naive conversion from an ASCII digit to a value could be coded with a switch instruction or a lookup table — too simple, right?

  7. Suppose we have a string containing ASCII zeros and ones, for example "11100100", and we want to interpret this text as a binary number and get value (0xe4).

  8. Conversion numbers to octal representation

    Introduction Conversion to octal isn't very computer-friendly, each digit occupy 3 bits, it isn't power of two.

  9. "Limited" means a value where at most one bit is set.

  10. The idea is simple: precondition: x is not zero; isolate lowest bit set: x & -x; check if this number is equal to x: x == (x & -x).

  11. Small win over compiler

    There are some places where a low-level programmer can beat a compiler.

  12. Interpolation search revisited

    Introduction Interpolation search is the modification of binary search, where the index of a "middle" key is obtained from linear interpolation of values at start & end of a processed range: a := start b := end key := searched key while a <= b loop t…

  13. Software emulation of PDEP

    Introduction PDEP is a new instruction from BMI2 (Bit Manipulation Instruction), pseudocode for 32-bit PDEP variant: src - a source word mask - a mask result := 0 k := 0 for i := 0 .. 31 loop if mask.bit[i] then result.bit[i] := src.bit[…

  14. Branchless converting single nibble For a nibble (0..15) stored in a byte conversion could be coded in this way: char nibble_to_hex(uint8_t byte) { assert(byte >= 0 && byte <= 15); char c = byte + '0'; if (byte > 9) c += 'a' - '0' - 1…

  15. Conversion numbers to binary representation

    Converting byte — SWAR version 1 Algorithm Populate byte v (bits: abcdefgh) in a 64-bit word: const uint64_t r1 = v * 0x0101010101010101 ┌────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┐ │abcdefgh│abcdefgh│abcdefgh│abcdefgh│abcdef…

  16. C++ bitset vs array

    The C++ bitset conserves a memory, but at cost of speed access.

  17. Is const-correctness paranoia good?

    Yes, definitely.

  18. Quick and dirty ad-hoc git hosting

    Recently I needed to synchronize my local repository with a remote machine, just for full backup.

  19. Scalar version of SSE move mask instruction

    Sample implementation C function for 32-bit numbers: #include <stdint.h> uint32_t movmask(const uint32_t input) { assert((input & 0x7f7f7f7f) == 0); const uint32_t mult = 0x02040810; const uint64_t result = (uint64_t)input * mult; ret…

  20. C++ standard inaccuracy

    First we read: 21.4.1 basic_string general requirements [string.require] [...] 3 No erase() or pop_back() member function shall throw any exceptions. ... a few pages later: 21.4.6.5 basic_string::erase [string::erase] basic_string<charT,traits, Allocator>&

  21. SIMD-friendly Rabin-Karp modification

    Algorithm Rabin-Karp algorithm uses a weak hash function to locate possible substring positions.

  22. GCC --- asm goto

    Starting from GCC 4.5 the asm statement has new form: asm goto.

  23. Mask for zero/non-zero bytes

    The description of Determine if a word has a zero byte from "Bit Twiddling Hacks" says about haszero(v): "the result is the high bits set where the bytes in v were zero".

  24. Fast calculate ceil(log10x) of an unsigned number is described on Bit Twiddling Hacks, this text show the SIMD solution for 32-bit numbers.

  25. Slow-paths in GNU libc strstr

    I've observed that some patterns issued to strstr cause significant slowdown.

  26. Introduction SSE provides not widely known control register, called MXCSR.

  27. Detailed results Whole table as txt file. instruction count % mov 5934098 37.63% call 1414355 8.97% lea 1071501 6.79% movl 760677 4.82% push 655921 4.16% jmp 611540 3.88% add 560517 3.55% je 490250 3.11% test 475899 3.02% pop 441608 2.80% sub 366228 2.32%…

  28. I accidentally created an infinite loop

    I needed to iterate through all values of 32-bit unsigned integer, so I wrote: #include <stdint.h> for (uint32_t i=0; i <= UINT32_MAX; i++) { // whatever } Is it ok?

  29. Presented algorithm works properly for any normalized floating point value, examples are given for double precision numbers (64-bit).

  30. Convert float to int without FPU/SSE

    This short article shows how a normalized floating point value could be safely converted to an integer value without assistance of FPU/SSE.

  31. fopen a directory

    It's not clear how function fopen applied to a directory should behave, manual pages don't say anything about this.

  32. x86 extensions are useless

    Intel announced new extension to SSE: instructions accelerating calculating hashes SHA-1 and SHA256.

  33. The size of an integer in PHP depends on machine, it has 32 bits on 32-bit architectures, and 64 on 64-bit architectures.

  34. Encoding array of unsigned integers

    Introduction Russ Cox wrote very interesting article about algorithms behind service Google Code Search.

  35. Sample sources Sources are available at github.

  36. Short story about PostgreSQL SUM function

    Here is a simple PostgreSQL type: CREATE TYPE foo_t AS ( id integer, total bigint ); and a simple query wrapped in a stored procedure: CREATE FUNCTION group_foo() RETURNS SETOF foo_t LANGUAGE "SQL" AS $$ SELECT…

  37. PostgreSQL --- faster reads from static tables

    Introduction "Static table" means that data is changed rarely, in my case it's a cache for some reporting system.

  38. PostgreSQL: printf in PL/pgSQL

    PostgreSQL wiki has entry about sprintf — is is quite simple approach (and isn't marked as immutable).

  39. SSE: trie lookup speedup

    Introduction Trie is a multiway tree where each edge is labelled by a letter; such trees are used as dictionaries.

  40. Introduction Detecting intersection of convex polygons is a common problem in a wide range of problems.

  41. PHP quirk

    PHP is very funny language.

  42. Average of two unsigned integers

    Sample program Following python script verifies both methods (for 8-bit integers) bits = 8 # unsigned width mask = (1 << bits) - 1 MSB = (1 << (bits - 1)) def base(a, b): return (a + b)/2 def safe1(a, b): LSB_carry = (a & b & 1) return…

  43. Introduction PostgreSQL executing queries with construct like '%text%' can't use any system index (I guess none of existing SQL servers have such feature).

  44. Introduction With SSE2 instructions it's possible to convert up to four numbers in range 0..9999_9999 and get 32 decimal digits results.

  45. Traversing DAGs

    If a DAG has got one component, then the simplest traversing method is depth-first-search, which could be easily implemented recursively (using an implicit stack). struct DAGNode { // user data bool visited; // after construction…

  46. DAWG as dictionary? Yes!

    If you read the Wikipedia entry about DAWG, then you find following sentence: Because the terminal nodes of a DAWG can be reached by multiple paths, a DAWG is not suitable for storing auxiliary information relating to each path, e.g. a word's frequency in…

  47. Python: C extensions --- sequence-like object

    If a class has to support standard len() function or operator in, then must be a sequence-like.

  48. Efficient trie representation

    Introduction Each node of a tree store two kinds of data: user data and trie-related data.

  49. Python: test if object is iterable

    def isiterable(obj) try: iter(obj) return True except TypeError: return False

  50. Traversing tree without stack

    Introduction Obvious traversal algorithms require O(logn) memory, i.e. an explicit or an implicit stack or a queue.