Skip to content

Commit 3b18cc1

Browse files
committed
Replace bit field manipulation functions with macros
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
1 parent 235a5b1 commit 3b18cc1

File tree

7 files changed

+55
-96
lines changed

7 files changed

+55
-96
lines changed

jerry-core/ecma/base/ecma-gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ ecma_gc_set_object_visited (ecma_object_t *object_p, /**< object */
180180
}
181181

182182
object_p->container = jrt_set_bit_field_value (object_p->container,
183-
is_visited,
183+
(uint64_t) is_visited,
184184
ECMA_OBJECT_GC_VISITED_POS,
185185
ECMA_OBJECT_GC_VISITED_WIDTH);
186186
} /* ecma_gc_set_object_visited */

jerry-core/ecma/base/ecma-helpers-value.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ static ecma_value_t __attr_pure___
6565
ecma_set_value_type_field (ecma_value_t value, /**< ecma value to set field in */
6666
ecma_type_t type_field) /**< new field value */
6767
{
68-
return (ecma_value_t) jrt_set_bit_field_value (value,
69-
type_field,
70-
ECMA_VALUE_TYPE_POS,
71-
ECMA_VALUE_TYPE_WIDTH);
68+
return jrt_set_bit_field_value (value,
69+
(ecma_value_t) type_field,
70+
ECMA_VALUE_TYPE_POS,
71+
ECMA_VALUE_TYPE_WIDTH);
7272
} /* ecma_set_value_type_field */
7373

7474
/**
@@ -80,10 +80,10 @@ static ecma_value_t __attr_pure___
8080
ecma_set_value_value_field (ecma_value_t value, /**< ecma value to set field in */
8181
uintptr_t value_field) /**< new field value */
8282
{
83-
return (ecma_value_t) jrt_set_bit_field_value (value,
84-
value_field,
85-
ECMA_VALUE_VALUE_POS,
86-
ECMA_VALUE_VALUE_WIDTH);
83+
return jrt_set_bit_field_value (value,
84+
(ecma_value_t) value_field,
85+
ECMA_VALUE_VALUE_POS,
86+
ECMA_VALUE_VALUE_WIDTH);
8787
} /* ecma_set_value_value_field */
8888

8989
/**

jerry-core/ecma/base/ecma-helpers.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ ecma_create_object (ecma_object_t *prototype_object_p, /**< pointer to prototybe
4949
ecma_init_gc_info (object_p);
5050

5151
object_p->container = jrt_set_bit_field_value (object_p->container,
52-
ECMA_NULL_POINTER,
52+
(uint64_t) ECMA_NULL_POINTER,
5353
ECMA_OBJECT_PROPERTIES_OR_BOUND_OBJECT_CP_POS,
5454
ECMA_OBJECT_PROPERTIES_OR_BOUND_OBJECT_CP_WIDTH);
5555
object_p->container = jrt_set_bit_field_value (object_p->container,
56-
false,
56+
(uint64_t) false,
5757
ECMA_OBJECT_IS_LEXICAL_ENVIRONMENT_POS,
5858
ECMA_OBJECT_IS_LEXICAL_ENVIRONMENT_WIDTH);
5959
object_p->container = jrt_set_bit_field_value (object_p->container,
60-
is_extensible,
60+
(uint64_t) is_extensible,
6161
ECMA_OBJECT_OBJ_EXTENSIBLE_POS,
6262
ECMA_OBJECT_OBJ_EXTENSIBLE_WIDTH);
6363
object_p->container = jrt_set_bit_field_value (object_p->container,
64-
type,
64+
(uint64_t) type,
6565
ECMA_OBJECT_OBJ_TYPE_POS,
6666
ECMA_OBJECT_OBJ_TYPE_WIDTH);
6767

@@ -96,23 +96,23 @@ ecma_create_decl_lex_env (ecma_object_t *outer_lexical_environment_p) /**< outer
9696
ecma_init_gc_info (new_lexical_environment_p);
9797

9898
new_lexical_environment_p->container = jrt_set_bit_field_value (new_lexical_environment_p->container,
99-
ECMA_NULL_POINTER,
99+
(uint64_t) ECMA_NULL_POINTER,
100100
ECMA_OBJECT_PROPERTIES_OR_BOUND_OBJECT_CP_POS,
101101
ECMA_OBJECT_PROPERTIES_OR_BOUND_OBJECT_CP_WIDTH);
102102
new_lexical_environment_p->container = jrt_set_bit_field_value (new_lexical_environment_p->container,
103-
true,
103+
(uint64_t) true,
104104
ECMA_OBJECT_IS_LEXICAL_ENVIRONMENT_POS,
105105
ECMA_OBJECT_IS_LEXICAL_ENVIRONMENT_WIDTH);
106106

107107
new_lexical_environment_p->container = jrt_set_bit_field_value (new_lexical_environment_p->container,
108-
ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE,
108+
(uint64_t) ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE,
109109
ECMA_OBJECT_LEX_ENV_TYPE_POS,
110110
ECMA_OBJECT_LEX_ENV_TYPE_WIDTH);
111111

112112
uint64_t outer_reference_cp;
113113
ECMA_SET_POINTER (outer_reference_cp, outer_lexical_environment_p);
114114
new_lexical_environment_p->container = jrt_set_bit_field_value (new_lexical_environment_p->container,
115-
outer_reference_cp,
115+
(uint64_t) outer_reference_cp,
116116
ECMA_OBJECT_LEX_ENV_OUTER_REFERENCE_CP_POS,
117117
ECMA_OBJECT_LEX_ENV_OUTER_REFERENCE_CP_WIDTH);
118118

@@ -121,7 +121,7 @@ ecma_create_decl_lex_env (ecma_object_t *outer_lexical_environment_p) /**< outer
121121
* but to not leave the value initialized, setting the flag to false.
122122
*/
123123
new_lexical_environment_p->container = jrt_set_bit_field_value (new_lexical_environment_p->container,
124-
false,
124+
(uint64_t) false,
125125
ECMA_OBJECT_LEX_ENV_PROVIDE_THIS_POS,
126126
ECMA_OBJECT_LEX_ENV_PROVIDE_THIS_WIDTH);
127127

