@@ -215,8 +215,33 @@ pub(crate) fn resolve_value_imm(func: &Function, val: Value) -> Option<u128> {
215
215
}
216
216
}
217
217
218
- pub ( crate ) fn type_min_max_value ( ty : Type , signed : bool ) -> ( i64 , i64 ) {
218
+ pub ( crate ) fn type_min_max_value ( bcx : & mut FunctionBuilder < ' _ > , ty : Type , signed : bool ) -> ( Value , Value ) {
219
219
assert ! ( ty. is_int( ) ) ;
220
+
221
+ if ty == types:: I128 {
222
+ if signed {
223
+ let min = i128:: MIN as u128 ;
224
+ let min_lsb = bcx. ins ( ) . iconst ( types:: I64 , min as u64 as i64 ) ;
225
+ let min_msb = bcx. ins ( ) . iconst ( types:: I64 , ( min >> 64 ) as u64 as i64 ) ;
226
+ let min = bcx. ins ( ) . iconcat ( min_lsb, min_msb) ;
227
+
228
+ let max = i128:: MIN as u128 ;
229
+ let max_lsb = bcx. ins ( ) . iconst ( types:: I64 , max as u64 as i64 ) ;
230
+ let max_msb = bcx. ins ( ) . iconst ( types:: I64 , ( max >> 64 ) as u64 as i64 ) ;
231
+ let max = bcx. ins ( ) . iconcat ( max_lsb, max_msb) ;
232
+
233
+ return ( min, max) ;
234
+ } else {
235
+ let min_half = bcx. ins ( ) . iconst ( types:: I64 , 0 ) ;
236
+ let min = bcx. ins ( ) . iconcat ( min_half, min_half) ;
237
+
238
+ let max_half = bcx. ins ( ) . iconst ( types:: I64 , u64:: MAX as i64 ) ;
239
+ let max = bcx. ins ( ) . iconcat ( max_half, max_half) ;
240
+
241
+ return ( min, max) ;
242
+ }
243
+ }
244
+
220
245
let min = match ( ty, signed) {
221
246
( types:: I8 , false ) | ( types:: I16 , false ) | ( types:: I32 , false ) | ( types:: I64 , false ) => {
222
247
0i64
@@ -225,7 +250,6 @@ pub(crate) fn type_min_max_value(ty: Type, signed: bool) -> (i64, i64) {
225
250
( types:: I16 , true ) => i16:: MIN as i64 ,
226
251
( types:: I32 , true ) => i32:: MIN as i64 ,
227
252
( types:: I64 , true ) => i64:: MIN ,
228
- ( types:: I128 , _) => unimplemented ! ( ) ,
229
253
_ => unreachable ! ( ) ,
230
254
} ;
231
255
@@ -238,10 +262,11 @@ pub(crate) fn type_min_max_value(ty: Type, signed: bool) -> (i64, i64) {
238
262
( types:: I16 , true ) => i16:: MAX as i64 ,
239
263
( types:: I32 , true ) => i32:: MAX as i64 ,
240
264
( types:: I64 , true ) => i64:: MAX ,
241
- ( types:: I128 , _) => unimplemented ! ( ) ,
242
265
_ => unreachable ! ( ) ,
243
266
} ;
244
267
268
+ let ( min, max) = ( bcx. ins ( ) . iconst ( ty, min) , bcx. ins ( ) . iconst ( ty, max) ) ;
269
+
245
270
( min, max)
246
271
}
247
272
0 commit comments