OpenCores
URL https://opencores.org/ocsvn/heap_sorter/heap_sorter/trunk

Subversion Repositories heap_sorter

[/] [heap_sorter/] [trunk/] [HLS_implementation/] [Fig7/] [wz_hsort.cc] - Blame information for rev 8

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 wzab
#include <stdlib.h>
2
#include <stdio.h>
3
#include <string.h>
4
#include "wz_hsort.h"
5
 
6
sort_data l_smem[NM][SORT_LEN / 2] = { 0, };
7
sort_data r_smem[NM][SORT_LEN / 2] = { 0, };
8
 
9
//Each level occupies the memory from 
10
sort_data
11
heap_sort (sort_data val)
12
{
13
#pragma HLS INTERFACE ap_hs port=val
14
#pragma HSL INTERFACE ap_hs port=return
15
#pragma HLS DATA_PACK variable=val
16
#pragma HLS DATA_PACK variable=return
17
#pragma HLS DATA_PACK variable=l_smem
18
#pragma HLS DATA_PACK variable=r_smem
19
//#pragma HLS RESOURCE  variable=l_smem core=RAM_2P
20
//#pragma HLS RESOURCE  variable=r_smem core=RAM_2P
21
 
22
  //#pragma HLS DATAFLOW
23
#pragma HLS PIPELINE II=2
24
#pragma HLS ARRAY_PARTITION variable=l_smem complete dim=1
25
#pragma HLS ARRAY_PARTITION variable=r_smem complete dim=1
26
#pragma HLS UNROLL
27
  sort_data res;
28
  sort_data cur = val;
29
  int tmp;
30
  int pos;
31
  int lev;
32
  int shift;
33
  int offs = 0;
34
  int active;
35
  //We compare the input value with the memory on the top
36
  cur = r_smem[0][0];
37
  if (kle (val.key, cur.key))
38
    return val;
39
  else
40
    {                           //We start the update process
41
      res = cur;
42
      cur = val;
43
      pos = 0;
44
      active = 1;
45
      for (lev = 1; lev <= NM; lev++)
46
        {
47
          shift = 0;
48
          if (lev >= 2)
49
            shift = 1 << (lev - 2);
50
          if (active)
51
            {
52
              if ((lev == NM)
53
                  || (kle (cur.key, l_smem[lev][pos].key)
54
                      && kle (cur.key, r_smem[lev][pos].key)))
55
                {
56
                  if (pos < shift)
57
                    l_smem[lev - 1][pos] = cur;
58
                  else
59
                    r_smem[lev - 1][pos - shift] = cur;
60
                  active = 0;
61
                }
62
              else if (active
63
                       && klt (l_smem[lev][pos].key, cur.key)
64
                       && kle (l_smem[lev][pos].key, r_smem[lev][pos].key))
65
                {
66
                  if (pos < shift)
67
                    l_smem[lev - 1][pos] = l_smem[lev][pos];
68
                  else
69
                    r_smem[lev - 1][pos - shift] = l_smem[lev][pos];
70
                }
71
              else if (klt (r_smem[lev][pos].key, cur.key))
72
                {
73
                  if (pos < shift)
74
                    l_smem[lev - 1][pos] = r_smem[lev][pos];
75
                  else
76
                    r_smem[lev - 1][pos - shift] = r_smem[lev][pos];
77
                  pos += (1 << (lev - 1));
78
                }
79
              else
80
                {
81
                  printf ("impossible!!!\n");
82
                }
83
            }
84
        }
85
    }
86
  return res;
87
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.