@@ -781,7 +781,7 @@ Expr halide_log(const Expr &x_full) {
781
781
782
782
Expr use_nan = x_full < 0 .0f ; // log of a negative returns nan
783
783
Expr use_neg_inf = x_full == 0 .0f ; // log of zero is -inf
784
- Expr exceptional = use_nan | use_neg_inf;
784
+ Expr exceptional = use_nan || use_neg_inf;
785
785
786
786
// Avoid producing nans or infs by generating ln(1.0f) instead and
787
787
// then fixing it later.
@@ -2419,54 +2419,81 @@ Expr reinterpret(Type t, Expr e) {
2419
2419
Expr operator &(Expr x, Expr y) {
2420
2420
match_types_bitwise (x, y, " bitwise and" );
2421
2421
Type t = x.type ();
2422
+ if (t.is_bool ()) {
2423
+ return std::move (x) && std::move (y);
2424
+ }
2422
2425
return Call::make (t, Call::bitwise_and, {std::move (x), std::move (y)}, Call::PureIntrinsic);
2423
2426
}
2424
2427
2425
2428
Expr operator &(Expr x, int y) {
2426
2429
Type t = x.type ();
2427
2430
check_representable (t, y);
2431
+ if (t.is_bool ()) {
2432
+ return std::move (x) && make_const (t, y);
2433
+ }
2428
2434
return Call::make (t, Call::bitwise_and, {std::move (x), make_const (t, y)}, Call::PureIntrinsic);
2429
2435
}
2430
2436
2431
2437
Expr operator &(int x, Expr y) {
2432
2438
Type t = y.type ();
2433
2439
check_representable (t, x);
2440
+ if (t.is_bool ()) {
2441
+ return make_const (t, x) && std::move (y);
2442
+ }
2434
2443
return Call::make (t, Call::bitwise_and, {make_const (t, x), std::move (y)}, Call::PureIntrinsic);
2435
2444
}
2436
2445
2437
2446
Expr operator |(Expr x, Expr y) {
2438
2447
match_types_bitwise (x, y, " bitwise or" );
2439
2448
Type t = x.type ();
2449
+ if (t.is_bool ()) {
2450
+ return std::move (x) || std::move (y);
2451
+ }
2440
2452
return Call::make (t, Call::bitwise_or, {std::move (x), std::move (y)}, Call::PureIntrinsic);
2441
2453
}
2442
2454
2443
2455
Expr operator |(Expr x, int y) {
2444
2456
Type t = x.type ();
2445
2457
check_representable (t, y);
2458
+ if (t.is_bool ()) {
2459
+ return std::move (x) || make_const (t, y);
2460
+ }
2446
2461
return Call::make (t, Call::bitwise_or, {std::move (x), make_const (t, y)}, Call::PureIntrinsic);
2447
2462
}
2448
2463
2449
2464
Expr operator |(int x, Expr y) {
2450
2465
Type t = y.type ();
2451
2466
check_representable (t, x);
2467
+ if (t.is_bool ()) {
2468
+ return make_const (t, x) || std::move (y);
2469
+ }
2452
2470
return Call::make (t, Call::bitwise_or, {make_const (t, x), std::move (y)}, Call::PureIntrinsic);
2453
2471
}
2454
2472
2455
2473
Expr operator ^(Expr x, Expr y) {
2456
2474
match_types_bitwise (x, y, " bitwise xor" );
2457
2475
Type t = x.type ();
2476
+ if (t.is_bool ()) {
2477
+ return std::move (x) != std::move (y);
2478
+ }
2458
2479
return Call::make (t, Call::bitwise_xor, {std::move (x), std::move (y)}, Call::PureIntrinsic);
2459
2480
}
2460
2481
2461
2482
Expr operator ^(Expr x, int y) {
2462
2483
Type t = x.type ();
2463
2484
check_representable (t, y);
2485
+ if (t.is_bool ()) {
2486
+ return std::move (x) != make_const (t, y);
2487
+ }
2464
2488
return Call::make (t, Call::bitwise_xor, {std::move (x), make_const (t, y)}, Call::PureIntrinsic);
2465
2489
}
2466
2490
2467
2491
Expr operator ^(int x, Expr y) {
2468
2492
Type t = y.type ();
2469
2493
check_representable (t, x);
2494
+ if (t.is_bool ()) {
2495
+ return make_const (t, x) != std::move (y);
2496
+ }
2470
2497
return Call::make (t, Call::bitwise_xor, {make_const (t, x), std::move (y)}, Call::PureIntrinsic);
2471
2498
}
2472
2499
0 commit comments