@@ -151,31 +151,31 @@ ecma_create_object_lex_env (ecma_object_t *outer_lexical_environment_p, /**< out
151151
ecma_init_gc_info (new_lexical_environment_p);
152152

153153
new_lexical_environment_p->container = jrt_set_bit_field_value (new_lexical_environment_p->container,
154-
true,
154+
(uint64_t) true,
155155
ECMA_OBJECT_IS_LEXICAL_ENVIRONMENT_POS,
156156
ECMA_OBJECT_IS_LEXICAL_ENVIRONMENT_WIDTH);
157157

158158
new_lexical_environment_p->container = jrt_set_bit_field_value (new_lexical_environment_p->container,
159-
ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND,
159+
(uint64_t) ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND,
160160
ECMA_OBJECT_LEX_ENV_TYPE_POS,
161161
ECMA_OBJECT_LEX_ENV_TYPE_WIDTH);
162162

163163
uint64_t outer_reference_cp;
164164
ECMA_SET_POINTER (outer_reference_cp, outer_lexical_environment_p);
165165
new_lexical_environment_p->container = jrt_set_bit_field_value (new_lexical_environment_p->container,
166-
outer_reference_cp,
166+
(uint64_t) outer_reference_cp,
167167
ECMA_OBJECT_LEX_ENV_OUTER_REFERENCE_CP_POS,
168168
ECMA_OBJECT_LEX_ENV_OUTER_REFERENCE_CP_WIDTH);
169169

170170
new_lexical_environment_p->container = jrt_set_bit_field_value (new_lexical_environment_p->container,
171-
provide_this,
171+
(uint64_t) provide_this,
172172
ECMA_OBJECT_LEX_ENV_PROVIDE_THIS_POS,
173173
ECMA_OBJECT_LEX_ENV_PROVIDE_THIS_WIDTH);
174174

175175
uint64_t bound_object_cp;
176176
ECMA_SET_NON_NULL_POINTER (bound_object_cp, binding_obj_p);
177177
new_lexical_environment_p->container = jrt_set_bit_field_value (new_lexical_environment_p->container,
178-
bound_object_cp,
178+
(uint64_t) bound_object_cp,
179179
ECMA_OBJECT_PROPERTIES_OR_BOUND_OBJECT_CP_POS,
180180
ECMA_OBJECT_PROPERTIES_OR_BOUND_OBJECT_CP_WIDTH);
181181

@@ -220,7 +220,7 @@ ecma_set_object_extensible (ecma_object_t *object_p, /**< object */
220220
JERRY_ASSERT (!ecma_is_lexical_environment (object_p));
221221

222222
object_p->container = jrt_set_bit_field_value (object_p->container,
223-
is_extensible,
223+
(uint64_t) is_extensible,
224224
ECMA_OBJECT_OBJ_EXTENSIBLE_POS,
225225
ECMA_OBJECT_OBJ_EXTENSIBLE_WIDTH);
226226
} /* ecma_set_object_extensible */
@@ -250,7 +250,7 @@ ecma_set_object_type (ecma_object_t *object_p, /**< object */
250250
JERRY_ASSERT (!ecma_is_lexical_environment (object_p));
251251

252252
object_p->container = jrt_set_bit_field_value (object_p->container,
253-
type,
253+
(uint64_t) type,
254254
ECMA_OBJECT_OBJ_TYPE_POS,
255255
ECMA_OBJECT_OBJ_TYPE_WIDTH);
256256
} /* ecma_set_object_type */
@@ -309,7 +309,7 @@ ecma_set_object_is_builtin (ecma_object_t *object_p, /**< object */
309309
const uint32_t width = ECMA_OBJECT_OBJ_IS_BUILTIN_WIDTH;
310310

311311
object_p->container = jrt_set_bit_field_value (object_p->container,
312-
(uintptr_t) is_builtin,
312+
(uint64_t) is_builtin,
313313
offset,
314314
width);
315315
} /* ecma_set_object_is_builtin */

