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_cifcmpo(u32 *ccr, int crfD, void *frA, void *frB) 128c2ecf20Sopenharmony_ci{ 138c2ecf20Sopenharmony_ci FP_DECL_D(A); 148c2ecf20Sopenharmony_ci FP_DECL_D(B); 158c2ecf20Sopenharmony_ci FP_DECL_EX; 168c2ecf20Sopenharmony_ci int code[4] = { (1 << 3), (1 << 1), (1 << 2), (1 << 0) }; 178c2ecf20Sopenharmony_ci long cmp; 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#ifdef DEBUG 208c2ecf20Sopenharmony_ci printk("%s: %p (%08x) %d %p %p\n", __func__, ccr, *ccr, crfD, frA, frB); 218c2ecf20Sopenharmony_ci#endif 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci FP_UNPACK_DP(A, frA); 248c2ecf20Sopenharmony_ci FP_UNPACK_DP(B, frB); 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#ifdef DEBUG 278c2ecf20Sopenharmony_ci printk("A: %ld %lu %lu %ld (%ld)\n", A_s, A_f1, A_f0, A_e, A_c); 288c2ecf20Sopenharmony_ci printk("B: %ld %lu %lu %ld (%ld)\n", B_s, B_f1, B_f0, B_e, B_c); 298c2ecf20Sopenharmony_ci#endif 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci if (A_c == FP_CLS_NAN || B_c == FP_CLS_NAN) 328c2ecf20Sopenharmony_ci FP_SET_EXCEPTION(EFLAG_VXVC); 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci FP_CMP_D(cmp, A, B, 2); 358c2ecf20Sopenharmony_ci cmp = code[(cmp + 1) & 3]; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci __FPU_FPSCR &= ~(0x1f000); 388c2ecf20Sopenharmony_ci __FPU_FPSCR |= (cmp << 12); 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci *ccr &= ~(15 << ((7 - crfD) << 2)); 418c2ecf20Sopenharmony_ci *ccr |= (cmp << ((7 - crfD) << 2)); 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#ifdef DEBUG 448c2ecf20Sopenharmony_ci printk("CR: %08x\n", *ccr); 458c2ecf20Sopenharmony_ci#endif 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci return FP_CUR_EXCEPTIONS; 488c2ecf20Sopenharmony_ci} 49