From 3f107464e35cf63a529358a1c240821b30c35d2b Mon Sep 17 00:00:00 2001 From: Indu Bhagat Date: Fri, 9 Dec 2022 10:23:07 -0800 Subject: 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. --- include/sframe.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include') diff --git a/include/sframe.h b/include/sframe.h index 7e167bf..03a2d75 100644 --- a/include/sframe.h +++ b/include/sframe.h @@ -273,6 +273,7 @@ typedef struct sframe_fre_info fi */ +/* Used when SFRAME_FRE_TYPE_ADDR1 is specified as FRE type. */ typedef struct sframe_frame_row_entry_addr1 { /* Start address of the frame row entry. Encoded as an 1-byte unsigned @@ -281,6 +282,11 @@ typedef struct sframe_frame_row_entry_addr1 sframe_fre_info sfre_info; } 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 { /* Start address of the frame row entry. Encoded as an 2-byte unsigned @@ -289,6 +295,11 @@ typedef struct sframe_frame_row_entry_addr2 sframe_fre_info sfre_info; } 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 { /* Start address of the frame row entry. Encoded as a 4-byte unsigned @@ -297,6 +308,10 @@ typedef struct sframe_frame_row_entry_addr4 sframe_fre_info sfre_info; } 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 } #endif -- cgit v1.1