Skip to content

Commit 0dfdd96

Browse files
authored
Update associative_iteration.h (#67)
1 parent 8e4ea2d commit 0dfdd96

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

inc/zoo/swar/associative_iteration.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,13 @@ struct ArithmeticResultTriplet {
8282

8383
/// \brief "Safe" addition, meaning non-corrupting unsigned overflow addition
8484
/// and producing the flags for unsigned overflow (carry) and signed overflow.
85+
///
8586
/// This is the function to perform signed addition (that relies on supporting
8687
/// unsigned overflow)
8788
///
89+
/// Notice that the support for unsigned overflow directly allows signed
90+
/// addition (and both signed and unsigned substraction).
91+
///
8892
/// This function is called "full addition" because it can perform the addition
8993
/// with all the bits of the inputs by making sure the overflow (in the
9094
/// unsigned sense) does not cross the lane boundary.
@@ -102,7 +106,15 @@ struct ArithmeticResultTriplet {
102106
/// normal arithmetic, but in unsigned SWAR it is preferable to double the
103107
/// precision before executing addition, thus guaranteeing no overflow will
104108
/// occur and using the more performant operator+ addition. Hence,
105-
/// the carry and overflow flags are mostly useful in SWAR for detection of unsigned overflow (as for unsigned addition they are semantically identical.
109+
/// the carry flag is mostly useful in SWAR for detection of unsigned overflow,
110+
/// as opposed to a helper to achieve higher precision as it is normally used:
111+
/// Once we support non-power-of-two sizes of lanes in number of bits, we could
112+
/// have transformations that would convert a SWAR of lanes of N bits to a SWAR
113+
/// of (N + 1) bits, however, functionally, the performance cost of doing this
114+
/// will be strictly higher than doubling the bit count of the current SWAR.
115+
/// With double the number of bits, not only are additions guaranteed to not
116+
/// overflow (as unsigned) but even multiplications won't. Then it is not
117+
/// practical to use the carry bit for other than detection of unsigned overflow.
106118
///
107119
/// The signed integer interpretation is two's complement, which
108120
/// routinely overflows (when interpreted as unsigned). Signed overflow may only

0 commit comments

Comments
 (0)