#include "xorshift.hh"

namespace xorshift
{

    namespace
    {
        std::uint64_t s[4];
    }

    void seed(std::uint64_t x)
    {
        s[0] = 1000*x;
        s[1] = 2000*x;
        s[2] = 3000*x;
        s[3] = 4000*x;
    }
    
    std::uint64_t next_u64()
    {
        std::uint64_t t = s[0] ^ (s[0] << 11);
        s[0] = s[1];
        s[1] = s[2];
        s[2] = s[3];
        s[3] = s[3] ^ (s[3] >> 19) ^ t ^ (t >> 8);
        return s[3];
    }

    float next_f32()
    {
        float x = next_u64();
        float div = 0xFFFFFFFFFFFFFFFF;
        return x / div;
    }

    void fill(float* begin, float* end)
    {
        while (begin != end)
            *begin++ = next_f32();
    }
    

    /*
        std::uint64_t x = s[0];
        std::uint64_t y = s[1];
	s[0] = y;
	x ^= x << 23; // a
	s[1] = x ^ y ^ (x >> 17) ^ (y >> 26); // b, c
	return s[1] + y;
    */
}

	.file	"tmpxft_0037457a_00000000-6_xorshift.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2014:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2014:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_ZN8xorshift4seedEm
	.type	_ZN8xorshift4seedEm, @function
_ZN8xorshift4seedEm:
.LFB2008:
	.cfi_startproc
	endbr64
	imulq	$1000, %rdi, %rax
	movq	%rax, _ZN8xorshift44_GLOBAL__N__8f892508_11_xorshift_cu_f81a6a7d1sE(%rip)
	imulq	$2000, %rdi, %rax
	movq	%rax, 8+_ZN8xorshift44_GLOBAL__N__8f892508_11_xorshift_cu_f81a6a7d1sE(%rip)
	imulq	$3000, %rdi, %rax
	imulq	$4000, %rdi, %rdi
	movq	%rax, 16+_ZN8xorshift44_GLOBAL__N__8f892508_11_xorshift_cu_f81a6a7d1sE(%rip)
	movq	%rdi, 24+_ZN8xorshift44_GLOBAL__N__8f892508_11_xorshift_cu_f81a6a7d1sE(%rip)
	ret
	.cfi_endproc
.LFE2008:
	.size	_ZN8xorshift4seedEm, .-_ZN8xorshift4seedEm
	.globl	_ZN8xorshift8next_u64Ev
	.type	_ZN8xorshift8next_u64Ev, @function
_ZN8xorshift8next_u64Ev:
.LFB2009:
	.cfi_startproc
	endbr64
	movq	_ZN8xorshift44_GLOBAL__N__8f892508_11_xorshift_cu_f81a6a7d1sE(%rip), %rax
	movq	24+_ZN8xorshift44_GLOBAL__N__8f892508_11_xorshift_cu_f81a6a7d1sE(%rip), %rcx
	movq	%rax, %rdx
	salq	$11, %rdx
	xorq	%rax, %rdx
	movq	8+_ZN8xorshift44_GLOBAL__N__8f892508_11_xorshift_cu_f81a6a7d1sE(%rip), %rax
	movq	%rax, _ZN8xorshift44_GLOBAL__N__8f892508_11_xorshift_cu_f81a6a7d1sE(%rip)
	movq	16+_ZN8xorshift44_GLOBAL__N__8f892508_11_xorshift_cu_f81a6a7d1sE(%rip), %rax
	movq	%rcx, 16+_ZN8xorshift44_GLOBAL__N__8f892508_11_xorshift_cu_f81a6a7d1sE(%rip)
	movq	%rax, 8+_ZN8xorshift44_GLOBAL__N__8f892508_11_xorshift_cu_f81a6a7d1sE(%rip)
	movq	%rcx, %rax
	shrq	$19, %rax
	xorq	%rcx, %rax
	xorq	%rdx, %rax
	shrq	$8, %rdx
	xorq	%rdx, %rax
	movq	%rax, 24+_ZN8xorshift44_GLOBAL__N__8f892508_11_xorshift_cu_f81a6a7d1sE(%rip)
	ret
	.cfi_endproc
