32-bit Integer Max/Min on Tenstorrent

30th January, 2026

Computing max/min of signed (two’s complement) or unsigned 32-bit integers is not directly supported on Tenstorrent’s AI accelerators. The available options are:

Binary Case

First, we’ll look at calculating max(a, b) and min(a, b), where a and b are tensors and processed elementwise.

32-bit Signed Integers

Looking more carefully at the SFPSWAP option, and using the following definition:

swap_minmax(x, y):
    # returns (min_sm(x, y), max_sm(x, y))
    # sign-magnitude ordering, with -0 < +0

Note that for max:

Similarly, for min:

In both cases, we simply have to check for the case where both values are negative, and invert the result.

Putting this together, we have:

a, b = swap_minmax(a, b)
if msb(a) == 1 and msb(b) == 1:
    a, b = b, a

result_min = a
result_max = b

32-bit Unsigned Integers

An elegant way to handle unsigned integers is to observe that if we treat an unsigned integer as a sign-magnitude integer, then values with MSB=1 become negative. If both values have MSB=1, then when treated as sign-magnitude, their order is reversed, i.e. in order to compute the maximum of two unsigned integers with MSB=1, we need to compute their minimum when treated as sign-magnitude (and vice versa).

If exactly one operand has MSB=1, this continues to work, as sign-magnitude ordering places the unsigned maximum in the min_sm position (as it’s negative in sign-magnitude).

If both values have MSB=0, then we have to invert the result.

a, b = swap_minmax(a, b)
if msb(a) == 0 and msb(b) == 0:
    a, b = b, a

result_max = a
result_min = b

Unary Case

Now consider max(a, k) and min(a, k), where a is a tensor, and k is a fixed scalar, potentially allowing us to precompute a transformed constant like ~k before processing a elementwise.

32-bit Signed Integers

32-bit Unsigned Integers

Future Work

Of course, the above can be optimised via SFPLOADMACRO. Watch this space!

Acknowledgements

Thanks to Tenstorrent for sponsoring this work.