// filename: freduce.cu

#include <stdint.h>

//======================================================================
#ifdef __CUDA__ 
__device__ __host__
#endif
void reduce_hash(uint32_t H[], uint8_t B[], uint32_t link_idx);

//======================================================================
#ifdef __CUDA__ 
__device__ __host__
#endif
void reduce_hash(uint32_t H[], uint8_t B[], uint32_t link_idx) {

		uint32_t z;
		uint16_t b0,b1;
		const uint16_t mask = 0xffff;
		
		uint32_t offset = link_idx;
		
		z = H[0] + offset;
		b0 = (uint16_t)(z & mask);
		B[0] = (b0 % 26) + 'A';
		z >>= 16;
		b1 = (uint16_t)(z & mask);
		B[1] = (b1 % 26) + 'A';

		z = H[1] + offset;
		b0 = (uint16_t)(z & mask);
		B[2] = (b0 % 10) + '0';
		z >>= 16;
		b1 = (uint16_t)(z & mask);
		B[3] = (b1 % 10) + '0';

		z = H[2] + offset;
		b0 = (uint16_t)(z & mask);
		B[4] = (b0 % 26) + 'a';
		z >>= 16;
		b1 = (uint16_t)(z & mask);
		B[5] = (b1 % 26) + 'a';
	
		z = H[3] + offset;
		b0 = (uint16_t)(z & mask);
		B[6] = (b0 % 26) + 'A';
		B[7] = '\0';
}
//=============================================================================

	.file	"tmpxft_003647b5_00000000-6_freduce.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2011:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2011:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z11reduce_hashPjPhj
	.type	_Z11reduce_hashPjPhj, @function
_Z11reduce_hashPjPhj:
.LFB2008:
	.cfi_startproc
	endbr64
	movl	(%rdi), %r8d
	movq	%rsi, %rcx
	movq	%rdi, %r9
	movl	%edx, %esi
	movl	$26, %edi
	movl	$10, %r10d
	addl	%edx, %r8d
	xorl	%edx, %edx
	movl	%r8d, %eax
	shrl	$16, %r8d
	divw	%di
	movl	%r8d, %eax
	addl	$65, %edx
	movb	%dl, (%rcx)
	xorl	%edx, %edx
	divw	%di
	addl	$65, %edx
	movb	%dl, 1(%rcx)
	movl	4(%r9), %r8d
	xorl	%edx, %edx
	addl	%esi, %r8d
	movl	%r8d, %eax
	shrl	$16, %r8d
	divw	%r10w
	movl	%r8d, %eax
	addl	$48, %edx
	movb	%dl, 2(%rcx)
	xorl	%edx, %edx
	divw	%r10w
	addl	$48, %edx
	movb	%dl, 3(%rcx)
	movl	8(%r9), %r8d
	xorl	%edx, %edx
	addl	%esi, %r8d
	movl	%r8d, %eax
	shrl	$16, %r8d
	divw	%di
	movl	%r8d, %eax
	addl	$97, %edx
	movb	%dl, 4(%rcx)
	xorl	%edx, %edx
	divw	%di
	movl	%esi, %eax
	addl	$97, %edx
	movb	%dl, 5(%rcx)
	xorl	%edx, %edx
	addl	12(%r9), %eax
	divw	%di
	movb	$0, 7(%rcx)
	addl	$65, %edx
	movb	%dl, 6(%rcx)
	ret
	.cfi_endproc
.LFE2008:
	.size	_Z11reduce_hashPjPhj, .-_Z11reduce_hashPjPhj
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2034:
	.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
.LFE2034:
	.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:

// filename: freduce.cu


#include <hip/hip_runtime.h>
#include <stdint.h>

//======================================================================
#ifdef __CUDA__ 
__device__ __host__
#endif
void reduce_hash(uint32_t H[], uint8_t B[], uint32_t link_idx);

