[Mesa-dev] [PATCH 4/9] gallium-tgsi: add TGSI_OPCODE_{FMA-POPCNT-MSB-LSB} description

Roland Scheidegger sroland at vmware.com
Mon Jan 6 07:56:48 PST 2014


Am 05.01.2014 01:34, schrieb Maxence Le Doré:
> FMA(a,b,c) keeps extra precision (usually 1 more bit of mantissa,
> afaik) for the result a*b and add this to c, to finally produce a
> IEEE754 32bit float result.
> 
> MAD(a,b,c) product a IEEE754 32bit float product a*b and add it to C.
> 
> So, fma can be slightly more accurate. An accuracy that is something
> very appreciate.

Actually in "newer" languages (such as opencl) "mad" is used to indicate
intermediate rounding does not matter, so if your cpu can do fma but not
mul+add in a single cycle it is allowed to use fma instead.
FMA OTOH of course forces no intermediate rounding.
Our tgsi definitions certainly initially were meaning intermediate
rounding should take place, I don't know if we need to keep it that way
or could repurpose that slightly (so if you require the intermediate
rounding you'd just use mul+add).

Roland



> 
> 
> 2014/1/5 Marek Olšák <maraeo at gmail.com>:
>> How is FMA different from MAD?
>>
>> Please document the new opcodes in src/gallium/docs/source/tgsi.rst.
>>
>> Marek
>>
>> On Sun, Jan 5, 2014 at 12:42 AM, Maxence Le Doré
>> <maxence.ledore at gmail.com> wrote:
>>> From: Maxence Le Doré <Maxence Le Doré>
>>>
>>> ---
>>>  src/gallium/auxiliary/tgsi/tgsi_info.c       | 16 ++++++++++++++++
>>>  src/gallium/auxiliary/tgsi/tgsi_opcode_tmp.h |  6 ++++++
>>>  src/gallium/include/pipe/p_shader_tokens.h   |  9 ++++++++-
>>>  3 files changed, 30 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/src/gallium/auxiliary/tgsi/tgsi_info.c b/src/gallium/auxiliary/tgsi/tgsi_info.c
>>> index 0beef44..ed55940 100644
>>> --- a/src/gallium/auxiliary/tgsi/tgsi_info.c
>>> +++ b/src/gallium/auxiliary/tgsi/tgsi_info.c
>>> @@ -221,6 +221,12 @@ static const struct tgsi_opcode_info opcode_info[TGSI_OPCODE_LAST] =
>>>     { 1, 3, 1, 0, 0, 0, OTHR, "TXL2", TGSI_OPCODE_TXL2 },
>>>     { 1, 2, 0, 0, 0, 0, COMP, "IMUL_HI", TGSI_OPCODE_IMUL_HI },
>>>     { 1, 2, 0, 0, 0, 0, COMP, "UMUL_HI", TGSI_OPCODE_UMUL_HI },
>>> +   { 1, 3, 0, 0, 0, 0, COMP, "FMA", TGSI_OPCODE_FMA },
>>> +   { 1, 1, 0, 0, 0, 0, COMP, "POPCNT", TGSI_OPCODE_POPCNT },
>>> +   { 1, 1, 0, 0, 0, 0, COMP, "IMSB", TGSI_OPCODE_IMSB },
>>> +   { 1, 1, 0, 0, 0, 0, COMP, "ILSB", TGSI_OPCODE_ILSB },
>>> +   { 1, 1, 0, 0, 0, 0, COMP, "UMSB", TGSI_OPCODE_UMSB },
>>> +   { 1, 1, 0, 0, 0, 0, COMP, "ULSB", TGSI_OPCODE_ULSB },
>>>  };
>>>
>>>  const struct tgsi_opcode_info *
>>> @@ -321,6 +327,11 @@ tgsi_opcode_infer_type( uint opcode )
>>>     case TGSI_OPCODE_IABS:
>>>     case TGSI_OPCODE_ISSG:
>>>     case TGSI_OPCODE_IMUL_HI:
>>> +   case TGSI_OPCODE_POPCNT:
>>> +   case TGSI_OPCODE_ILSB:
>>> +   case TGSI_OPCODE_IMSB:
>>> +   case TGSI_OPCODE_ULSB:
>>> +   case TGSI_OPCODE_UMSB:
>>>        return TGSI_TYPE_SIGNED;
>>>     default:
>>>        return TGSI_TYPE_FLOAT;
>>> @@ -344,9 +355,14 @@ tgsi_opcode_infer_src_type( uint opcode )
>>>     case TGSI_OPCODE_SAMPLE_I:
>>>     case TGSI_OPCODE_SAMPLE_I_MS:
>>>     case TGSI_OPCODE_UMUL_HI:
>>> +   case TGSI_OPCODE_POPCNT:
>>> +   case TGSI_OPCODE_ULSB:
>>> +   case TGSI_OPCODE_UMSB:
>>>        return TGSI_TYPE_UNSIGNED;
>>>     case TGSI_OPCODE_IMUL_HI:
>>>     case TGSI_OPCODE_I2F:
>>> +   case TGSI_OPCODE_ILSB:
>>> +   case TGSI_OPCODE_IMSB:
>>>        return TGSI_TYPE_SIGNED;
>>>     case TGSI_OPCODE_ARL:
>>>     case TGSI_OPCODE_ARR:
>>> diff --git a/src/gallium/auxiliary/tgsi/tgsi_opcode_tmp.h b/src/gallium/auxiliary/tgsi/tgsi_opcode_tmp.h
>>> index 1ef78dd..cba0975 100644
>>> --- a/src/gallium/auxiliary/tgsi/tgsi_opcode_tmp.h
>>> +++ b/src/gallium/auxiliary/tgsi/tgsi_opcode_tmp.h
>>> @@ -206,6 +206,12 @@ OP13(UCMP)
>>>
>>>  OP12(IMUL_HI)
>>>  OP12(UMUL_HI)
>>> +OP13(FMA)
>>> +OP11(POPCNT)
>>> +OP11(IMSB)
>>> +OP11(ILSB)
>>> +OP11(UMSB)
>>> +OP11(ULSB)
>>>
>>>  #undef OP00
>>>  #undef OP01
>>> diff --git a/src/gallium/include/pipe/p_shader_tokens.h b/src/gallium/include/pipe/p_shader_tokens.h
>>> index 8010902..5ed0c34 100644
>>> --- a/src/gallium/include/pipe/p_shader_tokens.h
>>> +++ b/src/gallium/include/pipe/p_shader_tokens.h
>>> @@ -453,7 +453,14 @@ struct tgsi_property_data {
>>>  #define TGSI_OPCODE_IMUL_HI             180
>>>  #define TGSI_OPCODE_UMUL_HI             181
>>>
>>> -#define TGSI_OPCODE_LAST                182
>>> +#define TGSI_OPCODE_FMA                 182
>>> +#define TGSI_OPCODE_POPCNT              183
>>> +#define TGSI_OPCODE_IMSB                184
>>> +#define TGSI_OPCODE_ILSB                185
>>> +#define TGSI_OPCODE_UMSB                186
>>> +#define TGSI_OPCODE_ULSB                187
>>> +
>>> +#define TGSI_OPCODE_LAST                188
>>>
>>>  #define TGSI_SAT_NONE            0  /* do not saturate */
>>>  #define TGSI_SAT_ZERO_ONE        1  /* clamp to [0,1] */
>>> --
>>> 1.8.5.2
>>>
>>> _______________________________________________
>>> mesa-dev mailing list
>>> mesa-dev at lists.freedesktop.org
>>> https://urldefense.proofpoint.com/v1/url?u=http://lists.freedesktop.org/mailman/listinfo/mesa-dev&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=F4msKE2WxRzA%2BwN%2B25muztFm5TSPwE8HKJfWfR2NgfY%3D%0A&m=UbogYegyhJOd8MD5pXDHVLpkdfH0gvvci5OW50vTexw%3D%0A&s=4da499b672e3e50826f923f340c51cfaa5c79830951ccc3034abd52a1b7402a8
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://urldefense.proofpoint.com/v1/url?u=http://lists.freedesktop.org/mailman/listinfo/mesa-dev&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=F4msKE2WxRzA%2BwN%2B25muztFm5TSPwE8HKJfWfR2NgfY%3D%0A&m=UbogYegyhJOd8MD5pXDHVLpkdfH0gvvci5OW50vTexw%3D%0A&s=4da499b672e3e50826f923f340c51cfaa5c79830951ccc3034abd52a1b7402a8
> 


More information about the mesa-dev mailing list