@@ -140,10 +140,13 @@ macro_rules! simple_op {
140
140
macro_rules! simple_shift_op {
141
141
(
142
142
$func_name: ident
143
- , int: $inst_name: ident
143
+ $( , int: $inst_int: ident) ?
144
+ $( , uint: $inst_uint: ident) ?
145
+ $( , sint: $inst_sint: ident) ?
144
146
$( , fold_const {
145
- $( shift_uint( $shift_uint_lhs: ident, $shift_uint_rhs: ident) => $fold_shift_uint: expr; ) ?
146
- $( shift_int( $shift_int_lhs: ident, $shift_int_rhs: ident) => $fold_shift_int: expr; ) ?
147
+ $( int( $int_lhs: ident, $int_rhs: ident) => $fold_int: expr; ) ?
148
+ $( uint( $uint_lhs: ident, $uint_rhs: ident) => $fold_uint: expr; ) ?
149
+ $( sint( $sint_lhs: ident, $sint_rhs: ident) => $fold_sint: expr; ) ?
147
150
} ) ?
148
151
) => {
149
152
fn $func_name( & mut self , lhs: Self :: Value , rhs: Self :: Value ) -> Self :: Value {
@@ -154,22 +157,44 @@ macro_rules! simple_shift_op {
154
157
#[ allow( unreachable_patterns) ]
155
158
match ( const_lhs, const_rhs) {
156
159
$(
157
- ( ConstValue :: Unsigned ( $shift_uint_lhs) , ConstValue :: Unsigned ( $shift_uint_rhs) ) => return self . const_uint_big( result_type, $fold_shift_uint) ,
158
- ( ConstValue :: Unsigned ( $shift_uint_lhs) , ConstValue :: Signed ( $shift_uint_rhs) ) => return self . const_uint_big( result_type, $fold_shift_uint) ,
160
+ ( ConstValue :: Unsigned ( $int_lhs) , ConstValue :: Unsigned ( $int_rhs) ) => return self . const_uint_big( result_type, $fold_int) ,
161
+ ( ConstValue :: Unsigned ( $int_lhs) , ConstValue :: Signed ( $int_rhs) ) => return self . const_uint_big( result_type, $fold_int) ,
162
+ ( ConstValue :: Signed ( $int_lhs) , ConstValue :: Unsigned ( $int_rhs) ) => return self . const_uint_big( result_type, $fold_int as u128 ) ,
163
+ ( ConstValue :: Signed ( $int_lhs) , ConstValue :: Signed ( $int_rhs) ) => return self . const_uint_big( result_type, $fold_int as u128 ) ,
164
+ ) ?
165
+ $(
166
+ ( ConstValue :: Unsigned ( $uint_lhs) , ConstValue :: Unsigned ( $uint_rhs) ) => return self . const_uint_big( result_type, $fold_uint) ,
167
+ ( ConstValue :: Unsigned ( $uint_lhs) , ConstValue :: Signed ( $uint_rhs) ) => return self . const_uint_big( result_type, $fold_uint) ,
159
168
) ?
160
169
$(
161
- ( ConstValue :: Signed ( $shift_int_lhs ) , ConstValue :: Unsigned ( $shift_uint_rhs ) ) => return self . const_uint_big( result_type, $fold_shift_int ) ,
162
- ( ConstValue :: Signed ( $shift_int_lhs ) , ConstValue :: Signed ( $shift_uint_rhs ) ) => return self . const_uint_big( result_type, $fold_shift_int ) ,
170
+ ( ConstValue :: Signed ( $sint_lhs ) , ConstValue :: Unsigned ( $sint_rhs ) ) => return self . const_uint_big( result_type, $fold_sint as u128 ) ,
171
+ ( ConstValue :: Signed ( $sint_lhs ) , ConstValue :: Signed ( $sint_rhs ) ) => return self . const_uint_big( result_type, $fold_sint as u128 ) ,
163
172
) ?
164
173
_ => ( ) ,
165
174
}
166
175
}
167
176
} ) ?
168
177
169
- self . emit( )
170
- . $inst_name( result_type, None , lhs. def( self ) , rhs. def( self ) )
171
- . unwrap( )
172
- . with_type( result_type)
178
+ match self . lookup_type( result_type) {
179
+ $( SpirvType :: Integer ( _, _) => {
180
+ self . emit( )
181
+ . $inst_int( result_type, None , lhs. def( self ) , rhs. def( self ) )
182
+ } ) ?
183
+ $( SpirvType :: Integer ( _, false ) => {
184
+ self . emit( )
185
+ . $inst_uint( result_type, None , lhs. def( self ) , rhs. def( self ) )
186
+ } ) ?
187
+ $( SpirvType :: Integer ( _, true ) => {
188
+ self . emit( )
189
+ . $inst_sint( result_type, None , lhs. def( self ) , rhs. def( self ) )
190
+ } ) ?
191
+ o => self . fatal( format!(
192
+ concat!( stringify!( $func_name) , "() not implemented for type {}" ) ,
193
+ o. debug( result_type, self )
194
+ ) ) ,
195
+ }
196
+ . unwrap( )
197
+ . with_type( result_type)
173
198
}
174
199
} ;
175
200
}
@@ -1759,24 +1784,24 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
1759
1784
simple_op ! { frem_algebraic, float: f_rem} // algebraic=normal
1760
1785
simple_shift_op ! {
1761
1786
shl,
1762
- int: shift_left_logical
1763
- // fold_const {
1764
- // int(a, b) => a.wrapping_shl(b as u32);
1765
- // }
1787
+ int: shift_left_logical,
1788
+ fold_const {
1789
+ int( a, b) => a. wrapping_shl( b as u32 ) ;
1790
+ }
1766
1791
}
1767
1792
simple_shift_op ! {
1768
1793
lshr,
1769
- int : shift_right_logical
1770
- // fold_const {
1771
- // int (a, b) => a.wrapping_shr(b as u32);
1772
- // }
1794
+ uint : shift_right_logical,
1795
+ fold_const {
1796
+ uint ( a, b) => a. wrapping_shr( b as u32 ) ;
1797
+ }
1773
1798
}
1774
1799
simple_shift_op ! {
1775
1800
ashr,
1776
- int : shift_right_arithmetic
1777
- // fold_const {
1778
- // int (a, b) => a.wrapping_shr(b as u32);
1779
- // }
1801
+ sint : shift_right_arithmetic,
1802
+ fold_const {
1803
+ sint ( a, b) => a. wrapping_shr( b as u32 ) ;
1804
+ }
1780
1805
}
1781
1806
simple_uni_op ! {
1782
1807
neg,
0 commit comments