summaryrefslogtreecommitdiff
path: root/libpcsxcore/pgxp_value.h
blob: a7ba1f3bbf4a85dc46e37390a5963e625014d7b4 (plain) (blame)
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
/***************************************************************************
*   Copyright (C) 2016 by iCatButler                                      *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program 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 General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
***************************************************************************/

/**************************************************************************
*	pgxp_value.h
*	PGXP - Parallel/Precision Geometry Xform Pipeline
*
*	Created on: 07 Jun 2016
*      Author: iCatButler
***************************************************************************/

#ifndef _PGXP_VALUE_H_
#define _PGXP_VALUE_H_

#include "psxcommon.h"

typedef union {
#if defined(__BIGENDIAN__)
	struct { u8 h3, h2, h, l; } b;
	struct { s8 h3, h2, h, l; } sb;
	struct { u16 h, l; } w;
	struct { s16 h, l; } sw;
#else
	struct { u8 l, h, h2, h3; } b;
	struct { u16 l, h; } w;
	struct { s8 l, h, h2, h3; } sb;
	struct { s16 l, h; } sw;
#endif
	u32 d;
	s32 sd;
} psx_value;

typedef struct PGXP_value_Tag
{
	float			x;
	float			y;
	float			z;
	union
	{
		unsigned int	flags;
		unsigned char	compFlags[4];
		unsigned short	halfFlags[2];
	};
	unsigned int	count;
	unsigned int	value;

	unsigned short	gFlags;
	unsigned char	lFlags;
	unsigned char	hFlags;
} PGXP_value;

typedef enum
{
	UNINITIALISED		= 0,
	INVALID_PSX_VALUE	= 1,
	INVALID_ADDRESS		= 2,
	INVALID_BITWISE_OP	= 3,
	DIVIDE_BY_ZERO		= 4,
	INVALID_8BIT_LOAD	= 5,
	INVALID_8BIT_STORE	= 6
} PGXP_error_states;

typedef enum
{
	VALID_HALF = (1 << 0)
} PGXP_half_flags;

//typedef enum
//{
#define NONE	 0
#define ALL		 0xFFFFFFFF
#define VALID	 1
#define VALID_0  (VALID << 0)
#define VALID_1  (VALID << 8)
#define VALID_2  (VALID << 16)
#define VALID_3  (VALID << 24)
#define VALID_01  (VALID_0 | VALID_1)
#define VALID_012  (VALID_0 | VALID_1 | VALID_2)
#define VALID_ALL  (VALID_0 | VALID_1 | VALID_2 | VALID_3)
#define INV_VALID_ALL  (ALL ^ VALID_ALL)
//} PGXP_value_flags;

static const PGXP_value PGXP_value_invalid_address = { 0.f, 0.f, 0.f, 0, 0, 0, INVALID_ADDRESS, 0, 0 };
static const PGXP_value PGXP_value_zero = { 0.f, 0.f, 0.f, 0, 0, VALID_ALL, 0, 0, 0 };

void	SetValue(PGXP_value *pV, u32 psxV);
void	MakeValid(PGXP_value *pV, u32 psxV);
void	Validate(PGXP_value *pV, u32 psxV);
void	MaskValidate(PGXP_value *pV, u32 psxV, u32 mask, u32 validMask);
u32		ValueToTolerance(PGXP_value *pV, u32 psxV, float tolerance);

double f16Sign(double in);
double f16Unsign(double in);
double fu16Trunc(double in);
double f16Overflow(double in);

typedef union
{
	struct
	{
		s16 x;
		s16 y;
	};
	struct
	{
		u16 ux;
		u16 uy;
	};
	u32 word;
} low_value;

#endif//_PGX_VALUE_H_