TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Unorm and SNORM to float, hardware edition

31 点作者 luu5 个月前

2 条评论

mtklein5 个月前
It can be fun to explore the interactions of unorm and float bit representations even when you have float instructions. E.g. if you bit-or a unorm8 into 0x47000000 (32768.0f) then subtract 32768.0f, you&#x27;ll get a number very close to right, just a float multiply of (256&#x2F;255.0f) away. Reordering the math so that the subtraction and multiply can become a single FMA is a fun homework exercise.<p><pre><code> union { int bits; float f; } pun = {x}, scale = {0x47000000}; pun.bits |= scale.bits; pun.f -= scale.f; pun.f *= (256&#x2F;255.0f); </code></pre> This basically amounts to a software implementation of int-&gt;float conversion instructions; sadly I have never found a spot where it&#x27;s actually worth doing when you have those int-&gt;float instructions available already, even with the FMA as a single instruction.<p>It&#x27;s also worth considering whether your application can handle approximate conversion. If you have a [0,255] unorm in x, x + (x&gt;&gt;7) or equivalently x + (x&gt;0x7f) will round it to a [0,256] fixed-point value. Crucially, this rounding does handle 0x00 and 0xff inputs correctly. Once in fixed-point with a nice power-of-two divisor, you can play all sorts of tricks, either again making use of the bit representation of floats, using ARM fixed-point instructions, etc. If you&#x27;ve ever looked longingly at the pmulhrsw family of instructions, this is a ripe area to explore.
mgaunard5 个月前
For those who like me had no ideas what UNORM&#x2F;SNORM are, it&#x27;s a base-2 fixed-point representation apparently common in the latest GPU APIs (DirectX 10&#x2F;11, Vulkan).
评论 #42515927 未加载
评论 #42515905 未加载
评论 #42516605 未加载