News for hackers. Stuff that matters.
Re:How to C in 2016 by ealloc on Friday January 08, 2016 @10:03AM (#10865293)
I'm not conviced. Maybe it really is that the wider type is faster, and int_fast16_t should be 64 bits. I just tried it out on a 64 bit system. The program is just a for loop.

If the loop variable is a int_fast16_t the loop increment step compiles to

    	addq	$1, -16(%rbp)
If it is int16_t it compiles to

    	movzwl	-4(%rbp), %eax
	addl	$1, %eax
	movw	%ax, -4(%rbp)
The 64 bit width version is shorter, and so conceivably faster. Performance seems the same though, but that's probably because this program isn't a proper benchmark.
Re:How to C in 2016 by Narishma on Friday January 08, 2016 @02:30PM (#10867527)
> The 64 bit width version is shorter, and so conceivably faster.

Without profiling there's no way to tell on modern processors.

Re:How to C in 2016 by nwmcsween on Saturday January 09, 2016 @01:13AM (#10870308)
Seriously, you think movzwl -4(%rbp), %eax addl $1, %eax movw %ax, -4(%rbp) will be on par with addq $1, -16(%rbp)
Re:How to C in 2016 by DSMan195276 on Saturday January 09, 2016 @10:59AM (#10871661)
Modern processors are pretty crazy beasts. He right in saying it's impossible to say for sure without some hard numbers or profiling.

Comparatively, while one is three instructions and the other is one, that single instruction is still doing everything the other three are doing. The only reason they aren't both one instruction seems to be that `addw` must not being a thing (Why, I don't know). Since the I/O done by both will be nearly identical, and the addition's should be very comparable in speed, it's not crazy to say they should perform basically the same. If you compiled with -O2 I bet you'd see almost identical code, since it would probably remove the memory access.