common_types.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * Copyright (C) 2005-2012 Gekko Emulator
  3. *
  4. * @file common_types.h
  5. * @author ShizZy <shizzy247@gmail.com>
  6. * @date 2012-02-11
  7. * @brief Common types used throughout the project
  8. *
  9. * @section LICENSE
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details at
  19. * http://www.gnu.org/copyleft/gpl.html
  20. *
  21. * Official project repository can be found at:
  22. * http://code.google.com/p/gekko-gc-emu/
  23. */
  24. #pragma once
  25. #include <cmath>
  26. #include <cstdint>
  27. #include <xmmintrin.h> // data_types__m128.cpp
  28. typedef std::uint8_t u8; ///< 8-bit unsigned byte
  29. typedef std::uint16_t u16; ///< 16-bit unsigned short
  30. typedef std::uint32_t u32; ///< 32-bit unsigned word
  31. typedef std::uint64_t u64; ///< 64-bit unsigned int
  32. typedef std::int8_t s8; ///< 8-bit signed byte
  33. typedef std::int16_t s16; ///< 16-bit signed short
  34. typedef std::int32_t s32; ///< 32-bit signed word
  35. typedef std::int64_t s64; ///< 64-bit signed int
  36. typedef float f32; ///< 32-bit floating point
  37. typedef double f64; ///< 64-bit floating point
  38. /// Union for fast 16-bit type casting
  39. union t16 {
  40. u8 _u8[2]; ///< 8-bit unsigned char(s)
  41. u16 _u16; ///< 16-bit unsigned shorts(s)
  42. };
  43. /// Union for fast 32-bit type casting
  44. union t32 {
  45. f32 _f32; ///< 32-bit floating point(s)
  46. u32 _u32; ///< 32-bit unsigned int(s)
  47. s32 _s32; ///< 32-bit signed int(s)
  48. u16 _u16[2]; ///< 16-bit unsigned shorts(s)
  49. u8 _u8[4]; ///< 8-bit unsigned char(s)
  50. };
  51. /// Union for fast 64-bit type casting
  52. union t64 {
  53. f64 _f64; ///< 64-bit floating point
  54. u64 _u64; ///< 64-bit unsigned long
  55. f32 _f32[2]; ///< 32-bit floating point(s)
  56. u32 _u32[2]; ///< 32-bit unsigned int(s)
  57. s32 _s32[2]; ///< 32-bit signed int(s)
  58. u16 _u16[4]; ///< 16-bit unsigned shorts(s)
  59. u8 _u8[8]; ///< 8-bit unsigned char(s)
  60. };
  61. /// Union for fast 128-bit type casting
  62. union t128 {
  63. struct
  64. {
  65. t64 ps0; ///< 64-bit paired single 0
  66. t64 ps1; ///< 64-bit paired single 1
  67. };
  68. __m128 a; ///< 128-bit floating point (__m128 maps to the XMM[0-7] registers)
  69. };
  70. namespace Common {
  71. /// Rectangle data structure
  72. class Rect {
  73. public:
  74. Rect(int x0=0, int y0=0, int x1=0, int y1=0) {
  75. x0_ = x0;
  76. y0_ = y0;
  77. x1_ = x1;
  78. y1_ = y1;
  79. }
  80. ~Rect() { }
  81. int x0_; ///< Rect top left X-coordinate
  82. int y0_; ///< Rect top left Y-coordinate
  83. int x1_; ///< Rect bottom left X-coordinate
  84. int y1_; ///< Rect bottom right Y-coordinate
  85. inline u32 width() const { return abs(x1_ - x0_); }
  86. inline u32 height() const { return abs(y1_ - y0_); }
  87. inline bool operator == (const Rect& val) const {
  88. return (x0_ == val.x0_ && y0_ == val.y0_ && x1_ == val.x1_ && y1_ == val.y1_);
  89. }
  90. };
  91. }