Teaching expression() to treat some operations specially
Alan Modra
amodra@gmail.com
Mon Jul 11 03:08:34 GMT 2022
On Mon, Jul 11, 2022 at 03:33:55AM +0100, lkcl wrote:
> alan thank you for the insights. i am using an unusual mailer which only topposts: rather than subject everyone to that i'm trimming all context.
>
> some background on svp64 predication (which is not part of Power ISA): it is the same concept as RVV and NEC SX Aurora (Cray-style) predicate masks except a bit more sophisticated. basic concept of Predicated Cray Vectors: elements may be dynamically skipped at runtime based on VL bits read from the regiater file:
>
> for i in range(VL):
> if get_mask()&(1<<i) == 0: continue
> // do operation
>
> get_mask() above may be one of the following sources:
>
> * all ones (disables predication)
> * the contents of r3, r10, r31 or their bit-inverses
> * 1<<r3 i.e. one single unary bit
> * the concatenation (and inversion) of a selected CR Field
> from CR0, CR1, ..... CRn
> sm=eq means concatenate CR0.eq CR1.eq CR2.eq as the mask
>
> i particularly like 1<<r3 because it is
>
> for i in range(VL):
> if (1<<GPR(r3))&(1<<i) == 0: continue
> GPR(RT+i) = GPR(RA+i) + GPR(RB+i) # vector add
>
> i.e. just
>
> GPR(RT+GPR(r3)) = GPR(RA+GPR(r3)) + GPR(RB+GPR(r3))
>
>
> this should help clear up some potential confusion on the meaning of sm=~r3, it is not the inversion of a static constant "3" (to create 0xfff....fffc) but a mnemonic to put a bitpattern into the 24-bit prefix, "at *instruction execute* time please read then use contents of register r3 as the predicate mask, invert all its bits before passing it on".
OK, then you'll want ppc_parse_name to continue to create O_register
values. I think in that case (haven't checked) that you'll get a tree
for ~r3, top node with X_op = O_bit_not and X_add_symbol an expression
symbol with value X_op = O_register, X_add_number = 3. There is
opportunity in ppc_optimize_expr to fiddle that tree to something
nicer.
> we could have used "sm=0b0111" or other numeric code and simply dropped that directly into the 24-bit prefix. however this loses the opportunity to perform macro substitution.
>
> another idea we discussed was to move the "~" to the lhs:
>
> ~sm=r3 / !sm=r3
>
> or
>
> sm ~= r3
>
> on the basis that only the rhs gets passed to expression(). in english:
>
> inverted source mask is r3
>
> readability of 1<<r3 is compromised however by trying something aimilar. we thought perhaps "sm=ur3" or such, for "source mask is unary from r3" but it is pushing things.
>
> adapting 0_constant to recognise 1<<r3 as a special pattern would help preserve readability greatly. i take it you mean that after the lexer has recognised "1" "<<" "r3" that there is a tree-walk done by cr_operand() that *replaces* the patterns?
>
> l.
>
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list