From c1181f65198ae081912f93e546ef23dbcdb2dc51 Mon Sep 17 00:00:00 2001 From: Jason Gross Date: Fri, 14 Oct 2016 13:13:09 -0400 Subject: Fix exponential blowup in some doubling ops Thanks @andres-erbsen ! --- src/BoundedArithmetic/Double/Core.v | 71 ++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 25 deletions(-) (limited to 'src/BoundedArithmetic') diff --git a/src/BoundedArithmetic/Double/Core.v b/src/BoundedArithmetic/Double/Core.v index 94d18673c..445fef971 100644 --- a/src/BoundedArithmetic/Double/Core.v +++ b/src/BoundedArithmetic/Double/Core.v @@ -65,7 +65,11 @@ Section tuple2. {selc : select_conditional W}. Definition select_conditional_double (b : bool) (x : tuple W 2) (y : tuple W 2) : tuple W 2 - := (selc b (fst x) (fst y), selc b (snd x) (snd y)). + := dlet x := x in + dlet y := y in + let (x1, x2) := eta x in + let (y1, y2) := eta y in + (selc b x1 x1, selc b x2 y2). Global Instance selc_double : select_conditional (tuple W 2) := { selc := select_conditional_double }. @@ -89,7 +93,11 @@ Section tuple2. {or : bitwise_or W}. Definition bitwise_or_double (x : tuple W 2) (y : tuple W 2) : tuple W 2 - := (or (fst x) (fst y), or (snd x) (snd y)). + := dlet x := x in + dlet y := y in + let (x1, x2) := eta x in + let (y1, y2) := eta y in + (or x1 x1, or x2 y2). Global Instance or_double : bitwise_or (tuple W 2) := { or := bitwise_or_double }. @@ -100,7 +108,11 @@ Section tuple2. {and : bitwise_and W}. Definition bitwise_and_double (x : tuple W 2) (y : tuple W 2) : tuple W 2 - := (and (fst x) (fst y), and (snd x) (snd y)). + := dlet x := x in + dlet y := y in + let (x1, x2) := eta x in + let (y1, y2) := eta y in + (and x1 x1, and x2 y2). Global Instance and_double : bitwise_and (tuple W 2) := { and := bitwise_and_double }. @@ -113,7 +125,8 @@ Section tuple2. {shr : shift_right_immediate W}. Definition spread_left_from_shift (r : W) (count : Z) : tuple W 2 - := (shl r count, if count =? 0 then ldi 0 else shr r (n - count)). + := dlet r := r in + (shl r count, if count =? 0 then ldi 0 else shr r (n - count)). (** Require a [decoder] instance to aid typeclass search in resolving [n] *) @@ -129,27 +142,31 @@ Section tuple2. {or : bitwise_or W}. Definition shift_left_immediate_double (r : tuple W 2) (count : Z) : tuple W 2 - := (if count =? 0 - then fst r + := dlet r := r in + let (r1, r2) := eta r in + (if count =? 0 + then r1 else if count