Finding the next in round-robin scheduling by bit twiddling

前端 未结 9 1711
日久生厌
日久生厌 2021-02-02 02:46

Consider the following problem. You have a bit-string that represents the current scheduled slave in one-hot encoding. For example, \"00000100\" (with the leftmost bit being #7

9条回答
  •  清歌不尽
    2021-02-02 03:02

    Interesting problem! I can't help but wonder if you can't simplify your scheduler operation so this sort of operation would be necessary.

    Given that you know VHDL, I won't go into detail, but my suggestion would be the following:

    Use a 3 bit encoder to turn the currently scheduled task into a number:

    01000000 --> 6

    Then use a barrel shifter to rotate the mask by that number + 1 (to skip the current task):

    00001010 --> 00010100

    Then use a priority encoder to find the first available "next" task:

    00010100 --> 00000100 --> 2

    Then reverse the barrel shift by addition:

    (2+7) % 8 = 1

    Which when re-encoded will give the next scheduled task:

    00000010

    Should be very fast and straightforward, although the barrel shifter is 'expensive' in terms of realestate, but I don't see an easy way to get around that at the moment.

    Edit: Doug's solution is significantly more elegant...

    -Adam

提交回复
热议问题