[Bug c/35213] 1 << -1 inconsistent across platforms
wtc at google dot com
gcc-bugzilla@gcc.gnu.org
Fri Feb 15 21:09:00 GMT 2008
------- Comment #2 from wtc at google dot com 2008-02-15 21:08 -------
We're just asking for consistent behavior across platforms. It would be
nice if our broken code fails in the same way. If it would take a lot of work
to get consistency, we don't want you to waste that time.
On PowerPC, the code generated for x << -i is x << (32-i). For example, here
is the diffs of a simple function that returns x << 10 or x << -10:
--- foo.s.10 2008-02-15 21:00:43.000000000 -0700
+++ foo.s.-10 2008-02-15 21:01:04.000000000 -0700
@@ -1,12 +1,12 @@
.file "foo.c"
.section ".text"
.align 2
.p2align 4,,15
.globl foo
.type foo, @function
foo:
- slwi 3,3,10
+ slwi 3,3,22
blr
.size foo,.-foo
.ident "GCC: (GNU) 4.1.1 20060525 (Yellow Dog 4.1.1-1)"
.section .note.GNU-stack,"",@progbits
On x86, the diffs in the generated code is:
--- foo.s.10 2008-02-15 13:02:19.893547000 -0800
+++ foo.s.-10 2008-02-15 13:02:31.821331000 -0800
@@ -1,14 +1,15 @@
.file "foo.c"
.text
.globl foo
.type foo, @function
foo:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
- sall $10, %eax
+ movl $-10, %ecx
+ sall %cl, %eax
popl %ebp
ret
.size foo, .-foo
.ident "GCC: (GNU) 4.0.3 (Ubuntu 4.0.3-1ubuntu5)"
.section .note.GNU-stack,"",@progbits
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35213
More information about the Gcc-bugs
mailing list