# 1 "bgl_comm.S"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "bgl_comm.S"
.globl bgl_send_u_nb
.globl bgl_send_u
.globl bgl_recv_u
.globl bgl_thr_u




# void bgl_send_u_nb(int* mu1, int* mu2, int* n, int* off_list,
# double* send_buf, double* recv_buf, int* spinor)
# mu : 0=0+, 1=0-, 2=1+, ..., 7=3-
# mu2=-1 -> not diagonal






##define 2047 255
##define 2048 256

#cr : 31 1 = diag
# 30 no diag: 1 <=> phys dir=3 (no torus)
# diag: 0
# 29 diag : 1 <=> dir2=3 (--> swap)
# 28 diag and swap
# 27 diag and no_swap
# 23 0 : gauge field, 1 : spinor field
#mesh:
# 26 no_send
# 25 no_recv
# 24 no_thr

#fpr: 0 send header 1
# 1 send header 2

#gpr:

# 3 mu1
# 4 mu2
# 5 scratch
# 6 off_list
# 7 send buffer
# 8 recv buffer


# 12 scratch

# 16 scratch
# 17 send addr 1
# 18 send addr 2
# 19 recv addr 1
# 20 recv addr 2
# 21 send stat
# 22 recv stat
# 23 send stat o1
# 24 send stat o2
# 25 recv stat o1
# 26 recv stat o2
# 27 16
# 28 n_recv1
# 29 n_recv2


bgl_send_u_nb:
        mflr 0
        stw 0, 4(1)
        stwu 1, -128(1)

        stw 13, 32(1)
        stw 14, 36(1)
        stw 15, 40(1)
        stw 16, 44(1)
        stw 17, 48(1)
        stw 18, 52(1)
        stw 19, 56(1)
        stw 20, 60(1)
        stw 21, 64(1)
        stw 22, 68(1)
        stw 23, 72(1)
        stw 24, 76(1)
        stw 25, 80(1)
        stw 26, 84(1)
        stw 27, 88(1)
        stw 28, 92(1)
        stw 29, 96(1)
        stw 30,100(1)


        lwz 3, 0(3)
        lwz 4, 0(4)
        lwz 5, 0(5)

        mr 28, 5
        mr 29, 5
        mtctr 5 # r5 now scratch
        addi 6, 6, -4
        addis 13, 0, wilson_data@ha
        addi 13, 13, wilson_data@l
        lwz 9, 0(9)
        cmpi 0, 9, 1
        crand 23, 2, 2

        rlwinm 14, 3, 0, 31, 31 # 14 = fw1
        rlwinm 3, 3, 31, 1, 31 # 3 = mu1
        add 3, 3, 13
        lbz 3, 772(3) # now physical dir.

#addi 4, 0, -1
        cmpi 0, 4, -1
        crnand 31, 2, 2 # cr31=1 <=>diag

#crxor 31, 31,31

        bc 4, 31, lab1
        rlwinm 15, 4, 0, 31, 31 # 15 = fw2
        rlwinm 4, 4, 31, 1, 31 # 4 = mu2
        add 4, 4, 13
        lbz 4, 772(4) # now physical dir.
        cmpi 0, 3, 3 #if mu1=3, exchange dirs
        bne+ lab2
        mr 3, 4
        li 4, 3
        mr 14, 15
        li 15, 0 # fw=bw in this case
lab2: cmpi 0, 4, 3
        crand 29, 2, 2

lab1: cmpi 0, 3, 3
        crand 30, 2, 2
        crand 28, 31, 29 # cr28: diag and swap
        crandc 27, 31, 29 # cr27: diag and !swap

        li 27, 16
        addi 7, 7, -16
        addi 8, 8, -16

#setup headers etc.







        bc 4, 30, lab3b

        addis 17, 0, send_fifo4_addr@ha
        addi 17, 17, send_fifo4_addr@l
        lwz 17, 0(17)
        addis 19, 0, recv_fifo4_addr@ha
        addi 19, 19, recv_fifo4_addr@l
        lwz 19, 0(19)


        b lab3
lab3b:


        add 5, 3, 3
        add 5, 5, 5 # r5=4*mu1
# 189 "bgl_comm.S"
        cmpi 0, 14, 1
        addi 12, 5, 12
        bne lab4
        addi 5, 5, 12
        addi 12, 12, -12
lab4:

        addis 17, 0, send_fifo_addr@ha
        addi 17, 17, send_fifo_addr@l
        lwzx 17, 5, 17
        addis 19, 0, recv_fifo_addr@ha
        addi 19, 19, recv_fifo_addr@l
        lwzx 19, 12, 19

        add 5, 5, 5
        add 5, 5, 5 # r5: 0=x+, 16=y+, 32=z+, 48=x-..
        addi 23, 3, 7
        add 25, 3, 3
        addi 25, 25, 1
        subf 25, 14, 25
        addis 16, 0, send_header@ha
        addi 16, 16, send_header@l
        lfpdx 0, 5, 16 # send header header 1
        stfpdx 0, 0, 1

        lbz 5, 2(1) # set size to 4 (=160 bytes)
        andi. 5, 5, 0x1f
        bc 12, 23, bgl_lsp17
        addi 5, 5, 0x80
        b bgl_lsp18
bgl_lsp17:
        addi 5, 5, 0xc0
