[Mesa-dev] [PATCH 2/2] i965: Optimize multiplication by -1 into a negated MOV.

Matt Turner mattst88 at gmail.com
Thu Feb 12 17:59:01 PST 2015


On Thu, Feb 12, 2015 at 5:45 PM, Tom Stellard <tom at stellard.net> wrote:
> On Thu, Feb 12, 2015 at 03:36:37PM -0800, Matt Turner wrote:
>> instructions in affected programs:     968 -> 942 (-2.69%)
>> helped:                                4
>> ---
>>  src/mesa/drivers/dri/i965/brw_fs.cpp   | 9 +++++++++
>>  src/mesa/drivers/dri/i965/brw_vec4.cpp | 5 +++++
>>  2 files changed, 14 insertions(+)
>>
>> diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
>> index e74a22e..988e36a 100644
>> --- a/src/mesa/drivers/dri/i965/brw_fs.cpp
>> +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
>> @@ -2335,6 +2335,15 @@ fs_visitor::opt_algebraic()
>>           break;
>>        }
>>
>> +      /* a * -1.0 = -a */
>> +      if (inst->src[1].is_negative_one()) {
>> +         inst->opcode = BRW_OPCODE_MOV;
>> +            inst->src[0].negate = !inst->src[0].negate;
>
> The indentation looks wrong here.

Indeed, thanks. I copied the block from immediately above and the old
code used tabs. I'll fix that.

>> +         inst->src[1] = reg_undef;
>> +         progress = true;
>> +         break;
>> +      }
>> +
>>           /* a * 0.0 = 0.0 */
>>           if (inst->src[1].is_zero()) {
>>              inst->opcode = BRW_OPCODE_MOV;
>> diff --git a/src/mesa/drivers/dri/i965/brw_vec4.cpp b/src/mesa/drivers/dri/i965/brw_vec4.cpp
>> index ee74052..7868465 100644
>> --- a/src/mesa/drivers/dri/i965/brw_vec4.cpp
>> +++ b/src/mesa/drivers/dri/i965/brw_vec4.cpp
>> @@ -725,6 +725,11 @@ vec4_visitor::opt_algebraic()
>>           inst->opcode = BRW_OPCODE_MOV;
>>           inst->src[1] = src_reg();
>>           progress = true;
>> +      } else if (inst->src[1].is_negative_one()) {
>> +         inst->opcode = BRW_OPCODE_MOV;
>> +            inst->src[0].negate = !inst->src[0].negate;
>
> Here too.
>
> Also, is this transformation valid when a is INF or NAN?

Indeed. Safe for both of those.

Thanks for taking a look!


More information about the mesa-dev mailing list