On 6/21/25 16:50, Richard Henderson wrote:
+uint64_t HELPER(sve2p1_cntp_c)(uint32_t png, uint32_t desc) +{ + int pl = FIELD_EX32(desc, PREDDESC, OPRSZ); + int vl = pl * 8; + unsigned v_esz = FIELD_EX32(desc, PREDDESC, ESZ); + int lg2_width = FIELD_EX32(desc, PREDDESC, DATA) + 1; + unsigned p_esz; + int p_count, maxelem; + bool p_invert; + + /* C.f. Arm pseudocode CounterToPredicate. */ + if ((png & 0xf) == 0) { + /* Canonical false predicate. */ + return 0; + } + p_esz = ctz32(png); + + /* + * maxbit = log2(pl * 4) + * = log2(vl / 8 * 4) + * = log2(vl / 2) + * = log2(vl) - 1 + * maxbit_mask = ones<maxbit:0> + * = (1 << (maxbit + 1)) - 1 + * = (1 << (log2(vl) - 1 + 1)) - 1 + * = (1 << log2(vl)) - 1 + * = pow2ceil(vl) - 1 + * Note that we keep count in bytes, not elements. + */ + p_count = (png & (pow2ceil(vl) - 1)) >> 1;
This is too clever for it's own good, and misses masking out the esz bit we located via ctz above. All of the predicate-as-counter insns suffer the same error.
I'll put all of the counter parsing into some helper functions. r~