Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace cdf! macro with const fns #3334

Merged
merged 3 commits into from
Jan 6, 2024

Conversation

FreezyLemon
Copy link
Contributor

Notable changes:

  • cdf! always required the parameter count to be == CDF_LEN - 1, the new cdf function accepts any parameter count < CDF_LEN. Any values after the last parameter will be zero. (e.g. if the output has a length of 8 and the parameter count is 5, then the output values 6 to 8 will be zero). This means:

    let test: [u16; 4] = cdf!(123); // Error: Number of parameters must be exactly (4 - 1)
    let test: [u16; 4] = cdf([123]); // Works: test == [some_value, 0, 0, 0]
  • Added helper functions for multi-dimensional arrays (up to 5D) to avoid spamming the cdf macro/fn

    [
      cdf!(123, 456, 789),
      cdf!(987, 654, 321),
      // ...
    ]

    will become

    cdf_2d([
      [123, 456, 789],
      [987, 654, 321],
      // ...
    ])

    and so on.

  • Check all input parameters to be in the range [0, 32768] to avoid underflows in 32768 - val

  • Fully replaced macro with generic code. Type safety is ensured through the function signatures and compile-time assert! statements

The code for cdf_2d, cdf_3d etc. is a little messy. But it's the best way I found to keep these const without some sort of macroized implementation (which seems a bit overkill for just 5 similar functions).

Copy link

codecov bot commented Jan 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d555dc8) 88.48% compared to head (d57026b) 88.52%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3334      +/-   ##
==========================================
+ Coverage   88.48%   88.52%   +0.04%     
==========================================
  Files          88       89       +1     
  Lines       28231    28334     +103     
==========================================
+ Hits        24981    25084     +103     
  Misses       3250     3250              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@FreezyLemon FreezyLemon force-pushed the replace-cdf-macro branch 2 times, most recently from 6535fa7 to 371555b Compare January 5, 2024 22:04
Copy link
Collaborator

@lu-zero lu-zero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good! Thank you

@shssoichiro shssoichiro merged commit 7d773ea into xiph:master Jan 6, 2024
@FreezyLemon FreezyLemon deleted the replace-cdf-macro branch January 6, 2024 12:59
lu-zero pushed a commit that referenced this pull request Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants