- union lp_type type;
- struct lp_build_context bld;
- LLVMTypeRef vec_type;
- LLVMTypeRef int_vec_type;
- LLVMTypeRef arg_types[4];
- LLVMTypeRef func_type;
- LLVMValueRef mask_ptr;
- LLVMValueRef src_ptr;
- LLVMValueRef dst_ptr;
- LLVMValueRef const_ptr;
- LLVMBasicBlockRef block;
- LLVMBuilderRef builder;
- LLVMValueRef mask;
- LLVMValueRef src[4];
- LLVMValueRef con[4];
- LLVMValueRef dst[4];
- LLVMValueRef res[4];
- char src_name[5] = "src?";
- char con_name[5] = "con?";
- char dst_name[5] = "dst?";
- char res_name[5] = "res?";
- unsigned i;
-
- type.value = 0;
- type.floating = FALSE;
- type.sign = FALSE;
- type.norm = TRUE;
- type.width = 8;
- type.length = 16;
-
- vec_type = lp_build_vec_type(type);
- int_vec_type = lp_build_int_vec_type(type);
-
- arg_types[0] = LLVMPointerType(int_vec_type, 0); /* mask */
- arg_types[1] = LLVMPointerType(vec_type, 0); /* src */
- arg_types[2] = LLVMPointerType(vec_type, 0); /* con */
- arg_types[3] = LLVMPointerType(vec_type, 0); /* dst */
- func_type = LLVMFunctionType(LLVMVoidType(), arg_types, Elements(arg_types), 0);
- blend->function = LLVMAddFunction(screen->module, "blend", func_type);
- LLVMSetFunctionCallConv(blend->function, LLVMCCallConv);
-
- mask_ptr = LLVMGetParam(blend->function, 0);
- src_ptr = LLVMGetParam(blend->function, 1);
- const_ptr = LLVMGetParam(blend->function, 2);
- dst_ptr = LLVMGetParam(blend->function, 3);
-
- block = LLVMAppendBasicBlock(blend->function, "entry");
- builder = LLVMCreateBuilder();
- LLVMPositionBuilderAtEnd(builder, block);
-
- lp_build_context_init(&bld, builder, type);
-
- mask = LLVMBuildLoad(builder, mask_ptr, "mask");
-
- for(i = 0; i < 4; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
- con_name[3] = dst_name[3] = src_name[3] = "rgba"[i];
- src[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, src_ptr, &index, 1, ""), src_name);
- con[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, const_ptr, &index, 1, ""), con_name);
- dst[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, dst_ptr, &index, 1, ""), dst_name);
- }
-
- lp_build_blend_soa(builder, &blend->base, type, src, dst, con, res);