cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
akboken
Adventurer
Adventurer
5,292 Views
Registered: ‎10-19-2015

Concatenation of multiple variables into one large variable.

Jump to solution

Hi All,

 

 

I am faced with following task.

 

I have following array in my HLS code as an output. 

 

ap_uint<4> ArrayA[256];

 

I want to convert this ArrayAto ap_uint<64> ArrayB[4];

 

In other words, I want to concatenate 64 elements of ArrayA into 1 element of ArrayB. I am wondering what is the most efficient way of doing this in HLS ? 

 

According to Xilinx documentation, apint_concatenate() does provide concatenation, but it seems this function is only takes 2 clock cycles. I want to do my concatenation in one clock cycle. 

 

I am wondering what is the best way of doing this in HLS ?

 

Thanks. 

 

 

0 Kudos
1 Solution

Accepted Solutions
hbucher
Scholar
Scholar
7,621 Views
Registered: ‎03-22-2016

@akboken

 

 

The union idea wont' work. I just tried and there are two problems:

1. The minimum size of a ap_uint<4> is one byte

2. unrestricted unions (unions with non-pod types) are only allowed in c++0x

 

 Perhaps a better idea would be: 

 

 

 

#include "ap_int.h"
#include <stdint.h>

uint32_t example( uint32_t v1, uint32_t v2 )
{
	struct Nibble2 {
		uint8_t lo :4;
		uint8_t hi :4;
	};
	union {
		Nibble2  ArrayA[4];
		uint32_t ArrayB[1];
	};
	ArrayA[0].lo = v1;
	ArrayA[0].hi = v2;
	ArrayA[1].lo = v1+1;
	ArrayA[1].hi = v2+1;
	ArrayA[2].lo = v1+2;
	ArrayA[2].hi = v2+2;
	ArrayA[3].lo = v1+3;
	ArrayA[3].hi = v2+3;
	return ArrayB[0];
}
vitorian.com --- We do this for fun. Always give kudos. Accept as solution if your question was answered.
I will not answer to personal messages - use the forums instead.

View solution in original post

2 Replies
hbucher
Scholar
Scholar
7,622 Views
Registered: ‎03-22-2016

@akboken

 

 

The union idea wont' work. I just tried and there are two problems:

1. The minimum size of a ap_uint<4> is one byte

2. unrestricted unions (unions with non-pod types) are only allowed in c++0x

 

 Perhaps a better idea would be: 

 

 

 

#include "ap_int.h"
#include <stdint.h>

uint32_t example( uint32_t v1, uint32_t v2 )
{
	struct Nibble2 {
		uint8_t lo :4;
		uint8_t hi :4;
	};
	union {
		Nibble2  ArrayA[4];
		uint32_t ArrayB[1];
	};
	ArrayA[0].lo = v1;
	ArrayA[0].hi = v2;
	ArrayA[1].lo = v1+1;
	ArrayA[1].hi = v2+1;
	ArrayA[2].lo = v1+2;
	ArrayA[2].hi = v2+2;
	ArrayA[3].lo = v1+3;
	ArrayA[3].hi = v2+3;
	return ArrayB[0];
}
vitorian.com --- We do this for fun. Always give kudos. Accept as solution if your question was answered.
I will not answer to personal messages - use the forums instead.

View solution in original post

hpoetzl
Voyager
Voyager
5,125 Views
Registered: ‎06-24-2013

Hmm, arriving late ... what's wrong with:

void foo(ap_uint<4> a[64], ap_uint<64> q[4]) {
    #pragma HLS INTERFACE ap_fifo port=a,q
    #pragma HLS INTERFACE ap_ctrl_none port=return

    for (int i=0; i<4; i++) {
        ap_uint<64> temp;

        for (int j=0; j<16; j++) {
            temp(j*4+3, j*4) = a[i*16+j];
        }

        q[i] = temp;
    }
}

Thanks in advance,

Herbert

-------------- Yes, I do this for fun!
0 Kudos