@@ -294,6 +294,76 @@ impl Encode for Function {
294
294
}
295
295
}
296
296
297
+ /// An IEEE binary32 immediate floating point value, represented as a u32
298
+ /// containing the bit pattern.
299
+ ///
300
+ /// All bit patterns are allowed.
301
+ #[ derive( Copy , Clone , Debug , Eq , PartialEq , Hash ) ]
302
+ pub struct Ieee32 ( pub ( crate ) u32 ) ;
303
+
304
+ impl Ieee32 {
305
+ /// Gets the underlying bits of the 32-bit float.
306
+ pub fn bits ( self ) -> u32 {
307
+ self . 0
308
+ }
309
+ }
310
+
311
+ impl From < f32 > for Ieee32 {
312
+ fn from ( value : f32 ) -> Self {
313
+ Ieee32 {
314
+ 0 : u32:: from_le_bytes ( value. to_le_bytes ( ) ) ,
315
+ }
316
+ }
317
+ }
318
+
319
+ impl From < Ieee32 > for f32 {
320
+ fn from ( bits : Ieee32 ) -> f32 {
321
+ f32:: from_bits ( bits. bits ( ) )
322
+ }
323
+ }
324
+
325
+ impl Encode for Ieee32 {
326
+ fn encode ( & self , sink : & mut Vec < u8 > ) {
327
+ let bits = self . bits ( ) ;
328
+ sink. extend ( bits. to_le_bytes ( ) )
329
+ }
330
+ }
331
+
332
+ /// An IEEE binary64 immediate floating point value, represented as a u64
333
+ /// containing the bit pattern.
334
+ ///
335
+ /// All bit patterns are allowed.
336
+ #[ derive( Copy , Clone , Debug , Eq , PartialEq , Hash ) ]
337
+ pub struct Ieee64 ( pub ( crate ) u64 ) ;
338
+
339
+ impl Ieee64 {
340
+ /// Gets the underlying bits of the 64-bit float.
341
+ pub fn bits ( self ) -> u64 {
342
+ self . 0
343
+ }
344
+ }
345
+
346
+ impl From < f64 > for Ieee64 {
347
+ fn from ( value : f64 ) -> Self {
348
+ Ieee64 {
349
+ 0 : u64:: from_le_bytes ( value. to_le_bytes ( ) ) ,
350
+ }
351
+ }
352
+ }
353
+
354
+ impl From < Ieee64 > for f64 {
355
+ fn from ( bits : Ieee64 ) -> f64 {
356
+ f64:: from_bits ( bits. bits ( ) )
357
+ }
358
+ }
359
+
360
+ impl Encode for Ieee64 {
361
+ fn encode ( & self , sink : & mut Vec < u8 > ) {
362
+ let bits = self . bits ( ) ;
363
+ sink. extend ( bits. to_le_bytes ( ) )
364
+ }
365
+ }
366
+
297
367
/// The immediate for a memory instruction.
298
368
#[ derive( Clone , Copy , Debug ) ]
299
369
pub struct MemArg {
@@ -471,8 +541,8 @@ pub enum Instruction<'a> {
471
541
// Numeric instructions.
472
542
I32Const ( i32 ) ,
473
543
I64Const ( i64 ) ,
474
- F32Const ( f32 ) ,
475
- F64Const ( f64 ) ,
544
+ F32Const ( Ieee32 ) ,
545
+ F64Const ( Ieee64 ) ,
476
546
I32Eqz ,
477
547
I32Eq ,
478
548
I32Ne ,
@@ -2202,12 +2272,12 @@ impl ConstExpr {
2202
2272
}
2203
2273
2204
2274
/// Create a constant expression containing a single `f32.const` instruction.
2205
- pub fn f32_const ( value : f32 ) -> Self {
2275
+ pub fn f32_const ( value : Ieee32 ) -> Self {
2206
2276
Self :: new ( |insn| insn. f32_const ( value) )
2207
2277
}
2208
2278
2209
2279
/// Create a constant expression containing a single `f64.const` instruction.
2210
- pub fn f64_const ( value : f64 ) -> Self {
2280
+ pub fn f64_const ( value : Ieee64 ) -> Self {
2211
2281
Self :: new ( |insn| insn. f64_const ( value) )
2212
2282
}
2213
2283
@@ -2242,12 +2312,12 @@ impl ConstExpr {
2242
2312
}
2243
2313
2244
2314
/// Add a `f32.const` instruction to this constant expression.
2245
- pub fn with_f32_const ( self , value : f32 ) -> Self {
2315
+ pub fn with_f32_const ( self , value : Ieee32 ) -> Self {
2246
2316
self . with ( |insn| insn. f32_const ( value) )
2247
2317
}
2248
2318
2249
2319
/// Add a `f64.const` instruction to this constant expression.
2250
- pub fn with_f64_const ( self , value : f64 ) -> Self {
2320
+ pub fn with_f64_const ( self , value : Ieee64 ) -> Self {
2251
2321
self . with ( |insn| insn. f64_const ( value) )
2252
2322
}
2253
2323
0 commit comments