Bug 27914

Summary: GLSL compiler uses MUL+ADD where it could use MAD
Product: Mesa Reporter: Filippo Argiolas <filippo.argiolas>
Component: Drivers/DRI/i915Assignee: Eric Anholt <eric>
Status: RESOLVED FIXED QA Contact:
Severity: minor    
Priority: medium    
Version: git   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Bug Depends on:    
Bug Blocks: 29044    

Description Filippo Argiolas 2010-04-30 07:52:05 UTC
Hi, while porting gst-plugins-gl shaders to work with i915 I've passed some time looking at the programs produced by the compiler (with MESA_GLSL=log) and noticed that statements like

a += b * c;

become

MUL C, B, C;
ADD A, A, C;

while 

a = b * c + a;

becomes

MAD A, B, C, A;

I don't know how this works in hardware but I guess the latter has a dedicated path and is more efficient or, at least, saves up an instruction (and that's particularly important where the maximum number of instructions is little as in i915).
For what is worth, assembly produced by nVidia's Cg uses MAD in both cases.
Not sure if this is valid elsewhere too in mesa, tested it with i915 only.
Comment 1 Eric Anholt 2010-04-30 15:16:39 UTC
Yeah, this is the sort of thing that the codegen in the new compiler will handle very easily but which is a pain to do in Mesa today.
Comment 2 Eric Anholt 2010-07-12 23:45:15 UTC
On the glsl2 branch:

commit 3f08989267d9cdd944787fcf7a300c6f1f84462c
Author: Eric Anholt <eric@anholt.net>
Date:   Mon Jul 12 19:28:07 2010 -0700

    ir_to_mesa: Emit OPCODE_MAD when we find an ADD of a MUL.
    
    Bug #27914.
Comment 3 Eric Anholt 2010-08-16 23:44:54 UTC
GLSL2 branch is now merged.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.