1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci * 4e1051a39Sopenharmony_ci * Licensed under the OpenSSL license (the "License"). You may not use 5e1051a39Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci */ 9e1051a39Sopenharmony_ci 10e1051a39Sopenharmony_ci#ifndef OSSL_INTERNAL_NUMBERS_H 11e1051a39Sopenharmony_ci# define OSSL_INTERNAL_NUMBERS_H 12e1051a39Sopenharmony_ci 13e1051a39Sopenharmony_ci# include <limits.h> 14e1051a39Sopenharmony_ci 15e1051a39Sopenharmony_ci# if (-1 & 3) == 0x03 /* Two's complement */ 16e1051a39Sopenharmony_ci 17e1051a39Sopenharmony_ci# define __MAXUINT__(T) ((T) -1) 18e1051a39Sopenharmony_ci# define __MAXINT__(T) ((T) ((((T) 1) << ((sizeof(T) * CHAR_BIT) - 1)) ^ __MAXUINT__(T))) 19e1051a39Sopenharmony_ci# define __MININT__(T) (-__MAXINT__(T) - 1) 20e1051a39Sopenharmony_ci 21e1051a39Sopenharmony_ci# elif (-1 & 3) == 0x02 /* One's complement */ 22e1051a39Sopenharmony_ci 23e1051a39Sopenharmony_ci# define __MAXUINT__(T) (((T) -1) + 1) 24e1051a39Sopenharmony_ci# define __MAXINT__(T) ((T) ((((T) 1) << ((sizeof(T) * CHAR_BIT) - 1)) ^ __MAXUINT__(T))) 25e1051a39Sopenharmony_ci# define __MININT__(T) (-__MAXINT__(T)) 26e1051a39Sopenharmony_ci 27e1051a39Sopenharmony_ci# elif (-1 & 3) == 0x01 /* Sign/magnitude */ 28e1051a39Sopenharmony_ci 29e1051a39Sopenharmony_ci# define __MAXINT__(T) ((T) (((((T) 1) << ((sizeof(T) * CHAR_BIT) - 2)) - 1) | (((T) 1) << ((sizeof(T) * CHAR_BIT) - 2)))) 30e1051a39Sopenharmony_ci# define __MAXUINT__(T) ((T) (__MAXINT__(T) | (((T) 1) << ((sizeof(T) * CHAR_BIT) - 1)))) 31e1051a39Sopenharmony_ci# define __MININT__(T) (-__MAXINT__(T)) 32e1051a39Sopenharmony_ci 33e1051a39Sopenharmony_ci# else 34e1051a39Sopenharmony_ci 35e1051a39Sopenharmony_ci# error "do not know the integer encoding on this architecture" 36e1051a39Sopenharmony_ci 37e1051a39Sopenharmony_ci# endif 38e1051a39Sopenharmony_ci 39e1051a39Sopenharmony_ci# ifndef INT8_MAX 40e1051a39Sopenharmony_ci# define INT8_MIN __MININT__(int8_t) 41e1051a39Sopenharmony_ci# define INT8_MAX __MAXINT__(int8_t) 42e1051a39Sopenharmony_ci# define UINT8_MAX __MAXUINT__(uint8_t) 43e1051a39Sopenharmony_ci# endif 44e1051a39Sopenharmony_ci 45e1051a39Sopenharmony_ci# ifndef INT16_MAX 46e1051a39Sopenharmony_ci# define INT16_MIN __MININT__(int16_t) 47e1051a39Sopenharmony_ci# define INT16_MAX __MAXINT__(int16_t) 48e1051a39Sopenharmony_ci# define UINT16_MAX __MAXUINT__(uint16_t) 49e1051a39Sopenharmony_ci# endif 50e1051a39Sopenharmony_ci 51e1051a39Sopenharmony_ci# ifndef INT32_MAX 52e1051a39Sopenharmony_ci# define INT32_MIN __MININT__(int32_t) 53e1051a39Sopenharmony_ci# define INT32_MAX __MAXINT__(int32_t) 54e1051a39Sopenharmony_ci# define UINT32_MAX __MAXUINT__(uint32_t) 55e1051a39Sopenharmony_ci# endif 56e1051a39Sopenharmony_ci 57e1051a39Sopenharmony_ci# ifndef INT64_MAX 58e1051a39Sopenharmony_ci# define INT64_MIN __MININT__(int64_t) 59e1051a39Sopenharmony_ci# define INT64_MAX __MAXINT__(int64_t) 60e1051a39Sopenharmony_ci# define UINT64_MAX __MAXUINT__(uint64_t) 61e1051a39Sopenharmony_ci# endif 62e1051a39Sopenharmony_ci 63e1051a39Sopenharmony_ci# ifndef SIZE_MAX 64e1051a39Sopenharmony_ci# define SIZE_MAX __MAXUINT__(size_t) 65e1051a39Sopenharmony_ci# endif 66e1051a39Sopenharmony_ci 67e1051a39Sopenharmony_ci#endif 68e1051a39Sopenharmony_ci 69