Change bold code snippets to inline code blocks
This commit is contained in:
parent
f658bfbb40
commit
3c76d884ef
185 changed files with 1772 additions and 1772 deletions
22
13-02.md
22
13-02.md
|
|
@ -11,11 +11,11 @@ pages: 252-254
|
|||
---
|
||||
|
||||
"When I looked closely as this, I realized that the two cycles for the
|
||||
final **ADD** is just the sum of 1 cycle to load the data from memory,
|
||||
final `ADD` is just the sum of 1 cycle to load the data from memory,
|
||||
and 1 cycle to add it to DX, so the code could just as well have been
|
||||
written as shown in Listing 13.3. The final breakthrough came when I
|
||||
realized that by initializing AX to zero outside the loop, I could
|
||||
rearrange it as shown in Listing 13.4 and do the final **ADD DX,AX**
|
||||
rearrange it as shown in Listing 13.4 and do the final `ADD DX,AX`
|
||||
after the loop. This way there are two single-cycle instructions between
|
||||
the first and the fourth line, avoiding all pipeline stalls, for a total
|
||||
throughput of two cycles/char."
|
||||
|
|
@ -52,12 +52,12 @@ Clever 486 optimization can pay off big. QED.
|
|||
### BSWAP: More Useful Than You Might Think {#Heading4}
|
||||
|
||||
There are only 3 non-system instructions unique to the 486. None is
|
||||
earthshaking, but they have their uses. Consider **BSWAP. BSWAP** does
|
||||
earthshaking, but they have their uses. Consider `BSWAP`. `BSWAP` does
|
||||
just what its name implies, swapping the bytes (not bits) of a 32-bit
|
||||
register from one end of the register to the other, as shown in Figure
|
||||
13.2. (**BSWAP** can only work with 32-bit registers; memory locations
|
||||
13.2. (`BSWAP` can only work with 32-bit registers; memory locations
|
||||
and 16-bit registers are not valid operands.) The obvious use of
|
||||
**BSWAP** is to convert data from Intel format (least significant byte
|
||||
`BSWAP` is to convert data from Intel format (least significant byte
|
||||
first in memory, also called *little endian*) to Motorola format (most
|
||||
significant byte first in memory, or *big endian*), like so:
|
||||
|
||||
|
|
@ -67,16 +67,16 @@ bswap
|
|||
stosd
|
||||
```
|
||||
|
||||
**BSWAP** can also be useful for reversing the order of pixel bits from
|
||||
`BSWAP` can also be useful for reversing the order of pixel bits from
|
||||
a bitmap so that they can be rotated 32 bits at a time with an
|
||||
instruction such as **ROR EAX,1**. Intel's byte ordering for multiword
|
||||
instruction such as `ROR EAX,1`. Intel's byte ordering for multiword
|
||||
values (least-significant byte first) loads pixels in the wrong order,
|
||||
so far as word rotation is concerned, but **BSWAP** can take care of
|
||||
so far as word rotation is concerned, but `BSWAP` can take care of
|
||||
that.
|
||||
|
||||

|
||||
|
||||
As it turns out, though, **BSWAP** is also useful in an unexpected way,
|
||||
As it turns out, though, `BSWAP` is also useful in an unexpected way,
|
||||
having to do with making efficient use of the upper half of 32-bit
|
||||
registers. As any assembly language programmer knows, the x86 register
|
||||
set is too small; or, to phrase that another way, it sure would be nice
|
||||
|
|
@ -118,8 +118,8 @@ Not necessarily. Shifts and rotates are among the worst performing
|
|||
instructions of the 486, taking 2 to 3 cycles to execute. Thus, it takes
|
||||
2 cycles to rotate the skip value into CX in Listing 13.5, and 2 more
|
||||
cycles to rotate it back to the upper half of ECX. I'd say four cycles
|
||||
is a pretty steep price to pay, especially considering that a **MOV** to
|
||||
or from memory takes only one cycle. Basically, using **ROR** to access
|
||||
is a pretty steep price to pay, especially considering that a `MOV` to
|
||||
or from memory takes only one cycle. Basically, using `ROR` to access
|
||||
a 16-bit value in the upper half of a 16-bit register is a pretty
|
||||
marginal technique, unless for some reason you can't access memory at
|
||||
all (for example, if you're using BP as a working register, temporarily
|
||||
|
|
|
|||
Loading…
Reference in a new issue