flat assembler
Message board for the users of flat assembler.

Index > Main > limiting a variable to a certain range

Author
Thread Post new topic Reply to topic
adnimo



Joined: 18 Jul 2008
Posts: 49
adnimo
hi, im new to the forums and fasm Smile
im in the need of limiting a variable's contents to a certain range.

i thought about using a macro for this but a function would do just fine, its the method that im after rather than the package.

what I don't know is how to write an efficient bound routine. having the variable contents and checking for min and max, limiting to this range. what would be the most efficient way of doing this? is there a specific instruction that isn't in sse or similar extended sets?

its clear that i want to do this with pixel data to bound it into 8bits while working on 32bits but i'm using just normal x86 instructions...

it would be cool to learn about the most efficient method in, say, sse too.

are there any examples or instructions I could learn from?

thanks.
Post 18 Jul 2008, 02:40
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3045
Location: vpcmipstrm
bitRAKE
PCMP* instructions can be used to test multiple values. There are many ways to use the mask produced. If possible it's better to use the mask directly than to branch execution. Usually, clamping can be integrated into the algorithm with saturation instructions, but PMIN*/PMAX* work too.

There are examples on the board - search for "SSE2".

_________________
¯\(°_o)/¯ unlicense.org
Post 18 Jul 2008, 03:04
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.