bgl_lsp18:
        stb 5, 2(1)
        bc 4, 28, lab5
        lbz 5, 1(1) # swap
        xori 5, 5, 1
        stb 5, 1(1)
lab5: lfpdx 0, 0, 1




        bc 4, 27, lab3
                                        # 2nd header

        add 5, 4, 4
        add 5, 5, 5 # r5=4*mu1
# 269 "bgl_comm.S"
        cmpi 0, 15, 1
        addi 12, 5, 12
        bne lab4b
        addi 5, 5, 12
        addi 12, 12, -12
lab4b:
        addis 18, 0, send_fifo_addr@ha
        addi 18, 18, send_fifo_addr@l
        lwzx 18, 5, 18
        mr 20, 19
        addis 19, 0, recv_fifo_addr@ha
        addi 19, 19, recv_fifo_addr@l
        lwzx 19, 12, 19


        add 5, 5, 5
        add 5, 5, 5 # r5: 0=x+, 16=y+, 32=z+, 48=x-..
        addi 24, 4, 7
        mr 26, 25
        add 25, 4, 4
        addi 25, 25, 1
        subf 25, 15, 25
        addis 16, 0, send_header@ha
        addi 16, 16, send_header@l
        lfpdx 1, 5, 16 # send header 1
        stfpdx 1, 0, 1
        lbz 5, 2(1) # set size to 4 (=160 bytes)
        andi. 5, 5, 0x1f
        bc 12, 23, bgl_lsp15
        addi 5, 5, 0x80
        b bgl_lsp16
bgl_lsp15:
        addi 5, 5, 0xc0
bgl_lsp16:
        stb 5, 2(1)
        lfpdx 1, 0, 1


lab3:

        bc 12, 27, bgl_nd1
        addi 29, 0, 0
bgl_nd1:
# 324 "bgl_comm.S"
        addis 22, 0, recv_stat_addr@ha
        addi 22, 22, recv_stat_addr@l
        lwz 22, 0(22)
        addis 21, 0, send_stat_addr@ha
        addi 21, 21, send_stat_addr@l
        lwz 21, 0(21)



#bl lll1
#lll1: addi 31, 0, 0
# mtctr 31
# bctr


bgl_main_loop:
# 348 "bgl_comm.S"
        # check status

        bc 4, 30, bgl_check_s_l1
bgl_check_s_l1x:
        lwz 5, 0(17) # rd offs
        lwz 12, 4(17) # wr offs
        subf 5, 5, 12
        cmpi 0, 5, 2048 -256
        bge- bgl_check_s_l1x
# bge- bgl_rd

        addi 5, 12, 256
        addi 16, 12, 128
        andi. 12, 12, 2047
        add 12, 12, 17
        andi. 16, 16, 2047
        add 16, 16, 17

        lfpdux 4, 7, 27
        lfpdux 5, 7, 27
        lfpdux 6, 7, 27
        lfpdux 7, 7, 27
        stfpdux 4, 12, 27
        lfpdux 4, 7, 27
        stfpdux 5, 12, 27
        lfpdux 5, 7, 27
        stfpdux 6, 12, 27

        bc 12, 23, bgl_lsp1
        lfpdux 6, 7, 27
        stfpdux 7, 12, 27
        lfpdux 7, 7, 27
        stfpdux 4, 12, 27
        lfpdux 4, 7, 27
        stfpdux 5, 12, 27

        stfpdux 6, 16, 27
        stfpdux 7, 16, 27
        stfpdux 4, 16, 27
        b bgl_lsp2
bgl_lsp1:
        lfpdux 6, 7, 27
        stfpdux 7, 12, 27
        lfpdux 7, 7, 27
        stfpdux 4, 12, 27
        lfpdux 4, 7, 27
        stfpdux 5, 12, 27
        lfpdux 5, 7, 27

        stfpdux 6, 16, 27
        lfpdux 6, 7, 27
        stfpdux 7, 16, 27
        lfpdux 7, 7, 27
        stfpdux 4, 16, 27
        stfpdux 5, 16, 27
        stfpdux 6, 16, 27
        stfpdux 7, 16, 27
bgl_lsp2:
        mbar
        stw 5, 4(17) # wr offs

        b bgl_l_s1d



bgl_check_s_l1:
        lfpdx 2, 0, 21
        stfpdx 2, 0, 1
        lbzx 5, 23, 1
        cmpi 0, 5, 24
# bgt- bgl_check_s_l1
        bgt- bgl_rd

        stfpdx 0, 0, 17 # header
        lfpdux 4, 7, 27
        lfpdux 5, 7, 27
        lfpdux 6, 7, 27
        lfpdux 7, 7, 27
        stfpdx 4, 0, 17
        lfpdux 4, 7, 27
        stfpdx 5, 0, 17
        lfpdux 5, 7, 27
        stfpdx 6, 0, 17
        bc 12, 23, bgl_lsp3
        lfpdux 6, 7, 27
        stfpdx 7, 0, 17
        lfpdux 7, 7, 27
        stfpdx 4, 0, 17
        lfpdux 4, 7, 27
        stfpdx 5, 0, 17
        stfpdx 6, 0, 17
        stfpdx 7, 0, 17
        stfpdx 4, 0, 17
        b bgl_lsp4
