1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
31 * Unit tests for blend LLVM IR generation
33 * @author Jose Fonseca <jfonseca@vmware.com>
35 * Blend computation code derived from code written by
36 * @author Brian Paul <brian@vmware.com>
40 #include "lp_bld_type.h"
41 #include "lp_bld_arit.h"
42 #include "lp_bld_blend.h"
53 typedef void (*blend_test_ptr_t
)(const void *src
, const void *dst
, const void *con
, void *res
);
57 write_tsv_header(FILE *fp
)
61 "cycles_per_channel\t"
72 "alpha_dst_factor\n");
79 write_tsv_row(FILE *fp
,
80 const struct pipe_blend_state
*blend
,
81 enum vector_mode mode
,
86 fprintf(fp
, "%s\t", success
? "pass" : "fail");
89 fprintf(fp
, "%.1f\t", cycles
/ type
.length
);
94 fprintf(fp
, "%.1f\t", cycles
/ (4 * type
.length
));
98 fprintf(fp
, "%s%u%sx%u\t",
99 type
.floating
? "f" : (type
.fixed
? "h" : (type
.sign
? "s" : "u")),
101 type
.norm
? "n" : "",
106 blend
->rgb_func
!= blend
->alpha_func
? "true" : "false",
107 blend
->rgb_src_factor
!= blend
->alpha_src_factor
? "true" : "false",
108 blend
->rgb_dst_factor
!= blend
->alpha_dst_factor
? "true" : "false");
111 "%s\t%s\t%s\t%s\t%s\t%s\n",
112 debug_dump_blend_func(blend
->rgb_func
, TRUE
),
113 debug_dump_blend_factor(blend
->rgb_src_factor
, TRUE
),
114 debug_dump_blend_factor(blend
->rgb_dst_factor
, TRUE
),
115 debug_dump_blend_func(blend
->alpha_func
, TRUE
),
116 debug_dump_blend_factor(blend
->alpha_src_factor
, TRUE
),
117 debug_dump_blend_factor(blend
->alpha_dst_factor
, TRUE
));
124 dump_blend_type(FILE *fp
,
125 const struct pipe_blend_state
*blend
,
126 enum vector_mode mode
,
129 fprintf(fp
, "%s", mode
? "soa" : "aos");
131 fprintf(fp
, " type=%s%u%sx%u",
132 type
.floating
? "f" : (type
.fixed
? "h" : (type
.sign
? "s" : "u")),
134 type
.norm
? "n" : "",
138 " %s=%s %s=%s %s=%s %s=%s %s=%s %s=%s",
139 "rgb_func", debug_dump_blend_func(blend
->rgb_func
, TRUE
),
140 "rgb_src_factor", debug_dump_blend_factor(blend
->rgb_src_factor
, TRUE
),
141 "rgb_dst_factor", debug_dump_blend_factor(blend
->rgb_dst_factor
, TRUE
),
142 "alpha_func", debug_dump_blend_func(blend
->alpha_func
, TRUE
),
143 "alpha_src_factor", debug_dump_blend_factor(blend
->alpha_src_factor
, TRUE
),
144 "alpha_dst_factor", debug_dump_blend_factor(blend
->alpha_dst_factor
, TRUE
));
146 fprintf(fp
, " ...\n");
152 add_blend_test(LLVMModuleRef module
,
153 const struct pipe_blend_state
*blend
,
154 enum vector_mode mode
,
157 LLVMTypeRef ret_type
;
158 LLVMTypeRef vec_type
;
161 LLVMValueRef src_ptr
;
162 LLVMValueRef dst_ptr
;
163 LLVMValueRef const_ptr
;
164 LLVMValueRef res_ptr
;
165 LLVMBasicBlockRef block
;
166 LLVMBuilderRef builder
;
168 ret_type
= LLVMInt64Type();
169 vec_type
= lp_build_vec_type(type
);
171 args
[3] = args
[2] = args
[1] = args
[0] = LLVMPointerType(vec_type
, 0);
172 func
= LLVMAddFunction(module
, "test", LLVMFunctionType(LLVMVoidType(), args
, 4, 0));
173 LLVMSetFunctionCallConv(func
, LLVMCCallConv
);
174 src_ptr
= LLVMGetParam(func
, 0);
175 dst_ptr
= LLVMGetParam(func
, 1);
176 const_ptr
= LLVMGetParam(func
, 2);
177 res_ptr
= LLVMGetParam(func
, 3);
179 block
= LLVMAppendBasicBlock(func
, "entry");
180 builder
= LLVMCreateBuilder();
181 LLVMPositionBuilderAtEnd(builder
, block
);
189 src
= LLVMBuildLoad(builder
, src_ptr
, "src");
190 dst
= LLVMBuildLoad(builder
, dst_ptr
, "dst");
191 con
= LLVMBuildLoad(builder
, const_ptr
, "const");
193 res
= lp_build_blend_aos(builder
, blend
, type
, src
, dst
, con
, 3);
195 LLVMSetValueName(res
, "res");
197 LLVMBuildStore(builder
, res
, res_ptr
);
205 char src_name
[5] = "src?";
206 char dst_name
[5] = "dst?";
207 char con_name
[5] = "con?";
208 char res_name
[5] = "res?";
211 for(i
= 0; i
< 4; ++i
) {
212 LLVMValueRef index
= LLVMConstInt(LLVMInt32Type(), i
, 0);
213 con_name
[3] = dst_name
[3] = src_name
[3] = "rgba"[i
];
214 src
[i
] = LLVMBuildLoad(builder
, LLVMBuildGEP(builder
, src_ptr
, &index
, 1, ""), src_name
);
215 dst
[i
] = LLVMBuildLoad(builder
, LLVMBuildGEP(builder
, dst_ptr
, &index
, 1, ""), dst_name
);
216 con
[i
] = LLVMBuildLoad(builder
, LLVMBuildGEP(builder
, const_ptr
, &index
, 1, ""), con_name
);
219 lp_build_blend_soa(builder
, blend
, type
, src
, dst
, con
, res
);
221 for(i
= 0; i
< 4; ++i
) {
222 LLVMValueRef index
= LLVMConstInt(LLVMInt32Type(), i
, 0);
223 res_name
[3] = "rgba"[i
];
224 LLVMSetValueName(res
[i
], res_name
);
225 LLVMBuildStore(builder
, res
[i
], LLVMBuildGEP(builder
, res_ptr
, &index
, 1, ""));
229 LLVMBuildRetVoid(builder
);;
231 LLVMDisposeBuilder(builder
);
236 /** Add and limit result to ceiling of 1.0 */
237 #define ADD_SAT(R, A, B) \
239 R = (A) + (B); if (R > 1.0f) R = 1.0f; \
242 /** Subtract and limit result to floor of 0.0 */
243 #define SUB_SAT(R, A, B) \
245 R = (A) - (B); if (R < 0.0f) R = 0.0f; \
250 compute_blend_ref_term(unsigned rgb_factor
,
251 unsigned alpha_factor
,
252 const double *factor
,
260 switch (rgb_factor
) {
261 case PIPE_BLENDFACTOR_ONE
:
262 term
[0] = factor
[0]; /* R */
263 term
[1] = factor
[1]; /* G */
264 term
[2] = factor
[2]; /* B */
266 case PIPE_BLENDFACTOR_SRC_COLOR
:
267 term
[0] = factor
[0] * src
[0]; /* R */
268 term
[1] = factor
[1] * src
[1]; /* G */
269 term
[2] = factor
[2] * src
[2]; /* B */
271 case PIPE_BLENDFACTOR_SRC_ALPHA
:
272 term
[0] = factor
[0] * src
[3]; /* R */
273 term
[1] = factor
[1] * src
[3]; /* G */
274 term
[2] = factor
[2] * src
[3]; /* B */
276 case PIPE_BLENDFACTOR_DST_COLOR
:
277 term
[0] = factor
[0] * dst
[0]; /* R */
278 term
[1] = factor
[1] * dst
[1]; /* G */
279 term
[2] = factor
[2] * dst
[2]; /* B */
281 case PIPE_BLENDFACTOR_DST_ALPHA
:
282 term
[0] = factor
[0] * dst
[3]; /* R */
283 term
[1] = factor
[1] * dst
[3]; /* G */
284 term
[2] = factor
[2] * dst
[3]; /* B */
286 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
:
287 temp
= MIN2(src
[3], 1.0f
- dst
[3]);
288 term
[0] = factor
[0] * temp
; /* R */
289 term
[1] = factor
[1] * temp
; /* G */
290 term
[2] = factor
[2] * temp
; /* B */
292 case PIPE_BLENDFACTOR_CONST_COLOR
:
293 term
[0] = factor
[0] * con
[0]; /* R */
294 term
[1] = factor
[1] * con
[1]; /* G */
295 term
[2] = factor
[2] * con
[2]; /* B */
297 case PIPE_BLENDFACTOR_CONST_ALPHA
:
298 term
[0] = factor
[0] * con
[3]; /* R */
299 term
[1] = factor
[1] * con
[3]; /* G */
300 term
[2] = factor
[2] * con
[3]; /* B */
302 case PIPE_BLENDFACTOR_SRC1_COLOR
:
303 assert(0); /* to do */
305 case PIPE_BLENDFACTOR_SRC1_ALPHA
:
306 assert(0); /* to do */
308 case PIPE_BLENDFACTOR_ZERO
:
309 term
[0] = 0.0f
; /* R */
310 term
[1] = 0.0f
; /* G */
311 term
[2] = 0.0f
; /* B */
313 case PIPE_BLENDFACTOR_INV_SRC_COLOR
:
314 term
[0] = factor
[0] * (1.0f
- src
[0]); /* R */
315 term
[1] = factor
[1] * (1.0f
- src
[1]); /* G */
316 term
[2] = factor
[2] * (1.0f
- src
[2]); /* B */
318 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
:
319 term
[0] = factor
[0] * (1.0f
- src
[3]); /* R */
320 term
[1] = factor
[1] * (1.0f
- src
[3]); /* G */
321 term
[2] = factor
[2] * (1.0f
- src
[3]); /* B */
323 case PIPE_BLENDFACTOR_INV_DST_ALPHA
:
324 term
[0] = factor
[0] * (1.0f
- dst
[3]); /* R */
325 term
[1] = factor
[1] * (1.0f
- dst
[3]); /* G */
326 term
[2] = factor
[2] * (1.0f
- dst
[3]); /* B */
328 case PIPE_BLENDFACTOR_INV_DST_COLOR
:
329 term
[0] = factor
[0] * (1.0f
- dst
[0]); /* R */
330 term
[1] = factor
[1] * (1.0f
- dst
[1]); /* G */
331 term
[2] = factor
[2] * (1.0f
- dst
[2]); /* B */
333 case PIPE_BLENDFACTOR_INV_CONST_COLOR
:
334 term
[0] = factor
[0] * (1.0f
- con
[0]); /* R */
335 term
[1] = factor
[1] * (1.0f
- con
[1]); /* G */
336 term
[2] = factor
[2] * (1.0f
- con
[2]); /* B */
338 case PIPE_BLENDFACTOR_INV_CONST_ALPHA
:
339 term
[0] = factor
[0] * (1.0f
- con
[3]); /* R */
340 term
[1] = factor
[1] * (1.0f
- con
[3]); /* G */
341 term
[2] = factor
[2] * (1.0f
- con
[3]); /* B */
343 case PIPE_BLENDFACTOR_INV_SRC1_COLOR
:
344 assert(0); /* to do */
346 case PIPE_BLENDFACTOR_INV_SRC1_ALPHA
:
347 assert(0); /* to do */
354 * Compute src/first term A
356 switch (alpha_factor
) {
357 case PIPE_BLENDFACTOR_ONE
:
358 term
[3] = factor
[3]; /* A */
360 case PIPE_BLENDFACTOR_SRC_COLOR
:
361 case PIPE_BLENDFACTOR_SRC_ALPHA
:
362 term
[3] = factor
[3] * src
[3]; /* A */
364 case PIPE_BLENDFACTOR_DST_COLOR
:
365 case PIPE_BLENDFACTOR_DST_ALPHA
:
366 term
[3] = factor
[3] * dst
[3]; /* A */
368 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
:
369 term
[3] = src
[3]; /* A */
371 case PIPE_BLENDFACTOR_CONST_COLOR
:
372 case PIPE_BLENDFACTOR_CONST_ALPHA
:
373 term
[3] = factor
[3] * con
[3]; /* A */
375 case PIPE_BLENDFACTOR_ZERO
:
376 term
[3] = 0.0f
; /* A */
378 case PIPE_BLENDFACTOR_INV_SRC_COLOR
:
379 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
:
380 term
[3] = factor
[3] * (1.0f
- src
[3]); /* A */
382 case PIPE_BLENDFACTOR_INV_DST_COLOR
:
383 case PIPE_BLENDFACTOR_INV_DST_ALPHA
:
384 term
[3] = factor
[3] * (1.0f
- dst
[3]); /* A */
386 case PIPE_BLENDFACTOR_INV_CONST_COLOR
:
387 case PIPE_BLENDFACTOR_INV_CONST_ALPHA
:
388 term
[3] = factor
[3] * (1.0f
- con
[3]);
397 compute_blend_ref(const struct pipe_blend_state
*blend
,
406 compute_blend_ref_term(blend
->rgb_src_factor
, blend
->alpha_src_factor
, src
, src
, dst
, con
, src_term
);
407 compute_blend_ref_term(blend
->rgb_dst_factor
, blend
->alpha_dst_factor
, dst
, src
, dst
, con
, dst_term
);
412 switch (blend
->rgb_func
) {
414 ADD_SAT(res
[0], src_term
[0], dst_term
[0]); /* R */
415 ADD_SAT(res
[1], src_term
[1], dst_term
[1]); /* G */
416 ADD_SAT(res
[2], src_term
[2], dst_term
[2]); /* B */
418 case PIPE_BLEND_SUBTRACT
:
419 SUB_SAT(res
[0], src_term
[0], dst_term
[0]); /* R */
420 SUB_SAT(res
[1], src_term
[1], dst_term
[1]); /* G */
421 SUB_SAT(res
[2], src_term
[2], dst_term
[2]); /* B */
423 case PIPE_BLEND_REVERSE_SUBTRACT
:
424 SUB_SAT(res
[0], dst_term
[0], src_term
[0]); /* R */
425 SUB_SAT(res
[1], dst_term
[1], src_term
[1]); /* G */
426 SUB_SAT(res
[2], dst_term
[2], src_term
[2]); /* B */
429 res
[0] = MIN2(src_term
[0], dst_term
[0]); /* R */
430 res
[1] = MIN2(src_term
[1], dst_term
[1]); /* G */
431 res
[2] = MIN2(src_term
[2], dst_term
[2]); /* B */
434 res
[0] = MAX2(src_term
[0], dst_term
[0]); /* R */
435 res
[1] = MAX2(src_term
[1], dst_term
[1]); /* G */
436 res
[2] = MAX2(src_term
[2], dst_term
[2]); /* B */
445 switch (blend
->alpha_func
) {
447 ADD_SAT(res
[3], src_term
[3], dst_term
[3]); /* A */
449 case PIPE_BLEND_SUBTRACT
:
450 SUB_SAT(res
[3], src_term
[3], dst_term
[3]); /* A */
452 case PIPE_BLEND_REVERSE_SUBTRACT
:
453 SUB_SAT(res
[3], dst_term
[3], src_term
[3]); /* A */
456 res
[3] = MIN2(src_term
[3], dst_term
[3]); /* A */
459 res
[3] = MAX2(src_term
[3], dst_term
[3]); /* A */
468 test_one(unsigned verbose
,
470 const struct pipe_blend_state
*blend
,
471 enum vector_mode mode
,
474 LLVMModuleRef module
= NULL
;
475 LLVMValueRef func
= NULL
;
476 LLVMExecutionEngineRef engine
= NULL
;
477 LLVMModuleProviderRef provider
= NULL
;
478 LLVMPassManagerRef pass
= NULL
;
480 blend_test_ptr_t blend_test_ptr
;
482 const unsigned n
= 32;
484 double cycles_avg
= 0.0;
488 dump_blend_type(stdout
, blend
, mode
, type
);
490 module
= LLVMModuleCreateWithName("test");
492 func
= add_blend_test(module
, blend
, mode
, type
);
494 if(LLVMVerifyModule(module
, LLVMPrintMessageAction
, &error
)) {
495 LLVMDumpModule(module
);
498 LLVMDisposeMessage(error
);
500 provider
= LLVMCreateModuleProviderForExistingModule(module
);
501 if (LLVMCreateJITCompiler(&engine
, provider
, 1, &error
)) {
503 dump_blend_type(stderr
, blend
, mode
, type
);
504 fprintf(stderr
, "%s\n", error
);
505 LLVMDisposeMessage(error
);
510 pass
= LLVMCreatePassManager();
511 LLVMAddTargetData(LLVMGetExecutionEngineTargetData(engine
), pass
);
512 /* These are the passes currently listed in llvm-c/Transforms/Scalar.h,
513 * but there are more on SVN. */
514 LLVMAddConstantPropagationPass(pass
);
515 LLVMAddInstructionCombiningPass(pass
);
516 LLVMAddPromoteMemoryToRegisterPass(pass
);
517 LLVMAddGVNPass(pass
);
518 LLVMAddCFGSimplificationPass(pass
);
519 LLVMRunPassManager(pass
, module
);
525 LLVMDumpModule(module
);
527 blend_test_ptr
= (blend_test_ptr_t
)LLVMGetPointerToGlobal(engine
, func
);
530 for(i
= 0; i
< n
&& success
; ++i
) {
532 uint8_t src
[LP_MAX_VECTOR_LENGTH
*LP_MAX_TYPE_WIDTH
/8];
533 uint8_t dst
[LP_MAX_VECTOR_LENGTH
*LP_MAX_TYPE_WIDTH
/8];
534 uint8_t con
[LP_MAX_VECTOR_LENGTH
*LP_MAX_TYPE_WIDTH
/8];
535 uint8_t res
[LP_MAX_VECTOR_LENGTH
*LP_MAX_TYPE_WIDTH
/8];
536 uint8_t ref
[LP_MAX_VECTOR_LENGTH
*LP_MAX_TYPE_WIDTH
/8];
537 int64_t start_counter
= 0;
538 int64_t end_counter
= 0;
540 random_vec(type
, src
);
541 random_vec(type
, dst
);
542 random_vec(type
, con
);
545 double fsrc
[LP_MAX_VECTOR_LENGTH
];
546 double fdst
[LP_MAX_VECTOR_LENGTH
];
547 double fcon
[LP_MAX_VECTOR_LENGTH
];
548 double fref
[LP_MAX_VECTOR_LENGTH
];
550 read_vec(type
, src
, fsrc
);
551 read_vec(type
, dst
, fdst
);
552 read_vec(type
, con
, fcon
);
554 for(j
= 0; j
< type
.length
; j
+= 4)
555 compute_blend_ref(blend
, fsrc
+ j
, fdst
+ j
, fcon
+ j
, fref
+ j
);
557 write_vec(type
, ref
, fref
);
560 start_counter
= rdtsc();
561 blend_test_ptr(src
, dst
, con
, res
);
562 end_counter
= rdtsc();
564 cycles
[i
] = end_counter
- start_counter
;
566 if(!compare_vec(type
, res
, ref
)) {
570 dump_blend_type(stderr
, blend
, mode
, type
);
571 fprintf(stderr
, "MISMATCH\n");
573 fprintf(stderr
, " Src: ");
574 dump_vec(stderr
, type
, src
);
575 fprintf(stderr
, "\n");
577 fprintf(stderr
, " Dst: ");
578 dump_vec(stderr
, type
, dst
);
579 fprintf(stderr
, "\n");
581 fprintf(stderr
, " Con: ");
582 dump_vec(stderr
, type
, con
);
583 fprintf(stderr
, "\n");
585 fprintf(stderr
, " Res: ");
586 dump_vec(stderr
, type
, res
);
587 fprintf(stderr
, "\n");
589 fprintf(stderr
, " Ref: ");
590 dump_vec(stderr
, type
, ref
);
591 fprintf(stderr
, "\n");
596 const unsigned stride
= type
.length
*type
.width
/8;
597 uint8_t src
[4*LP_MAX_VECTOR_LENGTH
*LP_MAX_TYPE_WIDTH
/8];
598 uint8_t dst
[4*LP_MAX_VECTOR_LENGTH
*LP_MAX_TYPE_WIDTH
/8];
599 uint8_t con
[4*LP_MAX_VECTOR_LENGTH
*LP_MAX_TYPE_WIDTH
/8];
600 uint8_t res
[4*LP_MAX_VECTOR_LENGTH
*LP_MAX_TYPE_WIDTH
/8];
601 uint8_t ref
[4*LP_MAX_VECTOR_LENGTH
*LP_MAX_TYPE_WIDTH
/8];
602 int64_t start_counter
= 0;
603 int64_t end_counter
= 0;
606 for(j
= 0; j
< 4; ++j
) {
607 random_vec(type
, src
+ j
*stride
);
608 random_vec(type
, dst
+ j
*stride
);
609 random_vec(type
, con
+ j
*stride
);
619 for(k
= 0; k
< type
.length
; ++k
) {
620 for(j
= 0; j
< 4; ++j
) {
621 fsrc
[j
] = read_elem(type
, src
+ j
*stride
, k
);
622 fdst
[j
] = read_elem(type
, dst
+ j
*stride
, k
);
623 fcon
[j
] = read_elem(type
, con
+ j
*stride
, k
);
626 compute_blend_ref(blend
, fsrc
, fdst
, fcon
, fref
);
628 for(j
= 0; j
< 4; ++j
)
629 write_elem(type
, ref
+ j
*stride
, k
, fref
[j
]);
633 start_counter
= rdtsc();
634 blend_test_ptr(src
, dst
, con
, res
);
635 end_counter
= rdtsc();
637 cycles
[i
] = end_counter
- start_counter
;
640 for (j
= 0; j
< 4; ++j
)
641 if(!compare_vec(type
, res
+ j
*stride
, ref
+ j
*stride
))
648 dump_blend_type(stderr
, blend
, mode
, type
);
649 fprintf(stderr
, "MISMATCH\n");
650 for(j
= 0; j
< 4; ++j
) {
651 char channel
= "RGBA"[j
];
652 fprintf(stderr
, " Src%c: ", channel
);
653 dump_vec(stderr
, type
, src
+ j
*stride
);
654 fprintf(stderr
, "\n");
656 fprintf(stderr
, " Dst%c: ", channel
);
657 dump_vec(stderr
, type
, dst
+ j
*stride
);
658 fprintf(stderr
, "\n");
660 fprintf(stderr
, " Con%c: ", channel
);
661 dump_vec(stderr
, type
, con
+ j
*stride
);
662 fprintf(stderr
, "\n");
664 fprintf(stderr
, " Res%c: ", channel
);
665 dump_vec(stderr
, type
, res
+ j
*stride
);
666 fprintf(stderr
, "\n");
668 fprintf(stderr
, " Ref%c: ", channel
);
669 dump_vec(stderr
, type
, ref
+ j
*stride
);
670 fprintf(stderr
, "\n");
677 * Unfortunately the output of cycle counter is not very reliable as it comes
678 * -- sometimes we get outliers (due IRQs perhaps?) which are
679 * better removed to avoid random or biased data.
682 double sum
= 0.0, sum2
= 0.0;
686 for(i
= 0; i
< n
; ++i
) {
688 sum2
+= cycles
[i
]*cycles
[i
];
692 std
= sqrtf((sum2
- n
*avg
*avg
)/n
);
696 for(i
= 0; i
< n
; ++i
) {
697 if(fabs(cycles
[i
] - avg
) <= 4.0*std
) {
708 write_tsv_row(fp
, blend
, mode
, type
, cycles_avg
, success
);
712 LLVMDumpModule(module
);
713 LLVMWriteBitcodeToFile(module
, "blend.bc");
714 fprintf(stderr
, "blend.bc written\n");
715 fprintf(stderr
, "Invoke as \"llc -o - blend.bc\"\n");
719 LLVMFreeMachineCodeForFunction(engine
, func
);
721 LLVMDisposeExecutionEngine(engine
);
723 LLVMDisposePassManager(pass
);
731 PIPE_BLENDFACTOR_ZERO
,
732 PIPE_BLENDFACTOR_ONE
,
733 PIPE_BLENDFACTOR_SRC_COLOR
,
734 PIPE_BLENDFACTOR_SRC_ALPHA
,
735 PIPE_BLENDFACTOR_DST_COLOR
,
736 PIPE_BLENDFACTOR_DST_ALPHA
,
737 PIPE_BLENDFACTOR_CONST_COLOR
,
738 PIPE_BLENDFACTOR_CONST_ALPHA
,
740 PIPE_BLENDFACTOR_SRC1_COLOR
,
741 PIPE_BLENDFACTOR_SRC1_ALPHA
,
743 PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
,
744 PIPE_BLENDFACTOR_INV_SRC_COLOR
,
745 PIPE_BLENDFACTOR_INV_SRC_ALPHA
,
746 PIPE_BLENDFACTOR_INV_DST_COLOR
,
747 PIPE_BLENDFACTOR_INV_DST_ALPHA
,
748 PIPE_BLENDFACTOR_INV_CONST_COLOR
,
749 PIPE_BLENDFACTOR_INV_CONST_ALPHA
,
751 PIPE_BLENDFACTOR_INV_SRC1_COLOR
,
752 PIPE_BLENDFACTOR_INV_SRC1_ALPHA
,
761 PIPE_BLEND_REVERSE_SUBTRACT
,
767 const union lp_type blend_types
[] = {
768 /* float, fixed, sign, norm, width, len */
769 {{ TRUE
, FALSE
, FALSE
, TRUE
, 32, 4 }}, /* f32 x 4 */
770 {{ FALSE
, FALSE
, FALSE
, TRUE
, 8, 16 }}, /* u8n x 16 */
774 const unsigned num_funcs
= sizeof(blend_funcs
)/sizeof(blend_funcs
[0]);
775 const unsigned num_factors
= sizeof(blend_factors
)/sizeof(blend_factors
[0]);
776 const unsigned num_types
= sizeof(blend_types
)/sizeof(blend_types
[0]);
780 test_all(unsigned verbose
, FILE *fp
)
782 const unsigned *rgb_func
;
783 const unsigned *rgb_src_factor
;
784 const unsigned *rgb_dst_factor
;
785 const unsigned *alpha_func
;
786 const unsigned *alpha_src_factor
;
787 const unsigned *alpha_dst_factor
;
788 struct pipe_blend_state blend
;
789 enum vector_mode mode
;
790 const union lp_type
*type
;
793 for(rgb_func
= blend_funcs
; rgb_func
< &blend_funcs
[num_funcs
]; ++rgb_func
) {
794 for(alpha_func
= blend_funcs
; alpha_func
< &blend_funcs
[num_funcs
]; ++alpha_func
) {
795 for(rgb_src_factor
= blend_factors
; rgb_src_factor
< &blend_factors
[num_factors
]; ++rgb_src_factor
) {
796 for(rgb_dst_factor
= blend_factors
; rgb_dst_factor
<= rgb_src_factor
; ++rgb_dst_factor
) {
797 for(alpha_src_factor
= blend_factors
; alpha_src_factor
< &blend_factors
[num_factors
]; ++alpha_src_factor
) {
798 for(alpha_dst_factor
= blend_factors
; alpha_dst_factor
<= alpha_src_factor
; ++alpha_dst_factor
) {
799 for(mode
= 0; mode
< 2; ++mode
) {
800 for(type
= blend_types
; type
< &blend_types
[num_types
]; ++type
) {
802 if(*rgb_dst_factor
== PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
||
803 *alpha_dst_factor
== PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
)
806 memset(&blend
, 0, sizeof blend
);
807 blend
.blend_enable
= 1;
808 blend
.rgb_func
= *rgb_func
;
809 blend
.rgb_src_factor
= *rgb_src_factor
;
810 blend
.rgb_dst_factor
= *rgb_dst_factor
;
811 blend
.alpha_func
= *alpha_func
;
812 blend
.alpha_src_factor
= *alpha_src_factor
;
813 blend
.alpha_dst_factor
= *alpha_dst_factor
;
815 if(!test_one(verbose
, fp
, &blend
, mode
, *type
))
832 test_some(unsigned verbose
, FILE *fp
, unsigned long n
)
834 const unsigned *rgb_func
;
835 const unsigned *rgb_src_factor
;
836 const unsigned *rgb_dst_factor
;
837 const unsigned *alpha_func
;
838 const unsigned *alpha_src_factor
;
839 const unsigned *alpha_dst_factor
;
840 struct pipe_blend_state blend
;
841 enum vector_mode mode
;
842 const union lp_type
*type
;
846 for(i
= 0; i
< n
; ++i
) {
847 rgb_func
= &blend_funcs
[random() % num_funcs
];
848 alpha_func
= &blend_funcs
[random() % num_funcs
];
849 rgb_src_factor
= &blend_factors
[random() % num_factors
];
850 alpha_src_factor
= &blend_factors
[random() % num_factors
];
853 rgb_dst_factor
= &blend_factors
[random() % num_factors
];
854 } while(*rgb_dst_factor
== PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
);
857 alpha_dst_factor
= &blend_factors
[random() % num_factors
];
858 } while(*alpha_dst_factor
== PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
);
862 type
= &blend_types
[random() % num_types
];
864 memset(&blend
, 0, sizeof blend
);
865 blend
.blend_enable
= 1;
866 blend
.rgb_func
= *rgb_func
;
867 blend
.rgb_src_factor
= *rgb_src_factor
;
868 blend
.rgb_dst_factor
= *rgb_dst_factor
;
869 blend
.alpha_func
= *alpha_func
;
870 blend
.alpha_src_factor
= *alpha_src_factor
;
871 blend
.alpha_dst_factor
= *alpha_dst_factor
;
873 if(!test_one(verbose
, fp
, &blend
, mode
, *type
))