]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/plr/server/src/asmjit/Util_p.h
update
[l4.git] / l4 / pkg / plr / server / src / asmjit / Util_p.h
1 // AsmJit - Complete JIT Assembler for C++ Language.
2
3 // Copyright (c) 2008-2010, Petr Kobalicek <kobalicek.petr@gmail.com>
4 //
5 // Permission is hereby granted, free of charge, to any person
6 // obtaining a copy of this software and associated documentation
7 // files (the "Software"), to deal in the Software without
8 // restriction, including without limitation the rights to use,
9 // copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following
12 // conditions:
13 //
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 // OTHER DEALINGS IN THE SOFTWARE.
25
26 // [Guard]
27 #ifndef _ASMJIT_UTIL_P_H
28 #define _ASMJIT_UTIL_P_H
29
30 // [Dependencies]
31 #include "Util.h"
32
33 #include <stdlib.h>
34 #include <string.h>
35
36 namespace AsmJit {
37
38 //! @addtogroup AsmJit_Util
39 //! @{
40
41 // ============================================================================
42 // [AsmJit::Util]
43 // ============================================================================
44
45 namespace Util
46 {
47   // --------------------------------------------------------------------------
48   // [AsmJit::floatAsInt32, int32AsFloat]
49   // --------------------------------------------------------------------------
50
51   //! @internal
52   //!
53   //! @brief used to cast from float to 32-bit integer and vica versa.
54   union I32FPUnion
55   {
56     //! @brief 32-bit signed integer value.
57     int32_t i;
58     //! @brief 32-bit SP-FP value.
59     float f;
60   };
61
62   //! @internal
63   //!
64   //! @brief used to cast from double to 64-bit integer and vica versa.
65   union I64FPUnion
66   {
67     //! @brief 64-bit signed integer value.
68     int64_t i;
69     //! @brief 64-bit DP-FP value.
70     double f;
71   };
72
73   //! @brief Binary cast from 32-bit integer to SP-FP value (@c float).
74   static inline float int32AsFloat(int32_t i) ASMJIT_NOTHROW
75   {
76     I32FPUnion u;
77     u.i = i;
78     return u.f;
79   }
80
81   //! @brief Binary cast SP-FP value (@c float) to 32-bit integer.
82   static inline int32_t floatAsInt32(float f) ASMJIT_NOTHROW
83   {
84     I32FPUnion u;
85     u.f = f;
86     return u.i;
87   }
88
89   //! @brief Binary cast from 64-bit integer to DP-FP value (@c double).
90   static inline double int64AsDouble(int64_t i) ASMJIT_NOTHROW
91   {
92     I64FPUnion u;
93     u.i = i;
94     return u.f;
95   }
96
97   //! @brief Binary cast from DP-FP value (@c double) to 64-bit integer.
98   static inline int64_t doubleAsInt64(double f) ASMJIT_NOTHROW
99   {
100     I64FPUnion u;
101     u.f = f;
102     return u.i;
103   }
104
105   // --------------------------------------------------------------------------
106   // [Str Utils]
107   // --------------------------------------------------------------------------
108
109   ASMJIT_HIDDEN char* mycpy(char* dst, const char* src, sysuint_t len = (sysuint_t)-1) ASMJIT_NOTHROW;
110   ASMJIT_HIDDEN char* myfill(char* dst, const int c, sysuint_t len) ASMJIT_NOTHROW;
111   ASMJIT_HIDDEN char* myhex(char* dst, const uint8_t* src, sysuint_t len) ASMJIT_NOTHROW;
112   ASMJIT_HIDDEN char* myutoa(char* dst, sysuint_t i, sysuint_t base = 10) ASMJIT_NOTHROW;
113   ASMJIT_HIDDEN char* myitoa(char* dst, sysint_t i, sysuint_t base = 10) ASMJIT_NOTHROW;
114
115   // --------------------------------------------------------------------------
116   // [Mem Utils]
117   // --------------------------------------------------------------------------
118
119   static inline void memset32(uint32_t* p, uint32_t c, sysuint_t len) ASMJIT_NOTHROW
120   {
121     sysuint_t i;
122     for (i = 0; i < len; i++) p[i] = c;
123   }
124 } // Util namespace
125
126 //! @}
127
128 } // AsmJit namespace
129
130 #endif // _ASMJIT_UTIL_P_H