Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7686987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:36:02+00:00 2026-05-31T19:36:02+00:00

saturating instructions saturate unsigned to unsigned or signed to signed int. What’s the best

  • 0

saturating instructions saturate unsigned to unsigned or signed to signed int.

What’s the best way to saturate signed 16-bit ints to unsigned byte?

In short, here’s the logic

uint8_t usat8(uint8_t u8, int16_t s16)
{
    s16 += u8;
    if(s16 <= 0) {
        return 0;
    } else if(s16 >=255){
        return 255;
    }else{
        return (uint8_t)s16;
    }
}

void add_row(uint8_t * dst, uint8_t * u8, int16_t * s16)
{
    for(int i=0; i<XXX; ++i)
    {
        dst[i] = usat8(u8[i] + s16[i]);
    }
}

values of s16 are usually not much off from the [0, 255] range, e.g. it’s safe to assume that abs(s16[x]) < 1000.

EDIT: I just realized that USAT16 actually saturates signed 16-bit int to unsigned integer. Simple USAT16 is the solution to the problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:36:04+00:00Added an answer on May 31, 2026 at 7:36 pm

    After 5 mins of thinking I have this idea (pseudo arm-asm):

    sadd16  sum, s16, u8                  @ do two additions in parallel
    
    orr     signs, 0x1001, sum, lsr #15   @ extract signs of the two 16 bit results
    usat16  sum, sum, #8                  @ saturate both of the 16-bit sums to unsigned 8-byte range
    uadd16  sum, sum, signs
    

    this way, if sign bit was set for any of the sums the resulting sum will become 256, or 0x100. When writing back the data the shifted out 0x1 will be discarded.

    Any comments, does that seem like the optimal approach, is there any better alternative?

    PS. I do it for an armv6 device, no NEON or armv6t2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best (cleanest, most efficient) way to write saturating addition in C?
I want to convert a floating point value to a 16-bit unsigned integer without
I have two signed 16-bit values in a 32-bit word, and I need to
Is there a way to apply some functions like:brightness,contrast,sharpness,hue,saturation,exposure to uiimages. For example I
When I want to convert between different integer types, it seems the best syntax
I'm really new to flash and am struggling to find a way to do
I have added one additional style to a Google Map, following Google's instructions .
i tried using the CGContextSetRGBStrokeColor before now i want to use other way to
I have a client who is seriously unhappy with the way their product thumbnails
Here is my query thus far: SELECT [Id], [HotelName], [StarRating], [Description], [CheckinDate], [CheckoutDate], [Price],

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.