-
|
It currently seems that Interceptors can only intercept a method. Are there any ideas to allow replacing a whole statement or line. Reason: We have many mathematical expressions on arrays in our code, and with the extension members in C# 14 w'd like to add math operations on arrays and spans so that you are able to write ´´´ var C = Math.Log(A + B); with extension member we want to allow operators which should be possible in C# 14, also Log has been extended to deal with arrays. But this should only be a symbolic expression with no execution. What I wanted to have then is to replace the whole expression with a method call created by a source generator that resolves this expression into a vectorized call. The problem with interceptors currently is that I cannot replace this expression with my own. Are there any ideas around this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
I think what you do is define a method that describes your computation and then intercept it by reading it's contents and either output code as-as or rewriting code if it matches what your generator is looking for. So it's basically a sort of compiler within compiler. E.g.: // input
static void MyArrayComputation(float[] a, float[] b, float c[])
{
var d = a * b + c;
var log = Math.Log(d);
...
}
// generated
[InterceptsLocation(blabla)]
static void MyArrayComputationGenerated(float[] a, float[] b)
{
var d = FmaRoutineAllocNew(a, b, c); // your helper method because you've recognized that a * b + c can be optimized with FMA
var log = Math.Log(d);
...
} |
Beta Was this translation helpful? Give feedback.
I think what you do is define a method that describes your computation and then intercept it by reading it's contents and either output code as-as or rewriting code if it matches what your generator is looking for. So it's basically a sort of compiler within compiler.
E.g.: