Skip to content
Snippets Groups Projects
Commit 3f107464 authored by Indu Bhagat's avatar Indu Bhagat
Browse files

sframe: gas: libsframe: define constants and remove magic numbers

Define constants in sframe.h for the various limits associated with the
range of offsets that can be encoded in the start address of an SFrame
FRE. E.g., sframe_frame_row_entry_addr1 is used when start address
offset can be encoded as 1-byte unsigned value.

Update the code in gas to use these defined constants as it checks for
these limits, and remove the usage of magic numbers.

ChangeLog:

	* gas/sframe-opt.c (sframe_estimate_size_before_relax):
	(sframe_convert_frag): Do not use magic numbers.
	* libsframe/sframe.c (sframe_calc_fre_type): Likewise.

include/ChangeLog:

	* sframe.h (SFRAME_FRE_TYPE_ADDR1_LIMIT): New constant.
	(SFRAME_FRE_TYPE_ADDR2_LIMIT): Likewise.
	(SFRAME_FRE_TYPE_ADDR4_LIMIT): Likewise.
parent 70cfae61
No related branches found
No related tags found
No related merge requests found
...@@ -53,9 +53,9 @@ sframe_estimate_size_before_relax (fragS *frag) ...@@ -53,9 +53,9 @@ sframe_estimate_size_before_relax (fragS *frag)
widthS = exp->X_op_symbol; widthS = exp->X_op_symbol;
width = resolve_symbol_value (widthS); width = resolve_symbol_value (widthS);
if (width < 0x100) if (width < SFRAME_FRE_TYPE_ADDR1_LIMIT)
ret = 1; ret = 1;
else if (width < 0x10000) else if (width < SFRAME_FRE_TYPE_ADDR2_LIMIT)
ret = 2; ret = 2;
else else
ret = 4; ret = 4;
...@@ -109,9 +109,9 @@ sframe_convert_frag (fragS *frag) ...@@ -109,9 +109,9 @@ sframe_convert_frag (fragS *frag)
{ {
fsizeS = frag->fr_symbol; fsizeS = frag->fr_symbol;
fsize = resolve_symbol_value (fsizeS); fsize = resolve_symbol_value (fsizeS);
if (fsize < 0x100) if (fsize < SFRAME_FRE_TYPE_ADDR1_LIMIT)
func_info = SFRAME_FRE_TYPE_ADDR1; func_info = SFRAME_FRE_TYPE_ADDR1;
else if (fsize < 0x10000) else if (fsize < SFRAME_FRE_TYPE_ADDR2_LIMIT)
func_info = SFRAME_FRE_TYPE_ADDR2; func_info = SFRAME_FRE_TYPE_ADDR2;
else else
func_info = SFRAME_FRE_TYPE_ADDR4; func_info = SFRAME_FRE_TYPE_ADDR4;
...@@ -133,11 +133,11 @@ sframe_convert_frag (fragS *frag) ...@@ -133,11 +133,11 @@ sframe_convert_frag (fragS *frag)
switch (frag->fr_subtype & 7) switch (frag->fr_subtype & 7)
{ {
case 1: case 1:
gas_assert (fsize < 0x100); gas_assert (fsize < SFRAME_FRE_TYPE_ADDR1_LIMIT);
frag->fr_literal[frag->fr_fix] = diff; frag->fr_literal[frag->fr_fix] = diff;
break; break;
case 2: case 2:
gas_assert (fsize < 0x10000); gas_assert (fsize < SFRAME_FRE_TYPE_ADDR2_LIMIT);
md_number_to_chars (frag->fr_literal + frag->fr_fix, diff, 2); md_number_to_chars (frag->fr_literal + frag->fr_fix, diff, 2);
break; break;
case 4: case 4:
......
...@@ -273,6 +273,7 @@ typedef struct sframe_fre_info ...@@ -273,6 +273,7 @@ typedef struct sframe_fre_info
fi fi
*/ */
/* Used when SFRAME_FRE_TYPE_ADDR1 is specified as FRE type. */
typedef struct sframe_frame_row_entry_addr1 typedef struct sframe_frame_row_entry_addr1
{ {
/* Start address of the frame row entry. Encoded as an 1-byte unsigned /* Start address of the frame row entry. Encoded as an 1-byte unsigned
...@@ -281,6 +282,11 @@ typedef struct sframe_frame_row_entry_addr1 ...@@ -281,6 +282,11 @@ typedef struct sframe_frame_row_entry_addr1
sframe_fre_info sfre_info; sframe_fre_info sfre_info;
} ATTRIBUTE_PACKED sframe_frame_row_entry_addr1; } ATTRIBUTE_PACKED sframe_frame_row_entry_addr1;
/* Upper limit of start address in sframe_frame_row_entry_addr1
is 0x100 (not inclusive). */
#define SFRAME_FRE_TYPE_ADDR1_LIMIT ((SFRAME_FRE_TYPE_ADDR1 + 1) * 8)
/* Used when SFRAME_FRE_TYPE_ADDR2 is specified as FRE type. */
typedef struct sframe_frame_row_entry_addr2 typedef struct sframe_frame_row_entry_addr2
{ {
/* Start address of the frame row entry. Encoded as an 2-byte unsigned /* Start address of the frame row entry. Encoded as an 2-byte unsigned
...@@ -289,6 +295,11 @@ typedef struct sframe_frame_row_entry_addr2 ...@@ -289,6 +295,11 @@ typedef struct sframe_frame_row_entry_addr2
sframe_fre_info sfre_info; sframe_fre_info sfre_info;
} ATTRIBUTE_PACKED sframe_frame_row_entry_addr2; } ATTRIBUTE_PACKED sframe_frame_row_entry_addr2;
/* Upper limit of start address in sframe_frame_row_entry_addr2
is 0x10000 (not inclusive). */
#define SFRAME_FRE_TYPE_ADDR2_LIMIT ((SFRAME_FRE_TYPE_ADDR2 * 2) * 8)
/* Used when SFRAME_FRE_TYPE_ADDR4 is specified as FRE type. */
typedef struct sframe_frame_row_entry_addr4 typedef struct sframe_frame_row_entry_addr4
{ {
/* Start address of the frame row entry. Encoded as a 4-byte unsigned /* Start address of the frame row entry. Encoded as a 4-byte unsigned
...@@ -297,6 +308,10 @@ typedef struct sframe_frame_row_entry_addr4 ...@@ -297,6 +308,10 @@ typedef struct sframe_frame_row_entry_addr4
sframe_fre_info sfre_info; sframe_fre_info sfre_info;
} ATTRIBUTE_PACKED sframe_frame_row_entry_addr4; } ATTRIBUTE_PACKED sframe_frame_row_entry_addr4;
/* Upper limit of start address in sframe_frame_row_entry_addr2
is 0x100000000 (not inclusive). */
#define SFRAME_FRE_TYPE_ADDR4_LIMIT ((SFRAME_FRE_TYPE_ADDR4 * 2) * 8)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -572,11 +572,11 @@ unsigned int ...@@ -572,11 +572,11 @@ unsigned int
sframe_calc_fre_type (unsigned int func_size) sframe_calc_fre_type (unsigned int func_size)
{ {
unsigned int fre_type = 0; unsigned int fre_type = 0;
if (func_size <= 0xff) if (func_size < SFRAME_FRE_TYPE_ADDR1_LIMIT)
fre_type = SFRAME_FRE_TYPE_ADDR1; fre_type = SFRAME_FRE_TYPE_ADDR1;
else if (func_size <= 0xffff) else if (func_size < SFRAME_FRE_TYPE_ADDR2_LIMIT)
fre_type = SFRAME_FRE_TYPE_ADDR2; fre_type = SFRAME_FRE_TYPE_ADDR2;
else if (func_size <= 0xffffffff) else if (func_size < SFRAME_FRE_TYPE_ADDR4_LIMIT)
fre_type = SFRAME_FRE_TYPE_ADDR4; fre_type = SFRAME_FRE_TYPE_ADDR4;
return fre_type; return fre_type;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment