#include <stdio.h>
#include <math.h>
#include <ctime>

using namespace std;

int transponowanie(){
  clock_t begin = clock();
  int const size(1000);
  static double tablica[size][size];
  static double tab[size][size];
  for(int i=0; i<size;i++){
    for(int j=0; j<size;j++){
      tablica[i][j]=i*size+j+1;
    }
  }
  printf("przed: 1:%f ", tablica[0][1]);
  printf("2:%f \n", tablica[1][0]);
  for(int i=0; i<size;i++){
    for(int j=0; j<size;j++){
      tab[j][i]=tablica[i][j];
    }
  }
  printf("po: 1:%f ", tab[0][1]);
  printf("2:%f \n", tab[1][0]);
  clock_t end = clock();
  double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
  printf("czas CPU: %f \n", elapsed_secs);
  return 1;
}




int main(void){
  transponowanie();
}

	.file	"tmpxft_002946bc_00000000-6_cuda_matrix.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"przed: 1:%f "
.LC1:
	.string	"2:%f \n"
.LC2:
	.string	"po: 1:%f "
.LC4:
	.string	"czas CPU: %f \n"
	.text
	.globl	_Z14transponowaniev
	.type	_Z14transponowaniev, @function
_Z14transponowaniev:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	_ZZ14transponowanievE7tablica(%rip), %rbx
	call	clock@PLT
	movq	%rbx, %rcx
	xorl	%edx, %edx
	movq	%rax, %rbp
.L3:
	movl	$1, %eax
.L4:
	leal	(%rdx,%rax), %esi
	cvtsi2sdl	%esi, %xmm0
	movsd	%xmm0, -8(%rcx,%rax,8)
	incq	%rax
	cmpq	$1001, %rax
	jne	.L4
	addl	$1000, %edx
	addq	$8000, %rcx
	cmpl	$1000000, %edx
	jne	.L3
	movsd	8+_ZZ14transponowanievE7tablica(%rip), %xmm0
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC1(%rip), %r12
	call	__printf_chk@PLT
	movq	%r12, %rsi
	movl	$2, %edi
	movb	$1, %al
	movsd	8000+_ZZ14transponowanievE7tablica(%rip), %xmm0
	call	__printf_chk@PLT
	leaq	_ZZ14transponowanievE3tab(%rip), %rdx
	leaq	8000(%rdx), %rsi
.L6:
	movq	%rdx, %rcx
	xorl	%eax, %eax
.L7:
	movsd	(%rbx,%rax,8), %xmm0
	incq	%rax
	addq	$8000, %rcx
	movsd	%xmm0, -8000(%rcx)
	cmpq	$1000, %rax
	jne	.L7
	addq	$8, %rdx
	addq	$8000, %rbx
	cmpq	%rsi, %rdx
	jne	.L6
	movsd	8+_ZZ14transponowanievE3tab(%rip), %xmm0
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	call	__printf_chk@PLT
	movq	%r12, %rsi
	movl	$2, %edi
	movb	$1, %al
	movsd	8000+_ZZ14transponowanievE3tab(%rip), %xmm0
	call	__printf_chk@PLT
	call	clock@PLT
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	subq	%rbp, %rax
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	divsd	.LC3(%rip), %xmm0
	call	__printf_chk@PLT
	popq	%rbx
	.cfi_def_cfa_offset 24
	movl	$1, %eax
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z14transponowaniev, .-_Z14transponowaniev
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	call	_Z14transponowaniev
	xorl	%eax, %eax
	popq	%rdx
	.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
	.local	_ZZ14transponowanievE3tab
	.comm	_ZZ14transponowanievE3tab,8000000,32
	.local	_ZZ14transponowanievE7tablica
	.comm	_ZZ14transponowanievE7tablica,8000000,32
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC3:
	.long	0
	.long	1093567616
	.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:


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <math.h>
#include <ctime>

using namespace std;

int transponowanie(){
  clock_t begin = clock();
  int const size(1000);
  static double tablica[size][size];
  static double tab[size][size];
  for(int i=0; i<size;i++){
    for(int j=0; j<size;j++){
      tablica[i][j]=i*size+j+1;
    }
  }
  printf("przed: 1:%f ", tablica[0][1]);
  printf("2:%f \n", tablica[1][0]);
  for(int i=0; i<size;i++){
    for(int j=0; j<size;j++){
      tab[j][i]=tablica[i][j];
    }
  }
  printf("po: 1:%f ", tab[0][1]);
  printf("2:%f \n", tab[1][0]);
  clock_t end = clock();
  double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
  printf("czas CPU: %f \n", elapsed_secs);
  return 1;
}




