With simple functions like math.square, I think it’s pretty unlikely Burst would need special intrinsics to optimize the code, so you can almost certainly just implement it yourself (or copy the implementation above) and get equal performance.
As far as I understand, most of the code in Unity.Mathematics doesn’t get any special treatment by Burst. You can write your own math library and as long as you use it in a Burst-compiled job, it will get optimized nicely.
math.square(myVar) seems more verbose than myVar * myVar but ok ^^
In fact, @apkdev summed it up nicely with
[quote=“apkdev, post:4, topic: 850547, username:apkdev”] most of the code in Unity.Mathematics doesn’t get any special treatment by Burst
[/quote]Even stuff like myfloat4.xxyy is vectorized optimally by LLVM (the backbone of Burst).
Some major exceptions to that rule are, for instance the math.shuffle functions, half conversions etc. etc. and most importantly all the trig functions and stuff like math.log, math.exp and all that, which actually calls into the Sleef library when using Burst.
[quote=“apkdev, post:4, topic: 850547, username:apkdev”]
You can write your own math library and as long as you use it in a Burst-compiled job, it will get optimized nicely.
[/quote].
While that is generally true, I’ve had to fight the compiler so very often when writing my own libraries, that I mostly stick to Burst intrinsics when necessary - especially when handling vectors which don’t fill up an entire SIMD register (128/256 bits), since LLVM has some major problems with such types. That makes me think that Unity.Mathematics’ types like int3 also get special treatment by Burst.
And also: even trivial control flow, which could be easily vectorized by hand, is most often not vectorized by Burst/LLVM, which is why one should stick to math.select, which is also an actual intrinsic function.