From 9b9c65b968fa2a1e6c2f86275e03f0ad96995b55 Mon Sep 17 00:00:00 2001 From: Lionel Debroux Date: Wed, 29 Nov 2023 12:45:17 +0100 Subject: [PATCH] Reduce padding and relocations (#355) * Optimize the JEP106 list by using __attribute__((packed)) to remove padding. The x86 & x86_64 series support unaligned accesses just fine, after all, and this is not remotely a hot path. * Optimize several string-related constructs by switching to fixed-length char arrays, which avoids pointers + relocations. * app/interrupt.c: array of different-length strings, but most of those are lengthy enough for this to be a clear win, especially on x86_64; * system/usbhcd.c: array of same-length strings; * tests/tests.h: array of structs containing same-length strings. * Reduce the size of the list of tests by using a narrower type for the cpu mode, which reduces padding. --- app/interrupt.c | 2 +- system/jedec_id.h | 4 ++-- system/usbhcd.c | 2 +- tests/tests.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/interrupt.c b/app/interrupt.c index 300610c..1a337c0 100644 --- a/app/interrupt.c +++ b/app/interrupt.c @@ -56,7 +56,7 @@ #define ADR_DIGITS "8" #endif -static const char *codes[] = { +static const char codes[][13] = { "Divide by 0", "Debug", "NMI", diff --git a/system/jedec_id.h b/system/jedec_id.h index 83a52f8..39d3082 100644 --- a/system/jedec_id.h +++ b/system/jedec_id.h @@ -10,12 +10,12 @@ #define JEP106_CNT \ sizeof(jep106)/sizeof(jep106[0]) -struct spd_jedec_manufacturer { +struct __attribute__((packed)) spd_jedec_manufacturer { uint16_t jedec_code; char *name; }; -static const struct spd_jedec_manufacturer jep106[] = { +static const struct __attribute__((packed)) spd_jedec_manufacturer jep106[] = { { 0x0001, "AMD" }, // { 0x0002, "AMI" }, // { 0x0003, "Fairchild" }, diff --git a/system/usbhcd.c b/system/usbhcd.c index e588504..5824eb1 100644 --- a/system/usbhcd.c +++ b/system/usbhcd.c @@ -56,7 +56,7 @@ typedef struct { // Private Variables //------------------------------------------------------------------------------ -static const char *hci_name[MAX_HCI_TYPE] = { "UHCI", "OHCI", "EHCI", "XHCI" }; +static const char hci_name[MAX_HCI_TYPE][5] = { "UHCI", "OHCI", "EHCI", "XHCI" }; static const hcd_methods_t methods = { .reset_root_hub_port = NULL, diff --git a/tests/tests.h b/tests/tests.h index cc1e1c9..9b5b873 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -18,11 +18,11 @@ typedef struct { bool enabled; - cpu_mode_t cpu_mode; + uint8_t cpu_mode; int stages; int iterations; int errors; - char *description; + char description[40]; } test_pattern_t; extern test_pattern_t test_list[NUM_TEST_PATTERNS];