.LFE2009:
	.size	_ZN8xorshift8next_u64Ev, .-_ZN8xorshift8next_u64Ev
	.globl	_ZN8xorshift8next_f32Ev
	.type	_ZN8xorshift8next_f32Ev, @function
_ZN8xorshift8next_f32Ev:
.LFB2010:
	.cfi_startproc
	endbr64
	call	_ZN8xorshift8next_u64Ev
	testq	%rax, %rax
	js	.L5
	cvtsi2ssq	%rax, %xmm0
	jmp	.L6
.L5:
	movq	%rax, %rdx
	andl	$1, %eax
	shrq	%rdx
	orq	%rax, %rdx
	cvtsi2ssq	%rdx, %xmm0
	addss	%xmm0, %xmm0
.L6:
	mulss	.LC0(%rip), %xmm0
	ret
	.cfi_endproc
.LFE2010:
	.size	_ZN8xorshift8next_f32Ev, .-_ZN8xorshift8next_f32Ev
	.globl	_ZN8xorshift4fillEPfS0_
	.type	_ZN8xorshift4fillEPfS0_, @function
_ZN8xorshift4fillEPfS0_:
.LFB2011:
	.cfi_startproc
	endbr64
.L9:
	cmpq	%rsi, %rdi
	je	.L11
	call	_ZN8xorshift8next_f32Ev
	addq	$4, %rdi
	movss	%xmm0, -4(%rdi)
	jmp	.L9
.L11:
	ret
	.cfi_endproc
.LFE2011:
	.size	_ZN8xorshift4fillEPfS0_, .-_ZN8xorshift4fillEPfS0_
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2037:
	.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
.LFE2037:
	.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
	.hidden	_ZN8xorshift44_GLOBAL__N__8f892508_11_xorshift_cu_f81a6a7d1sE
	.globl	_ZN8xorshift44_GLOBAL__N__8f892508_11_xorshift_cu_f81a6a7d1sE
	.bss
	.align 32
	.type	_ZN8xorshift44_GLOBAL__N__8f892508_11_xorshift_cu_f81a6a7d1sE, @object
	.size	_ZN8xorshift44_GLOBAL__N__8f892508_11_xorshift_cu_f81a6a7d1sE, 32
_ZN8xorshift44_GLOBAL__N__8f892508_11_xorshift_cu_f81a6a7d1sE:
	.zero	32
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	528482304
	.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 "xorshift.hh"

namespace xorshift
{

    namespace
    {
        std::uint64_t s[4];
    }

    void seed(std::uint64_t x)
    {
        s[0] = 1000*x;
        s[1] = 2000*x;
        s[2] = 3000*x;
        s[3] = 4000*x;
    }
    
    std::uint64_t next_u64()
    {
        std::uint64_t t = s[0] ^ (s[0] << 11);
        s[0] = s[1];
        s[1] = s[2];
        s[2] = s[3];
        s[3] = s[3] ^ (s[3] >> 19) ^ t ^ (t >> 8);
        return s[3];
    }

    float next_f32()
    {
        float x = next_u64();
        float div = 0xFFFFFFFFFFFFFFFF;
        return x / div;
    }

    void fill(float* begin, float* end)
    {
        while (begin != end)
            *begin++ = next_f32();
    }
    

    /*
        std::uint64_t x = s[0];
        std::uint64_t y = s[1];
	s[0] = y;
	x ^= x << 23; // a
	s[1] = x ^ y ^ (x >> 17) ^ (y >> 26); // b, c
	return s[1] + y;
    */
}

	.text
	.file	"xorshift.hip"
	.globl	_ZN8xorshift4seedEm             # -- Begin function _ZN8xorshift4seedEm
	.type	_ZN8xorshift4seedEm,@function
_ZN8xorshift4seedEm:                    # @_ZN8xorshift4seedEm
	.cfi_startproc
# %bb.0:
	imulq	$1000, %rdi, %rax               # imm = 0x3E8
	movq	%rax, _ZN8xorshift12_GLOBAL__N_11sE.0(%rip)
	imulq	$2000, %rdi, %rax               # imm = 0x7D0
	movq	%rax, _ZN8xorshift12_GLOBAL__N_11sE.1(%rip)
	imulq	$3000, %rdi, %rax               # imm = 0xBB8
	movq	%rax, _ZN8xorshift12_GLOBAL__N_11sE.2(%rip)
	imulq	$4000, %rdi, %rax               # imm = 0xFA0
	movq	%rax, _ZN8xorshift12_GLOBAL__N_11sE.3(%rip)
	retq
