|  3DSoftware.com > Programming > Integers > Page 5 |
|
Integers
Page 5
Wide Unsigned Integers Subtraction Subtraction assumes the operands are the same sign. If they are not, then use addition instead of subtraction. Likewise, when adding numbers with different signs, use subtraction instead of addition. The numbers are the same sign, and we subtract the smaller number from the larger number. This is the absolute value of the subtraction. A change sign flag (CHS) determines what the sign of the result will be. If the operands are equal, return zero. If the first operand is greater than the second operand, the first operand becomes A, the second operand becomes B, and CHS is cleared (made equal to zero). Otherwise the the first operand becomes B, the second becomes A, and CHS is set (made equal to 1). Then the digit packets of B are subtracted from the digit packets |
|
Subtracting Digits
First, set Then process the digits sequentially (not simd) beginning with the least significant digit. If |
|
Advanced Method
The method just discussed should work for initial implementations. A more advanced method is discussed in this section, for performing borrowing with simd. To subtract the digit packets of B from the digit packets First, set Copy (with MOVDQU) all of the new A digits to the next row of (two) simd registers: |
||||
|
||||
|
We now refer to the copy of A as a new variable S: |
||||
|
||||
|
|
||||
|
||||
|
POR each A digit with 0x40000000 to set Then we need to rotate (shift) the S digits one digit position to the left. First shift the high order S digits left |
||||
|
||||
|
Copy S3 S0 to another xmm register, right shift that other register |
||||
|
||||
|
Left shift the low order S digits |
||||
|
||||
|
Invoke PSUBD to subtract the borrows from the Note: In assembly language, AMD uses Microsoft (backwards) packet ordering to be compatible with Microsoft Windows. |
| Page 5 | ||||||
|
|
Copyright © 2008 by 3D Software. All rights reserved. 3D Software, P.O. Box 221190, Sacramento CA 95822 USA www.3DSoftware.com Contact us |
| Thursday, 20-Nov-2008 11:51:07 GMT |