@@ -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
}
@@ -1765,24 +1790,24 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
1765
1790
simple_op ! { frem_algebraic, float: f_rem} // algebraic=normal
1766
1791
simple_shift_op ! {
1767
1792
shl,
1768
- int: shift_left_logical
1769
- // fold_const {
1770
- // int(a, b) => a.wrapping_shl(b as u32);
1771
- // }
1793
+ int: shift_left_logical,
1794
+ fold_const {
1795
+ int( a, b) => a. wrapping_shl( b as u32 ) ;
1796
+ }
1772
1797
}
1773
1798
simple_shift_op ! {
1774
1799
lshr,
1775
- int : shift_right_logical
1776
- // fold_const {
1777
- // int (a, b) => a.wrapping_shr(b as u32);
1778
- // }
1800
+ uint : shift_right_logical,
1801
+ fold_const {
1802
+ uint ( a, b) => a. wrapping_shr( b as u32 ) ;
1803
+ }
1779
1804
}
1780
1805
simple_shift_op ! {
1781
1806
ashr,
1782
- int : shift_right_arithmetic
1783
- // fold_const {
1784
- // int (a, b) => a.wrapping_shr(b as u32);
1785
- // }
1807
+ sint : shift_right_arithmetic,
1808
+ fold_const {
1809
+ sint ( a, b) => a. wrapping_shr( b as u32 ) ;
1810
+ }
1786
1811
}
1787
1812
simple_uni_op ! {
1788
1813
neg,
0 commit comments