#include <iostream>
using namespace std;
#define L 1e-4
#define N_grid 16
#define dx (L/float(N_grid))

void test(float x)
{
    float y = x - floor(x/L)*L;
    cout << x << " " << y << endl;
}
int main()
{
    cout << "L:" << L << endl;
    test(-3*L);
    test(-2*L);
    test(-L);
    test(-0.5*L);
    test(0);
    test(L/2.0);
    test(L);
    test(L*1.5);
    test(3*L);
}

	.file	"tmpxft_00230a30_00000000-6_test_pbc.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3639:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3639:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	" "
	.text
	.globl	_Z4testf
	.type	_Z4testf, @function
_Z4testf:
.LFB3635:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	cvtss2sd	%xmm0, %xmm2
	movaps	%xmm2, %xmm0
	divsd	.LC0(%rip), %xmm0
	movsd	%xmm2, 8(%rsp)
	call	floor@PLT
	mulsd	.LC0(%rip), %xmm0
	movsd	8(%rsp), %xmm2
	leaq	_ZSt4cout(%rip), %rdi
	movaps	%xmm2, %xmm1
	subsd	%xmm0, %xmm1
	movaps	%xmm2, %xmm0
	cvtsd2ss	%xmm1, %xmm1
	movss	%xmm1, 8(%rsp)
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movss	8(%rsp), %xmm1
	movq	%rax, %rdi
	cvtss2sd	%xmm1, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	movq	%rax, %rdi
	jmp	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	.cfi_endproc
.LFE3635:
	.size	_Z4testf, .-_Z4testf
	.section	.rodata.str1.1
.LC2:
	.string	"L:"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3636:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	.LC2(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	.LC0(%rip), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movss	.LC3(%rip), %xmm0
	call	_Z4testf
	movss	.LC4(%rip), %xmm0
	call	_Z4testf
	movss	.LC5(%rip), %xmm0
	call	_Z4testf
	movss	.LC6(%rip), %xmm0
	call	_Z4testf
	xorps	%xmm0, %xmm0
	call	_Z4testf
	movss	.LC8(%rip), %xmm0
	call	_Z4testf
	movss	.LC9(%rip), %xmm0
	call	_Z4testf
	movss	.LC10(%rip), %xmm0
	call	_Z4testf
	movss	.LC11(%rip), %xmm0
	call	_Z4testf
	xorl	%eax, %eax
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3636:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3662:
	.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
.LFE3662:
	.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
.LC0:
	.long	-350469331
	.long	1058682594
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC3:
	.long	-1180874414
	.align 4
.LC4:
	.long	-1185827049
	.align 4
.LC5:
	.long	-1194215657
	.align 4
.LC6:
	.long	-1202604265
	.align 4
.LC8:
	.long	944879383
	.align 4
.LC9:
	.long	953267991
	.align 4
.LC10:
	.long	958220626
	.align 4
.LC11:
	.long	966609234
	.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 <iostream>
using namespace std;
#define L 1e-4
#define N_grid 16
#define dx (L/float(N_grid))

void test(float x)
{
    float y = x - floor(x/L)*L;
    cout << x << " " << y << endl;
}
int main()
{
    cout << "L:" << L << endl;
    test(-3*L);
    test(-2*L);
    test(-L);
    test(-0.5*L);
    test(0);
    test(L/2.0);
    test(L);
    test(L*1.5);
    test(3*L);
}

	.text
	.file	"test_pbc.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z4testf
.LCPI0_0:
	.quad	0x3f1a36e2eb1c432d              # double 1.0E-4
	.text
	.globl	_Z4testf
	.type	_Z4testf,@function
_Z4testf:                               # @_Z4testf
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	cvtss2sd	%xmm0, %xmm0
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	divsd	.LCPI0_0(%rip), %xmm0
	callq	floor@PLT
	mulsd	.LCPI0_0(%rip), %xmm0
	movsd	8(%rsp), %xmm2                  # 8-byte Reload
                                        # xmm2 = mem[0],zero
	movapd	%xmm2, %xmm1
	subsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	movl	$_ZSt4cout, %edi
	movapd	%xmm2, %xmm0
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movl	$.L.str, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorps	%xmm0, %xmm0
	cvtss2sd	4(%rsp), %xmm0                  # 4-byte Folded Reload
	movq	%rbx, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	_ZNSo5flushEv                   # TAILCALL
.Lfunc_end0:
	.size	_Z4testf, .Lfunc_end0-_Z4testf
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI1_0:
	.quad	0x3f1a36e2eb1c432d              # double 1.0E-4
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI1_1:
	.long	0xb99d4952                      # float -3.00000014E-4
.LCPI1_2:
	.long	0xb951b717                      # float -1.99999995E-4
.LCPI1_3:
	.long	0xb8d1b717                      # float -9.99999974E-5
.LCPI1_4:
	.long	0xb851b717                      # float -4.99999987E-5
.LCPI1_5:
	.long	0x3851b717                      # float 4.99999987E-5
.LCPI1_6:
	.long	0x38d1b717                      # float 9.99999974E-5
.LCPI1_7:
	.long	0x391d4952                      # float 1.50000007E-4
.LCPI1_8:
	.long	0x399d4952                      # float 3.00000014E-4
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$2, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movsd	.LCPI1_0(%rip), %xmm0           # xmm0 = mem[0],zero
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movss	.LCPI1_1(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	callq	_Z4testf
	movss	.LCPI1_2(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	callq	_Z4testf
	movss	.LCPI1_3(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	callq	_Z4testf
	movss	.LCPI1_4(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	callq	_Z4testf
	xorps	%xmm0, %xmm0
	callq	_Z4testf
	movss	.LCPI1_5(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	callq	_Z4testf
	movss	.LCPI1_6(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	callq	_Z4testf
	movss	.LCPI1_7(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	callq	_Z4testf
	movss	.LCPI1_8(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	callq	_Z4testf
	xorl	%eax, %eax
	popq	%rbx
	.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	" "
	.size	.L.str, 2

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"L:"
	.size	.L.str.1, 3

	.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 _ZSt4cout
	.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
