ispc/ispc

"is mask all on" paradigm to be added to stdlib

Open

#2,296 opened on Apr 6, 2022

 (4 comments) (0 reactions) (0 assignees)C++ (350 forks)auto 404
Good First IssueStandard Library

Repository metrics

Stars
 (2,930 stars)
PR merge metrics
 (PR metrics pending)

Description

Doing performance fine tuning, it may be beneficial to have separate code paths if the mask is "all on". Right now there are multiple ways of expressing this paradigm, which are not guaranteed to be optimal on all platforms. Possible ways of checking this are:

  1. __all(__mask). Seem to produces good code on all platforms, but uses builtins (that are not recommended for the use outside of standard library)
  2. ((1<<TARGET_WIDTH)-1 ^ lanemask()) == 0. Produces same good code, but not an obvious construct.
  3. popcnt(lanemask()) == programCount. Does no produce optimal code.

I suggest adding a standard library function, which implement the first case:

inline uniform bool is_mask_all_on() {
    return __all(__mask);
}

Contributor guide