[PATCH] D137361: IR: Add atomicrmw uinc_wrap and udec_wrap

Ruiling, Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 7 16:51:50 PST 2022


ruiling added inline comments.


================
Comment at: llvm/docs/LangRef.rst:10471
+-  udec_wrap: ``*ptr = ((*ptr == 0) || (*ptr u> val)) ? val : (*ptr - 1)``
 
 Example:
----------------
JonChesterfield wrote:
> The expressions here look suspicious - I thought these operated as inc/dec then modulo value. Does inc(p,10) really go to zero if p has the initial value 15? If so clamp might be a better name.
> 
> Likewise the ==0 in dec, though I think unsigned compare makes that expression work. Is it *ptr = ((*ptr -1) % val) ?
> 
> 
The two operations work like maintaining the pointer to a circular/ring buffer (with `val+1` elements). The uinc_wrap would move the pointer forward while the udec_wrap would move the pointer backward. IMO, this is more of a wrap-around than clamp.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137361/new/

https://reviews.llvm.org/D137361



More information about the llvm-commits mailing list