"fixed.h"

[Internal header for use with TR18037]


Include the internal header "fixed.h" to define several functions that perform basic arithmetic operations on the fixed-point types. The compiler front end from Edison Design Group calls these functions, when it generates C code directly, to implement the fixed-point arithmetic described in TR18037.

    /* TYPES */
typedef unsigned long long fxvalue;

typedef unsigned short fxmask1;  /* op/result */
typedef unsigned short fxmaskf;  /* op */
typedef unsigned short fxmaskg;  /* result */
typedef unsigned short fxmaskc;  /* op, result */
typedef unsigned short fxmaskr;  /* op1, op2 */
typedef unsigned long  fxmask2;  /* op1, op2, result */

    /* FUNCTIONS */
fxvalue _Fixed_negate(fxmask1 mask, fxvalue x);  /* -x */
fxvalue _Fixed_incr(fxmask1 mask, fxvalue x);    /* x+1 */
fxvalue _Fixed_decr(fxmask1 mask, fxvalue x);    /* x+1 */

fxvalue _Fixed_add(fxmask2 mask, fxvalue x, fxvalue y);       /* x+y */
fxvalue _Fixed_subtract(fxmask2 mask, fxvalue x, fxvalue y);  /* x-y */
fxvalue _Fixed_multiply(fxmask2 mask, fxvalue x, fxvalue y);  /* x*y */
fxvalue _Fixed_divide(fxmask2 mask, fxvalue x, fxvalue y);    /* x/y */

int _Fixed_eq(fxmaskr mask, fxvalue x, fxvalue y);  /* x==y */
int _Fixed_ne(fxmaskr mask, fxvalue x, fxvalue y);  /* x!=y */
int _Fixed_gt(fxmaskr mask, fxvalue x, fxvalue y);  /* x>y */
int _Fixed_lt(fxmaskr mask, fxvalue x, fxvalue y);  /* x<y */
int _Fixed_ge(fxmaskr mask, fxvalue x, fxvalue y);  /* x>=y */
int _Fixed_le(fxmask maskr, fxvalue x, fxvalue y);  /* x<=y */

fxvalue _Fixed_shiftl(fxmask1 mask, fxvalue x, int y);  /* x<<y */
fxvalue _Fixed_shiftr(fxmask1 mask, fxvalue x, int y);  /* x>>y */

fxvalue _Fixed_conv(fxmaskc mask, fxvalue x);            /* (T)x */
float _Fixed_to_float(fxmaskf mask, fxvalue x);          /* (float)x */
double _Fixed_to_double(fxmaskf mask, fxvalue x);        /* (double)x */
long double _Fixed_to_ldouble(fxmaskf mask, fxvalue x);  /* (long double)x */

fxvalue _Fixed_from_float(fxmaskg mask, float x);          /* (T)x */
fxvalue _Fixed_from_double(fxmaskg mask, double x);        /* (T)x */
fxvalue _Fixed_from_ldouble(fxmaskg mask, long double x);  /* (T)x */

All functions convey fixed-point values in the least-significant bits of the common type fxvalue. A mask argument conveys type information, in the form of one to three five-bit fields, packed as:

mask = field1 | (field2 << 5) | field3 << 10);

Each field is the union of:

In this implementation, all types are saturating, so the 0x10 bit is ignored.

The field arguments are then:

The comment after each of the functions above describes the operation it implements.


See also the Table of Contents and the Index.

Copyright © 1992-2013 by P.J. Plauger. All rights reserved.