int main(void){
  transponowanie();
}

	.text
	.file	"cuda_matrix.hip"
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z14transponowaniev
.LCPI0_0:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	_Z14transponowaniev
	.type	_Z14transponowaniev,@function
_Z14transponowaniev:                    # @_Z14transponowaniev
	.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
	movl	$_ZZ14transponowanievE7tablica, %r14d
	movl	$1, %r15d
	xorl	%r12d, %r12d
	callq	clock
	movq	%rax, %rbx
	movl	$1000, %eax                     # imm = 0x3E8
.LBB0_1:                                # %.preheader21
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_2 Depth 2
	xorl	%ecx, %ecx
.LBB0_2:                                #   Parent Loop BB0_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	leal	(%r15,%rcx), %edx
	xorps	%xmm0, %xmm0
	cvtsi2sd	%edx, %xmm0
	movsd	%xmm0, (%r14,%rcx,8)
	incq	%rcx
	cmpq	$1000, %rcx                     # imm = 0x3E8
	jne	.LBB0_2
# %bb.3:                                #   in Loop: Header=BB0_1 Depth=1
	incq	%r12
	addq	$8000, %r14                     # imm = 0x1F40
	addq	%rax, %r15
	cmpq	%rax, %r12
	jne	.LBB0_1
# %bb.4:
	movl	$_ZZ14transponowanievE7tablica, %r14d
	movsd	_ZZ14transponowanievE7tablica+8(%rip), %xmm0 # xmm0 = mem[0],zero
	movl	$.L.str, %edi
	movb	$1, %al
	callq	printf
	movsd	_ZZ14transponowanievE7tablica+8000(%rip), %xmm0 # xmm0 = mem[0],zero
	movl	$.L.str.1, %edi
	movb	$1, %al
	callq	printf
	movl	$_ZZ14transponowanievE3tab, %eax
	xorl	%ecx, %ecx
.LBB0_5:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_6 Depth 2
	movq	%rax, %rdx
	xorl	%esi, %esi
.LBB0_6:                                #   Parent Loop BB0_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%r14,%rsi,8), %xmm0            # xmm0 = mem[0],zero
	movsd	%xmm0, (%rdx)
	incq	%rsi
	addq	$8000, %rdx                     # imm = 0x1F40
	cmpq	$1000, %rsi                     # imm = 0x3E8
	jne	.LBB0_6
# %bb.7:                                #   in Loop: Header=BB0_5 Depth=1
	incq	%rcx
	addq	$8000, %r14                     # imm = 0x1F40
	addq	$8, %rax
	cmpq	$1000, %rcx                     # imm = 0x3E8
	jne	.LBB0_5
# %bb.8:
	movsd	_ZZ14transponowanievE3tab+8(%rip), %xmm0 # xmm0 = mem[0],zero
	movl	$.L.str.2, %edi
	movb	$1, %al
	callq	printf
	movsd	_ZZ14transponowanievE3tab+8000(%rip), %xmm0 # xmm0 = mem[0],zero
	movl	$.L.str.1, %edi
	movb	$1, %al
	callq	printf
	callq	clock
	subq	%rbx, %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI0_0(%rip), %xmm0
	movl	$.L.str.3, %edi
	movb	$1, %al
	callq	printf
	movl	$1, %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_end0:
	.size	_Z14transponowaniev, .Lfunc_end0-_Z14transponowaniev
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	_Z14transponowaniev
	xorl	%eax, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.type	_ZZ14transponowanievE7tablica,@object # @_ZZ14transponowanievE7tablica
	.local	_ZZ14transponowanievE7tablica
	.comm	_ZZ14transponowanievE7tablica,8000000,16
	.type	_ZZ14transponowanievE3tab,@object # @_ZZ14transponowanievE3tab
	.local	_ZZ14transponowanievE3tab
	.comm	_ZZ14transponowanievE3tab,8000000,16
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"przed: 1:%f "
	.size	.L.str, 13

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"2:%f \n"
	.size	.L.str.1, 7

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"po: 1:%f "
	.size	.L.str.2, 10

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"czas CPU: %f \n"
	.size	.L.str.3, 15

	.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
