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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
/*******************************************************************************
* fnpovfpu.h
*
* This module contains all defines, typedefs, and prototypes for fnpovfpu.cpp.
*
* This module is inspired by code by D. Skarda, T. Bily and R. Suzuki.
*
* ---------------------------------------------------------------------------
* Persistence of Vision Ray Tracer ('POV-Ray') version 3.7.
* Copyright 1991-2013 Persistence of Vision Raytracer Pty. Ltd.
*
* POV-Ray is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* POV-Ray is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------------
* POV-Ray is based on the popular DKB raytracer version 2.12.
* DKBTrace was originally written by David K. Buck.
* DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
* ---------------------------------------------------------------------------
* $File: //depot/public/povray/3.x/source/backend/vm/fnpovfpu.h $
* $Revision: #1 $
* $Change: 6069 $
* $DateTime: 2013/11/06 11:59:40 $
* $Author: chrisc $
*******************************************************************************/
#ifndef FNPOVFPU_H
#define FNPOVFPU_H
#include <vector>
#include <set>
#include <boost/thread.hpp>
namespace pov
{
class FunctionVM;
struct FPUContext;
}
#include "backend/frame.h"
#include "backend/vm/fncode.h"
namespace pov
{
#define MAX_CALL_STACK_SIZE 1024
enum
{
ITYPE_R = 0,
ITYPE_I,
ITYPE_S,
ITYPE_J,
ITYPE_X,
ITYPE_M
};
struct Opcode
{
const char *name;
unsigned int code;
int type;
};
enum
{
TRAP_SYS1_SIN = 0,
TRAP_SYS1_COS,
TRAP_SYS1_TAN,
TRAP_SYS1_ASIN,
TRAP_SYS1_ACOS,
TRAP_SYS1_ATAN,
TRAP_SYS1_SINH,
TRAP_SYS1_COSH,
TRAP_SYS1_TANH,
TRAP_SYS1_ASINH,
TRAP_SYS1_ACOSH,
TRAP_SYS1_ATANH,
TRAP_SYS1_FLOOR,
TRAP_SYS1_CEIL,
TRAP_SYS1_SQRT,
TRAP_SYS1_EXP,
TRAP_SYS1_LN,
TRAP_SYS1_LOG,
TRAP_SYS1_INT
};
enum
{
TRAP_SYS2_POW = 0,
TRAP_SYS2_ATAN2,
TRAP_SYS2_MOD,
TRAP_SYS2_DIV
};
typedef SYS_MATH_RETURN (*Sys1)(SYS_MATH_PARAM r0);
typedef SYS_MATH_RETURN (*Sys2)(SYS_MATH_PARAM r0,SYS_MATH_PARAM r1);
class FunctionVM;
// WARNING: Do not change this structure without notice!!!
// Platform specific code may depend on the exact layout and size! [trf]
struct FunctionEntry
{
union {
FunctionCode fn; // valid if reference_count != 0
FUNCTION next_unreferenced; // valid if reference_count == 0
};
unsigned int reference_count;
SYS_FUNCTION_ENTRY
};
// WARNING: Do not change this structure without notice!!!
// Platform specific code may depend on the exact layout and size! [trf]
struct StackFrame
{
unsigned int pc;
FUNCTION fn;
};
// WARNING: Do not change this structure without notice!!!
// Platform specific code may depend on the exact layout and size! [trf]
struct FPUContext
{
StackFrame *pstackbase;
DBL *dblstackbase;
unsigned int maxdblstacksize;
FunctionVM *functionvm;
TraceThreadData *threaddata;
#if (SYS_FUNCTIONS == 1)
DBL *dblstack;
#endif
void SetLocal(unsigned int k, DBL v);
DBL GetLocal(unsigned int k);
};
#define OPCODE(i,s,d) ((i << 6) | (s << 3) | d)
#define OPCODE_ADD OPCODE(0,0,0)
#define OPCODE_SUB OPCODE(1,0,0)
#define OPCODE_MUL OPCODE(2,0,0)
#define OPCODE_DIV OPCODE(3,0,0)
#define OPCODE_MOD OPCODE(4,0,0)
#define OPCODE_MOVE OPCODE(5,0,0)
#define OPCODE_CMP OPCODE(6,0,0)
#define OPCODE_NEG OPCODE(7,0,0)
#define OPCODE_ABS OPCODE(8,0,0)
#define OPCODE_ADDI OPCODE(9,0,0)
#define OPCODE_SUBI OPCODE(9,1,0)
#define OPCODE_MULI OPCODE(9,2,0)
#define OPCODE_DIVI OPCODE(9,3,0)
#define OPCODE_MODI OPCODE(9,4,0)
#define OPCODE_LOADI OPCODE(9,5,0)
#define OPCODE_CMPI OPCODE(9,6,0)
#define OPCODE_SEQ OPCODE(10,0,0)
#define OPCODE_SNE OPCODE(10,1,0)
#define OPCODE_SLT OPCODE(10,2,0)
#define OPCODE_SLE OPCODE(10,3,0)
#define OPCODE_SGT OPCODE(10,4,0)
#define OPCODE_SGE OPCODE(10,5,0)
#define OPCODE_TEQ OPCODE(10,6,0)
#define OPCODE_TNE OPCODE(10,7,0)
#define OPCODE_LOAD OPCODE(11,0,0)
#define OPCODE_STORE OPCODE(12,0,0)
#define OPCODE_BEQ OPCODE(13,0,0)
#define OPCODE_BNE OPCODE(13,1,0)
#define OPCODE_BLT OPCODE(13,2,0)
#define OPCODE_BLE OPCODE(13,3,0)
#define OPCODE_BGT OPCODE(13,4,0)
#define OPCODE_BGE OPCODE(13,5,0)
#define OPCODE_XEQ OPCODE(14,0,0)
#define OPCODE_XNE OPCODE(14,1,0)
#define OPCODE_XLT OPCODE(14,2,0)
#define OPCODE_XLE OPCODE(14,3,0)
#define OPCODE_XGT OPCODE(14,4,0)
#define OPCODE_XGE OPCODE(14,5,0)
#define OPCODE_XDZ OPCODE(14,6,0)
// #define OPCODE_XINF OPCODE(14,7,0)
#define OPCODE_JSR OPCODE(15,0,0)
#define OPCODE_JMP OPCODE(15,0,1)
#define OPCODE_RTS OPCODE(15,0,2)
#define OPCODE_CALL OPCODE(15,0,3)
#define OPCODE_SYS1 OPCODE(15,0,4)
#define OPCODE_SYS2 OPCODE(15,0,5)
#define OPCODE_TRAP OPCODE(15,0,6)
#define OPCODE_TRAPS OPCODE(15,0,7)
#define OPCODE_GROW OPCODE(15,1,0)
#define OPCODE_PUSH OPCODE(15,1,1)
#define OPCODE_POP OPCODE(15,1,2)
#define OPCODE_DEBUG OPCODE(15,1,5)
#define OPCODE_NOP OPCODE(15,3,7)
extern const Opcode POVFPU_Opcodes[];
extern const Sys1 POVFPU_Sys1Table[];
extern const Sys2 POVFPU_Sys2Table[];
extern const unsigned int POVFPU_Sys1TableSize;
extern const unsigned int POVFPU_Sys2TableSize;
void POVFPU_Exception(FPUContext *context, FUNCTION fn, const char *msg = NULL);
DBL POVFPU_RunDefault(FPUContext *context, FUNCTION k);
class FunctionVM
{
friend void POVFPU_Exception(FPUContext *, FUNCTION, const char *);
friend DBL POVFPU_RunDefault(FPUContext *, FUNCTION);
public:
FunctionVM();
~FunctionVM();
void Reset();
void SetGlobal(unsigned int k, DBL v);
DBL GetGlobal(unsigned int k);
FunctionCode *GetFunction(FUNCTION k);
FunctionCode *GetFunctionAndReference(FUNCTION k);
unsigned int AddConstant(DBL v);
FUNCTION AddFunction(FunctionCode *f);
void RemoveFunction(FUNCTION fn);
FPUContext *NewContext(TraceThreadData *);
void DeleteContext(FPUContext *);
private:
vector<FunctionEntry> functions;
FUNCTION nextUnreferenced;
std::set<FPUContext *> contexts;
vector<DBL> globals;
vector<DBL> consts;
boost::recursive_mutex contextMutex;
};
}
#endif
|