Is a mov to a segmentation register slower than a mov to a general purpose register?

mov %eax, %ebx between general-purpose registers is one of the most common instructions. Modern hardware supports it extremely efficiently, often with special cases that don’t apply to any other instruction. On older hardware, it’s always been one of the cheapest instructions. On Ivybridge and later, it doesn’t even need an execution unit and has zero … Read more

What is the purpose of segment registers in x86 protected mode?

Some historical background The 8086 always used a fixed 64KiB Window per segment whose starting address was calculated by (segment register * 16). Since the 80286 there are some special tables in memory (GDT and LDT). These tables contain the starting address, the length and the access rights of a segment. The segment registers (CS, … Read more

Does C have an equivalent of std::less from C++?

On implementations with a flat memory model (basically everything), casting to uintptr_t will Just Work. (But see Should pointer comparisons be signed or unsigned in 64-bit x86? for discussion of whether you should treat pointers as signed or not, including issues of forming pointers outside of objects which is UB in C.) But systems with … Read more