@triton.jit
def _compute_exp(group_max, rounding_mode, rand_bits, MBITS: tl.constexpr):
    """Compute shared exponent of group using specified rounding mode.

    Args:
        group_max (Tensor): Group of values to compute exponent of.
        rounding_mode (int or RoundingMode): Which rounding mode to use.
        rand_bits (int): Random integer values used for stochastic rounding.
        mbits (int): Number of mantissa bits in target mx4 format.

    Returns:
        Tensor: Shared exponent of group.
    """
    MBITS_FP32: tl.constexpr = 23
    M_ROUND: tl.constexpr = (1 << MBITS_FP32 - MBITS - 1) - 1
    RAND_MASK: tl.constexpr = (1 << MBITS_FP32 - MBITS) - 1
    if rounding_mode == 0:
        return tl.floor(tl.log2(group_max) + 0.5)
    if rounding_mode == 1:
        return _floor_log2(group_max)
    elif rounding_mode == 2:
        group_max = group_max.to(tl.int32, bitcast=True) + M_ROUND
        return _floor_log2(group_max)
    elif rounding_mode == 3:
        group_max = group_max.to(tl.int32, bitcast=True) + (RAND_MASK &
            rand_bits)
        return _floor_log2(group_max)
    else:
        return tl.ceil(tl.log2(group_max))
