@@ -143,10 +143,13 @@ macro_rules! simple_op {
143
143
macro_rules! simple_shift_op {
144
144
(
145
145
$func_name: ident
146
- , int: $inst_name: ident
146
+ $( , int: $inst_int: ident) ?
147
+ $( , uint: $inst_uint: ident) ?
148
+ $( , sint: $inst_sint: ident) ?
147
149
$( , fold_const {
148
- $( shift_uint( $shift_uint_lhs: ident, $shift_uint_rhs: ident) => $fold_shift_uint: expr; ) ?
149
- $( shift_int( $shift_int_lhs: ident, $shift_int_rhs: ident) => $fold_shift_int: expr; ) ?
150
+ $( int( $int_lhs: ident, $int_rhs: ident) => $fold_int: expr; ) ?
151
+ $( uint( $uint_lhs: ident, $uint_rhs: ident) => $fold_uint: expr; ) ?
152
+ $( sint( $sint_lhs: ident, $sint_rhs: ident) => $fold_sint: expr; ) ?
150
153
} ) ?
151
154
) => {
152
155
fn $func_name( & mut self , lhs: Self :: Value , rhs: Self :: Value ) -> Self :: Value {
@@ -159,23 +162,45 @@ macro_rules! simple_shift_op {
159
162
#[ allow( unreachable_patterns) ]
160
163
match ( const_lhs, const_rhs) {
161
164
$(
162
- ( ConstValue :: Unsigned ( $shift_uint_lhs) , ConstValue :: Unsigned ( $shift_uint_rhs) ) => return self . const_uint_big( result_type, $fold_shift_uint) ,
163
- ( ConstValue :: Unsigned ( $shift_uint_lhs) , ConstValue :: Signed ( $shift_uint_rhs) ) => return self . const_uint_big( result_type, $fold_shift_uint) ,
165
+ ( ConstValue :: Unsigned ( $int_lhs) , ConstValue :: Unsigned ( $int_rhs) ) => return self . const_uint_big( result_type, $fold_int) ,
166
+ ( ConstValue :: Unsigned ( $int_lhs) , ConstValue :: Signed ( $int_rhs) ) => return self . const_uint_big( result_type, $fold_int) ,
167
+ ( ConstValue :: Signed ( $int_lhs) , ConstValue :: Unsigned ( $int_rhs) ) => return self . const_uint_big( result_type, $fold_int as u128 ) ,
168
+ ( ConstValue :: Signed ( $int_lhs) , ConstValue :: Signed ( $int_rhs) ) => return self . const_uint_big( result_type, $fold_int as u128 ) ,
169
+ ) ?
170
+ $(
171
+ ( ConstValue :: Unsigned ( $uint_lhs) , ConstValue :: Unsigned ( $uint_rhs) ) => return self . const_uint_big( result_type, $fold_uint) ,
172
+ ( ConstValue :: Unsigned ( $uint_lhs) , ConstValue :: Signed ( $uint_rhs) ) => return self . const_uint_big( result_type, $fold_uint) ,
164
173
) ?
165
174
$(
166
- ( ConstValue :: Signed ( $shift_int_lhs ) , ConstValue :: Unsigned ( $shift_uint_rhs ) ) => return self . const_uint_big( result_type, $fold_shift_int ) ,
167
- ( ConstValue :: Signed ( $shift_int_lhs ) , ConstValue :: Signed ( $shift_uint_rhs ) ) => return self . const_uint_big( result_type, $fold_shift_int ) ,
175
+ ( ConstValue :: Signed ( $sint_lhs ) , ConstValue :: Unsigned ( $sint_rhs ) ) => return self . const_uint_big( result_type, $fold_sint as u128 ) ,
176
+ ( ConstValue :: Signed ( $sint_lhs ) , ConstValue :: Signed ( $sint_rhs ) ) => return self . const_uint_big( result_type, $fold_sint as u128 ) ,
168
177
) ?
169
178
_ => ( ) ,
170
179
}
171
180
}
172
181
}
173
182
) ?
174
183
175
- self . emit( )
176
- . $inst_name( result_type, None , lhs. def( self ) , rhs. def( self ) )
177
- . unwrap( )
178
- . with_type( result_type)
184
+ match self . lookup_type( result_type) {
185
+ $( SpirvType :: Integer ( _, _) => {
186
+ self . emit( )
187
+ . $inst_int( result_type, None , lhs. def( self ) , rhs. def( self ) )
188
+ } ) ?
189
+ $( SpirvType :: Integer ( _, false ) => {
190
+ self . emit( )
191
+ . $inst_uint( result_type, None , lhs. def( self ) , rhs. def( self ) )
192
+ } ) ?
193
+ $( SpirvType :: Integer ( _, true ) => {
194
+ self . emit( )
195
+ . $inst_sint( result_type, None , lhs. def( self ) , rhs. def( self ) )
196
+ } ) ?
197
+ o => self . fatal( format!(
198
+ concat!( stringify!( $func_name) , "() not implemented for type {}" ) ,
199
+ o. debug( result_type, self )
200
+ ) ) ,
201
+ }
202
+ . unwrap( )
203
+ . with_type( result_type)
179
204
}
180
205
} ;
181
206
}
@@ -1600,24 +1625,24 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
1600
1625
simple_op ! { frem_algebraic, float: f_rem} // algebraic=normal
1601
1626
simple_shift_op ! {
1602
1627
shl,
1603
- int: shift_left_logical
1604
- // fold_const {
1605
- // int(a, b) => a.wrapping_shl(b as u32);
1606
- // }
1628
+ int: shift_left_logical,
1629
+ fold_const {
1630
+ int( a, b) => a. wrapping_shl( b as u32 ) ;
1631
+ }
1607
1632
}
1608
1633
simple_shift_op ! {
1609
1634
lshr,
1610
- int : shift_right_logical
1611
- // fold_const {
1612
- // int (a, b) => a.wrapping_shr(b as u32);
1613
- // }
1635
+ uint : shift_right_logical,
1636
+ fold_const {
1637
+ uint ( a, b) => a. wrapping_shr( b as u32 ) ;
1638
+ }
1614
1639
}
1615
1640
simple_shift_op ! {
1616
1641
ashr,
1617
- int : shift_right_arithmetic
1618
- // fold_const {
1619
- // int (a, b) => a.wrapping_shr(b as u32);
1620
- // }
1642
+ sint : shift_right_arithmetic,
1643
+ fold_const {
1644
+ sint ( a, b) => a. wrapping_shr( b as u32 ) ;
1645
+ }
1621
1646
}
1622
1647
simple_uni_op ! {
1623
1648
neg,
0 commit comments