| 1 | /** |
| 2 | * Copyright (c) 2006-2023 LOVE Development Team |
| 3 | * |
| 4 | * This software is provided 'as-is', without any express or implied |
| 5 | * warranty. In no event will the authors be held liable for any damages |
| 6 | * arising from the use of this software. |
| 7 | * |
| 8 | * Permission is granted to anyone to use this software for any purpose, |
| 9 | * including commercial applications, and to alter it and redistribute it |
| 10 | * freely, subject to the following restrictions: |
| 11 | * |
| 12 | * 1. The origin of this software must not be misrepresented; you must not |
| 13 | * claim that you wrote the original software. If you use this software |
| 14 | * in a product, an acknowledgment in the product documentation would be |
| 15 | * appreciated but is not required. |
| 16 | * 2. Altered source versions must be plainly marked as such, and must not be |
| 17 | * misrepresented as being the original software. |
| 18 | * 3. This notice may not be removed or altered from any source distribution. |
| 19 | **/ |
| 20 | |
| 21 | #ifndef LOVE_INT_H |
| 22 | #define LOVE_INT_H |
| 23 | |
| 24 | // C standard sized integer types. |
| 25 | #include <stdint.h> |
| 26 | |
| 27 | #define LOVE_INT8_MAX 0x7F |
| 28 | #define LOVE_UINT8_MAX 0xFF |
| 29 | #define LOVE_INT16_MAX 0x7FFF |
| 30 | #define LOVE_UINT16_MAX 0xFFFF |
| 31 | #define LOVE_INT32_MAX 0x7FFFFFFF |
| 32 | #define LOVE_UINT32_MAX 0xFFFFFFFF |
| 33 | #define LOVE_INT64_MAX 0x7FFFFFFFFFFFFFFF |
| 34 | #define LOVE_UINT64_MAX 0xFFFFFFFFFFFFFFFF |
| 35 | |
| 36 | namespace love |
| 37 | { |
| 38 | |
| 39 | typedef int8_t int8; |
| 40 | typedef uint8_t uint8; |
| 41 | typedef int16_t int16; |
| 42 | typedef uint16_t uint16; |
| 43 | typedef int32_t int32; |
| 44 | typedef uint32_t uint32; |
| 45 | typedef int64_t int64; |
| 46 | typedef uint64_t uint64; |
| 47 | |
| 48 | static inline uint16 swapuint16(uint16 x) |
| 49 | { |
| 50 | return (x >> 8) | (x << 8); |
| 51 | } |
| 52 | |
| 53 | static inline uint32 swapuint32(uint32 x) |
| 54 | { |
| 55 | return ((x & 0x000000FF) << 24) | |
| 56 | ((x & 0x0000FF00) << 8) | |
| 57 | ((x & 0x00FF0000) >> 8) | |
| 58 | ((x & 0xFF000000) >> 24); |
| 59 | } |
| 60 | |
| 61 | static inline uint64 swapuint64(uint64 x) |
| 62 | { |
| 63 | return ((x << 56) & 0xFF00000000000000ULL) | ((x << 40) & 0x00FF000000000000ULL) | |
| 64 | ((x << 24) & 0x0000FF0000000000ULL) | ((x << 8) & 0x000000FF00000000ULL) | |
| 65 | ((x >> 8) & 0x00000000FF000000ULL) | ((x >> 24) & 0x0000000000FF0000ULL) | |
| 66 | ((x >> 40) & 0x000000000000FF00ULL) | ((x >> 56) & 0x00000000000000FFULL); |
| 67 | } |
| 68 | |
| 69 | } // love |
| 70 | |
| 71 | #endif // LOVE_INT_H |
| 72 | |