.Lfunc_end0:
	.size	_ZN8xorshift4seedEm, .Lfunc_end0-_ZN8xorshift4seedEm
	.cfi_endproc
                                        # -- End function
	.globl	_ZN8xorshift8next_u64Ev         # -- Begin function _ZN8xorshift8next_u64Ev
	.type	_ZN8xorshift8next_u64Ev,@function
_ZN8xorshift8next_u64Ev:                # @_ZN8xorshift8next_u64Ev
	.cfi_startproc
# %bb.0:
	movq	_ZN8xorshift12_GLOBAL__N_11sE.0(%rip), %rcx
	movq	%rcx, %rax
	shlq	$11, %rax
	xorq	%rcx, %rax
	movq	_ZN8xorshift12_GLOBAL__N_11sE.1(%rip), %rcx
	movq	%rcx, _ZN8xorshift12_GLOBAL__N_11sE.0(%rip)
	movq	_ZN8xorshift12_GLOBAL__N_11sE.2(%rip), %rcx
	movq	%rcx, _ZN8xorshift12_GLOBAL__N_11sE.1(%rip)
	movq	_ZN8xorshift12_GLOBAL__N_11sE.3(%rip), %rcx
	movq	%rcx, _ZN8xorshift12_GLOBAL__N_11sE.2(%rip)
	movq	%rcx, %rdx
	shrq	$19, %rdx
	xorq	%rax, %rdx
	shrq	$8, %rax
	xorq	%rdx, %rax
	xorq	%rcx, %rax
	movq	%rax, _ZN8xorshift12_GLOBAL__N_11sE.3(%rip)
	retq
.Lfunc_end1:
	.size	_ZN8xorshift8next_u64Ev, .Lfunc_end1-_ZN8xorshift8next_u64Ev
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _ZN8xorshift8next_f32Ev
.LCPI2_0:
	.long	0x1f800000                      # float 5.42101086E-20
	.text
	.globl	_ZN8xorshift8next_f32Ev
	.type	_ZN8xorshift8next_f32Ev,@function
_ZN8xorshift8next_f32Ev:                # @_ZN8xorshift8next_f32Ev
	.cfi_startproc
# %bb.0:
	movq	_ZN8xorshift12_GLOBAL__N_11sE.0(%rip), %rcx
	movq	%rcx, %rax
	shlq	$11, %rax
	xorq	%rcx, %rax
	movq	_ZN8xorshift12_GLOBAL__N_11sE.1(%rip), %rcx
	movq	%rcx, _ZN8xorshift12_GLOBAL__N_11sE.0(%rip)
	movq	_ZN8xorshift12_GLOBAL__N_11sE.2(%rip), %rcx
	movq	%rcx, _ZN8xorshift12_GLOBAL__N_11sE.1(%rip)
	movq	_ZN8xorshift12_GLOBAL__N_11sE.3(%rip), %rcx
	movq	%rcx, _ZN8xorshift12_GLOBAL__N_11sE.2(%rip)
	movq	%rcx, %rdx
	shrq	$19, %rdx
	xorq	%rax, %rdx
	shrq	$8, %rax
	xorq	%rdx, %rax
	xorq	%rcx, %rax
	movq	%rax, _ZN8xorshift12_GLOBAL__N_11sE.3(%rip)
	js	.LBB2_1
# %bb.2:
	cvtsi2ss	%rax, %xmm0
	jmp	.LBB2_3
.LBB2_1:
	movq	%rax, %rcx
	shrq	%rcx
	andl	$1, %eax
	orq	%rcx, %rax
	cvtsi2ss	%rax, %xmm0
	addss	%xmm0, %xmm0
.LBB2_3:
	mulss	.LCPI2_0(%rip), %xmm0
	retq
.Lfunc_end2:
	.size	_ZN8xorshift8next_f32Ev, .Lfunc_end2-_ZN8xorshift8next_f32Ev
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _ZN8xorshift4fillEPfS0_
.LCPI3_0:
	.long	0x1f800000                      # float 5.42101086E-20
	.text
	.globl	_ZN8xorshift4fillEPfS0_
	.type	_ZN8xorshift4fillEPfS0_,@function
