@@ -99,44 +99,61 @@ void testEquality(bool testingEqual) {
9999 check (Int32x4 (_min, 2 , _max, 4 ), Int32x4 (0 , 2 , 0 , 4 ));
100100}
101101
102- void testAnyTrue () {
103- // Exhaustive over all 16 zero/non-zero lane combinations: anyTrue is true
104- // iff at least one lane is non-zero.
105- for (int bits = 0 ; bits < 16 ; bits++ ) {
106- final v = Int32x4 (
107- (bits & 1 ) != 0 ? 1 : 0 ,
108- (bits & 2 ) != 0 ? 1 : 0 ,
109- (bits & 4 ) != 0 ? 1 : 0 ,
110- (bits & 8 ) != 0 ? 1 : 0 ,
111- );
112- Expect .equals (bits != 0 , v.anyTrue);
102+ void testAnyTrueAndAllTrue () {
103+ // For the full 16-combination matrix:
104+ // - anyTrue is true iff at least one lane is non-zero (disjunction of the
105+ // lane flags).
106+ // - allTrue is true iff every lane is non-zero (conjunction of the flags).
107+ // - a lane counts as non-zero for any set bit, so each combination is filled
108+ // from several lane-value sets, including one with a distinct bit per lane
109+ // (no bit in common) and the int32 extremes.
110+ const laneValueSets = [
111+ (1 , 2 , 4 , 8 ),
112+ (- 1 , - 1 , - 1 , - 1 ),
113+ (1 , 2147483647 , - 2147483648 , 8 ),
114+ ];
115+ for (final vals in laneValueSets) {
116+ for (int bits = 0 ; bits < 16 ; bits++ ) {
117+ final v = Int32x4 (
118+ (bits & 1 ) != 0 ? vals.$1 : 0 ,
119+ (bits & 2 ) != 0 ? vals.$2 : 0 ,
120+ (bits & 4 ) != 0 ? vals.$3 : 0 ,
121+ (bits & 8 ) != 0 ? vals.$4 : 0 ,
122+ );
123+ // Expected result: at least one lane non-zero.
124+ Expect .equals (bits != 0 , v.anyTrue);
125+ // Equivalent to the disjunction of the lane flags.
126+ Expect .equals (v.flagX || v.flagY || v.flagZ || v.flagW, v.anyTrue);
127+ // Expected result: every lane non-zero.
128+ Expect .equals (bits == 0xf , v.allTrue);
129+ // Equivalent to the conjunction of the lane flags.
130+ Expect .equals (v.flagX && v.flagY && v.flagZ && v.flagW, v.allTrue);
131+ }
113132 }
114133
115- // anyTrue is "any bit set in any lane", not "signMask != 0" (which only
116- // checks the sign bit). Int32x4(1, 0, 0, 0) distinguishes them: it is
117- // non-zero but the sign bit is clear, so signMask is 0 while anyTrue is true.
134+ // Both look at any set bit, not the sign bit that signMask reads. Lanes with
135+ // only low bits set have signMask 0 but are still non-zero.
118136 final lowBit = Int32x4 (1 , 0 , 0 , 0 );
119137 Expect .equals (0 , lowBit.signMask);
120138 Expect .isTrue (lowBit.anyTrue);
139+ Expect .isFalse (lowBit.allTrue);
121140
122- // All lanes non-zero -> true.
123- Expect .isTrue (Int32x4 (- 1 , - 1 , - 1 , - 1 ).anyTrue);
141+ final lowBits = Int32x4 (1 , 1 , 1 , 1 );
142+ Expect .equals (0 , lowBits.signMask);
143+ Expect .isTrue (lowBits.allTrue);
124144
125- // Consistent with the comparison mask: a match makes anyTrue true .
145+ // Typically applied to a comparison mask .
126146 final a = Int32x4 (1 , 2 , 3 , 4 );
147+ Expect .isTrue (a.equal (a).allTrue);
127148 Expect .isFalse (a.equal (Int32x4 (5 , 6 , 7 , 8 )).anyTrue);
128149 Expect .isTrue (a.equal (Int32x4 (0 , 2 , 0 , 0 )).anyTrue);
129- Expect .isTrue (a.equal (a).anyTrue);
130-
131- // Equivalent to the disjunction of the lane flags.
132- final m = a.equal (Int32x4 (0 , 2 , 0 , 4 ));
133- Expect .equals (m.flagX || m.flagY || m.flagZ || m.flagW, m.anyTrue);
150+ Expect .isFalse (a.equal (Int32x4 (1 , 2 , 3 , 0 )).allTrue);
134151}
135152
136153void main () {
137154 for (int i = 0 ; i < 20 ; i++ ) {
138155 testEquality (true ); // equal
139156 testEquality (false ); // notEqual
140- testAnyTrue ();
157+ testAnyTrueAndAllTrue ();
141158 }
142159}
0 commit comments