Skip to content

Instantly share code, notes, and snippets.

@bbrezillon
Created August 10, 2020 14:39
Show Gist options
  • Select an option

  • Save bbrezillon/9283df26059db636a12a8f7668aeeafd to your computer and use it in GitHub Desktop.

Select an option

Save bbrezillon/9283df26059db636a12a8f7668aeeafd to your computer and use it in GitHub Desktop.
static nir_ssa_def *
build_round(nir_builder *nb, nir_ssa_def *src)
{
nir_ssa_def *half = nir_imm_floatN_t(nb, 0.5, src->bit_size);
nir_ssa_def *truncated = nir_ftrunc(nb, src);
nir_ssa_def *remainder = nir_fsub(nb, src, truncated);
return nir_bcsel(nb, nir_fge(nb, nir_fabs(nb, remainder), half),
nir_fadd(nb, truncated, nir_fsign(nb, src)), truncated);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment