@@ -5,6 +5,7 @@ use rustc_target::spec::abi::Abi;
5
5
6
6
use rand:: Rng as _;
7
7
8
+ use super :: FloatCmpOp ;
8
9
use crate :: * ;
9
10
use shims:: foreign_items:: EmulateByNameResult ;
10
11
@@ -100,22 +101,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
100
101
let [ left, right, imm] =
101
102
this. check_shim ( abi, Abi :: C { unwind : false } , link_name, args) ?;
102
103
103
- let which = match this. read_scalar ( imm) ?. to_i8 ( ) ? {
104
- 0 => FloatBinOp :: Cmp ( FloatCmpOp :: Eq ) ,
105
- 1 => FloatBinOp :: Cmp ( FloatCmpOp :: Lt ) ,
106
- 2 => FloatBinOp :: Cmp ( FloatCmpOp :: Le ) ,
107
- 3 => FloatBinOp :: Cmp ( FloatCmpOp :: Unord ) ,
108
- 4 => FloatBinOp :: Cmp ( FloatCmpOp :: Neq ) ,
109
- 5 => FloatBinOp :: Cmp ( FloatCmpOp :: Nlt ) ,
110
- 6 => FloatBinOp :: Cmp ( FloatCmpOp :: Nle ) ,
111
- 7 => FloatBinOp :: Cmp ( FloatCmpOp :: Ord ) ,
112
- imm => {
113
- throw_unsup_format ! (
114
- "invalid 3rd parameter of llvm.x86.sse.cmp.ps: {}" ,
115
- imm
116
- ) ;
117
- }
118
- } ;
104
+ let which = FloatBinOp :: Cmp ( FloatCmpOp :: from_intrinsic_imm (
105
+ this. read_scalar ( imm) ?. to_i8 ( ) ?,
106
+ "llvm.x86.sse.cmp.ss" ,
107
+ ) ?) ;
119
108
120
109
bin_op_ss ( this, which, left, right, dest) ?;
121
110
}
@@ -127,22 +116,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
127
116
let [ left, right, imm] =
128
117
this. check_shim ( abi, Abi :: C { unwind : false } , link_name, args) ?;
129
118
130
- let which = match this. read_scalar ( imm) ?. to_i8 ( ) ? {
131
- 0 => FloatBinOp :: Cmp ( FloatCmpOp :: Eq ) ,
132
- 1 => FloatBinOp :: Cmp ( FloatCmpOp :: Lt ) ,
133
- 2 => FloatBinOp :: Cmp ( FloatCmpOp :: Le ) ,
134
- 3 => FloatBinOp :: Cmp ( FloatCmpOp :: Unord ) ,
135
- 4 => FloatBinOp :: Cmp ( FloatCmpOp :: Neq ) ,
136
- 5 => FloatBinOp :: Cmp ( FloatCmpOp :: Nlt ) ,
137
- 6 => FloatBinOp :: Cmp ( FloatCmpOp :: Nle ) ,
138
- 7 => FloatBinOp :: Cmp ( FloatCmpOp :: Ord ) ,
139
- imm => {
140
- throw_unsup_format ! (
141
- "invalid 3rd parameter of llvm.x86.sse.cmp.ps: {}" ,
142
- imm
143
- ) ;
144
- }
145
- } ;
119
+ let which = FloatBinOp :: Cmp ( FloatCmpOp :: from_intrinsic_imm (
120
+ this. read_scalar ( imm) ?. to_i8 ( ) ?,
121
+ "llvm.x86.sse.cmp.ps" ,
122
+ ) ?) ;
146
123
147
124
bin_op_ps ( this, which, left, right, dest) ?;
148
125
}
@@ -292,6 +269,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
292
269
let op = this. read_scalar ( & this. project_index ( & op, i) ?) ?;
293
270
let op = op. to_u32 ( ) ?;
294
271
272
+ // Extract the highest bit of `op` and place it in the `i`-th bit of `res`
295
273
res |= ( op >> 31 ) << i;
296
274
}
297
275
@@ -303,25 +281,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
303
281
}
304
282
}
305
283
306
- /// Floating point comparison operation
307
- ///
308
- /// <https://www.felixcloutier.com/x86/cmpss>
309
- /// <https://www.felixcloutier.com/x86/cmpps>
310
- #[ derive( Copy , Clone ) ]
311
- enum FloatCmpOp {
312
- Eq ,
313
- Lt ,
314
- Le ,
315
- Unord ,
316
- Neq ,
317
- /// Not less-than
318
- Nlt ,
319
- /// Not less-or-equal
320
- Nle ,
321
- /// Ordered, i.e. neither of them is NaN
322
- Ord ,
323
- }
324
-
325
284
#[ derive( Copy , Clone ) ]
326
285
enum FloatBinOp {
327
286
/// Arithmetic operation
0 commit comments