cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

AndreiB
Journeyman III

Incorrect results for integer shifts

Following IL code is supposed to calculate ( 0xabfd3082 << 5 ) which is 0x7fa61040.

But it gives slightly different result -- 0x7fe61040. There's only one-bit difference but it makes huge difference for me.

Is this some bug in CAL or am I missing something?

Thanks in advance.



il_ps_2_0
dcl_input vObjIndex0

dcl_literal l0, 0xabfd3082, 0xabfd3082, 0xabfd3082, 0xabfd3082
dcl_literal l1, 0x00000005, 0x00000005, 0x00000005, 0x00000005

mov r0, vObjIndex0.xxxx

ishl r1, l0, l1

iadd r0, r0, r0
iadd r0, r0, r0

mov g[r0.x + 0], r1
mov g[r0.x + 1], r1
mov g[r0.x + 2], r1
mov g[r0.x + 3], r1

ret_dyn
end
0 Likes
6 Replies

Andrei,
If you look at the disassembly of your shader, you see that the compiler does the shift instead of allowing the hardware to do this. It seems that the compiler is using a singed integer shift instead of an unsigned integer for the shifts. I'll report this and hopefully get it fixed before the next release. A workaround is to use the constant buffer to pass in the shift value so that the compiler doesn't try to optimize the instruction out.

i.e.
il_ps_2_0
dcl_input vObjIndex0
dcl_cb cb0[1]
dcl_literal l0, 0xabfd3082, 0xabfd3082, 0xabfd3082, 0xabfd3082
mov r0, vObjIndex0.xxxx
ishl r1, l0, cb0[0].x // x is equal to 5
iadd r0, r0, r0
iadd r0, r0, r0
mov g[r0.x + 0], r1
mov g[r0.x + 1], r1
mov g[r0.x + 2], r1
mov g[r0.x + 3], r1
ret_dyn
end
0 Likes

Ok, thanks for quick reply.

UPD: Is it possible to use dcl_immed_cb?
If so, can you give usage example? Can't figure out its format and compiler is crashing
0 Likes

After further analysis and talking to one of the compiler engineers it isn't because of the shift and is another problem. Thanks for bringing this to our attention.
0 Likes

AndreiB,
dcl_immed_cb was an old constant format that was used but was deprecated long ago for CAL. It wasn't until recently that we focused on updating the documentation and removed it. Sorry for the problems. The current constant format is to use dcl_cb or dcl_literal.
0 Likes

Micah, thanks for clarifying this.
0 Likes

What's status of this compiler issue? Has it been resolved in 1.2 release?
0 Likes