cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

realhet
Miniboss

Weird GCN nested loop bug

Hi!

Here's my code:

  @weirdbug:

  s_mov_b32 s60,0            //debug counter

  s_mov_b32 s70,10-1         //outer loop counter

  @mainloop0:

 

    s_add_i32 s60,s60,1      //increase debug counter

     

    s_mov_b32 s50,5          //inner loop counter

    @loop20:

      s_sub_u32 s50,s50,1    //dercease inner loop counter

    s_cbranch_scc0 @loop20   //!!!!!!!!!

 

    s_subb_u32 s70,s70,1     //decrease outer loop counter

  s_cbranch_scc0 @mainloop0

  uavWrite(0,grpid,s60)      //write debug counter to mem, (this works for sure)

The outer loop (s70) executed 10 times: (counter starts at 9, and loop stops when in underflows below zero)

Then there is a debug counter (s60) which is incremented every time when the outer loop executes, and I write it's value to the memory, to check after.

The inner loop (s50) is just an empty loop, and yet it causes the problem:

Normally it should report the value 10 in the debug counter, but with the inner loop it only counts to half of it: 5.

Methods to eliminate the bug:

a) commenting out the line marked with !!!!!!, that breaks the inner loop and the debug counter will report 10 as it should.

b) move the part "increase the debug counter" right after the inner loop below the line marked with !!!!!!!)

I don't understand why? Anyone can explain please? Maybe a GCN rule that I've forgot to apply?

(The most weird thing is that it works on 50% when it bugs. Not 0%. I could even make a an shr1 out of it without using s_lshr_b32. o.O)

Thank You!

0 Likes
1 Solution
kd2
Adept II

Is it a bug? That last subtraction is a s_subb with the double 'b'. That subtracts not only 1, but also the SCC=1 which was used to exit out of the inner loop.

View solution in original post

0 Likes
3 Replies
kd2
Adept II

Is it a bug? That last subtraction is a s_subb with the double 'b'. That subtracts not only 1, but also the SCC=1 which was used to exit out of the inner loop.

0 Likes

Actually a bug in my eyesight

Didn't notice that extra 'b' in s_subb_u32. (Code completion can be dangerous lol)

Thank you all!

0 Likes
himanshu_gautam
Grandmaster

I have asked some knowledgeable people. Hopefully they will reply soon.