Home | History | Annotate | Download | only in Common
      1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //    http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 #ifndef sw_Types_hpp
     16 #define sw_Types_hpp
     17 
     18 #if defined(_MSC_VER)
     19 	typedef signed __int8 int8_t;
     20 	typedef signed __int16 int16_t;
     21 	typedef signed __int32 int32_t;
     22 	typedef signed __int64 int64_t;
     23 	typedef unsigned __int8 uint8_t;
     24 	typedef unsigned __int16 uint16_t;
     25 	typedef unsigned __int32 uint32_t;
     26 	typedef unsigned __int64 uint64_t;
     27 	#define ALIGN(bytes, type) __declspec(align(bytes)) type
     28 #else
     29 	#include <stdint.h>
     30 	#define ALIGN(bytes, type) type __attribute__((aligned(bytes)))
     31 #endif
     32 
     33 namespace sw
     34 {
     35 	typedef ALIGN(1, uint8_t) byte;
     36 	typedef ALIGN(2, uint16_t) word;
     37 	typedef ALIGN(4, uint32_t) dword;
     38 	typedef ALIGN(8, uint64_t) qword;
     39 	typedef ALIGN(16, uint64_t) qword2[2];
     40 	typedef ALIGN(4, uint8_t) byte4[4];
     41 	typedef ALIGN(8, uint8_t) byte8[8];
     42 	typedef ALIGN(16, uint8_t) byte16[16];
     43 	typedef ALIGN(8, uint16_t) word4[4];
     44 	typedef ALIGN(8, uint32_t) dword2[2];
     45 	typedef ALIGN(16, uint32_t) dword4[4];
     46 	typedef ALIGN(16, uint64_t) xword[2];
     47 
     48 	typedef ALIGN(1, int8_t) sbyte;
     49 	typedef ALIGN(4, int8_t) sbyte4[4];
     50 	typedef ALIGN(8, int8_t) sbyte8[8];
     51 	typedef ALIGN(16, int8_t) sbyte16[16];
     52 	typedef ALIGN(8, short) short4[4];
     53 	typedef ALIGN(8, unsigned short) ushort4[4];
     54 	typedef ALIGN(16, short) short8[8];
     55 	typedef ALIGN(16, unsigned short) ushort8[8];
     56 	typedef ALIGN(8, int) int2[2];
     57 	typedef ALIGN(8, unsigned int) uint2[2];
     58 	typedef ALIGN(16, unsigned int) uint4[4];
     59 
     60 	typedef ALIGN(8, float) float2[2];
     61 
     62 	ALIGN(16, struct int4
     63 	{
     64 		int x;
     65 		int y;
     66 		int z;
     67 		int w;
     68 
     69 		int &operator[](int i)
     70 		{
     71 			return (&x)[i];
     72 		}
     73 
     74 		const int &operator[](int i) const
     75 		{
     76 			return (&x)[i];
     77 		}
     78 
     79 		bool operator!=(const int4 &rhs)
     80 		{
     81 			return x != rhs.x || y != rhs.y || z != rhs.z || w != rhs.w;
     82 		}
     83 
     84 		bool operator==(const int4 &rhs)
     85 		{
     86 			return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w;
     87 		}
     88 	});
     89 
     90 	ALIGN(16, struct float4
     91 	{
     92 		float x;
     93 		float y;
     94 		float z;
     95 		float w;
     96 
     97 		float &operator[](int i)
     98 		{
     99 			return (&x)[i];
    100 		}
    101 
    102 		const float &operator[](int i) const
    103 		{
    104 			return (&x)[i];
    105 		}
    106 
    107 		bool operator!=(const float4 &rhs)
    108 		{
    109 			return x != rhs.x || y != rhs.y || z != rhs.z || w != rhs.w;
    110 		}
    111 
    112 		bool operator==(const float4 &rhs)
    113 		{
    114 			return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w;
    115 		}
    116 	});
    117 
    118 	inline float4 vector(float x, float y, float z, float w)
    119 	{
    120 		float4 v;
    121 
    122 		v.x = x;
    123 		v.y = y;
    124 		v.z = z;
    125 		v.w = w;
    126 
    127 		return v;
    128 	}
    129 
    130 	inline float4 replicate(float f)
    131 	{
    132 		float4 v;
    133 
    134 		v.x = f;
    135 		v.y = f;
    136 		v.z = f;
    137 		v.w = f;
    138 
    139 		return v;
    140 	}
    141 
    142 	#define OFFSET(s,m) (int)(size_t)&reinterpret_cast<const volatile char&>((((s*)0)->m))
    143 }
    144 
    145 #endif   // sw_Types_hpp
    146