URL
https://opencores.org/ocsvn/heap_sorter/heap_sorter/trunk
Subversion Repositories heap_sorter
[/] [heap_sorter/] [trunk/] [HLS_implementation/] [Fig5/] [wz_hsort.cc] - Rev 9
Go to most recent revision | Compare with Previous | Blame | View Log
#include <stdint.h> #include <stdio.h> #include <string.h> #include "wz_hsort.h" sort_data sort_mem[NM][SORT_LEN]; sort_data heap_sort (sort_data val) { #pragma HLS PIPELINE II=2 #pragma HLS INTERFACE ap_hs port=val #pragma HLS DATA_PACK variable=val #pragma HLS INTERFACE ap_ctrl_hs port=return #pragma HLS DATA_PACK variable=return #pragma HLS ARRAY_PARTITION variable=sort_mem dim=1 sort_data res; sort_data cur = val; int lev, offs, top, left, right, enable; cur = sort_mem[0][0]; if (kcmp(val.key,cur.key) <= 0) return val; //No need to update the heap else { res = cur; cur = val; offs = 0; enable = 1; for (lev = 1; lev <= NM; lev++) { top = offs; left = offs; right = (1 << (lev - 1)) + offs; if(enable){ if ((lev == NM) || ((kcmp(cur.key,sort_mem[lev][left].key) <= 0) && (kcmp(cur.key,sort_mem[lev][right].key) <= 0))) { sort_mem[lev-1][top] = cur; enable=0; } else if ((kcmp(sort_mem[lev][left].key,cur.key) < 0) && (kcmp(sort_mem[lev][left].key,sort_mem[lev][right].key) <= 0)) { sort_mem[lev-1][top] = sort_mem[lev][left]; } else if (kcmp(sort_mem[lev][right].key,cur.key)<0) { sort_mem[lev-1][top] = sort_mem[lev][right]; offs += (1 << (lev - 1)); } else { printf ("impossible!!!\n"); } } } } return res; }
Go to most recent revision | Compare with Previous | Blame | View Log