| 40 | | */ |
|---|
| 41 | | |
|---|
| 42 | | /** @note |
|---|
| 43 | | * |
|---|
| 44 | | * Some remarks about __volatile__: Without this keyword gcc is allowed to reorder |
|---|
| 45 | | * or even optimize assembler instructions away. For instance, in the following code |
|---|
| 46 | | * the second rdmsr instruction is optimized away because gcc treats that instruction |
|---|
| 47 | | * as deterministic: |
|---|
| 48 | | * |
|---|
| 49 | | * @code |
|---|
| 50 | | * static inline uint64_t rdmsr_low(idx) |
|---|
| 51 | | * { |
|---|
| 52 | | * uint32_t low; |
|---|
| 53 | | * __asm__ ("rdmsr" : "=a"(low) : "c"(idx) : "edx"); |
|---|
| 54 | | * } |
|---|
| 55 | | * ... |
|---|
| 56 | | * uint32_t msr1 = rdmsr(1); |
|---|
| 57 | | * foo(msr1); |
|---|
| 58 | | * msr1 = rdmsr(1); |
|---|
| 59 | | * bar(msr1); |
|---|
| 60 | | * @endcode |
|---|
| 61 | | * |
|---|
| 62 | | * The input parameter of rdmsr_low is the same for both calls and therefore gcc will |
|---|
| 63 | | * use the result of the first call as input parameter for bar() as well. For rdmsr this |
|---|
| 64 | | * is not acceptable as this instruction is _not_ deterministic. This applies to reading |
|---|
| 65 | | * machine status information in general. |
|---|
| | 117 | * @remarks Some remarks about __volatile__: Without this keyword gcc is allowed to reorder |
|---|
| | 118 | * or even optimize assembler instructions away. For instance, in the following code |
|---|
| | 119 | * the second rdmsr instruction is optimized away because gcc treats that instruction |
|---|
| | 120 | * as deterministic: |
|---|
| | 121 | * |
|---|
| | 122 | * @code |
|---|
| | 123 | * static inline uint64_t rdmsr_low(int idx) |
|---|
| | 124 | * { |
|---|
| | 125 | * uint32_t low; |
|---|
| | 126 | * __asm__ ("rdmsr" : "=a"(low) : "c"(idx) : "edx"); |
|---|
| | 127 | * } |
|---|
| | 128 | * ... |
|---|
| | 129 | * uint32_t msr1 = rdmsr_low(1); |
|---|
| | 130 | * foo(msr1); |
|---|
| | 131 | * msr1 = rdmsr_low(1); |
|---|
| | 132 | * bar(msr1); |
|---|
| | 133 | * @endcode |
|---|
| | 134 | * |
|---|
| | 135 | * The input parameter of rdmsr_low is the same for both calls and therefore gcc will |
|---|
| | 136 | * use the result of the first call as input parameter for bar() as well. For rdmsr this |
|---|
| | 137 | * is not acceptable as this instruction is _not_ deterministic. This applies to reading |
|---|
| | 138 | * machine status information in general. |
|---|
| | 139 | * |
|---|