What Volatile Means (and Doesn't Mean)## What Volatile Means (and Doesn't Mean) BEN SAKS ## Saks & Associates These notes are Copyright © 2024 by Ben Saks and Dan Saks and distributed with their permission by: Saks & Associates +1-412-521-4117 (voice) service@saksandassociates.com saksandassociates.com ## I ntroduction - The volatile qualifier is a vital tool for preventing compilers from performing certain harmful optimizations programmers aren’t clear on exactly what protections volatile provides. ■ As such, many programmers apply the volatile qualifier incorrectly. ■ A misapplied volatile might: • prevent optimizations unnecessarily0 码力 | 32 页 | 901.80 KB | 1 年前3
Template Metaprogramming: Type Traits## is_void: cv qualifiers • Is void const void? • Is void volatile void? ## is\_void: cv qualifiers • Is void const void? • Is void volatile void? • is_void is in Primary Type Categories ## is\_void: is\_void: cv qualifiers • Is void const void? • Is void volatile void? • is_void is in Primary Type Categories "For any given type T, the result of applying one of these templates to T and to cv T shall shall yield the same result." ## is\_void: cv qualifiers • Is void const void? • Is void volatile void? • is_void is in Primary Type Categories "For any given type T, the result of applying one0 码力 | 403 页 | 5.30 MB | 1 年前3
The Zig Programming Language 0.12.0 Documentationmain(); /home/ci/actions-runner/_work/zig-bootstrap/out/host/lib/zig/std/start.zig:253:5: 0x103: asm volatile (switch (native_arch) { All 1 tests passed. 1 errors were logged. 1 tests leaked memory. error: C Pointers ## volatile Loads and stores are assumed to not have side effects. If a given load or store should have side effects, such as Memory Mapped Input/Output (MMIO), use volatile. In the following the same order as in source code: test_volatile.zig const expect = @import("std").testing.expect; test "volatile" { const mmio_ptr: *volatile u8 = @ptrFromInt(0x12345678); try0 码力 | 241 页 | 7.37 MB | 2 年前3
The Zig Programming Language 0.11.0 DocumentationPointers #### 13.1. volatile Loads and stores are assumed to not have side effects. If a given load or store should have side effects, such as Memory Mapped Input/Output (MMIO), use volatile. In the following the same order as in source code: test_volatile.zig const expect = @import("std").testing.expect; test "volatile" { const mmio_ptr: *volatile u8 = @ptrFromInt(0x12345678); try expect(@TypeOf(mmio_ptr) == *volatile u8); } Shell $ zig test test_volatile.zig 1/1 test.volatile... OK All 1 tests passed. Note that volatile is unrelated to concurrency and Atomics. If you see code0 码力 | 238 页 | 7.80 MB | 2 年前3
CppCon 2021: Persistent Data Structuresas a new tier in the memory hierarchy that delivers capacity of non-volatile storage at speeds close to DRAM Benefits: Non-volatile storage Byte addressable Provides higher density than DRAM Has access |0000|0000|000000||| ## Statistics |Feature|DRAM|PMEM|NAND SSD| |---|---|---|---| |Volatility|Volatile|Non-Volatile|Non-Volatile| |Capacity|16GB-64GB \[2]|128GB, 256GB, 512GB \[2]|256GB-1TB \[3]| |Latency|0.1 x 1 a large number of updates ▶ High endurance Data set updates are computationally expensive Non-volatile, low latency |Introduction|Persistent Hash Map|Persistent Transactional Data Structures|Live De0 码力 | 56 页 | 1.90 MB | 1 年前3
C++ Memory Model: from C++11 to C++23(reads and writes) to volatile objects occur strictly according to the semantics of the expressions in which they occur. In particular, they are not reordered with respect to other volatile accesses on the same p45_1.jpg) ## V olatile • Volatile is not a synchronization tool • Volatile doesn’t affect threading • It's not an atomic value • It doesn’t add barriers Volatile: what is it good for? • Tells order. • Alas the CPU can still reorder ## V olatile: Bad Example int main() { int y = 1; volatile int* x = &y; auto w = std::thread([x]) { for (int i = 0; i < 50; i++) {0 码力 | 112 页 | 5.17 MB | 1 年前3
The Zig Programming Language 0.4.0 DocumentationOperators - Table of Operators - Precedence - Arrays - Vectors - SIMD - Pointers - volatile - Alignment - allowzero - Slices - struct - extern struct - packed struct - struct Bit Types ## volatile Loads and stores are assumed to not have side effects. If a given load or store should have side effects, such as Memory Mapped Input/Output (MMIO), use volatile. In the following debug.assert; test "volatile" { const mmio_ptr = @intToPtr(*volatile u8, 0x12345678); assert(@typeOf(mmio_ptr) == *volatile u8); } $ zig test test.zig Test 1/1 volatile...0K All tests passed0 码力 | 207 页 | 5.29 MB | 2 年前3
Comprehensive Rust ?processors ..... 278 53.1 Getting Ready to Rust ..... 278 53.2 Inline assembly ..... 280 53.3 Volatile memory access for MMIO ..... 281 53.4 Let's write a UART driver ..... 281 53.4.1 More traits write_volatile( DIR_OUTPUT | INPUT_DISCONNECT | PULL_DISABLED | DRIVE_S0S1 | SENSE_DISABLED, ); pin_cnf_28.write_volatile( registers, and no aliases exist. unsafe { gpio0_outclr.write_volatile(1 << 28); gpio0_outset.write_volatile(1 << 21); } loop {} } - GPIO 0 pin 21 is connected to0 码力 | 378 页 | 1009.46 KB | 2 年前3
Comprehensive Rust(Ukrainian) 202412write_volatile( DIR_OUTPUT | INPUT_DISCONNECT | PULL_DISABLED | DRIVE_S0S1 | SENSE_DISABLED, ); pin_cnf_28.write_volatile( і ніяких псевдонімів не існує. unsafe { gpio0_outclr.write_volatile(1 << 28); gpio0_outset.write_volatile(1 << 21); } loop {} } Файли SVD (System View Здійснення непостійного доступу до пам'яті для ММІО • Використовуйте pointer::read_volatile та pointer::write_volatile. • Николи не тримайте посилання. • Використовуйте &раш для отримання полів структур0 码力 | 396 页 | 1.08 MB | 1 年前3
Comprehensive Rust(Persian ) 202412aliases exist // } unsafe )pin_cnf_21.write_volatile DIR_OUTPUT INPUT_DISCONNECT | PULL_DISABLED | DRIVE_S0S1 | ,SENSE_DISABLED | ); )pin_cnf_28.write_volatile DIR_OUTPUT INPUT_DISCONNECT | PULL_DISABLED control registers, and no // .aliases exist // } unsafe ); (gpio0_outclr.write_volatile(1 << 28 ; (gpio0_outset.write_volatile(1 << 21 { }} loop { cargo embed --bin mmio ## memory- make qemu_psci Q ### MMIO ☐☐☐☐ ☐☐☐☐ ☐☐☐☐ ☐☐☐☐☐ ☐☐☐☐☐☐ 53.3 .☐☐☐☐☐☐☐☐☐pointer::write_volatile_pointer::read_volatile☐☐• .reference !addr_of □ struct field ☐!addr_of ☐ ### □□□□□□ UART □□□□□□ □□ □□□□□0 码力 | 393 页 | 987.97 KB | 1 年前3
共 400 条
- 1
- 2
- 3
- 4
- 5
- 6
- 40
相关搜索词
volatilecompiler optimizationsmemory barriersatomicitystd::uint32_tmetaprogramming techniquestype traitsspecializationprimary templatemetafunctionsZig LanguageStandard LibraryC InteropTestingBuild SystemZig语言标准库内联汇编构建系统交叉平台Persistent Data StructuresConcurrencyPersistenceTransactional MemoryOptane Persistent MemoryC++内存模型原子操作内存顺序数据依赖性编译器重排内存分配错误处理指针数组文档RustCargo类型系统变量和值控制流Comprehensive Rustбезпечний Rustнебезпечний Rustодночасність виконанняconcurrencythreaderror handlingsafety













