MHEG5  22.11.0
glue_ulong.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2012 Ocean Blue Software Ltd
4  *
5  * This file is part of a DTVKit Software Component
6  * You are permitted to copy, modify or distribute this file subject to the terms
7  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
8  *
9  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
10  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
11  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * If you or your organisation is not a member of DTVKit then you have access
14  * to this source code outside of the terms of the licence agreement
15  * and you are expected to delete this and any associated files immediately.
16  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
17  *******************************************************************************/
25 #ifndef _GLUE_ULONG_H_
26 #define _GLUE_ULONG_H_
27 
28 /*---includes for this file--------------------------------------------------*/
29 
30 #include "techtype.h"
31 
32 #ifndef NO_STDINT_H
33 # define USE_TRUE_64BIT
34 #else
35 # undef USE_TRUE_64BIT
36 #endif
37 
38 /*---Constant and macro definitions for public use---------------------------*/
39 
40 /* largest unsigned 64 bit is 18446744073709551615 (2**64-1), so that's 21 chars */
41 #define MAX_64BIT_DECIMAL_STRING 22
42 
43 #ifdef USE_TRUE_64BIT
44  #define INVALID_64BIT_VAL 0xffffffffffffffffULL
45  #define ULL_Get32(variable) ((U32BIT)variable)
46  #define ULL_Add(variable, value) variable += (value)
47  #define ULL_Add32(variable, value) variable += ((U64BIT)value)
48  #define ULL_Sub(variable, value) variable -= (value)
49  #define ULL_Sub32(variable, value) variable -= ((U64BIT)value)
50  #define ULL_Mul32(variable, value) variable *= ((U64BIT)value)
51  #define ULL_Div32(variable, value) variable /= ((U64BIT)value)
52  #define ULL_ShiftLeft(variable, value) variable <<= (value)
53  #define ULL_ShiftRight(variable, value) variable >>= (value)
54  #define ULL_Set32(variable, value) variable = (U64BIT)value
55  #define ULL_SetInvalid(variable) variable = INVALID_64BIT_VAL
56  #define ULL_IsValid(variable) variable != INVALID_64BIT_VAL
57  #define ULL_IsEqual(variable, value) (variable == value)
58  #define ULL_Mod32(variable, value) (variable % (value))
59  #define ULL_Compare(first, second) (first > second) ? 1 : (first == second) ? 0 : -1
60  #define ULL_Compare32(first, second) UL_Compare(first, ((U64BIT)second))
61 #else
62 /* U64HL is a structure with 'h' and 'l' as 32 bit variables */
63  #define ULL_Get32(variable) variable.l
64  #define ULL_Add(variable, value) variable = ULONG_Add(variable, value)
65  #define ULL_Add32(variable, value) variable = ULONG_Add32(variable, value)
66  #define ULL_Sub(variable, value) variable = ULONG_Sub(variable, value)
67  #define ULL_Sub32(variable, value) variable = ULONG_Sub32(variable, value)
68  #define ULL_Mul32(variable, value) variable = ULONG_Mul32(variable, value)
69  #define ULL_Div32(variable, value) variable = ULONG_Div32(variable, value)
70  #define ULL_ShiftLeft(variable, value) variable = ULONG_ShiftLeft(variable, value)
71  #define ULL_ShiftRight(variable, value) variable = ULONG_ShiftRight(variable, value)
72  #define ULL_Set32(variable, value) variable.h = 0; variable.l = value;
73  #define ULL_SetInvalid(variable) variable.h = 0xffffffffU; variable.l = 0xffffffffU;
74  #define ULL_IsValid(variable) ((variable.h != 0xffffffffU) || (variable.l != 0xffffffffU))
75  #define ULL_IsEqual(variable, value) (variable.l == value.l && variable.h == value.h)
76  #define ULL_Mod32(variable, value) ULONG_Mod32(variable, value)
77  #define ULL_Compare(first, second) ULONG_Compare(first, second)
78  #define ULL_Compare32(first, second) ULONG_Compare32(first, second)
79 #endif
80 
81 #define ULL_Itoa(variable, str) ULONG_Itoa(variable, str)
82 
83 /*---Enumerations for public use---------------------------------------------*/
84 
85 /*---Global type defs for public use-----------------------------------------*/
86 
87 #ifdef USE_TRUE_64BIT
88 
89 typedef U64BIT U64HL;
90 
91 #else
92 
93 typedef struct { U32BIT h; U32BIT l; } U64HL;
94 
95 #endif
96 
97 /*---Global variable declarations for public use-----------------------------*/
98 
99 /*---Global Function prototypes for public use-------------------------------*/
100 
101 #ifndef USE_TRUE_64BIT
102 
109 U64HL ULONG_Add(U64HL variable, U64HL value);
110 
117 U64HL ULONG_Add32(U64HL variable, U32BIT value);
118 
127 U64HL ULONG_Sub(U64HL variable, U64HL value);
128 
137 U64HL ULONG_Sub32(U64HL variable, U32BIT value);
138 
145 U64HL ULONG_Mul32(U64HL variable, U32BIT value);
146 
155 U64HL ULONG_Div32(U64HL variable, U32BIT value);
156 
163 U64HL ULONG_ShiftLeft(U64HL variable, U32BIT value);
164 
171 U64HL ULONG_ShiftRight(U64HL variable, U32BIT value);
172 
182 U32BIT ULONG_Mod32(U64HL variable, U32BIT value);
183 
193 S32BIT ULONG_Compare(U64HL first, U64HL second);
194 
195 
205 S32BIT ULONG_Compare32(U64HL variable, U32BIT value);
206 
207 #endif
216 U64HL ULONG_Atoi(char *str);
217 
226 void ULONG_Itoa(U64HL variable, char *str);
227 
228 
229 
230 #endif /*_GLUE_ULONG_H*/
U64HL ULONG_Div32(U64HL variable, U32BIT value)
Divide a unsigned 64 bit variable by a 24-bit value. NOTE: This function will produce invalid values ...
Definition: glue_ulong.c:195
S32BIT ULONG_Compare(U64HL first, U64HL second)
Compare two variables, returning a value that indicates the result of the comparison.
Definition: glue_ulong.c:321
U64HL ULONG_Mul32(U64HL variable, U32BIT value)
Multiply a unsigned 64 bit variable by a 32-bit value.
Definition: glue_ulong.c:124
U64HL ULONG_ShiftRight(U64HL variable, U32BIT value)
Shift bits right on unsigned 64 bit variable by a 32-bit value.
Definition: glue_ulong.c:266
S32BIT ULONG_Compare32(U64HL variable, U32BIT value)
Compare a variable with a 32-bit value, returning a value that indicates the result of the comparison...
Definition: glue_ulong.c:364
U64HL ULONG_Sub(U64HL variable, U64HL value)
Subtract a value from a unsigned 64 bit variable. It is the responsibility of the caller to make sure...
Definition: glue_ulong.c:89
U64HL ULONG_Add(U64HL variable, U64HL value)
Add a value to a unsigned 64 bit variable.
Definition: glue_ulong.c:48
U64HL ULONG_ShiftLeft(U64HL variable, U32BIT value)
Shift bits left on unsigned 64 bit variable by a 32-bit value.
Definition: glue_ulong.c:236
U32BIT ULONG_Mod32(U64HL variable, U32BIT value)
Find the remainer after dividing a unsigned 64 bit variable by a 24-bit value. NOTE: This function wi...
Definition: glue_ulong.c:299
U64HL ULONG_Sub32(U64HL variable, U32BIT value)
Subtract a 32-bit value from a unsigned 64 bit variable. It is the responsibility of the caller to ma...
Definition: glue_ulong.c:108
System Wide Global Technical Data Type Definitions.
void ULONG_Itoa(U64HL variable, char *str)
Convert unsigned 64 bit to a string. The string should be able to hold at least 21 characters...
Definition: glue_ulong.c:427
U64HL ULONG_Add32(U64HL variable, U32BIT value)
Add a 32-bit value to a unsigned 64 bit variable.
Definition: glue_ulong.c:68