flat assembler
Message board for the users of flat assembler.

Index > Main > Finding the maximum's ID between 3 variables

Author
Thread Post new topic Reply to topic
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
Let's say we have 3 variables: a, b and c

And I'd like an efficient (possibly very tricky) solution to compute "which" of them is the maximum in magnitude (i.e largest in absolute value). By "which" I mean an ID representing them:

Code:
if a is maximum
  return 0
else if b is maximum
  return 1
else
  return 2
end if    
Of course, as I said, I need the absolute values. i.e -5 is as large as 5, and therefore both are larger than, let's say, 4. In case two of them are equal, then it really doesn't matter for me which one is returned, so feel free to adjust the trick how you want in this aspect.

I've been thinking of doing it with set instructions (you know, after a cmp), but that's just plain too slow. I'm still working on a very tricky way of doing it with "magic" boolean logic operators, but meanwhile I hope you guys help me out.

A floating point implementation is also welcome, but I'm mainly interested in a plain integer one (without SSE/MMX).

of course as a bonus you could also add SSE/MMX or FPU... Wink
Post 08 Jan 2008, 14:23
View user's profile Send private message 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.