flat assembler
Message board for the users of flat assembler.

Index > Main > limiting a variable to a certain range

Thread Post new topic Reply to topic

Joined: 18 Jul 2008
Posts: 49
adnimo 18 Jul 2008, 02:40
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?

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

Joined: 21 Jul 2003
Posts: 3883
Location: vpcmipstrm
bitRAKE 18 Jul 2008, 03:04
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)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
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-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.