• About TC
  • Affiliate Disclaimer
  • Privacy Policy
  • TOS
  • Contact
Monday, June 16, 2025
Techcratic
  • TC
  • AI
    Artificial Intelligence

    Amazon Nova Lite enables Bito to offer a free tier option for its AI-powered code reviews

    Artificial Intelligence

    Bridging the Gap: New Datasets Push Recommender Research Toward Real-World Scale

    Artificial Intelligence

    7 Python Errors That Are Actually Features

    Artificial Intelligence

    10 Awesome OCR Models for 2025

    Artificial Intelligence

    5 Error Handling Patterns in Python (Beyond Try-Except)

    Artificial Intelligence

    Top 5 Alternative Data Career Paths and How to Learn Them for Free

    Artificial Intelligence

    Implementing Machine Learning Pipelines with Apache Spark

    Artificial Intelligence

    Learn Power BI for Free This Week

    Artificial Intelligence

    Build GraphRAG applications using Amazon Bedrock Knowledge Bases

  • Crypto
    Crypto to “Become Part of All Sectors” Under Trump: Kevin O’Leary

    Metaplanet Issues Fresh $210M Bonds to Evo Fund

    Bitcoin Going to $1M: Saylor’s Call Revives Interest in Adam Back’s 21M BTC Order

    Bitcoin Going to $1M: Saylor’s Call Revives Interest in Adam Back’s 21M BTC Order

    Bitcoin Eyes $30T Treasury Store of Value Market, Says Bitwise CEO

    Bitcoin Eyes $30T Treasury Store of Value Market, Says Bitwise CEO

    ZKJ Token Plummets More Than 60% in Flash Crash Amid Rug-Pull Allegations

    ZKJ Token Plummets More Than 60% in Flash Crash Amid Rug-Pull Allegations

    Bitcoin Holding $105K During War Is Bullish for Crypto

    Bitcoin Holding $105K During War Is Bullish for Crypto

    Saylor Signals Another Bitcoin Buy—Orange Dots Strike Again

    Saylor Signals Another Bitcoin Buy—Orange Dots Strike Again

    XRP Technical Analysis: Downtrend Dominates—Is the $2.05 Floor About to Collapse?

    XRP Technical Analysis: Downtrend Dominates—Is the $2.05 Floor About to Collapse?

    Best Presales to Buy Today – Which Coins Are Poised for a Breakout?

    Last 72 Hours to Join $49M Raise

    Corporate Bitcoin Holdings a ‘Blessing’ Now, Challenge Later, Says Roxom CEO

    Corporate Bitcoin Holdings a ‘Blessing’ Now, Challenge Later, Says Roxom CEO

  • Cybersecurity
    Cybersecurity

    AI Agents Run on Secret Accounts — Learn How to Secure Them in This Webinar

    Cybersecurity

    How to Address the Expanding Security Risk

    Cybersecurity

    ConnectWise to Rotate ScreenConnect Code Signing Certificates Due to Security Risks

    Cybersecurity

    5 Lessons from River Island

    Cybersecurity

    INTERPOL Dismantles 20,000+ Malicious IPs Linked to 69 Malware Variants in Operation Secure

    Cybersecurity

    SinoTrack GPS Devices Vulnerable to Remote Vehicle Control via Default Passwords

    Cybersecurity

    Researchers Uncover 20+ Configuration Risks, Including Five CVEs, in Salesforce Industry Cloud

    Cybersecurity

    Adobe Releases Patch Fixing 254 Vulnerabilities, Closing High-Severity Security Gaps

    Cybersecurity

    Researcher Found Flaw to Discover Phone Numbers Linked to Any Google Account

  • Deals
    Lexar 1TB Professional Go Portable SSD w/Hub, Supports Apple 4K 60fps ProRes, Up to…

    Lexar 1TB Professional Go Portable SSD w/Hub, Supports Apple 4K 60fps ProRes, Up to…

    Kingston NV3 1TB M.2 2280 NVMe SSD | PCIe 4.0 Gen 4×4 | Up to 6000 MB/s | SNV3S/1000G

    Kingston NV3 1TB M.2 2280 NVMe SSD | PCIe 4.0 Gen 4×4 | Up to 6000 MB/s | SNV3S/1000G

    Intel Core Ultra 7 Desktop Processor 265K – 20 cores (8 P-cores + 12 E-cores) up to 5.5…

    Intel Core Ultra 7 Desktop Processor 265K – 20 cores (8 P-cores + 12 E-cores) up to 5.5…

    Hitachi FIJ0038 Fuel Injector

    Hitachi FIJ0038 Fuel Injector

    EVGA Supernova 1300 P+, 80+ Platinum 1300W, Fully Modular, 10 Year Warranty, Includes…

    EVGA Supernova 1300 P+, 80+ Platinum 1300W, Fully Modular, 10 Year Warranty, Includes…

    Logitech G502 X Plus Wireless Gaming Mouse – LIGHTSPEED Optical, LIGHTFORCE Switches,…

    Logitech G502 X Plus Wireless Gaming Mouse – LIGHTSPEED Optical, LIGHTFORCE Switches,…

    Cable Matters 8-Pack Snagless Cat 5e Ethernet Cable – 5ft, Gigabit Cat5e Cable, Cat5e…

    Cable Matters 8-Pack Snagless Cat 5e Ethernet Cable – 5ft, Gigabit Cat5e Cable, Cat5e…

    Logitech iPad Pro 12.9 inch Keyboard Case | SLIM COMBO with Detachable, Backlit,…

    Logitech iPad Pro 12.9 inch Keyboard Case | SLIM COMBO with Detachable, Backlit,…

    TECKNET Ergonomic Mouse, Wireless Bluetooth Vertical Mouse, 4800 DPI Optical Tracking, 6…

    TECKNET Ergonomic Mouse, Wireless Bluetooth Vertical Mouse, 4800 DPI Optical Tracking, 6…

  • Gaming
    Hello Neighbor – Finland Story | Full Game Walkthrough

    Hello Neighbor – Finland Story | Full Game Walkthrough

    Elden Ring NIGHTREIGN Early Reviews Say It All….

    Elden Ring NIGHTREIGN Early Reviews Say It All….

    Zelda Oot episode 2 More tutorials

    Zelda Oot episode 2 More tutorials

    Zelda: The Minish Cap | Episode 13

    Zelda: The Minish Cap | Episode 13

    The Legend of Zelda: Breath of the Wild – Shada Naw Shrine Walkthrough [HD 1080P]

    The Legend of Zelda: Breath of the Wild – Shada Naw Shrine Walkthrough [HD 1080P]

    Zelda Breath of the Wild – All Rito Weapons (Complete Set Location)

    Zelda Breath of the Wild – All Rito Weapons (Complete Set Location)

    Walkthrough FR l Zelda Ocarina Of Time l Premier Flacon

    Walkthrough FR l Zelda Ocarina Of Time l Premier Flacon

    Five Nights At Freddy’s still going strong: The latest game briefly grappled with Dune over Steam’s top seller spot

    Five Nights At Freddy’s still going strong: The latest game briefly grappled with Dune over Steam’s top seller spot

    The Super Mario Bros Movie Reaction!

    The Super Mario Bros Movie Reaction!

  • Tesla
    Level 1/2 Tesla Charger – 16A 3.84KW Mobile EV Charging with 240V NEMA 6-20 Plug, 5-15…

    Level 1/2 Tesla Charger – 16A 3.84KW Mobile EV Charging with 240V NEMA 6-20 Plug, 5-15…

    Upgrade fit Tesla Model Y (2019-2023) Center Console Wireless Charger Mat – Silicone…

    Upgrade fit Tesla Model Y (2019-2023) Center Console Wireless Charger Mat – Silicone…

    Torx Plus Socket, 5-External Torx Socket 1/4″ Dr 10EPR Compatible With Tesla Model 3…

    Torx Plus Socket, 5-External Torx Socket 1/4″ Dr 10EPR Compatible With Tesla Model 3…

    Car Seat Organizers,Multi-functional Back Seat Protectors, Storage Pouches, and Tray…

    Car Seat Organizers,Multi-functional Back Seat Protectors, Storage Pouches, and Tray…

    AOHI USB C Car Charger, PD 45W&QC 30W 2 Port Type-C Fast Charging Car Charger Lighter…

    AOHI USB C Car Charger, PD 45W&QC 30W 2 Port Type-C Fast Charging Car Charger Lighter…

    Roof Sunshades for Tesla Model 3 2025, Upgraded 3.0 Sunroof Shade Sunshade Roof Sun…

    Roof Sunshades for Tesla Model 3 2025, Upgraded 3.0 Sunroof Shade Sunshade Roof Sun…

    SOOPII for Tesla Phone Mount,Strongest Magnetic Monitor Mount for Tesla 3/Y…

    SOOPII for Tesla Phone Mount,Strongest Magnetic Monitor Mount for Tesla 3/Y…

    A2C Gym Fitness Phone Mount for MagSafe – 17 N52 Strong Magnets Stable and Secure Phone…

    A2C Gym Fitness Phone Mount for MagSafe – 17 N52 Strong Magnets Stable and Secure Phone…

    3PCS All Weather Tesla Model 3 Highland Floor Mats 2024 2025 | Sleek Design,…

    3PCS All Weather Tesla Model 3 Highland Floor Mats 2024 2025 | Sleek Design,…

  • UFO
    UFO Cover Up – They Want You Confused About the Truth!

    UFO Cover Up – They Want You Confused About the Truth!

    Nitro Green for Men – 3.4 oz EDP Spray

    Nitro Green for Men – 3.4 oz EDP Spray

    Argentinian Town Has One Of The Best Documented Mass UFO Sightings | The Unexplained Files

    Football Fan Patch Trucker Hat – Netted Snapback Baseball Cap with Team Design for Men & Women

    Football Fan Patch Trucker Hat – Netted Snapback Baseball Cap with Team Design for Men & Women

    [F4A] Alien researcher reports her findings [Scientist Speaker] [Research]

    [F4A] Alien researcher reports her findings [Scientist Speaker] [Research]

    Secrets of the Moon (S11, E11) | Ancient Aliens | Full Episode

    Secrets of the Moon (S11, E11) | Ancient Aliens | Full Episode

    UFOs Over Arizona: A True History of Extraterrestrial Encounters in the Grand Canyon State

    UFOs Over Arizona: A True History of Extraterrestrial Encounters in the Grand Canyon State

    French Contactee confirms Intergalactic Confederation is seeding human worlds

    French Contactee confirms Intergalactic Confederation is seeding human worlds

    New Balance Men’s 574 Greens V2 Golf Shoe

    New Balance Men’s 574 Greens V2 Golf Shoe

