← Înapoi la Urmăritori

Cel mai recent articol

Ultima verificare

Urmăritori 0 urmăritori
Articole: 174
  1. Suppose we need to get a mask when a nonnegative argument is greater then some constant value; in other words, we want to evaluate following expression: if x > const_n then mask := 0xffffffff; else mask := 0x00000000; Portable branchless solution:…

  2. Speedup reversing table of bytes

    Tests Two scenarios of test were considered: The table size is hardware friendly, i.e. is multiply of implementation base step; also address of table is aligned: all procedures use MOVUPS, all procedures use MOVAPS.

  3. Determining if an integer is a power of 2

    Method from Bit Twiddling Hacks: (x !

  4. Brenchless conditional exchange

    Suppose we have to exchange (or just move) two registers A and B: C := A xor B C := 0 if condition is not true A := A xor C B := B xor C If C is 0, then A and B left unchanged, else A and B are swapped.

  5. STL: map with string as key --- access speedup

    The idea is quite simple: we do not have a single stl::map<string, something>, but a vector of maps, indexed with O(1) time — each map stores keys sharing certain properties.

  6. Branchless signum

    Problem: calculate value of sign(x): -1 when x < 0 0 when x = 0, +1 when x > 0.

  7. Fill word with selected bit

    The most general algorithm mask bit: [10111010] => [00010000] clone word: a=[00010000], b=[00010000] shift bit in first word to MSB, and to LSB in second word: a=[10000000], b=[00000001] subtract c = a - b: c=[01111111] add missing MSB c = c OR a: c=[…

  8. Transpose bits in byte using SIMD instructions

    Method presented here allows to get any bit permutation, transposition is just one of possible operations.

  9. PostgreSQL: get selected rows with given order

    Suppose that a database stores some kind of a dictionary and an user picks some items, but wants to keep the order.

  10. Join locate databases

    man locatedb says: "Databases can not be concatenated together, even if the first (dummy) entry is trimmed from all but the first database.

  11. SSE4.1: PHMINPOSUW --- insertion sort

    Unusual application of PHMINPOSUW instruction as key part of insertion sort for 8 element tables.

  12. SSSE3: PMADDUBSW and image crossfading

    Introduction Image crossfading is a kind of alpha blending where a final pixel is the result of linear interpolation of pixels from two images: result_pixel = pixel1 * alpha + pixel2 * (1 - alpha) where alpha lie in range [0, 1].

  13. SSE: conversion uint32 to float

    There is no such instruction — CVTDQ2PS converts signed 32-bit ints.

  14. Floating point tricks

    Converting float to int Few years ago I've developed a method that do not need any floating-point operations — description is written in Polish, but sample code should be easy to understand.

  15. Branch-less x86 code: movl %eax, %ebx sarl $32, %ebx ; fill ebx with sign bit xorl %ebx, %eax ; negate eax (if negative) subl %ebx, %eax ; increment eax by 1 (if negative) SSE2: pshufd $0b11110101, %xmm0, %xmm1 ; populate…

  16. RDTSC on Core2

    RDTSC is incremented with bus-clock cycles, and then multiplied by core-clock/bus-clock ratio.

  17. GCC asm constraints

    Read-write variables asm( "

  18. SSSE3/SSE4: alpha blending --- operator over

    Introduction Alpha blending refers to many different operations.

  19. Proof In the proof we consider three cases: x < y, x = y and x > y.

  20. SSE: modify 32bpp images with lookup tables

    x86 code The x86 code is a base for further improvements.

  21. Introduction Basically this kind of conversion needs following steps: extract components R, G and B (using bitwise and) extend words from 6 or 5 bits to 8 bits (shift left) place components at desired places in a 32-bit word (shift, bitwise or) R = (pixel…

  22. Introduction String search is a common task in text processing.

  23. SSSE3: fast popcount

    Introduction Population count is a procedure of counting number of ones in a bit string.

  24. SSSE3: printing hex values

    SIMD algorithm Instruction PSHUFB does parallel lookup from 16-byte array stored in an XMM register — this is exactly what bin to hex conversion needs.