Skip to content

Commit 941834a

Browse files
committed
mul -> imul
1 parent 41a8a91 commit 941834a

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎content/english/hpc/pipelining/branchless.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ There are no boolean types in assembly, nor any instructions that yield either o
3737
mov ebx, eax ; t = x
3838
sub ebx, 50 ; t -= 50
3939
sar ebx, 31 ; t >>= 31
40-
mul eax, ebx ; x *= t
40+
imul eax, ebx ; x *= t
4141
```
4242

43-
Another, more complicated way to implement this whole sequence is to convert this sign byte into a mask and then use bitwise `and` instead of multiplication: `((a[i] - 50) >> 1 - 1) & a`. This makes the whole sequence one cycle faster, considering that unlike other instructions, `mul` takes 3 cycles:
43+
Another, more complicated way to implement this whole sequence is to convert this sign byte into a mask and then use bitwise `and` instead of multiplication: `((a[i] - 50) >> 1 - 1) & a`. This makes the whole sequence one cycle faster, considering that unlike other instructions, `imul` takes 3 cycles:
4444

4545
```nasm
4646
mov ebx, eax ; t = x
4747
sub ebx, 50 ; t -= 50
4848
sar ebx, 31 ; t >>= 31
49-
; mul eax, ebx ; x *= t
49+
; imul eax, ebx ; x *= t
5050
sub ebx, 1 ; t -= 1 (causing underflow if t = 0)
5151
and eax, ebx ; x &= t
5252
```

0 commit comments

Comments
 (0)