Make it fast and readable!

there's too much unused parallelism on a single core

Data-Structure Vectorization

29 Jul 2021

One of the major benefits of type-based vectorization is data-structure vectorization. I’ll introduce and hopefully motivate the pattern in this post.

Read on …

Making the C++ conditional operator overloadable

25 Jul 2019

Why are operator?: overloads not allowed in C++? See, basically every operator in C++ is overloadable. Sure, you can do stupid things with such power, but that’s a general problem with humans that have power. C++ gives power to programmers, we need to use it wisely. Apparently operator?: is not overloadable because: “There is no fundamental reason to disallow overloading of ?:. I just didn’t see the need to introduce the special case of overloading a ternary operator. Note that a function overloading expr1?expr2:expr3 would not be able to guarantee that only one of expr2 and expr3 was executed.” [Stroustrup: C++ Style and Technique FAQ]

Read on …

Vectorized conversion from UTF-8 using stdx::simd

27 May 2019

Bob Steagall presented his high-speed UTF-8 conversion at CppCon and C++Now where he showed that his approach outperformed most existing conversion algorithms. For some extra speed, he implemented a function for converting ASCII to char16_t/char32_t using SSE intrinsics. This latter part got me hooked, because:

  • stdx::simd (my contribution to the Parallelism TS 2; note that I use namespace stdx = std::experimental, because the latter is just way too long.) was just sent off for publication by the C++ committee and should have made reliance on intrinsics unnecessary.
  • I had no prior experience with vectorizing string operations (which is one of the reasons my previous vector types library Vc didn’t have 8-bit integer support). I was curious, how hard can it be?
  • Bob’s presentation made it look like one needs access to special instructions like movmskb to get good performance.
  • Scalability to different vector widths is unclear. The SSE intrinsics certainly won’t scale. But how much can performance actually scale, knowing that the larger the vector, the lower the chance the full vector of chars is only made up of ASCII?
  • And what about newer ISA extensions such as SSE4.1 which adds instructions for converting unsigned char to short or int? Will it help?
  • Most important to me, can the code be more readable and portable and at least as fast at the same time?
  • And is there a chance for vectorization of non-ASCII code point conversions?
Read on …

Shortcuts for WG21 content

14 Feb 2019

Since at least KDE 2, the runner (krunner - per default on Alt-F2) supports configurable prefixes that resolve to a URL that is then opened like kioclient5 exec would open them. I created the following shortcuts:

Read on …

Optimizing std::hypot for simd arguments

18 Jan 2019

Do you know about std::hypot(a, b) and std::hypot(a, b, c)? (The 3-argument overload exists since C++17, sometimes referred to as hypot3.) Why do the C and C++ standard libraries provide a function that is as simple as sqrt(a*a + b*b)? It doesn’t save enough characters to warrant its existence, right? Have you ever considered what happens if the input values are “very” small or large? Or if an input is an IEEE754 special value such as infinity or NaN? Have you ever considered how precise the calculation is, especially if an exact answer is obvious if one of the inputs is 0?

Read on …