bgl_lsp3:
        lfpdux 6, 7, 27
        stfpdx 7, 0, 17
        lfpdux 7, 7, 27
        stfpdx 4, 0, 17
        lfpdux 4, 7, 27
        stfpdx 5, 0, 17
        lfpdux 5, 7, 27
        stfpdx 6, 0, 17
        lfpdux 6, 7, 27
        stfpdx 7, 0, 17
        lfpdux 7, 7, 27
        stfpdx 4, 0, 17
        stfpdx 5, 0, 17
        stfpdx 6, 0, 17
        stfpdx 7, 0, 17
        stfpdx 7, 0, 17
bgl_lsp4:


bgl_l_s1d:




# dec ctr


        lwzu 5, 4(6)
        bc 12, 23, bgl_lsp13
        mulli 5, 5, 144
        b bgl_lsp14
bgl_lsp13:
        mulli 5, 5, 192
bgl_lsp14:
        add 7, 7, 5


        bdz bgl_recv_loop

bgl_rd:

        bc 4, 27, bgl_no_thr3
        cmpi 0, 29, 0
        beq bgl_no_thr3



        # check status







#bgl_check_s_l1c:
        lfpdx 2, 0, 22
        stfpdx 2, 0, 1
        lbzx 5, 26, 1
        cmpi 0, 5, 0
        beq- bgl_no_thr3


        # check status
bgl_check_s_l2c:
        lfpdx 2, 0, 21
        stfpdx 2, 0, 1
        lbzx 5, 24, 1
        cmpi 0, 5, 24
# bgt- bgl_check_s_l2c
        bgt- bgl_no_thr3





        lfpdx 4, 0, 20 # header
        stfpdx 1, 0, 18 # header


        lfpdx 4, 0, 20 # data
        lfpdx 5, 0, 20
        lfpdx 6, 0, 20
        lfpdx 7, 0, 20
        stfpdx 4, 0, 18
        lfpdx 4, 0, 20
        stfpdx 5, 0, 18
        lfpdx 5, 0, 20
        stfpdx 6, 0, 18
        lfpdx 6, 0, 20
        stfpdx 7, 0, 18
        lfpdx 7, 0, 20
        stfpdx 4, 0, 18
        lfpdx 4, 0, 20
        stfpdx 5, 0, 18
        stfpdx 6, 0, 18
        stfpdx 7, 0, 18
        stfpdx 4, 0, 18

        addi 29, 29, -1

bgl_no_thr3:
# 563 "bgl_comm.S"
        bc 4, 30, bgl_check_s_l2

        cmpi 0, 28, 0
        beq bgl_no_recv1



bgl_check_s_l2x:
        lwz 5, 0(19) # rd offs
        lwz 12, 4(19) # wr offs
        cmp 0, 5, 12
        beq- bgl_check_s_l2x
# beq- bgl_no_recv1



        addi 12, 5, 256
        addi 16, 5, 128
        andi. 5, 5, 2047
        add 5, 5, 19
        andi. 16, 16, 2047
        add 16, 16, 19



        lfpdux 4, 5, 27 # data
        lfpdux 5, 5, 27
        lfpdux 6, 5, 27
        lfpdux 7, 5, 27
        stfpdux 4, 8, 27
        lfpdux 4, 5, 27
        stfpdux 5, 8, 27
        lfpdux 5, 5, 27
        stfpdux 6, 8, 27
        bc 12, 23, bgl_lsp5
        lfpdux 6,16, 27
        stfpdux 7, 8, 27
        lfpdux 7,16, 27
        stfpdux 4, 8, 27
        lfpdux 4,16, 27
        stfpdux 5, 8, 27
        stfpdux 6, 8, 27
        stfpdux 7, 8, 27
        stfpdux 4, 8, 27
        b bgl_lsp6
bgl_lsp5:
        lfpdux 6,16, 27
        stfpdux 7, 8, 27
        lfpdux 7,16, 27
        stfpdux 4, 8, 27
        lfpdux 4,16, 27
        stfpdux 5, 8, 27
        lfpdux 5,16, 27
        stfpdux 6, 8, 27
        lfpdux 6,16, 27
        stfpdux 7, 8, 27
        lfpdux 7,16, 27
        stfpdux 4, 8, 27
        stfpdux 5, 8, 27
        stfpdux 6, 8, 27
        stfpdux 7, 8, 27
bgl_lsp6:
                mbar
        stw 12, 0(19) # rd offs

        addi 28, 28, -1
        b bgl_no_recv1


                        # check status
bgl_check_s_l2:
        lfpdx 2, 0, 22
        stfpdx 2, 0, 1
        lbzx 5, 25, 1
        cmpi 0, 5, 0
        beq- bgl_no_recv1



        lfpdx 4, 0, 19 # header
        lfpdx 4, 0, 19 # data
        lfpdx 5, 0, 19
        lfpdx 6, 0, 19
        lfpdx 7, 0, 19
        stfpdux 4, 8, 27
        lfpdx 4, 0, 19
        stfpdux 5, 8, 27
        lfpdx 5, 0, 19
        stfpdux 6, 8, 27
        bc 12, 23, bgl_lsp7
        lfpdx 6, 0, 19
        stfpdux 7, 8, 27
        lfpdx 7, 0, 19
        stfpdux 4, 8, 27
        lfpdx 4, 0, 19
        stfpdux 5, 8, 27
        stfpdux 6, 8, 27
        stfpdux 7, 8, 27
        stfpdux 4, 8, 27
        b bgl_lsp8
