/******************************************************************************
 This function converts HSV values to RGB values, scaled from 0 to maxBrightness

 The ranges for the input variables are:
 hue: 0-360
 sat: 0-255
 lig: 0-255

 The ranges for the output variables are:
 r: 0-maxBrightness
 g: 0-maxBrightness
 b: 0-maxBrightness

 r,g, and b are passed as pointers, because a function cannot have 3 return variables
 Use it like this:
 int hue, sat, val;
 unsigned char red, green, blue;
 // set hue, sat and val
 hsv2rgb(hue, sat, val, &red, &green, &blue, maxBrightness); //pass r, g, and b as the location where the result should be stored
 // use r, b and g.

 (c) Elco Jacobs, E-atelier Industrial Design TU/e, July 2011.

 *****************************************************************************/

__device__ void hsv2rgb(unsigned int hue, unsigned int sat, unsigned int val, unsigned char * r, unsigned char * g, unsigned char * b,
		unsigned char maxBrightness) {

	if (val > 255) val = 255;

	unsigned int H_accent = hue / 60;
	unsigned int bottom = ((255 - sat) * val) >> 8;
	unsigned int top = val;
	unsigned char rising = ((top - bottom) * (hue % 60)) / 60 + bottom;
	unsigned char falling = ((top - bottom) * (60 - hue % 60)) / 60 + bottom;

	switch (H_accent) {
	case 0:
		*r = top;
		*g = rising;
		*b = bottom;
		break;

	case 1:
		*r = falling;
		*g = top;
		*b = bottom;
		break;

	case 2:
		*r = bottom;
		*g = top;
		*b = rising;
		break;

	case 3:
		*r = bottom;
		*g = falling;
		*b = top;
		break;

	case 4:
		*r = rising;
		*g = bottom;
		*b = top;
		break;

	case 5:
		*r = top;
		*g = bottom;
		*b = falling;
		break;
	}
	// Scale values to maxBrightness
	*r = *r * maxBrightness / 255;
	*g = *g * maxBrightness / 255;
	*b = *b * maxBrightness / 255;
}

void hsv2rgbSerial(unsigned int hue, unsigned int sat, unsigned int val, unsigned char * r, unsigned char * g, unsigned char * b,
		unsigned char maxBrightness) {

	if (val > 255) val = 255;

	unsigned int H_accent = hue / 60;
	unsigned int bottom = ((255 - sat) * val) >> 8;
	unsigned int top = val;
	unsigned char rising = ((top - bottom) * (hue % 60)) / 60 + bottom;
	unsigned char falling = ((top - bottom) * (60 - hue % 60)) / 60 + bottom;

	switch (H_accent) {
	case 0:
		*r = top;
		*g = rising;
		*b = bottom;
		break;

	case 1:
		*r = falling;
		*g = top;
		*b = bottom;
		break;

	case 2:
		*r = bottom;
		*g = top;
		*b = rising;
		break;

	case 3:
		*r = bottom;
		*g = falling;
		*b = top;
		break;

	case 4:
		*r = rising;
		*g = bottom;
		*b = top;
		break;

	case 5:
		*r = top;
		*g = bottom;
		*b = falling;
		break;
	}
	// Scale values to maxBrightness
	*r = *r * maxBrightness / 255;
	*g = *g * maxBrightness / 255;
	*b = *b * maxBrightness / 255;
}

	.file	"tmpxft_00371875_00000000-6_color_conversion.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2012:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2012:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z7hsv2rgbjjjPhS_S_h
	.type	_Z7hsv2rgbjjjPhS_S_h, @function
_Z7hsv2rgbjjjPhS_S_h:
.LFB2008:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2008:
	.size	_Z7hsv2rgbjjjPhS_S_h, .-_Z7hsv2rgbjjjPhS_S_h
	.globl	_Z13hsv2rgbSerialjjjPhS_S_h
	.type	_Z13hsv2rgbSerialjjjPhS_S_h, @function
_Z13hsv2rgbSerialjjjPhS_S_h:
.LFB2009:
	.cfi_startproc
	endbr64
	movl	$255, %eax
	movl	%esi, %r10d
	movq	%rcx, %rsi
	movl	$255, %ecx
	cmpl	%eax, %edx
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$60, %r11d
	cmovbe	%edx, %eax
	subl	%r10d, %ecx
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	xorl	%edx, %edx
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	imull	%eax, %ecx
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movl	%eax, %r12d
	movl	%eax, %ebx
	movl	%edi, %eax
	movl	40(%rsp), %ebp
	divl	%r11d
	shrl	$8, %ecx
	subl	%ecx, %r12d
	movl	%eax, %edi
	movl	%r12d, %eax
	movl	%edx, %r13d
	imull	%edx, %eax
	xorl	%edx, %edx
	divl	%r11d
	xorl	%edx, %edx
	leal	(%rcx,%rax), %r10d
	movl	%r11d, %eax
	subl	%r13d, %eax
	imull	%r12d, %eax
	divl	%r11d
	leal	(%rcx,%rax), %edx
	cmpl	$5, %edi
	ja	.L5
	leaq	.L7(%rip), %r11
	movslq	(%r11,%rdi,4), %rax
	addq	%r11, %rax
	notrack jmp	*%rax
	.section	.rodata
	.align 4
	.align 4