//======================================================================
#ifdef __CUDA__ 
__device__ __host__
#endif
void reduce_hash(uint32_t H[], uint8_t B[], uint32_t link_idx) {

		uint32_t z;
		uint16_t b0,b1;
		const uint16_t mask = 0xffff;
		
		uint32_t offset = link_idx;
		
		z = H[0] + offset;
		b0 = (uint16_t)(z & mask);
		B[0] = (b0 % 26) + 'A';
		z >>= 16;
		b1 = (uint16_t)(z & mask);
		B[1] = (b1 % 26) + 'A';

		z = H[1] + offset;
		b0 = (uint16_t)(z & mask);
		B[2] = (b0 % 10) + '0';
		z >>= 16;
		b1 = (uint16_t)(z & mask);
		B[3] = (b1 % 10) + '0';

		z = H[2] + offset;
		b0 = (uint16_t)(z & mask);
		B[4] = (b0 % 26) + 'a';
		z >>= 16;
		b1 = (uint16_t)(z & mask);
		B[5] = (b1 % 26) + 'a';
	
		z = H[3] + offset;
		b0 = (uint16_t)(z & mask);
		B[6] = (b0 % 26) + 'A';
		B[7] = '\0';
}
//=============================================================================

	.text
	.file	"freduce.hip"
	.globl	_Z11reduce_hashPjPhj            # -- Begin function _Z11reduce_hashPjPhj
	.type	_Z11reduce_hashPjPhj,@function
_Z11reduce_hashPjPhj:                   # @_Z11reduce_hashPjPhj
	.cfi_startproc
# %bb.0:
	movl	(%rdi), %ecx
	addl	%edx, %ecx
	movl	$65535, %eax                    # imm = 0xFFFF
	movl	%ecx, %r8d
	andl	%eax, %r8d
	imull	$20165, %r8d, %r8d              # imm = 0x4EC5
	shrl	$19, %r8d
	leal	(%r8,%r8,4), %r9d
	leal	(%r9,%r9,4), %r9d
	addl	%r8d, %r9d
	movl	%ecx, %r8d
	subl	%r9d, %r8d
	addb	$65, %r8b
	movb	%r8b, (%rsi)
	shrl	$16, %ecx
	imull	$20165, %ecx, %r8d              # imm = 0x4EC5
	shrl	$19, %r8d
	leal	(%r8,%r8,4), %r9d
	leal	(%r9,%r9,4), %r9d
	addl	%r8d, %r9d
	subl	%r9d, %ecx
	addb	$65, %cl
	movb	%cl, 1(%rsi)
	movl	4(%rdi), %ecx
	addl	%edx, %ecx
	movl	%ecx, %r8d
	andl	%eax, %r8d
	imull	$52429, %r8d, %r8d              # imm = 0xCCCD
	shrl	$18, %r8d
	andl	$-2, %r8d
	leal	(%r8,%r8,4), %r8d
	movl	%ecx, %r9d
	subl	%r8d, %r9d
	orb	$48, %r9b
	movb	%r9b, 2(%rsi)
	shrl	$16, %ecx
	imull	$52429, %ecx, %r8d              # imm = 0xCCCD
	shrl	$18, %r8d
	andl	$-2, %r8d
	leal	(%r8,%r8,4), %r8d
	subl	%r8d, %ecx
	orb	$48, %cl
	movb	%cl, 3(%rsi)
	movl	8(%rdi), %ecx
	addl	%edx, %ecx
	movl	%ecx, %r8d
	andl	%eax, %r8d
	imull	$20165, %r8d, %r8d              # imm = 0x4EC5
	shrl	$19, %r8d
	leal	(%r8,%r8,4), %r9d
	leal	(%r9,%r9,4), %r9d
	addl	%r8d, %r9d
	movl	%ecx, %r8d
	subl	%r9d, %r8d
	addb	$97, %r8b
	movb	%r8b, 4(%rsi)
	shrl	$16, %ecx
	imull	$20165, %ecx, %r8d              # imm = 0x4EC5
	shrl	$19, %r8d
	leal	(%r8,%r8,4), %r9d
	leal	(%r9,%r9,4), %r9d
	addl	%r8d, %r9d
	subl	%r9d, %ecx
	addb	$97, %cl
	movb	%cl, 5(%rsi)
	addl	12(%rdi), %edx
	andl	%edx, %eax
	imull	$20165, %eax, %eax              # imm = 0x4EC5
	shrl	$19, %eax
	leal	(%rax,%rax,4), %ecx
	leal	(%rcx,%rcx,4), %ecx
	addl	%eax, %ecx
	subl	%ecx, %edx
	addb	$65, %dl
	movb	%dl, 6(%rsi)
	movb	$0, 7(%rsi)
	retq
.Lfunc_end0:
	.size	_Z11reduce_hashPjPhj, .Lfunc_end0-_Z11reduce_hashPjPhj
	.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
