/* DATA_SIZE ̕_̐ωZ CPU łȂ */
/*  - rev.201905 by Yoshiki NAGATANI */

#include <stdio.h>
#include <stdlib.h>

#define DATA_SIZE 1048576

/* xr̂ߓvZ REPEAT JԂ */
#define REPEAT 10000

/*-----------------------------------------------------------*/
/* ωZ R=A*B Ȃ֐(PRA) */
void MultiplyOnCPU(float* h_data_A, float* h_data_B, float* h_data_R) {
	long i;

	/* CPU ł̓f[^̐ for ܂킷 */
	for (i = 0; i < DATA_SIZE; i++) {
		h_data_R[i] = h_data_A[i] * h_data_B[i];
	}
}

/*-----------------------------------------------------------*/
int main(void) {

	int i;

	printf("DATA_SIZE(%d)\n", DATA_SIZE);

	float* h_data_A;   /* Host(CPU) */
	float* h_data_B;   /* Host(CPU) */
	float* h_data_R;   /* Host(CPU) */

	/* ̈̊mہiǐd̂߃G[`FbNȂ̂ŒӁj */
	h_data_A = (float*)malloc(DATA_SIZE * sizeof(float));
	h_data_B = (float*)malloc(DATA_SIZE * sizeof(float));
	h_data_R = (float*)malloc(DATA_SIZE * sizeof(float));

	/* f[^ */
	for (i = 0; i < DATA_SIZE; i++) {
		h_data_A[i] = (double)(rand()) / 32768.0;
		h_data_B[i] = (double)(rand()) / 32768.0;
		h_data_R[i] = 0.0;
	}

	/* ωZsixv̂ REPEAT JԂj */
	printf("Start calculation on CPU for %d times...", REPEAT);
	for (i = 0; i < REPEAT; i++) {
		MultiplyOnCPU(h_data_A, h_data_B, h_data_R);
	}
	printf("done!!\n");

	/* ʂ̕\(ʕ\̓sCŏƍŌ̃f[^\) */
	printf("Results:\n");
	printf(" %8d: %f\n", 0, h_data_R[0]);
	printf(" %8d: %f\n", DATA_SIZE - 1, h_data_R[DATA_SIZE - 1]);

	return 0;
}

	.file	"tmpxft_002d1640_00000000-6_multiply_cpu_01.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	_Z13MultiplyOnCPUPfS_S_
	.type	_Z13MultiplyOnCPUPfS_S_, @function
_Z13MultiplyOnCPUPfS_S_:
.LFB2027:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
.L3:
	movss	(%rdi,%rax,4), %xmm0
	mulss	(%rsi,%rax,4), %xmm0
	movss	%xmm0, (%rdx,%rax,4)
	incq	%rax
	cmpq	$1048576, %rax
	jne	.L3
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z13MultiplyOnCPUPfS_S_, .-_Z13MultiplyOnCPUPfS_S_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"DATA_SIZE(%d)\n"
.LC3:
	.string	"Start calculation on CPU for %d times..."
.LC4:
	.string	"done!!\n"
.LC5:
	.string	"Results:\n"
.LC6:
	.string	" %8d: %f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$1048576, %edx
	leaq	.LC0(%rip), %rsi
	xorl	%eax, %eax
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	$2, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	pushq	%rcx
	.cfi_def_cfa_offset 48
	call	__printf_chk@PLT
	movl	$4194304, %edi
	call	malloc@PLT
	movl	$4194304, %edi
	movq	%rax, %r12
	call	malloc@PLT
	movl	$4194304, %edi
	movq	%rax, %r13
	call	malloc@PLT
	movq	%rax, %rbx