.L7:
	.long	.L12-.L7
	.long	.L11-.L7
	.long	.L10-.L7
	.long	.L9-.L7
	.long	.L8-.L7
	.long	.L6-.L7
	.text
.L12:
	movb	%bl, (%rsi)
	movb	%r10b, (%r8)
	jmp	.L14
.L11:
	movb	%dl, (%rsi)
	movb	%bl, (%r8)
.L14:
	movb	%cl, (%r9)
	jmp	.L5
.L10:
	movb	%cl, (%rsi)
	movb	%bl, (%r8)
	movb	%r10b, (%r9)
	jmp	.L5
.L9:
	movb	%cl, (%rsi)
	movb	%dl, (%r8)
	jmp	.L15
.L8:
	movb	%r10b, (%rsi)
	movb	%cl, (%r8)
.L15:
	movb	%bl, (%r9)
	jmp	.L5
.L6:
	movb	%bl, (%rsi)
	movb	%cl, (%r8)
	movb	%dl, (%r9)
.L5:
	movzbl	(%rsi), %eax
	movzbl	%bpl, %ebp
	movl	$255, %ecx
	popq	%rbx
	.cfi_def_cfa_offset 32
	imull	%ebp, %eax
	cltd
	idivl	%ecx
	movb	%al, (%rsi)
	movzbl	(%r8), %eax
	imull	%ebp, %eax
	cltd
	idivl	%ecx
	movb	%al, (%r8)
	movzbl	(%r9), %eax
	imull	%ebp, %eax
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	cltd
	idivl	%ecx
	movb	%al, (%r9)
	ret
	.cfi_endproc
.LFE2009:
	.size	_Z13hsv2rgbSerialjjjPhS_S_h, .-_Z13hsv2rgbSerialjjjPhS_S_h
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2035:
	.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
.LFE2035:
	.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:


#include <hip/hip_runtime.h>
/******************************************************************************
 This function converts HSV values to RGB values, scaled from 0 to maxBrightness

 The ranges for the input variables are:
 hue: 0-360
 sat: 0-255
 lig: 0-255

 The ranges for the output variables are:
 r: 0-maxBrightness
 g: 0-maxBrightness
 b: 0-maxBrightness

 r,g, and b are passed as pointers, because a function cannot have 3 return variables
 Use it like this:
 int hue, sat, val;
 unsigned char red, green, blue;
 // set hue, sat and val
 hsv2rgb(hue, sat, val, &red, &green, &blue, maxBrightness); //pass r, g, and b as the location where the result should be stored
 // use r, b and g.

 (c) Elco Jacobs, E-atelier Industrial Design TU/e, July 2011.

 *****************************************************************************/

__device__ void hsv2rgb(unsigned int hue, unsigned int sat, unsigned int val, unsigned char * r, unsigned char * g, unsigned char * b,
		unsigned char maxBrightness) {

	if (val > 255) val = 255;

	unsigned int H_accent = hue / 60;
	unsigned int bottom = ((255 - sat) * val) >> 8;
	unsigned int top = val;
	unsigned char rising = ((top - bottom) * (hue % 60)) / 60 + bottom;
	unsigned char falling = ((top - bottom) * (60 - hue % 60)) / 60 + bottom;

	switch (H_accent) {
	case 0:
		*r = top;
		*g = rising;
		*b = bottom;
		break;

	case 1:
		*r = falling;
		*g = top;
		*b = bottom;
		break;

	case 2:
		*r = bottom;
		*g = top;
		*b = rising;
		break;

	case 3:
		*r = bottom;
		*g = falling;
		*b = top;
		break;

	case 4:
		*r = rising;
		*g = bottom;
		*b = top;
		break;

	case 5:
		*r = top;
		*g = bottom;
		*b = falling;
		break;
	}
	// Scale values to maxBrightness
	*r = *r * maxBrightness / 255;
	*g = *g * maxBrightness / 255;
	*b = *b * maxBrightness / 255;
}