No Result
View All Result
  • TC
  • AI
    Artificial Intelligence

    Amazon Nova Lite enables Bito to offer a free tier option for its AI-powered code reviews

    Artificial Intelligence

    Bridging the Gap: New Datasets Push Recommender Research Toward Real-World Scale

    Artificial Intelligence

    7 Python Errors That Are Actually Features

    Artificial Intelligence

    10 Awesome OCR Models for 2025

    Artificial Intelligence

    5 Error Handling Patterns in Python (Beyond Try-Except)

    Artificial Intelligence

    Top 5 Alternative Data Career Paths and How to Learn Them for Free

    Artificial Intelligence

    Implementing Machine Learning Pipelines with Apache Spark

    Artificial Intelligence

    Learn Power BI for Free This Week

    Artificial Intelligence

    Build GraphRAG applications using Amazon Bedrock Knowledge Bases

  • Crypto
    Crypto to “Become Part of All Sectors” Under Trump: Kevin O’Leary

    Metaplanet Issues Fresh $210M Bonds to Evo Fund

    Bitcoin Going to $1M: Saylor’s Call Revives Interest in Adam Back’s 21M BTC Order

    Bitcoin Going to $1M: Saylor’s Call Revives Interest in Adam Back’s 21M BTC Order

    Bitcoin Eyes $30T Treasury Store of Value Market, Says Bitwise CEO

    Bitcoin Eyes $30T Treasury Store of Value Market, Says Bitwise CEO

    ZKJ Token Plummets More Than 60% in Flash Crash Amid Rug-Pull Allegations

    ZKJ Token Plummets More Than 60% in Flash Crash Amid Rug-Pull Allegations

    Bitcoin Holding $105K During War Is Bullish for Crypto

    Bitcoin Holding $105K During War Is Bullish for Crypto

    Saylor Signals Another Bitcoin Buy—Orange Dots Strike Again

    Saylor Signals Another Bitcoin Buy—Orange Dots Strike Again

    XRP Technical Analysis: Downtrend Dominates—Is the $2.05 Floor About to Collapse?

    XRP Technical Analysis: Downtrend Dominates—Is the $2.05 Floor About to Collapse?

    Best Presales to Buy Today – Which Coins Are Poised for a Breakout?

    Last 72 Hours to Join $49M Raise

    Corporate Bitcoin Holdings a ‘Blessing’ Now, Challenge Later, Says Roxom CEO

    Corporate Bitcoin Holdings a ‘Blessing’ Now, Challenge Later, Says Roxom CEO

  • Cybersecurity
    Cybersecurity

    AI Agents Run on Secret Accounts — Learn How to Secure Them in This Webinar

    Cybersecurity

    How to Address the Expanding Security Risk

    Cybersecurity

    ConnectWise to Rotate ScreenConnect Code Signing Certificates Due to Security Risks

    Cybersecurity

    5 Lessons from River Island

    Cybersecurity

    INTERPOL Dismantles 20,000+ Malicious IPs Linked to 69 Malware Variants in Operation Secure

    Cybersecurity

    SinoTrack GPS Devices Vulnerable to Remote Vehicle Control via Default Passwords

    Cybersecurity

    Researchers Uncover 20+ Configuration Risks, Including Five CVEs, in Salesforce Industry Cloud

    Cybersecurity

    Adobe Releases Patch Fixing 254 Vulnerabilities, Closing High-Severity Security Gaps

    Cybersecurity

    Researcher Found Flaw to Discover Phone Numbers Linked to Any Google Account

  • Deals
    Lexar 1TB Professional Go Portable SSD w/Hub, Supports Apple 4K 60fps ProRes, Up to…

    Lexar 1TB Professional Go Portable SSD w/Hub, Supports Apple 4K 60fps ProRes, Up to…

    Kingston NV3 1TB M.2 2280 NVMe SSD | PCIe 4.0 Gen 4×4 | Up to 6000 MB/s | SNV3S/1000G

    Kingston NV3 1TB M.2 2280 NVMe SSD | PCIe 4.0 Gen 4×4 | Up to 6000 MB/s | SNV3S/1000G

    Intel Core Ultra 7 Desktop Processor 265K – 20 cores (8 P-cores + 12 E-cores) up to 5.5…

    Intel Core Ultra 7 Desktop Processor 265K – 20 cores (8 P-cores + 12 E-cores) up to 5.5…

    Hitachi FIJ0038 Fuel Injector

    Hitachi FIJ0038 Fuel Injector

    EVGA Supernova 1300 P+, 80+ Platinum 1300W, Fully Modular, 10 Year Warranty, Includes…

    EVGA Supernova 1300 P+, 80+ Platinum 1300W, Fully Modular, 10 Year Warranty, Includes…

    Logitech G502 X Plus Wireless Gaming Mouse – LIGHTSPEED Optical, LIGHTFORCE Switches,…

    Logitech G502 X Plus Wireless Gaming Mouse – LIGHTSPEED Optical, LIGHTFORCE Switches,…

    Cable Matters 8-Pack Snagless Cat 5e Ethernet Cable – 5ft, Gigabit Cat5e Cable, Cat5e…

    Cable Matters 8-Pack Snagless Cat 5e Ethernet Cable – 5ft, Gigabit Cat5e Cable, Cat5e…

    Logitech iPad Pro 12.9 inch Keyboard Case | SLIM COMBO with Detachable, Backlit,…

    Logitech iPad Pro 12.9 inch Keyboard Case | SLIM COMBO with Detachable, Backlit,…

    TECKNET Ergonomic Mouse, Wireless Bluetooth Vertical Mouse, 4800 DPI Optical Tracking, 6…

    TECKNET Ergonomic Mouse, Wireless Bluetooth Vertical Mouse, 4800 DPI Optical Tracking, 6…

  • Gaming
    Hello Neighbor – Finland Story | Full Game Walkthrough

    Hello Neighbor – Finland Story | Full Game Walkthrough

    Elden Ring NIGHTREIGN Early Reviews Say It All….

    Elden Ring NIGHTREIGN Early Reviews Say It All….

    Zelda Oot episode 2 More tutorials

    Zelda Oot episode 2 More tutorials

    Zelda: The Minish Cap | Episode 13

    Zelda: The Minish Cap | Episode 13

    The Legend of Zelda: Breath of the Wild – Shada Naw Shrine Walkthrough [HD 1080P]

    The Legend of Zelda: Breath of the Wild – Shada Naw Shrine Walkthrough [HD 1080P]

    Zelda Breath of the Wild – All Rito Weapons (Complete Set Location)

    Zelda Breath of the Wild – All Rito Weapons (Complete Set Location)

    Walkthrough FR l Zelda Ocarina Of Time l Premier Flacon

    Walkthrough FR l Zelda Ocarina Of Time l Premier Flacon

    Five Nights At Freddy’s still going strong: The latest game briefly grappled with Dune over Steam’s top seller spot

    Five Nights At Freddy’s still going strong: The latest game briefly grappled with Dune over Steam’s top seller spot

    The Super Mario Bros Movie Reaction!

    The Super Mario Bros Movie Reaction!

  • Tesla
    Level 1/2 Tesla Charger – 16A 3.84KW Mobile EV Charging with 240V NEMA 6-20 Plug, 5-15…

    Level 1/2 Tesla Charger – 16A 3.84KW Mobile EV Charging with 240V NEMA 6-20 Plug, 5-15…

    Upgrade fit Tesla Model Y (2019-2023) Center Console Wireless Charger Mat – Silicone…

    Upgrade fit Tesla Model Y (2019-2023) Center Console Wireless Charger Mat – Silicone…

    Torx Plus Socket, 5-External Torx Socket 1/4″ Dr 10EPR Compatible With Tesla Model 3…

    Torx Plus Socket, 5-External Torx Socket 1/4″ Dr 10EPR Compatible With Tesla Model 3…

    Car Seat Organizers,Multi-functional Back Seat Protectors, Storage Pouches, and Tray…

    Car Seat Organizers,Multi-functional Back Seat Protectors, Storage Pouches, and Tray…

    AOHI USB C Car Charger, PD 45W&QC 30W 2 Port Type-C Fast Charging Car Charger Lighter…

    AOHI USB C Car Charger, PD 45W&QC 30W 2 Port Type-C Fast Charging Car Charger Lighter…

    Roof Sunshades for Tesla Model 3 2025, Upgraded 3.0 Sunroof Shade Sunshade Roof Sun…

    Roof Sunshades for Tesla Model 3 2025, Upgraded 3.0 Sunroof Shade Sunshade Roof Sun…

    SOOPII for Tesla Phone Mount,Strongest Magnetic Monitor Mount for Tesla 3/Y…

    SOOPII for Tesla Phone Mount,Strongest Magnetic Monitor Mount for Tesla 3/Y…

    A2C Gym Fitness Phone Mount for MagSafe – 17 N52 Strong Magnets Stable and Secure Phone…

    A2C Gym Fitness Phone Mount for MagSafe – 17 N52 Strong Magnets Stable and Secure Phone…

    3PCS All Weather Tesla Model 3 Highland Floor Mats 2024 2025 | Sleek Design,…

    3PCS All Weather Tesla Model 3 Highland Floor Mats 2024 2025 | Sleek Design,…

  • UFO
    UFO Cover Up – They Want You Confused About the Truth!

    UFO Cover Up – They Want You Confused About the Truth!

    Nitro Green for Men – 3.4 oz EDP Spray

    Nitro Green for Men – 3.4 oz EDP Spray

    Argentinian Town Has One Of The Best Documented Mass UFO Sightings | The Unexplained Files

    Football Fan Patch Trucker Hat – Netted Snapback Baseball Cap with Team Design for Men & Women

    Football Fan Patch Trucker Hat – Netted Snapback Baseball Cap with Team Design for Men & Women

    [F4A] Alien researcher reports her findings [Scientist Speaker] [Research]

    [F4A] Alien researcher reports her findings [Scientist Speaker] [Research]

    Secrets of the Moon (S11, E11) | Ancient Aliens | Full Episode

    Secrets of the Moon (S11, E11) | Ancient Aliens | Full Episode

    UFOs Over Arizona: A True History of Extraterrestrial Encounters in the Grand Canyon State

    UFOs Over Arizona: A True History of Extraterrestrial Encounters in the Grand Canyon State

    French Contactee confirms Intergalactic Confederation is seeding human worlds

    French Contactee confirms Intergalactic Confederation is seeding human worlds

    New Balance Men’s 574 Greens V2 Golf Shoe

    New Balance Men’s 574 Greens V2 Golf Shoe

