Composing Ancient Mathematical Knowledge Into Powerful Bit-fiddlingComposing Ancient Mathematical Knowledge Into Powerful Bit-fiddling techniques Jamie Pond -- CppCon 2024TLDW; New insights from Ancient Egyptian Multiplication gives us the freedom of synthesising iterationCount ← number of bits in type T result ← 0 while true do if most significant bit of multiplier is 1 then result ← result + multiplicand end if iterationCount lots of bit manipulation, but these operations are very cheap! ● Superscalar CPUs do speculative, out of order, parallel instruction execution via multiple execution units. ● Adding 8 8-bit ints takes0 码力 | 73 页 | 947.99 KB | 6 月前3
Template Metaprogramming: Type Traitsbeginner oriented: shallow depth, slow current 3Intended Audience • Beginner/Intermediate • Gentle entry: swimming pool to river • Part 1 is beginner oriented: shallow depth, slow current • Not necessarily Beginner/Intermediate • Gentle entry: swimming pool to river • Part 1 is beginner oriented: shallow depth, slow current • Not necessarily beginner to C++, but beginner to traditional template metaprogramming Beginner/Intermediate • Gentle entry: swimming pool to river • Part 1 is beginner oriented: shallow depth, slow current • Not necessarily beginner to C++, but beginner to traditional template metaprogramming0 码力 | 403 页 | 5.30 MB | 6 月前3
Tracy: A Profiler You Don't Want to Missscope • zone name is inferred (enclosing function name) • zone color is automatic (per-thread and depth) 22 thread timeline zone statistics Tracy Zoning 101 int foo() { ZoneScoped; ... ... } } • ZoneScopedN • only 1 zone per scope • zone color is automatic (per-thread and depth) • you name it! (must be persistent string literal)• ZoneScoped[N]C • only 1 zone per scope • you the host application (e.g., a plugin)• ZoneScopedS(depth) • captures callstack • adds some overhead • useful for code exploration • max callstack depth: ~60 • (enables selective sampling profiling) • ZoneScoped[N|C|S]0 码力 | 85 页 | 6.51 MB | 6 月前3
C++ Exceptions for Smaller FirmwareI2C Device I2C Device A simplified Introduction to I2C SDA SCL SDA SCL SDA SCL ADDRESS (7-bit) Byte 0 STA NACK/ ACK W/R ACK Byte 1 ACK NACK Wanna Learn More? i2c-bus.org 23 STOPPossible I2C I2C Errors 24 ⚠ ADDR NACK Device Not Present IO ERROR Unexpected Bus State ADDRESS (7-bit) Byte 0 STA NACK/ ACK W/R ACK Byte 1 ACK NACK STOPLet's consider an I2C I/O expander 25 output_pin output_pin cleanup) 123 Note: Instructions are in 8-bit segments Limit is 7 bytes 3 bytes typicallyARM Personality Data: Unwind Instructions SU16 = Short Personality with 16-bit scopes (always 4-bytes) Personality0 码力 | 237 页 | 6.74 MB | 6 月前3
A Long Journey of Changing std::sort Implementation at Scalesort GCC libstdc++ uses 2log2n depth limit 16.3INTROSORT Almost like a quick sort If we suspect a lot of recursion calls, use heap sort GCC libstdc++ uses 2log2n depth limit Microso� standard library (__comp_result << __j); 5 __j++; 6 ++__iter; 7 } 8 67.1CTZ - Count Trailing Zeros, BLSR - Reset Lowest Set Bit void __swap_bitset_pos(__first, __last, __left_bitset, __rig while (__left_bitset != 0 && __right_bitset __last - tz_right); } } 1 2 3 4 5 6 7 8 9 68CTZ - Count Trailing Zeros, BLSR - Reset Lowest Set Bit void __swap_bitset_pos(__first, __last, __left_bitset, __rig while (__left_bitset != 0 && __right_bitset0 码力 | 182 页 | 7.65 MB | 6 月前3
Hello 算法 1.0.0b1 C++版通过字符集查表来完成编号到字符的转换。占用空间与具体编程语言有关,通常为 2 bytes 或 1 byte ; ‧「布尔」代表逻辑中的“是”与“否”,其占用空间需要具体根据编程语言确定,通常为 1 byte 或 1 bit ; 类别 符号 占用空间 取值范围 默认值 整数 byte 1 byte −27 ~ 27 − 1 ( −128 ~ 127 ) 0 short 2 bytes −215 ~ 215 − 1 − 1 0 布尔 bool 1 byte / 1 bit true 或 false false � 以上表格中,加粗项在「算法题」中最为常用。此表格无需硬背,大致理解即可,需要时可以 通过查表来回忆。 整数表示方式 整数的取值范围取决于变量使用的内存长度,即字节(或比特)数。在计算机中,1 字节 (byte) = 8 比特 (bit) , 1 比特即 1 个二进制位。以 int 类型为例: 其实,这是因为浮点数 float 采用了不同的表示方式。IEEE 754 标准规定,32‑bit 长度的 float 由以下部分构 成: ‧ 符号位 S :占 1 bit ; ‧ 指数位 E :占 8 bits ; ‧ 分数位 N :占 24 bits ,其中 23 位显式存储; 设 32‑bit 二进制数的第 ? 位为 ?? ,则 float 值的计算方法定义为 val = (−1)0 码力 | 187 页 | 14.71 MB | 1 年前3
Hello 算法 1.0.0b2 C++版通过字符集查表来完成编号到字符的转换。占用空间通常为 2 bytes 或 1 byte ; ‧「布尔」代表逻辑中的“是”与“否”,其占用空间需根据编程语言确定,通常为 1 byte 或 1 bit ; 类别 符号 占用空间 取值范围 默认值 整数 byte 1 byte −27 ~ 27 − 1 ( −128 ~ 127 ) 0 short 2 bytes −215 ~ 215 − 1 − 1 0 布尔 bool 1 byte / 1 bit true 或 false false � 以上表格中,加粗项在「算法题」中最为常用。此表格无需硬背,大致理解即可,需要时可以 通过查表来回忆。 整数表示方式 整数的取值范围取决于变量使用的内存长度,即字节(或比特)数。在计算机中,1 字节 (byte) = 8 比特 (bit) , 1 比特即 1 个二进制位。以 int 类型为例: 其实,这是因为浮点数 float 采用了不同的表示方式。IEEE 754 标准规定,32‑bit 长度的 float 由以下部分构 成: ‧ 符号位 S :占 1 bit ; ‧ 指数位 E :占 8 bits ; ‧ 分数位 N :占 24 bits ,其中 23 位显式存储; 设 32‑bit 二进制数的第 ? 位为 ?? ,则 float 值的计算方法定义为 val = (−1)0 码力 | 197 页 | 15.72 MB | 1 年前3
Tracy: A Profiler You Don't Want to Missscope • zone name is inferred (enclosing function name) • zone color is automatic (per-thread and depth) 22 thread timeline zone statistics Tracy Zoning 101 int foo() { ZoneScoped; ... ... } } • ZoneScopedN • only 1 zone per scope • zone color is automatic (per-thread and depth) • you name it! (must be persistent string literal)• ZoneScoped[N]C • only 1 zone per scope • you the host application (e.g., a plugin)• ZoneScopedS(depth) • captures callstack • adds some overhead • useful for code exploration • max callstack depth: ~60 • (enables selective sampling profiling) • ZoneScoped[N|C|S]0 码力 | 84 页 | 8.70 MB | 6 月前3
Multi Producer, Multi Consumer, Lock Free, Atomic Queuefree, MPMC Queue - Internal algorithm ● Entries hold data value and sequence & data-present flag bit (lsb) ● The seq is 32 or 64 bits ● Data is 4 to 12 bytes, and can contain pointer / unique_ptr<> | Lockfree, MPMC Queue https://github.com/erez-strauss/lockfree_mpmc_queueLockfree, MPMC Queue - Depth Capacity 4 - S_0 - Empty State: Empty Seq: 3 D.Flag: 0 State: Empty Seq: 2 D.Flag: 0 State: Lockfree, MPMC Queue https://github.com/erez-strauss/lockfree_mpmc_queue 28Lockfree, MPMC Queue - Depth Capacity 4 - S_1 - One data item State: Empty Seq: 3 D.Flag: 0 State: Empty Seq: 2 D.Flag: 00 码力 | 54 页 | 886.12 KB | 6 月前3
Hello 算法 1.1.0 C++ 版。 ‧ 布尔类型 bool ,用于表示“是”与“否”判断。 基本数据类型以二进制的形式存储在计算机中。一个二进制位即为 1 比特。在绝大多数现代操作系统中,1 字节(byte)由 8 比特(bit)组成。 基本数据类型的取值范围取决于其占用的空间大小。下面以 Java 为例。 ‧ 整数类型 byte 占用 1 字节 = 8 比特,可以表示 28 个数字。 ‧ 整数类型 int 占用 4 需要表示小数,取值范围应该变小才对。 实际上,这是因为浮点数 float 采用了不同的表示方式。记一个 32 比特长度的二进制数为: ?31?30?29 … ?2?1?0 根据 IEEE 754 标准,32‑bit 长度的 float 由以下三个部分构成。 ‧ 符号位 S :占 1 位,对应 ?31 。 ‧ 指数位 E :占 8 位,对应 ?30?29 … ?23 。 ‧ 分数位 N :占 23 位,对应 hello‑algo.com 134 MD5 SHA‑1 SHA‑2 SHA‑3 推出时 间 1992 1995 2002 2008 输出长 度 128 bit 160 bit 256/512 bit 224/256/384/512 bit 哈希冲 突 较多 较多 很少 很少 安全等 级 低,已被成功攻击 低,已被成功攻 击 高 高 应用 已被弃用,仍用于数据完整性检 查0 码力 | 379 页 | 18.47 MB | 1 年前3
共 203 条
- 1
- 2
- 3
- 4
- 5
- 6
- 21













