No, the uchar has to be promoted to uint before multiplication or shiftingxmas79 wrote:All the for loop stuff is usually folded away (in these simple cases) since you are accessing only the first element. The compiler then keeps onlyCode: Select all
... vector< PackedColor > hmap( 256 ); for ( int i=0; i<256; i++ ) { hmap[i].packed = 128*256; } int h = 256 * hmap[0].GetG(); // expect 32768 here but get 0 cout << "h=" << h << endl; return 0; }
which produces 0, because GetG() returns an uchar that will be shifted left by 8 bits, leaving you with 0 as result... as expected!Code: Select all
int h = 256 * hmap[0].GetG();
Intel compiler bug?
Moderators: hgm, Rebel, chrisw
-
- Posts: 741
- Joined: Tue May 22, 2007 11:13 am
Re: Intel compiler bug?
-
- Posts: 286
- Joined: Mon Jun 03, 2013 7:05 pm
- Location: Italy
Re: Intel compiler bug?
Code: Select all
movzx esi,byte ptr [esi]
and esi,0FFFFFF00h
EDIT:
thinking about it, where does esi points to? maybe it points directly to the right byte? But I still miss the and part...
-
- Posts: 286
- Joined: Mon Jun 03, 2013 7:05 pm
- Location: Italy
Re: Intel compiler bug?
This is what MSVC says about it:mar wrote:I don't want to prevent the bug, I want it gone!xmas79 wrote:Why don't you look at generated assembly? With 257 the compiler emits a multiply instruction. The 256 instead is probably optimized as left shift, and extra care could be needed (to prevent the compiler bug)?
Assembly:Anyway it fetches the first byte instead of second (x86 is little endian).Code: Select all
movzx esi,byte ptr [esi] and esi,0FFFFFF00h
Code: Select all
mov rdi,qword ptr [hmap]
...
movzx ebx,byte ptr [rdi+1]
shl ebx,8
-
- Posts: 2555
- Joined: Fri Nov 26, 2010 2:00 pm
- Location: Czech Republic
- Full name: Martin Sedlak
Re: Intel compiler bug?
esi points to the first element of the vector.xmas79 wrote:I see... But what is the "and" supposed to do? Can you post all the relevant assembly?
EDIT:
thinking about it, where does esi points to? maybe it points directly to the right byte? But I still miss the and part...
I think it indended this (unaligned is ok on x86):
Code: Select all
movzx esi,word ptr [esi]
and esi,0FFFFFF00h
Code: Select all
movzx esi, byte ptr [esi+1]
shl esi, 8
-
- Posts: 286
- Joined: Mon Jun 03, 2013 7:05 pm
- Location: Italy
Re: Intel compiler bug?
Yes, "now" they are equivalent... Filed the bug?mar wrote:...
I think it indended this (unaligned is ok on x86):But I'd probably prefer thisCode: Select all
movzx esi,word ptr [esi] and esi,0FFFFFF00h
...Code: Select all
movzx esi, byte ptr [esi+1] shl esi, 8
-
- Posts: 2555
- Joined: Fri Nov 26, 2010 2:00 pm
- Location: Czech Republic
- Full name: Martin Sedlak
Re: Intel compiler bug?
Yes, waiting for response, they wanted something reproducible so I sent the code above. But it's possible it's been already fixed in the latest version (which I don't have).xmas79 wrote:Yes, "now" they are equivalent... Filed the bug?
Still I find it really scary, imagine an important system compiled with icc and this bug triggering in some rare path not covered by tests...
-
- Posts: 286
- Joined: Mon Jun 03, 2013 7:05 pm
- Location: Italy
Re: Intel compiler bug?
Quite expensive.... $699 for a single developer "base" license...
-
- Posts: 2555
- Joined: Fri Nov 26, 2010 2:00 pm
- Location: Czech Republic
- Full name: Martin Sedlak
Re: Intel compiler bug?
Yes, considering it's buggyxmas79 wrote:Quite expensive.... $699 for a single developer "base" license...
-
- Posts: 154
- Joined: Thu Oct 03, 2013 4:17 pm
Re: Intel compiler bug?
Parallel Studio XE13 was free on Linux with a non-commercial license. Some day XE15 will be the same.
https://software.intel.com/en-us/non-co ... evelopment
https://software.intel.com/en-us/non-co ... evelopment
Functional programming combines the flexibility and power of abstract mathematics with the intuitive clarity of abstract mathematics.
https://github.com/mAarnos
https://github.com/mAarnos
-
- Posts: 2555
- Joined: Fri Nov 26, 2010 2:00 pm
- Location: Czech Republic
- Full name: Martin Sedlak
Re: Intel compiler bug?
The bug has been confirmed by Intel support and passed to engineering (reproducible in XE 15 as well).