<div dir="ltr"><div dir="ltr"><div>I personally don't see a point in reimplementing existing LLVM functions. There is also LLVMConstNull for zeros and LLVMConstAllOnes for integer ones, though I think those are mainly good for vectors and people are most used to seeing LLVMConstInt and LLVMConstReal for scalars.<br></div><div><br></div><div>Marek<br></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 19, 2018 at 5:03 PM Rhys Perry <<a href="mailto:pendingchaos02@gmail.com">pendingchaos02@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I would expect these helpers to be much more efficient than the<br>
functions you suggested. They are also (in my opinion) more readable<br>
than the suggested functions.<br>
<br>
I don't think it matters much though, so I'm fine either way.<br>
<br>
On Tue, 18 Dec 2018 at 02:48, Marek Olšák <<a href="mailto:maraeo@gmail.com" target="_blank">maraeo@gmail.com</a>> wrote:<br>
><br>
> On Fri, Dec 7, 2018 at 12:22 PM Rhys Perry <<a href="mailto:pendingchaos02@gmail.com" target="_blank">pendingchaos02@gmail.com</a>> wrote:<br>
>><br>
>> Signed-off-by: Rhys Perry <<a href="mailto:pendingchaos02@gmail.com" target="_blank">pendingchaos02@gmail.com</a>><br>
>> ---<br>
>> src/amd/common/ac_llvm_build.c | 123 ++++++++++++++++++++++++++++++--<br>
>> src/amd/common/ac_llvm_build.h | 22 +++++-<br>
>> src/amd/common/ac_nir_to_llvm.c | 30 ++++----<br>
>> 3 files changed, 154 insertions(+), 21 deletions(-)<br>
>><br>
>> diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c<br>
>> index 154cc696a2..cc7c6da5a4 100644<br>
>> --- a/src/amd/common/ac_llvm_build.c<br>
>> +++ b/src/amd/common/ac_llvm_build.c<br>
>> @@ -87,12 +87,16 @@ ac_llvm_context_init(struct ac_llvm_context *ctx,<br>
>> ctx->v4f32 = LLVMVectorType(ctx->f32, 4);<br>
>> ctx->v8i32 = LLVMVectorType(ctx->i32, 8);<br>
>><br>
>> + ctx->i8_0 = LLVMConstInt(ctx->i8, 0, false);<br>
>> + ctx->i8_1 = LLVMConstInt(ctx->i8, 1, false);<br>
>> ctx->i16_0 = LLVMConstInt(ctx->i16, 0, false);<br>
>> ctx->i16_1 = LLVMConstInt(ctx->i16, 1, false);<br>
>> ctx->i32_0 = LLVMConstInt(ctx->i32, 0, false);<br>
>> ctx->i32_1 = LLVMConstInt(ctx->i32, 1, false);<br>
>> ctx->i64_0 = LLVMConstInt(ctx->i64, 0, false);<br>
>> ctx->i64_1 = LLVMConstInt(ctx->i64, 1, false);<br>
>> + ctx->f16_0 = LLVMConstReal(ctx->f16, 0.0);<br>
>> + ctx->f16_1 = LLVMConstReal(ctx->f16, 1.0);<br>
>> ctx->f32_0 = LLVMConstReal(ctx->f32, 0.0);<br>
>> ctx->f32_1 = LLVMConstReal(ctx->f32, 1.0);<br>
>> ctx->f64_0 = LLVMConstReal(ctx->f64, 0.0);<br>
>> @@ -201,7 +205,9 @@ ac_get_type_size(LLVMTypeRef type)<br>
>><br>
>> static LLVMTypeRef to_integer_type_scalar(struct ac_llvm_context *ctx, LLVMTypeRef t)<br>
>> {<br>
>> - if (t == ctx->f16 || t == ctx->i16)<br>
>> + if (t == ctx->i8)<br>
>> + return ctx->i8;<br>
>> + else if (t == ctx->f16 || t == ctx->i16)<br>
>> return ctx->i16;<br>
>> else if (t == ctx->f32 || t == ctx->i32)<br>
>> return ctx->i32;<br>
>> @@ -268,6 +274,110 @@ ac_to_float(struct ac_llvm_context *ctx, LLVMValueRef v)<br>
>> return LLVMBuildBitCast(ctx->builder, v, ac_to_float_type(ctx, type), "");<br>
>> }<br>
>><br>
>> +LLVMValueRef ac_get_zerof(struct ac_llvm_context *ctx, LLVMTypeRef t)<br>
>> +{<br>
>> + if (t == ctx->f16)<br>
>> + return ctx->f16_0;<br>
>> + else if (t == ctx->f32)<br>
>> + return ctx->f32_0;<br>
>> + else if (t == ctx->f64)<br>
>> + return ctx->f64_0;<br>
>> + else<br>
>> + unreachable("Unhandled float size");<br>
>> +}<br>
>> +<br>
>> +LLVMValueRef ac_get_onef(struct ac_llvm_context *ctx, LLVMTypeRef t)<br>
>> +{<br>
>> + if (t == ctx->f16)<br>
>> + return ctx->f16_1;<br>
>> + else if (t == ctx->f32)<br>
>> + return ctx->f32_1;<br>
>> + else if (t == ctx->f64)<br>
>> + return ctx->f64_1;<br>
>> + else<br>
>> + unreachable("Unhandled float size");<br>
>> +}<br>
>> +<br>
>> +LLVMValueRef ac_get_zero(struct ac_llvm_context *ctx, LLVMTypeRef t)<br>
>> +{<br>
>> + if (t == ctx->i8)<br>
>> + return ctx->i8_0;<br>
>> + else if (t == ctx->i16)<br>
>> + return ctx->i16_0;<br>
>> + else if (t == ctx->i32)<br>
>> + return ctx->i32_0;<br>
>> + else if (t == ctx->i64)<br>
>> + return ctx->i64_0;<br>
>> + else<br>
>> + unreachable("Unhandled bit size");<br>
>> +}<br>
>> +<br>
>> +LLVMValueRef ac_get_one(struct ac_llvm_context *ctx, LLVMTypeRef t)<br>
>> +{<br>
>> + if (t == ctx->i8)<br>
>> + return ctx->i8_1;<br>
>> + else if (t == ctx->i16)<br>
>> + return ctx->i16_1;<br>
>> + else if (t == ctx->i32)<br>
>> + return ctx->i32_1;<br>
>> + else if (t == ctx->i64)<br>
>> + return ctx->i64_1;<br>
>> + else<br>
>> + unreachable("Unhandled bit size");<br>
>> +}<br>
><br>
><br>
> You don't need these helpers. You can just use LLVMConstInt and LLVMConstReal.<br>
><br>
>><br>
>> +<br>
>> +LLVMTypeRef ac_float_of_size(struct ac_llvm_context *ctx, unsigned bit_size)<br>
>> +{<br>
>> + switch (bit_size) {<br>
>> + case 16:<br>
>> + return ctx->f16;<br>
>> + case 32:<br>
>> + return ctx->f32;<br>
>> + case 64:<br>
>> + return ctx->f64;<br>
>> + default:<br>
>> + unreachable("Unhandled bit size");<br>
>> + }<br>
>> +}<br>
>> +<br>
>> +LLVMTypeRef ac_int_of_size(struct ac_llvm_context *ctx, unsigned bit_size)<br>
>> +{<br>
>> + switch (bit_size) {<br>
>> + case 8:<br>
>> + return ctx->i8;<br>
>> + case 16:<br>
>> + return ctx->i16;<br>
>> + case 32:<br>
>> + return ctx->i32;<br>
>> + case 64:<br>
>> + return ctx->i64;<br>
>> + default:<br>
>> + unreachable("Unhandled bit size");<br>
>> + }<br>
>> +}<br>
><br>
><br>
> This is the same as LLVMIntTypeInContext.<br>
><br>
> Marek<br>
><br>
</blockquote></div></div></div>