saturation-arithmetic Questions

19

Solved

What is the best (cleanest, most efficient) way to write saturating addition in C? The function or macro should add two unsigned inputs (need both 16- and 32-bit versions) and return all-bits-one ...

4

The problem for signed 2's complement 32-bit integers: satMul2 - multiplies by 2, saturating to Tmin or Tmax if overflow. Examples: satMul2(0x30000000) = 0x60000000            satMul2(0x40000000) ...

2

Solved

Is there an elegant way to cast a bigger datatype to a smaller one without causing the result to overflow? E.g. casting 260 to uint8_t should result in 255 instead of 4. A possible solution would b...
Fitful asked 1/4, 2022 at 9:49

3

Can someone recommend a fast way to add saturate 32-bit signed integers using Intel intrinsics (AVX, SSE4 ...) ? I looked at the intrinsics guide and found _mm256_adds_epi16 but this seems to onl...
Ostiole asked 7/4, 2015 at 18:41

1

I've been looking at MMX/SSE and I am wondering. There are instructions for packed, saturated subtraction of unsigned bytes and words, but not doublewords. Is there a way of doing what I want, or ...
Antonioantonius asked 10/6, 2019 at 12:6

4

I'm looking for some C code for signed saturated 64-bit addition that compiles to efficient x86-64 code with the gcc optimizer. Portable code would be ideal, although an asm solution could be used ...
Eckman asked 10/7, 2013 at 20:16

2

I'm working on an assignment and I can't figure out how to implement this. I have to make a function sadd(int x, int y) that returns the numbers added together unless it overflows (then just return...
Clint asked 11/3, 2011 at 19:50

14

Solved

I am working on a simple video game program for school and I have created a method where the player gets 15 health points if that method is called. I have to keep the health at a max of 100 and wit...
Precancel asked 5/9, 2013 at 22:53

11

Solved

Imagine I have two unsigned bytes b and x. I need to calculate bsub as b - x and badd as b + x. However, I don't want underflow/overflow occur during these operations. For example (pseudo-code): b...

2

Solved

Alright, so the assignment I have to do is to multiply a signed integer by 2 and return the value. If the value overflows then saturate it by returning Tmin or Tmax instead. The challenge is using ...
Choanocyte asked 26/3, 2015 at 4:7
1

© 2022 - 2024 — McMap. All rights reserved.