From 6994ea0046784f0f70f167c131720697c104ccca Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sun, 6 Dec 2020 17:40:52 -0800 Subject: [PATCH] Fix segmentation fault. --- bpred.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bpred.c b/bpred.c index d41f827..62969cc 100644 --- a/bpred.c +++ b/bpred.c @@ -966,7 +966,9 @@ bpred_update(struct bpred_t *pred, /* branch predictor instance */ /* update state (but not for jumps) */ if (dir_update_ptr->pdir1) { - char pred_cutoff = (pred->dirpred.bimod->class == BPred3bit) ? 7 : 3; + struct bpred_dir_t* p1 = + pred->dirpred.bimod ? pred->dirpred.bimod : pred->dirpred.twolev; + char pred_cutoff = (p1->class == BPred3bit) ? 7 : 3; if (taken) { if (*dir_update_ptr->pdir1 < pred_cutoff) @@ -983,6 +985,7 @@ bpred_update(struct bpred_t *pred, /* branch predictor instance */ /* second direction predictor */ if (dir_update_ptr->pdir2) { + /* Assumption: second predictor is always two-level. */ char pred_cutoff = (pred->dirpred.twolev->class == BPred3bit) ? 7 : 3; if (taken) {