Post Reply 
(42, all flavours) Integer Division - how?
12-13-2020, 06:41 PM
Post: #16
RE: (42, all flavours) Integer Division - how?
(12-13-2020 04:21 PM)Albert Chan Wrote:  Assuming q is correctly rounded (mode round-to-nearest), r = 0 or -1

This allowed optimization of my FMA (Fused-Multiply-Add) code.
Without using MOD, this is the fastest of all.

Bonus: it removed the integer arguments requirement.
PHP Code:
function idiv4(a,b)     -- asuumed b 0
    local q 
floor(a/b)
    
local b1 * (0x1p27+1)
    
local q1 * (0x1p27+1)
    
b1 b1 b1    -- hi bits
    q1 
q1 q1
    local b0 
b1   -- lo bits
    local q0 
q1
    
if q1*b1 q1*b0 q0*b1 >= q0*b0 then return q end
    
return 1
end 

It would be nice if Free42 exposed FMA(a,b,c) to the user ...
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (42, all flavours) Integer Division - how? - Albert Chan - 12-13-2020 06:41 PM



User(s) browsing this thread: 1 Guest(s)