code: def arbitrary_fp32_downcast(
      x,
      rounding: tl.constexpr,
      exponent_bits: tl.constexpr,
      mantissa_bits: tl.constexpr,
      exponent_bias: tl.constexpr,
  ):
      tl.static_assert(x.dtype == tl.float32, "input must be float32")
      numbits_dst: tl.constexpr = 1 + exponent_bits + mantissa_bits
      tl.static_assert(
          (numbits_dst == 8) or (numbits_dst == 16),
          "numbits_dst must be 8 or 16",
      )
  
      x = x.to(tl.uint32, bitcast=True)
  
      mantissa = x & 0x7FFFFF
      exponent = ((x >> 23) & 0xFF).to(tl.int32)
      mantissa = tl.where(
          exponent == 0, mantissa, mantissa + 0x800000
      ).to(tl.int32)
      exponent = tl.where(exponent == 0, exponent, exponent - 1)
  
      sign = x >> 31
  
      exponent = exponent + exponent_bias - 127
      adjustment: tl.constexpr = 0.5 ** (23 - mantissa_bits)
      mantissa = mantissa.to(tl.float32) * adjustment
  
      # make exponent nonnegative:
      mantissa = tl.where(
          exponent > -16, mantissa, 0.0
      )  # destination has fewer than 16 mantissa bits, so safe
      exponent = tl.where(exponent > -16, exponent, 0)
      mantissa = tl.where(
          exponent > -8, mantissa, mantissa * 0.00390625
      )
      exponent = tl.where(exponent > -8, exponent, exponent + 8)
      mantissa = tl.where(exponent > -4, mantissa, mantissa * 0.0625)
      exponent = tl.where(exponent > -4, exponent, exponent + 4)
      mantissa = tl.where(exponent > -2, mantissa, mantissa * 0.25)
      exponent = tl.where(exponent > -2, exponent, exponent + 2)
      mantissa = tl.where(exponent > -1, mantissa, mantissa * 0.5)
      exponent = tl.where(exponent > -1, exponent, exponent + 1)
  
      if rounding == "rtne":
          mantissa = tl.inline_asm_elementwise(
              """{
          cvt.rni.s32.f32 $0, $1;
  }""",
              "=r,r",
              [
                  mantissa,
              ],
              dtype=tl.int32,
              is_pure=True,
              pack=1,
          ).to(tl.uint32)
      elif rounding == "rtz":
          mantissa = tl.inline_asm_elementwise(
              """{
          cvt.rzi.s32.f32 $0, $1;
  }""",
              "=r,r",
              [
                  mantissa,
              ],
              dtype=tl.int32,
              is_pure=True,
              pack=1,
          ).to(tl.uint32)
      else:
          raise ValueError("unrecognized rounding mode")
  
      # Reassemble output floating-point representation:
      exponent = exponent.to(tl.uint32)
      y = (
          (sign << (exponent_bits + mantissa_bits))
          + (exponent << mantissa_bits)
          + mantissa
      )
      if numbits_dst == 8:
          y = y.to(tl.uint8)
      elif numbits_dst == 16:
          y = y.to(tl.uint16)
      return y
  
file_path: triton/python/test/unit/language/test_conversions.py
imports: import numpy
  import torch
  import pytest
  import triton
  import triton.language
label_desc: Use image node_id 6 for calling a global function with example usage: arbitrary_fp32_downcast(x, rounding, exponent_bits, mantissa_bits, exponent_bias) and returns: y