[llvm-dev] Floor-integer-div and integer sign operations?

edA-qa mort-ora-y via llvm-dev llvm-dev at lists.llvm.org
Fri Mar 30 02:58:14 PDT 2018


I'm looking for ways to do some basic operations without using branches.

The key operation I want is a floored/round-to-negative-infinity integer
division (as opposed to the default round-to-zero).

    7 floordiv 5 = 1
    -3 floordiv 5 = -1
    -6 floordiv 5 = -2

As I guess that doesn't exist, the operation can be constructed as:

   (a/b) + (a>>31)

Assuming a is 32 bits. I can probably check the bit count, but perhaps
there's an op that does this already.


I'm also looking for a `sign(a) => (-1,0,1)` operation. Is there some
easy way to do this without branches? That is, have I overlooked from IR
function?

-- 
edA-qa mort-ora-y  
	http://mortoray.com/

Creator of the Leaf language
	http://leaflang.org/

Streaming algorithms, AI, and design on Twitch
	https://www.twitch.tv/mortoray

Twitter
	edaqa
	



More information about the llvm-dev mailing list