CUDA atomic functions Is is possible to modify cuda atomic functions


I would like to know if there is a way to perform atomic operations in global memory apart from using CUDA atomic functions. My problem is that I want to perform the following atomic operation on a global memory variable:

((old == 0) ? 0 : (old-1)) //where old is the old value stored in memory and the result is the new value I would like to store at that location
CUDA function atomicDec however does following:
(((old == 0) | (old > val)) ? val : (old-1))

Alternatively I would like to do:
((old >=val)? val : (old+1) but atomicInc does the following:
((old >= val) ? 0 : (old+1)),

I also looked at ptx assembly which just show instruction as ( mem location, val).

Anyone has any idea if this is possible.

Thanks a lot in advance.

Appendix B.11 of the Programming Guide starts with a description of how to derive any atomic function from atomicCAS().

tjanks. Found it in Programming guide version 4 :)