// A serial (CPU-based) matrix multiplication program

#include "stdio.h"

#define SIZE 512

// Matrix multiply function
void multiply(float * A, float * B, float * C) 
{
    
    int i;
    for (i=0;i<SIZE*SIZE;i++) 
        C[i]=0.00; // initialize C to be on the safe side
    
    int row,col,row_len=SIZE,col_len=SIZE;
    for (row=0; row<row_len; row++) {
        
        for (col=0;col < col_len;col++) {
            
            for (i=0;i<SIZE;i++)
                C[row*row_len+col] += A[row*row_len+i]*B[col+i*row_len];
            
        }
        
    }
    
}

int main(int argc, char ** argv) 
{
    // create matrices and initialize A and B to arbitray values
    float A[SIZE*SIZE],B[SIZE*SIZE],C[SIZE*SIZE];
    int i;
    for (i=0;i<SIZE*SIZE;i++) {
        A[i] = (float)i;
        B[i] = (float)SIZE*(float)SIZE-(float)i-1.0;
    }
    
    multiply(A,B,C); // perform matrix multiply

    return 0;
}

	.file	"tmpxft_0028d42c_00000000-6_mat_multiply.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z8multiplyPfS_S_
	.type	_Z8multiplyPfS_S_, @function
_Z8multiplyPfS_S_:
.LFB2027:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	movq	%rdi, %r8
	movl	$262144, %ecx
	movq	%rdx, %rdi
	rep stosl
	movq	%rsi, %r9
	xorl	%eax, %eax
.L3:
	leaq	(%rdx,%rax), %rsi
	xorl	%ecx, %ecx
	leaq	(%r8,%rax), %r11
.L7:
	leaq	(%r9,%rcx,4), %r10
	xorl	%edi, %edi
.L4:
	movss	(%r11,%rdi,4), %xmm0
	mulss	(%r10), %xmm0
	incq	%rdi
	addq	$2048, %r10
	addss	(%rsi), %xmm0
	movss	%xmm0, (%rsi)
	cmpq	$512, %rdi
	jne	.L4
	incq	%rcx
	addq	$4, %rsi
	cmpq	$512, %rcx
	jne	.L7
	addq	$2048, %rax
	cmpq	$1048576, %rax
	jne	.L3
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z8multiplyPfS_S_, .-_Z8multiplyPfS_S_
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	leaq	-3145728(%rsp), %r11
	.cfi_def_cfa 11, 3145736
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$24, %rsp
	.cfi_def_cfa_offset 3145760
	movss	.LC0(%rip), %xmm3
	movss	.LC1(%rip), %xmm2
	movq	%fs:40, %rax
	movq	%rax, 3145736(%rsp)
	xorl	%eax, %eax
.L11:
	cvtsi2ssl	%eax, %xmm1
	movaps	%xmm3, %xmm0
	leaq	8(%rsp), %rdi
	leaq	1048584(%rsp), %rsi
	subss	%xmm1, %xmm0
	movss	%xmm1, (%rdi,%rax,4)
	subss	%xmm2, %xmm0
	movss	%xmm0, (%rsi,%rax,4)
	incq	%rax
	cmpq	$262144, %rax
	jne	.L11
	leaq	2097160(%rsp), %rdx
	call	_Z8multiplyPfS_S_
	movq	3145736(%rsp), %rax
	subq	%fs:40, %rax
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	xorl	%eax, %eax
	addq	$3145752, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2054:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2054:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	1216348160
	.align 4
.LC1:
	.long	1065353216
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

// A serial (CPU-based) matrix multiplication program


#include <hip/hip_runtime.h>
#include "stdio.h"

#define SIZE 512

// Matrix multiply function
void multiply(float * A, float * B, float * C) 
{
    
    int i;
    for (i=0;i<SIZE*SIZE;i++) 
        C[i]=0.00; // initialize C to be on the safe side
    
    int row,col,row_len=SIZE,col_len=SIZE;
    for (row=0; row<row_len; row++) {
        
        for (col=0;col < col_len;col++) {
            
            for (i=0;i<SIZE;i++)
                C[row*row_len+col] += A[row*row_len+i]*B[col+i*row_len];
            
        }
        
    }
    
}