bgl_lsp7:
        lfpdx 6, 0, 19
        stfpdux 7, 8, 27
        lfpdx 7, 0, 19
        stfpdux 4, 8, 27
        lfpdx 4, 0, 19
        stfpdux 5, 8, 27
        lfpdx 5, 0, 19
        stfpdux 6, 8, 27
        lfpdx 6, 0, 19
        stfpdux 7, 8, 27
        lfpdx 7, 0, 19
        stfpdux 4, 8, 27
        lfpdx 7, 0, 19
        stfpdux 5, 8, 27
        stfpdux 6, 8, 27
        stfpdux 7, 8, 27
bgl_lsp8:

        addi 28, 28, -1
bgl_no_recv1:







#b bgl_finish


# lwzu 5, 4(6)
# mulli 5, 5, 144
# add 7, 7, 5


# bdz bgl_recv_loop

# bdnz bgl_main_loop
        b bgl_main_loop




#bl lll1
#lll1: addi 31, 0, 0
# mtctr 31
# bctr


bgl_recv_loop:


#bl lll1
#lll1: addi 31, 0, 0
# mtctr 31
# bctr


# #ifdef MESH
# bc 12, 25, bgl_finish
# #endif

        cmpi 0, 28, 0
        cmpi 1, 29, 0
        crand 2, 2, 6
        beq bgl_finish






        bc 4, 27, bgl_no_thr2
        cmpi 0, 29, 0
        beq bgl_no_thr2
# 747 "bgl_comm.S"
                # check status
        lfpdx 2, 0, 22
        stfpdx 2, 0, 1
        lbzx 5, 26, 1
        cmpi 0, 5, 0
        beq- bgl_no_thr2


        # check status
bgl_check_s_l2b:
        lfpdx 2, 0, 21
        stfpdx 2, 0, 1
        lbzx 5, 24, 1
        cmpi 0, 5, 24
# bgt- bgl_check_s_l2b
        bgt- bgl_no_thr2


        lfpdx 4, 0, 20 # header
        stfpdx 1, 0, 18


        lfpdx 4, 0, 20 # data
        lfpdx 5, 0, 20
        lfpdx 6, 0, 20
        lfpdx 7, 0, 20
        stfpdx 4, 0, 18
        lfpdx 4, 0, 20
        stfpdx 5, 0, 18
        lfpdx 5, 0, 20
        stfpdx 6, 0, 18
        lfpdx 6, 0, 20
        stfpdx 7, 0, 18
        lfpdx 7, 0, 20
        stfpdx 4, 0, 18
        lfpdx 4, 0, 20
        stfpdx 5, 0, 18
        stfpdx 6, 0, 18
        stfpdx 7, 0, 18
        stfpdx 4, 0, 18

        addi 29, 29, -1






bgl_no_thr2:
        cmpi 0, 28, 0
        beq bgl_no_recv1b



        bc 4, 30, bgl_recv_t1

bgl_check_s_l2x2:
        lwz 5, 0(19) # rd offs
        lwz 12, 4(19) # wr offs
        cmp 0, 5, 12
        beq- bgl_no_recv1b
# beq- bgl_check_s_l2x2



        addi 12, 5, 256
        addi 16, 5, 128
        andi. 5, 5, 2047
        add 5, 5, 19
        andi. 16, 16, 2047
        add 16, 16, 19



        lfpdux 4, 5, 27 # data
        lfpdux 5, 5, 27
        lfpdux 6, 5, 27
        lfpdux 7, 5, 27
        stfpdux 4, 8, 27
        lfpdux 4, 5, 27
        stfpdux 5, 8, 27
        lfpdux 5, 5, 27
        stfpdux 6, 8, 27
        bc 12, 23, bgl_lsp9
        lfpdux 6,16, 27
        stfpdux 7, 8, 27
        lfpdux 7,16, 27
        stfpdux 4, 8, 27
        lfpdux 4,16, 27
        stfpdux 5, 8, 27
        stfpdux 6, 8, 27
        stfpdux 7, 8, 27
        stfpdux 4, 8, 27
        b bgl_lsp10
bgl_lsp9:
        lfpdux 6,16, 27
        stfpdux 7, 8, 27
        lfpdux 7,16, 27
        stfpdux 4, 8, 27
        lfpdux 4,16, 27
        stfpdux 5, 8, 27
        lfpdux 5,16, 27
        stfpdux 6, 8, 27
        lfpdux 6,16, 27
        stfpdux 7, 8, 27
        lfpdux 7,16, 27
        stfpdux 4, 8, 27
        stfpdux 5, 8, 27
        stfpdux 6, 8, 27
        stfpdux 7, 8, 27
bgl_lsp10:
        mbar
        stw 12, 0(19) # rd offs

        addi 28, 28, -1
        b bgl_no_recv1b


bgl_recv_t1:
                # check status
        lfpdx 2, 0, 22
        stfpdx 2, 0, 1
        lbzx 5, 25, 1
        cmpi 0, 5, 0
        beq- bgl_no_recv1b

        lfpdx 4, 0, 19 # header

        lfpdx 4, 0, 19 # data
        lfpdx 5, 0, 19
        lfpdx 6, 0, 19
        lfpdx 7, 0, 19
        stfpdux 4, 8, 27
        lfpdx 4, 0, 19
        stfpdux 5, 8, 27
        lfpdx 5, 0, 19
        stfpdux 6, 8, 27
        bc 12, 23, bgl_lsp11
        lfpdx 6, 0, 19
        stfpdux 7, 8, 27
        lfpdx 7, 0, 19
        stfpdux 4, 8, 27
        lfpdx 4, 0, 19
        stfpdux 5, 8, 27
        stfpdux 6, 8, 27
        stfpdux 7, 8, 27
        stfpdux 4, 8, 27
        b bgl_lsp12
