/**
 * vec - a tiny SIMD vector library in plain C99
 * 
 * Copyright (c) 2024 Paper
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
**/

#ifndef VEC_TYPES_H_
#define VEC_TYPES_H_

#cmakedefine HAVE_SYS_TYPES_H
#cmakedefine HAVE_STDDEF_H
#cmakedefine HAVE_STDINT_H

#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif

typedef signed char   vec_int8;
typedef @SIZE16@      vec_int16;
typedef @SIZE32@      vec_int32;
typedef @SIZE64@      vec_int64;

typedef unsigned char vec_uint8;
typedef @USIZE16@     vec_uint16;
typedef @USIZE32@     vec_uint32;
typedef @USIZE64@     vec_uint64;

/* this is only used for bitshifting right now */
typedef vec_int64     vec_intmax;
typedef vec_uint64    vec_uintmax;

typedef @USIZESIZE@   vec_uintsize;
typedef @USIZEPTR@    vec_uintptr;

// okay, now we have to do this crap.
#ifdef HAVE_STDINT_H
# define VEC_INT8_C(x)    INT8_C(x)
# define VEC_UINT8_C(x)   UINT8_C(x)
# define VEC_INT16_C(x)   INT16_C(x)
# define VEC_UINT16_C(x)  UINT16_C(x)
# define VEC_INT32_C(x)   INT32_C(x)
# define VEC_UINT32_C(x)  UINT32_C(x)
# define VEC_INT64_C(x)   INT64_C(x)
# define VEC_UINT64_C(x)  UINT64_C(x)
# define VEC_INTMAX_C(x)  INTMAX_C(x)
# define VEC_UINTMAX_C(x) UINTMAX_C(x)

# define VEC_INT8_MAX     INT8_MAX
# define VEC_INT8_MIN     INT8_MIN
# define VEC_UINT8_MAX    UINT8_MAX
# define VEC_INT16_MAX    INT16_MAX
# define VEC_INT16_MIN    INT16_MIN
# define VEC_UINT16_MAX   UINT16_MAX
# define VEC_INT32_MAX    INT32_MAX
# define VEC_INT32_MIN    INT32_MIN
# define VEC_UINT32_MAX   UINT32_MAX
# define VEC_INT64_MAX    INT64_MAX
# define VEC_INT64_MIN    INT64_MIN
# define VEC_UINT64_MAX   UINT64_MAX
#else
// These are based on the minimum sizes for each integer type.
//
// i.e. long is guaranteed to be at least 32 bits, long long is
// guaranteed to be at least 64 bits, etc.
# define VEC_INT8_C(x)    x
# define VEC_UINT8_C(x)   x##U
# define VEC_INT16_C(x)   x
# define VEC_UINT16_C(x)  x##U
# define VEC_INT32_C(x)   x##L
# define VEC_UINT32_C(x)  x##UL
# define VEC_INT64_C(x)   x##LL
# define VEC_UINT64_C(x)  x##ULL
# define VEC_INTMAX_C(x)  VEC_INT64_C(x)
# define VEC_UINTMAX_C(x) VEC_UINT64_C(x)

# define VEC_INT8_MAX     0x7F
# define VEC_INT8_MIN     (-0x7F - 1)
# define VEC_UINT8_MAX    0xFFU
# define VEC_INT16_MAX    0x7FFF
# define VEC_INT16_MIN    (-0x7FFF - 1)
# define VEC_UINT16_MAX   0xFFFFU
# define VEC_INT32_MAX    0x7FFFFFFFL
# define VEC_INT32_MIN    (-0x7FFFFFFFL - 1L)
# define VEC_UINT32_MAX   0xFFFFFFFFUL
# define VEC_INT64_MAX    0x7FFFFFFFFFFFFFFFLL
# define VEC_INT64_MIN    (-0x7FFFFFFFFFFFFFFFLL - 1LL)
# define VEC_UINT64_MAX   0xFFFFFFFFFFFFFFFFULL
#endif

#endif /* VEC_TYPES_H_ */
