// File: /workspace/github_cpp_makefile_star2_O2/rossy[P]crossc/SPIRV-Cross/spirv_msl.cpp
// Function: spirv_cross::CompilerMSL::emit_glsl_op(unsigned int, unsigned int, unsigned int, unsigned int const*, unsigned int)
void CompilerMSL::emit_glsl_op(uint32_t result_type, uint32_t id, uint32_t eop, const uint32_t *args, uint32_t count)
{
	GLSLstd450 op = static_cast<GLSLstd450>(eop);

	switch (op)
	{
	case GLSLstd450Atan2:
		emit_binary_func_op(result_type, id, args[0], args[1], "atan2");
		break;
	case GLSLstd450InverseSqrt:
		emit_unary_func_op(result_type, id, args[0], "rsqrt");
		break;
	case GLSLstd450RoundEven:
		emit_unary_func_op(result_type, id, args[0], "rint");
		break;

	case GLSLstd450FindSMsb:
		emit_unary_func_op(result_type, id, args[0], "findSMSB");
		break;
	case GLSLstd450FindUMsb:
		emit_unary_func_op(result_type, id, args[0], "findUMSB");
		break;

	case GLSLstd450PackSnorm4x8:
		emit_unary_func_op(result_type, id, args[0], "pack_float_to_snorm4x8");
		break;
	case GLSLstd450PackUnorm4x8:
		emit_unary_func_op(result_type, id, args[0], "pack_float_to_unorm4x8");
		break;
	case GLSLstd450PackSnorm2x16:
		emit_unary_func_op(result_type, id, args[0], "pack_float_to_snorm2x16");
		break;
	case GLSLstd450PackUnorm2x16:
		emit_unary_func_op(result_type, id, args[0], "pack_float_to_unorm2x16");
		break;

	case GLSLstd450PackHalf2x16:
	{
		auto expr = join("as_type<uint>(half2(", to_expression(args[0]), "))");
		emit_op(result_type, id, expr, should_forward(args[0]));
		inherit_expression_dependencies(id, args[0]);
		break;
	}

	case GLSLstd450UnpackSnorm4x8:
		emit_unary_func_op(result_type, id, args[0], "unpack_snorm4x8_to_float");
		break;
	case GLSLstd450UnpackUnorm4x8:
		emit_unary_func_op(result_type, id, args[0], "unpack_unorm4x8_to_float");
		break;
	case GLSLstd450UnpackSnorm2x16:
		emit_unary_func_op(result_type, id, args[0], "unpack_snorm2x16_to_float");
		break;
	case GLSLstd450UnpackUnorm2x16:
		emit_unary_func_op(result_type, id, args[0], "unpack_unorm2x16_to_float");
		break;

	case GLSLstd450UnpackHalf2x16:
	{
		auto expr = join("float2(as_type<half2>(", to_expression(args[0]), "))");
		emit_op(result_type, id, expr, should_forward(args[0]));
		inherit_expression_dependencies(id, args[0]);
		break;
	}

	case GLSLstd450PackDouble2x32:
		emit_unary_func_op(result_type, id, args[0], "unsupported_GLSLstd450PackDouble2x32"); // Currently unsupported
		break;
	case GLSLstd450UnpackDouble2x32:
		emit_unary_func_op(result_type, id, args[0], "unsupported_GLSLstd450UnpackDouble2x32"); // Currently unsupported
		break;

	case GLSLstd450MatrixInverse:
	{
		auto &mat_type = get<SPIRType>(result_type);
		switch (mat_type.columns)
		{
		case 2:
			emit_unary_func_op(result_type, id, args[0], "spvInverse2x2");
			break;
		case 3:
			emit_unary_func_op(result_type, id, args[0], "spvInverse3x3");
			break;
		case 4:
			emit_unary_func_op(result_type, id, args[0], "spvInverse4x4");
			break;
		default:
			break;
		}
		break;
	}

	case GLSLstd450FMin:
		// If the result type isn't float, don't bother calling the specific
		// precise::/fast:: version. Metal doesn't have those for half and
		// double types.
		if (get<SPIRType>(result_type).basetype != SPIRType::Float)
			emit_binary_func_op(result_type, id, args[0], args[1], "min");
		else
			emit_binary_func_op(result_type, id, args[0], args[1], "fast::min");
		break;

	case GLSLstd450FMax:
		if (get<SPIRType>(result_type).basetype != SPIRType::Float)
			emit_binary_func_op(result_type, id, args[0], args[1], "max");
		else
			emit_binary_func_op(result_type, id, args[0], args[1], "fast::max");
		break;

	case GLSLstd450FClamp:
		// TODO: If args[1] is 0 and args[2] is 1, emit a saturate() call.
		if (get<SPIRType>(result_type).basetype != SPIRType::Float)
			emit_trinary_func_op(result_type, id, args[0], args[1], args[2], "clamp");
		else
			emit_trinary_func_op(result_type, id, args[0], args[1], args[2], "fast::clamp");
		break;

	case GLSLstd450NMin:
		if (get<SPIRType>(result_type).basetype != SPIRType::Float)
			emit_binary_func_op(result_type, id, args[0], args[1], "min");
		else
			emit_binary_func_op(result_type, id, args[0], args[1], "precise::min");
		break;

	case GLSLstd450NMax:
		if (get<SPIRType>(result_type).basetype != SPIRType::Float)
			emit_binary_func_op(result_type, id, args[0], args[1], "max");
		else
			emit_binary_func_op(result_type, id, args[0], args[1], "precise::max");
		break;

	case GLSLstd450NClamp:
		// TODO: If args[1] is 0 and args[2] is 1, emit a saturate() call.
		if (get<SPIRType>(result_type).basetype != SPIRType::Float)
			emit_trinary_func_op(result_type, id, args[0], args[1], args[2], "clamp");
		else
			emit_trinary_func_op(result_type, id, args[0], args[1], args[2], "precise::clamp");
		break;

		// TODO:
		//        GLSLstd450InterpolateAtCentroid (centroid_no_perspective qualifier)
		//        GLSLstd450InterpolateAtSample (sample_no_perspective qualifier)
		//        GLSLstd450InterpolateAtOffset

	default:
		CompilerGLSL::emit_glsl_op(result_type, id, eop, args, count);
		break;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %r8, %r15
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, %r14
leal -0x19(%rcx), %eax
cmpl $0x38, %eax
ja 0x762bb
leaq 0x24885(%rip), %rdx     # 0x9ab24
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
movl (%r15), %ecx
movl 0x4(%r15), %r8d
leaq 0x22df4(%rip), %r9      # 0x990aa
jmp 0x7659a
cmpl $0x2, %ecx
jne 0x762cf
movl (%r15), %ecx
leaq 0x27454(%rip), %r8      # 0x9d71e
jmp 0x7655b
movq %r14, %rdi
movl %ebp, %esi
movl %ebx, %edx
movq %r15, %r8
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x32812
movl (%r15), %ecx
leaq 0x274cd(%rip), %r8      # 0x9d7c1
jmp 0x7655b
movl (%r15), %ecx
leaq 0x27420(%rip), %r8      # 0x9d723
jmp 0x7655b
movl (%r15), %edx
leaq 0x30(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x2b9f0
leaq 0x27471(%rip), %rsi     # 0x9d793
leaq 0x2715f(%rip), %rcx     # 0x9d488
leaq 0x10(%rsp), %rdi
movq %r12, %rdx
callq 0x81905
leaq 0x30(%rsp), %rdi
callq 0x6548
movl (%r15), %esi
movq %r14, %rdi
callq 0x2f360
movzbl %al, %r8d
leaq 0x10(%rsp), %rcx
movq %r14, %rdi
movl %ebp, %esi
movl %ebx, %edx
xorl %r9d, %r9d
callq 0x2f196
movl (%r15), %edx
movq %r14, %rdi
movl %ebx, %esi
callq 0x13128
jmp 0x76426
movl (%r15), %ecx
leaq 0x27429(%rip), %r8      # 0x9d7a8
jmp 0x7655b
movl (%r15), %ecx
leaq 0x27466(%rip), %r8      # 0x9d7f4
jmp 0x7655b
movq %r14, %rdi
movl %ebp, %esi
callq 0x90a4
cmpl $0xa, 0xc(%rax)
movl (%r15), %ecx
movl 0x4(%r15), %r8d
movl 0x8(%r15), %r9d
jne 0x765d6
leaq 0x274f6(%rip), %rax     # 0x9d8af
jmp 0x765dd
movl (%r15), %edx
leaq 0x30(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x2b9f0
leaq 0x27436(%rip), %rsi     # 0x9d80e
leaq 0x270a9(%rip), %rcx     # 0x9d488
leaq 0x10(%rsp), %rdi
movq %r12, %rdx
callq 0x8197f
leaq 0x30(%rsp), %rdi
callq 0x6548
movl (%r15), %esi
movq %r14, %rdi
callq 0x2f360
movzbl %al, %r8d
leaq 0x10(%rsp), %rcx
movq %r14, %rdi
movl %ebp, %esi
movl %ebx, %edx
xorl %r9d, %r9d
callq 0x2f196
movl (%r15), %edx
movq %r14, %rdi
movl %ebx, %esi
callq 0x13128
leaq 0x10(%rsp), %rdi
callq 0x6548
jmp 0x765ed
movq %r14, %rdi
movl %ebp, %esi
callq 0x90a4
cmpl $0xa, 0xc(%rax)
movl (%r15), %ecx
movl 0x4(%r15), %r8d
jne 0x76593
leaq 0x27444(%rip), %r9      # 0x9d89b
jmp 0x7659a
movl (%r15), %ecx
leaq 0x27315(%rip), %r8      # 0x9d77b
jmp 0x7655b
movl (%r15), %ecx
leaq 0x272b7(%rip), %r8      # 0x9d72c
jmp 0x7655b
movl (%r15), %ecx
leaq 0x27356(%rip), %r8      # 0x9d7da
jmp 0x7655b
movq %r14, %rdi
movl %ebp, %esi
callq 0x90a4
cmpl $0xa, 0xc(%rax)
movl (%r15), %ecx
movl 0x4(%r15), %r8d
jne 0x764ed
leaq 0x27421(%rip), %r9      # 0x9d8c8
jmp 0x7659a
movl (%r15), %ecx
leaq 0x22b91(%rip), %r8      # 0x99047
jmp 0x7655b
movl (%r15), %ecx
leaq 0x2729e(%rip), %r8      # 0x9d763
jmp 0x7655b
movq %r14, %rdi
movl %ebp, %esi
callq 0x90a4
cmpl $0xa, 0xc(%rax)
movl (%r15), %ecx
movl 0x4(%r15), %r8d
jne 0x764ed
leaq 0x273bd(%rip), %r9      # 0x9d8a5
jmp 0x7659a
leaq 0x273dd(%rip), %r9      # 0x9d8d1
jmp 0x7659a
movl (%r15), %ecx
leaq 0x27347(%rip), %r8      # 0x9d84a
jmp 0x7655b
movq %r14, %rdi
movl %ebp, %esi
callq 0x90a4
movl 0x18(%rax), %eax
cmpl $0x4, %eax
je 0x76609
cmpl $0x3, %eax
je 0x765fa
cmpl $0x2, %eax
jne 0x765ed
movl (%r15), %ecx
leaq 0x2733a(%rip), %r8      # 0x9d871
jmp 0x7655b
movl (%r15), %ecx
leaq 0x27209(%rip), %r8      # 0x9d74c
jmp 0x7655b
movl (%r15), %ecx
leaq 0x271e6(%rip), %r8      # 0x9d735
jmp 0x7655b
movl (%r15), %ecx
leaq 0x272ca(%rip), %r8      # 0x9d825
movq %r14, %rdi
movl %ebp, %esi
movl %ebx, %edx
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x2f9ee
movq %r14, %rdi
movl %ebp, %esi
callq 0x90a4
cmpl $0xa, 0xc(%rax)
movl (%r15), %ecx
movl 0x4(%r15), %r8d
jne 0x76593
leaq 0x2732a(%rip), %r9      # 0x9d8bb
jmp 0x7659a
leaq 0x2732a(%rip), %r9      # 0x9d8c4
movq %r14, %rdi
movl %ebp, %esi
movl %ebx, %edx
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x2fab8
movq %r14, %rdi
movl %ebp, %esi
callq 0x90a4
cmpl $0xa, 0xc(%rax)
movl (%r15), %ecx
movl 0x4(%r15), %r8d
movl 0x8(%r15), %r9d
jne 0x765d6
leaq 0x27301(%rip), %rax     # 0x9d8d5
jmp 0x765dd
leaq 0x27301(%rip), %rax     # 0x9d8de
movq %rax, (%rsp)
movq %r14, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x2fe8e
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl (%r15), %ecx
leaq 0x2727b(%rip), %r8      # 0x9d87f
jmp 0x7655b
movl (%r15), %ecx
leaq 0x2727a(%rip), %r8      # 0x9d88d
jmp 0x7655b
jmp 0x7661a
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
jmp 0x7662e
jmp 0x76626
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x6548
movq %rbx, %rdi
callq 0x64b0
nop