18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci#include <linux/types.h>
38c2ecf20Sopenharmony_ci#include <linux/errno.h>
48c2ecf20Sopenharmony_ci#include <linux/uaccess.h>
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <asm/sfp-machine.h>
78c2ecf20Sopenharmony_ci#include <math-emu/soft-fp.h>
88c2ecf20Sopenharmony_ci#include <math-emu/double.h>
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciint
118c2ecf20Sopenharmony_cifdiv(void *frD, void *frA, void *frB)
128c2ecf20Sopenharmony_ci{
138c2ecf20Sopenharmony_ci	FP_DECL_D(A);
148c2ecf20Sopenharmony_ci	FP_DECL_D(B);
158c2ecf20Sopenharmony_ci	FP_DECL_D(R);
168c2ecf20Sopenharmony_ci	FP_DECL_EX;
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#ifdef DEBUG
198c2ecf20Sopenharmony_ci	printk("%s: %p %p %p\n", __func__, frD, frA, frB);
208c2ecf20Sopenharmony_ci#endif
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci	FP_UNPACK_DP(A, frA);
238c2ecf20Sopenharmony_ci	FP_UNPACK_DP(B, frB);
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#ifdef DEBUG
268c2ecf20Sopenharmony_ci	printk("A: %ld %lu %lu %ld (%ld)\n", A_s, A_f1, A_f0, A_e, A_c);
278c2ecf20Sopenharmony_ci	printk("B: %ld %lu %lu %ld (%ld)\n", B_s, B_f1, B_f0, B_e, B_c);
288c2ecf20Sopenharmony_ci#endif
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	if (A_c == FP_CLS_ZERO && B_c == FP_CLS_ZERO) {
318c2ecf20Sopenharmony_ci		FP_SET_EXCEPTION(EFLAG_VXZDZ);
328c2ecf20Sopenharmony_ci#ifdef DEBUG
338c2ecf20Sopenharmony_ci		printk("%s: FPSCR_VXZDZ raised\n", __func__);
348c2ecf20Sopenharmony_ci#endif
358c2ecf20Sopenharmony_ci	}
368c2ecf20Sopenharmony_ci	if (A_c == FP_CLS_INF && B_c == FP_CLS_INF) {
378c2ecf20Sopenharmony_ci		FP_SET_EXCEPTION(EFLAG_VXIDI);
388c2ecf20Sopenharmony_ci#ifdef DEBUG
398c2ecf20Sopenharmony_ci		printk("%s: FPSCR_VXIDI raised\n", __func__);
408c2ecf20Sopenharmony_ci#endif
418c2ecf20Sopenharmony_ci	}
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci	if (B_c == FP_CLS_ZERO && A_c != FP_CLS_ZERO) {
448c2ecf20Sopenharmony_ci		FP_SET_EXCEPTION(EFLAG_DIVZERO);
458c2ecf20Sopenharmony_ci		if (__FPU_TRAP_P(EFLAG_DIVZERO))
468c2ecf20Sopenharmony_ci			return FP_CUR_EXCEPTIONS;
478c2ecf20Sopenharmony_ci	}
488c2ecf20Sopenharmony_ci	FP_DIV_D(R, A, B);
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#ifdef DEBUG
518c2ecf20Sopenharmony_ci	printk("D: %ld %lu %lu %ld (%ld)\n", R_s, R_f1, R_f0, R_e, R_c);
528c2ecf20Sopenharmony_ci#endif
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci	__FP_PACK_D(frD, R);
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	return FP_CUR_EXCEPTIONS;
578c2ecf20Sopenharmony_ci}
58