From bf4b19501699fe1ab286878ff8c23f4296cf82d2 Mon Sep 17 00:00:00 2001 From: Greg King Date: Fri, 18 Sep 2020 15:50:26 -0400 Subject: [PATCH] Added some comments that explain where the g_branch() code generator can and can't be used. --- src/cc65/codegen.c | 6 ++++++ src/cc65/codegen.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index 031e4e81a..cb448d738 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -2447,6 +2447,8 @@ void g_falsejump (unsigned flags attribute ((unused)), unsigned label) void g_branch (unsigned Label) /* Branch unconditionally to Label if the CPU has the BRA instruction. ** Otherwise, jump to Label. +** Use this function, instead of g_jump(), only where it is certain that +** the label cannot be farther away from the branch than -128/+127 bytes. */ { if ((CPUIsets[CPU] & CPU_ISET_65SC02) != 0) { @@ -4542,6 +4544,10 @@ void g_extractbitfield (unsigned Flags, unsigned FullWidthFlags, int IsSigned, AddCodeLine ("pla"); g_or (FullWidthFlags | CF_CONST, ~Mask); + /* We can generate a branch, instead of a jump, here because we know + ** that only a few instructions will be put between here and where + ** DoneLabel will be defined. + */ unsigned DoneLabel = GetLocalLabel (); g_branch (DoneLabel); diff --git a/src/cc65/codegen.h b/src/cc65/codegen.h index 3054a39b3..d6d3d2370 100644 --- a/src/cc65/codegen.h +++ b/src/cc65/codegen.h @@ -416,6 +416,8 @@ void g_falsejump (unsigned flags, unsigned label); void g_branch (unsigned Label); /* Branch unconditionally to Label if the CPU has the BRA instruction. ** Otherwise, jump to Label. +** Use this function, instead of g_jump(), only where it is certain that +** the label cannot be farther away from the branch than -128/+127 bytes. */ void g_lateadjustSP (unsigned label);