def ceil_log2(n):
    """Returns the integer log2 of the smallest power-of-2 greater than or equal to ``n``.

    Raises a ``ValueError`` for negative inputs.
    """
    n = operator.index(n)
    if n < 0:
        raise ValueError(f"{n} is negative")
    if n == 0:
        return 0
    return (n - 1).bit_length()
Returns the integer log2 of the smallest power-of-2 greater than or equal to ``n``.

    Raises a ``ValueError`` for negative inputs.
    
amaranth/utils.py