Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved mathemathics lib's github functions not included by default

Discussion in 'Entity Component System' started by tassarho, Aug 1, 2021.

  1. tassarho

    tassarho

    Joined:
    Aug 25, 2019
    Posts:
    75
  2. apkdev

    apkdev

    Joined:
    Dec 12, 2015
    Posts:
    277
  3. tassarho

    tassarho

    Joined:
    Aug 25, 2019
    Posts:
    75
    so we can assume Burst will have no effect on these function for now?
     
  4. apkdev

    apkdev

    Joined:
    Dec 12, 2015
    Posts:
    277
    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.
     
  5. Mortuus17

    Mortuus17

    Joined:
    Jan 6, 2020
    Posts:
    105
    :D
    math.square(myVar)
    seems more verbose than
    myVar * myVar
    but ok ^^
    In fact, @apkdev summed it up nicely with
    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.

    .
    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.
     
    Last edited: Aug 2, 2021
    Ghat-Smith, tassarho and apkdev like this.
  6. tassarho

    tassarho

    Joined:
    Aug 25, 2019
    Posts:
    75
    thanks for thoses informations it really helps
     
    apkdev likes this.