void hsv2rgbSerial(unsigned int hue, unsigned int sat, unsigned int val, unsigned char * r, unsigned char * g, unsigned char * b,
		unsigned char maxBrightness) {

	if (val > 255) val = 255;

	unsigned int H_accent = hue / 60;
	unsigned int bottom = ((255 - sat) * val) >> 8;
	unsigned int top = val;
	unsigned char rising = ((top - bottom) * (hue % 60)) / 60 + bottom;
	unsigned char falling = ((top - bottom) * (60 - hue % 60)) / 60 + bottom;

	switch (H_accent) {
	case 0:
		*r = top;
		*g = rising;
		*b = bottom;
		break;

	case 1:
		*r = falling;
		*g = top;
		*b = bottom;
		break;

	case 2:
		*r = bottom;
		*g = top;
		*b = rising;
		break;

	case 3:
		*r = bottom;
		*g = falling;
		*b = top;
		break;

	case 4:
		*r = rising;
		*g = bottom;
		*b = top;
		break;

	case 5:
		*r = top;
		*g = bottom;
		*b = falling;
		break;
	}
	// Scale values to maxBrightness
	*r = *r * maxBrightness / 255;
	*g = *g * maxBrightness / 255;
	*b = *b * maxBrightness / 255;
}

	.text
	.file	"color_conversion.hip"
	.globl	_Z13hsv2rgbSerialjjjPhS_S_h     # -- Begin function _Z13hsv2rgbSerialjjjPhS_S_h
	.type	_Z13hsv2rgbSerialjjjPhS_S_h,@function
_Z13hsv2rgbSerialjjjPhS_S_h:            # @_Z13hsv2rgbSerialjjjPhS_S_h
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movb	32(%rsp), %al
	movl	$255, %r10d
	cmpl	%r10d, %edx
	cmovael	%r10d, %edx
	movl	%edi, %r11d
	movl	$2290649225, %ebx               # imm = 0x88888889
	imulq	%rbx, %r11
	shrq	$37, %r11
	cmpl	$5, %r11d
	ja	.LBB0_11
# %bb.1:
	subl	%esi, %r10d
	imull	%edx, %r10d
	shrl	$8, %r10d
	movl	%edx, %esi
	subl	%r10d, %esi
	imull	$60, %r11d, %ebp
	subl	%ebp, %edi
	movl	$60, %r14d
	subl	%edi, %r14d
	imull	%esi, %r14d
                                        # kill: def $esi killed $esi def $rsi
	imull	%edi, %esi
	imulq	%rbx, %rsi
	shrq	$37, %rsi
	addl	%r10d, %esi
	imulq	%rbx, %r14
	shrq	$37, %r14
	addl	%r10d, %r14d
	jmpq	*.LJTI0_0(,%r11,8)
.LBB0_2:
	movb	%dl, (%rcx)
	movb	%sil, (%r8)
	jmp	.LBB0_3
.LBB0_4:
	movb	%sil, (%rcx)
	movb	%r10b, (%r8)
	jmp	.LBB0_7
.LBB0_5:
	movb	%r10b, (%rcx)
	movb	%dl, (%r8)
	jmp	.LBB0_10
.LBB0_6:
	movb	%r10b, (%rcx)
	movb	%r14b, (%r8)
.LBB0_7:                                # %.sink.split
	movl	%edx, %esi
	jmp	.LBB0_10
.LBB0_8:
	movb	%r14b, (%rcx)
	movb	%dl, (%r8)
.LBB0_3:                                # %.sink.split
	movl	%r10d, %esi
	jmp	.LBB0_10
.LBB0_9:
	movb	%dl, (%rcx)
	movb	%r10b, (%r8)
	movl	%r14d, %esi
.LBB0_10:                               # %.sink.split
	movb	%sil, (%r9)
.LBB0_11:
	movzbl	(%rcx), %edx
	movzbl	%al, %eax
	imull	%eax, %edx
	imull	$32897, %edx, %edx              # imm = 0x8081
	shrl	$23, %edx
	movb	%dl, (%rcx)
	movzbl	(%r8), %ecx
	imull	%eax, %ecx
	imull	$32897, %ecx, %ecx              # imm = 0x8081
	shrl	$23, %ecx
	movb	%cl, (%r8)
	movzbl	(%r9), %ecx
	imull	%eax, %ecx
	imull	$32897, %ecx, %eax              # imm = 0x8081
	shrl	$23, %eax
	movb	%al, (%r9)
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z13hsv2rgbSerialjjjPhS_S_h, .Lfunc_end0-_Z13hsv2rgbSerialjjjPhS_S_h
	.cfi_endproc
	.section	.rodata,"a",@progbits
	.p2align	3, 0x0
.LJTI0_0:
	.quad	.LBB0_2
	.quad	.LBB0_8
	.quad	.LBB0_5
	.quad	.LBB0_6
	.quad	.LBB0_4
	.quad	.LBB0_9
                                        # -- 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