bgl_lsp11:
        lfpdx 6, 0, 19
        stfpdux 7, 8, 27
        lfpdx 7, 0, 19
        stfpdux 4, 8, 27
        lfpdx 4, 0, 19
        stfpdux 5, 8, 27
        lfpdx 5, 0, 19
        stfpdux 6, 8, 27
        lfpdx 6, 0, 19
        stfpdux 7, 8, 27
        lfpdx 7, 0, 19
        stfpdux 4, 8, 27
        lfpdx 7, 0, 19
        stfpdux 5, 8, 27
        stfpdux 6, 8, 27
        stfpdux 7, 8, 27
bgl_lsp12:
        addi 28, 28, -1


bgl_no_recv1b:
        b bgl_recv_loop



bgl_finish:



# bl lll1
# lll1: addi 31, 0, 0
# mtctr 31
# bctr


        lwz 13, 32(1)
        lwz 14, 36(1)
        lwz 15, 40(1)
        lwz 16, 44(1)
        lwz 17, 48(1)
        lwz 18, 52(1)
        lwz 19, 56(1)
        lwz 20, 60(1)
        lwz 21, 64(1)
        lwz 22, 68(1)
        lwz 23, 72(1)
        lwz 24, 76(1)
        lwz 25, 80(1)
        lwz 26, 84(1)
        lwz 27, 88(1)
        lwz 28, 92(1)
        lwz 29, 96(1)
        lwz 30,100(1)

        addi 1, 1, 128
        lwz 0, 4(1)
        mtlr 0
        blr



# void bgl_send_u(int* mu, double* send_buf, int* n_block,
# int* block_length, int* stride)
# block_lengh in units of 12 doubles
# stride in bytes
# mu=logical direction


# gpr
# 0 scratch
# 3 mu
# 4 send_buf
# 5 fw
# 6 wilson_data
# 7 scratch
# 8 scratch
# 9 send_fifo_addr
# 10 send_stat
# 11 send_stat_o
# 12 16
# 13 blocksize (in 12 doubles)
# 14 stride in bytes
# 15 scratch
# ctr # blocks
#cr
# 30 1=fw

bgl_send_u:
        mflr 0
        stw 0, 4(1)
        stwu 1, -128(1)

        stw 13, 32(1)
        stw 14, 36(1)
        stw 15, 40(1)

        lwz 5, 0(5)
        lwz 13, 0(6)
        lwz 14, 0(7)
        mtctr 5

        addis 6, 0, wilson_data@ha
        addi 6, 6, wilson_data@l

        lwz 3, 0(3)
        li 12, 16
        addi 4, 4, -16
        rlwinm 5, 3, 0, 31, 31 # 5 = fw
        rlwinm 3, 3, 31, 1, 31 # 3 = mu2
        cmpi 7, 5, 1
        add 3, 3, 6
        lbz 3, 772(3) # now physical dir.
        cmpi 0, 3, 3
        beq- bsu_d3



        add 7, 3, 3
        add 7, 7, 7 # r7=4mu
        bc 4, 30, bsu_l1
        addi 7, 7, 12
bsu_l1:
        addis 9, 0, send_fifo_addr@ha
        addi 9, 9, send_fifo_addr@l
        lwzx 9, 7, 9


        add 7, 7, 7
        add 7, 7, 7 # r7: 0=x+, 16=y+, 32=z+, 48=x-..
        addis 8, 0, send_header@ha
        addi 11, 3, 7
        addi 8, 8, send_header@l
        lfpdx 0, 7, 8 # send header header
        stfpdx 0, 0, 1
        lbz 7, 2(1) # set size to 4 (=128 bytes)
        andi. 7, 7, 0x1f
        addi 7, 7, 0x60
        stb 7, 2(1)
        lfpdx 0, 0, 1

        addis 10, 0, send_stat_addr@ha
        addi 10, 10, send_stat_addr@l
        lwz 10, 0(10)


bsu_loop_send:

        mr 8, 13

bsu_loop_block:

bsu_l2:
        lfpdx 2, 0, 10
        stfpdx 2, 0, 1
        lbzx 7, 11, 1
        cmpi 0, 7, 24
        bgt- bsu_l2


        stfpdx 0, 0, 9 # header
        stfpdx 0, 0, 9 # header again(dummy)
        lfpdux 4, 4, 12
        lfpdux 5, 4, 12
        lfpdux 6, 4, 12
        lfpdux 7, 4, 12
        stfpdx 4, 0, 9
        lfpdux 4, 4, 12
        stfpdx 5, 0, 9
        lfpdux 5, 4, 12
        stfpdx 6, 0, 9
# lfpdux 6, 4, 12
        stfpdx 7, 0, 9
# lfpdux 7, 4, 12
        stfpdx 4, 0, 9
# lfpdux 4, 4, 12
        stfpdx 5, 0, 9
