File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -734,15 +734,26 @@ impl Instance {
734734 } } ;
735735 }
736736 macro_rules! minmax {
737- ( $type: ident, $f: ident) => { {
737+ ( $type: ident, min) => { { minmax!( @impl $type, min, true ) } } ;
738+ ( $type: ident, max) => { { minmax!( @impl $type, max, false ) } } ;
739+ ( @impl $type: ident, $op: ident, $want_negative: literal) => { {
738740 paste! {
739741 let b = pop_val!( ) . [ <as_ $type>] ( ) ;
740742 let a = pop_val!( ) . [ <as_ $type>] ( ) ;
741- if a. is_nan( ) || b. is_nan( ) {
742- stack. push( WasmValue :: [ <from_ $type>] ( $type:: NAN ) ) ;
743+
744+ let result = if a. is_nan( ) {
745+ a
746+ } else if b. is_nan( ) {
747+ b
748+ } else if a == b && a == 0.0 {
749+ const SIGN_BIT_SHIFT : usize = std:: mem:: size_of:: <$type>( ) * 8 - 1 ;
750+ let a_has_sign = a. to_bits( ) >> SIGN_BIT_SHIFT != 0 ;
751+ if a_has_sign == $want_negative { a } else { b }
743752 } else {
744- stack. push( WasmValue :: [ <from_ $type>] ( $type:: $f( a, b) ) ) ;
745- }
753+ a. $op( b)
754+ } ;
755+
756+ stack. push( WasmValue :: [ <from_ $type>] ( result) ) ;
746757 }
747758 } } ;
748759 }
You can’t perform that action at this time.
0 commit comments