@@ -3399,6 +3399,38 @@ impl<W: Write> Writer<W> {
3399
3399
Ok ( ( ) )
3400
3400
}
3401
3401
3402
+ /// Convert the arguments of `Dot4{I, U}Packed` to `packed_(u?)char4`.
3403
+ ///
3404
+ /// Caches the results in temprary variables (whose names are derived from
3405
+ /// the original variable names). This caching avoids the need to redo the
3406
+ /// casting for each vector component when emitting the dot product.
3407
+ fn put_casting_to_packed_chars (
3408
+ & mut self ,
3409
+ fun : crate :: MathFunction ,
3410
+ arg0 : Handle < crate :: Expression > ,
3411
+ arg1 : Handle < crate :: Expression > ,
3412
+ indent : back:: Level ,
3413
+ context : & StatementContext < ' _ > ,
3414
+ ) -> Result < ( ) , Error > {
3415
+ let packed_type = match fun {
3416
+ crate :: MathFunction :: Dot4I8Packed => "packed_char4" ,
3417
+ crate :: MathFunction :: Dot4U8Packed => "packed_uchar4" ,
3418
+ _ => unreachable ! ( ) ,
3419
+ } ;
3420
+
3421
+ for arg in [ arg0, arg1] {
3422
+ write ! (
3423
+ self . out,
3424
+ "{indent}{packed_type} {0} = as_type<{packed_type}>(" ,
3425
+ Reinterpreted :: new( packed_type, arg)
3426
+ ) ?;
3427
+ self . put_expression ( arg, & context. expression , true ) ?;
3428
+ writeln ! ( self . out, ");" ) ?;
3429
+ }
3430
+
3431
+ Ok ( ( ) )
3432
+ }
3433
+
3402
3434
fn put_block (
3403
3435
& mut self ,
3404
3436
level : back:: Level ,
@@ -3443,31 +3475,14 @@ impl<W: Write> Writer<W> {
3443
3475
arg,
3444
3476
arg1,
3445
3477
..
3446
- } => {
3447
- if context. expression . lang_version >= ( 2 , 1 ) {
3448
- let arg1 = arg1. unwrap ( ) ;
3449
- let packed_type = match fun {
3450
- Mf :: Dot4I8Packed => "packed_char4" ,
3451
- Mf :: Dot4U8Packed => "packed_uchar4" ,
3452
- _ => unreachable ! ( ) ,
3453
- } ;
3454
-
3455
- write ! (
3456
- self . out,
3457
- "{level}{packed_type} {0} = as_type<{packed_type}>(" ,
3458
- Reinterpreted :: new( packed_type, arg)
3459
- ) ?;
3460
- self . put_expression ( arg, & context. expression , true ) ?;
3461
- writeln ! ( self . out, ");" ) ?;
3462
-
3463
- write ! (
3464
- self . out,
3465
- "{level}{packed_type} {0} = as_type<{packed_type}>(" ,
3466
- Reinterpreted :: new( packed_type, arg1)
3467
- ) ?;
3468
- self . put_expression ( arg1, & context. expression , true ) ?;
3469
- writeln ! ( self . out, ");" ) ?;
3470
- }
3478
+ } if context. expression . lang_version >= ( 2 , 1 ) => {
3479
+ self . put_casting_to_packed_chars (
3480
+ fun,
3481
+ arg,
3482
+ arg1. unwrap ( ) ,
3483
+ level,
3484
+ context,
3485
+ ) ?;
3471
3486
}
3472
3487
3473
3488
_ => ( ) ,
0 commit comments