_ZN8xorshift4fillEPfS0_:                # @_ZN8xorshift4fillEPfS0_
	.cfi_startproc
# %bb.0:
	cmpq	%rsi, %rdi
	je	.LBB3_7
# %bb.1:                                # %.lr.ph.preheader
	movq	_ZN8xorshift12_GLOBAL__N_11sE.3(%rip), %rax
	movq	_ZN8xorshift12_GLOBAL__N_11sE.2(%rip), %r11
	movq	_ZN8xorshift12_GLOBAL__N_11sE.1(%rip), %r10
	movq	_ZN8xorshift12_GLOBAL__N_11sE.0(%rip), %r9
	movss	.LCPI3_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
.LBB3_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	%rax, %rcx
	movq	%r11, %rdx
	movq	%r10, %r8
	movq	%r9, %rax
	shlq	$11, %rax
	xorq	%r9, %rax
	movq	%rcx, %r9
	shrq	$19, %r9
	xorq	%rax, %r9
	shrq	$8, %rax
	xorq	%r9, %rax
	xorq	%rcx, %rax
	js	.LBB3_3
# %bb.4:                                # %.lr.ph
                                        #   in Loop: Header=BB3_2 Depth=1
	xorps	%xmm1, %xmm1
	cvtsi2ss	%rax, %xmm1
	jmp	.LBB3_5
.LBB3_3:                                #   in Loop: Header=BB3_2 Depth=1
	movq	%rax, %r9
	shrq	%r9
	movl	%eax, %r10d
	andl	$1, %r10d
	orq	%r9, %r10
	xorps	%xmm1, %xmm1
	cvtsi2ss	%r10, %xmm1
	addss	%xmm1, %xmm1
.LBB3_5:                                # %.lr.ph
                                        #   in Loop: Header=BB3_2 Depth=1
	mulss	%xmm0, %xmm1
	movss	%xmm1, (%rdi)
	addq	$4, %rdi
	movq	%r8, %r9
	movq	%rdx, %r10
	movq	%rcx, %r11
	cmpq	%rsi, %rdi
	jne	.LBB3_2
# %bb.6:                                # %._crit_edge
	movq	%r8, _ZN8xorshift12_GLOBAL__N_11sE.0(%rip)
	movq	%rdx, _ZN8xorshift12_GLOBAL__N_11sE.1(%rip)
	movq	%rcx, _ZN8xorshift12_GLOBAL__N_11sE.2(%rip)
	movq	%rax, _ZN8xorshift12_GLOBAL__N_11sE.3(%rip)
.LBB3_7:
	retq
.Lfunc_end3:
	.size	_ZN8xorshift4fillEPfS0_, .Lfunc_end3-_ZN8xorshift4fillEPfS0_
	.cfi_endproc
                                        # -- End function
	.type	_ZN8xorshift12_GLOBAL__N_11sE.0,@object # @_ZN8xorshift12_GLOBAL__N_11sE.0
	.local	_ZN8xorshift12_GLOBAL__N_11sE.0
	.comm	_ZN8xorshift12_GLOBAL__N_11sE.0,8,16
	.type	_ZN8xorshift12_GLOBAL__N_11sE.1,@object # @_ZN8xorshift12_GLOBAL__N_11sE.1
	.local	_ZN8xorshift12_GLOBAL__N_11sE.1
	.comm	_ZN8xorshift12_GLOBAL__N_11sE.1,8,16
	.type	_ZN8xorshift12_GLOBAL__N_11sE.2,@object # @_ZN8xorshift12_GLOBAL__N_11sE.2
	.local	_ZN8xorshift12_GLOBAL__N_11sE.2
	.comm	_ZN8xorshift12_GLOBAL__N_11sE.2,8,16
	.type	_ZN8xorshift12_GLOBAL__N_11sE.3,@object # @_ZN8xorshift12_GLOBAL__N_11sE.3
	.local	_ZN8xorshift12_GLOBAL__N_11sE.3
	.comm	_ZN8xorshift12_GLOBAL__N_11sE.3,8,16
	.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
