public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgcc/61662] New: Incorrect value calculated for _lrotl on LLP64 systems
@ 2014-07-01 7:06 gccbugzilla at limegreensocks dot com
2014-07-01 22:43 ` [Bug target/61662] " hjl.tools at gmail dot com
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: gccbugzilla at limegreensocks dot com @ 2014-07-01 7:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61662
Bug ID: 61662
Summary: Incorrect value calculated for _lrotl on LLP64 systems
Product: gcc
Version: 4.10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libgcc
Assignee: unassigned at gcc dot gnu.org
Reporter: gccbugzilla at limegreensocks dot com
Created attachment 33037
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33037&action=edit
Proposed patch
There is a problem in ia32intrin.h. Extracting bits of the code to highlight
the problem, we get:
#ifdef __x86_64__
#define _lrotl(a,b) __rolq((a), (b)) // rotate left qword
#else
#define _lrotl(a,b) __rold((a), (b)) // rotate left dword
#endif
This works correctly for linux, since on linux, longs use 8 bytes on 64bit and
4 bytes on 32bit (aka LP64). However, in native Windows, longs are 4 bytes for
both (aka LLP64).
So on 64bit Windows, 4 byte longs get promoted to a qword, bits get rotated
into the upper bytes, then get truncated when cast back into a 4 byte long.
Oops.
The problem here is that using "#ifdef __x86_64__" to determine the size of a
long does not reliably yield the correct result.
While gcc provides a define named __SIZEOF_LONG__, it doesn't seem like this is
used very often outside of the testsuite. Therefore the proposed patch
(attached) uses the __LP64__ define.
Testcase:
printf("sizeof(long): %d sizeof(ptr): %d "
"_lrotl(0x80000000,1): 0x%lx _lrotr(1,1): 0x%lx\n",
sizeof(long), sizeof(void *), _lrotl(0x80000000, 1), _lrotr(1,1));
64bit Windows yields:
sizeof(long): 4 sizeof(ptr): 8 _lrotl(0x80000000,1): 0x0 _lrotr(1,1): 0x0
Applying the patch yields:
sizeof(long): 4 sizeof(ptr): 8 _lrotl(0x80000000,1): 0x1 _lrotr(1,1):
0x80000000
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/61662] Incorrect value calculated for _lrotl on LLP64 systems
2014-07-01 7:06 [Bug libgcc/61662] New: Incorrect value calculated for _lrotl on LLP64 systems gccbugzilla at limegreensocks dot com
@ 2014-07-01 22:43 ` hjl.tools at gmail dot com
2014-07-15 17:14 ` gccbugzilla at limegreensocks dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: hjl.tools at gmail dot com @ 2014-07-01 22:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61662
H.J. Lu <hjl.tools at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2014-07-01
CC| |hjl.tools at gmail dot com
Component|libgcc |target
Ever confirmed|0 |1
--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> ---
Please send the patch to the gcc-patches mailing list. Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/61662] Incorrect value calculated for _lrotl on LLP64 systems
2014-07-01 7:06 [Bug libgcc/61662] New: Incorrect value calculated for _lrotl on LLP64 systems gccbugzilla at limegreensocks dot com
2014-07-01 22:43 ` [Bug target/61662] " hjl.tools at gmail dot com
@ 2014-07-15 17:14 ` gccbugzilla at limegreensocks dot com
2014-07-16 22:02 ` gerald at gcc dot gnu.org
2014-07-16 22:03 ` gerald at pfeifer dot com
3 siblings, 0 replies; 5+ messages in thread
From: gccbugzilla at limegreensocks dot com @ 2014-07-15 17:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61662
--- Comment #2 from David <gccbugzilla at limegreensocks dot com> ---
Sent July 9, 2014: https://gcc.gnu.org/ml/gcc-patches/2014-07/msg00604.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/61662] Incorrect value calculated for _lrotl on LLP64 systems
2014-07-01 7:06 [Bug libgcc/61662] New: Incorrect value calculated for _lrotl on LLP64 systems gccbugzilla at limegreensocks dot com
2014-07-01 22:43 ` [Bug target/61662] " hjl.tools at gmail dot com
2014-07-15 17:14 ` gccbugzilla at limegreensocks dot com
@ 2014-07-16 22:02 ` gerald at gcc dot gnu.org
2014-07-16 22:03 ` gerald at pfeifer dot com
3 siblings, 0 replies; 5+ messages in thread
From: gerald at gcc dot gnu.org @ 2014-07-16 22:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61662
--- Comment #3 from gerald at gcc dot gnu.org <gerald at gcc dot gnu.org> ---
Author: gerald
Date: Wed Jul 16 22:01:41 2014
New Revision: 212699
URL: https://gcc.gnu.org/viewcvs?rev=212699&root=gcc&view=rev
Log:
PR target/61662
* config/i386/ia32intrin.h: Use __LP64__ to determine size of long.
Modified:
trunk/gcc/ChangeLog
trunk/gcc/config/i386/ia32intrin.h
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/61662] Incorrect value calculated for _lrotl on LLP64 systems
2014-07-01 7:06 [Bug libgcc/61662] New: Incorrect value calculated for _lrotl on LLP64 systems gccbugzilla at limegreensocks dot com
` (2 preceding siblings ...)
2014-07-16 22:02 ` gerald at gcc dot gnu.org
@ 2014-07-16 22:03 ` gerald at pfeifer dot com
3 siblings, 0 replies; 5+ messages in thread
From: gerald at pfeifer dot com @ 2014-07-16 22:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61662
Gerald Pfeifer <gerald at pfeifer dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |gerald at pfeifer dot com
Resolution|--- |FIXED
--- Comment #4 from Gerald Pfeifer <gerald at pfeifer dot com> ---
I committed a minor variation (no code changes) of this patch.
Thanks, David!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-07-16 22:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-01 7:06 [Bug libgcc/61662] New: Incorrect value calculated for _lrotl on LLP64 systems gccbugzilla at limegreensocks dot com
2014-07-01 22:43 ` [Bug target/61662] " hjl.tools at gmail dot com
2014-07-15 17:14 ` gccbugzilla at limegreensocks dot com
2014-07-16 22:02 ` gerald at gcc dot gnu.org
2014-07-16 22:03 ` gerald at pfeifer dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).