Data Dependency

https://en.wikipedia.org/wiki/Data_dependency

(There’s some misleading expression on the flow/data dependency statement.)

1, what is data dependency

A data dependency in computer science is a situation in which a program statement (instruction) refers to the data of a preceding statement.

2, Bernstein Condition

The Bernstein Condition defines what data dependency’s logic format:

image

If above conditions are met, we say S2 depends on S1.

3, types

There’re 3 types of data dependencies: ante-dependency, flow(data) dependency and output dependency.

Their definitions as followed:

(1) ante-dependency

definition: I(S1) AND O(S2), S1->S2, S1 reads a memory location before S2 writes it.

To be more specific, S1->S2 means this is the correct order that S1 reads first before S2 writes, otherwise there may be execution error.

This is also known as WAR, writer-after-read.

Be aware that WAR is not an error; we should not confuse it with WAR hazard.

WAR hazard is a ‘hazard’, and WAR is the rule that’s violated that caused the hazard. The hazard happens because the rule of WAR is not followed.

Let’s see an example below:

      1,  B = 3

       2, A = B+1

       3, B = 7

(2, 3) is an ante-dependency example.

In this example, S1 is (A=B+1), and S2 is (B=7), so I(S1) targets memory B (read from B), and O(S2) also targets memory B(write to B).

(2) flow/data dependency

definition: O(S1) AND I(S2), S1->S2, S1 writes a memory location before S2 reads it.

This is also named as RAW. Some people also call this true data dependency.

Note: Statement in wikipedia is a little misleading.

(3) output dependency

definition: O(S1) AND O(S2), S1->S2, both write to the same memory location

This is WAW.

4, how to reduce data dependency

One of the disadvantages is data dependency may hinder parallelism. One of the ways to avoid that is :

(1) use scoreboarding to avoid RAW;

(2) use register renaming to cover WAR and WAW.

posted on 2018-03-30 14:53  freshair_cn  阅读(390)  评论(0编辑  收藏  举报

导航