//
// global.cu
// Kernel of verifing ciphertext and constant-time copy.
//
// Copyright (c) 2021 Tatsuki Ono
//
// This software is released under the MIT License.
// https://opensource.org/licenses/mit-license.php
//

#include "device.cuh"
#include "global.cuh"

namespace atpqc_cuda::verify_cmov_ws::global {

__global__ void verify_cmov(std::uint8_t* r, std::size_t r_pitch,
                            const std::uint8_t* x, std::size_t x_pitch,
                            std::size_t cmove_len, const std::uint8_t* a,
                            std::size_t a_pitch, const std::uint8_t* b,
                            std::size_t b_pitch, std::size_t verify_len,
                            unsigned ninputs) {
  device::verify_cmov vc;

  if (unsigned pos = blockIdx.x * blockDim.y + threadIdx.y; pos < ninputs) {
    r += r_pitch * pos;
    x += x_pitch * pos;
    a += a_pitch * pos;
    b += b_pitch * pos;

    vc.cmov(r, x, cmove_len, vc.verify(a, b, verify_len));
  }
}

}  // namespace atpqc_cuda::verify_cmov_ws::global

	.file	"tmpxft_002a9962_00000000-6_global.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2024:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2024:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z84__device_stub__ZN10atpqc_cuda14verify_cmov_ws6global11verify_cmovEPhmPKhmmS4_mS4_mmjPhmPKhmmS1_mS1_mmj
	.type	_Z84__device_stub__ZN10atpqc_cuda14verify_cmov_ws6global11verify_cmovEPhmPKhmmS4_mS4_mmjPhmPKhmmS1_mS1_mmj, @function
_Z84__device_stub__ZN10atpqc_cuda14verify_cmov_ws6global11verify_cmovEPhmPKhmmS4_mS4_mmjPhmPKhmmS1_mS1_mmj:
.LFB2046:
	.cfi_startproc
	endbr64
	subq	$232, %rsp
	.cfi_def_cfa_offset 240
	movq	248(%rsp), %rax
	movq	%rdi, 56(%rsp)
	leaq	80(%rsp), %rdi
	movq	%rsi, 48(%rsp)
	leaq	92(%rsp), %rsi
	movq	%rdx, 40(%rsp)
	leaq	64(%rsp), %rdx
	movq	%rcx, 32(%rsp)
	leaq	72(%rsp), %rcx
	movq	%r8, 24(%rsp)
	movq	%r9, 16(%rsp)
	movq	%rax, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 216(%rsp)
	xorl	%eax, %eax
	leaq	56(%rsp), %rax
	movl	$1, 88(%rsp)
	movq	%rax, 128(%rsp)
	leaq	48(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	240(%rsp), %rax
	movq	%rax, 176(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 184(%rsp)
	leaq	256(%rsp), %rax
	movq	%rax, 192(%rsp)
	leaq	264(%rsp), %rax
	movq	%rax, 200(%rsp)
	leaq	272(%rsp), %rax
	movq	%rax, 208(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 80(%rsp)
	movq	%rax, 92(%rsp)
	movl	$1, 100(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	72(%rsp)
	.cfi_def_cfa_offset 248
	leaq	_ZN10atpqc_cuda14verify_cmov_ws6global11verify_cmovEPhmPKhmmS4_mS4_mmj(%rip), %rdi
	pushq	72(%rsp)
	.cfi_def_cfa_offset 256
	movq	108(%rsp), %rcx
	movl	116(%rsp), %r8d
	movq	96(%rsp), %rsi
	movl	104(%rsp), %edx
	leaq	144(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 248
	popq	%rdx
	.cfi_def_cfa_offset 240
.L2:
	movq	216(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$232, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2046:
	.size	_Z84__device_stub__ZN10atpqc_cuda14verify_cmov_ws6global11verify_cmovEPhmPKhmmS4_mS4_mmjPhmPKhmmS1_mS1_mmj, .-_Z84__device_stub__ZN10atpqc_cuda14verify_cmov_ws6global11verify_cmovEPhmPKhmmS4_mS4_mmjPhmPKhmmS1_mS1_mmj
	.globl	_ZN10atpqc_cuda14verify_cmov_ws6global11verify_cmovEPhmPKhmmS4_mS4_mmj
	.type	_ZN10atpqc_cuda14verify_cmov_ws6global11verify_cmovEPhmPKhmmS4_mS4_mmj, @function
_ZN10atpqc_cuda14verify_cmov_ws6global11verify_cmovEPhmPKhmmS4_mS4_mmj:
.LFB2047:
	.cfi_startproc
	endbr64
	jmp	_Z84__device_stub__ZN10atpqc_cuda14verify_cmov_ws6global11verify_cmovEPhmPKhmmS4_mS4_mmjPhmPKhmmS1_mS1_mmj
	.cfi_endproc
.LFE2047:
	.size	_ZN10atpqc_cuda14verify_cmov_ws6global11verify_cmovEPhmPKhmmS4_mS4_mmj, .-_ZN10atpqc_cuda14verify_cmov_ws6global11verify_cmovEPhmPKhmmS4_mS4_mmj
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"_ZN10atpqc_cuda14verify_cmov_ws6global11verify_cmovEPhmPKhmmS4_mS4_mmj"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2049:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC0(%rip), %rdx
	movq	%rax, %rdi
	leaq	_ZN10atpqc_cuda14verify_cmov_ws6global11verify_cmovEPhmPKhmmS4_mS4_mmj(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2049:
	.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
	.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:

//
// global.cuh
// Kernel header of verifing ciphertext and constant-time copy.
//
// Copyright (c) 2021 Tatsuki Ono
//
// This software is released under the MIT License.
// https://opensource.org/licenses/mit-license.php
//

#ifndef ATPQC_CUDA_LIB_VERIFY_CMOV_WS_GLOBAL_CUH_
#define ATPQC_CUDA_LIB_VERIFY_CMOV_WS_GLOBAL_CUH_

#include <cstddef>
#include <cstdint>

namespace atpqc_cuda::verify_cmov_ws::global {

__global__ void verify_cmov(std::uint8_t* r, std::size_t r_pitch,
                            const std::uint8_t* x, std::size_t x_pitch,
                            std::size_t move_len, const std::uint8_t* a,
                            std::size_t a_pitch, const std::uint8_t* b,
                            std::size_t b_pitch, std::size_t cmp_len,
                            unsigned ninputs);

}

#endif

	.text
	.file	"global.hip"
	.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
