[BR 2887108]: Use overflow_ helper to catch inapropriate imm optimization

View: New views
3 Messages — Rating Filter:   Alert me  

[BR 2887108]: Use overflow_ helper to catch inapropriate imm optimization

by Cyrill Gorcunov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Before any further action I would like to get some comments
on this patch. Hmm?

We have a number of is_sbyte16/32 calls which have the same issue
I suppose.

        -- Cyrill
---
From: Cyrill Gorcunov <gorcunov@...>
Date: Sat, 31 Oct 2009 01:12:50 +0300
Subject: [PATCH] [BR 2887108]: Use overflow_ helper to catch inapropriate imm optimization

Use proper method to find minimal size of storage for
immediate operand (and as result -- to find respective
instruction template): we should use overflow_ helpers
before smaller storage unit tests since we may
loose high bits.

The bug example is assembling the following instruction:

        imul eax,eax,0x10000

immediate operand will be "optimized" up to imm8
which is wrong since it must be imm32.

The bug is triggered with optimization specified at
command line only (-Ox).

Signed-off-by: Cyrill Gorcunov <gorcunov@...>
---
 parser.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/parser.c b/parser.c
index d0d660b..3fabcee 100644
--- a/parser.c
+++ b/parser.c
@@ -855,11 +855,10 @@ restart_parse:
                 result->oprs[operand].segment = NO_SEG; /* don't care again */
                 result->oprs[operand].wrt = NO_SEG;     /* still don't care */
 
+                /* Be optimistic */
                 if(optimizing >= 0 && !(result->oprs[operand].type & STRICT))
-                {
-                    /* Be optimistic */
                     result->oprs[operand].type |= SBYTE16 | SBYTE32 | SBYTE64;
-                }
+
             } else if (is_reloc(value)) {       /* it's immediate */
                 result->oprs[operand].type |= IMMEDIATE;
                 result->oprs[operand].offset = reloc_value(value);
@@ -876,10 +875,12 @@ restart_parse:
 
  if (v64 >= -128 && v64 <= 127)
                             result->oprs[operand].type |= SBYTE64;
- if (v32 >= -128 && v32 <= 127)
-                            result->oprs[operand].type |= SBYTE32;
- if (v16 >= -128 && v16 <= 127)
-                            result->oprs[operand].type |= SBYTE16;
+ if (!overflow_signed(v64, sizeof(v32)))
+ if (v32 >= -128 && v32 <= 127)
+                             result->oprs[operand].type |= SBYTE32;
+ if (!overflow_signed(v64, sizeof(v16)))
+ if (v16 >= -128 && v16 <= 127)
+                             result->oprs[operand].type |= SBYTE16;
                     }
                 }
             } else {            /* it's a register */
--
1.6.5


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Nasm-devel mailing list
Nasm-devel@...
https://lists.sourceforge.net/lists/listinfo/nasm-devel

Re: [BR 2887108]: Use overflow_ helper to catch inapropriate imm optimization

by Cyrill Gorcunov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

[Cyrill Gorcunov - Sat, Oct 31, 2009 at 01:29:14AM +0300]
| Before any further action I would like to get some comments
| on this patch. Hmm?
|
| We have a number of is_sbyte16/32 calls which have the same issue
| I suppose.
|
| -- Cyrill
...

Just pushed it out into main repo.

        -- Cyrill

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Nasm-devel mailing list
Nasm-devel@...
https://lists.sourceforge.net/lists/listinfo/nasm-devel

Re: [BR 2887108]: Use overflow_ helper to catch inapropriate imm optimization

by H. Peter Anvin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 10/31/2009 07:29 AM, Cyrill Gorcunov wrote:
> Before any further action I would like to get some comments
> on this patch. Hmm?
>
> We have a number of is_sbyte16/32 calls which have the same issue
> I suppose.
>

 > The bug example is assembling the following instruction:
 >
 > imul eax,eax,0x10000

0x10000 should be SBYTE16, but not SBYTE32, so it getting promoted to an
sbyte is an indication of an invalid instruction pattern.

        -hpa

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Nasm-devel mailing list
Nasm-devel@...
https://lists.sourceforge.net/lists/listinfo/nasm-devel