# stfpdx 6, 0, 9
# stfpdx 7, 0, 9
# stfpdx 4, 0, 9


        addi 8, 8, -1
        cmpi 0, 8, 0
        bne+ bsu_loop_block

        add 4, 4, 14

        bdnz bsu_loop_send



        b bsu_finish
bsu_d3:
        addis 9, 0, send_fifo4_addr@ha
        addi 9, 9, send_fifo4_addr@l
        lwz 9, 0(9)


bsu_loop_send_d3:

        mr 15, 13

bsu_loop_block_d3:



bsu_l3:
        lwz 7, 0(9) # rd offs
        lwz 8, 4(9) # wr offs
        subf 7, 7, 8
        cmpi 0, 7, 2048 -128
        bge- bsu_l3

        addi 7, 8, 128
        addi 3, 8, 128
        andi. 8, 8, 2047
        add 8, 8, 9
        andi. 3, 3, 2047
        add 3, 3, 9

        lfpdux 4, 4, 12
        lfpdux 5, 4, 12
        lfpdux 6, 4, 12
        lfpdux 7, 4, 12
        stfpdux 4, 8, 12
        lfpdux 4, 4, 12
        stfpdux 5, 8, 12
        lfpdux 5, 4, 12
        stfpdux 6, 8, 12
        stfpdux 7, 8, 12
        stfpdux 4, 8, 12
        stfpdux 5, 8, 12

mbar
        stw 7, 4(9) # wr offs


        addi 15, 15, -1
        cmpi 0, 15, 0
        bne+ bsu_loop_block_d3

        add 4, 4, 14

        bdnz bsu_loop_send_d3


bsu_finish:

        lwz 13, 32(1)
        lwz 14, 36(1)
        lwz 15, 40(1)

        addi 1, 1, 128
        lwz 0, 4(1)
        mtlr 0
        blr
# 1160 "bgl_comm.S"
# void bgl_recv_u(int* mu, double* send_buf, int* n_blocks,
# int* block_length, int* stride)
# mu=logical direction


# gpr
# 0 scratch
# 3 mu
# 4 send_buf
# 5 fw
# 6 wilson_data
# 7 scratch
# 8 scratch
# 9 recv_fifo_addr
# 10 recv_stat
# 11 recv_stat_o
# 12 16
#cr
# 30 1=fw

bgl_recv_u:
        mflr 0
        stw 0, 4(1)
        stwu 1, -128(1)

        stw 13, 32(1)
        stw 14, 36(1)
        stw 15, 40(1)

        lwz 5, 0(5)
        lwz 13, 0(6)
        lwz 14, 0(7)
        mtctr 5




        addis 6, 0, wilson_data@ha
        addi 6, 6, wilson_data@l

        li 12, 16
        addi 4, 4, -16

        lwz 3, 0(3)

        rlwinm 5, 3, 0, 31, 31 # 5 = fw
        rlwinm 3, 3, 31, 1, 31 # 3 = mu
        cmpi 7, 5, 1
        add 3, 3, 6
        lbz 3, 772(3) # now physical dir.
        cmpi 0, 3, 3
        beq- bru_d3



        add 7, 3, 3
        add 7, 7, 7 # r7=4mu
        bc 4, 30, bru_l1
        addi 7, 7, 12
bru_l1:
        addis 9, 0, recv_fifo_addr@ha
        addi 9, 9, recv_fifo_addr@l
        lwzx 9, 7, 9


        add 11, 3, 3
        add 11, 11, 5

        addis 10, 0, recv_stat_addr@ha
        addi 10, 10, recv_stat_addr@l
        lwz 10, 0(10)


bru_loop_recv:

        mr 15, 13

bru_loop_block:


bru_l2:
        lfpdx 2, 0, 10
        stfpdx 2, 0, 1
        lbzx 7, 11, 1
        cmpi 0, 7, 0


# bne bru_xxx1

# addi 31, 0, 0
# mtctr 31
# bctr

        beq- bru_l2


bru_xxx1:

        lfpdx 4, 0, 9 # header
        lfpdx 4, 0, 9 # header again
        lfpdx 4, 0, 9
        lfpdx 5, 0, 9
        lfpdx 6, 0, 9
        lfpdx 7, 0, 9
        stfpdux 4, 4, 12
        lfpdx 4, 0, 9
        stfpdux 5, 4, 12
        lfpdx 5, 0, 9
        stfpdux 6, 4, 12
# lfpdx 6, 0, 9
        stfpdux 7, 4, 12
# lfpdx 7, 0, 9
        stfpdux 4, 4, 12
# lfpdx 4, 0, 9
        stfpdux 5, 4, 12
# stfpdux 6, 4, 12
# stfpdux 7, 4, 12
# stfpdux 4, 4, 12


        addi 15, 15, -1
        cmpi 0, 15, 0
        bne+ bru_loop_block

        add 4, 4, 14

        bdnz bru_loop_recv



        b bru_finish
bru_d3:
        addis 9, 0, recv_fifo4_addr@ha
        addi 9, 9, recv_fifo4_addr@l
        lwz 9, 0(9)


bru_loop_recv_d3:

        mr 15, 13

bru_loop_block_d3:



bru_l3:
        lwz 7, 0(9) # rd offs
        lwz 8, 4(9) # wr offs
        cmp 0, 7, 8



        beq- bru_l3
