Cengiz Can

an exuberant codesmith

Read this first

You should thank your compiler for `vectorizing` your loops

 What is vectorizing?

Vectorization (in CPU sense) is the way of performing an operation on multiple elements of a vector at once. Thus the operation is done chunk-wise instead of element-wise.

It’s either done by your compiler automagically, or explicitly if you’re writing assembly by hand (SIMD instructions).

I’m going to talk about the former case.

 Why?

Let’s say that you have a loop that performs add operation on two integer arrays. In the most simplistic case, that would require your code to loop on each member of each array, add and move on to next element.

If you could vectorize that loop, your CPU would be able to process multiple elements from both of the arrays at the same time.

That will reduce the number of CPU cycles, and if done properly, reduce your binary size.

 How can I see that?

If you’re using gcc you can dump loop vectorization info with these flags:

➜  ~

Continue reading →


How long a function should be?

Wondering if that function you just finished implementing is too long? Or maybe it looks so short that you think you’d better get rid of it?

Whenever that happens in future, I’ll try to follow this guideline from my colleague Martin Fowler‘s Bliki named “FunctionLength”

(emphasis mine)

If you have to spend effort into looking at a fragment of code to figure out what it’s doing, then you should extract it into a function and name the function after that “what”. That way when you read it again, the purpose of the function leaps right out at you, and most of the time you won’t need to care about how the function fulfills its purpose - which is the body of the function.

What’s your guideline on function length? Share with me on twitter: @cengizIO

Continue reading →


Structured Exception Handling - Windows way of OS traps

Today I wondered

How does my C++ program’s SEGFAULT signal (or ‘Access Violation’) trigger a popup to appear in Windows?

After some wrestling with cygwin and its Win64 toolchain (terribly called mingw64-x86_64-w64-gcc), I noticed that it links binaries to a DLL called libgcc_s_seh-1.dll.

What could this SEH be?

It turned out to be a very old way of Software/Hardware exception handling mechanism that’s been used by Windows.

I don’t know if there are any successors to it, but it is the thing behind this popup that every Windows user/developer hates:

Capture.PNG

I’m not a Windows developer, and not using Windows for development, but I’m always curious about the differences between System/User space implementations of Linux and other systems.

(Oh and BTW, both Visual Studio’s Native Decompiler and WinDbg suck)

Continue reading →


Large file download? Use ‘axel'

Hello internet!

This is my first Svbtle post. I hope to have more of these.

And I’d like to tell you about an extremely easy to use CLI tool that has been successfully downloading files with maximum achievable speed for 15 years.

It’s axel!

Originally developed by Wilmer van der Gaast around 2001 and continues to live on GitHub thanks to Joao Eriberto Mota Filho and other contributors, axel can utilise multiple connections to same file, resume your download, and show you a nerdgasmic progress bar while doing that.

Screen Shot 2016-12-28 at 23.50.25.png

In the example above, -n8 indicates that I want 8 concurrent connections to the server and -a instructs axel to show that nice sticky progress bar.

axel is available as a package generally named axel in all major Linux distros and if you’re using macOS, you can get it via homebrew.

$ brew install axel

If you’re like me and like to hack around things just to see what

Continue reading →