summaryrefslogtreecommitdiff
path: root/arch/nds32/math-emu/fd2si.c
blob: fae3e16a0a10317925613ca6fe5704dce7228889 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// SPDX-License-Identifier: GPL-2.0
// Copyright (C) 2005-2019 Andes Technology Corporation
#include <linux/uaccess.h>

#include <asm/sfp-machine.h>
#include <math-emu/soft-fp.h>
#include <math-emu/double.h>

void fd2si(void *ft, void *fa)
{
	int r;

	FP_DECL_D(A);
	FP_DECL_EX;

	FP_UNPACK_DP(A, fa);

	if (A_c == FP_CLS_INF) {
		*(int *)ft = (A_s == 0) ? 0x7fffffff : 0x80000000;
		__FPU_FPCSR |= FP_EX_INVALID;
	} else if (A_c == FP_CLS_NAN) {
		*(int *)ft = 0xffffffff;
		__FPU_FPCSR |= FP_EX_INVALID;
	} else {
		FP_TO_INT_ROUND_D(r, A, 32, 1);
		__FPU_FPCSR |= FP_CUR_EXCEPTIONS;
		*(int *)ft = r;
	}

}