EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
FastInt.h
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Aim, Captnoord, Zhur, Bloody.Rabbit
24 */
25 
26 #ifndef __UTILS__FAST_INT_H__INCL__
27 #define __UTILS__FAST_INT_H__INCL__
28 
29 // fast int abs
30 inline int32 int32abs( const int32 value )
31 {
32  return (value ^ (value >> 31)) - (value >> 31);
33 }
34 
35 // fast int abs and recast to unsigned
36 inline uint32 int32abs2uint32( const int32 value )
37 {
38  return (uint32)(value ^ (value >> 31)) - (value >> 31);
39 }
40 
42 inline int32 float2int32( const float value )
43 {
44 #ifdef HAVE___ASM
45  int32 i;
46  __asm {
47  fld value
48  frndint
49  fistp i
50  }
51  return i;
52 #else /* !HAVE___ASM */
53  union { int32 asInt[2]; double asDouble; } n;
54  n.asDouble = value + 6755399441055744.0;
55 
56  return n.asInt[0];
57 #endif /* !HAVE___ASM */
58 }
59 
61 inline int32 double2int32( const double value )
62 {
63 #ifdef HAVE___ASM
64  int32 i;
65  __asm {
66  fld value
67  frndint
68  fistp i
69  }
70  return i;
71 #else /* !HAVE___ASM */
72  union { int32 asInt[2]; double asDouble; } n;
73  n.asDouble = value + 6755399441055744.0;
74 
75  return n.asInt[0];
76 #endif /* !HAVE___ASM */
77 }
78 
79 #endif /* !__UTILS__FAST_INT_H__INCL__ */
int32 double2int32(const double value)
Fastest Method of double2int32.
Definition: FastInt.h:61
signed __int32 int32
Definition: eve-compat.h:49
unsigned __int32 uint32
Definition: eve-compat.h:50
int32 int32abs(const int32 value)
Definition: FastInt.h:30
int32 float2int32(const float value)
Fastest Method of float2int32.
Definition: FastInt.h:42
uint32 int32abs2uint32(const int32 value)
Definition: FastInt.h:36