mathemathics lib's github functions not included by default

a was checking mathematics library on Unity.Mathematics/src/Unity.Mathematics/math.cs at master · Unity-Technologies/Unity.Mathematics · GitHub

And it seems some function are not included by default like this one :
7379414--900281--upload_2021-8-1_16-29-53.png

The question is: Are thoses functions not added because Burst won’t recognize them or just a miss?

PS: I checked my version of unity mathematics and reset my library to be sure the problem was not on my side.

According to the change log on GitHub these additions are currently still unreleased:

so we can assume Burst will have no effect on these function for now?

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.

:smile: 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.

3 Likes

thanks for thoses informations it really helps

1 Like