int main(int argc, char ** argv) 
{
    // create matrices and initialize A and B to arbitray values
    float A[SIZE*SIZE],B[SIZE*SIZE],C[SIZE*SIZE];
    int i;
    for (i=0;i<SIZE*SIZE;i++) {
        A[i] = (float)i;
        B[i] = (float)SIZE*(float)SIZE-(float)i-1.0;
    }
    
    multiply(A,B,C); // perform matrix multiply

    return 0;
}

	.text
	.file	"mat_multiply.hip"
	.globl	_Z8multiplyPfS_S_               # -- Begin function _Z8multiplyPfS_S_
	.type	_Z8multiplyPfS_S_,@function
_Z8multiplyPfS_S_:                      # @_Z8multiplyPfS_S_
	.cfi_startproc
# %bb.0:                                # %.preheader25.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdx, %rbx
	movq	%rsi, %r14
	movq	%rdi, %r15
	xorl	%r12d, %r12d
	movl	$1048576, %edx                  # imm = 0x100000
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
.LBB0_1:                                # %.preheader25
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_2 Depth 2
                                        #       Child Loop BB0_3 Depth 3
	movq	%r12, %rax
	shlq	$9, %rax
	movq	%r14, %rcx
	xorl	%edx, %edx
.LBB0_2:                                # %.preheader
                                        #   Parent Loop BB0_1 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB0_3 Depth 3
	movq	%rdx, %rsi
	orq	%rax, %rsi
	movss	(%rbx,%rsi,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movq	%rcx, %rdi
	xorl	%r8d, %r8d
.LBB0_3:                                #   Parent Loop BB0_1 Depth=1
                                        #     Parent Loop BB0_2 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	(%r15,%r8,4), %xmm1             # xmm1 = mem[0],zero,zero,zero
	mulss	(%rdi), %xmm1
	addss	%xmm1, %xmm0
	movss	%xmm0, (%rbx,%rsi,4)
	incq	%r8
	addq	$2048, %rdi                     # imm = 0x800
	cmpq	$512, %r8                       # imm = 0x200
	jne	.LBB0_3
# %bb.4:                                #   in Loop: Header=BB0_2 Depth=2
	incq	%rdx
	addq	$4, %rcx
	cmpq	$512, %rdx                      # imm = 0x200
	jne	.LBB0_2
# %bb.5:                                #   in Loop: Header=BB0_1 Depth=1
	incq	%r12
	addq	$2048, %r15                     # imm = 0x800
	cmpq	$512, %r12                      # imm = 0x200
	jne	.LBB0_1
# %bb.6:
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z8multiplyPfS_S_, .Lfunc_end0-_Z8multiplyPfS_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI1_0:
	.long	0x48800000                      # float 262144
.LCPI1_1:
	.long	0xbf800000                      # float -1
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	subq	$3145736, %rsp                  # imm = 0x300008
	.cfi_def_cfa_offset 3145744
	xorl	%eax, %eax
	movss	.LCPI1_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movss	.LCPI1_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	xorps	%xmm2, %xmm2
	cvtsi2ss	%eax, %xmm2
	movss	%xmm2, 1048576(%rsp,%rax,4)
	movaps	%xmm0, %xmm3
	subss	%xmm2, %xmm3
	addss	%xmm1, %xmm3
	movss	%xmm3, (%rsp,%rax,4)
	incq	%rax
	cmpq	$262144, %rax                   # imm = 0x40000
	jne	.LBB1_1
# %bb.2:
	leaq	1048576(%rsp), %rdi
	movq	%rsp, %rsi
	leaq	2097152(%rsp), %rdx
	callq	_Z8multiplyPfS_S_
	xorl	%eax, %eax
	addq	$3145736, %rsp                  # imm = 0x300008
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
