To Int or to Uint, This is the Question
summary
Compares signed vs unsigned on x86 with gcc 13 -O2 and shows concrete assembly: uint64 uses a logical shift; int64 compiles into add + arithmetic shift, so division-by-2 costs extra ops. Demonstrates an arithmetic-series sum where signed version is 40× faster than unsigned on that toolchain. Recommends -fsanitize=signed-integer-overflow, fixed-width helpers (make_signed/make_unsigned, int_fast_t), C++20 two’s-complement guarantee and C++23 ssize, and using safe comparisons, concrete types and strong wrappers to avoid UB.
AI-written summary · about
chapters (29)
- 0:00Welcome and introduction
- 1:08Why integers matter
- 3:36Simple example comparison
- 5:43Assembly basics
- 8:59Latency and performance
- 11:52Signed vs unsigned storage
- 14:00Signed integer representations
- 16:32Shift operations explained
- 18:41Performance results
- 19:02Integer promotion pitfalls
- 22:40Mixing types causes bugs
- 24:28Avoid abusing auto
- 25:31Literal types explained
- 26:16Size_t and portability
- 28:47Pop quiz overflow
- 30:10Arithmetic series performance
- 35:12Undefined behavior trade-offs
- 36:34Compiler optimizations
- 37:16Sanitizers for safety
- 38:20Fixed-width integer types
- 39:23Generic programming helpers
- 40:47Safe comparisons in C++20
- 42:11Performance vs correctness
- 43:17Avoid auto when unsure
- 43:38Modern loops and safety
- 44:21Strong types recommendation
- 45:31Compiler warnings matter
- 47:38Best type for math
- 48:41Exploiting undefined behavior
