| 1 |
/* |
| 2 |
* Copyright (C) 2021 Collabora, Ltd. |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "bi_builder.h" |
| 7 |
#include "bi_test.h" |
| 8 |
#include "compiler.h" |
| 9 |
|
| 10 |
#include <gtest/gtest.h> |
| 11 |
|
| 12 |
static void |
| 13 |
bi_optimizer(bi_context *ctx) |
| 14 |
{ |
| 15 |
bi_opt_mod_prop_forward(ctx); |
| 16 |
bi_opt_mod_prop_backward(ctx); |
| 17 |
bi_opt_dce(ctx, true); |
| 18 |
} |
| 19 |
|
| 20 |
/* Define reg first so it has a consistent variable index, and pass it to an |
| 21 |
* instruction that cannot be dead code eliminated so the program is nontrivial. |
| 22 |
*/ |
| 23 |
#define CASE(instr, expected) \ |
| 24 |
INSTRUCTION_CASE( \ |
| 25 |
{ \ |
| 26 |
UNUSED bi_index reg = bi_temp(b->shader); \ |
| 27 |
instr; \ |
| 28 |
bi_kaboom(b, reg); \ |
| 29 |
}, \ |
| 30 |
{ \ |
| 31 |
UNUSED bi_index reg = bi_temp(b->shader); \ |
| 32 |
expected; \ |
| 33 |
bi_kaboom(b, reg); \ |
| 34 |
}, \ |
| 35 |
bi_optimizer); |
| 36 |
|
| 37 |
#define NEGCASE(instr) CASE(instr, instr) |
| 38 |
|
| 39 |
class Optimizer : public testing::Test { |
| 40 |
protected: |
| 41 |
Optimizer() |
| 42 |
{ |
| 43 |
mem_ctx = ralloc_context(NULL); |
| 44 |
|
| 45 |
x = bi_register(1); |
| 46 |
y = bi_register(2); |
| 47 |
negabsx = bi_neg(bi_abs(x)); |
| 48 |
} |
| 49 |
|
| 50 |
~Optimizer() |
| 51 |
{ |
| 52 |
ralloc_free(mem_ctx); |
| 53 |
} |
| 54 |
|
| 55 |
void *mem_ctx; |
| 56 |
|
| 57 |
bi_index x; |
| 58 |
bi_index y; |
| 59 |
bi_index negabsx; |
| 60 |
}; |
| 61 |
|
| 62 |
TEST_F(Optimizer, FusedFABSNEG) |
| 63 |
{ |
| 64 |
CASE(bi_fadd_f32_to(b, reg, bi_fabsneg_f32(b, bi_abs(x)), y), |
| 65 |
bi_fadd_f32_to(b, reg, bi_abs(x), y)); |
| 66 |
|
| 67 |
CASE(bi_fadd_f32_to(b, reg, bi_fabsneg_f32(b, bi_neg(x)), y), |
| 68 |
bi_fadd_f32_to(b, reg, bi_neg(x), y)); |
| 69 |
|
| 70 |
CASE(bi_fadd_f32_to(b, reg, bi_fabsneg_f32(b, negabsx), y), |
| 71 |
bi_fadd_f32_to(b, reg, negabsx, y)); |
| 72 |
|
| 73 |
CASE(bi_fadd_f32_to(b, reg, bi_fabsneg_f32(b, x), y), |
| 74 |
bi_fadd_f32_to(b, reg, x, y)); |
| 75 |
|
| 76 |
CASE(bi_fmin_f32_to(b, reg, bi_fabsneg_f32(b, negabsx), bi_neg(y)), |
| 77 |
bi_fmin_f32_to(b, reg, negabsx, bi_neg(y))); |
| 78 |
} |
| 79 |
|
| 80 |
TEST_F(Optimizer, FusedFABSNEGForFP16) |
| 81 |
{ |
| 82 |
CASE(bi_fadd_v2f16_to(b, reg, bi_fabsneg_v2f16(b, negabsx), y), |
| 83 |
bi_fadd_v2f16_to(b, reg, negabsx, y)); |
| 84 |
|
| 85 |
CASE(bi_fmin_v2f16_to(b, reg, bi_fabsneg_v2f16(b, negabsx), bi_neg(y)), |
| 86 |
bi_fmin_v2f16_to(b, reg, negabsx, bi_neg(y))); |
| 87 |
} |
| 88 |
|
| 89 |
TEST_F(Optimizer, FuseFADD_F32WithEqualSourcesAbsAbsAndClamp) |
| 90 |
{ |
| 91 |
CASE( |
| 92 |
{ |
| 93 |
bi_instr *I = |
| 94 |
bi_fadd_f32_to(b, reg, bi_fabsneg_f32(b, bi_abs(x)), bi_abs(x)); |
| 95 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 96 |
}, |
| 97 |
{ |
| 98 |
bi_instr *I = bi_fadd_f32_to(b, reg, bi_abs(x), bi_abs(x)); |
| 99 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 100 |
}); |
| 101 |
|
| 102 |
CASE( |
| 103 |
{ |
| 104 |
bi_instr *I = |
| 105 |
bi_fadd_f32_to(b, reg, bi_abs(x), bi_fabsneg_f32(b, bi_abs(x))); |
| 106 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 107 |
}, |
| 108 |
{ |
| 109 |
bi_instr *I = bi_fadd_f32_to(b, reg, bi_abs(x), bi_abs(x)); |
| 110 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 111 |
}); |
| 112 |
|
| 113 |
CASE( |
| 114 |
{ |
| 115 |
bi_instr *I = |
| 116 |
bi_fclamp_f32_to(b, reg, bi_fadd_f32(b, bi_abs(x), bi_abs(x))); |
| 117 |
I->clamp = BI_CLAMP_CLAMP_0_INF; |
| 118 |
}, |
| 119 |
{ |
| 120 |
bi_instr *I = bi_fadd_f32_to(b, reg, bi_abs(x), bi_abs(x)); |
| 121 |
I->clamp = BI_CLAMP_CLAMP_0_INF; |
| 122 |
}); |
| 123 |
} |
| 124 |
|
| 125 |
TEST_F(Optimizer, FuseFADD_V2F16WithDifferentSourcesAbsAbsAndClamp) |
| 126 |
{ |
| 127 |
CASE( |
| 128 |
{ |
| 129 |
bi_instr *I = |
| 130 |
bi_fadd_v2f16_to(b, reg, bi_fabsneg_v2f16(b, bi_abs(x)), bi_abs(y)); |
| 131 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 132 |
}, |
| 133 |
{ |
| 134 |
bi_instr *I = bi_fadd_v2f16_to(b, reg, bi_abs(x), bi_abs(y)); |
| 135 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 136 |
}); |
| 137 |
|
| 138 |
CASE( |
| 139 |
{ |
| 140 |
bi_instr *I = |
| 141 |
bi_fadd_v2f16_to(b, reg, bi_abs(x), bi_fabsneg_v2f16(b, bi_abs(y))); |
| 142 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 143 |
}, |
| 144 |
{ |
| 145 |
bi_instr *I = bi_fadd_v2f16_to(b, reg, bi_abs(x), bi_abs(y)); |
| 146 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 147 |
}); |
| 148 |
|
| 149 |
CASE( |
| 150 |
{ |
| 151 |
bi_instr *I = |
| 152 |
bi_fclamp_v2f16_to(b, reg, bi_fadd_v2f16(b, bi_abs(x), bi_abs(y))); |
| 153 |
I->clamp = BI_CLAMP_CLAMP_0_INF; |
| 154 |
}, |
| 155 |
{ |
| 156 |
bi_instr *I = bi_fadd_v2f16_to(b, reg, bi_abs(x), bi_abs(y)); |
| 157 |
I->clamp = BI_CLAMP_CLAMP_0_INF; |
| 158 |
}); |
| 159 |
} |
| 160 |
|
| 161 |
TEST_F(Optimizer, AvoidFADD_V2F16WithEqualSourcesAbsAbsAndClamp) |
| 162 |
{ |
| 163 |
NEGCASE({ |
| 164 |
bi_instr *I = |
| 165 |
bi_fadd_v2f16_to(b, reg, bi_fabsneg_v2f16(b, bi_abs(x)), bi_abs(x)); |
| 166 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 167 |
}); |
| 168 |
|
| 169 |
NEGCASE({ |
| 170 |
bi_instr *I = |
| 171 |
bi_fadd_v2f16_to(b, reg, bi_abs(x), bi_fabsneg_v2f16(b, bi_abs(x))); |
| 172 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 173 |
}); |
| 174 |
|
| 175 |
NEGCASE({ |
| 176 |
bi_instr *I = |
| 177 |
bi_fclamp_v2f16_to(b, reg, bi_fadd_v2f16(b, bi_abs(x), bi_abs(x))); |
| 178 |
I->clamp = BI_CLAMP_CLAMP_0_INF; |
| 179 |
}); |
| 180 |
} |
| 181 |
|
| 182 |
TEST_F(Optimizer, SwizzlesComposedForFP16) |
| 183 |
{ |
| 184 |
CASE(bi_fadd_v2f16_to( |
| 185 |
b, reg, bi_fabsneg_v2f16(b, bi_swz_16(negabsx, true, false)), y), |
| 186 |
bi_fadd_v2f16_to(b, reg, bi_swz_16(negabsx, true, false), y)); |
| 187 |
|
| 188 |
CASE(bi_fadd_v2f16_to( |
| 189 |
b, reg, bi_swz_16(bi_fabsneg_v2f16(b, negabsx), true, false), y), |
| 190 |
bi_fadd_v2f16_to(b, reg, bi_swz_16(negabsx, true, false), y)); |
| 191 |
|
| 192 |
CASE(bi_fadd_v2f16_to( |
| 193 |
b, reg, |
| 194 |
bi_swz_16(bi_fabsneg_v2f16(b, bi_swz_16(negabsx, true, false)), true, |
| 195 |
false), |
| 196 |
y), |
| 197 |
bi_fadd_v2f16_to(b, reg, negabsx, y)); |
| 198 |
|
| 199 |
CASE(bi_fadd_v2f16_to( |
| 200 |
b, reg, |
| 201 |
bi_swz_16(bi_fabsneg_v2f16(b, bi_half(negabsx, false)), true, false), |
| 202 |
y), |
| 203 |
bi_fadd_v2f16_to(b, reg, bi_half(negabsx, false), y)); |
| 204 |
|
| 205 |
CASE(bi_fadd_v2f16_to( |
| 206 |
b, reg, |
| 207 |
bi_swz_16(bi_fabsneg_v2f16(b, bi_half(negabsx, true)), true, false), |
| 208 |
y), |
| 209 |
bi_fadd_v2f16_to(b, reg, bi_half(negabsx, true), y)); |
| 210 |
} |
| 211 |
|
| 212 |
TEST_F(Optimizer, PreserveWidens) |
| 213 |
{ |
| 214 |
/* Check that widens are passed through */ |
| 215 |
CASE(bi_fadd_f32_to(b, reg, bi_fabsneg_f32(b, bi_half(negabsx, false)), y), |
| 216 |
bi_fadd_f32_to(b, reg, bi_half(negabsx, false), y)); |
| 217 |
|
| 218 |
CASE(bi_fadd_f32_to(b, reg, bi_fabsneg_f32(b, bi_half(negabsx, true)), y), |
| 219 |
bi_fadd_f32_to(b, reg, bi_half(negabsx, true), y)); |
| 220 |
|
| 221 |
CASE(bi_fadd_f32_to(b, reg, bi_fabsneg_f32(b, bi_half(x, true)), |
| 222 |
bi_fabsneg_f32(b, bi_half(x, false))), |
| 223 |
bi_fadd_f32_to(b, reg, bi_half(x, true), bi_half(x, false))); |
| 224 |
} |
| 225 |
|
| 226 |
TEST_F(Optimizer, DoNotMixSizesForFABSNEG) |
| 227 |
{ |
| 228 |
/* Refuse to mix sizes for fabsneg, that's wrong */ |
| 229 |
NEGCASE(bi_fadd_f32_to(b, reg, bi_fabsneg_v2f16(b, negabsx), y)); |
| 230 |
NEGCASE(bi_fadd_v2f16_to(b, reg, bi_fabsneg_f32(b, negabsx), y)); |
| 231 |
} |
| 232 |
|
| 233 |
TEST_F(Optimizer, AvoidZeroAndFABSNEGFootguns) |
| 234 |
{ |
| 235 |
/* It's tempting to use addition by 0.0 as the absneg primitive, but that |
| 236 |
* has footguns around signed zero and round modes. Check we don't |
| 237 |
* incorrectly fuse these rules. */ |
| 238 |
|
| 239 |
bi_index zero = bi_zero(); |
| 240 |
|
| 241 |
NEGCASE(bi_fadd_f32_to(b, reg, bi_fadd_f32(b, bi_abs(x), zero), y)); |
| 242 |
NEGCASE(bi_fadd_f32_to(b, reg, bi_fadd_f32(b, bi_neg(x), zero), y)); |
| 243 |
NEGCASE(bi_fadd_f32_to(b, reg, bi_fadd_f32(b, bi_neg(bi_abs(x)), zero), y)); |
| 244 |
NEGCASE(bi_fadd_f32_to(b, reg, bi_fadd_f32(b, x, zero), y)); |
| 245 |
} |
| 246 |
|
| 247 |
TEST_F(Optimizer, ClampsPropagated) |
| 248 |
{ |
| 249 |
CASE( |
| 250 |
{ |
| 251 |
bi_instr *I = bi_fclamp_f32_to(b, reg, bi_fadd_f32(b, x, y)); |
| 252 |
I->clamp = BI_CLAMP_CLAMP_0_INF; |
| 253 |
}, |
| 254 |
{ |
| 255 |
bi_instr *I = bi_fadd_f32_to(b, reg, x, y); |
| 256 |
I->clamp = BI_CLAMP_CLAMP_0_INF; |
| 257 |
}); |
| 258 |
|
| 259 |
CASE( |
| 260 |
{ |
| 261 |
bi_instr *I = bi_fclamp_v2f16_to(b, reg, bi_fadd_v2f16(b, x, y)); |
| 262 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 263 |
}, |
| 264 |
{ |
| 265 |
bi_instr *I = bi_fadd_v2f16_to(b, reg, x, y); |
| 266 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 267 |
}); |
| 268 |
} |
| 269 |
|
| 270 |
TEST_F(Optimizer, ClampsComposed) |
| 271 |
{ |
| 272 |
CASE( |
| 273 |
{ |
| 274 |
bi_instr *I = bi_fadd_f32_to(b, bi_temp(b->shader), x, y); |
| 275 |
bi_instr *J = bi_fclamp_f32_to(b, reg, I->dest[0]); |
| 276 |
I->clamp = BI_CLAMP_CLAMP_M1_1; |
| 277 |
J->clamp = BI_CLAMP_CLAMP_0_INF; |
| 278 |
}, |
| 279 |
{ |
| 280 |
bi_instr *I = bi_fadd_f32_to(b, reg, x, y); |
| 281 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 282 |
}); |
| 283 |
|
| 284 |
CASE( |
| 285 |
{ |
| 286 |
bi_instr *I = bi_fadd_f32_to(b, bi_temp(b->shader), x, y); |
| 287 |
bi_instr *J = bi_fclamp_f32_to(b, reg, I->dest[0]); |
| 288 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 289 |
J->clamp = BI_CLAMP_CLAMP_0_INF; |
| 290 |
}, |
| 291 |
{ |
| 292 |
bi_instr *I = bi_fadd_f32_to(b, reg, x, y); |
| 293 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 294 |
}); |
| 295 |
|
| 296 |
CASE( |
| 297 |
{ |
| 298 |
bi_instr *I = bi_fadd_f32_to(b, bi_temp(b->shader), x, y); |
| 299 |
bi_instr *J = bi_fclamp_f32_to(b, reg, I->dest[0]); |
| 300 |
I->clamp = BI_CLAMP_CLAMP_0_INF; |
| 301 |
J->clamp = BI_CLAMP_CLAMP_0_INF; |
| 302 |
}, |
| 303 |
{ |
| 304 |
bi_instr *I = bi_fadd_f32_to(b, reg, x, y); |
| 305 |
I->clamp = BI_CLAMP_CLAMP_0_INF; |
| 306 |
}); |
| 307 |
|
| 308 |
CASE( |
| 309 |
{ |
| 310 |
bi_instr *I = bi_fadd_v2f16_to(b, bi_temp(b->shader), x, y); |
| 311 |
bi_instr *J = bi_fclamp_v2f16_to(b, reg, I->dest[0]); |
| 312 |
I->clamp = BI_CLAMP_CLAMP_M1_1; |
| 313 |
J->clamp = BI_CLAMP_CLAMP_0_INF; |
| 314 |
}, |
| 315 |
{ |
| 316 |
bi_instr *I = bi_fadd_v2f16_to(b, reg, x, y); |
| 317 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 318 |
}); |
| 319 |
|
| 320 |
CASE( |
| 321 |
{ |
| 322 |
bi_instr *I = bi_fadd_v2f16_to(b, bi_temp(b->shader), x, y); |
| 323 |
bi_instr *J = bi_fclamp_v2f16_to(b, reg, I->dest[0]); |
| 324 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 325 |
J->clamp = BI_CLAMP_CLAMP_0_INF; |
| 326 |
}, |
| 327 |
{ |
| 328 |
bi_instr *I = bi_fadd_v2f16_to(b, reg, x, y); |
| 329 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 330 |
}); |
| 331 |
|
| 332 |
CASE( |
| 333 |
{ |
| 334 |
bi_instr *I = bi_fadd_v2f16_to(b, bi_temp(b->shader), x, y); |
| 335 |
bi_instr *J = bi_fclamp_v2f16_to(b, reg, I->dest[0]); |
| 336 |
I->clamp = BI_CLAMP_CLAMP_0_INF; |
| 337 |
J->clamp = BI_CLAMP_CLAMP_0_INF; |
| 338 |
}, |
| 339 |
{ |
| 340 |
bi_instr *I = bi_fadd_v2f16_to(b, reg, x, y); |
| 341 |
I->clamp = BI_CLAMP_CLAMP_0_INF; |
| 342 |
}); |
| 343 |
} |
| 344 |
|
| 345 |
TEST_F(Optimizer, DoNotMixSizesWhenClamping) |
| 346 |
{ |
| 347 |
NEGCASE({ |
| 348 |
bi_instr *I = bi_fclamp_f32_to(b, reg, bi_fadd_v2f16(b, x, y)); |
| 349 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 350 |
}); |
| 351 |
|
| 352 |
NEGCASE({ |
| 353 |
bi_instr *I = bi_fclamp_v2f16_to(b, reg, bi_fadd_f32(b, x, y)); |
| 354 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 355 |
}); |
| 356 |
} |
| 357 |
|
| 358 |
TEST_F(Optimizer, DoNotUseAdditionByZeroForClamps) |
| 359 |
{ |
| 360 |
bi_index zero = bi_zero(); |
| 361 |
|
| 362 |
/* We can't use addition by 0.0 for clamps due to signed zeros. */ |
| 363 |
NEGCASE({ |
| 364 |
bi_instr *I = bi_fadd_f32_to(b, reg, bi_fadd_f32(b, x, y), zero); |
| 365 |
I->clamp = BI_CLAMP_CLAMP_M1_1; |
| 366 |
}); |
| 367 |
|
| 368 |
NEGCASE({ |
| 369 |
bi_instr *I = bi_fadd_v2f16_to(b, reg, bi_fadd_v2f16(b, x, y), zero); |
| 370 |
I->clamp = BI_CLAMP_CLAMP_0_1; |
| 371 |
}); |
| 372 |
} |
| 373 |
|
| 374 |
TEST_F(Optimizer, FuseComparisonsWithDISCARD) |
| 375 |
{ |
| 376 |
CASE(bi_discard_b32(b, bi_fcmp_f32(b, x, y, BI_CMPF_LE, BI_RESULT_TYPE_F1)), |
| 377 |
bi_discard_f32(b, x, y, BI_CMPF_LE)); |
| 378 |
|
| 379 |
CASE(bi_discard_b32(b, bi_fcmp_f32(b, x, y, BI_CMPF_NE, BI_RESULT_TYPE_I1)), |
| 380 |
bi_discard_f32(b, x, y, BI_CMPF_NE)); |
| 381 |
|
| 382 |
CASE(bi_discard_b32(b, bi_fcmp_f32(b, x, y, BI_CMPF_EQ, BI_RESULT_TYPE_M1)), |
| 383 |
bi_discard_f32(b, x, y, BI_CMPF_EQ)); |
| 384 |
|
| 385 |
for (unsigned h = 0; h < 2; ++h) { |
| 386 |
CASE(bi_discard_b32( |
| 387 |
b, bi_half(bi_fcmp_v2f16(b, x, y, BI_CMPF_LE, BI_RESULT_TYPE_F1), |
| 388 |
h)), |
| 389 |
bi_discard_f32(b, bi_half(x, h), bi_half(y, h), BI_CMPF_LE)); |
| 390 |
|
| 391 |
CASE(bi_discard_b32( |
| 392 |
b, bi_half(bi_fcmp_v2f16(b, x, y, BI_CMPF_NE, BI_RESULT_TYPE_I1), |
| 393 |
h)), |
| 394 |
bi_discard_f32(b, bi_half(x, h), bi_half(y, h), BI_CMPF_NE)); |
| 395 |
|
| 396 |
CASE(bi_discard_b32( |
| 397 |
b, bi_half(bi_fcmp_v2f16(b, x, y, BI_CMPF_EQ, BI_RESULT_TYPE_M1), |
| 398 |
h)), |
| 399 |
bi_discard_f32(b, bi_half(x, h), bi_half(y, h), BI_CMPF_EQ)); |
| 400 |
} |
| 401 |
} |
| 402 |
|
| 403 |
TEST_F(Optimizer, DoNotFuseSpecialComparisons) |
| 404 |
{ |
| 405 |
NEGCASE( |
| 406 |
bi_discard_b32(b, bi_fcmp_f32(b, x, y, BI_CMPF_GTLT, BI_RESULT_TYPE_F1))); |
| 407 |
NEGCASE(bi_discard_b32( |
| 408 |
b, bi_fcmp_f32(b, x, y, BI_CMPF_TOTAL, BI_RESULT_TYPE_F1))); |
| 409 |
} |
| 410 |
|
| 411 |
TEST_F(Optimizer, FuseResultType) |
| 412 |
{ |
| 413 |
CASE(bi_mux_i32_to(b, reg, bi_imm_f32(0.0), bi_imm_f32(1.0), |
| 414 |
bi_fcmp_f32(b, x, y, BI_CMPF_LE, BI_RESULT_TYPE_M1), |
| 415 |
BI_MUX_INT_ZERO), |
| 416 |
bi_fcmp_f32_to(b, reg, x, y, BI_CMPF_LE, BI_RESULT_TYPE_F1)); |
| 417 |
|
| 418 |
CASE(bi_mux_i32_to( |
| 419 |
b, reg, bi_imm_f32(0.0), bi_imm_f32(1.0), |
| 420 |
bi_fcmp_f32(b, bi_abs(x), bi_neg(y), BI_CMPF_LE, BI_RESULT_TYPE_M1), |
| 421 |
BI_MUX_INT_ZERO), |
| 422 |
bi_fcmp_f32_to(b, reg, bi_abs(x), bi_neg(y), BI_CMPF_LE, |
| 423 |
BI_RESULT_TYPE_F1)); |
| 424 |
|
| 425 |
CASE(bi_mux_i32_to( |
| 426 |
b, reg, bi_imm_u32(0), bi_imm_u32(1), |
| 427 |
bi_fcmp_f32(b, bi_abs(x), bi_neg(y), BI_CMPF_LE, BI_RESULT_TYPE_M1), |
| 428 |
BI_MUX_INT_ZERO), |
| 429 |
bi_fcmp_f32_to(b, reg, bi_abs(x), bi_neg(y), BI_CMPF_LE, |
| 430 |
BI_RESULT_TYPE_I1)); |
| 431 |
|
| 432 |
CASE(bi_mux_v2i16_to(b, reg, bi_imm_f16(0.0), bi_imm_f16(1.0), |
| 433 |
bi_fcmp_v2f16(b, bi_abs(x), bi_neg(y), BI_CMPF_LE, |
| 434 |
BI_RESULT_TYPE_M1), |
| 435 |
BI_MUX_INT_ZERO), |
| 436 |
bi_fcmp_v2f16_to(b, reg, bi_abs(x), bi_neg(y), BI_CMPF_LE, |
| 437 |
BI_RESULT_TYPE_F1)); |
| 438 |
|
| 439 |
CASE(bi_mux_v2i16_to(b, reg, bi_imm_u16(0), bi_imm_u16(1), |
| 440 |
bi_fcmp_v2f16(b, bi_abs(x), bi_neg(y), BI_CMPF_LE, |
| 441 |
BI_RESULT_TYPE_M1), |
| 442 |
BI_MUX_INT_ZERO), |
| 443 |
bi_fcmp_v2f16_to(b, reg, bi_abs(x), bi_neg(y), BI_CMPF_LE, |
| 444 |
BI_RESULT_TYPE_I1)); |
| 445 |
|
| 446 |
CASE(bi_mux_i32_to(b, reg, bi_imm_u32(0), bi_imm_u32(1), |
| 447 |
bi_icmp_u32(b, x, y, BI_CMPF_LE, BI_RESULT_TYPE_M1), |
| 448 |
BI_MUX_INT_ZERO), |
| 449 |
bi_icmp_u32_to(b, reg, x, y, BI_CMPF_LE, BI_RESULT_TYPE_I1)); |
| 450 |
|
| 451 |
CASE(bi_mux_v2i16_to(b, reg, bi_imm_u16(0), bi_imm_u16(1), |
| 452 |
bi_icmp_v2u16(b, x, y, BI_CMPF_LE, BI_RESULT_TYPE_M1), |
| 453 |
BI_MUX_INT_ZERO), |
| 454 |
bi_icmp_v2u16_to(b, reg, x, y, BI_CMPF_LE, BI_RESULT_TYPE_I1)); |
| 455 |
|
| 456 |
CASE(bi_mux_v4i8_to(b, reg, bi_imm_u8(0), bi_imm_u8(1), |
| 457 |
bi_icmp_v4u8(b, x, y, BI_CMPF_LE, BI_RESULT_TYPE_M1), |
| 458 |
BI_MUX_INT_ZERO), |
| 459 |
bi_icmp_v4u8_to(b, reg, x, y, BI_CMPF_LE, BI_RESULT_TYPE_I1)); |
| 460 |
|
| 461 |
CASE(bi_mux_i32_to(b, reg, bi_imm_u32(0), bi_imm_u32(1), |
| 462 |
bi_icmp_s32(b, x, y, BI_CMPF_LE, BI_RESULT_TYPE_M1), |
| 463 |
BI_MUX_INT_ZERO), |
| 464 |
bi_icmp_s32_to(b, reg, x, y, BI_CMPF_LE, BI_RESULT_TYPE_I1)); |
| 465 |
|
| 466 |
CASE(bi_mux_v2i16_to(b, reg, bi_imm_u16(0), bi_imm_u16(1), |
| 467 |
bi_icmp_v2s16(b, x, y, BI_CMPF_LE, BI_RESULT_TYPE_M1), |
| 468 |
BI_MUX_INT_ZERO), |
| 469 |
bi_icmp_v2s16_to(b, reg, x, y, BI_CMPF_LE, BI_RESULT_TYPE_I1)); |
| 470 |
|
| 471 |
CASE(bi_mux_v4i8_to(b, reg, bi_imm_u8(0), bi_imm_u8(1), |
| 472 |
bi_icmp_v4s8(b, x, y, BI_CMPF_LE, BI_RESULT_TYPE_M1), |
| 473 |
BI_MUX_INT_ZERO), |
| 474 |
bi_icmp_v4s8_to(b, reg, x, y, BI_CMPF_LE, BI_RESULT_TYPE_I1)); |
| 475 |
} |
| 476 |
|
| 477 |
TEST_F(Optimizer, DoNotFuseMixedSizeResultType) |
| 478 |
{ |
| 479 |
NEGCASE(bi_mux_i32_to( |
| 480 |
b, reg, bi_imm_f32(0.0), bi_imm_f32(1.0), |
| 481 |
bi_fcmp_v2f16(b, bi_abs(x), bi_neg(y), BI_CMPF_LE, BI_RESULT_TYPE_M1), |
| 482 |
BI_MUX_INT_ZERO)); |
| 483 |
|
| 484 |
NEGCASE(bi_mux_v2i16_to( |
| 485 |
b, reg, bi_imm_f16(0.0), bi_imm_f16(1.0), |
| 486 |
bi_fcmp_f32(b, bi_abs(x), bi_neg(y), BI_CMPF_LE, BI_RESULT_TYPE_M1), |
| 487 |
BI_MUX_INT_ZERO)); |
| 488 |
} |
| 489 |
|
| 490 |
TEST_F(Optimizer, VarTexCoord32) |
| 491 |
{ |
| 492 |
CASE( |
| 493 |
{ |
| 494 |
bi_index ld = |
| 495 |
bi_ld_var_imm(b, bi_null(), BI_REGISTER_FORMAT_F32, |
| 496 |
BI_SAMPLE_CENTER, BI_UPDATE_STORE, BI_VECSIZE_V2, 0); |
| 497 |
|
| 498 |
bi_index x = bi_temp(b->shader); |
| 499 |
bi_index y = bi_temp(b->shader); |
| 500 |
bi_instr *split = bi_split_i32_to(b, 2, ld); |
| 501 |
split->dest[0] = x; |
| 502 |
split->dest[1] = y; |
| 503 |
|
| 504 |
bi_texs_2d_f32_to(b, reg, x, y, false, 0, 0); |
| 505 |
}, |
| 506 |
{ |
| 507 |
bi_var_tex_f32_to(b, reg, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 0, |
| 508 |
0); |
| 509 |
}); |
| 510 |
} |
| 511 |
|
| 512 |
TEST_F(Optimizer, Int8ToFloat32) |
| 513 |
{ |
| 514 |
for (unsigned i = 0; i < 4; ++i) { |
| 515 |
CASE(bi_s32_to_f32_to(b, reg, bi_s8_to_s32(b, bi_byte(x, i))), |
| 516 |
bi_s8_to_f32_to(b, reg, bi_byte(x, i))); |
| 517 |
|
| 518 |
CASE(bi_s32_to_f32_to(b, reg, bi_u8_to_u32(b, bi_byte(x, i))), |
| 519 |
bi_u8_to_f32_to(b, reg, bi_byte(x, i))); |
| 520 |
|
| 521 |
CASE(bi_u32_to_f32_to(b, reg, bi_u8_to_u32(b, bi_byte(x, i))), |
| 522 |
bi_u8_to_f32_to(b, reg, bi_byte(x, i))); |
| 523 |
} |
| 524 |
} |
| 525 |
|
| 526 |
TEST_F(Optimizer, Int16ToFloat32) |
| 527 |
{ |
| 528 |
for (unsigned i = 0; i < 2; ++i) { |
| 529 |
CASE(bi_s32_to_f32_to(b, reg, bi_s16_to_s32(b, bi_half(x, i))), |
| 530 |
bi_s16_to_f32_to(b, reg, bi_half(x, i))); |
| 531 |
|
| 532 |
CASE(bi_s32_to_f32_to(b, reg, bi_u16_to_u32(b, bi_half(x, i))), |
| 533 |
bi_u16_to_f32_to(b, reg, bi_half(x, i))); |
| 534 |
|
| 535 |
CASE(bi_u32_to_f32_to(b, reg, bi_u16_to_u32(b, bi_half(x, i))), |
| 536 |
bi_u16_to_f32_to(b, reg, bi_half(x, i))); |
| 537 |
} |
| 538 |
} |