No Result
View All Result
Techcratic
No Result
View All Result
Home Hacker News

UNORM and SNORM to float, hardware edition

Hacker News by Hacker News
December 26, 2024
in Hacker News
Reading Time: 8 mins read
121 9
A A
0

2024-12-24 10:54:00
fgiesen.wordpress.com

I mentioned in a previous post that doing exact UNORM or SNORM conversions to float in hardware was not particularly expensive, but didn’t go into detail how. Let’s rectify that! (If you haven’t read that post yet, please start there if you need an explanation of what the UNORM and SNORM formats are, as well as the basic idea.)

Previously, I explained how for n ≥ 1,

\displaystyle \frac{x}{2^n - 1} = \sum_{k=1}^\infty \frac{x}{2^{nk}}

using the specific case n=8, but the proof is identical for other n. For UNORM8, SNORM8, UNORM16 and SNORM16 we need the cases n=8, n=7, n=16 and n=15, respectively. This is already good news, because this boils down to just a number of bit shifts (for the divisions by powers of two) and adds. In the cases we care about for UNORM/SNORM conversions, we also have 0 ≤ x ≤ 2n – 1, meaning it’s actually even simpler than adds, because we have n-bit values shifted by multiples of n bits, making the bit ranges non-overlapping, so there’s not even real additions involved, we’re really just repeating a bit string over and over. Therefore, even though expanding our division by 2n – 1 into an infinite series looks scary at first sight, it gives us a straightforward way to get the exact quotient to as many significant digits as we want.

