Home | History | Annotate | Download | only in gallivm

Lines Matching refs:bld

90 lp_build_min_simple(struct lp_build_context *bld,
95 const struct lp_type type = bld->type;
223 min = lp_build_intrinsic_binary_anylength(bld->gallivm, intrinsic,
227 isnan = lp_build_isnan(bld, b);
228 return lp_build_select(bld, isnan, a, min);
231 isnan = lp_build_isnan(bld, a);
232 return lp_build_select(bld, isnan, a, min);
235 return lp_build_intrinsic_binary_anylength(bld->gallivm, intrinsic,
244 LLVMValueRef isnan = lp_build_isnan(bld, b);
245 cond = lp_build_cmp(bld, PIPE_FUNC_LESS, a, b);
246 cond = LLVMBuildXor(bld->gallivm->builder, cond, isnan, "");
247 return lp_build_select(bld, cond, a, b);
251 LLVMValueRef isnan = lp_build_isnan(bld, a);
252 cond = lp_build_cmp(bld, PIPE_FUNC_LESS, a, b);
253 cond = LLVMBuildXor(bld->gallivm->builder, cond, isnan, "");
254 return lp_build_select(bld, cond, a, b);
258 cond = lp_build_cmp_ordered(bld, PIPE_FUNC_LESS, a, b);
259 return lp_build_select(bld, cond, a, b);
261 cond = lp_build_cmp(bld, PIPE_FUNC_LESS, b, a);
262 return lp_build_select(bld, cond, b, a);
264 cond = lp_build_cmp(bld, PIPE_FUNC_LESS, a, b);
265 return lp_build_select(bld, cond, a, b);
269 cond = lp_build_cmp(bld, PIPE_FUNC_LESS, a, b);
270 return lp_build_select(bld, cond, a, b);
273 cond = lp_build_cmp(bld, PIPE_FUNC_LESS, a, b);
274 return lp_build_select(bld, cond, a, b);
308 lp_build_max_simple(struct lp_build_context *bld,
313 const struct lp_type type = bld->type;
436 max = lp_build_intrinsic_binary_anylength(bld->gallivm, intrinsic,
440 isnan = lp_build_isnan(bld, b);
441 return lp_build_select(bld, isnan, a, max);
444 isnan = lp_build_isnan(bld, a);
445 return lp_build_select(bld, isnan, a, max);
448 return lp_build_intrinsic_binary_anylength(bld->gallivm, intrinsic,
457 LLVMValueRef isnan = lp_build_isnan(bld, b);
458 cond = lp_build_cmp(bld, PIPE_FUNC_GREATER, a, b);
459 cond = LLVMBuildXor(bld->gallivm->builder, cond, isnan, "");
460 return lp_build_select(bld, cond, a, b);
464 LLVMValueRef isnan = lp_build_isnan(bld, a);
465 cond = lp_build_cmp(bld, PIPE_FUNC_GREATER, a, b);
466 cond = LLVMBuildXor(bld->gallivm->builder, cond, isnan, "");
467 return lp_build_select(bld, cond, a, b);
471 cond = lp_build_cmp_ordered(bld, PIPE_FUNC_GREATER, a, b);
472 return lp_build_select(bld, cond, a, b);
474 cond = lp_build_cmp(bld, PIPE_FUNC_GREATER, b, a);
475 return lp_build_select(bld, cond, b, a);
477 cond = lp_build_cmp(bld, PIPE_FUNC_GREATER, a, b);
478 return lp_build_select(bld, cond, a, b);
482 cond = lp_build_cmp(bld, PIPE_FUNC_GREATER, a, b);
483 return lp_build_select(bld, cond, a, b);
486 cond = lp_build_cmp(bld, PIPE_FUNC_GREATER, a, b);
487 return lp_build_select(bld, cond, a, b);
493 * Generate 1 - a, or ~a depending on bld->type.
496 lp_build_comp(struct lp_build_context *bld,
499 LLVMBuilderRef builder = bld->gallivm->builder;
500 const struct lp_type type = bld->type;
504 if(a == bld->one)
505 return bld->zero;
506 if(a == bld->zero)
507 return bld->one;
518 return LLVMConstFSub(bld->one, a);
520 return LLVMConstSub(bld->one, a);
523 return LLVMBuildFSub(builder, bld->one, a, "");
525 return LLVMBuildSub(builder, bld->one, a, "");
533 lp_build_add(struct lp_build_context *bld,
537 LLVMBuilderRef builder = bld->gallivm->builder;
538 const struct lp_type type = bld->type;
544 if(a == bld->zero)
546 if(b == bld->zero)
548 if(a == bld->undef || b == bld->undef)
549 return bld->undef;
551 if(bld->type.norm) {
554 if(a == bld->one || b == bld->one)
555 return bld->one;
582 return lp_build_intrinsic_binary(builder, intrinsic, lp_build_vec_type(bld->gallivm, bld->type), a, b);
588 LLVMValueRef max_val = lp_build_const_int_vec(bld->gallivm, type, sign - 1);
589 LLVMValueRef min_val = lp_build_const_int_vec(bld->gallivm, type, sign);
592 LLVMValueRef a_clamp_max = lp_build_min_simple(bld, a, LLVMBuildSub(builder, max_val, b, ""), GALLIVM_NAN_BEHAVIOR_UNDEFINED);
593 LLVMValueRef a_clamp_min = lp_build_max_simple(bld, a, LLVMBuildSub(builder, min_val, b, ""), GALLIVM_NAN_BEHAVIOR_UNDEFINED);
594 a = lp_build_select(bld, lp_build_cmp(bld, PIPE_FUNC_GREATER, b, bld->zero), a_clamp_max, a_clamp_min);
596 a = lp_build_min_simple(bld, a, lp_build_comp(bld, b), GALLIVM_NAN_BEHAVIOR_UNDEFINED);
612 if(bld->type.norm && (bld->type.floating || bld->type.fixed))
613 res = lp_build_min_simple(bld, res, bld->one, GALLIVM_NAN_BEHAVIOR_UNDEFINED);
625 lp_build_horizontal_add(struct lp_build_context *bld,
628 LLVMBuilderRef builder = bld->gallivm->builder;
629 const struct lp_type type = bld->type;
642 assert(!bld->type.norm);
658 shuffles1[i] = lp_build_const_int32(bld->gallivm, i);
659 shuffles2[i] = lp_build_const_int32(bld->gallivm, i + length);
677 index = lp_build_const_int32(bld->gallivm, 0);
679 index = lp_build_const_int32(bld->gallivm, 1);
695 lp_build_horizontal_add4x4f(struct lp_build_context *bld,
698 struct gallivm_state *gallivm = bld->gallivm;
759 lp_build_hadd_partial4(struct lp_build_context *bld,
763 struct gallivm_state *gallivm = bld->gallivm;
770 assert(bld->type.floating);
783 if (util_cpu_caps.has_sse3 && bld->type.width == 32 &&
784 bld->type.length == 4) {
787 else if (util_cpu_caps.has_avx && bld->type.width == 32 &&
788 bld->type.length == 8) {
793 lp_build_vec_type(gallivm, bld->type),
797 lp_build_vec_type(gallivm, bld->type),
804 lp_build_vec_type(gallivm, bld->type),
808 if (bld->type.length == 4) {
809 ret_vec = lp_build_horizontal_add4x4f(bld, tmp);
814 unsigned num_iter = bld->type.length / 4;
815 struct lp_type parttype = bld->type;
823 partres[j] = lp_build_horizontal_add4x4f(bld, partsrc);
834 lp_build_sub(struct lp_build_context *bld,
838 LLVMBuilderRef builder = bld->gallivm->builder;
839 const struct lp_type type = bld->type;
845 if(b == bld->zero)
847 if(a == bld->undef || b == bld->undef)
848 return bld->undef;
850 return bld->zero;
852 if(bld->type.norm) {
855 if(b == bld->one)
856 return bld->zero;
883 return lp_build_intrinsic_binary(builder, intrinsic, lp_build_vec_type(bld->gallivm, bld->type), a, b);
889 LLVMValueRef max_val = lp_build_const_int_vec(bld->gallivm, type, sign - 1);
890 LLVMValueRef min_val = lp_build_const_int_vec(bld->gallivm, type, sign);
893 LLVMValueRef a_clamp_max = lp_build_min_simple(bld, a, LLVMBuildAdd(builder, max_val, b, ""), GALLIVM_NAN_BEHAVIOR_UNDEFINED);
894 LLVMValueRef a_clamp_min = lp_build_max_simple(bld, a, LLVMBuildAdd(builder, min_val, b, ""), GALLIVM_NAN_BEHAVIOR_UNDEFINED);
895 a = lp_build_select(bld, lp_build_cmp(bld, PIPE_FUNC_GREATER, b, bld->zero), a_clamp_min, a_clamp_max);
897 a = lp_build_max_simple(bld, a, b, GALLIVM_NAN_BEHAVIOR_UNDEFINED);
912 if(bld->type.norm && (bld->type.floating || bld->type.fixed))
913 res = lp_build_max_simple(bld, res, bld->zero, GALLIVM_NAN_BEHAVIOR_UNDEFINED);
972 struct lp_build_context bld;
981 lp_build_context_init(&bld, gallivm, wide_type);
998 ab = LLVMBuildAdd(builder, ab, lp_build_shr_imm(&bld, ab, n), "");
1007 LLVMValueRef sign = lp_build_shr_imm(&bld, ab, wide_type.width - 1);
1008 half = lp_build_select(&bld, sign, minus_half, half);
1013 ab = lp_build_shr_imm(&bld, ab, n);
1022 lp_build_mul(struct lp_build_context *bld,
1026 LLVMBuilderRef builder = bld->gallivm->builder;
1027 const struct lp_type type = bld->type;
1034 if(a == bld->zero)
1035 return bld->zero;
1036 if(a == bld->one)
1038 if(b == bld->zero)
1039 return bld->zero;
1040 if(b == bld->one)
1042 if(a == bld->undef || b == bld->undef)
1043 return bld->undef;
1049 lp_build_unpack2_native(bld->gallivm, type, wide_type, a, &al, &ah);
1050 lp_build_unpack2_native(bld->gallivm, type, wide_type, b, &bl, &bh);
1053 abl = lp_build_mul_norm(bld->gallivm, wide_type, al, bl);
1054 abh = lp_build_mul_norm(bld->gallivm, wide_type, ah, bh);
1056 ab = lp_build_pack2_native(bld->gallivm, wide_type, type, abl, abh);
1062 shift = lp_build_const_int_vec(bld->gallivm, type, type.width/2);
1101 lp_build_mul_32_lohi_cpu(struct lp_build_context *bld,
1106 struct gallivm_state *gallivm = bld->gallivm;
1109 assert(bld->type.width == 32);
1110 assert(bld->type.floating == 0);
1111 assert(bld->type.fixed == 0);
1112 assert(bld->type.norm == 0);
1126 if ((bld->type.length == 4 || bld->type.length == 8) &&
1127 ((util_cpu_caps.has_sse2 && (bld->type.sign == 0)) ||
1132 struct lp_type type_wide = lp_wider_type(bld->type);
1135 for (i = 0; i < bld->type.length; i += 2) {
1139 shuf_vec = LLVMConstVector(shuf, bld->type.length);
1142 aodd = LLVMBuildShuffleVector(builder, aeven, bld->undef, shuf_vec, "");
1143 bodd = LLVMBuildShuffleVector(builder, beven, bld->undef, shuf_vec, "");
1145 if (util_cpu_caps.has_avx2 && bld->type.length == 8) {
1146 if (bld->type.sign) {
1158 if (bld->type.sign) {
1168 if (bld->type.length == 8) {
1203 muleven = LLVMBuildBitCast(builder, muleven, bld->vec_type, "");
1204 mulodd = LLVMBuildBitCast(builder, mulodd, bld->vec_type, "");
1206 for (i = 0; i < bld->type.length; i += 2) {
1208 shuf[i+1] = lp_build_const_int32(gallivm, i + 1 + bld->type.length);
1210 shuf_vec = LLVMConstVector(shuf, bld->type.length);
1213 for (i = 0; i < bld->type.length; i += 2) {
1215 shuf[i+1] = lp_build_const_int32(gallivm, i + bld->type.length);
1217 shuf_vec = LLVMConstVector(shuf, bld->type.length);
1221 return lp_build_mul_32_lohi(bld, a, b, res_hi);
1233 lp_build_mul_32_lohi(struct lp_build_context *bld,
1238 struct gallivm_state *gallivm = bld->gallivm;
1244 type_tmp = bld->type;
1250 if (bld->type.sign) {
1271 lp_build_mad(struct lp_build_context *bld,
1276 const struct lp_type type = bld->type;
1278 return lp_build_fmuladd(bld->gallivm->builder, a, b, c);
1280 return lp_build_add(bld, lp_build_mul(bld, a, b), c);
1289 lp_build_mul_imm(struct lp_build_context *bld,
1293 LLVMBuilderRef builder = bld->gallivm->builder;
1296 assert(lp_check_value(bld->type, a));
1299 return bld->zero;
1305 return lp_build_negate(bld, a);
1307 if(b == 2 && bld->type.floating)
1308 return lp_build_add(bld, a, a);
1313 if(bld->type.floating) {
1322 unsigned mantissa = lp_mantissa(bld->type);
1323 factor = lp_build_const_int_vec(bld->gallivm, bld->type, (unsigned long long)shift << mantissa);
1324 a = LLVMBuildBitCast(builder, a, lp_build_int_vec_type(bld->type), "");
1326 a = LLVMBuildBitCast(builder, a, lp_build_vec_type(bld->gallivm, bld->type), "");
1331 factor = lp_build_const_vec(bld->gallivm, bld->type, shift);
1336 factor = lp_build_const_vec(bld->gallivm, bld->type, (double)b);
1337 return lp_build_mul(bld, a, factor);
1345 lp_build_div(struct lp_build_context *bld,
1349 LLVMBuilderRef builder = bld->gallivm->builder;
1350 const struct lp_type type = bld->type;
1355 if(a == bld->zero)
1356 return bld->zero;
1357 if(a == bld->one && type.floating)
1358 return lp_build_rcp(bld, b);
1359 if(b == bld->zero)
1360 return bld->undef;
1361 if(b == bld->one)
1363 if(a == bld->undef || b == bld->undef)
1364 return bld->undef;
1378 return lp_build_mul(bld, a, lp_build_rcp(bld, b));
1398 lp_build_lerp_simple(struct lp_build_context *bld,
1404 unsigned half_width = bld->type.width/2;
1405 LLVMBuilderRef builder = bld->gallivm->builder;
1409 assert(lp_check_value(bld->type, x));
1410 assert(lp_check_value(bld->type, v0));
1411 assert(lp_check_value(bld->type, v1));
1413 delta = lp_build_sub(bld, v1, v0);
1415 if (bld->type.floating) {
1417 return lp_build_mad(bld, x, delta, v0);
1421 if (!bld->type.sign) {
1429 x = lp_build_add(bld, x, lp_build_shr_imm(bld, x, half_width - 1));
1433 res = lp_build_mul(bld, x, delta);
1434 res = lp_build_shr_imm(bld, res, half_width);
1442 res = lp_build_mul_norm(bld->gallivm, bld->type, x, delta);
1446 res = lp_build_mul(bld, x, delta);
1449 bld->type.sign) {
1458 narrow_type.sign = bld->type.sign;
1459 narrow_type.width = bld->type.width/2;
1460 narrow_type.length = bld->type.length*2;
1462 lp_build_context_init(&narrow_bld, bld->gallivm, narrow_type);
1466 res = LLVMBuildBitCast(builder, res, bld->vec_type, "");
1468 res = lp_build_add(bld, v0, res);
1470 if (bld->type.fixed) {
1481 low_bits = lp_build_const_int_vec(bld->gallivm, bld->type, (1 << half_width) - 1);
1494 lp_build_lerp(struct lp_build_context *bld,
1500 const struct lp_type type = bld->type;
1525 lp_build_context_init(&wide_bld, bld->gallivm, wide_type);
1527 lp_build_unpack2_native(bld->gallivm, type, wide_type, x, &xl, &xh);
1528 lp_build_unpack2_native(bld->gallivm, type, wide_type, v0, &v0l, &v0h);
1529 lp_build_unpack2_native(bld->gallivm, type, wide_type, v1, &v1l, &v1h);
1540 res = lp_build_pack2_native(bld->gallivm, wide_type, type, resl, resh);
1542 res = lp_build_lerp_simple(bld, x, v0, v1, flags);
1555 lp_build_lerp_2d(struct lp_build_context *bld,
1564 LLVMValueRef v0 = lp_build_lerp(bld, x, v00, v01, flags);
1565 LLVMValueRef v1 = lp_build_lerp(bld, x, v10, v11, flags);
1566 return lp_build_lerp(bld, y, v0, v1, flags);
1571 lp_build_lerp_3d(struct lp_build_context *bld,
1585 LLVMValueRef v0 = lp_build_lerp_2d(bld, x, y, v000, v001, v010, v011, flags);
1586 LLVMValueRef v1 = lp_build_lerp_2d(bld, x, y, v100, v101, v110, v111, flags);
1587 return lp_build_lerp(bld, z, v0, v1, flags);
1596 lp_build_min(struct lp_build_context *bld,
1600 assert(lp_check_value(bld->type, a));
1601 assert(lp_check_value(bld->type, b));
1603 if(a == bld->undef || b == bld->undef)
1604 return bld->undef;
1609 if (bld->type.norm) {
1610 if (!bld->type.sign) {
1611 if (a == bld->zero || b == bld->zero) {
1612 return bld->zero;
1615 if(a == bld->one)
1617 if(b == bld->one)
1621 return lp_build_min_simple(bld, a, b, GALLIVM_NAN_BEHAVIOR_UNDEFINED);
1631 lp_build_min_ext(struct lp_build_context *bld,
1636 assert(lp_check_value(bld->type, a));
1637 assert(lp_check_value(bld->type, b));
1639 if(a == bld->undef || b == bld->undef)
1640 return bld->undef;
1645 if (bld->type.norm) {
1646 if (!bld->type.sign) {
1647 if (a == bld->zero || b == bld->zero) {
1648 return bld->zero;
1651 if(a == bld->one)
1653 if(b == bld->one)
1657 return lp_build_min_simple(bld, a, b, nan_behavior);
1665 lp_build_max(struct lp_build_context *bld,
1669 assert(lp_check_value(bld->type, a));
1670 assert(lp_check_value(bld->type, b));
1672 if(a == bld->undef || b == bld->undef)
1673 return bld->undef;
1678 if(bld->type.norm) {
1679 if(a == bld->one || b == bld->one)
1680 return bld->one;
1681 if (!bld->type.sign) {
1682 if (a == bld->zero) {
1685 if (b == bld->zero) {
1691 return lp_build_max_simple(bld, a, b, GALLIVM_NAN_BEHAVIOR_UNDEFINED);
1702 lp_build_max_ext(struct lp_build_context *bld,
1707 assert(lp_check_value(bld->type, a));
1708 assert(lp_check_value(bld->type, b));
1710 if(a == bld->undef || b == bld->undef)
1711 return bld->undef;
1716 if(bld->type.norm) {
1717 if(a == bld->one || b == bld->one)
1718 return bld->one;
1719 if (!bld->type.sign) {
1720 if (a == bld->zero) {
1723 if (b == bld->zero) {
1729 return lp_build_max_simple(bld, a, b, nan_behavior);
1738 lp_build_clamp(struct lp_build_context *bld,
1743 assert(lp_check_value(bld->type, a));
1744 assert(lp_check_value(bld->type, min));
1745 assert(lp_check_value(bld->type, max));
1747 a = lp_build_min(bld, a, max);
1748 a = lp_build_max(bld, a, min);
1758 lp_build_clamp_zero_one_nanzero(struct lp_build_context *bld,
1761 a = lp_build_max_ext(bld, a, bld->zero, GALLIVM_NAN_RETURN_OTHER_SECOND_NONNAN);
1762 a = lp_build_min(bld, a, bld->one);
1771 lp_build_abs(struct lp_build_context *bld,
1774 LLVMBuilderRef builder = bld->gallivm->builder;
1775 const struct lp_type type = bld->type;
1776 LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
1786 LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
1788 LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type, ((unsigned long long) absMask));
1827 return lp_build_max(bld, a, LLVMBuildNeg(builder, a, ""));
1832 lp_build_negate(struct lp_build_context *bld,
1835 LLVMBuilderRef builder = bld->gallivm->builder;
1837 assert(lp_check_value(bld->type, a));
1839 if (bld->type.floating)
1850 lp_build_sgn(struct lp_build_context *bld,
1853 LLVMBuilderRef builder = bld->gallivm->builder;
1854 const struct lp_type type = bld->type;
1863 res = bld->one;
1873 int_type = lp_build_int_vec_type(bld->gallivm, type);
1874 vec_type = lp_build_vec_type(bld->gallivm, type);
1875 mask = lp_build_const_int_vec(bld->gallivm, type, maskBit);
1880 one = LLVMConstBitCast(bld->one, int_type);
1888 LLVMValueRef minus_one = lp_build_const_vec(bld->gallivm, type, -1.0);
1889 cond = lp_build_cmp(bld, PIPE_FUNC_GREATER, a, bld->zero);
1890 res = lp_build_select(bld, cond, bld->one, minus_one);
1894 cond = lp_build_cmp(bld, PIPE_FUNC_EQUAL, a, bld->zero);
1895 res = lp_build_select(bld, cond, bld->zero, res);
1908 lp_build_set_sign(struct lp_build_context *bld,
1911 LLVMBuilderRef builder = bld->gallivm->builder;
1912 const struct lp_type type = bld->type;
1913 LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
1914 LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
1915 LLVMValueRef shift = lp_build_const_int_vec(bld->gallivm, type, type.width - 1);
1916 LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type,
1942 lp_build_int_to_float(struct lp_build_context *bld,
1945 LLVMBuilderRef builder = bld->gallivm->builder;
1946 const struct lp_type type = bld->type;
1947 LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
1977 lp_build_iround_nearest_sse2(struct lp_build_context *bld,
1980 LLVMBuilderRef builder = bld->gallivm->builder;
1981 const struct lp_type type = bld->type;
1982 LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context);
1983 LLVMTypeRef ret_type = lp_build_int_vec_type(bld->gallivm, type);
2001 vec_type = LLVMVectorType(bld->elem_type, 4);
2033 lp_build_round_altivec(struct lp_build_context *bld,
2037 LLVMBuilderRef builder = bld->gallivm->builder;
2038 const struct lp_type type = bld->type;
2063 return lp_build_intrinsic_unary(builder, intrinsic, bld->vec_type, a);
2067 lp_build_round_arch(struct lp_build_context *bld,
2072 LLVMBuilderRef builder = bld->gallivm->builder;
2073 const struct lp_type type = bld->type;
2096 lp_format_intrinsic(intrinsic, sizeof intrinsic, intrinsic_root, bld->vec_type);
2097 return lp_build_intrinsic_unary(builder, intrinsic, bld->vec_type, a);
2100 return lp_build_round_altivec(bld, a, mode);
2109 lp_build_trunc(struct lp_build_context *bld,
2112 LLVMBuilderRef builder = bld->gallivm->builder;
2113 const struct lp_type type = bld->type;
2119 return lp_build_round_arch(bld, a, LP_BUILD_ROUND_TRUNCATE);
2122 const struct lp_type type = bld->type;
2125 LLVMValueRef cmpval = lp_build_const_vec(bld->gallivm, type, 1<<24);
2127 LLVMTypeRef int_vec_type = bld->int_vec_type;
2128 LLVMTypeRef vec_type = bld->vec_type;
2134 lp_build_context_init(&intbld, bld->gallivm, inttype);
2141 anosign = lp_build_abs(bld, a);
2152 return lp_build_select(bld, mask, a, res);
2164 lp_build_round(struct lp_build_context *bld,
2167 LLVMBuilderRef builder = bld->gallivm->builder;
2168 const struct lp_type type = bld->type;
2174 return lp_build_round_arch(bld, a, LP_BUILD_ROUND_NEAREST);
2177 const struct lp_type type = bld->type;
2180 LLVMValueRef cmpval = lp_build_const_vec(bld->gallivm, type, 1<<24);
2182 LLVMTypeRef int_vec_type = bld->int_vec_type;
2183 LLVMTypeRef vec_type = bld->vec_type;
2189 lp_build_context_init(&intbld, bld->gallivm, inttype);
2191 res = lp_build_iround(bld, a);
2195 anosign = lp_build_abs(bld, a);
2206 return lp_build_select(bld, mask, a, res);
2217 lp_build_floor(struct lp_build_context *bld,
2220 LLVMBuilderRef builder = bld->gallivm->builder;
2221 const struct lp_type type = bld->type;
2227 return lp_build_round_arch(bld, a, LP_BUILD_ROUND_FLOOR);
2230 const struct lp_type type = bld->type;
2233 LLVMValueRef cmpval = lp_build_const_vec(bld->gallivm, type, 1<<24);
2235 LLVMTypeRef int_vec_type = bld->int_vec_type;
2236 LLVMTypeRef vec_type = bld->vec_type;
2248 lp_build_context_init(&intbld, bld->gallivm, inttype);
2261 mask = lp_build_cmp(bld, PIPE_FUNC_GREATER, res, a);
2263 tmp = LLVMBuildBitCast(builder, bld->one, int_vec_type, "");
2266 res = lp_build_sub(bld, res, tmp);
2270 anosign = lp_build_abs(bld, a);
2281 return lp_build_select(bld, mask, a, res);
2292 lp_build_ceil(struct lp_build_context *bld,
2295 LLVMBuilderRef builder = bld->gallivm->builder;
2296 const struct lp_type type = bld->type;
2302 return lp_build_round_arch(bld, a, LP_BUILD_ROUND_CEIL);
2305 const struct lp_type type = bld->type;
2308 LLVMValueRef cmpval = lp_build_const_vec(bld->gallivm, type, 1<<24);
2310 LLVMTypeRef int_vec_type = bld->int_vec_type;
2311 LLVMTypeRef vec_type = bld->vec_type;
2323 lp_build_context_init(&intbld, bld->gallivm, inttype);
2333 mask = lp_build_cmp(bld, PIPE_FUNC_LESS, trunc, a);
2335 tmp = LLVMBuildBitCast(builder, bld->one, int_vec_type, "");
2338 res = lp_build_add(bld, trunc, tmp);
2341 anosign = lp_build_abs(bld, a);
2352 return lp_build_select(bld, mask, a, res);
2362 lp_build_fract(struct lp_build_context *bld,
2365 assert(bld->type.floating);
2366 return lp_build_sub(bld, a, lp_build_floor(bld, a));
2375 clamp_fract(struct lp_build_context *bld, LLVMValueRef fract)
2380 max = lp_build_const_vec(bld->gallivm, bld->type,
2381 1.0 - 1.0/(1LL << (lp_mantissa(bld->type) + 1)));
2382 return lp_build_min_ext(bld, fract, max,
2392 lp_build_fract_safe(struct lp_build_context *bld,
2395 return clamp_fract(bld, lp_build_fract(bld, a));
2405 lp_build_itrunc(struct lp_build_context *bld,
2408 LLVMBuilderRef builder = bld->gallivm->builder;
2409 const struct lp_type type = bld->type;
2410 LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
2426 lp_build_iround(struct lp_build_context *bld,
2429 LLVMBuilderRef builder = bld->gallivm->builder;
2430 const struct lp_type type = bld->type;
2431 LLVMTypeRef int_vec_type = bld->int_vec_type;
2441 return lp_build_iround_nearest_sse2(bld, a);
2444 res = lp_build_round_arch(bld, a, LP_BUILD_ROUND_NEAREST);
2449 half = lp_build_const_vec(bld->gallivm, type, 0.5);
2452 LLVMTypeRef vec_type = bld->vec_type;
2453 LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type,
2482 lp_build_ifloor(struct lp_build_context *bld,
2485 LLVMBuilderRef builder = bld->gallivm->builder;
2486 const struct lp_type type = bld->type;
2487 LLVMTypeRef int_vec_type = bld->int_vec_type;
2496 res = lp_build_round_arch(bld, a, LP_BUILD_ROUND_FLOOR);
2508 lp_build_context_init(&intbld, bld->gallivm, inttype);
2512 trunc = LLVMBuildSIToFP(builder, itrunc, bld->vec_type, "ifloor.trunc");
2520 mask = lp_build_cmp(bld, PIPE_FUNC_GREATER, trunc, a);
2539 lp_build_iceil(struct lp_build_context *bld,
2542 LLVMBuilderRef builder = bld
2543 const struct lp_type type = bld->type;
2544 LLVMTypeRef int_vec_type = bld->int_vec_type;
2551 res = lp_build_round_arch(bld, a, LP_BUILD_ROUND_CEIL);
2563 lp_build_context_init(&intbld, bld->gallivm, inttype);
2567 trunc = LLVMBuildSIToFP(builder, itrunc, bld->vec_type, "iceil.trunc");
2575 mask = lp_build_cmp(bld, PIPE_FUNC_LESS, trunc, a);
2594 lp_build_ifloor_fract(struct lp_build_context *bld,
2599 LLVMBuilderRef builder = bld->gallivm->builder;
2600 const struct lp_type type = bld->type;
2611 ipart = lp_build_floor(bld, a);
2613 *out_ipart = LLVMBuildFPToSI(builder, ipart, bld->int_vec_type, "ipart");
2620 *out_ipart = lp_build_ifloor(bld, a);
2621 ipart = LLVMBuildSIToFP(builder, *out_ipart, bld->vec_type, "ipart");
2632 lp_build_ifloor_fract_safe(struct lp_build_context *bld,
2637 lp_build_ifloor_fract(bld, a, out_ipart, out_fpart);
2638 *out_fpart = clamp_fract(bld, *out_fpart);
2643 lp_build_sqrt(struct lp_build_context *bld,
2646 LLVMBuilderRef builder = bld->gallivm->builder;
2647 const struct lp_type type = bld->type;
2648 LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
2675 lp_build_rcp_refine(struct lp_build_context *bld,
2679 LLVMBuilderRef builder = bld->gallivm->builder;
2680 LLVMValueRef two = lp_build_const_vec(bld->gallivm, bld->type, 2.0);
2692 lp_build_rcp(struct lp_build_context *bld,
2695 LLVMBuilderRef builder = bld->gallivm->builder;
2696 const struct lp_type type = bld->type;
2700 if(a == bld->zero)
2701 return bld->undef;
2702 if(a == bld->one)
2703 return bld->one;
2704 if(a == bld->undef)
2705 return bld->undef;
2710 return LLVMConstFDiv(bld->one, a);
2739 res = lp_build_intrinsic_unary(builder, intrinsic, bld->vec_type, a);
2742 res = lp_build_rcp_refine(bld, a, res);
2748 return LLVMBuildFDiv(builder, bld->one, a, "");
2760 lp_build_rsqrt_refine(struct lp_build_context *bld,
2764 LLVMBuilderRef builder = bld->gallivm->builder;
2765 LLVMValueRef half = lp_build_const_vec(bld->gallivm, bld->type, 0.5);
2766 LLVMValueRef three = lp_build_const_vec(bld->gallivm, bld->type, 3.0);
2784 lp_build_rsqrt(struct lp_build_context *bld,
2787 const struct lp_type type = bld->type;
2802 res = lp_build_fast_rsqrt(bld, a);
2813 LLVMValueRef flt_min = lp_build_const_vec(bld->gallivm, type, FLT_MIN);
2814 LLVMValueRef inf = lp_build_const_vec(bld->gallivm, type, INFINITY);
2817 res = lp_build_rsqrt_refine(bld, a, res);
2819 cmp = lp_build_compare(bld->gallivm, type, PIPE_FUNC_LESS, a, flt_min);
2820 res = lp_build_select(bld, cmp, inf, res);
2821 cmp = lp_build_compare(bld->gallivm, type, PIPE_FUNC_EQUAL, a, inf);
2822 res = lp_build_select(bld, cmp, bld->zero, res);
2823 cmp = lp_build_compare(bld->gallivm, type, PIPE_FUNC_EQUAL, a, bld->one);
2824 res = lp_build_select(bld, cmp, bld->one, res);
2830 return lp_build_rcp(bld, lp_build_sqrt(bld, a));
2860 lp_build_fast_rsqrt(struct lp_build_context *bld,
2863 LLVMBuilderRef builder = bld->gallivm->builder;
2864 const struct lp_type type = bld->type;
2877 return lp_build_intrinsic_unary(builder, intrinsic, bld->vec_type, a);
2882 return lp_build_rcp(bld, lp_build_sqrt(bld, a));
2895 lp_build_sin_or_cos(struct lp_build_context *bld,
2899 struct gallivm_state *gallivm = bld->gallivm;
2901 struct lp_type int_type = lp_int_type(bld->type);
2908 LLVMValueRef inv_sig_mask = lp_build_const_int_vec(gallivm, bld->type, ~0x80000000);
2909 LLVMValueRef a_v4si = LLVMBuildBitCast(b, a, bld->int_vec_type, "a_v4si");
2912 LLVMValueRef x_abs = LLVMBuildBitCast(b, absi, bld->vec_type, "x_abs");
2919 LLVMValueRef FOPi = lp_build_const_vec(gallivm, bld->type, 1.27323954473516);
2927 LLVMValueRef emm2_i = LLVMBuildFPToSI(b, scale_y, bld->int_vec_type, "emm2_i");
2934 LLVMValueRef all_one = lp_build_const_int_vec(gallivm, bld->type, 1);
2939 LLVMValueRef inv_one = lp_build_const_int_vec(gallivm, bld->type, ~1);
2945 LLVMValueRef y_2 = LLVMBuildSIToFP(b, emm2_and, bld->vec_type, "y_2");
2947 LLVMValueRef const_2 = lp_build_const_int_vec(gallivm, bld->type, 2);
2948 LLVMValueRef const_4 = lp_build_const_int_vec(gallivm, bld->type, 4);
2949 LLVMValueRef const_29 = lp_build_const_int_vec(gallivm, bld->type, 29);
2950 LLVMValueRef sign_mask = lp_build_const_int_vec(gallivm, bld->type, 0x80000000);
2980 emm2_3, lp_build_const_int_vec(gallivm, bld->type, 0));
2987 LLVMValueRef DP1 = lp_build_const_vec(gallivm, bld->type, -0.78515625);
2988 LLVMValueRef DP2 = lp_build_const_vec(gallivm, bld->type, -2.4187564849853515625e-4);
2989 LLVMValueRef DP3 = lp_build_const_vec(gallivm, bld->type, -3.77489497744594108e-8);
3011 LLVMValueRef coscof_p0 = lp_build_const_vec(gallivm, bld->type, 2.443315711809948E-005);
3012 LLVMValueRef coscof_p1 = lp_build_const_vec(gallivm, bld->type, -1.388731625493765E-003);
3013 LLVMValueRef coscof_p2 = lp_build_const_vec(gallivm, bld->type, 4.166664568298827E-002);
3030 LLVMValueRef half = lp_build_const_vec(gallivm, bld->type, 0.5);
3033 LLVMValueRef one = lp_build_const_vec(gallivm, bld->type, 1.0);
3041 LLVMValueRef sincof_p0 = lp_build_const_vec(gallivm, bld->type, -1.9515295891E-4);
3042 LLVMValueRef sincof_p1 = lp_build_const_vec(gallivm, bld->type, 8.3321608736E-3);
3043 bld->type, -1.6666654611E-1);
3070 LLVMValueRef y2_i = LLVMBuildBitCast(b, y2_9, bld->int_vec_type, "y2_i");
3071 LLVMValueRef y_i = LLVMBuildBitCast(b, y_10, bld->int_vec_type, "y_i");
3082 LLVMValueRef y_result = LLVMBuildBitCast(b, y_sign, bld->vec_type, "y_result");
3084 LLVMValueRef isfinite = lp_build_isfinite(bld, a);
3087 y_result = lp_build_clamp(bld, y_result,
3088 lp_build_const_vec(bld->gallivm, bld->type, -1.f),
3089 lp_build_const_vec(bld->gallivm, bld->type, 1.f));
3091 y_result = lp_build_select(bld, isfinite, y_result,
3092 lp_build_const_vec(bld->gallivm, bld->type, NAN));
3101 lp_build_sin(struct lp_build_context *bld,
3104 return lp_build_sin_or_cos(bld, a, FALSE);
3112 lp_build_cos(struct lp_build_context *bld,
3115 return lp_build_sin_or_cos(bld, a, TRUE);
3123 lp_build_pow(struct lp_build_context *bld,
3134 return lp_build_exp2(bld, lp_build_mul(bld, lp_build_log2(bld, x), y));
3142 lp_build_exp(struct lp_build_context *bld,
3146 LLVMValueRef log2e = lp_build_const_vec(bld->gallivm, bld->type,
3149 assert(lp_check_value(bld->type, x));
3151 return lp_build_exp2(bld, lp_build_mul(bld, log2e, x));
3160 lp_build_log(struct lp_build_context *bld,
3164 LLVMValueRef log2 = lp_build_const_vec(bld->gallivm, bld->type,
3167 assert(lp_check_value(bld->type, x));
3169 return lp_build_mul(bld, log2, lp_build_log2(bld, x));
3176 lp_build_log_safe(struct lp_build_context *bld,
3180 LLVMValueRef log2 = lp_build_const_vec(bld->gallivm, bld->type,
3183 assert(lp_check_value(bld->type, x));
3185 return lp_build_mul(bld, log2, lp_build_log2_safe(bld, x));
3194 lp_build_polynomial(struct lp_build_context *bld,
3199 const struct lp_type type = bld->type;
3204 assert(lp_check_value(bld->type, x));
3219 x2 = lp_build_mul(bld, x, x);
3224 coeff = lp_build_const_vec(bld->gallivm, type, coeffs[i]);
3228 even = lp_build_mad(bld, x2, even, coeff);
3233 odd = lp_build_mad(bld, x2, odd, coeff);
3240 return lp_build_mad(bld, odd, x, even);
3244 return bld->undef;
3281 lp_build_exp2(struct lp_build_context *bld,
3284 LLVMBuilderRef builder = bld->gallivm->builder;
3285 const struct lp_type type = bld->type;
3286 LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
3293 assert(lp_check_value(bld->type, x));
3306 x = lp_build_min_ext(bld, lp_build_const_vec(bld->gallivm, type, 128.0), x,
3308 x = lp_build_max_ext(bld, lp_build_const_vec(bld->gallivm, type, -126.99999),
3313 lp_build_ifloor_fract(bld, x, &ipart, &fpart);
3317 lp_build_const_int_vec(bld->gallivm, type, 127), "");
3319 lp_build_const_int_vec(bld->gallivm, type, 23), "");
3322 expfpart = lp_build_polynomial(bld, fpart, lp_build_exp2_polynomial,
3342 lp_build_extract_exponent(struct lp_build_context *bld,
3346 LLVMBuilderRef builder = bld->gallivm->builder;
3347 const struct lp_type type = bld->type;
3353 assert(lp_check_value(bld->type, x));
3355 x = LLVMBuildBitCast(builder, x, bld->int_vec_type, "");
3358 lp_build_const_int_vec(bld->gallivm, type, mantissa), "");
3360 lp_build_const_int_vec(bld->gallivm, type, 255), "");
3362 lp_build_const_int_vec(bld->gallivm, type, 127 - bias), "");
3376 lp_build_extract_mantissa(struct lp_build_context *bld,
3379 LLVMBuilderRef builder = bld->gallivm->builder;
3380 const struct lp_type type = bld->type;
3382 LLVMValueRef mantmask = lp_build_const_int_vec(bld->gallivm, type,
3384 LLVMValueRef one = LLVMConstBitCast(bld->one, bld->int_vec_type);
3387 assert(lp_check_value(bld->type, x));
3391 x = LLVMBuildBitCast(builder, x, bld->int_vec_type, "");
3396 res = LLVMBuildBitCast(builder, res, bld->vec_type, "");
3449 lp_build_log2_approx(struct lp_build_context *bld,
3456 LLVMBuilderRef builder = bld->gallivm->builder;
3457 const struct lp_type type = bld->type;
3458 LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
3459 LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
3461 LLVMValueRef expmask = lp_build_const_int_vec(bld->gallivm, type, 0x7f800000);
3462 LLVMValueRef mantmask = lp_build_const_int_vec(bld->gallivm, type, 0x007fffff);
3463 LLVMValueRef one = LLVMConstBitCast(bld->one, int_vec_type);
3474 assert(lp_check_value(bld->type, x));
3499 logexp = LLVMBuildLShr(builder, exp, lp_build_const_int_vec(bld->gallivm, type, 23), "");
3500 logexp = LLVMBuildSub(builder, logexp, lp_build_const_int_vec(bld->gallivm, type, 127), "");
3511 y = lp_build_div(bld,
3512 lp_build_sub(bld, mant, bld->one),
3513 lp_build_add(bld, mant, bld->one)
3517 z = lp_build_mul(bld, y, y);
3520 p_z = lp_build_polynomial(bld, z, lp_build_log2_polynomial,
3524 res = lp_build_mad(bld, y, p_z, logexp);
3528 negmask = lp_build_cmp(bld, PIPE_FUNC_LESS, x,
3529 lp_build_const_vec(bld->gallivm, type, 0.0f));
3530 zmask = lp_build_cmp(bld, PIPE_FUNC_EQUAL, x,
3531 lp_build_const_vec(bld->gallivm, type, 0.0f));
3532 infmask = lp_build_cmp(bld, PIPE_FUNC_GEQUAL, x,
3533 lp_build_const_vec(bld->gallivm, type, INFINITY));
3536 res = lp_build_select(bld, infmask,
3537 lp_build_const_vec(bld->gallivm, type, INFINITY),
3540 res = lp_build_select(bld, zmask,
3541 lp_build_const_vec(bld->gallivm, type, -INFINITY),
3544 res = lp_build_select(bld, negmask,
3545 lp_build_const_vec(bld->gallivm, type, NAN),
3569 lp_build_log2(struct lp_build_context *bld,
3573 lp_build_log2_approx(bld, x, NULL, NULL, &res, FALSE);
3583 lp_build_log2_safe(struct lp_build_context *bld,
3587 lp_build_log2_approx(bld, x, NULL, NULL, &res, TRUE);
3603 lp_build_fast_log2(struct lp_build_context *bld,
3606 LLVMBuilderRef builder = bld->gallivm->builder;
3610 assert(lp_check_value(bld->type, x));
3612 assert(bld->type.floating);
3615 ipart = lp_build_extract_exponent(bld, x, -1);
3616 ipart = LLVMBuildSIToFP(builder, ipart, bld->vec_type, "");
3619 fpart = lp_build_extract_mantissa(bld, x);
3632 lp_build_ilog2(struct lp_build_context *bld,
3635 LLVMBuilderRef builder = bld->gallivm->builder;
3636 LLVMValueRef sqrt2 = lp_build_const_vec(bld->gallivm, bld->type, M_SQRT2);
3639 assert(bld->type.floating);
3641 assert(lp_check_value(bld->type, x));
3647 ipart = lp_build_extract_exponent(bld, x, 0);
3653 lp_build_mod(struct lp_build_context *bld,
3657 LLVMBuilderRef builder = bld->gallivm->builder;
3659 const struct lp_type type = bld->type;
3680 lp_build_isnan(struct lp_build_context *bld,
3684 LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, bld->type);
3686 assert(bld->type.floating);
3687 assert(lp_check_value(bld->type, x));
3689 mask = LLVMBuildFCmp(bld->gallivm->builder, LLVMRealOEQ, x, x,
3691 mask = LLVMBuildNot(bld->gallivm->builder, mask, "");
3692 mask = LLVMBuildSExt(bld->gallivm->builder, mask, int_vec_type, "isnan");
3700 lp_build_isfinite(struct lp_build_context *bld,
3703 LLVMBuilderRef builder = bld->gallivm->builder;
3704 LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, bld->type);
3705 struct lp_type int_type = lp_int_type(bld->type);
3707 LLVMValueRef infornan32 = lp_build_const_int_vec(bld->gallivm, bld->type,
3710 if (!bld->type.floating) {
3711 return lp_build_const_int_vec(bld->gallivm, bld->type, 0);
3713 assert(bld->type.floating);
3714 assert(lp_check_value(bld->type, x));
3715 assert(bld->type.width == 32);
3718 return lp_build_compare(bld->gallivm, int_type, PIPE_FUNC_NOTEQUAL,