1293034Sdes/*- 2293034Sdes * Copyright (c) 2015 Dag-Erling Sm��rgrav 3293034Sdes * All rights reserved. 4293034Sdes * 5293034Sdes * Redistribution and use in source and binary forms, with or without 6293034Sdes * modification, are permitted provided that the following conditions 7293034Sdes * are met: 8293034Sdes * 1. Redistributions of source code must retain the above copyright 9293034Sdes * notice, this list of conditions and the following disclaimer. 10293034Sdes * 2. Redistributions in binary form must reproduce the above copyright 11293034Sdes * notice, this list of conditions and the following disclaimer in the 12293034Sdes * documentation and/or other materials provided with the distribution. 13293034Sdes * 14293034Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15293034Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16293034Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17293034Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18293034Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19293034Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20293034Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21293034Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22293034Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23293034Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24293034Sdes * SUCH DAMAGE. 25293034Sdes * 26293034Sdes * $FreeBSD: releng/11.0/sys/dev/syscons/plasma/fp16.h 293049 2016-01-02 16:40:37Z des $ 27293034Sdes */ 28293034Sdes 29293034Sdes#ifndef FP16_H_INCLUDED 30293034Sdes#define FP16_H_INCLUDED 31293034Sdes 32293034Sdestypedef signed long long fp16_t; 33293034Sdes 34293034Sdes#define ItoFP16(n) ((signed long long)(n) << 16) 35293034Sdes#define FP16toI(n) ((signed long long)(n) >> 16) 36293034Sdes 37293034Sdes#ifndef _KERNEL 38293034Sdes#define FP16toF(n) ((n) / 65536.0) 39293034Sdes#endif 40293034Sdes 41293034Sdes/* add a and b */ 42293034Sdesstatic inline fp16_t 43293034Sdesfp16_add(fp16_t a, fp16_t b) 44293034Sdes{ 45293034Sdes 46293034Sdes return (a + b); 47293034Sdes} 48293034Sdes 49293034Sdes/* subtract b from a */ 50293034Sdesstatic inline fp16_t 51293034Sdesfp16_sub(fp16_t a, fp16_t b) 52293034Sdes{ 53293034Sdes 54293034Sdes return (a - b); 55293034Sdes} 56293034Sdes 57293034Sdes/* multiply a by b */ 58293034Sdesstatic inline fp16_t 59293034Sdesfp16_mul(fp16_t a, fp16_t b) 60293034Sdes{ 61293034Sdes 62293034Sdes return (a * b >> 16); 63293034Sdes} 64293034Sdes 65293034Sdes/* divide a by b */ 66293034Sdesstatic inline fp16_t 67293034Sdesfp16_div(fp16_t a, fp16_t b) 68293034Sdes{ 69293034Sdes 70293034Sdes return ((a << 16) / b); 71293034Sdes} 72293034Sdes 73293034Sdes/* square root */ 74293034Sdesfp16_t fp16_sqrt(fp16_t); 75293034Sdes 76293034Sdes#define FP16_2PI 411774 77293034Sdes#define FP16_PI 205887 78293034Sdes#define FP16_PI_2 102943 79293034Sdes#define FP16_PI_4 51471 80293034Sdes 81293049Sdes/* sine and cosine */ 82293049Sdesfp16_t fp16_sin(fp16_t); 83293034Sdesfp16_t fp16_cos(fp16_t); 84293034Sdes 85293034Sdes#endif 86