With the scary-looking division step turning into something fairly benign, this looks fairly doable, but there’s a few special cases to take care of first.

Special values

Ultimately, our goal is to turn our integer inputs into floating-point numbers. In this post I’m assuming we want to convert to the IEEE 754 binary32 format, other output formats work similarly though. That means we need to determine the correct values for the sign, exponent and significand fields.

Both UNORM and SNORM formats have a few particular values that need some extra care for various reasons. For UNORM8, the two special values are the extremal ones: 0x00 (which turns into 0.0) and 0xff (which turns into 1.0). Both of these produce all-zero significand bits and exponent values that don’t occur for any of the other values (biased exponent values of 0 and 127, respectively), and it’s easiest to treat them as special cases.

UNORM16 is similar, with the special values being 0x0000 (turns into 0.0) and 0xffff (turns into 1.0). Also, UNORM8 and UNORM16 are very closely related. Converting a UNORM8 value x to float is exactly the same as converting the UNORM16 value (x to float. (This works because 65535 = 2562 – 12 = (256 – 1) * (256 + 1) = 255 * 257 by the usual difference-of-squares formula, so instead of dividing x/255 we can also divide x*257 by 65535.) Since this is just repeating the same byte value twice, one possible, and entirely sensible, implementation of both UNORM8- and UNORM16-to-float conversions is to treat the former as the latter with the single byte input replicated twice.

The SNORM formats are slightly more complicated: the divisors 127 and 32767 don’t have a common factor, so they’re actually distinct cases as far as we’re concerned. We also need to handle the sign, and there are a few more special values to consider. For the latter, in the SNORM8 case, 0 and 127 (bit patterns 0x00 and 0x7f) turn into 0.0 and 1.0 respectively, and we gain two additional inputs, -128 and -127 (bit patterns 0x80 and 0x81 respectively) that both map to -1.0. For SNORM16, the relevant bit patterns are 0x0000 -> 0.0, 0x7fff -> 1.0, { 0x8000, 0x8001 } -> -1.0.

IEEE754 binary32 float is a sign-magnitude format; we therefore also need to convert the two’s complement SNORM input values into separate sign and magnitude, which boils down to extracting the sign bit (MSB) and computing the absolute value of the input integer. The latter requires a 15-bit adder for SNORM16 that is also sufficient for SNORM8.

For both UNORM and SNORM formats, this takes care of all the special cases and leaves us with a fraction x / (2n – 1) where we know that x is nonzero and the quotient is not an integer, since we just took care of the cases with exact integer results.

The general case

That leaves the remaining cases, where we need to determine the exponent and the significand rounded to the target precision. I’ll work through it in detail for UNORM16, and add some final remarks at the end on how to handle the SNORM8 and SNORM16 cases. (UNORM8 is trivial to reduce to UNORM16, as pointed out above.)

For UNORM16, conceptually we want to compute x/65535.0 with infinite precision and then round the result to the nearest representable binary32 float, or whatever our target format is. All binary32 floats representing UNORM16 values are outside the subnormal range, which makes things fairly easy. The main thing is that we need to align the significand so it starts with a 1 bit to determine the correct exponent. We know x≠0, so there is definitely a 1 bit somewhere in x’s binary expansion. Therefore, normalizing x boils down to doing a leading zero count and shifting x accordingly:

// x has at most 16 bits (covers SNORM8/SNORM16 cases too)
num_lz = clz16(x)
normalized_x = x 

In practice, normalized_x and num_lz can be computed at the same time, not serially. One straightforward divide-and-conquer approach goes like this, but there are others:

normalized_x = x
num_lz = 0

if (normalized_x & 0xff00) == 0:
    num_lz += 8
    normalized_x 

This is not particular to UNORM->binary32 float conversions; regular uint16->binary32 conversions perform the same normalization step (and can easily be handled on the same datapath if desired).

Afterwards, normalized_x is known to have its MSB (bit 15) set, so we can treat it as a constant 1, which simplifies things very slightly.

Next, we compute the tentative exponent (which turns out to be the final exponent because there are no rounding cases that would change it). The largest UNORM16 value we handle in this path is 0xfffe, which falls into the [0.5,1) interval, and has a binary32 biased exponent of 126. Any extra leading zeros decrement that exponent further, so we get

exponent : uint8 = 126 - num_lz

and our calculation earlier told us that to get x/65535.0, we just need to keep repeating the normalized mantissa. Sans implicit leading 1 bit, that means we get 23 bits worth of significand by concatenating

initial_significand = { normalized_x[14:0], normalized_x[15:8] }

However, we still need to perform rounding. If we’re doing truncation (or rounding towards negative infinity, which is the same for non-negative numbers), this significand is final. If we’re rounding towards positive infinity or away from zero, we’re always adding 1 – normalized_x is not 0, which means there are always non-0 digits to the right of our significand, which means we should always round up in this case. That leaves round-to-nearest, which needs to look at the next-lower unrounded fraction bit, which in our case comes from normalized_x[7]. If that bit is 1, we need to increment initial_significand, otherwise we leave it as it is, meaning the final significand calculation for round-to-nearest is:

final_significand = initial_significand + normalized_x[7]

In short, all the standard IEEE rounding modes are easy and just require a single add at the end. This does not require a full-width adder: we don’t need to handle the case where the 16-bit normalized_x is all 1s, since that’s one of the special cases we handled outside. Since the bottom bits of initial_significand all come from normalized_x (with wrap-around since we keep repeating it), and we only ever add at most 1, we know carries can’t propagate arbitrarily far – any carries will be absorbed after at most 15 bits, since we eventually have to run into at least one originally 0 bit in normalized_x. This is slightly more convenient than the situation with normal int-to-float conversions, where rounding can end up propagating a carry all the way across every significand bit and into the exponent bits. For UNORM or SNORM conversions, our initial guess at the exponent is always correct; the only case where rounding would ordinarily cause us to increment the exponent is the inputs corresponding to -1.0 and 1.0, but we handle those as special cases elsewhere.

For UNORM8/UNORM16, what’s the damage in total? A bit of multiplexing up front to handle UNORM8 and UNORM16 inputs both (to replicate the input byte into two copies turning UNORM8 into UNORM16), the detection and handling of the two special inputs 0x0000 and 0xffff, the 16-bit leading zero count/normalization, a 16-bit adder for the rounding, and the rest is wiring. Nothing particularly expensive!

Dealing with SNORM formats

I won’t work through it in detail for SNORM8/SNORM16, but the same idea applies. For these formats, there’s a few more special cases to handle up front, and (as I’ve described it) we need to also detect the sign of the input (trivial, it’s just in the operand MSB) and compute the absolute value (in effect, a 16-bit adder).

After that, the significand datapath works the exact same way as the UNORM case. If we want to support directed roundings, we now have a sign bit to worry about, but that’s bog standard IEEE stuff and not hard. If we want a datapath that can handle all four of { UNORM8, UNORM16, SNORM8, SNORM16 }, probably the easiest way to do it is to place the SNORM8/SNORM16 absolute-value inputs into the top bits of the 16-bit leading-zero-count/normalize path.

Below that, we repeat the mantissa bits with a period of 15 bits for SNORM16 and a period of 7 bits for SNORM8 – a tiny bit more muxing. The rounding works exactly the same and the argument for why rounding only needs an adder covering the low 16 mantissa bits also stays the same.

And that’s it!

Does anyone have reason to care about this that doesn’t already know it? Probably not. I just thought it was fun to write up. I also wrote a small C++ test program to demonstrate that it this approach really gives the correct results.

Source Link


Keep your files stored safely and securely with the SanDisk 2TB Extreme Portable SSD. With over 69,505 ratings and an impressive 4.6 out of 5 stars, this product has been purchased over 8K+ times in the past month. At only $129.99, this Amazon’s Choice product is a must-have for secure file storage.

Help keep private content private with the included password protection featuring 256-bit AES hardware encryption. Order now for just $129.99 on Amazon!


Start your free Amazon Prime trial
today and unlock unlimited streaming and more!

Support Techcratic

If you find value in Techcratic’s insights and articles, consider supporting us with Bitcoin. Your support helps me, as a solo operator, continue delivering high-quality content while managing all the technical aspects, from server maintenance to blog writing, future updates, and improvements. Support Innovation! Thank you.

Bitcoin Address:

bc1qlszw7elx2qahjwvaryh0tkgg8y68enw30gpvge

Please verify this address before sending funds.

Bitcoin QR Code

Simply scan the QR code below to support Techcratic.

Bitcoin QR code for donations

Please read the Privacy and Security Disclaimer on how Techcratic handles your support.

Disclaimer: As an Amazon Associate, Techcratic may earn from qualifying purchases.

Tags: Hacker News
Previous Post

Study of chimps cracking nuts shows some are much better at it than others

Next Post

Brazilian Hacker Charged for Extorting $3.2M in Bitcoin After Breaching 300,000 Accounts

Hacker News

Hacker News

Stay updated with Hacker News, where technology meets entrepreneurial spirit. Get the latest on tech trends, startup news, and discussions from the tech community. Read the latest updates here at Techcratic.

Related Posts

KAIST NEWS CENTER
Hacker News

KAIST NEWS CENTER

June 15, 2025
1.3k
How fast can the RPython GC allocate?
Hacker News

How fast can the RPython GC allocate?

June 15, 2025
1.3k
Biofuels Policy, a Mainstay of American Agriculture, Has Been a Failure for the Climate, a New Report Claims
Hacker News

Biofuels Policy, a Mainstay of American Agriculture, Has Been a Failure for the Climate, a New Report Claims

June 15, 2025
1.3k
SakanaAI/text-to-lora: Hypernetworks that adapt LLMs for specific benchmark tasks using only textual task description as the input
Hacker News

SakanaAI/text-to-lora: Hypernetworks that adapt LLMs for specific benchmark tasks using only textual task description as the input

June 15, 2025
1.3k
tanelp/tiny-diffusion: A minimal PyTorch implementation of probabilistic diffusion models for 2D datasets.
Hacker News

tanelp/tiny-diffusion: A minimal PyTorch implementation of probabilistic diffusion models for 2D datasets.

June 15, 2025
1.3k
How we investigated Amsterdam’s attempt to build a ‘fair’ fraud detection model
Hacker News

How we investigated Amsterdam’s attempt to build a ‘fair’ fraud detection model

June 14, 2025
1.3k
Waymo rides cost more than Uber or Lyft — and people are paying anyway
Hacker News

Waymo rides cost more than Uber or Lyft — and people are paying anyway

June 14, 2025
1.3k
GitHub – zachlatta/sshtron: $ ssh sshtron.zachlatta.com
Hacker News

GitHub – zachlatta/sshtron: $ ssh sshtron.zachlatta.com

June 14, 2025
1.3k
Load More
Next Post
Cybersecurity

Brazilian Hacker Charged for Extorting $3.2M in Bitcoin After Breaching 300,000 Accounts

The Callisto Protocol Review | Worth the Hype?

The Callisto Protocol Review | Worth the Hype?

Unidentified Flying Object (Remastered)

Unidentified Flying Object (Remastered)

Your Tech Resources

  • 30 Second Tech ™
  • AI
  • App Zone ™
  • Apple
  • Ars Technica
  • CNET
  • ComputerWorld
  • Crypto News
  • Cybersecurity
  • Endgadget
  • Fossbytes
  • Gaming
  • GeekWire
  • Gizmodo
  • Google News
  • Hacker News
  • Harvard Tech
  • I Like Cats ™
  • I Like Dogs ™
  • LifeHacker
  • MacRumors
  • Macworld
  • Mashable
  • Microsoft
  • MIT Tech
  • PC World
  • Photofocus
  • Physics
  • Random Tech
  • Retro Rewind ™
  • Robot Report
  • SiliconANGLE
  • SlashGear
  • Smartphone
  • StackSocial
  • Tech Art
  • Tech Careers
  • Tech Deals
  • Techcratic ™
  • TechCrunch
  • Techdirt
  • TechRepublic
  • Techs Got To Eat ™
  • TechSpot
  • Tesla
  • The Verge
  • TNW
  • Trusted Reviews
  • UFO
  • VentureBeat
  • Visual Capitalist
  • Wired
  • ZDNet

Tech News

  • 30 Second Tech ™
  • AI
  • Apple Insider
  • Ars Technica
  • CNET
  • ComputerWorld
  • Crypto News
  • Cybersecurity
  • Endgadget
  • ExtremeTech
  • Fossbytes
  • Gaming
  • GeekWire
  • Gizmodo

Tech News

  • Harvard Tech
  • MacRumors
  • Macworld
  • Mashable
  • Microsoft
  • MIT Tech
  • Physics
  • PC World
  • Random Tech
  • Retro Rewind ™
  • SiliconANGLE
  • SlashGear
  • Smartphone
  • StackSocial
  • Tech Careers

Tech News​

  • Tech Art
  • TechCrunch
  • Techdirt
  • TechRepublic
  • Techs Got To Eat ™
  • TechSpot
  • Tesla
  • The Verge
  • TNW
  • Trusted Reviews
  • UFO
  • VentureBeat
  • Visual Capitalist
  • Wired
  • ZDNet

Site Links

  • About Techcratic
  • Affiliate Disclaimer
  • Affiliate Link Policy
  • Contact Techcratic
  • Dealors Discount Store
  • Privacy and Security Disclaimer
  • Privacy Policy
  • RSS Feed
  • Site Map
  • Support Techcratic
  • Techcratic
  • Tech Deals
  • TOS
  • 𝕏
Click For A Secret Deal

Techcratic – Your All In One Tech Hub © 2020 – 2025
All Rights Reserved
∞

No Result
View All Result
  • 30 Second Tech ™
  • AI
  • App Zone ™
  • Apple
  • Ars Technica
  • CNET
  • Crypto News
  • Cybersecurity
  • Endgadget
  • Gaming
  • I Like Cats ™
  • I Like Dogs ™
  • MacRumors
  • Macworld
  • Tech Deals
  • Techcratic ™
  • Techs Got To Eat ™
  • Tesla
  • UFO
  • Wired