# addi 31, 0, 0
# mtctr 31
# bctr

        addi 8, 7, 128
        addi 3, 7, 128
        andi. 7, 7, 2047
        add 7, 7, 9
        andi. 3, 3, 2047
        add 3, 3, 9



        lfpdux 4, 7, 12 # data
        lfpdux 5, 7, 12
        lfpdux 6, 7, 12
        lfpdux 7, 7, 12
        stfpdux 4, 4, 12
        lfpdux 4, 7, 12
        stfpdux 5, 4, 12
        lfpdux 5, 7, 12
        stfpdux 6, 4, 12
        stfpdux 7, 4, 12
        stfpdux 4, 4, 12
        stfpdux 5, 4, 12


mbar
        stw 8, 0(9) # rd offs


# addi 31, 0, 0
# mtctr 31
# bctr


        addi 15, 15, -1
        cmpi 0, 15, 0
        bne+ bru_loop_block_d3

        add 4, 4, 14

        bdnz bru_loop_recv_d3




bgl_ru_d3:
bru_finish:
        lwz 13, 32(1)
        lwz 14, 36(1)
        lwz 15, 40(1)

        addi 1, 1, 128
        lwz 0, 4(1)
        mtlr 0
        blr







# void bgl_thr_U(int* mu_s, int* mu_r, int* n)
# mu_x=logical direction
# n = number of (12 double)-blocks

# gpr
# 0 scratch
# 3 mu_s
# 4 mu_r
# 5 fw
# 6 wilson_data
# 7 scratch
# 8 scratch
# 9 send_fifo_addr
# 10 send_stat
# 11 send_stat_o
# 12 16
#cr
# 30 1=fw

bgl_thr_u:
        mflr 0
        stw 0, 4(1)
        stwu 1, -128(1)

        stw 13, 32(1)
        stw 14, 36(1)

        addis 6, 0, wilson_data@ha
        addi 6, 6, wilson_data@l

        lwz 5, 0(5)
        lwz 3, 0(3)
        lwz 4, 0(4)

        mtctr 5
        li 12, 16
        rlwinm 5, 4, 0, 31, 31 # 5 = fw
        rlwinm 4, 4, 31, 1, 31 # 4 = mu
        cmpi 7, 5, 1
        add 4, 4, 6
        lbz 4, 772(4) # now physical dir.

        rlwinm 13, 3, 0, 31, 31 # 13 = fw
        rlwinm 3, 3, 31, 1, 31 # 3 = mu2
        cmpi 6, 13, 1
        add 3, 3, 6
        lbz 3, 772(3) # now physical dir.



btu_thr_loop:
        cmpi 0, 4, 3
        beq- btu_rd3



        add 7, 4, 4
        add 7, 7, 7 # r7=4mu
        bc 4, 30, btu_l1
        addi 7, 7, 12
btu_l1:
        addis 9, 0, recv_fifo_addr@ha
        addi 9, 9, recv_fifo_addr@l
        lwzx 9, 7, 9


        add 11, 4, 4
        add 11, 11, 5

        addis 10, 0, recv_stat_addr@ha
        addi 10, 10, recv_stat_addr@l
        lwz 10, 0(10)

btu_l2:
        lfpdx 2, 0, 10
        stfpdx 2, 0, 1
        lbzx 7, 11, 1
        cmpi 0, 7, 0
# addi 31, 0, 0
# mtctr 31
# bctr
        beq- btu_l2


        lfpdx 4, 0, 9 # header
        lfpdx 4, 0, 9 # header again
        lfpdx 4, 0, 9
        lfpdx 5, 0, 9
        lfpdx 6, 0, 9
        lfpdx 7, 0, 9
        lfpdx 8, 0, 9
        lfpdx 9, 0, 9

        b btu_send
btu_rd3:
        addis 9, 0, recv_fifo4_addr@ha
        addi 9, 9, recv_fifo4_addr@l
        lwz 9, 0(9)


btu_l3:
        lwz 7, 0(9) # rd offs
        lwz 8, 4(9) # wr offs
        cmp 0, 7, 8
        beq- btu_l3

        addi 8, 7, 128
# addi 4, 7, 128
        andi. 7, 7, 2047
        add 7, 7, 9
# andi. 4, 4, 2047
 # add 4, 4, 9

        lfpdux 4, 7, 12 # data
        lfpdux 5, 7, 12
        lfpdux 6, 7, 12
        lfpdux 7, 7, 12
        lfpdux 8, 7, 12
        lfpdux 9, 7, 12

mbar
        stw 8, 0(9) # rd offs




btu_send:


        cmpi 0, 3, 3
        beq- btu_sd3



        add 7, 3, 3
        add 7, 7, 7 # r7=4mu
        bc 4, 26, btu_l4
        addi 7, 7, 12
btu_l4:
        addis 9, 0, send_fifo_addr@ha
        addi 9, 9, send_fifo_addr@l
        lwzx 9, 7, 9


        add 7, 7, 7
        add 7, 7, 7 # r7: 0=x+, 16=y+, 32=z+, 48=x-..
        addis 8, 0, send_header@ha
        addi 11, 3, 7
        addi 8, 8, send_header@l
        lfpdx 0, 7, 8 # send header header
        stfpdx 0, 0, 1
        lbz 7, 2(1) # set size to 4 (=160 bytes)
        andi. 7, 7, 0x1f
        addi 7, 7, 0x60
        stb 7, 2(1)
        lfpdx 0, 0, 1

        addis 10, 0, send_stat_addr@ha
        addi 10, 10, send_stat_addr@l
        lwz 10, 0(10)

