
Sebastian Redl wrote:
Hi,
First off, this whole thing uses Boost 1.42.
I'm trying to define arithmetic types where some expression patterns will be matched and replaced by something else (e.g. a & ~b, the andnot pattern). The whole thing is a proof-of-concept and teach-myself-proto thing that should eventually do SIMD operations. Right now, though, it simply wraps integers.
Very laudable goal ;) I think i can give you some hints :p
What can I do? Can I teach matches<> to handle adapted types? Is there a "right" way to implement smartint so that it needn't be an adapted type, which would work around the whole issue? Is this a bug in Proto that is fixed in trunk, or can be fixed?
You need a grammar transform, not a context.
struct optimize_andnot :
or_<
where< proto::bitwise_and
{};
(more or less typos) Basically if yopu match a & ~b, you extarct left_ of the expression (ie a) then the child of the right part (ie b) and you construct a new node from that. Applyting this transform is done like: optimize_andnot optimizer; auto optimized = optimizer(your_expression); should return you the modified AST where a & ~b have been replaced everywhere by andnot(a,b). That's how we handle all the fused operations in NT² including vec_madd on altivec and such.