Patchwork [11/11] target-i386: use floatx80_log2() to implement helper_fyl2x*()

login
register
mail settings
Submitter Aurelien Jarno
Date May 15, 2011, 2:13 p.m.
Message ID <1305468801-6015-12-git-send-email-aurelien@aurel32.net>
Download mbox | patch
Permalink /patch/95618/
State New
Headers show

Comments

Aurelien Jarno - May 15, 2011, 2:13 p.m.
Use the new floatx80_log2() softfloat function to implement both
helper_fyl2x() and helper_fyl2xp1().

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
 target-i386/op_helper.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)
Richard Henderson - May 17, 2011, 3:41 p.m.
On 05/15/2011 07:13 AM, Aurelien Jarno wrote:
> +    temp = floatx80_add(ST0, floatx80_one, &env->fp_status);
> +    if (!floatx80_is_neg(temp)) {
> +        temp = floatx80_add(ST0, floatx80_one, &env->fp_status);
> +        temp = floatx80_log2(temp, &env->fp_status);
> +        ST1 = floatx80_mul(ST1, temp, &env->fp_status);

While this is probably better than the existing code, you really
should be using a different series expansion than for log2.  This
expansion will be wildly inaccurate for inputs near zero.


r~

Patch

diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c
index eccb957..b021a00 100644
--- a/target-i386/op_helper.c
+++ b/target-i386/op_helper.c
@@ -3972,12 +3972,11 @@  void helper_f2xm1(void)
 
 void helper_fyl2x(void)
 {
-    double fptemp = floatx80_to_double(ST0);
+    floatx80 temp;
 
-    if (fptemp>0.0){
-        fptemp = log(fptemp)/log(2.0);    /* log2(ST) */
-        fptemp *= floatx80_to_double(ST1);
-        ST1 = double_to_floatx80(fptemp);
+    if (! floatx80_is_neg(ST0)) {
+        temp = floatx80_log2(ST0, &env->fp_status);
+        ST1 = floatx80_mul(ST1, temp, &env->fp_status);
         fpop();
     } else {
         env->fpus &= (~0x4700);
@@ -4153,12 +4152,13 @@  void helper_fprem(void)
 
 void helper_fyl2xp1(void)
 {
-    double fptemp = floatx80_to_double(ST0);
+    floatx80 temp;
 
-    if ((fptemp+1.0)>0.0) {
-        fptemp = log(fptemp+1.0) / log(2.0); /* log2(ST+1.0) */
-        fptemp *= floatx80_to_double(ST1);
-        ST1 = double_to_floatx80(fptemp);
+    temp = floatx80_add(ST0, floatx80_one, &env->fp_status);
+    if (!floatx80_is_neg(temp)) {
+        temp = floatx80_add(ST0, floatx80_one, &env->fp_status);
+        temp = floatx80_log2(temp, &env->fp_status);
+        ST1 = floatx80_mul(ST1, temp, &env->fp_status);
         fpop();
     } else {
         env->fpus &= (~0x4700);