jerry-core/ecma/builtin-objects/ecma-builtins.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,11 @@ ecma_builtin_make_function_object_for_routine (ecma_builtin_id_t builtin_id, /**
479479
ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_OBJECT_ID_POS,
480480
ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_OBJECT_ID_WIDTH);
481481
packed_value = jrt_set_bit_field_value (packed_value,
482-
routine_id,
482+
(uint64_t) routine_id,
483483
ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_ROUTINE_ID_POS,
484484
ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_ROUTINE_ID_WIDTH);
485485
packed_value = jrt_set_bit_field_value (packed_value,
486-
length_prop_value,
486+
(uint64_t) length_prop_value,
487487
ECMA_BUILTIN_ROUTINE_ID_LENGTH_VALUE_POS,
488488
ECMA_BUILTIN_ROUTINE_ID_LENGTH_VALUE_WIDTH);
489489

jerry-core/jrt/jrt-bit-fields.c

Lines changed: 0 additions & 62 deletions
This file was deleted.

jerry-core/jrt/jrt-bit-fields.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
1+
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
2+
* Copyright 2016 University of Szeged
23
*
34
* Licensed under the Apache License, Version 2.0 (the "License");
45
* you may not use this file except in compliance with the License.
@@ -16,7 +17,27 @@
1617
#ifndef JERRY_BIT_FIELDS_H
1718
#define JERRY_BIT_FIELDS_H
1819

19-
extern uint64_t __attr_const___ jrt_extract_bit_field (uint64_t, size_t, size_t);
20-
extern uint64_t __attr_const___ jrt_set_bit_field_value (uint64_t, uint64_t, size_t, size_t);
20+
/**
21+
* Extract a bit-field.
22+
*
23+
* @param container container to extract bit-field from
24+
* @param lsb least significant bit of the value to be extracted
25+
* @param width width of the bit-field to be extracted
26+
* @return bit-field's value
27+
*/
28+
#define jrt_extract_bit_field(container, lsb, width) \
29+
(((container) >> lsb) & ((((__typeof__ (container)) 1) << (width)) - 1))
30+
31+
/**
32+
* Set a bit-field.
33+
*
34+
* @param container container to insert bit-field to
35+
* @param new_bit_field_value value of bit-field to insert
36+
* @param lsb least significant bit of the value to be inserted
37+
* @param width width of the bit-field to be inserted
38+
* @return bit-field's value
39+
*/
40+
#define jrt_set_bit_field_value(container, new_bit_field_value, lsb, width) \
41+
((container) & ~(((((__typeof__ (container)) 1) << (width)) - 1) << (lsb))) | ((new_bit_field_value) << (lsb))
2142

2243
#endif /* !JERRY_BIT_FIELDS_H */

jerry-core/rcs/rcs-records.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* Copyright 2015 Samsung Electronics Co., Ltd.
2-
* Copyright 2015 University of Szeged
1+
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
2+
* Copyright 2015-2016 University of Szeged
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@ rcs_record_set_field (rcs_record_t *rec_p, /**< record */
3535
JERRY_ASSERT (field_pos + field_width <= RCS_DYN_STORAGE_LENGTH_UNIT * JERRY_BITSINBYTE);
3636

3737
uint32_t prev_value = *(uint32_t *) rec_p;
38-
*(uint32_t *) rec_p = (uint32_t) jrt_set_bit_field_value (prev_value, value, field_pos, field_width);
38+
*(uint32_t *) rec_p = jrt_set_bit_field_value (prev_value, (uint32_t) value, field_pos, field_width);
3939
} /* rcs_record_set_field */
4040

4141
/**

0 commit comments

Comments
 (0)