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

Subversion Repositories heap_sorter

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 wzab
#include <stdint.h>
2
#include <stdio.h>
3
#include <string.h>
4
#include "wz_hsort.h"
5
 
6
sort_data sort_mem[NM][SORT_LEN];
7
sort_data heap_sort (sort_data val)
8
{
9
#pragma HLS PIPELINE II=2
10
#pragma HLS INTERFACE ap_hs port=val
11
#pragma HLS DATA_PACK variable=val
12
#pragma HLS INTERFACE ap_ctrl_hs port=return
13
#pragma HLS DATA_PACK variable=return
14
#pragma HLS ARRAY_PARTITION variable=sort_mem dim=1
15
        sort_data res;
16
        sort_data cur = val;
17
        int lev, offs, top, left, right, enable;
18
        cur = sort_mem[0][0];
19
        if (kcmp(val.key,cur.key) <= 0)
20
                return val;                     //No need to update the heap
21
        else
22
        {
23
                res = cur;
24
                cur = val;
25
                offs = 0;
26
                enable = 1;
27
                for (lev = 1; lev <= NM; lev++)
28
                {
29
                        top = offs;
30
                        left = offs;
31
                        right = (1 << (lev - 1)) + offs;
32
                        if(enable){
33
                                if ((lev == NM) ||
34
                                                ((kcmp(cur.key,sort_mem[lev][left].key) <= 0) &&
35
                                                                (kcmp(cur.key,sort_mem[lev][right].key) <= 0)))
36
                                {
37
                                        sort_mem[lev-1][top] = cur;
38
                                        enable=0;
39
                                }
40
                                else if ((kcmp(sort_mem[lev][left].key,cur.key) < 0) &&
41
                                                (kcmp(sort_mem[lev][left].key,sort_mem[lev][right].key) <= 0))
42
                                {
43
                                        sort_mem[lev-1][top] = sort_mem[lev][left];
44
                                }
45
                                else if (kcmp(sort_mem[lev][right].key,cur.key)<0)
46
                                {
47
                                        sort_mem[lev-1][top] = sort_mem[lev][right];
48
                                        offs += (1 << (lev - 1));
49
                                }
50
                                else
51
                                {
52
                                        printf ("impossible!!!\n");
53
                                }
54
                        }
55
                }
56
        }
57
        return res;
58
}

powered by: WebSVN 2.1.0

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