.L7:
	call	rand@PLT
	cvtsi2sdl	%eax, %xmm0
	mulsd	.LC1(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r12,%rbp)
	call	rand@PLT
	movl	$0x00000000, (%rbx,%rbp)
	cvtsi2sdl	%eax, %xmm0
	mulsd	.LC1(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 0(%r13,%rbp)
	addq	$4, %rbp
	cmpq	$4194304, %rbp
	jne	.L7
	movl	$10000, %edx
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$10000, %ecx
.L8:
	movq	%rbx, %rdx
	movq	%r13, %rsi
	movq	%r12, %rdi
	call	_Z13MultiplyOnCPUPfS_S_
	decl	%ecx
	jne	.L8
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC6(%rip), %rbp
	leaq	.LC5(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	%rbp, %rsi
	xorl	%edx, %edx
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	(%rbx), %xmm0
	call	__printf_chk@PLT
	movl	$1048575, %edx
	movq	%rbp, %rsi
	movb	$1, %al
	movl	$2, %edi
	cvtss2sd	4194300(%rbx), %xmm0
	call	__printf_chk@PLT
	popq	%rdx
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.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.cst8,"aM",@progbits,8
	.align 8
.LC1:
	.long	0
	.long	1056964608
	.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:

/* DATA_SIZE ̕_̐ωZ CPU łȂ */
/*  - rev.201905 by Yoshiki NAGATANI */


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

#define DATA_SIZE 1048576

/* xr̂ߓvZ REPEAT JԂ */
#define REPEAT 10000

/*-----------------------------------------------------------*/
/* ωZ R=A*B Ȃ֐(PRA) */
void MultiplyOnCPU(float* h_data_A, float* h_data_B, float* h_data_R) {
	long i;

	/* CPU ł̓f[^̐ for ܂킷 */
	for (i = 0; i < DATA_SIZE; i++) {
		h_data_R[i] = h_data_A[i] * h_data_B[i];
	}
}

/*-----------------------------------------------------------*/
int main(void) {

	int i;

	printf("DATA_SIZE(%d)\n", DATA_SIZE);

	float* h_data_A;   /* Host(CPU) */
	float* h_data_B;   /* Host(CPU) */
	float* h_data_R;   /* Host(CPU) */

	/* ̈̊mہiǐd̂߃G[`FbNȂ̂ŒӁj */
	h_data_A = (float*)malloc(DATA_SIZE * sizeof(float));
	h_data_B = (float*)malloc(DATA_SIZE * sizeof(float));
	h_data_R = (float*)malloc(DATA_SIZE * sizeof(float));

	/* f[^ */
	for (i = 0; i < DATA_SIZE; i++) {
		h_data_A[i] = (double)(rand()) / 32768.0;
		h_data_B[i] = (double)(rand()) / 32768.0;
		h_data_R[i] = 0.0;
	}

	/* ωZsixv̂ REPEAT JԂj */
	printf("Start calculation on CPU for %d times...", REPEAT);
	for (i = 0; i < REPEAT; i++) {
		MultiplyOnCPU(h_data_A, h_data_B, h_data_R);
	}
	printf("done!!\n");

	/* ʂ̕\(ʕ\̓sCŏƍŌ̃f[^\) */
	printf("Results:\n");
	printf(" %8d: %f\n", 0, h_data_R[0]);
	printf(" %8d: %f\n", DATA_SIZE - 1, h_data_R[DATA_SIZE - 1]);

	return 0;
}

	.text
	.file	"multiply_cpu_01.hip"
	.globl	_Z13MultiplyOnCPUPfS_S_         # -- Begin function _Z13MultiplyOnCPUPfS_S_
	.type	_Z13MultiplyOnCPUPfS_S_,@function
_Z13MultiplyOnCPUPfS_S_:                # @_Z13MultiplyOnCPUPfS_S_
	.cfi_startproc
# %bb.0:
	xorl	%eax, %eax
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
	movss	(%rdi,%rax,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	mulss	(%rsi,%rax,4), %xmm0
	movss	%xmm0, (%rdx,%rax,4)
	incq	%rax
	cmpq	$1048576, %rax                  # imm = 0x100000
	jne	.LBB0_1
# %bb.2:
	retq
.Lfunc_end0:
	.size	_Z13MultiplyOnCPUPfS_S_, .Lfunc_end0-_Z13MultiplyOnCPUPfS_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI1_0:
	.quad	0x3f00000000000000              # double 3.0517578125E-5
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	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
	xorl	%r12d, %r12d
	movl	$.L.str, %edi
	movl	$1048576, %esi                  # imm = 0x100000
	xorl	%eax, %eax
	callq	printf
	movl	$4194304, %edi                  # imm = 0x400000
	callq	malloc
	movq	%rax, %r14
	movl	$4194304, %edi                  # imm = 0x400000
	callq	malloc
	movq	%rax, %r15
	movl	$4194304, %edi                  # imm = 0x400000
	callq	malloc
	movq	%rax, %rbx
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	movsd	.LCPI1_0(%rip), %xmm1           # xmm1 = mem[0],zero
	mulsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r14,%r12,4)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	mulsd	.LCPI1_0(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r15,%r12,4)
	movl	$0, (%rbx,%r12,4)
	incq	%r12
	cmpq	$1048576, %r12                  # imm = 0x100000
	jne	.LBB1_1
# %bb.2:
	xorl	%r12d, %r12d
	movl	$.L.str.1, %edi
	movl	$10000, %esi                    # imm = 0x2710
	xorl	%eax, %eax
	callq	printf
.LBB1_3:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_4 Depth 2
	xorl	%eax, %eax
.LBB1_4:                                #   Parent Loop BB1_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%r14,%rax,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	mulss	(%r15,%rax,4), %xmm0
	movss	%xmm0, (%rbx,%rax,4)
	incq	%rax
	cmpq	$1048576, %rax                  # imm = 0x100000
	jne	.LBB1_4
# %bb.5:                                # %_Z13MultiplyOnCPUPfS_S_.exit
                                        #   in Loop: Header=BB1_3 Depth=1
	incl	%r12d
	cmpl	$10000, %r12d                   # imm = 0x2710
	jne	.LBB1_3
# %bb.6:
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.4, %edi
	xorl	%esi, %esi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	4194300(%rbx), %xmm0
	movl	$.L.str.4, %edi
	movl	$1048575, %esi                  # imm = 0xFFFFF
	movb	$1, %al
	callq	printf
	xorl	%eax, %eax
	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_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"DATA_SIZE(%d)\n"
	.size	.L.str, 15

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Start calculation on CPU for %d times..."
	.size	.L.str.1, 41

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	" %8d: %f\n"
	.size	.L.str.4, 10

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"done!!"
	.size	.Lstr, 7

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Results:"
	.size	.Lstr.1, 9

	.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