btu_l5:
        lfpdx 2, 0, 10
        stfpdx 2, 0, 1
        lbzx 7, 11, 1
        cmpi 0, 7, 24
        bgt- btu_l5


        stfpdx 0, 0, 9 # header
        stfpdx 0, 0, 9 # header again
        stfpdx 4, 0, 9
        stfpdx 5, 0, 9
        stfpdx 6, 0, 9
        stfpdx 7, 0, 9
        stfpdx 8, 0, 9
        stfpdx 9, 0, 9

        b btu_finish
btu_sd3:
        addis 9, 0, send_fifo4_addr@ha
        addi 9, 9, send_fifo4_addr@l
        lwz 9, 0(9)


btu_l6:
        lwz 7, 0(9) # rd offs
        lwz 8, 4(9) # wr offs
        subf 7, 7, 8
        cmpi 0, 7, 2048 -128
        bge- btu_l6

        addi 7, 8, 128
# addi 3, 8, 128
        andi. 8, 8, 2047
        add 8, 8, 9
# andi. 3, 3, 2047
 # add 3, 3, 9

        stfpdux 4, 8, 12
        stfpdux 5, 8, 12
        stfpdux 6, 8, 12
        stfpdux 7, 8, 12
        stfpdux 8, 8, 12
        stfpdux 9, 8, 12
mbar
        stw 7, 4(9) # wr offs


btu_finish:


        bdnz btu_thr_loop

        lwz 13, 32(1)
        lwz 14, 36(1)
        addi 1, 1, 128
        lwz 0, 4(1)
        mtlr 0
        blr
# 1627 "bgl_comm.S"
# li 12, 16
# addi 4, 4, -16
# rlwinm 5, 3, 0, 31, 31 # 5 = fw
# rlwinm 3, 3, 31, 1, 31 # 4 = mu2
# cmpi 7, 5, 1
# add 3, 3, 6
# lbz 3, 772(3) # now physical dir.
# cmpi 0, 3, 3
# beq- bgl_su_d3



# add 7, 3, 3
# add 7, 7, 7 # r7=4mu
# bc 4, 30, btsu_l1
# addi 7, 7, 12
# btsu_l1:
# addis 9, 0, send_fifo_addr@ha
# addi 9, 9, send_fifo_addr@l
# lwzx 9, 7, 9


# add 7, 7, 7
# add 7, 7, 7 # r7: 0=x+, 16=y+, 32=z+, 48=x-..
# addis 8, 0, send_header@ha
# addi 11, 3, 7
# addi 8, 8, send_header@l
# lfpdx 0, 7, 8 # send header header
# stfpdx 0, 0, 1
# lbz 7, 2(1) # set size to 4 (=160 bytes)
# andi. 7, 7, 0x1f
# addi 7, 7, 0x80
# stb 7, 2(1)
# lfpdx 0, 0, 1

# addis 10, 0, send_stat_addr@ha
# addi 10, 10, send_stat_addr@l
# lwz 10, 0(10)

# btsu_l2:
# lfpdx 2, 0, 10
# stfpdx 2, 0, 1
# lbzx 7, 11, 1
# cmpi 0, 7, 24
# bgt- btsu_l2


# stfpdx 0, 0, 9 # header
# lfpdux 4, 4, 12
# lfpdux 5, 4, 12
# lfpdux 6, 4, 12
# lfpdux 7, 4, 12
# stfpdx 4, 0, 9
# lfpdux 4, 4, 12
# stfpdx 5, 0, 9
# lfpdux 5, 4, 12
# stfpdx 6, 0, 9
# lfpdux 6, 4, 12
# stfpdx 7, 0, 9
# lfpdux 7, 4, 12
# stfpdx 4, 0, 9
# lfpdux 4, 4, 12
# stfpdx 5, 0, 9
# stfpdx 6, 0, 9
# stfpdx 7, 0, 9
# stfpdx 4, 0, 9

# b btsu_finish
# # bsu_d3:
# addis 9, 0, send_fifo4_addr@ha
# addi 9, 9, send_fifo4_addr@l
# lwz 9, 0(9)


# btsu_l3:
# lwz 7, 0(9) # rd offs
# lwz 8, 4(9) # wr offs
# subf 7, 7, 12
# cmpi 0, 7, 2048 -256
# bge- btsu_l3

# addi 7, 8, 256
# addi 3, 8, 128
# andi. 8, 8, 2047
 # add 8, 8, 9
# andi. 3, 3, 2047
 # add 3, 3, 9

# lfpdux 4, 4, 12
# lfpdux 5, 4, 12
# lfpdux 6, 4, 12
# lfpdux 7, 4, 12
# stfpdux 4, 8, 12
# lfpdux 4, 4, 12
# stfpdux 5, 8, 12
# lfpdux 5, 4, 12
# stfpdux 6, 8, 12
# lfpdux 6, 4, 12
# stfpdux 7, 8, 12
# lfpdux 7, 4, 12
# stfpdux 4, 8, 12
# lfpdux 4, 4, 12
# stfpdux 5, 8, 12

# stfpdux 6, 12, 3
# stfpdux 7, 12, 3
# stfpdux 4, 12, 3

# stw 7, 4(9) # wr offs

# btsu_finish:
# addi 1, 1, 128
# lwz 0, 4(1)
# mtlr 0
# blr
