[Mesa-dev] [PATCH 01/38] ac: add various helpers for float16/int16/int8

Rhys Perry pendingchaos02 at gmail.com
Wed Dec 19 22:02:56 UTC 2018


I would expect these helpers to be much more efficient than the
functions you suggested. They are also (in my opinion) more readable
than the suggested functions.

I don't think it matters much though, so I'm fine either way.

On Tue, 18 Dec 2018 at 02:48, Marek Olšák <maraeo at gmail.com> wrote:
>
> On Fri, Dec 7, 2018 at 12:22 PM Rhys Perry <pendingchaos02 at gmail.com> wrote:
>>
>> Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
>> ---
>>  src/amd/common/ac_llvm_build.c  | 123 ++++++++++++++++++++++++++++++--
>>  src/amd/common/ac_llvm_build.h  |  22 +++++-
>>  src/amd/common/ac_nir_to_llvm.c |  30 ++++----
>>  3 files changed, 154 insertions(+), 21 deletions(-)
>>
>> diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
>> index 154cc696a2..cc7c6da5a4 100644
>> --- a/src/amd/common/ac_llvm_build.c
>> +++ b/src/amd/common/ac_llvm_build.c
>> @@ -87,12 +87,16 @@ ac_llvm_context_init(struct ac_llvm_context *ctx,
>>         ctx->v4f32 = LLVMVectorType(ctx->f32, 4);
>>         ctx->v8i32 = LLVMVectorType(ctx->i32, 8);
>>
>> +       ctx->i8_0 = LLVMConstInt(ctx->i8, 0, false);
>> +       ctx->i8_1 = LLVMConstInt(ctx->i8, 1, false);
>>         ctx->i16_0 = LLVMConstInt(ctx->i16, 0, false);
>>         ctx->i16_1 = LLVMConstInt(ctx->i16, 1, false);
>>         ctx->i32_0 = LLVMConstInt(ctx->i32, 0, false);
>>         ctx->i32_1 = LLVMConstInt(ctx->i32, 1, false);
>>         ctx->i64_0 = LLVMConstInt(ctx->i64, 0, false);
>>         ctx->i64_1 = LLVMConstInt(ctx->i64, 1, false);
>> +       ctx->f16_0 = LLVMConstReal(ctx->f16, 0.0);
>> +       ctx->f16_1 = LLVMConstReal(ctx->f16, 1.0);
>>         ctx->f32_0 = LLVMConstReal(ctx->f32, 0.0);
>>         ctx->f32_1 = LLVMConstReal(ctx->f32, 1.0);
>>         ctx->f64_0 = LLVMConstReal(ctx->f64, 0.0);
>> @@ -201,7 +205,9 @@ ac_get_type_size(LLVMTypeRef type)
>>
>>  static LLVMTypeRef to_integer_type_scalar(struct ac_llvm_context *ctx, LLVMTypeRef t)
>>  {
>> -       if (t == ctx->f16 || t == ctx->i16)
>> +       if (t == ctx->i8)
>> +               return ctx->i8;
>> +       else if (t == ctx->f16 || t == ctx->i16)
>>                 return ctx->i16;
>>         else if (t == ctx->f32 || t == ctx->i32)
>>                 return ctx->i32;
>> @@ -268,6 +274,110 @@ ac_to_float(struct ac_llvm_context *ctx, LLVMValueRef v)
>>         return LLVMBuildBitCast(ctx->builder, v, ac_to_float_type(ctx, type), "");
>>  }
>>
>> +LLVMValueRef ac_get_zerof(struct ac_llvm_context *ctx, LLVMTypeRef t)
>> +{
>> +       if (t == ctx->f16)
>> +               return ctx->f16_0;
>> +       else if (t == ctx->f32)
>> +               return ctx->f32_0;
>> +       else if (t == ctx->f64)
>> +               return ctx->f64_0;
>> +       else
>> +               unreachable("Unhandled float size");
>> +}
>> +
>> +LLVMValueRef ac_get_onef(struct ac_llvm_context *ctx, LLVMTypeRef t)
>> +{
>> +       if (t == ctx->f16)
>> +               return ctx->f16_1;
>> +       else if (t == ctx->f32)
>> +               return ctx->f32_1;
>> +       else if (t == ctx->f64)
>> +               return ctx->f64_1;
>> +       else
>> +               unreachable("Unhandled float size");
>> +}
>> +
>> +LLVMValueRef ac_get_zero(struct ac_llvm_context *ctx, LLVMTypeRef t)
>> +{
>> +       if (t == ctx->i8)
>> +               return ctx->i8_0;
>> +       else if (t == ctx->i16)
>> +               return ctx->i16_0;
>> +       else if (t == ctx->i32)
>> +               return ctx->i32_0;
>> +       else if (t == ctx->i64)
>> +               return ctx->i64_0;
>> +       else
>> +               unreachable("Unhandled bit size");
>> +}
>> +
>> +LLVMValueRef ac_get_one(struct ac_llvm_context *ctx, LLVMTypeRef t)
>> +{
>> +       if (t == ctx->i8)
>> +               return ctx->i8_1;
>> +       else if (t == ctx->i16)
>> +               return ctx->i16_1;
>> +       else if (t == ctx->i32)
>> +               return ctx->i32_1;
>> +       else if (t == ctx->i64)
>> +               return ctx->i64_1;
>> +       else
>> +               unreachable("Unhandled bit size");
>> +}
>
>
> You don't need these helpers. You can just use LLVMConstInt and LLVMConstReal.
>
>>
>> +
>> +LLVMTypeRef ac_float_of_size(struct ac_llvm_context *ctx, unsigned bit_size)
>> +{
>> +       switch (bit_size) {
>> +       case 16:
>> +               return ctx->f16;
>> +       case 32:
>> +               return ctx->f32;
>> +       case 64:
>> +               return ctx->f64;
>> +       default:
>> +               unreachable("Unhandled bit size");
>> +       }
>> +}
>> +
>> +LLVMTypeRef ac_int_of_size(struct ac_llvm_context *ctx, unsigned bit_size)
>> +{
>> +       switch (bit_size) {
>> +       case 8:
>> +               return ctx->i8;
>> +       case 16:
>> +               return ctx->i16;
>> +       case 32:
>> +               return ctx->i32;
>> +       case 64:
>> +               return ctx->i64;
>> +       default:
>> +               unreachable("Unhandled bit size");
>> +       }
>> +}
>
>
> This is the same as LLVMIntTypeInContext.
>
> Marek
>


More information about the mesa-dev mailing list